com.sap.ip.me.api.smartsync
Class SmartSyncJQueryFactory

java.lang.Object
  extended bycom.sap.ip.me.api.smartsync.SmartSyncJQueryFactory

public abstract class SmartSyncJQueryFactory
extends java.lang.Object

Query factory class for join enabled queries. The queries are reusable, read-only objects that allow filtering the data in a container. Usually, you create the query on first use, store it into a static field and then re-use it later.

The query interface also supports sorting. To enable sorting, simply add attribute terms on which you wish to sort when creating the query.

Conditions should be added from left to right with decreasing selectivity.

SmartSyncJQuery factory can be used with JDBC Persistence to implement optimized queries with join support. A JQuery does only return field values and not complete Structures by default. See Persistence JQuery Javadoc for more details.

Author:
SAP
See Also:
JQuery, JQueryAttribute, JQueryCondition, JQueryParameter, JQuerySortOrder, JQueryGroupBy

Constructor Summary
SmartSyncJQueryFactory()
           
 
Method Summary
abstract  JQueryAttribute createAggregate(JQueryAttribute attr, AggregationOperatorType aggreg)
          Create an aggregate on the query attribute.
abstract  JQueryAttribute createAttribute(FieldDescriptor fieldName)
          Create a query attribute.
abstract  JQueryAttribute createAttribute(FieldDescriptor fieldName, java.lang.Object tag)
          Create a query attribute.
abstract  JQueryCondition createCondition(JQueryAttribute left, java.lang.Object[] right)
          Create simple IN condition.
abstract  JQueryCondition createCondition(JQueryAttribute left, java.lang.Object[] right, java.lang.Object tag)
          Create named simple IN condition.
abstract  JQueryCondition createCondition(JQueryAttribute left, RelationalOperatorType operator, JQueryAttribute right)
          Create simple condition.
abstract  JQueryCondition createCondition(JQueryAttribute left, RelationalOperatorType operator, JQueryParameter right)
          Create simple condition with parameterized right operand.
abstract  JQueryCondition createCondition(JQueryAttribute left, RelationalOperatorType operator, java.lang.Object right)
          Create simple condition.
abstract  JQueryCondition createCondition(JQueryAttribute left, RelationalOperatorType operator, java.lang.Object right, java.lang.Object tag)
          Create named simple condition.
abstract  JQueryCondition createCondition(JQueryCondition[] conditions, LogicalOperatorType operator)
          Construct n-ary logical operator.
abstract  JQueryCondition createCondition(JQueryCondition left, LogicalOperatorType operator, JQueryCondition right)
          Construct binary logical operator.
abstract  JQueryCondition createCondition(LogicalOperatorType operator, JQueryCondition right)
          Construct unary logical operator.
abstract  JQueryGroupBy createGroupBy(JQueryAttribute[] groupBy)
          Create group by for the specified attributes in the same order as the delivered JQueryAttribute[]
abstract  JQueryCondition createLinkCondition(RowDescriptor sourceRow, RowDescriptor targetRow)
          Create link condition between top row and child row or between related rows.
abstract  JQueryParameter createParameter(java.lang.Object defaultValue)
          Create query parameter.
abstract  JQueryParameter createParameter(java.lang.Object defaultValue, java.lang.Object tag)
          Create named query parameter.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond)
          Create query based on specified attributes and condition.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond, boolean distinct)
          Create query based on specified attributes and condition.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond, boolean distinct, JQuerySortOrder sortOrder)
          Create sorted query based on specified attributes and condition.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond, boolean distinct, JQuerySortOrder[] sortOrders)
          Create sorted query based on specified attributes and condition.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond, boolean distinct, JQuerySortOrder[] sortOrders, JQueryGroupBy groupBy)
          Create sorted and grouped query based on specified attributes and condition.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond, JQuerySortOrder sortOrder)
          Create sorted query based on specified attributes and condition.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond, JQuerySortOrder[] sortOrders)
          Create sorted query based on specified attributes and condition.
abstract  JQuery createQuery(JQueryAttribute[] attributes, JQueryCondition cond, JQuerySortOrder[] sortOrders, JQueryGroupBy groupBy)
          Create sorted and grouped query based on specified attributes and condition.
abstract  JQuerySortOrder createSortOrder(JQueryAttribute attribute)
          Create ascending sort order on given attribute.
