Class RetrieveDescImpl
- java.lang.Object
-
- com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl
-
- All Implemented Interfaces:
ActionDesc
,RetrieveDesc
,Cloneable
public class RetrieveDescImpl extends Object implements RetrieveDesc, Cloneable
-
-
Field Summary
Fields Modifier and Type Field Description static int
OPT_ADD_FETCHGROUPS
Indicates, that fetch group fields should be added.static int
OPT_ADD_KEYS_ONLY
Indicates, that only key fields should be added.static int
OPT_AGGREGATE
Sum of all aggregate options.static int
OPT_AGGREGATE_NON_COUNT_PC
Sum of all aggregate options excluding count on persistent capable objects.static int
OPT_AVG
Indicates, that an avg aggregate query should be run.static int
OPT_COUNT
Indicates, that a count aggregate query should be run.static int
OPT_COUNT_PC
Special treatment for count on persistent capable objects.static int
OPT_DISABLE_RELATIONSHIP_PREFETCH
Indicates, that even if relationship fields are in DFG, they should not be prefetched.static int
OPT_DISTINCT
Indicates, that a distinct query should be run.static int
OPT_FOR_UPDATE
Indicates, that the selected rows should be locked for update.static int
OPT_MAX
Indicates, that a max aggregate query should be run.static int
OPT_MIN
Indicates, that a min aggregate query should be run.static int
OPT_PROJECTION
Indicates, that the query projects on this RD.static int
OPT_SUM
Indicates, that a sum aggregate query should be run.static int
OPT_VERIFY
Indicates special treatment for version consistency verifications.-
Fields inherited from interface com.sun.jdo.spi.persistence.support.sqlstore.ActionDesc
LOG_CREATE, LOG_DESTROY, LOG_NOOP, LOG_UPDATE, OP_ABS, OP_ADD, OP_AND, OP_APPROX, OP_AVG, OP_BETWEEN, OP_CONCAT, OP_COUNT, OP_COUNT_PC, OP_DISTINCT, OP_DIV, OP_EQ, OP_EQ_CLASS, OP_EQUIJOIN, OP_EXISTS, OP_FIELD, OP_FOR_UPDATE, OP_GE, OP_GT, OP_IN, OP_LE, OP_LEFTJOIN, OP_LENGTH, OP_LENGTHB, OP_LIKE, OP_LIKE_ESCAPE, OP_LOWER, OP_LT, OP_LTRIM, OP_MAX, OP_MAX_ROWS, OP_MAYBE_NULL, OP_MIN, OP_MOD, OP_MUL, OP_NE, OP_NONKEY, OP_NONREL_JOIN, OP_NOT, OP_NOTEXISTS, OP_NOTIN, OP_NOTNULL, OP_NULL, OP_NULL_COMPARISION_FUNCTION, OP_OR, OP_ORDERBY, OP_ORDERBY_DESC, OP_PARAMETER, OP_PARAMETER_COUNT, OP_POSITION, OP_POSITION_START, OP_RIGHTJOIN, OP_RTRIM, OP_RTRIMFIXED, OP_SOUNDEX, OP_SQRT, OP_SUB, OP_SUBSTR, OP_SUBSTRB, OP_SUBSTRING, OP_SUM, OP_UPPER, OP_VALUE
-
-
Constructor Summary
Constructors Constructor Description RetrieveDescImpl(Class pcClass, ClassDesc config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConstraint(String name, int operation, RetrieveDesc foreignConstraint, String foreignName)
Adds a constraint on the relationship field specified byname
.void
addConstraint(String name, int operation, Object value)
The addConstraint method is used to limit the values of fields for objects being selected.void
addConstraint(String name, RetrieveDesc foreignConstraint)
Adds a constraint on the foreign field specified byname
.void
addParameterConstraint(LocalFieldDesc field, int index)
Add ParameterConstraint corresponding to givenfield
at givenindex
.void
addParameterConstraints(LocalFieldDesc[] fields, int startIndex)
Add Constraints corresponding to givenfields
.void
addPrefetchedField(String name, RetrieveDesc foreignConstraint)
Add a field specified byname
to the list of fields to be prefetched.void
addResult(int opCode, int aggregateResultType)
The addResult method can be used to specifyglobal query attributes that don't end up in the where clause.void
addResult(String name, RetrieveDesc foreignConstraint, boolean projection)
The addResult method is used to specify which fields should be returned in a persistent object.SelectQueryPlan
buildQueryPlan(SQLStoreManager store, Concurrency concurrency)
Builds the internal query plan and initializes the select statements.Object
clone()
int
getAggregateResultType()
Returns the result type for aggregate queries.ClassDesc
getConfig()
Constraint
getConstraint()
Iterator
getFields()
Object
getNavigationalId()
Returns the navigational id of this retrieve descriptor.int
getOptions()
Returns the options of this retrieve descriptor.Class
getPersistenceCapableClass()
SelectQueryPlan
getPlan()
void
setNavigationalId(Object navigationalId)
Sets a navigational id on the retrieve descriptor.void
setOption(int option)
Sets optionoption
.void
setPlan(SelectQueryPlan plan)
void
setPrefetchEnabled(boolean prefetchEnabled)
Sets the prefetchEnabled option.
-
-
-
Field Detail
-
OPT_PROJECTION
public static final int OPT_PROJECTION
Indicates, that the query projects on this RD.- See Also:
- Constant Field Values
-
OPT_DISTINCT
public static final int OPT_DISTINCT
Indicates, that a distinct query should be run.- See Also:
- Constant Field Values
-
OPT_FOR_UPDATE
public static final int OPT_FOR_UPDATE
Indicates, that the selected rows should be locked for update.- See Also:
- Constant Field Values
-
OPT_AVG
public static final int OPT_AVG
Indicates, that an avg aggregate query should be run.- See Also:
- Constant Field Values
-
OPT_MIN
public static final int OPT_MIN
Indicates, that a min aggregate query should be run.- See Also:
- Constant Field Values
-
OPT_MAX
public static final int OPT_MAX
Indicates, that a max aggregate query should be run.- See Also:
- Constant Field Values
-
OPT_SUM
public static final int OPT_SUM
Indicates, that a sum aggregate query should be run.- See Also:
- Constant Field Values
-
OPT_COUNT
public static final int OPT_COUNT
Indicates, that a count aggregate query should be run.- See Also:
- Constant Field Values
-
OPT_COUNT_PC
public static final int OPT_COUNT_PC
Special treatment for count on persistent capable objects.- See Also:
- Constant Field Values
-
OPT_AGGREGATE
public static final int OPT_AGGREGATE
Sum of all aggregate options.- See Also:
- Constant Field Values
-
OPT_AGGREGATE_NON_COUNT_PC
public static final int OPT_AGGREGATE_NON_COUNT_PC
Sum of all aggregate options excluding count on persistent capable objects.- See Also:
- Constant Field Values
-
OPT_ADD_FETCHGROUPS
public static final int OPT_ADD_FETCHGROUPS
Indicates, that fetch group fields should be added.- See Also:
- Constant Field Values
-
OPT_ADD_KEYS_ONLY
public static final int OPT_ADD_KEYS_ONLY
Indicates, that only key fields should be added. When this option is set, it modifies meaning of OPT_ADD_FETCHGROUPS. It is assumed that only key fieldes from the fetch group will be added.- See Also:
- Constant Field Values
-
OPT_DISABLE_RELATIONSHIP_PREFETCH
public static final int OPT_DISABLE_RELATIONSHIP_PREFETCH
Indicates, that even if relationship fields are in DFG, they should not be prefetched. The runtime will attempt to fetch relationhip fields only when OPT_ADD_FETCH_GROUPS is set.
-
OPT_VERIFY
public static final int OPT_VERIFY
Indicates special treatment for version consistency verifications.- See Also:
- Constant Field Values
-
-
Method Detail
-
addResult
public void addResult(String name, RetrieveDesc foreignConstraint, boolean projection)
The addResult method is used to specify which fields should be returned in a persistent object. If the field requested is a reference to another persistent object then a RetrieveDesc may be provided which describes which fields of the referenced object should be returned and, optionally, constraints on it. If the parameterprojection
is true, the field specified byname
should be projected.- Specified by:
addResult
in interfaceRetrieveDesc
- Parameters:
name
- The name of the field to return.foreignConstraint
- RetrieveDesc describing fields and constraints for a referenced object.projection
- Specifies, if this is a projection.
-
addResult
public void addResult(int opCode, int aggregateResultType)
The addResult method can be used to specifyglobal query attributes that don't end up in the where clause. Aggregate functions and the distinct op code are examples for those query options. The result type defines the object to be returned by an aggregate query. In case of distinct the result type should be FieldTypeEnumeration.NOT_ENUMERATED. The method might be called twice, in case of a JDOQL query having both an aggregate and distinct: query.setResult("avg (distinct salary)"); -> retrieveDesc.addResult(OP_AVG, FieldTypeEnumeration.DOUBLE); retrieveDesc.addResult(OP_DISTINCT, FieldTypeEnumeration.NOT_ENUMERATED); retrieveDesc.addResult("salary", null, true);- Specified by:
addResult
in interfaceRetrieveDesc
- Parameters:
opCode
- The operation code.aggregateResultType
- The object type returned by aggregate queries.- See Also:
FieldTypeEnumeration
-
addPrefetchedField
public void addPrefetchedField(String name, RetrieveDesc foreignConstraint)
Add a field specified byname
to the list of fields to be prefetched.- Parameters:
name
- Name of the field to be prefetched.foreignConstraint
- This parameter is null if the field is a local field. If the field is a foreign field, this parameter should be not null and must refer to an instance of RetrieveDesc correpsonding to the config of the foreign field.
-
setPrefetchEnabled
public void setPrefetchEnabled(boolean prefetchEnabled)
Sets the prefetchEnabled option. The prefetchEnabled option specifies whether prefetch of relationship fields should be enabled for this retrieve descriptor. The prefetch is enabled by default if such fields are part of DFG. A user needs to explicitely disable prefetch for any particular query if the related instances will not be used in this transaction.- Specified by:
setPrefetchEnabled
in interfaceRetrieveDesc
- Parameters:
prefetchEnabled
- the setting of the prefetchEnabled option.
-
addConstraint
public void addConstraint(String name, RetrieveDesc foreignConstraint)
Adds a constraint on the foreign field specified by
name
. This method is used to specify a relationship navigation on fieldname
to the class represented by the retrieve descriptorforeignConstraint
. Ifname
is null, an unrelated constraint is added. A constraint is unrelated, if there is neither a foreign field nor a local field connecting to the retrieve descriptorforeignConstraint
.- Specified by:
addConstraint
in interfaceRetrieveDesc
-
addConstraint
public void addConstraint(String name, int operation, RetrieveDesc foreignConstraint, String foreignName)
Adds a constraint on the relationship field specified by
name
. This method is useful e.g. for comparisons of local fields with field of a related object: emp.addConstraint("lastName", ActionDesc.OP_EQ, mgr, lastName"); compares the employee's lastName field with the lastName field of the related manager.- Specified by:
addConstraint
in interfaceRetrieveDesc
-
addConstraint
public void addConstraint(String name, int operation, Object value)
The addConstraint method is used to limit the values of fields for objects being selected. addConstraint pushes the value, name, and operation onto the Constraint stack. The constraints are anded together by default. Arbitrarily complex relationships on the Constraint stack are supported. The Constraint stack can be manipulated directly if necessary.- Specified by:
addConstraint
in interfaceRetrieveDesc
- Parameters:
name
- The name parameter specifies the field whose value should be limited.operation
- The operation parameter specifies the relationship the field should bear to the value. Values for operation are defined in the ActionDesc interface.value
- The value parameter usually specifies the value to which the field should be limited, however it is sometimes used to hold a parameter count as for the OP_IN operation.
-
addParameterConstraints
public void addParameterConstraints(LocalFieldDesc[] fields, int startIndex)
Add Constraints corresponding to givenfields
. The constraints are added as Parameter Constraints. index of the parameter starts at givenstartIndex
- Parameters:
fields
- fields for which constraints are to be added.startIndex
- starting Index for the parameter.
-
addParameterConstraint
public void addParameterConstraint(LocalFieldDesc field, int index)
Add ParameterConstraint corresponding to givenfield
at givenindex
.- Parameters:
field
- The field for which constraints are to be added.index
- Index at which the ParameterConstraint is to be inserted.
-
buildQueryPlan
public SelectQueryPlan buildQueryPlan(SQLStoreManager store, Concurrency concurrency)
Builds the internal query plan and initializes the select statements. Projections on collection fields will not be resolved until the actual retrieval inSQLStoreManager.retrieve( com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager, RetrieveDesc, com.sun.jdo.spi.persistence.support.sqlstore.ValueFetcher)
.
-
setNavigationalId
public void setNavigationalId(Object navigationalId)
Sets a navigational id on the retrieve descriptor. This id will be used to discriminate different retrieve descriptors which use the same navigational field. If not set, the field name is used.- Specified by:
setNavigationalId
in interfaceRetrieveDesc
- Parameters:
navigationalId
- Tag to discriminate different retrieve descriptors that use the same navigational field.
-
getNavigationalId
public Object getNavigationalId()
Returns the navigational id of this retrieve descriptor. This id will be used to discriminate different retrieve descriptors which use the same navigational field. If not set, the field name is used.- Returns:
- Tag to discriminate different retrieve descriptors that use the same navigational field.
-
setOption
public void setOption(int option)
Sets optionoption
. Only used to mark this retrieve descriptor as internal. All valid options are defined in this class.- Parameters:
option
- Option being set.
-
getAggregateResultType
public int getAggregateResultType()
Returns the result type for aggregate queries.
-
getOptions
public int getOptions()
Returns the options of this retrieve descriptor.- Returns:
- The options of this retrieve descriptor.
-
getPlan
public SelectQueryPlan getPlan()
-
getConfig
public ClassDesc getConfig()
-
setPlan
public void setPlan(SelectQueryPlan plan)
-
getPersistenceCapableClass
public Class getPersistenceCapableClass()
- Specified by:
getPersistenceCapableClass
in interfaceActionDesc
-
getConstraint
public Constraint getConstraint()
-
getFields
public Iterator getFields()
-
-