Errai 3.0.1-SNAPSHOT

org.jboss.errai.jpa.sync.client.local
Class ClientSyncManager

java.lang.Object
  extended by org.jboss.errai.jpa.sync.client.local.ClientSyncManager

@ApplicationScoped
public class ClientSyncManager
extends Object

The main contact point for applications that want to initiate data sync operations from the client side of an Errai application.

Author:
Jonathan Fuerth

Field Summary
 Caller<DataSyncService> dataSyncService
          Temporarily public so we can override the caller from within the tests.
protected static ErrorCallback<?> DEFAULT_ERROR_CALLBACK
           
 
Constructor Summary
ClientSyncManager()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ERROR_CALLBACK

protected static final ErrorCallback<?> DEFAULT_ERROR_CALLBACK

dataSyncService

@Inject
public Caller<DataSyncService> dataSyncService
Temporarily public so we can override the caller from within the tests. Will find a better way in the future!

Constructor Detail

ClientSyncManager

public ClientSyncManager()
Method Detail

getInstance

public static ClientSyncManager getInstance()
Returns the global instance of ClientSyncManager.


resetInstance

public static void resetInstance()
Resets the global instance of ClientSyncManager.


coldSync

public <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. After a successful synchronization, both the expected state and desired state entity managers will yield the same results as the server-side entity manager does for the given query with the given set of parameters.

Parameters:
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.

isSyncInProgress

public 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. If this method returns true, a call to coldSync(String, Class, Map, RemoteCallback, ErrorCallback) will fail immediately with an IllegalStateException.


getExpectedStateEm

public 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). This method exists mostly to promote testability, and is rarely needed by applications at runtime.


getDesiredStateEm

public 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). This method exists mostly to promote testability, and is rarely needed by applications at runtime.


clear

public void clear()
Clears all expected state and actual state data (essentially wiping out all localStorage data that Errai cares about). This operation will destroy any local data that has not been synced to the server, including data that the sync manager was never told about.


Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.