abstract  JQuerySortOrder createSortOrder(JQueryAttribute attribute, boolean ascending)
          Create sort order on given attribute.
abstract  JQuerySortOrder createSortOrder(JQuerySortOrder[] orders)
          Deprecated.  
static SmartSyncJQueryFactory getInstance()
          Deprecated. use SmartSyncRuntime.getJQueryFactory() instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmartSyncJQueryFactory

public SmartSyncJQueryFactory()
Method Detail

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond)
                            throws java.lang.IllegalArgumentException
Create query based on specified attributes and condition.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
Throws:
java.lang.IllegalArgumentException - if condition uses attributes not mentioned in attributes parameter.

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond,
                                   JQuerySortOrder[] sortOrders)
                            throws java.lang.IllegalArgumentException
Create sorted query based on specified attributes and condition.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
sortOrders - sort orders to use for this query or null to use default sorting.
Throws:
java.lang.IllegalArgumentException - if condition or sort orders use attributes not mentioned in attributes parameter.

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond,
                                   JQuerySortOrder sortOrder)
                            throws java.lang.IllegalArgumentException
Create sorted query based on specified attributes and condition.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
sortOrder - sort order to use for this query or null to use default sorting.
Throws:
java.lang.IllegalArgumentException - if condition or sort orders use attributes not mentioned in attributes parameter.

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond,
                                   boolean distinct)
                            throws java.lang.IllegalArgumentException
Create query based on specified attributes and condition.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
distinct - if true, select only distinct rows (no duplicates).
Throws:
java.lang.IllegalArgumentException - if condition uses attributes not mentioned in attributes parameter.

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond,
                                   boolean distinct,
                                   JQuerySortOrder[] sortOrders)
                            throws java.lang.IllegalArgumentException
Create sorted query based on specified attributes and condition.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
distinct - if true, select only distinct rows (no duplicates).
sortOrders - sort orders to use for this query or null to use default sorting.
Throws:
java.lang.IllegalArgumentException - if condition or sort orders use attributes not mentioned in attributes parameter.

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond,
                                   boolean distinct,
                                   JQuerySortOrder sortOrder)
                            throws java.lang.IllegalArgumentException
Create sorted query based on specified attributes and condition.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
distinct - if true, select only distinct rows (no duplicates).
sortOrder - sort order to use for this query or null to use default sorting.
Throws:
java.lang.IllegalArgumentException - if condition or sort orders use attributes not mentioned in attributes parameter.

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond,
                                   JQuerySortOrder[] sortOrders,
                                   JQueryGroupBy groupBy)
                            throws java.lang.IllegalArgumentException
Create sorted and grouped query based on specified attributes and condition. groupBy consists of the attributes to group by.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
sortOrders - sort order to use for this query or null to use default sorting.
groupBy - grouping to use for this query or null to use no grouping
Throws:
java.lang.IllegalArgumentException - if condition or sort orders use attributes not mentioned in attributes parameter.

createQuery

public abstract JQuery createQuery(JQueryAttribute[] attributes,
                                   JQueryCondition cond,
                                   boolean distinct,
                                   JQuerySortOrder[] sortOrders,
                                   JQueryGroupBy groupBy)
                            throws java.lang.IllegalArgumentException
Create sorted and grouped query based on specified attributes and condition. groupBy consists of the attributes to group by.

Parameters:
attributes - attributes used in this query.
cond - condition to use to filter results.
distinct - if true, select only distinct rows (no duplicates).
sortOrders - sort order to use for this query or null to use default sorting.
groupBy - grouping to use for this query or null to use no grouping
Throws:
java.lang.IllegalArgumentException - if condition or sort orders use attributes not mentioned in attributes parameter.

createAttribute

public abstract JQueryAttribute createAttribute(FieldDescriptor fieldName)
Create a query attribute.

Parameters:
fieldName - field name in candidate class to bind to this term.
Returns:
new term representing given class attribute.

createAttribute

public abstract JQueryAttribute createAttribute(FieldDescriptor fieldName,
                                                java.lang.Object tag)
Create a query attribute.

Parameters:
fieldName - field name in candidate class to bind to this term.
tag - identificator tag.
Returns:
new term representing given class attribute.

createAggregate

