Persistence - Java SDK

Persistence - Java SDK

Persistent classes in an application implement the entities of the business problem. In Java SDK, two default persistence classes with their implementations are provided. On the other hand, if a developer wants his specific implementation, he can define his custom implementation by connecting to their respective database system.

Implementing OAuth Persistence

Once the application is authorized, OAuth access and refresh tokens can be used for subsequent user data requests to Zoho CRM. Hence, they need to be persisted by the client app.

The persistence is achieved by writing an implementation of the inbuilt ZohoPersistenceHandler interface, which has the following callback methods.
  • saveOAuthData(ZohoOAuthTokens tokens) — invoked while fetching access and refresh tokens from Zoho.
  • deleteOAuthTokens()— invoked before saving the newly received tokens.
  • getOAuthTokens() — invoked before firing a request to fetch the saved tokens. This method should return ZohoOAuthTokens object for the library to process it. 
Our Java SDK provides two sample implementations of ZohoPersistenceHandler interface within the client library as shown below:
      
      

You could use any of the above mentioned interface implementations provided in the library.

ZohoOAuthFilePersistence

ZohoOAuthFilePersistence uses a local properties file to write and read the OAuth tokens data. If you are using this persistence, then you need to provide the following attributes and their values in the oauth_configuration.properties file.
  1. persistence_handler_class=com.zoho.oauth.clientapp.ZohoOAuthFilePersistence
  2. oauth_tokens_file_path=relative path of the "oauthtokens.properties" file in the workspace.

ZohoOAuthDBPersistence

ZohoOAuthDBPersistence uses a custom MySQL persistence. To use this, you should make sure of the following, 

  • MySQL should be running in the same machine serving at the default port 3306.
  • The database name should be "zohooauth".
  • There must be a table "oauthtokens" with the columns "useridentifier" (varchar), "accesstoken" (varchar), "refreshtoken" (varchar) and "expirytime" (bigint).
If you are using ZohoOAuthDBPersistencethen you need to provide the following attributes and values in the oauth_configuration.properties file.
  1. persistence_handler_class=com.zoho.oauth.clientapp.ZohoOAuthDBPersistence
  2. mysql_username=root
  3. mysql_password=
Note
  • ZohoOAuthFilePersistence implementation only supports to store and refresh only a single user’s token. Hence this shall be used if your app accesses Zoho APIs on behalf of a single user only.
  • In case if your app has to support for multiple users, please use ZohoOAuthDBPersistence or write your own implementation of ZohoPersistenceHandler.

    • Related Articles

    • Configuration - Java SDK

      Setting up the configuration is a system engineering process, for establishing and maintaining the consistency of the application's performance, functional and physical attributes with its requirements, design and operational information throughout ...
    • Initialization - Java SDK

      Now the app is ready to be initialized after defining OAuth configuration file and OAuth persistence handler class for your app. Generating grant tokens For a Single User The developer console has an option to generate grant token for a user ...
    • Create the first Java Application

      Let us quickly walk through the sequence of steps to use Java SDK.       1. Register a Zoho client as described in the page link.       2. Create the File hierarchy in your eclipse project as shown below:                  3. Create a folder ...
    • Java SDK - Overview

      Java SDK offers a way to create client java applications that can be integrated with Zoho CRM. This SDK makes the access and use of necessary CRM APIs with ease. In other words, it serves as a wrapper for the REST APIs, making it easier to use the ...
    • File Structure Hierarchy - Java SDK

      In your Java IDE setup, create and arrange the packages containing resource files, properties files, and required jars (ZCRMSDK.jar) as displayed in the image. The numbered items shown in the image are the files to be created in a step wise manner.   ...