Android Client SDK
com.verivo.akula.persistence.AKPersistenceManager Class Reference

The AKPersistenceManager is the central interface for reading and writing objects into persistable storage and for synchronizing data in the persistent storage with the Akula Server. More...

Public Member Functions

boolean add (AKModel data)
 Adds the data in a AKModel object to the persistent data store. More...
 
void close ()
 Closes this instance of AKPersistenceManager, making it unusable. More...
 
boolean delete (AKModel data)
 Deletes a record in the persistent store. More...
 
String getClientSyncID ()
 Get the unique persisted client ID that identifies the device to the sync server. More...
 
boolean isOpen ()
 Returns the state of this AKPersistenceManager instance. More...
 
boolean isPersisted (AKModel data)
 Check whether a given model has been added to the persistent store. More...
 
boolean update (AKModel data)
 Updates the data in a AKModel object in the persistent store. More...
 

Static Public Member Functions

static boolean addPersistenceListener (AKPersistenceListener listener)
 Associate an AKPersistenceListener object to listen for persistence manager clear events. More...
 
static void addSyncBlockedListener (AKSyncBlockedListener listener)
 Add an AKSyncBlockedListener object to handle events when sync becomes blocked or unblocked, as defined by a sync client rule. More...
 
static void clearPersistedData ()
 Clear all persisted data. More...
 
static AKPersistenceManager getInstance ()
 Get an instance of the AKPersistenceManager. More...
 
static void initSchema (Class<?extends AKModel > type, AKSchema schema)
 Initializes the persistent data store on the client with the specified schema. More...
 
static void initSchema (Class<?extends AKModel > type, AKSchema schema, String syncEndpoint)
 Initializes the persistent data store on the client with the specified schema and prepares the class to synchronize its data with the sync server. More...
 
static void initSchema (Class<?extends AKModel > type, AKSchema schema, String syncEndpoint, AKSyncSerializer syncSerializer)
 Initializes the persistent data store on the client with the specified schema and prepares the class to synchronize its data with the sync server. More...
 
static boolean isSyncBlocked (Class entity)
 Returns true if sync is currently blocked for the specified entity. More...
 
static boolean removePersistenceListener (AKPersistenceListener listener)
 Remove an associated AKPersistenceListener object. More...
 

Detailed Description

The AKPersistenceManager is the central interface for reading and writing objects into persistable storage and for synchronizing data in the persistent storage with the Akula Server.

Call the initSchema() method to initialize the persistence mechanism with the schema for each class that you want to persist. For example, if your app defines four persistent classes, you call initSchema() four times to initialize the persistence mechanism for the four classes.

Call the getInstance() method to get a reference to the AKPersistenceManager class in your client app.

Call the sync() method to synchronize models in the persistent data with the Akula Server.

An AKPersistenceManager instance can have two states:

See Also
AKBasicModel
Version
1.0

Member Function Documentation

boolean com.verivo.akula.persistence.AKPersistenceManager.add ( AKModel  data)

Adds the data in a AKModel object to the persistent data store.

Parameters
dataThe data to persist.
Returns
true if the operation was successful.
Exceptions
AKPersistenceExceptionif the specified AKModel cannot be added.
Version
1.0
static boolean com.verivo.akula.persistence.AKPersistenceManager.addPersistenceListener ( AKPersistenceListener  listener)
static

Associate an AKPersistenceListener object to listen for persistence manager clear events.

Parameters
listenerThe listener, which must implement AKPersistenceListener.
Returns
true if the listener was added, false otherwise.
Version
1.0
static void com.verivo.akula.persistence.AKPersistenceManager.addSyncBlockedListener ( AKSyncBlockedListener  listener)
static

Add an AKSyncBlockedListener object to handle events when sync becomes blocked or unblocked, as defined by a sync client rule.

System administrators define sync client rules that are sent down to the client on a successful log in to an app scope.

Parameters
listenerAn AKSyncBlockedListener object that defines the handler for the sync blocking events.
Version
1.5.0
static void com.verivo.akula.persistence.AKPersistenceManager.clearPersistedData ( )
static

Clear all persisted data.

This method delete all the data and metadata in the persistent data store, including any change tracking data used by the Akula sync mechanism, and all schema and entity information for registered classes. After the persistent data storage is cleared, any attempt to perform a CRUD operation on the persistent data throws an error.

Clearing the data from the persistent data store also closes all AKPersistenceManager instances. Therefore, any attempt to use an AKPersistenceManager instance after the clear results in an error.

After clearing the persistent data store, you must call the initSchema() method to initialize the persistence mechanism with the schema for each class that you want to persist. After initializing the schema, create new instances of the AKPersistenceManager class, and then use the methods of the AKPersistenceManager instance to perform CRUD operations on the persistent data store.

Attach an AKPersistenceListener to the persistence manager to be notified of the clear event when this method is invoked.

See Also
AKPersistenceListener
Version
1.0
void com.verivo.akula.persistence.AKPersistenceManager.close ( )

Closes this instance of AKPersistenceManager, making it unusable.

This method removes all open connections to the persistent data stores, sets the state of this instance to closed, and removes the listener from AKEncryptionManager.

Version
1.0
boolean com.verivo.akula.persistence.AKPersistenceManager.delete ( AKModel  data)

Deletes a record in the persistent store.

Parameters
dataThe data to delete.
Returns
true if the operation was successful.
Exceptions
AKPersistenceExceptionif the specified AKModel cannot be deleted.
Version
1.0
String com.verivo.akula.persistence.AKPersistenceManager.getClientSyncID ( )

