Generated proxy classes are convenience classes that leverage the Dynamic API. It is possible to use only the Dynamic API without any generated proxy classes, enabling properly-written applications to respond to compatible changes in the data model. However, a truly flexible application likely requires loadable metadata to drive UI, the data model, and business logic. For most applications, their development assumes a prior knowledge of the Entity Data Model and in those cases, use of proxy classes offers type safety and helper methods that require less code.
The generated proxy classes consist of three main components:
A metadata class that represents the service metadata document. The service metadata is preserved within an internal class and is loaded on instantiation. The metadata class contains class variables for all entity sets, entity types, and service operations. These can be used directly as parameters to the Dynamic API.
A service class that supports retrieval of entity sets with or without a
DataQueryobject, count with and without a
DataQueryobject, and the invocation of service operations or function imports. The generated service class is a subclass of the Dynamic API
Strongly-typed entity classes for each entity type within the service metadata document. These classes simplify using the Dynamic API for complex query and CRUD operations. In addition, there are strongly-typed getter and setter methods for each property.
Generating Proxy Classes¶
You can generate proxy classes using the proxy generation Gradle plugin either within Android Studio or directly with Gradle. In addition, a proxy generator command line tool is included in the SAP BTP SDK for Android download. See Generating Proxy Classes for the steps to generate proxy classes.
Convenience Methods for the Generated Service Class¶
The generated service class has the following convenience methods:
Get Collection Methods¶
There are two getter methods for each entity set, including one with a
DataQuery instance as a parameter to build a filter condition for the data. The return is a
java.util.List of generated strongly-typed class for the entity type of the entity set. In the following sample, the variable
eventService refers to an instance of the generated service class.
Retrieving the entire collection:
// OData Query: /Events List<Event> events = eventService.getEvents();
// OData Query: /Events val events = eventService.events
Retrieving entities that satisfy the condition of the data query:
// OData Query: /Events?$filter=… // Construct a DataQuery instance to do filtering DataQuery query = new DataQuery().filter(...); List<Event> events = eventService.getEvents(query);
// OData Query: /Events?$filter=… // Construct a DataQuery instance to do filtering val query = DataQuery().filter(...) val events = eventService.getEvents(query)
Get Single Instance Method¶
There is one getter method for each entity set with a
DataQuery instance as a parameter. The return is a single instance. This is a more convenient method than using the get collection methods and filtering with a key or a condition that returns only one instance. Note that if the query returns either no result or more than one result, an exception is thrown.
// OData: /Events(1000L) // Construct a DataQuery instance to specify the key of the instance to retrieve DataQuery query = …; Event event = eventService.getEvent(query);
// OData: /Events(1000L) // Construct a DataQuery instance to specify the key of the instance to retrieve val query = ... val event = eventService.getEvent(query)
Service Operation Methods¶
For every service operation in the service metadata document, there is a corresponding method in the generated service class. Invoking a service operation is as simple as calling a method with appropriate parameters.
Long count = eventService.getSessionAttendeesCount(999L);
val count = eventService.getSessionAttendeesCount(999L)