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 "oauthtokenswith 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.


SEE ALSO

Release Notes
    • Related Articles

    • 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 ...
    • Release Notes - Java SDK

      ZCRMSDK -VERSION 1.0.6  Downloadable JAR file  You can download the jar file for the version1.0.6 of Java SDKs at the end of this page.  Install command - Maven:(in pom.xml)  <repositories>        <repository>              ...
    • Responses & Exceptions - Java SDK

      APIResponse, BulkAPIResponse and FileAPIResponse are the wrapper objects for Zoho CRM APIs’ responses. All API calling methods would return one of these three objects. A method-seeking entity would return APIResponse object, whereas a method-seeking ...
    • 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 ...