Skip to content

Proxy Classes

Generated proxy classes are convenience classes that leverage the Dynamic API. It is possible to use only Dynamic API without any generated proxy classes enabling properly written application to respond to compatible changes in the data model. However, a truly flexible application likely requires loadable metadata to drive UI, 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 lead to less code.

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 Cloud Platform 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 an 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 entire collection

1
2
// OData Query: /Events
List<Event> events = eventService.getEvents();
1
2
// OData Query: /Events
val events = eventService.events

Retrieving entities that satisfy the condition of the data query

1
2
3
4
// OData Query: /Events?$filter=…
// Construct an DataQuery instance to do filtering
DataQuery query = new DataQuery().filter(...);
List<Event> events = eventService.getEvents(query);
1
2
3
// OData Query: /Events?$filter=…
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 just a convenience method over the get collection methods when filtering with a key or a condition that only returns one instance. Note that if the query returns either no result or more than one result, an exception is thrown.

1
2
3
4
// OData: /Events(1000L)
// Construct a DataQuery instance to specify the key of the instance to retrieve
DataQuery query = ;
Event event = eventService.getEvent(query);
1
2
3
4
// 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.

1
Long count = eventService.getSessionAttendeesCount(999L);
1
val count = eventService.getSessionAttendeesCount(999L)