public abstract JQueryAttribute createAggregate(JQueryAttribute attr,
                                                AggregationOperatorType aggreg)
Create an aggregate on the query attribute. The query attribute is modified by calling this method and returned back.

Parameters:
attr - attribute to change to aggregate.
aggreg - aggregation function to use.
Returns:
attr, aggregation is set on this attribute.

createGroupBy

public abstract JQueryGroupBy createGroupBy(JQueryAttribute[] groupBy)
Create group by for the specified attributes in the same order as the delivered JQueryAttribute[]

Parameters:
groupBy - attributes to group by in the given order
Returns:
a group by for the given attributes

createParameter

public abstract JQueryParameter createParameter(java.lang.Object defaultValue)
Create query parameter.

Parameters:
defaultValue - default value for this parameter.
Returns:
new term representing query parameter.

createParameter

public abstract JQueryParameter createParameter(java.lang.Object defaultValue,
                                                java.lang.Object tag)
Create named query parameter.

Parameters:
defaultValue - default value for this parameter.
tag - identificator tag.
Returns:
new term representing query parameter.

createSortOrder

public abstract JQuerySortOrder createSortOrder(JQueryAttribute attribute)
Create ascending sort order on given attribute.

Make sure that the corresponding FieldDescriptor is indexed for best performance!

Parameters:
attribute - attribute to sort.
Returns:
sort order for the attribute.

createSortOrder

public abstract JQuerySortOrder createSortOrder(JQueryAttribute attribute,
                                                boolean ascending)
Create sort order on given attribute.

Make sure that the corresponding FieldDescriptor is indexed for best performance!

Parameters:
attribute - attribute to sort.
ascending - if true, sort ascending.
Returns:
sort order for the attribute.

createSortOrder

public abstract JQuerySortOrder createSortOrder(JQuerySortOrder[] orders)
Deprecated.  

Create composite sort order.

Parameters:
orders - sort orders to join.
Returns:
sort order for the attribute.

createCondition

public abstract JQueryCondition createCondition(JQueryAttribute left,
                                                RelationalOperatorType operator,
                                                JQueryParameter right)
                                         throws java.lang.IllegalArgumentException
Create simple condition with parameterized right operand. This Parameter can be set before execution.

Parameters:
left - left operand.
operator - comparison operator.
right - right operand as parameter.
Throws:
java.lang.IllegalArgumentException - if the operator is invalid, one of terms is null or the term types do not match.

createCondition

public abstract JQueryCondition createCondition(JQueryAttribute left,
                                                RelationalOperatorType operator,
                                                JQueryAttribute right)
                                         throws java.lang.IllegalArgumentException
Create simple condition.

Parameters:
left - left operand.
operator - comparison operator.
right - right operand as parameter.
Throws:
java.lang.IllegalArgumentException - if the operator is invalid, one of terms is null or the term types do not match.

createCondition

public abstract JQueryCondition createCondition(JQueryAttribute left,
                                                RelationalOperatorType operator,
                                                java.lang.Object right)
                                         throws java.lang.IllegalArgumentException
Create simple condition. This method creates a parameter internally, with given default value and identificator taken from left attribute.

Parameters:
left - left operand.
operator - comparison operator.
right - directly specified parameter (can be array for IN operator).
Throws:
java.lang.IllegalArgumentException - if the operator is invalid, one of terms is null or the term types do not match.

createCondition

public abstract JQueryCondition createCondition(JQueryAttribute left,
                                                java.lang.Object[] right)
                                         throws java.lang.IllegalArgumentException
Create simple IN condition. This method creates a parameter internally, with given default value and identificator taken from left attribute.

Parameters:
left - left operand.
right - directly specified parameter (array for IN operator).
Throws:
java.lang.IllegalArgumentException - if the type doesn't match.

createCondition

public abstract JQueryCondition createCondition(JQueryAttribute left,
                                                RelationalOperatorType operator,
                                                java.lang.Object right,
                                                java.lang.Object tag)
                                         throws java.lang.IllegalArgumentException
Create named simple condition. This method creates a parameter internally, with given default value and identificator.

Parameters:
left - left operand.
operator - comparison operator.
right - directly specified parameter (can be array for IN operator).
tag - parameter identificator tag to be used for implicitly created parameter.
Throws:
java.lang.IllegalArgumentException - if the operator is invalid, one of terms is null or the term types do not match.

