Documentation 1.0.1
Related Topics

Labels
Documentation Downloads
All Versions
Documentation Version 1.0.1
NOTE: You are currently viewing version 1.0.1 of the Akula documentation.
View the latest version of this page or go to the current documentation home page. |
Clearing Persistent Data Stores
You can 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. To do this, you use the following static methods of the persistence manager:
- Android
– AKPersistenceManager.clearPersistedData()
- iOS
– clearPersistedData:
class - JavaScript
– AK.PersistenceManager.clearPersistedData()
After you clear the persistent data, Akula throws an error if you attempt to perform a CRUD operation on the persistent data.
Clearing the data from the persistent data store also closes all persistence manager instances. Therefore, any attempt to use a persistence manager instance after the clear results in an error.
![]() | After clearing the persistent data, you should assume that all in-memory versions of data read from the persistent data store are no longer valid. |
After clearing an unencrypted persistent data store
After clearing the persistent data store, you must initialize the persistence mechanism with the schema for each class that you want to persist. To do this, use the following methods of the persistence manager:
- Android
– AKPersistenceManager.initSchema()
- iOS
– initSchema:forClass:error:
- JavaScript
– AK.PersistenceManager.initializeEntityStore()
After initializing the schema, create new instances of the persistence manager, and then use the methods of the instance to perform CRUD operations on the persistent data store.
For more information, see Storing Persistent Data on the Client.
After clearing an encrypted persistent data store
If you are using an encrypted persistent data store, the encrypted persistent data store is locked when you clear it, and the current passphrase is discarded. Therefore, the first action after clearing the encrypted persistent data store is to unlock it with the previous passphrase or with a new passphrase.
You can then reinitialize the encrypted persistent data store by calling the following methods of the persistence manager to access the encrypted persistent data store:
- Android
– AKPersistenceManager.initSchema()
- iOS
– initSchema:forClass:error:
The JavaScript version of the persistence manager does not currently support using an encrypted data store.
For more information, see Encrypting Data in the Persistent Data Store.
After clearing the persistent data store when using sync
If you are using the Akula synchronization mechanism, clearing the persistent data store deletes all current data and any changes you made to data since you last synced from the server. Therefore, you must reinitialize the persistent data store by calling the following persistence manager methods:
- Android
– AKPersistenceManager.initSchema()
- iOS
– initSchema:forClass:error:
- JavaScript
– AK.PersistenceManager.initSchema()
After calling these methods, you can perform a sync operation with the server to download data to the persistent data store.
For more information on the Akula synchronization mechanism, see Synchronizing Client Data with the Akula Server.
Handling the clear event
When you clear the persistent data store, the persistence manager dispatches a clear event that you can then handle in your client app. Your event handler can reinitialize the persistent data store, unlock an encrypted persistent data store, perform a sync operation with the Akula Server, or perform other operations.
Handling the clear event in an Android app
In Android, use the static AKPersistenceManager.addPersistenceListener()
method to register an event listener for the change event. A listener is an object that implements the AKPersistenceListener interface to define the onClearPersistedData()
method, as the following example shows:
Handling the clear event in an iOS app
In an iOS app, the event handler for a clear event receives an NSNotification object that contains three fields:
name
- The event name as defined by theAKPersistedDataClearedNotification
static method on the AKPersistenceManager class.object
- The object associated with the event.userInfo
- An NSDictionary object that is nil for the clear event.
The following example handles the clear event for AKPersistenceManager:
Handling the clear event in a JavaScript app
In a JavaScript app, register your listener with the addPersistenceListener()
method. The onClearPersistedData
function is triggered when you call the AK.PersistenceManager.learPersistenceData()
method, as the following example shows:
0 Comments
Hide/Show Comments