Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
claudiapacheco
Product and Topic Expert
Product and Topic Expert

The SMP 3.0 OData SDK SP06 for Android introduced the concept of technical cache in the online store (OnlineODataStore). The technical cache stores the response of a GET request in the device. It is read-only, in consequence CREATE, UPDATE and DELETE requests would fail if the device is out of coverage.


The Technical cache is disabled by default. It is up to the application developer to use this feature, for example, to improve user experience.


Four (4) steps are required to use the technical cache:


1. Initialize Online Store with OnlineStoreOptions

The OnlineStoreOptions contains configuration information for the online store. In order to enable the Technical cache you need to set the useCache property to true and assign a cache encryption key (cacheEncryptionKey) to encrypt/decrypt cache persistent store.

The memory size of the device limits the technical cache size but it has a mechanism to remove older items in case the data exceeds the cache size. In the OnlineStoreOptions the following optional attributes can be used to configure the maximum cache size in kBytes (maximumCacheSize – default: 16384 kBytes) and percentage of remaining items size in the cache when the older items are removed (cacheCleanupTreshold – default: 60%). A cacheCleanupTreshold of 60% means that 40% of the cache data will be removed.


Code Snippets - How to enable technical cache

//Options to enable Technical Cache

OnlineStoreOptions onlineOptions = new OnlineStoreOptions();

onlineOptions.useCache = true;

onlineOptions.cacheEncryptionKey = "secret";

                  

//Method to open a new online store asynchronously

OnlineODataStore.open(context, endpointURL, httpConversationManager, openListener, onlineOptions);


2.  Send a GET request asynchronously

The client app must send the GET requests through the asynchronous read methods because the content of the technical cache will be return in the ODataRequestListener. For example, application developers can use any of the following read methods:

  • scheduleReadEntity(ODataEntity entity, ODataRequestListener listener, Map<String,String> options)

        Scheduling method for reading an Entity

  • scheduleReadEntity(String resourcePath, ODataRequestListener listener, Map<String,String>  options)

        Scheduling method for reading an Entity

  • scheduleReadEntitySet(String resourcePath, ODataRequestListener listener, Map<String,String>  options)

        Scheduling method for reading an Entity set

3. Implement the callback method requestCacheResponse in the ODataRequestListener

In each request the online store notifies the application about the cached response within the request listener through the requestCacheResponse callback


The callback sequence for requests is represented in the following diagram:

Code Snippets - How to get data from technical cache

@Override

public void requestCacheResponse(ODataRequestExecution request) {

ODataProperty property;

ODataPropMap properties;

//Verify request’s response is not null. Request is always not null

if (request.getResponse() != null) {

       //Parse the response

       ODataResponseSingle response = (ODataResponseSingle) request.getResponse();

       if (response!=null){

              //Get the response payload

              ODataEntitySet feed = (ODataEntitySet) response.getPayload();

              if (feed!=null){

                //Get the list of ODataEntity

                List<ODataEntity> entities = feed.getEntities();

                           //Loop to retrieve the information from the response

                           for (ODataEntity entity: entities){

                            //Obtain the properties you want to display in the screen

                      properties = entity.getProperties();

                      property = properties.get(<property-name>);

                }

                //TODO - Send content to the screen

         }

    }

}

}


and last but not least,


4. include the following libraries and resources

The following libraries should be imported under libs folder

    • AfariaSLL.jar
    • ClientHubSLL
    • ClientLog.jar
    • Common.jar
    • Connectivity.jar
    • CoreServices.jar
    • DataVaultLib.jar
    • guava.jar
    • HttpConvAuthFlows.jar
    • HttpConversation.jar
    • maflogger.jar
    • maflogoncore.jar
    • maflogonui.jar
    • mafuicomponents.jar
    • mafsettingscreen.jar
    • MobilePlace.jar
    • ODataAPI.jar
    • odataoffline.jar
    • ODataOnline.jar
    • perflib.jar
    • Request.jar
    • sap-e2etrace.jar
    • simple-xml.jar
    • SupportabilityFacade.jar
    • XscriptParser.jar

2. The following resources should be imported under libs/armeabi folder

    • libdatabase_sqlcipher.so
    • libsqlcipher_android.so
    • libstlport_shared.so

You can find the .jar and .so files in your OData SDK installation folder:

  • <Client SDK dir>\NativeSDK\ODataFramework\Android\libraries
  • <Client SDK dir>\NativeSDK\MAFReuse\Android\libraries
  • <Client SDK dir>\NativeSDK\ODataFramework\Android\libraries\armeabi

Hope this helps

Claudia



10 Comments