createCondition

public abstract JQueryCondition createCondition(JQueryAttribute left,
                                                java.lang.Object[] right,
                                                java.lang.Object tag)
                                         throws java.lang.IllegalArgumentException
Create named simple IN condition. This method creates a parameter internally, with given default value and identificator.

Parameters:
left - left operand.
right - directly specified parameter (array for IN operator).
tag - parameter identificator tag to be used for implicitly created parameter.
Throws:
java.lang.IllegalArgumentException - if the type doesn't match.

createLinkCondition

public abstract JQueryCondition createLinkCondition(RowDescriptor sourceRow,
                                                    RowDescriptor targetRow)
Create link condition between top row and child row or between related rows. This method either allows binding of topRow with childRow in the same SyncBO, effectively enhancing SyncBo.getRows(RowDescriptor) or binding of related rows, effectively replacing Row.getRelatedRow(RowDescriptor) and Row.getRelatingRows(RowDescriptor). Method versions with Query as parameter are replaced by defining other conditions on this query in addition to link condition.

Let's say, we have SyncBO A with row A1 field A1F that relates to key of row B2 in SyncBO B. To replace A.getRelatedRow(B), create a link condition between A and B and parameter condition binding key of A to row key you are interested in (Row.getKey() and bind those two with AND. Similarly, to get all relating rows A relating to a particular row B, create a link condition between A and B and parameter condition binding key of B to row key you are interested in and bind those two with AND. In both cases, this builds a join query over two tables, which is executed faster as comparable old query.

To query all child rows B belonging to particular SyncBo with given topRow A, create a link condition between A and B and parameter condition binding key of A to given topRow key.

Example for creating alink condition between related rows (see assumption above):

	RowDescriptor A = ... //the source (top Row or child Row) which has a Field that has a relation to Row B
	RowDescriptor B = ... //the target (top Row) to which A's field is pointing to.
	JQueryCondition linkCondition = smartSyncJQueryFactory.createCondition(A, B);
 

Example for creating a link condition between top row and child row:

 	SyncBo syncBo = ...
 	RowDescriptor topRow = syncBo.getTopRow();
 	RowDescriptor childRow = syncBo.getChildRow();
 	JQueryCondition linkCondition = smartSyncJQueryFactory.createCondition(topRow, childRow);
 

Parameters:
sourceRow - when searching for a Relation between a Field and a SyncBo this is the RowDescriptor of the source (Field). When searching for a parent - child link this is the top RowDescriptor of the SyncBo.
targetRow - when searching for a Relation between a Field and a SyncBo this is the RowDescriptor of the target (Row). When searching for a parent - child link this is the child RowDescriptor of the SyncBo.
See Also:
SyncBo.getTopRow(), Row.getSyncBo(), FieldDescriptor.getRelatedRelation(), RelationDescriptor

createCondition

public abstract JQueryCondition createCondition(JQueryCondition left,
                                                LogicalOperatorType operator,
                                                JQueryCondition right)
                                         throws java.lang.IllegalArgumentException
Construct binary logical operator.

Parameters:
left - left operand.
operator - logical operator.
right - right operand.
Throws:
java.lang.IllegalArgumentException - if an invalid operator is specified or one of operands is null.

createCondition

public abstract JQueryCondition createCondition(JQueryCondition[] conditions,
                                                LogicalOperatorType operator)
                                         throws java.lang.IllegalArgumentException
Construct n-ary logical operator.

Parameters:
conditions - operands.
operator - logical operator.
Throws:
java.lang.IllegalArgumentException - if an invalid operator is specified or one of operands is null.

createCondition

public abstract JQueryCondition createCondition(LogicalOperatorType operator,
                                                JQueryCondition right)
                                         throws java.lang.IllegalArgumentException
Construct unary logical operator.

Parameters:
operator - logical operator (currently only NOT supported).
right - right operand.
Throws:
java.lang.IllegalArgumentException - if an invalid operator is specified or the operand is null.

getInstance

public static SmartSyncJQueryFactory getInstance()
Deprecated. use SmartSyncRuntime.getJQueryFactory() instead.

Get an instance of the SmartSyncJQueryFactory.

Returns:
an instance of the SmartSyncJQueryFactory.


Copyright © 2005 SAP AG. All Rights Reserved.