Skip to content

Using Client-only Entities

The client-only entities feature is introduced in SAP BTP SDK for Android 7.0 and SAP BTP SDK for iOS 9.2.

Using Client-only Models for SAP SDK

  1. Extend the back-end metadata with client-only models. Refer to Client-only metadata definition for detailed instructions.

  2. Generate proxy class.

    The option "-parser:RETAIN_ORIGINAL_TEXT" is required to support client-only models.

    • For SAP BTP SDK for Android, the -parser:RETAIN_ORIGINAL_TEXT option can be added to the additional parameters of OData gradle plugin for the proxy class generation.
    odata {
        verbose true
        services {
            //connection id: com.sap.edm.sampleservice.v2
            espmcontainer {
                schemaFile file("src/main/res/raw/com_sap_edm_sampleservice_v2.xml")
                packageName "com.sap.cloud.android.odata.espmcontainer"
                serviceClass "ESPMContainer"
                additionalParameters "-parser:RETAIN_ORIGINAL_TEXT"
            }
    }
    }
    

    Refer to Creating Apps From Scratch for detailed information on the proxy class generator.

    • For SAP BTP SDK for iOS, the -parser:RETAIN_ORIGINAL_TEXT option can be added to the command line directly for the proxy class generator.
    ./sapcpsdk-proxygenerator -m sampleservicewithclientonlymodel.xml -d ProxyClasses -offline -parser:RETAIN_ORIGINAL_TEXT
    

    Refer to Proxy Class Generator for instructions on installing the sapcpsdk-proxygenerator command line tool on macOS.

    Note

    Select the Supports client only entities checkbox in the SAP BTP SDK Assistant for iOS to enable the -parser:RETAIN_ORIGINAL_TEXT option for the generated proxy classes.

  3. Enable the client-only metadata support for Offline OData.

    OfflineODataParameters parameters = new OfflineODataParameters();
    parameters.setEnableClientOnlyMetadata(true);
    
    var offlineODataParameters = OfflineODataParameters().apply {
        isEnableClientOnlyMetadata = true
    }
    
    let offlineParameters = OfflineODataParameters()
    offlineParameters.enableClientOnlyMetadata = true
    
  4. Read and write client-only entities using existing OData APIs. You read and write client-only entities the same as reading and writing any other entity. The client-only entities are persisted into the client database. Here is an example of accessing the client-only entity set defined in the client-only metadata.

    ConfigItem configItem = new ConfigItem();
    configItem.setId(1);
    configItem.setKey_("someConfigKey");
    configItem.setValue("someConfigValue");
    // create client-only entity
    eSPMContainer.createEntity(configItem);
    
    // read client-only entity
    ConfigItem item1 = eSPMContainer.getConfigItemWithKey(1);
    
    item1.setValue("updatedValue");
    // update client-only entity
    eSPMContainer.updateEntity(item1);
    
    // delete client-only entity
    eSPMContainer.deleteEntity(item1);
    
    var configItem = ConfigItem().apply {
            id = 1
            key_ = "someConfigKey"
            value = "someConfigValue"
    }
    // create client-only entity
    eSPMContainer.createEntity(configItem)
    
    // read client-only entity
    var item1 = eSPMContainer.getConfigItemWithKey(1)
    
    // update client-only entity
    item1.value = "updatedValue"
    eSPMContainer.updateEntity(item1)
    
    // delete client-only entity
    eSPMContainer.deleteEntity(item1)
    
    let configItem : ConfigItem = ConfigItem()
    configItem.id = 1
    configItem.key_ = "someConfigKey"
    configItem.value = "someConfigValue"
    
    // create client-only entity
    eSPMContainer.createEntity(configItem)
    
    // read client-only entity
    let item1 = eSPMContainer.fetchConfigItemWithKey(id: 1)
    
    // update client-only entity
    item1.value = "updatedValue"
    eSPMContainer.updateEntity(item1)
    
    // delete client-only entity
    eSPMContainer.deleteEntity(item1)
    

Last update: June 15, 2023