To get sync service instance pass context of the activity.
Creating a Sync Object
Create a Sync Object
You need to have the following files to use Sync SDKs:
Once you upload the sync config file, the system generates code. For Android, the generated code will contain the following two packages:
com.voltmx.sdk.services.sync.codegen: This contains model class for each object in sync config and named as .java
com.voltmx.sdk.services.sync.metadata: This contains single class containing ddls needed to create device database and named as SyncGeneratedMetadata.java
Import above packages into your project.
Error Codes
The following is a list of error codes for Android platform along with the corresponding causes and error messages:
Error Code
Cause
Error Message
Comments
HCL1000E
Unknown Error
HCL1001E
Please initialize init before calling any other API
Cannot delete as child record(s) with cascades false exist for this record
HCL8888E
whatever message comes from server
HCL1010E
UpgradeRequired In Progress
1000
Unknown error occurred at network layer
Unknown Error occurred
1005
Invalid input url. Please check the url
Invalid input url. Please check the url
1012
Network Request Failed
Request Failed
1011
Device has no data connectivity. Please try the operation after establishing connectivity.
HCL2005E
Invalid Arguments for the API (Messages Differ as per the API Calls) For example, eventType can not be null. Provide a proper eventType eventSubType value is greater than 256 characters. Provide a Event Subtype with at most 256 chars etc.
HCL2000E
1. Not able to add header or param to service 2. Not able to start a thread for making network call
<Generic exception, error message will be thrown by android layer>
Create, Read, Update, and Delete (CRUD) operations in Native SDK
Create/Update
For both Create and Update, we have the same APIs. If object passed is a new object then create happens, otherwise if object is fetched from device update happens.
Creating a Record
API Used: public void save(T syncObject) throws VoltMXException
Sample Code
Creating a Record in Background
API Used: public void saveInBackground(T dataObject, SyncObjectCallback callback)
Sample Code:
Bulk Create
Bulk Create in Background
Bulk Update
Bulk Update in Background
Updating a Sync Object
Updating a Record
Updating a Record in Background
Retrieving an Object
Executing Queries
Query class can be used to define queries.
Execute Query
Execute Query in Background
Getting an Object
To retrieve an object from database using its primary key.
getObject
getObject in background
Fetching an Object
To fetch all the details of a partially fetched object.
Fetching an Object
Fetching an Object in Background
Deleting an Object
Delete
Delete in Background
Bulk Delete
Bulk Delete in Background
Pushing (or syncing ) Changes to the Sync Server
The startSessionInBackgroundAPI can be used to sync (upload and download/push and pull) changes between device and sync server. This is purely asynchronous API. To get notifications during the API execution you can implement SyncListener interface and pass object of implementing class to synchronize.
Configuring Various Sync Options
You can use sync options class to configure various sync options like:
Upload Error Policy: This policy can be used to configure whether to continue or abort on getting upload error. Default value is continue on error.
Schema Upgrade Policy: This policy is used to configure what action to be taken when schema upgrade is available. Default value is upload and upgrade.
Enabling or disabling download/upload for a scope: Default value is continue on error.
Adding filter for syncing: This can be used to set download filters. By default, all pass filters are used.
Configuring remove after upload policy: this can be used to configure removal of records instance from device after successful upload. By default, this option is disabled for all scopes.
Configuring NetworkOptions
The NetworkOptions class can be used to configure various options for APIs that use the network.
For example, startSessionInBackground, performUpgradeInBackground, and isUpgradeRequiredInBackground.
Following options can be configured:
Network Timeout: the time for which device should wait for server to respond. If server does not respond in the specified time, an error is thrown. Default value is ten seconds.
Retry Count: Retry count specifies how many times a request can be sent to server in case of a server error. Default value is five.
Retry Wait Time: Time between two retries. Default value is five seconds.
Retry Listener: The listener which should be invoked on each retry.