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.
Execution of a query may result in some query properties being changed (e.g. the addition of DataQuery.expandItems
or DataQuery.selectItems
that are required for correct execution).
Thus for thread safety, a query should be used only by a single thread at a time. Preferably a new query should be created before each query execution.
DataService.executeQuery
.
public void 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); Customer__List customers = service.getCustomers(query); this.showCustomers(customers); }
public void 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); }
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. |
void |
applyKeyToFilter()
If this query has an
DataQuery.entityKey , then apply it to the DataQuery.queryFilter as additional equality conditions. |
DataQuery |
bind(BindingPath resource)
Bind a resource as the binding parameter 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 ). |
StringSet |
filteredProperties()
Return the names of all properties filtered by this query.
|
boolean |
filtersProperty(Property property)
Return
true if this query filters property from the target entity. |
DataQuery |
forAllClients()
Alter this query to apply to all clients.
|
DataQuery |
forAllTenants()
Alter this query to apply to all tenants.
|
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()
Return (nullable) Parameter alias values.
|
boolean |
getAllSelected()
Return
true if all properties are selected (using "*"). |
boolean |
getCountInline()
Return if
true , the service should return the total number of available results as an inline count in the result list. |
DataMetric |
getCountMetric()
Return (nullable) Result count metric to be used for execution of this query.
|
boolean |
getCountOnly()
Return if
true , the service should return only the number of available results matching the query. |
java.lang.String |
getCustom(java.lang.String name)
Get a custom option from
DataQuery.customOptions . |
StringMap |
getCustomOptions()
Return (nullable) Custom query options.
|
java.lang.Integer |
getDataFormat()
Return (nullable) The data format for this query's result.
|
boolean |
getDeltaResponse()
Return if
true , the client should use delta parsing of the response. |
GlobalDateTime |
getDeltaTime()
Return (nullable) The delta time (
DataQuery.deltaToken as UTC date/time). |
java.lang.String |
getDeltaToken()
Return (nullable) The delta token for use in change tracking.
|
StructureType |
getDerivedType()
Return (nullable) Derived type for limiting query results.
|
boolean |
getDistinctItems()
Return whether to select only distinct items.
|
EntityKey |
getEntityKey()
Return (nullable) The entity key for this query.
|
EntitySet |
getEntitySet()
Return (nullable) The entity set expected for the result of this query.
|
EntityType |
getEntityType()
Return (nullable) The entity type expected for the result of this query.
|
ExpandItemList |
getExpandItems()
Return (nullable) The properties to expand from target entities.
|
boolean |
getExpectSingle()
Return set to
true if a single result is expected. |
GroupTransform |
getGroupTransform()
Return (nullable) A group transformation item set through groupBy method
|
java.lang.Object |
getInternalData()
For internal use only.
|
boolean |
getKeySelected()
Return
true if all key properties should be selected. |
DataMethodCall |
getMethodCall()
Return (nullable) The method call for this query.
|
java.lang.Integer |
getPageSize()
Return (nullable) The maximum number of results per page.
|
DataPath |
getPropertyPath()
Return (nullable) Property path for accessing individual properties of an entity.
|
QueryFilter |
getQueryFilter()
Return (nullable) The filter criteria for the target entities.
|
java.lang.String |
getQueryString()
Return (nullable) The query string for this query.
|
java.lang.Object |
getRequestContext()
Return (nullable) Data context (for internal use).
|
java.lang.String |
getRequestPath()
Return (nullable) The request path for this query.
|
EntityKey |
getRequiredEntityKey()
Return the required entity key for this query.
|
EntitySet |
getRequiredEntitySet()
Return the required entity set for this query.
|
java.lang.String |
getSearchText()
Return (nullable) The search text to locate in the target entities.
|
SelectItemList |
getSelectItems()
Return (nullable) The properties to select from target entities.
|
java.lang.Integer |
getSkipCount()
Return (nullable) The number of initial results to skip.
|
java.lang.String |
getSkipToken()
Return (nullable) The skip token for use in server-driven paging.
|
SortItemList |
getSortItems()
Return (nullable) The sort criteria for the target entities.
|
boolean |
getStreamResponse()
Return if
true , the client should use streamed parsing of the response. |
int |
getSystemFlags()
For internal use only.
|
DataMetric |
getTimeMetric()
Return (nullable) Elapsed time metric (unit: "MICROSECOND") to be used for execution of this query.
|
java.lang.Integer |
getTopCount()
Return (nullable) The number of initial results to return.
|
boolean |
getTrackChanges()
Return does the client want the server to track changes?
|
boolean |
getTrackDownloads()
Return does the server want to track downloads (key tracking)?
|
TransformValueList |
getTransformValues()
Return (nullable) The OData transformation items as described in OData Data Aggregation.
|
ExpandItemList |
getUnadjustedExpandItems()
Return (nullable) The expandItems as they were before adjustItems.
|
SelectItemList |
getUnadjustedSelectItems()
Return (nullable) The selectItems as they were before adjustItems.
|
java.lang.String |
getUrl()
Return (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.
|
boolean |
hasAdjustedItems()
Return has
DataQuery.adjustItems been called for this query? |
DataQuery |
hasPendingChanges()
Alter this query to apply to all entities with pending changes.
|
DataQuery |
ifDeleted()
Alter this query to include logically-deleted entities.
|
DataQuery |
ifModifiedAfter(GlobalDateTime time)
Alter this query to include only entities that were last modified after the specified
time . |
DataQuery |
ifModifiedBefore(GlobalDateTime time)
Alter this query to include only entities that were last modified before the specified
time . |
DataQuery |
ifNotDeleted()
Alter this query to include not-logically-deleted entities.
|
DataQuery |
ifOriginalEntity()
Alter this query to apply to all entities with original state.
|
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. |
static DataQuery |
newIfNull(DataQuery query)
Construct a new DataQuery if the
query parameter is null . |
DataQuery |
notForDownload()
Alter this query to mark it as not being a client's download query.
|
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 |
selectDistinct(PropertyPath... items)
Add properties (to
DataQuery.selectItems ) for selecting from the target entity and set DataQuery.distinctItems to true . |
StringSet |
selectedProperties()
Return the names of all properties selected by this query.
|
DataQuery |
selectKey()
Set
DataQuery.keySelected to true . |
boolean |
selectsProperty(Property property)
Return
true if this query selects property from the target entity. |
void |
setAdjustedItems(boolean value)
Set has
DataQuery.adjustItems been called for this query? |
void |
setAliasValues(DataValueMap value)
Set parameter alias values.
|
void |
setAllSelected(boolean value)
Set
true if all properties are selected (using "*"). |
void |
setCountInline(boolean value)
Set if
true , the service should return the total number of available results as an inline count in the result list. |
void |
setCountMetric(DataMetric value)
Set result count metric to be used for execution of this query.
|
void |
setCountOnly(boolean value)
Set if
true , the service should return only the number of available results matching the query. |
void |
setCustomOptions(StringMap value)
Set custom query options.
|
void |
setDataFormat(java.lang.Integer value)
Set the data format for this query's result.
|
void |
setDeltaResponse(boolean value)
Set if
true , the client should use delta parsing of the response. |
void |
setDeltaTime(GlobalDateTime value)
Set the delta time (
DataQuery.deltaToken as UTC date/time). |
void |
setDeltaToken(java.lang.String value)
Set the delta token for use in change tracking.
|
void |
setDerivedType(StructureType value)
Set derived type for limiting query results.
|
void |
setDistinctItems(boolean value)
Set whether to select only distinct items.
|
void |
setEntityKey(EntityKey value)
Set the entity key for this query.
|
void |
setEntitySet(EntitySet value)
Set the entity set expected for the result of this query.
|
void |
setEntityType(EntityType value)
Set the entity type expected for the result of this query.
|
void |
setExpandItems(ExpandItemList value)
Set the properties to expand from target entities.
|
void |
setExpectSingle(boolean value)
Set set to
true if a single result is expected. |
void |
setGroupTransform(GroupTransform value)
Set a group transformation item set through groupBy method
|
void |
setInternalData(java.lang.Object value)
For internal use only.
|
void |
setKeySelected(boolean value)
Set
true if all key properties should be selected. |
void |
setMethodCall(DataMethodCall value)
Set the method call for this query.
|
void |
setPageSize(java.lang.Integer value)
Set the maximum number of results per page.
|
void |
setPropertyPath(DataPath value)
Set property path for accessing individual properties of an entity.
|
void |
setQueryFilter(QueryFilter value)
Set the filter criteria for the target entities.
|
void |
setQueryString(java.lang.String value)
Set the query string for this query.
|
void |
setRequestContext(java.lang.Object value)
Set data context (for internal use).
|
void |
setRequestPath(java.lang.String value)
Set the request path for this query.
|
void |
setSearchText(java.lang.String value)
Set the search text to locate in the target entities.
|
void |
setSelectItems(SelectItemList value)
Set the properties to select from target entities.
|
void |
setSkipCount(java.lang.Integer value)
Set the number of initial results to skip.
|
void |
setSkipToken(java.lang.String value)
Set the skip token for use in server-driven paging.
|
void |
setSortItems(SortItemList value)
Set the sort criteria for the target entities.
|
void |
setStreamResponse(boolean value)
Set if
true , the client should use streamed parsing of the response. |
void |
setSystemFlags(int value)
For internal use only.
|
void |
setTimeMetric(DataMetric value)
Set elapsed time metric (unit: "MICROSECOND") to be used for execution of this query.
|
void |
setTopCount(java.lang.Integer value)
Set the number of initial results to return.
|
void |
setTrackChanges(boolean value)
Set does the client want the server to track changes?
|
void |
setTrackDownloads(boolean value)
Set does the server want to track downloads (key tracking)?
|
void |
setTransformValues(TransformValueList value)
Set the OData transformation items as described in OData Data Aggregation.
|
void |
setUnadjustedExpandItems(ExpandItemList value)
Set the expandItems as they were before adjustItems.
|
void |
setUnadjustedSelectItems(SelectItemList value)
Set the selectItems as they were before adjustItems.
|
void |
setUrl(java.lang.String value)
Set 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 void applyKeyToFilter()
If this query has an DataQuery.entityKey
, then apply it to the DataQuery.queryFilter
as additional equality conditions.
public DataQuery bind(BindingPath resource)
Bind a resource as the binding parameter of a bound action/function.
resource
- The resource to be bound.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() { NorthwindService service = this.getService(); Customer customer = service.getCustomer(new DataQuery() .expand(Customer.orders).top(1)); Order__List orders = customer.getOrders(); DataQuery query = new DataQuery().load(customer, Customer.orders).count(); long count = service.executeQuery(query).getCount(); assert count == ((long)orders.length()); }
public void collectionCountExample() { NorthwindService service = this.getService(); Customer__List customers = service.getCustomers(); DataQuery query = new DataQuery() .from(NorthwindServiceMetadata.EntitySets.customers).count(); long count = service.executeQuery(query).getCount(); assert count == ((long)customers.length()); }
public void 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()); }
public void 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()); }
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() { 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); Customer__List customers = service.getCustomers(query); int countOrders = 0; for (Customer customer : customers) { this.showCustomer(customer); Order__List orders = customer.getOrders(); for (Order order : orders) { int orderID = order.getOrderID(); Example.show(" Order ", Example.formatInt(orderID)); countOrders++; } } assert countOrders > 0; }
public void 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; }
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() { 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); Customer__List customers = service.getCustomers(query); int countDetails = 0; for (Customer customer : customers) { this.showCustomer(customer); Order__List 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; }
public void 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)); } } }
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() { 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"))); Customer__List customers = service.getCustomers(query); this.showCustomers(customers); }
public void filterByDateExample() { NorthwindService service = this.getService(); GlobalDateTime oneWeekAgo = GlobalDateTime.now().plusDays(-7); DataQuery query = new DataQuery() .filter(Order.orderDate.greaterThan(oneWeekAgo)); Order__List orders = service.getOrders(query); this.showOrders(orders); }
public void 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); }
public void 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); }
public void 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); }
public void 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); }
test
- The query filter.public StringSet filteredProperties()
Return the names of all properties filtered by this query.
public boolean filtersProperty(Property property)
Return true
if this query filters property
from the target entity.
property
- Property to check for.true
if this query filters property
from the target entity.public DataQuery forAllClients()
Alter this query to apply to all clients. By default, for client-partitioned entities, queries apply only to the current client.
public DataQuery forAllTenants()
Alter this query to apply to all tenants. By default, if multitenancy is enabled, queries apply only to the current tenant.
public DataQuery from(EntitySet entitySet)
Set the DataQuery.entitySet
property to identify this query's target entity set.
public void fromExample() { NorthwindService service = this.getService(); Customer__List customers = service.getCustomers(); for (Customer customer : customers) { this.showCustomer(customer); } }
public void 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); } }
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()
Return (nullable) Parameter alias values.
public boolean getAllSelected()
Return true
if all properties are selected (using "*").
public boolean getCountInline()
Return if true
, the service should return the total number of available results as an inline count in the result list.
public DataMetric getCountMetric()
Return (nullable) Result count metric to be used for execution of this query.
public boolean getCountOnly()
Return if true
, the service should return only the number of available results matching the query.
public java.lang.String getCustom(java.lang.String name)
Get a custom option from DataQuery.customOptions
.
name
- Option name.null
if there is no such custom option.public StringMap getCustomOptions()
Return (nullable) Custom query options.
public java.lang.Integer getDataFormat()
Return (nullable) The data format for this query's result.
public boolean getDeltaResponse()
Return if true
, the client should use delta parsing of the response.
public GlobalDateTime getDeltaTime()
Return (nullable) The delta time (DataQuery.deltaToken
as UTC date/time).
DataQuery.deltaToken
as UTC date/time).public java.lang.String getDeltaToken()
Return (nullable) The delta token for use in change tracking.
public StructureType getDerivedType()
Return (nullable) Derived type for limiting query results.
public boolean getDistinctItems()
Return whether to select only distinct items.
public EntityKey getEntityKey()
Return (nullable) The entity key for this query.
If specified, then DataQuery.entitySet
should also be specified.
public EntitySet getEntitySet()
Return (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()
Return (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()
Return (nullable) The properties to expand from target entities.
public boolean getExpectSingle()
Return set to true
if a single result is expected.
This may be required if url
has been explicitly set.
true
if a single result is expected.public GroupTransform getGroupTransform()
Return (nullable) A group transformation item set through groupBy method
public java.lang.Object getInternalData()
For internal use only.
public boolean getKeySelected()
Return true
if all key properties should be selected.
public DataMethodCall getMethodCall()
Return (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()
Return (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()
Return (nullable) Property path for accessing individual properties of an entity.
public QueryFilter getQueryFilter()
Return (nullable) The filter criteria for the target entities.
public java.lang.String getQueryString()
Return (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.Object getRequestContext()
Return (nullable) Data context (for internal use).
public java.lang.String getRequestPath()
Return (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 EntityKey getRequiredEntityKey()
Return the required entity key for this query. Can be changed using DataQuery.withKey
.
DataQueryException
if this query has no entity key.
DataQuery.withKey
.public EntitySet getRequiredEntitySet()
Return the required entity set for this query. Can be changed using DataQuery.from
.
DataQueryException
if this query has no entity set.
DataQuery.from
.public java.lang.String getSearchText()
Return (nullable) The search text to locate in the target entities.
public SelectItemList getSelectItems()
Return (nullable) The properties to select from target entities.
public java.lang.Integer getSkipCount()
Return (nullable) The number of initial results to skip.
public java.lang.String getSkipToken()
Return (nullable) The skip token for use in server-driven paging.
public SortItemList getSortItems()
Return (nullable) The sort criteria for the target entities.
public boolean getStreamResponse()
Return if true
, the client should use streamed parsing of the response.
public int getSystemFlags()
For internal use only.
public DataMetric getTimeMetric()
Return (nullable) Elapsed time metric (unit: "MICROSECOND") to be used for execution of this query.
public java.lang.Integer getTopCount()
Return (nullable) The number of initial results to return.
public boolean getTrackChanges()
Return does the client want the server to track changes?
public boolean getTrackDownloads()
Return does the server want to track downloads (key tracking)?
public TransformValueList getTransformValues()
Return (nullable) The OData transformation items as described in OData Data Aggregation.
public ExpandItemList getUnadjustedExpandItems()
Return (nullable) The expandItems as they were before adjustItems.
public SelectItemList getUnadjustedSelectItems()
Return (nullable) The selectItems as they were before adjustItems.
public java.lang.String getUrl()
Return (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
.
DataQuery.requestPath
and DataQuery.queryString
if either is non-`null`, or `null` if the URL is intended to be derived from other properties.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 boolean hasAdjustedItems()
Return has DataQuery.adjustItems
been called for this query?
DataQuery.adjustItems
been called for this query?public DataQuery hasPendingChanges()
Alter this query to apply to all entities with pending changes.
public DataQuery ifDeleted()
Alter this query to include logically-deleted entities. This is only applicable to entity sets that are enabled for change tracking. Logically deleted entities are entities that were marked for deletion, but not physically deleted as they need to remain in the database for change tracking purposes.
public DataQuery ifModifiedAfter(GlobalDateTime time)
Alter this query to include only entities that were last modified after the specified time
.
This is only applicable to entity sets that are enabled for change tracking.
time
- Modification time.public DataQuery ifModifiedBefore(GlobalDateTime time)
Alter this query to include only entities that were last modified before the specified time
.
This is only applicable to entity sets that are enabled for change tracking.
time
- Modification time.public DataQuery ifNotDeleted()
Alter this query to include not-logically-deleted entities. This is only applicable to entity sets that are enabled for change tracking. Logically deleted entities are entities that were marked for deletion, but not physically deleted as they need to remain in the database for change tracking purposes.
public DataQuery ifOriginalEntity()
Alter this query to apply to all entities with original state.
public DataQuery inlineCount()
Set DataQuery.countInline
to true
to request an inline count in the server's response.
public void inlineCountExample() { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .from(NorthwindServiceMetadata.EntitySets.customers).skip(20).top(10) .inlineCount(); QueryResult result = service.executeQuery(query); Customer__List customers = Customer.list(result.getEntityList()); long count = result.getInlineCount(); assert customers.length() == 10; assert count > 10L; }
public void 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; }
public DataQuery invoke(DataMethod method)
method
- Method parameter.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() { TrippinService service = this.getService(); TrippinPerson person = service.getPersonWithMostFriends(); this.showPerson(person); }
public void 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); }
method
- Data method to be called (action or function).parameters
- Method parameters.public DataQuery load(EntityValue entity)
entity
- Entity parameter.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 static DataQuery newIfNull(DataQuery query)
Construct a new DataQuery if the query
parameter is null
.
query
- (nullable) Query to be checked.query
parameter, if non-null
. Otherwise a new DataQuery.public DataQuery notForDownload()
Alter this query to mark it as not being a client's download query.
public DataQuery orderBy(QueryValue value)
value
- Value parameter.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)); ArtistList 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() { 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); Customer__List customers = Customer.list(result.getEntityList()); this.showCustomers(customers); found = found + customers.length(); query = result.getNextQuery(); } while (query.getUrl() != null); assert ((long)found) == expected; }
public void 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); }
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"); Product__List 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() { NorthwindService service = this.getService(); DataQuery query = new DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName); Customer__List customers = service.getCustomers(query); for (Customer customer : customers) { this.showCustomer(customer); } }
public void 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); } }
items
- The items to be selected.public DataQuery selectAll()
Set DataQuery.allSelected
to true
.
public DataQuery selectDistinct(PropertyPath... items)
Add properties (to DataQuery.selectItems
) for selecting from the target entity and set DataQuery.distinctItems
to true
.
Note that this isn't a standard OData query option, so servers might ignore it.
items
- The items to be selected.public DataQuery selectKey()
Set DataQuery.keySelected
to true
.
public StringSet selectedProperties()
Return the names of all properties selected by this query.
If DataQuery.allSelected
or DataQuery.keySelected
is set, then calling
this function might result in additional items being added
to DataQuery.selectItems
so that the resulting set of properties
is consistent with the other configured query options.
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 setAdjustedItems(boolean value)
Set has DataQuery.adjustItems
been called for this query?
value
- Has DataQuery.adjustItems
been called for this query?public void setAliasValues(DataValueMap value)
Set parameter alias values.
value
- Parameter alias values.public void setAllSelected(boolean value)
Set true
if all properties are selected (using "*").
value
- `true` if all properties are selected (using "*").public void setCountInline(boolean value)
Set if true
, the service should return the total number of available results as an inline count in the result list.
value
- If `true`, the service should return the total number of available results as an inline count in the result list.public void setCountMetric(DataMetric value)
Set result count metric to be used for execution of this query.
value
- Result count metric to be used for execution of this query.public void setCountOnly(boolean value)
Set if true
, the service should return only the number of available results matching the query.
value
- If `true`, the service should return only the number of available results matching the query.public void setCustomOptions(StringMap value)
Set custom query options.
value
- Custom query options.public void setDataFormat(java.lang.Integer value)
Set the data format for this query's result.
value
- The data format for this query's result.public void setDeltaResponse(boolean value)
Set if true
, the client should use delta parsing of the response.
value
- If `true`, the client should use delta parsing of the response.public void setDeltaTime(GlobalDateTime value)
Set the delta time (DataQuery.deltaToken
as UTC date/time).
value
- The delta time (DataQuery.deltaToken
as UTC date/time).public void setDeltaToken(java.lang.String value)
Set the delta token for use in change tracking.
value
- The delta token for use in change tracking.public void setDerivedType(StructureType value)
Set derived type for limiting query results.
value
- Derived type for limiting query results.public void setDistinctItems(boolean value)
Set whether to select only distinct items.
value
- Whether to select only *distinct* items.public void setEntityKey(EntityKey value)
Set the entity key for this query.
If specified, then DataQuery.entitySet
should also be specified.
value
- The entity key for this query.public void setEntitySet(EntitySet value)
Set 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
.
value
- The entity set expected for the result of this query.public void setEntityType(EntityType value)
Set 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.
value
- The entity type expected for the result of this query.public void setExpandItems(ExpandItemList value)
Set the properties to expand from target entities.
value
- The properties to expand from target entities.public void setExpectSingle(boolean value)
Set set to true
if a single result is expected.
This may be required if url
has been explicitly set.
value
- Set to true
if a single result is expected.public void setGroupTransform(GroupTransform value)
Set a group transformation item set through groupBy method
value
- A group transformation item set through groupBy methodpublic void setInternalData(java.lang.Object value)
For internal use only.
value
- (internal use only)public void setKeySelected(boolean value)
Set true
if all key properties should be selected.
value
- `true` if all key properties should be selected.public void setMethodCall(DataMethodCall value)
Set the method call for this query.
To execute a query, either this must be non-null
, or DataQuery.entitySet
must be non-null
.
value
- The method call for this query.public void setPageSize(java.lang.Integer value)
Set 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.
value
- The maximum number of results per page.public void setPropertyPath(DataPath value)
Set property path for accessing individual properties of an entity.
value
- Property path for accessing individual properties of an entity.public void setQueryFilter(QueryFilter value)
Set the filter criteria for the target entities.
value
- The filter criteria for the target entities.public void setQueryString(java.lang.String value)
Set 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.
value
- The query string for this query.public void setRequestContext(java.lang.Object value)
Set data context (for internal use).
value
- Data context (for internal use).public void setRequestPath(java.lang.String value)
Set the request path for this query.
Intended for use by servers. Clients should use API calls (e.g. DataQuery.from
) to create request paths.
value
- The request path for this query.public void setSearchText(java.lang.String value)
Set the search text to locate in the target entities.
value
- The search text to locate in the target entities.public void setSelectItems(SelectItemList value)
Set the properties to select from target entities.
value
- The properties to select from target entities.public void setSkipCount(java.lang.Integer value)
Set the number of initial results to skip.
value
- The number of initial results to skip.public void setSkipToken(java.lang.String value)
Set the skip token for use in server-driven paging.
value
- The skip token for use in server-driven paging.public void setSortItems(SortItemList value)
Set the sort criteria for the target entities.
value
- The sort criteria for the target entities.public void setStreamResponse(boolean value)
Set if true
, the client should use streamed parsing of the response.
value
- If `true`, the client should use streamed parsing of the response.public void setSystemFlags(int value)
For internal use only.
value
- (internal use only)public void setTimeMetric(DataMetric value)
Set elapsed time metric (unit: "MICROSECOND") to be used for execution of this query.
value
- Elapsed time metric (unit: "MICROSECOND") to be used for execution of this query.public void setTopCount(java.lang.Integer value)
Set the number of initial results to return.
value
- The number of initial results to return.public void setTrackChanges(boolean value)
Set does the client want the server to track changes?
value
- Does the client want the server to track changes?public void setTrackDownloads(boolean value)
Set does the server want to track downloads (key tracking)?
value
- Does the server want to track downloads (key tracking)?public void setTransformValues(TransformValueList value)
Set the OData transformation items as described in OData Data Aggregation.
value
- The OData transformation items as described in OData Data Aggregation.public void setUnadjustedExpandItems(ExpandItemList value)
Set the expandItems as they were before adjustItems.
value
- The expandItems as they were before adjustItems.public void setUnadjustedSelectItems(SelectItemList value)
Set the selectItems as they were before adjustItems.
value
- The selectItems as they were before adjustItems.public void setUrl(java.lang.String value)
Set 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
.
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.public DataQuery skip(int count)
Set DataQuery.skipCount
to specify the number of initial results to return.
public void queryWithSkipExample() { NorthwindService service = this.getService(); DataQuery query = new DataQuery().skip(20).top(10); Customer__List customers = service.getCustomers(query); this.showCustomers(customers); assert customers.length() == 10; }
public void 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; }
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)
value
- Value parameter.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() { MediaService service = this.getService(); DataQuery query = new DataQuery().orderBy(Artist.lastName) .thenBy(Artist.firstName); ArtistList artists = service.getArtists(query); this.showArtists(artists); }
public void 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); }
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() { NorthwindService service = this.getService(); DataQuery query = new DataQuery().top(10); Customer__List customers = service.getCustomers(query); this.showCustomers(customers); assert customers.length() == 10; }
public void 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; }
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
.
Also set DataQuery.deltaResponse
to true
if deltaLink
is non-null, otherwise false
.
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() { 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); }
public void 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); }
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).