Get the unique persisted client ID that identifies the device to the sync server.

Returns
String containing the client sync ID.
Version
1.0
static AKPersistenceManager com.verivo.akula.persistence.AKPersistenceManager.getInstance ( )
static

Get an instance of the AKPersistenceManager.

Returns
An open AKPersistenceManager object.
Exceptions
AKPersistenceExceptionif an AKPersistenceManager instance cannot be created.
Version
1.0
static void com.verivo.akula.persistence.AKPersistenceManager.initSchema ( Class<?extends AKModel type,
AKSchema  schema 
)
static

Initializes the persistent data store on the client with the specified schema.

You must initialize the persistent data store with the schema before you can store objects to the data store.

The schema defines the class data to persist. It can include all class properties, or a subset. For example, you define a class with many different properties, but you only want to persist a subset of those properties. Therefore, the schema for that class may only include a subset of the class properties.

Parameters
typeThe Class type to associate with the AKSchema.
schemaThe AKSchema to associate with the Class type.
Exceptions
AKPersistenceException
Version
1.0
static void com.verivo.akula.persistence.AKPersistenceManager.initSchema ( Class<?extends AKModel type,
AKSchema  schema,
String  syncEndpoint 
)
static

Initializes the persistent data store on the client with the specified schema and prepares the class to synchronize its data with the sync server.

You must initialize the persistent data store with the schema before you can store objects to the data store.

The schema defines the class data to persist. It can include all class properties, or a subset. For example, you define a class with many different properties, but you only want to persist a subset of those properties. Therefore, the schema for that class may only include a subset of the class properties.

For the syncEndpoint argument, specify only the endpoint portion of the URL. You must have already called the AK.init() method with the URL of the app scope. For example, you might have already made the following call:

AK.init(getApplicationContext(), "http://myCo.com:8080/akula/SampleSync&quot;,
  "my.co.myApp");

Therefore, you only pass "/data/sync" as the value of syncEndpoint.

Parameters
typeThe Class type to associate with the AKSchema and sync URL.
schemaThe AKSchema to associate with the Class type.
syncEndpointThe endpoint controlled by an Akula app scope that contains a custom module to handle the sync.
Exceptions
AKPersistenceException
AKSchemaExceptionif a sync endpoint is provided but the given schema has no primary key defined.
Version
1.0
static void com.verivo.akula.persistence.AKPersistenceManager.initSchema ( Class<?extends AKModel type,
AKSchema  schema,
String  syncEndpoint,
AKSyncSerializer  syncSerializer 
)
static

Initializes the persistent data store on the client with the specified schema and prepares the class to synchronize its data with the sync server.

You must initialize the persistent data store with the schema before you can store objects to the data store.

The schema defines the class data to persist. It can include all class properties, or a subset. For example, you define a class with many different properties, but you only want to persist a subset of those properties. Therefore, the schema for that class may only include a subset of the class properties.

For the syncEndpoint argument, specify only the endpoint portion of the URL. You must have already called the AK.init() method with the URL of the app scope. For example, you might have already made the following call:

AK.init(getApplicationContext(), "http://myCo.com:8080/akula/SampleSync&quot;,
  "my.co.myApp");

Therefore, you only pass "/data/sync" as the value of syncEndpoint.

Parameters
typeThe Class type to associate with the AKSchema and sync URL.
schemaThe AKSchema to associate with the Class type, sync URL, and sync strategy.
syncEndpointThe endpoint controlled by an Akula app scope that contains a custom module to handle the synch.
syncSerializerAKSyncSerializer for this class. Can be null. If it is null, AKBasicSyncSerializer will be used.
Exceptions
AKPersistenceException
AKSchemaExceptionif a sync endpoint is provided but the given schema has no primary key defined.
Version
1.0
boolean com.verivo.akula.persistence.AKPersistenceManager.isOpen ( )

Returns the state of this AKPersistenceManager instance.

Returns
true if the instance is open, and false if not.
Version
1.0
boolean com.verivo.akula.persistence.AKPersistenceManager.isPersisted ( AKModel  data)

Check whether a given model has been added to the persistent store.

Parameters
dataThe data model to check.
Returns
true if the data model has been stored, and its contents should be updated.
Version
2.0.0
static boolean com.verivo.akula.persistence.AKPersistenceManager.isSyncBlocked ( Class  entity)
static

Returns true if sync is currently blocked for the specified entity.

Sync can be blocked by a client rule. System administrators define sync client rules that are sent down to the client on a successful log in to an app scope.

Parameters
entityThe syncable entity to test. When a system administrator creates a client rule to block sync, they can specify to block sync for all entities, or for a specific set of entities, where the name of the entity corresponds to the class name that defines the syncable object. For example, for the class Customer:
AKPersistenceManager.isSyncBlocked(Customer.class);
Returns
true if sync is currently blocked, and false otherwise.
Version
1.5.0
static boolean com.verivo.akula.persistence.AKPersistenceManager.removePersistenceListener ( AKPersistenceListener  listener)
static

Remove an associated AKPersistenceListener object.

Parameters
listenerThe listener.
Returns
true if the listener was deleted, false otherwise.
Version
1.0
boolean com.verivo.akula.persistence.AKPersistenceManager.update ( AKModel  data)

Updates the data in a AKModel object in the persistent store.

Parameters
dataThe data to update.
Returns
true if the operation was successful.
Exceptions
AKPersistenceExceptionif the specified AKModel cannot be updated.
Version
1.0