public class DataQuery
extends java.lang.Object
Encapsulates an OData query request. A query can be defined by setting query properties, or by calling query functions which provide a fluent interface.
public void dataQueryExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.dataQueryExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .filter(Customer.address.toLower().contains("king")) .orderBy(Customer.companyName); List<Customer> customers = service.getCustomers(query); this.showCustomers(customers); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:89:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.dataQueryExample"); } }
public void dataQueryExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.dataQueryExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property customerIDProperty = customerEntityType.getProperty("CustomerID"); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); Property addressProperty = customerEntityType.getProperty("Address"); DataQuery query = new DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).filter(addressProperty.toLower() .contains("king")) .orderBy(companyNameProperty); EntityValueList customers = service.executeQuery(query) .getEntityList(); this.showCustomers(customers); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:101:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.dataQueryExample"); } }
Constructor and Description |
---|
DataQuery() |
Modifier and Type | Method and Description |
---|---|
DataQuery |
aggregate(AggregateValue... items)
Adds aggregate transformation items (to
DataQuery.transformValues ) for transforming the result of a query sent to an entity set. |
DataQuery |
bind(DataValue value)
Bind a value before
DataQuery.invoke of a bound action/function. |
void |
check()
Check if this query is properly configured from the client's perspective.
|
DataQuery |
count()
Set
DataQuery.countOnly to true to request only the number of matching query results. |
DataQuery |
custom(java.lang.String name,
java.lang.String value)
Add a custom option to
DataQuery.customOptions . |
DataQuery |
expand(PropertyPath... items)
Add properties (to
DataQuery.expandItems ) for expanding from the target entity. |
StringSet |
expandedProperties()
Return the names of all properties expanded by this query.
|
boolean |
expandsProperty(Property property)
Return
true if this query expands property from the target entity. |
DataQuery |
expandWithQuery(PropertyPath item,
DataQuery query)
Add a property with a nested query to
DataQuery.expandItems . |
DataQuery |
filter(QueryFilter test)
Modify
DataQuery.queryFilter to be and'ed with test (or set to test if DataQuery.queryFilter was null ). |
DataQuery |
from(EntitySet entitySet)
Set the
DataQuery.entitySet property to identify this query's target entity set. |
DataQuery |
fromDefault(EntitySet entitySet)
Set the
DataQuery.entitySet property to identify this query's target entity set, but only if the DataQuery.entitySet property wasn't previously set. |
DataValueMap |
getAliasValues()
(nullable) Parameter alias values.
|
boolean |
getAllSelected()
true if all properties are selected (using "*"). |
boolean |
getCountInline()
If
true , the service should return the total number of available results as an inline count in the result list. |
boolean |
getCountOnly()
If
true , the service should return only the number of available results matching the query. |
StringMap |
getCustomOptions()
(nullable) Custom query options.
|
java.lang.Integer |
getDataFormat()
(nullable) The data format for this query's result.
|
boolean |
getDeltaResponse()
If
true , the client should use delta parsing of the response. |
GlobalDateTime |
getDeltaTime()
(nullable) The delta time (
DataQuery.deltaToken as UTC date/time). |
java.lang.String |
getDeltaToken()
(nullable) The delta token for use in change tracking.
|
StructureType |
getDerivedType()
(nullable) Derived type for limiting query results.
|
EntityKey |
getEntityKey()
(nullable) The entity key for this query.
|
EntitySet |
getEntitySet()
(nullable) The entity set expected for the result of this query.
|
EntityType |
getEntityType()
(nullable) The entity type expected for the result of this query.
|
ExpandItemList |
getExpandItems()
(nullable) The properties to expand from target entities.
|
boolean |
getExpectSingle()
Set to
true if a single result is expected. |
GroupTransform |
getGroupTransform()
(nullable) A group transformation item set through groupBy method
|
java.lang.Object |
getInternalData()
For internal use only.
|
boolean |
getKeySelected()
true if all key properties should be selected. |
DataMethodCall |
getMethodCall()
(nullable) The method call for this query.
|
java.lang.Integer |
getPageSize()
(nullable) The maximum number of results per page.
|
DataPath |
getPropertyPath()
(nullable) Property path for accessing individual properties of an entity.
|
QueryFilter |
getQueryFilter()
(nullable) The filter criteria for the target entities.
|
java.lang.String |
getQueryString()
(nullable) The query string for this query.
|
java.lang.String |
getRequestPath()
(nullable) The request path for this query.
|
java.lang.String |
getSearchText()
(nullable) The search text to locate in the target entities.
|
SelectItemList |
getSelectItems()
(nullable) The properties to select from target entities.
|
java.lang.Integer |
getSkipCount()
(nullable) The number of initial results to skip.
|
java.lang.String |
getSkipToken()
(nullable) The skip token for use in server-driven paging.
|
SortItemList |
getSortItems()
(nullable) The sort criteria for the target entities.
|
boolean |
getStreamResponse()
If
true , the client should use streamed parsing of the response. |
int |
getSystemFlags()
For internal use only.
|
java.lang.Integer |
getTopCount()
(nullable) The number of initial results to return.
|
boolean |
getTrackChanges()
Does the client want the server to track changes?
|
TransformValueList |
getTransformValues()
(nullable) The OData transformation items as described in OData Data Aggregation.
|
java.lang.String |
getUrl()
(nullable) The relative URL for this query; a combination of
DataQuery.requestPath and DataQuery.queryString if either is non-null , or null if the URL is intended to be derived from other properties. |
DataQuery |
groupBy(PropertyPath... items)
Adds a group transformation item to the DataQuery with the property paths given in the parameter list.
|
DataQuery |
inlineCount()
Set
DataQuery.countInline to true to request an inline count in the server's response. |
DataQuery |
invoke(DataMethod method)
|
DataQuery |
invoke(DataMethod method,
ParameterList parameters)
Set
DataQuery.methodCall to associate this query with an action/function invocation. |
DataQuery |
load(EntityValue entity)
|
DataQuery |
load(EntityValue entity,
PropertyPath path)
Set
DataQuery.entitySet and DataQuery.entityKey to configure this query to load an existing entity. |
DataQuery |
orderBy(QueryValue value)
|
DataQuery |
orderBy(QueryValue value,
SortOrder order)
Add to
DataQuery.sortItems a value for result ordering. |
DataQuery |
page(int size)
Set
DataQuery.pageSize to specify the page-size for server-driven paging of results. |
DataQuery |
path(DataPath target)
Set
DataQuery.propertyPath to identify this query's target path. |
DataQuery |
property(Property target)
Set
DataQuery.propertyPath to identify this query's target property. |
DataQuery |
search(java.lang.String text)
Set
DataQuery.searchText for free-text searching. |
DataQuery |
select(PropertyPath... items)
Add properties (to
DataQuery.selectItems ) for selecting from the target entity. |
DataQuery |
selectAll()
Set
DataQuery.allSelected to true . |
DataQuery |
selectKey()
Set
DataQuery.keySelected to true . |
boolean |
selectsProperty(Property property)
Return
true if this query selects property from the target entity. |
void |
setAliasValues(DataValueMap value)
Parameter alias values.
|
void |
setAllSelected(boolean value)
true if all properties are selected (using "*"). |
void |
setCountInline(boolean value)
If
true , the service should return the total number of available results as an inline count in the result list. |
void |
setCountOnly(boolean value)
If
true , the service should return only the number of available results matching the query. |
void |
setCustomOptions(StringMap value)
Custom query options.
|
void |
setDataFormat(java.lang.Integer value)
The data format for this query's result.
|
void |
setDeltaResponse(boolean value)
If
true , the client should use delta parsing of the response. |
void |
setDeltaTime(GlobalDateTime value)
The delta time (
DataQuery.deltaToken as UTC date/time). |
void |
setDeltaToken(java.lang.String value)
The delta token for use in change tracking.
|
void |
setDerivedType(StructureType value)
Derived type for limiting query results.
|
void |
setEntityKey(EntityKey value)
The entity key for this query.
|
void |
setEntitySet(EntitySet value)
The entity set expected for the result of this query.
|
void |
setEntityType(EntityType value)
The entity type expected for the result of this query.
|
void |
setExpandItems(ExpandItemList value)
The properties to expand from target entities.
|
void |
setExpectSingle(boolean value)
Set to
true if a single result is expected. |
void |
setGroupTransform(GroupTransform value)
A group transformation item set through groupBy method
|
void |
setInternalData(java.lang.Object value)
For internal use only.
|
void |
setKeySelected(boolean value)
true if all key properties should be selected. |
void |
setMethodCall(DataMethodCall value)
The method call for this query.
|
void |
setPageSize(java.lang.Integer value)
The maximum number of results per page.
|
void |
setPropertyPath(DataPath value)
Property path for accessing individual properties of an entity.
|
void |
setQueryFilter(QueryFilter value)
The filter criteria for the target entities.
|
void |
setQueryString(java.lang.String value)
The query string for this query.
|
void |
setRequestPath(java.lang.String value)
The request path for this query.
|
void |
setSearchText(java.lang.String value)
The search text to locate in the target entities.
|
void |
setSelectItems(SelectItemList value)
The properties to select from target entities.
|
void |
setSkipCount(java.lang.Integer value)
The number of initial results to skip.
|
void |
setSkipToken(java.lang.String value)
The skip token for use in server-driven paging.
|
void |
setSortItems(SortItemList value)
The sort criteria for the target entities.
|
void |
setStreamResponse(boolean value)
If
true , the client should use streamed parsing of the response. |
void |
setSystemFlags(int value)
For internal use only.
|
void |
setTopCount(java.lang.Integer value)
The number of initial results to return.
|
void |
setTrackChanges(boolean value)
Does the client want the server to track changes?
|
void |
setTransformValues(TransformValueList value)
The OData transformation items as described in OData Data Aggregation.
|
void |
setUrl(java.lang.String value)
The relative URL for this query; a combination of
DataQuery.requestPath and DataQuery.queryString if either is non-null , or null if the URL is intended to be derived from other properties. |
DataQuery |
skip(int count)
Set
DataQuery.skipCount to specify the number of initial results to return. |
StringSet |
sortedByProperties()
Return the names of all properties used for sorting by this query.
|
DataQuery |
stream()
Set
DataQuery.streamResponse to true to request streamed response processing. |
DataQuery |
thenBy(QueryValue value)
|
DataQuery |
thenBy(QueryValue value,
SortOrder order)
Add to
DataQuery.sortItems a value for result ordering. |
DataQuery |
top(int count)
Set
DataQuery.topCount to specify the maximum number of results to return. |
java.lang.String |
toString() |
DataQuery |
transform(TransformValue... items)
Adds transformation items (to
DataQuery.transformValues ) for transforming the result of a query sent to an entity set. |
DataQuery |
where(QueryFilter test)
This function is an alias for
DataQuery.filter . |
DataQuery |
withChangeTracking()
|
DataQuery |
withChangeTracking(java.lang.String deltaLink)
|
DataQuery |
withKey(EntityKey key)
Set
DataQuery.entityKey to locate an entity by its primary key. |
DataQuery |
withType(StructureType type)
Set
DataQuery.derivedType to limit results to a derived complex/entity type. |
DataQuery |
withURL(java.lang.String url)
Set
DataQuery.url . |
public DataQuery aggregate(AggregateValue... items)
Adds aggregate transformation items (to DataQuery.transformValues
) for transforming the result of a query sent to an entity set.
This method is only for adding aggregate transformation items (in contrast to 'transform' method) for readibility purposes.
public void aggregationExample() { DataService service = this.getService(); EntitySet employeeEntitySet = service.getEntitySet("Employees"); EntityType employeeEntityType = employeeEntitySet.getEntityType(); Property ordersProperty = employeeEntityType.getProperty("Orders"); Property orderDetails = ordersProperty.getEntityType() .getProperty("Order_Details"); Property ordersQuantity = orderDetails.getEntityType() .getProperty("Quantity"); DataQuery query = new DataQuery(); AggregateValue aggregateTransform = ordersProperty.path(ordersQuantity) .sum("SumQuantity"); query.aggregate(aggregateTransform); this.testApplyQueryResult(query, "SumQuantity"); DataQuery queryCount = new DataQuery(); AggregateValue countAggregate = AggregateValue.count("AllEmployees"); queryCount.aggregate(countAggregate); this.testApplyQueryResult(queryCount, null); }
public void aggregationExample() { DataQuery query = new DataQuery(); AggregateValue aggregateTransform = Employee.orders.path(Order.orderDetails) .path(OrderDetail.quantity).sum("SumQuantity"); query.aggregate(aggregateTransform); this.testApplyQueryResult(query, "SumQuantity"); DataQuery queryCount = new DataQuery(); AggregateValue countAggregate = AggregateValue.count("AllEmployees"); queryCount.aggregate(countAggregate); this.testApplyQueryResult(queryCount, null); }
items
- The items to be added.public DataQuery bind(DataValue value)
Bind a value before DataQuery.invoke
of a bound action/function.
value
- (nullable) The value to be bound. Note: currently, only binding to an EntityValue
is supported.public void check()
Check if this query is properly configured from the client's perspective. Note: This does not guarantee that the server will be able to execute it.
DataQueryException
if the query is definitely not valid.
public DataQuery count()
Set DataQuery.countOnly
to true
to request only the number of matching query results.
public void navigationCountExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.navigationCountExample"); { NorthwindService service = this.getService(); Customer customer = service.getCustomer(new DataQuery() .expand(Customer.orders).top(1)); List<Order> orders = customer.getOrders(); DataQuery query = new DataQuery().load(customer, Customer.orders) .count(); long count = service.executeQuery(query).getCount(); assert count == ((long)orders.size()); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:314:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.navigationCountExample"); } }
public void collectionCountExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.collectionCountExample"); { NorthwindService service = this.getService(); List<Customer> customers = service.getCustomers(); DataQuery query = new DataQuery() .from(NorthwindServiceMetadata.EntitySets.customers).count(); long count = service.executeQuery(query).getCount(); assert count == ((long)customers.size()); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:292:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.collectionCountExample"); } }
public void collectionCountExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.collectionCountExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityValueList customers = service.executeQuery(new DataQuery() .from(customersEntitySet)) .getEntityList(); DataQuery query = new DataQuery().from(customersEntitySet).count(); long count = service.executeQuery(query).getCount(); assert count == ((long)customers.length()); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:308:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.collectionCountExample"); } }
public void navigationCountExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.navigationCountExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property ordersProperty = customerEntityType.getProperty("Orders"); EntityValue customer = service.executeQuery(new DataQuery() .from(customersEntitySet).expand(ordersProperty).top(1)) .getEntityList().first(); EntityValueList orders = ordersProperty.getEntityList(customer); DataQuery query = new DataQuery().load(customer, ordersProperty) .count(); long count = service.executeQuery(query).getCount(); assert count == ((long)orders.length()); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:332:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.navigationCountExample"); } }
public DataQuery custom(java.lang.String name, java.lang.String value)
Add a custom option to DataQuery.customOptions
.
name
- Option name.value
- Option value.public DataQuery expand(PropertyPath... items)
Add properties (to DataQuery.expandItems
) for expanding from the target entity.
public void expandExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.expandExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .filter(Customer.customerID.equal("ALFKI") .or(Customer.customerID.equal("ANATR"))) .expand(Customer.orders).orderBy(Customer.companyName); List<Customer> customers = service.getCustomers(query); int countOrders = 0; for (Customer customer : customers) { this.showCustomer(customer); List<Order> orders = customer.getOrders(); for (Order order : orders) { int orderID = order.getOrderID(); Example.show(" Order ", Example.formatInt(orderID)); countOrders++; } } assert countOrders > 0; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:507:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.expandExample"); } }
public void expandExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.expandExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property customerIDProperty = customerEntityType.getProperty("CustomerID"); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); Property ordersProperty = customerEntityType.getProperty("Orders"); Property orderIDProperty = ordersProperty.getItemEntityType() .getProperty("OrderID"); DataQuery query = new DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).expand(ordersProperty) .filter(customerIDProperty.equal("ALFKI") .or(customerIDProperty.equal("ANATR"))) .orderBy(companyNameProperty); EntityValueList customers = service.executeQuery(query) .getEntityList(); int countOrders = 0; for (EntityValue customer : customers) { this.showCustomer(customer); EntityValueList orders = ordersProperty.getEntityList(customer); for (EntityValue order : orders) { int orderID = orderIDProperty.getInt(order); Example.show(" Order ", Example.formatInt(orderID)); countOrders++; } } assert countOrders > 0; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:576:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.expandExample"); } }
items
- The items to be expanded.public DataQuery expandWithQuery(PropertyPath item, DataQuery query)
Add a property with a nested query to DataQuery.expandItems
.
public void expandWithQueryExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.expandWithQueryExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .filter(Customer.customerID.equal("ALFKI") .or(Customer.customerID.equal("ANATR"))) .expandWithQuery(Customer.orders, new DataQuery() .select(Order.orderID) .expandWithQuery(Order.orderDetails, new DataQuery().select(OrderDetail.quantity, OrderDetail.unitPrice))) .orderBy(Customer.companyName); List<Customer> customers = service.getCustomers(query); int countDetails = 0; for (Customer customer : customers) { this.showCustomer(customer); List<Order> orders = customer.getOrders(); for (Order order : orders) { int orderID = order.getOrderID(); java.math.BigDecimal totalPrice = NorthwindProxyClient.DECIMAL_ZERO; for (OrderDetail orderDetail : order.getOrderDetails()) { totalPrice = DecimalOperator.add(totalPrice, DecimalOperator.multiply(DecimalFunction.fromShort(orderDetail.getQuantity()), orderDetail.getUnitPrice())); countDetails++; } Example.show("Order ", Example.formatInt(orderID), ": total price ", Example.formatDecimal(totalPrice)); } } assert countDetails > 0; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:532:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.expandWithQueryExample"); } }
public void expandWithQueryExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.expandWithQueryExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property customerIDProperty = customerEntityType.getProperty("CustomerID"); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); Property ordersProperty = customerEntityType.getProperty("Orders"); Property orderIDProperty = ordersProperty.getItemEntityType() .getProperty("OrderID"); Property orderDetailsProperty = ordersProperty.getItemEntityType() .getProperty("Order_Details"); Property quantityProperty = orderDetailsProperty.getItemEntityType() .getProperty("Quantity"); Property unitPriceProperty = orderDetailsProperty.getItemEntityType() .getProperty("UnitPrice"); DataQuery query = new DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet) .filter(customerIDProperty.equal("ALFKI") .or(customerIDProperty.equal("ANATR"))) .expandWithQuery(ordersProperty, new DataQuery() .select(orderIDProperty) .expandWithQuery(orderDetailsProperty, new DataQuery().select(quantityProperty, unitPriceProperty))) .orderBy(companyNameProperty); EntityValueList customers = service.executeQuery(query) .getEntityList(); for (EntityValue customer : customers) { this.showCustomer(customer); EntityValueList orders = ordersProperty.getEntityList(customer); for (EntityValue order : orders) { int orderID = orderIDProperty.getInt(order); java.math.BigDecimal totalPrice = NorthwindClient.DECIMAL_ZERO; for (EntityValue orderDetail : orderDetailsProperty.getEntityList(order)) { short quantity = quantityProperty.getShort(orderDetail); java.math.BigDecimal unitPrice = unitPriceProperty.getDecimal(orderDetail); totalPrice = DecimalOperator.add(totalPrice, DecimalOperator.multiply(DecimalFunction.fromShort(quantity), unitPrice)); } Example.show("Order ", Example.formatInt(orderID), ": total price ", Example.formatDecimal(totalPrice)); } } } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:609:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.expandWithQueryExample"); } }
item
- Item to be expanded.query
- Query to control expansion.public StringSet expandedProperties()
Return the names of all properties expanded by this query.
public boolean expandsProperty(Property property)
Return true
if this query expands property
from the target entity.
property
- Property to check for.true
if this query expands property
from the target entity.public DataQuery filter(QueryFilter test)
Modify DataQuery.queryFilter
to be and'ed with test
(or set to test
if DataQuery.queryFilter
was null
).
public void queryWithFilterExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.queryWithFilterExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .filter(Customer.country.equal("Germany") .and(Customer.contactName.greaterEqual("N"))); List<Customer> customers = service.getCustomers(query); this.showCustomers(customers); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:325:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.queryWithFilterExample"); } }
public void filterByDateExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.filterByDateExample"); { NorthwindService service = this.getService(); GlobalDateTime oneWeekAgo = GlobalDateTime.now().plusDays(-7); DataQuery query = new DataQuery() .filter(Order.orderDate.greaterThan(oneWeekAgo)); List<Order> orders = service.getOrders(query); this.showOrders(orders); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:342:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.filterByDateExample"); } }
public void filterByEnumExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.TrippinProxyClient.filterByEnumExample"); { TrippinService service = this.getService(); DataQuery query = new DataQuery() .filter(TrippinPerson.gender.equal(TrippinServiceMetadata.EnumValues.TrippinPersonGender.female)); // Alternate syntax using convenience enumValue: // DataQuery query = new DataQuery().filter(TrippinPerson.gender.equal(TrippinPersonGender.FEMALE.enumValue())) List<TrippinPerson> people = service.getPeople(query); this.showPeople(people); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.TrippinProxyClient.xs:37:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.TrippinProxyClient.filterByEnumExample"); } }
public void queryWithFilterExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.queryWithFilterExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property customerIDProperty = customerEntityType.getProperty("CustomerID"); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); Property countryProperty = customerEntityType.getProperty("Country"); DataQuery query = new DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet) .filter(countryProperty.equal("Germany") .and(contactNameProperty.greaterEqual("N"))); EntityValueList customers = service.executeQuery(query) .getEntityList(); this.showCustomers(customers); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:346:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.queryWithFilterExample"); } }
public void filterByDateExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.filterByDateExample"); { DataService service = this.getService(); EntitySet ordersEntitySet = service.getEntitySet("Orders"); EntityType orderEntityType = ordersEntitySet.getEntityType(); Property orderDateProperty = orderEntityType.getProperty("OrderDate"); GlobalDateTime oneWeekAgo = GlobalDateTime.now().plusDays(-7); DataQuery query = new DataQuery().from(ordersEntitySet) .filter(orderDateProperty.greaterThan(oneWeekAgo)); EntityValueList orders = service.executeQuery(query) .getEntityList(); this.showOrders(orders); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:371:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.filterByDateExample"); } }
public void filterByEnumExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.TrippinClient.filterByEnumExample"); { DataService service = this.getService(); EntitySet peopleEntitySet = service.getEntitySet("People"); EntityType personEntityType = peopleEntitySet.getEntityType(); Property genderProperty = personEntityType.getProperty("Gender"); EnumType genderEnumType = service.getMetadata() .getEnumType("Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender"); EnumValue female = genderEnumType.getMember("Female"); DataQuery query = new DataQuery().from(peopleEntitySet) .filter(genderProperty.equal(female)); EntityValueList people = service.executeQuery(query) .getEntityList(); this.showPeople(people); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.TrippinClient.xs:37:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.TrippinClient.filterByEnumExample"); } }
test
- The query filter.public DataQuery from(EntitySet entitySet)
Set the DataQuery.entitySet
property to identify this query's target entity set.
public void fromExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.fromExample"); { NorthwindService service = this.getService(); List<Customer> customers = service.getCustomers(); for (Customer customer : customers) { this.showCustomer(customer); } } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:207:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.fromExample"); } }
public void fromExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.fromExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); DataQuery query = new DataQuery().from(customersEntitySet); EntityValueList customers = service.executeQuery(query) .getEntityList(); for (EntityValue customer : customers) { this.showCustomer(customer); } } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:206:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.fromExample"); } }
entitySet
- The target entity set.public DataQuery fromDefault(EntitySet entitySet)
Set the DataQuery.entitySet
property to identify this query's target entity set, but only if the DataQuery.entitySet
property wasn't previously set.
This function is intended for use by generated proxy classes.
entitySet
- The target entity set.public DataValueMap getAliasValues()
(nullable) Parameter alias values.
public boolean getAllSelected()
true
if all properties are selected (using "*").
public boolean getCountInline()
If true
, the service should return the total number of available results as an inline count in the result list.
public boolean getCountOnly()
If true
, the service should return only the number of available results matching the query.
public StringMap getCustomOptions()
(nullable) Custom query options.
public java.lang.Integer getDataFormat()
(nullable) The data format for this query's result.
public boolean getDeltaResponse()
If true
, the client should use delta parsing of the response.
public GlobalDateTime getDeltaTime()
(nullable) The delta time (DataQuery.deltaToken
as UTC date/time).
public java.lang.String getDeltaToken()
(nullable) The delta token for use in change tracking.
public StructureType getDerivedType()
(nullable) Derived type for limiting query results.
public EntityKey getEntityKey()
(nullable) The entity key for this query.
If specified, then DataQuery.entitySet
should also be specified.
public EntitySet getEntitySet()
(nullable) The entity set expected for the result of this query.
To execute a query, either this must be non-null
, or DataQuery.methodCall
must be non-null
.
public EntityType getEntityType()
(nullable) The entity type expected for the result of this query.
Can be used for inference of DataQuery.entitySet
, if only one entity set in the data model uses this type.
public ExpandItemList getExpandItems()
(nullable) The properties to expand from target entities.
public boolean getExpectSingle()
Set to true
if a single result is expected.
This may be required if url
has been explicitly set.
public GroupTransform getGroupTransform()
(nullable) A group transformation item set through groupBy method
public java.lang.Object getInternalData()
For internal use only.
public boolean getKeySelected()
true
if all key properties should be selected.
public DataMethodCall getMethodCall()
(nullable) The method call for this query.
To execute a query, either this must be non-null
, or DataQuery.entitySet
must be non-null
.
public java.lang.Integer getPageSize()
(nullable) The maximum number of results per page.
Note that this is just a hint to the service. The service is permitted to ignore the client-requested page size.
Use DataQuery.skipCount
and DataQuery.topCount
for predictable paging.
public DataPath getPropertyPath()
(nullable) Property path for accessing individual properties of an entity.
public QueryFilter getQueryFilter()
(nullable) The filter criteria for the target entities.
public java.lang.String getQueryString()
(nullable) The query string for this query.
Intended for use by servers. Clients should use API calls (e.g. DataQuery.select
, DataQuery.expand
, DataQuery.filter
, DataQuery.orderBy
) to create query strings.
public java.lang.String getRequestPath()
(nullable) The request path for this query.
Intended for use by servers. Clients should use API calls (e.g. DataQuery.from
) to create request paths.
public java.lang.String getSearchText()
(nullable) The search text to locate in the target entities.
public SelectItemList getSelectItems()
(nullable) The properties to select from target entities.
public java.lang.Integer getSkipCount()
(nullable) The number of initial results to skip.
public java.lang.String getSkipToken()
(nullable) The skip token for use in server-driven paging.
public SortItemList getSortItems()
(nullable) The sort criteria for the target entities.
public boolean getStreamResponse()
If true
, the client should use streamed parsing of the response.
public int getSystemFlags()
For internal use only.
public java.lang.Integer getTopCount()
(nullable) The number of initial results to return.
public boolean getTrackChanges()
Does the client want the server to track changes?
public TransformValueList getTransformValues()
(nullable) The OData transformation items as described in OData Data Aggregation.
public java.lang.String getUrl()
(nullable) The relative URL for this query; a combination of DataQuery.requestPath
and DataQuery.queryString
if either is non-null
, or null
if the URL is intended to be derived from other properties.
Note: It is not recommended for clients to explicitly set the URL, except by using a URL from EntityValueList.deltaLink
or EntityValueList.nextLink
.
public DataQuery groupBy(PropertyPath... items)
Adds a group transformation item to the DataQuery with the property paths given in the parameter list. Note: If this method is called then all the transformation and aggregation items added to the query will be applied to the group transformation in the query.
public void transformationExample() { DataService service = this.getService(); EntitySet employeeEntitySet = service.getEntitySet("Employees"); EntityType employeeEntityType = employeeEntitySet.getEntityType(); Property employeeReportsToProperty = employeeEntityType.getProperty("ReportsTo"); Property employee1Property = employeeEntityType.getProperty("Employee1"); Property ordersProperty = employeeEntityType.getProperty("Orders"); Property ordersQuantity = ordersProperty.getEntityType() .getProperty("Quantity"); Property countryProperty = employeeEntityType.getProperty("Country"); DataQuery queryGroup = new DataQuery(); FilterTransform filterGroupTransform = FilterTransform.of(QueryOperator.equal(countryProperty, StringValue.of("Budapest"))); GroupTransform groupTransform = GroupTransform.groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(ordersQuantity).sum("SumQuantity")); queryGroup.transform(groupTransform); this.testApplyQueryResult(queryGroup, "SumQuantity"); DataQuery groupTransformForQuery = new DataQuery() .groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(ordersQuantity).sum("SumQuantity")) .transform(filterGroupTransform); this.testApplyQueryResult(groupTransformForQuery, "SumQuantity"); DataQuery queryTopPercent = new DataQuery(); TopTransform topPercentTransform = TopTransform.percent(((double)50), employeeReportsToProperty); queryTopPercent.transform(topPercentTransform); this.testApplyQueryResult(queryTopPercent, null); DataQuery queryExpand = new DataQuery(); ExpandTransform expandTransform = ExpandTransform.withFilter(ordersProperty, FilterTransform.of(QueryOperator.equal(employeeReportsToProperty, IntValue.of(1000)))); queryExpand.transform(expandTransform); this.testApplyQueryResult(queryExpand, null); ExpandTransform expandWithExpandTransform = ExpandTransform.withExpand(employee1Property, expandTransform); DataQuery queryExpand1 = new DataQuery(); queryExpand1.transform(expandWithExpandTransform); this.testApplyQueryResult(queryExpand1, null); }
public void transformationExample() { DataQuery queryGroup = new DataQuery(); GroupTransform groupTransform = GroupTransform.groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderDetails) .path(OrderDetail.quantity).sum("SumQuantity")); queryGroup.transform(groupTransform); this.testApplyQueryResult(queryGroup, "SumQuantity"); FilterTransform filterGroupTransform = FilterTransform.of(QueryOperator.equal(Employee.country, StringValue.of("Budapest"))); DataQuery groupTransformForQuery = new DataQuery() .groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderDetails) .path(OrderDetail.quantity).sum("SumQuantity")) .transform(filterGroupTransform); this.testApplyQueryResult(groupTransformForQuery, "SumQuantity"); DataQuery queryTopPercent = new DataQuery(); TopTransform topPercentTransform = TopTransform.percent(((double)50), Employee.reportsTo); queryTopPercent.transform(topPercentTransform); this.testApplyQueryResult(queryTopPercent, null); DataQuery queryExpand = new DataQuery(); ExpandTransform expandTransform = ExpandTransform.withFilter(Employee.orders, FilterTransform.of(QueryOperator.equal(Employee.reportsTo, IntValue.of(1000)))); queryExpand.transform(expandTransform); this.testApplyQueryResult(queryExpand, null); ExpandTransform expandWithExpandTransform = ExpandTransform.withExpand(Employee.employee1, expandTransform); DataQuery queryExpand1 = new DataQuery(); queryExpand1.transform(expandWithExpandTransform); this.testApplyQueryResult(queryExpand1, null); }
items
- The property paths to be added to the group transformation.public DataQuery inlineCount()
Set DataQuery.countInline
to true
to request an inline count in the server's response.
public void inlineCountExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.inlineCountExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .from(NorthwindServiceMetadata.EntitySets.customers).skip(20).top(10) .inlineCount(); QueryResult result = service.executeQuery(query); List<Customer> customers = Customer.list(result.getEntityList()); long count = result.getInlineCount(); assert customers.size() == 10; assert count > 10L; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:302:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.inlineCountExample"); } }
public void inlineCountExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.inlineCountExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); DataQuery query = new DataQuery().from(customersEntitySet).skip(20) .top(10).inlineCount(); QueryResult result = service.executeQuery(query); EntityValueList customers = result.getEntityList(); long count = result.getInlineCount(); assert customers.length() == 10; assert count > 10L; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:319:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.inlineCountExample"); } }
public DataQuery invoke(DataMethod method)
public DataQuery invoke(DataMethod method, ParameterList parameters)
Set DataQuery.methodCall
to associate this query with an action/function invocation.
DataQuery.bind
, for setting the binding parameter for a bound action/function.
public void invokeExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.TrippinProxyClient.invokeExample"); { TrippinService service = this.getService(); TrippinPerson person = service.getPersonWithMostFriends(); this.showPerson(person); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.TrippinProxyClient.xs:54:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.TrippinProxyClient.invokeExample"); } }
public void invokeExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.TrippinClient.invokeExample"); { DataService service = this.getService(); DataMethod functionImport = service.getDataMethod("GetPersonWithMostFriends"); DataQuery query = new DataQuery().invoke(functionImport); EntityValue person = service.executeQuery(query) .getRequiredEntity(); this.showPerson(person); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.TrippinClient.xs:56:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.TrippinClient.invokeExample"); } }
method
- Data method to be called (action or function).parameters
- Method parameters.public DataQuery load(EntityValue entity)
public DataQuery load(EntityValue entity, PropertyPath path)
Set DataQuery.entitySet
and DataQuery.entityKey
to configure this query to load an existing entity.
Equivalent to calling from(entity.entitySet).withKey(entity.entityKey)
.
entity
- The entity to be loaded.path
- (nullable) Optionally specify DataQuery.propertyPath
.public DataQuery orderBy(QueryValue value)
public DataQuery orderBy(QueryValue value, SortOrder order)
Add to DataQuery.sortItems
a value for result ordering.
public void orderByExample() { MediaService service = this.getService(); GeographyPoint avila = GeographyPoint.withLatitudeLongitude(40.6567d, -4.6812d); DataQuery query = new DataQuery().top(3) .orderBy(Artist.placeOfBirth.geoDistance(avila)); List<Artist> artists = service.getArtists(query); this.showArtists(artists); }
public void orderByExample() { DataService service = this.getService(); EntitySet artistsEntitySet = service.getEntitySet("Artists"); EntityType artistEntityType = artistsEntitySet.getEntityType(); Property placeOfBirthProperty = artistEntityType.getProperty("placeOfBirth"); GeographyPoint avila = GeographyPoint.withLatitudeLongitude(40.6567d, -4.6812d); DataQuery query = new DataQuery().top(3).from(artistsEntitySet) .orderBy(placeOfBirthProperty.geoDistance(avila)); EntityValueList artists = service.executeQuery(query).getEntityList(); this.showArtists(artists); }
value
- Value for ordering.order
- The sort order (defaults to ascending).public DataQuery page(int size)
Set DataQuery.pageSize
to specify the page-size for server-driven paging of results.
Note: the server is not required to respect this setting. But if this setting is used, the client should expect to have to follow next-links.
public void queryWithPageExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.queryWithPageExample"); { NorthwindService service = this.getService(); long expected = service.executeQuery(new DataQuery() .from(NorthwindServiceMetadata.EntitySets.customers).count()) .getCount(); int found = 0; DataQuery query = new DataQuery() .from(NorthwindServiceMetadata.EntitySets.customers).page(5); do { QueryResult result = service.executeQuery(query); List<Customer> customers = Customer.list(result.getEntityList()); this.showCustomers(customers); found += customers.size(); query = result.getNextQuery(); } while (query.getUrl() != null); assert ((long)found) == expected; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:367:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.queryWithPageExample"); } }
public void queryWithPageExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.queryWithPageExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); DataQuery query = new DataQuery().from(customersEntitySet).page(5); do { QueryResult result = service.executeQuery(query); EntityValueList customers = result.getEntityList(); this.showCustomers(customers); query = result.getNextQuery(); } while (query.getUrl() != null); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:407:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.queryWithPageExample"); } }
size
- Client-requested page size for use by server-driven paging.public DataQuery path(DataPath target)
Set DataQuery.propertyPath
to identify this query's target path.
target
- The target path.public DataQuery property(Property target)
Set DataQuery.propertyPath
to identify this query's target property.
target
- The target property.public DataQuery search(java.lang.String text)
Set DataQuery.searchText
for free-text searching.
public void searchExample() { NorthwindService service = this.getService(); DataQuery query = new DataQuery().search("Juice"); List<Product> products = service.getProducts(query); this.showProducts(products); }
public void searchExample() { DataService service = this.getService(); EntitySet productsEntitySet = service.getEntitySet("Products"); DataQuery query = new DataQuery().from(productsEntitySet).search("Juice"); EntityValueList products = service.executeQuery(query).getEntityList(); this.showProducts(products); }
text
- The search expression.public DataQuery select(PropertyPath... items)
Add properties (to DataQuery.selectItems
) for selecting from the target entity.
public void selectExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.selectExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName); List<Customer> customers = service.getCustomers(query); for (Customer customer : customers) { this.showCustomer(customer); } } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:194:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.selectExample"); } }
public void selectExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.selectExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property customerIDProperty = customerEntityType.getProperty("CustomerID"); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); DataQuery query = new DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet); EntityValueList customers = service.executeQuery(query) .getEntityList(); for (EntityValue customer : customers) { this.showCustomer(customer); } } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:187:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.selectExample"); } }
items
- The items to be selected.public DataQuery selectAll()
Set DataQuery.allSelected
to true
.
public DataQuery selectKey()
Set DataQuery.keySelected
to true
.
public boolean selectsProperty(Property property)
Return true
if this query selects property
from the target entity.
property
- Property to check for.true
if this query selects property
from the target entity.public void setAliasValues(DataValueMap value)
Parameter alias values.
public void setAllSelected(boolean value)
true
if all properties are selected (using "*").
public void setCountInline(boolean value)
If true
, the service should return the total number of available results as an inline count in the result list.
public void setCountOnly(boolean value)
If true
, the service should return only the number of available results matching the query.
public void setCustomOptions(StringMap value)
Custom query options.
public void setDataFormat(java.lang.Integer value)
The data format for this query's result.
public void setDeltaResponse(boolean value)
If true
, the client should use delta parsing of the response.
public void setDeltaTime(GlobalDateTime value)
The delta time (DataQuery.deltaToken
as UTC date/time).
public void setDeltaToken(java.lang.String value)
The delta token for use in change tracking.
public void setDerivedType(StructureType value)
Derived type for limiting query results.
public void setEntityKey(EntityKey value)
The entity key for this query.
If specified, then DataQuery.entitySet
should also be specified.
public void setEntitySet(EntitySet value)
The entity set expected for the result of this query.
To execute a query, either this must be non-null
, or DataQuery.methodCall
must be non-null
.
public void setEntityType(EntityType value)
The entity type expected for the result of this query.
Can be used for inference of DataQuery.entitySet
, if only one entity set in the data model uses this type.
public void setExpandItems(ExpandItemList value)
The properties to expand from target entities.
public void setExpectSingle(boolean value)
Set to true
if a single result is expected.
This may be required if url
has been explicitly set.
public void setGroupTransform(GroupTransform value)
A group transformation item set through groupBy method
public void setInternalData(java.lang.Object value)
For internal use only.
public void setKeySelected(boolean value)
true
if all key properties should be selected.
public void setMethodCall(DataMethodCall value)
The method call for this query.
To execute a query, either this must be non-null
, or DataQuery.entitySet
must be non-null
.
public void setPageSize(java.lang.Integer value)
The maximum number of results per page.
Note that this is just a hint to the service. The service is permitted to ignore the client-requested page size.
Use DataQuery.skipCount
and DataQuery.topCount
for predictable paging.
public void setPropertyPath(DataPath value)
Property path for accessing individual properties of an entity.
public void setQueryFilter(QueryFilter value)
The filter criteria for the target entities.
public void setQueryString(java.lang.String value)
The query string for this query.
Intended for use by servers. Clients should use API calls (e.g. DataQuery.select
, DataQuery.expand
, DataQuery.filter
, DataQuery.orderBy
) to create query strings.
public void setRequestPath(java.lang.String value)
The request path for this query.
Intended for use by servers. Clients should use API calls (e.g. DataQuery.from
) to create request paths.
public void setSearchText(java.lang.String value)
The search text to locate in the target entities.
public void setSelectItems(SelectItemList value)
The properties to select from target entities.
public void setSkipCount(java.lang.Integer value)
The number of initial results to skip.
public void setSkipToken(java.lang.String value)
The skip token for use in server-driven paging.
public void setSortItems(SortItemList value)
The sort criteria for the target entities.
public void setStreamResponse(boolean value)
If true
, the client should use streamed parsing of the response.
public void setSystemFlags(int value)
For internal use only.
public void setTopCount(java.lang.Integer value)
The number of initial results to return.
public void setTrackChanges(boolean value)
Does the client want the server to track changes?
public void setTransformValues(TransformValueList value)
The OData transformation items as described in OData Data Aggregation.
public void setUrl(java.lang.String value)
The relative URL for this query; a combination of DataQuery.requestPath
and DataQuery.queryString
if either is non-null
, or null
if the URL is intended to be derived from other properties.
Note: It is not recommended for clients to explicitly set the URL, except by using a URL from EntityValueList.deltaLink
or EntityValueList.nextLink
.
public DataQuery skip(int count)
Set DataQuery.skipCount
to specify the number of initial results to return.
public void queryWithSkipExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.queryWithSkipExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery().skip(20).top(10); List<Customer> customers = service.getCustomers(query); this.showCustomers(customers); assert customers.size() == 10; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:401:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.queryWithSkipExample"); } }
public void queryWithSkipExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.queryWithSkipExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); DataQuery query = new DataQuery().from(customersEntitySet).skip(20) .top(10); EntityValueList customers = service.executeQuery(query) .getEntityList(); this.showCustomers(customers); assert customers.length() == 10; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:439:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.queryWithSkipExample"); } }
count
- Number of initial results for query execution to skip.public StringSet sortedByProperties()
Return the names of all properties used for sorting by this query.
public DataQuery stream()
Set DataQuery.streamResponse
to true
to request streamed response processing.
public DataQuery thenBy(QueryValue value)
public DataQuery thenBy(QueryValue value, SortOrder order)
Add to DataQuery.sortItems
a value for result ordering.
This function is an alias for DataQuery.orderBy
.
By convention to improve readability when multiple ordering values are required, the first ordering value is added using orderBy
, and subsequent ordering values are added using thenBy
.
public void thenByExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.MediaProxyClient.thenByExample"); { MediaService service = this.getService(); DataQuery query = new DataQuery().orderBy(Artist.lastName) .thenBy(Artist.firstName); List<Artist> artists = service.getArtists(query); this.showArtists(artists); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.MediaProxyClient.xs:142:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.MediaProxyClient.thenByExample"); } }
public void thenByExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.MediaClient.thenByExample"); { DataService service = this.getService(); EntitySet artistsEntitySet = service.getEntitySet("Artists"); EntityType artistEntityType = artistsEntitySet.getEntityType(); Property lastNameProperty = artistEntityType.getProperty("lastName"); Property firstNameProperty = artistEntityType.getProperty("firstName"); DataQuery query = new DataQuery().from(artistsEntitySet) .orderBy(lastNameProperty).thenBy(firstNameProperty); EntityValueList artists = service.executeQuery(query) .getEntityList(); this.showArtists(artists); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.MediaClient.xs:176:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.MediaClient.thenByExample"); } }
value
- Value for ordering.order
- The sort order (defaults to ascending).public java.lang.String toString()
toString
in class java.lang.Object
public DataQuery top(int count)
Set DataQuery.topCount
to specify the maximum number of results to return.
public void queryWithTopExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.queryWithTopExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery().top(10); List<Customer> customers = service.getCustomers(query); this.showCustomers(customers); assert customers.size() == 10; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:411:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.queryWithTopExample"); } }
public void queryWithTopExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.queryWithTopExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); DataQuery query = new DataQuery().from(customersEntitySet).top(10); EntityValueList customers = service.executeQuery(query) .getEntityList(); this.showCustomers(customers); assert customers.length() == 10; } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:450:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.queryWithTopExample"); } }
count
- Maximum number of results for query execution to return.public DataQuery transform(TransformValue... items)
Adds transformation items (to DataQuery.transformValues
) for transforming the result of a query sent to an entity set.
public void transformationExample() { DataService service = this.getService(); EntitySet employeeEntitySet = service.getEntitySet("Employees"); EntityType employeeEntityType = employeeEntitySet.getEntityType(); Property employeeReportsToProperty = employeeEntityType.getProperty("ReportsTo"); Property employee1Property = employeeEntityType.getProperty("Employee1"); Property ordersProperty = employeeEntityType.getProperty("Orders"); Property ordersQuantity = ordersProperty.getEntityType() .getProperty("Quantity"); Property countryProperty = employeeEntityType.getProperty("Country"); DataQuery queryGroup = new DataQuery(); FilterTransform filterGroupTransform = FilterTransform.of(QueryOperator.equal(countryProperty, StringValue.of("Budapest"))); GroupTransform groupTransform = GroupTransform.groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(ordersQuantity).sum("SumQuantity")); queryGroup.transform(groupTransform); this.testApplyQueryResult(queryGroup, "SumQuantity"); DataQuery groupTransformForQuery = new DataQuery() .groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(ordersQuantity).sum("SumQuantity")) .transform(filterGroupTransform); this.testApplyQueryResult(groupTransformForQuery, "SumQuantity"); DataQuery queryTopPercent = new DataQuery(); TopTransform topPercentTransform = TopTransform.percent(((double)50), employeeReportsToProperty); queryTopPercent.transform(topPercentTransform); this.testApplyQueryResult(queryTopPercent, null); DataQuery queryExpand = new DataQuery(); ExpandTransform expandTransform = ExpandTransform.withFilter(ordersProperty, FilterTransform.of(QueryOperator.equal(employeeReportsToProperty, IntValue.of(1000)))); queryExpand.transform(expandTransform); this.testApplyQueryResult(queryExpand, null); ExpandTransform expandWithExpandTransform = ExpandTransform.withExpand(employee1Property, expandTransform); DataQuery queryExpand1 = new DataQuery(); queryExpand1.transform(expandWithExpandTransform); this.testApplyQueryResult(queryExpand1, null); }
public void transformationExample() { DataQuery queryGroup = new DataQuery(); GroupTransform groupTransform = GroupTransform.groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderDetails) .path(OrderDetail.quantity).sum("SumQuantity")); queryGroup.transform(groupTransform); this.testApplyQueryResult(queryGroup, "SumQuantity"); FilterTransform filterGroupTransform = FilterTransform.of(QueryOperator.equal(Employee.country, StringValue.of("Budapest"))); DataQuery groupTransformForQuery = new DataQuery() .groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderDetails) .path(OrderDetail.quantity).sum("SumQuantity")) .transform(filterGroupTransform); this.testApplyQueryResult(groupTransformForQuery, "SumQuantity"); DataQuery queryTopPercent = new DataQuery(); TopTransform topPercentTransform = TopTransform.percent(((double)50), Employee.reportsTo); queryTopPercent.transform(topPercentTransform); this.testApplyQueryResult(queryTopPercent, null); DataQuery queryExpand = new DataQuery(); ExpandTransform expandTransform = ExpandTransform.withFilter(Employee.orders, FilterTransform.of(QueryOperator.equal(Employee.reportsTo, IntValue.of(1000)))); queryExpand.transform(expandTransform); this.testApplyQueryResult(queryExpand, null); ExpandTransform expandWithExpandTransform = ExpandTransform.withExpand(Employee.employee1, expandTransform); DataQuery queryExpand1 = new DataQuery(); queryExpand1.transform(expandWithExpandTransform); this.testApplyQueryResult(queryExpand1, null); }
items
- The items to be added.public DataQuery where(QueryFilter test)
This function is an alias for DataQuery.filter
.
test
- The query filter.public DataQuery withChangeTracking()
public DataQuery withChangeTracking(java.lang.String deltaLink)
Set DataQuery.url
from deltaLink
and set DataQuery.trackChanges
to true
.
deltaLink
- (nullable) Delta link (absolute or, preferably, relative to the service root URL).public DataQuery withKey(EntityKey key)
Set DataQuery.entityKey
to locate an entity by its primary key.
public void queryWithKeyExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindProxyClient.queryWithKeyExample"); { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .withKey(Customer.key("QUEEN")); Customer customer = service.getCustomer(query); this.showCustomer(customer); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindProxyClient.xs:356:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindProxyClient.queryWithKeyExample"); } }
public void queryWithKeyExample() { try { com.sap.client.odata.v4.core.DebugConsole.traceIn("example.NorthwindClient.queryWithKeyExample"); { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property customerIDProperty = customerEntityType.getProperty("CustomerID"); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); DataQuery query = new DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet) .withKey(new EntityKey() .withProperty(customerIDProperty, StringValue.of("QUEEN"))); EntityValue customer = service.executeQuery(query) .getRequiredEntity(); this.showCustomer(customer); } } catch (java.lang.RuntimeException _tex_) { com.sap.client.odata.v4.core.Assert.error("/data/home/ppurple/xMDP/workspace/NAAS-Mobile-com.sap.odata.core.framework-OD-darwinintel64_ent_indirectshipment-darwinintel64_ent/src/main/xs/examples/example.NorthwindClient.xs:390:11", _tex_); throw _tex_; } finally { com.sap.client.odata.v4.core.DebugConsole.traceOut("example.NorthwindClient.queryWithKeyExample"); } }
key
- Entity key.public DataQuery withType(StructureType type)
Set DataQuery.derivedType
to limit results to a derived complex/entity type.
type
- Complex/entity type.public DataQuery withURL(java.lang.String url)
Set DataQuery.url
.
Note: It is not recommended for clients to explicitly set the URL, except by using a URL from EntityValueList.deltaLink
or EntityValueList.nextLink
.
url
- (nullable) Query URL (absolute or, preferably, relative to the service root URL).