@ApplicationScoped public class ClientSyncManager extends Object
Modifier and Type | Field and Description |
---|---|
Caller<DataSyncService> |
dataSyncService
Temporarily public so we can override the caller from within the tests.
|
protected static ErrorCallback<?> |
DEFAULT_ERROR_CALLBACK |
Constructor and Description |
---|
ClientSyncManager() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all expected state and actual state data (essentially wiping out all
localStorage data that Errai cares about).
|
<E> void |
coldSync(String queryName,
Class<E> queryResultType,
Map<String,Object> queryParams,
RemoteCallback<List<SyncResponse<E>>> onCompletion,
ErrorCallback<?> onError)
Performs a "cold" synchronization on the results of the given query with the given parameters.
|
ErraiEntityManager |
getDesiredStateEm()
Returns the persistence context that holds the "desired state" of this
Client-side Sync Manager (the state that the application has set up, which
we will eventually sync to the server).
|
ErraiEntityManager |
getExpectedStateEm()
Returns the persistence context that holds the "expected state" of this
Client-side Sync Manager (the state that we believe the entities have on
the server).
|
static ClientSyncManager |
getInstance()
Returns the global instance of ClientSyncManager.
|
boolean |
isSyncInProgress()
Returns true if a sync request has been sent to the server for which no
response or error has yet been received; false if no sync operation is
currently pending.
|
static void |
resetInstance()
Resets the global instance of ClientSyncManager.
|
protected static final ErrorCallback<?> DEFAULT_ERROR_CALLBACK
@Inject public Caller<DataSyncService> dataSyncService
public static ClientSyncManager getInstance()
public static void resetInstance()
public <E> void coldSync(String queryName, Class<E> queryResultType, Map<String,Object> queryParams, RemoteCallback<List<SyncResponse<E>>> onCompletion, ErrorCallback<?> onError)
queryName
- The name of a JPA named query. This query must be defined in a NamedQuery
annotation that is visible to both the client and server applications. This usually
means it is defined on an entity in the shared
package.queryResultType
- The result type returned by the query. Must be a JPA entity type known to both the
client and server applications.queryParams
- The name-value pairs to use for filling in the named parameters in the query.onCompletion
- Called when the data sync response has been received from the server, and the sync
response operations have been applied to the expected state and desired state entity
managers. Must not be null. In case of conflicts, the original client values are
available in the list of SyncResponse objects, which gives you a chance to implement a
different conflict resolution policy.onError
- Called when the data sync fails: either because the remote service threw an exception,
or because of a communication error. Can be null, in which case the default error
handling for the Caller<DataSyncService>
will apply.public boolean isSyncInProgress()
coldSync(String, Class, Map, RemoteCallback, ErrorCallback)
will
fail immediately with an IllegalStateException.public ErraiEntityManager getExpectedStateEm()
public ErraiEntityManager getDesiredStateEm()
public void clear()
Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.