Skip to content

A Comparison of Proxy Classes and Dynamic API

The following code samples are based on the Northwind OData service.

Getting an Entity List

Proxy Classes

1
2
3
4
5
6
7
8
void entityListExample() {
    DataQuery query = new DataQuery()
            .select(Customer.customerID, Customer.companyName, Customer.contactName)
            .orderBy(Customer.companyName);
    List<Customer> customers = ds.getCustomers(query);
    for (Customer customer : customers) {
        this.showCustomer(customer);
    }

Dynamic API

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
void entityListExample() {
    EntitySet s_customers = ds.getEntitySet("Customers");
    EntityType t_customer = s_customers.getEntityType();
    Property p_customerID = t_customer.getProperty("CustomerID");
    Property p_companyName = t_customer.getProperty("CompanyName");
    Property p_contactName = t_customer.getProperty("ContactName");
    DataQuery query = new DataQuery()
        .select(p_customerID, p_companyName, p_contactName)
        .from(s_customers)
        .orderBy(p_companyName);
    EntityValueList customers = ds.executeQuery(query).getEntityList();
    for (EntityValue customer : customers) {
        this.showCustomer(customer);
    }
}

Creating an Entity

Proxy Classes

1
2
3
4
5
6
7
void createEntityExample() {
    Customer customer = new Customer();
    customer.setCustomerID(GuidValue.random().toString());
    customer.setCompanyName("Enterprise Inc.");
    customer.setContactName("Jean-Luc Picard");
    ds.createEntity(customer);
}

Dynamic API

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void createEntityExample() {
    EntityType t_customer = s_customers.getEntityType();
    Property p_customerID = t_customer.getProperty("CustomerID");
    Property p_companyName = t_customer.getProperty("CompanyName");
    Property p_contactName = t_customer.getProperty("ContactName");
    EntityValue customer = EntityValue.ofType(t_customer);
    p_customerID.setString(customer, GuidValue.random().toString());
    p_companyName.setString(customer, "Enterprise Inc.");
    p_contactName.setString(customer, "Jean-Luc Picard");
    ds.createEntity(customer);
}

Updating an Entity

Proxy Classes

1
2
3
4
5
6
7
8
9
void updateEntityExample() {
    DataQuery query = new DataQuery()
        .top(1)
        .filter(Customer.contactName.equal("Jean-Luc Picard"));
    List<Customer> customers = try ds.getCustomers(query);
    Customer customer = customers.get(0);
    customer.setContactName("Beverly Crusher");
    ds.updateEntity(customer);
}

Dynamic API

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
void updateEntityExample() {
    EntitySet s_customers = ds.getEntitySet("Customers");
    EntityType t_customer = s_customers.getEntityType();
    Property p_contactName = t_customer.getProperty("ContactName");
    DataQuery query = new DataQuery()
        .top(1)
        .from(s_customers)
        .filter(p_contactName.equal("Jean-Luc Picard"));
    EntityValue customer = ds.executeQuery(query)
        .getRequiredEntity();
    p_contactName.setString(customer, "Beverly Crusher");
    ds.updateEntity(customer);
}

Deleting an Entity

Proxy Classes

1
2
3
4
5
6
7
8
9
void deleteEntityExample() {
    DataQuery query = new DataQuery()
        .top(1)
        .selectKey()
        .filter(Customer.contactName.equal("Beverly Crusher"));
    List<Customer> customers = ds.getCustomers(query);
    Customer customer = customers.get(0);
    ds.deleteEntity(customer);
}

Dynamic API

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
void deleteEntityExample() {
    EntitySet s_customers = try ds.getEntitySet("Customers");
    EntityType t_customer = s_customers.getEntityType();
    Property p_contactName = t_customer.getProperty("ContactName");
    DataQuery query = new DataQuery()
        .top(1)
        .selectKey()
        .from(s_customers)
        .filter(p_contactName.equal("Beverly Crusher"));
    EntityValue customer = ds.executeQuery(query).getRequiredEntity();
    ds.deleteEntity(customer);
}