Fields Summary |
---|
private static final int | OPINFO_FIELD_DISALLOWED |
private static final int | OPINFO_FIELD_REQUIRED |
private static final int | OPINFO_VAL_DISALLOWED |
private static final int | OPINFO_VAL_REQUIRED |
private static final int | OPINFO_VAL_IS_PCOUNT |
private static final int | OPINFO_ILLEGAL |
private static final int | OPINFO_NO_OPERATION |
public static final int | OPT_PROJECTIONIndicates, that the query projects on this RD. |
public static final int | OPT_DISTINCTIndicates, that a distinct query should be run. |
public static final int | OPT_FOR_UPDATEIndicates, that the selected rows should be locked for update. |
public static final int | OPT_AVGIndicates, that an avg aggregate query should be run. |
public static final int | OPT_MINIndicates, that a min aggregate query should be run. |
public static final int | OPT_MAXIndicates, that a max aggregate query should be run. |
public static final int | OPT_SUMIndicates, that a sum aggregate query should be run. |
public static final int | OPT_COUNTIndicates, that a count aggregate query should be run. |
public static final int | OPT_COUNT_PCSpecial treatment for count on persistent capable objects. |
public static final int | OPT_AGGREGATESum of all aggregate options. |
public static final int | OPT_AGGREGATE_NON_COUNT_PCSum of all aggregate options excluding count on persistent capable objects. |
public static final int | OPT_ADD_FETCHGROUPSIndicates, that fetch group fields should be added. |
public static final int | OPT_ADD_KEYS_ONLYIndicates, 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. |
public static final int | OPT_DISABLE_RELATIONSHIP_PREFETCHIndicates, 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. |
public static final int | OPT_VERIFYIndicates special treatment for version consistency verifications. |
private ArrayList | fieldsArray of ConstraintFieldName. |
private com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.Constraint | constraintThe constraint stack |
private int | optionsBitmask of options for this instance as specified by the OPT_* constants |
private Class | pcClassCandidate class of this instance |
private com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc | configConfig for candidate class of this instance |
private com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.SelectQueryPlan | planSelectQueryPlan for this instance |
private Object | navigationalIdDiscriminates different retrieve descriptors which use the same
navigational field. |
private int | aggregateResultTypeResult type for an aggregate query. |
private static final ResourceBundle | messagesI18N message handler |
Methods Summary |
---|
public void | addConstraint(java.lang.String name, com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc foreignConstraint)Adds a constraint on the foreign field specified by
name . This method is used to specify a relationship
navigation on field name to the class represented by
the retrieve descriptor foreignConstraint .
If name 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 descriptor
foreignConstraint .
if (name == null) {
constraint.addField(null, foreignConstraint);
} else {
constraint.addForeignField(name, foreignConstraint);
}
|
public void | addConstraint(java.lang.String name, int operation, com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc foreignConstraint, java.lang.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.
constraint.addField(foreignName, foreignConstraint);
constraint.addField(name, null);
constraint.addOperation(operation);
|
public void | addConstraint(java.lang.String name, int operation, java.lang.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.
int info = getOperationInfo(operation);
if ((info & OPINFO_ILLEGAL) > 0) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.illegalop", "" + operation)); // NOI18N
} else if ((info & OPINFO_FIELD_REQUIRED) > 0 && name == null) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.fieldrequired", "" + operation)); // NOI18N
} else if ((info & OPINFO_FIELD_DISALLOWED) > 0 && name != null) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.fielddisallowed", "" + operation)); // NOI18N
} else if ((info & OPINFO_VAL_REQUIRED) > 0 && value == null) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.valrequired", "" + operation)); // NOI18N
} else if ((info & OPINFO_VAL_DISALLOWED) > 0 && value != null) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.valdisallowed", "" + operation)); // NOI18N
}
if ((info & OPINFO_VAL_IS_PCOUNT) > 0) {
if (name != null) {
constraint.addField(name, null);
}
addValueConstraint(name, value);
} else {
switch (operation) {
case RetrieveDescImpl.OP_PARAMETER:
addParameterConstraint(value);
break;
case ActionDesc.OP_IN:
case ActionDesc.OP_NOTIN:
constraint.addConstraintFieldSubQuery(name,(ActionDesc) value);
break;
default:
if (value != null) {
addValueConstraint(name, value);
}
if (name != null) {
constraint.addField(name, null);
}
break;
}
}
if ((info & OPINFO_NO_OPERATION) == 0) {
constraint.addOperation(operation);
}
|
public void | addParameterConstraint(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc field, int index)Add ParameterConstraint corresponding to given field
at given index .
// Generate parameter info for this parameter.
String fieldName = field.getName();
int type = field.getEnumType();
addConstraint(null, ActionDesc.OP_PARAMETER,new ParameterInfo(index, type, fieldName));
addConstraint(fieldName, ActionDesc.OP_FIELD, null);
addConstraint(null, ActionDesc.OP_EQ, null);
|
private void | addParameterConstraint(java.lang.Object value)Adds information about parameter on the constraint stack.
if (value instanceof ParameterInfo) {
ParameterInfo parameterInfo = (ParameterInfo)value;
constraint.addParamIndex(parameterInfo.getIndex(), parameterInfo.getType(),
getLocalFieldDesc(parameterInfo.getAssociatedField()));
} else {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.illegalParameterInfo")); // NOI18N
}
|
public void | addParameterConstraints(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc[] fields, int startIndex)Add Constraints corresponding to given fields .
The constraints are added as Parameter Constraints.
index of the parameter starts at given startIndex
for (int i = 0; i < fields.length; i++) {
LocalFieldDesc field = fields[i];
addParameterConstraint(field, i + startIndex);
}
|
public void | addPrefetchedField(java.lang.String name, com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc foreignConstraint)Add a field specified by name to the list of fields to be prefetched.
fields.add(new ConstraintFieldName(name, foreignConstraint, true));
|
public void | addResult(java.lang.String name, com.sun.jdo.spi.persistence.support.sqlstore.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 parameter projection is true, the field
specified by name should be projected.
ConstraintFieldName cfName = new ConstraintFieldName(name, foreignConstraint);
if (projection) {
if ((options & OPT_PROJECTION) > 0) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"sqlstore.retrievedesc.toomanyprojections")); // NOI18N
}
// For projections on foreign fields, mark the foreign constraint.
// For local fields, set the property on the field constraint.
if (foreignConstraint != null) {
((RetrieveDescImpl) foreignConstraint).options |= OPT_PROJECTION;
} else {
cfName.setProjection();
// Set this property if you want to have DFG fields added for
// projections on local fields.
// options = options | OPT_PROJECTION;
}
}
fields.add(cfName);
|
public void | addResult(int opCode, int aggregateResultType)The addResult method can be used to specify global
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);
switch (opCode) {
case ActionDesc.OP_DISTINCT:
options = options | OPT_DISTINCT;
break;
case ActionDesc.OP_AVG:
options = options | OPT_AVG;
break;
case ActionDesc.OP_MIN:
options = options | OPT_MIN;
break;
case ActionDesc.OP_MAX:
options = options | OPT_MAX;
break;
case ActionDesc.OP_SUM:
options = options | OPT_SUM;
break;
case ActionDesc.OP_COUNT:
options = options | OPT_COUNT;
break;
case ActionDesc.OP_COUNT_PC:
options = options | OPT_COUNT_PC;
break;
default:
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.illegalop", "" + opCode)); // NOI18N
}
if (aggregateResultType != FieldTypeEnumeration.NOT_ENUMERATED) {
if (this.aggregateResultType == FieldTypeEnumeration.NOT_ENUMERATED) {
this.aggregateResultType = aggregateResultType;
} else {
// aggregate result type has already been set
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"sqlstore.retrievedesc.toomanyresulttypes")); // NOI18N
}
}
|
private void | addValueConstraint(java.lang.String name, java.lang.Object value)Adds information about value on the constraint stack.
constraint.addValue(value, getLocalFieldDesc(name));
|
public synchronized com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.SelectQueryPlan | buildQueryPlan(com.sun.jdo.spi.persistence.support.sqlstore.SQLStoreManager store, com.sun.jdo.spi.persistence.support.sqlstore.sql.concurrency.Concurrency concurrency)Builds the internal query plan and initializes the select statements.
Projections on collection fields will not be resolved until the actual
retrieval in {@link SQLStoreManager#retrieve(
com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager,
RetrieveDesc, com.sun.jdo.spi.persistence.support.sqlstore.ValueFetcher)}.
if (plan == null) {
handleProjection();
plan = SelectQueryPlan.newInstance(this, store, concurrency);
plan.build();
// Generate the text for the select statements.
ArrayList statements = plan.getStatements();
// Sanity check.
if (statements.size() > 1) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"sqlstore.retrievedesc.stmntsnotjoined")); // NOI18N
}
}
return plan;
|
public java.lang.Object | clone()
try {
RetrieveDescImpl clone = (RetrieveDescImpl) super.clone();
clone.fields = new ArrayList();
clone.constraint = new Constraint();
return clone;
} catch (CloneNotSupportedException e) {
//
// shouldn't happen.
//
return null;
}
|
private com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl | distributeQueryOptions(int queryOptions, int aggregateResultType)Marks each descriptor with the options queryOptions and
finds the projection in the retrieve descriptor hierarchy.
The query options have to be known for each descriptor, because we don't want to
generate outer joins for OPT_COUNT_PC and we want to propagate users
choice to disable prefetch for a finder to projected RetrieveDesc.
This method relies on the fact, that each query can have only
one projection.
RetrieveDescImpl projectedDesc = null;
if ((options & OPT_PROJECTION) > 0) {
// This is a foreign field projection.
// Set the fetch group properties.
setFetchGroupOptions(queryOptions);
this.aggregateResultType = aggregateResultType;
projectedDesc = this;
}
// Distribute the aggregate option to all retrieve descriptors.
options |= queryOptions;
// Loop through all dependent retrieve descriptors in the field list.
for (int i = 0; i < fields.size(); i++) {
ConstraintFieldName cfn = (ConstraintFieldName) fields.get(i);
if (cfn.isProjection()) {
// This is a local field projection.
// No fetch groups are added.
this.aggregateResultType = aggregateResultType;
projectedDesc = this;
} else if (cfn.desc != null) {
projectedDesc = ((RetrieveDescImpl) cfn.desc).distributeQueryOptions(
queryOptions, aggregateResultType);
}
}
return projectedDesc;
|
public int | getAggregateResultType()Returns the result type for aggregate queries.
return aggregateResultType;
|
public com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc | getConfig()
return config;
|
public com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.Constraint | getConstraint()
return constraint;
|
public java.util.Iterator | getFields()
return fields.iterator();
|
private com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc | getLocalFieldDesc(java.lang.String name)Returns the local field descriptor for the field name .
Delegates to ClassDesc#getLocalFieldDesc(String).
return name == null ? null : config.getLocalFieldDesc(name);
|
public java.lang.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.
return navigationalId;
|
private static int | getOperationInfo(int operation)The getOperationInfo method returns information about the operation
requested. The following constants define different properties of
an operation and can be or'd together:
OPINFO_FIELD_DISALLOWED A field parameter cannot be specified
with this operation
OPINFO_FIELD_REQUIRED A field parameter must be specified
with this operation
OPINFO_VAL_DISALLOWED A value parameter cannot be specified
with this operation
OPINFO_VAL_REQUIRED A value parameter must be specified
with this operation
OPINFO_NULL This operation is a "null" type operation
(i.e. "is null", or "is not null")
OPINFO_ILLEGAL This operation is illegal
OPINFO_NO_OPERATION This isn't an operation at all,
it is some other specifier.
OPINFO_VAL_IS_PCOUNT This operation has a value which is the
parameter count of following parameter
nodes
int info;
switch (operation) {
case ActionDesc.OP_ABS:
info = OPINFO_VAL_DISALLOWED;
break;
case ActionDesc.OP_ADD:
info = 0;
break;
case ActionDesc.OP_AND:
info = 0;
break;
case ActionDesc.OP_FIELD:
info = OPINFO_FIELD_REQUIRED | OPINFO_VAL_DISALLOWED | OPINFO_NO_OPERATION;
break;
case ActionDesc.OP_BETWEEN:
info = 0;
break;
case ActionDesc.OP_DIV:
info = 0;
break;
case ActionDesc.OP_EQ:
info = 0;
break;
case ActionDesc.OP_NE:
info = 0;
break;
case ActionDesc.OP_EQUIJOIN:
info = 0;
break;
case ActionDesc.OP_NOT:
info = OPINFO_FIELD_DISALLOWED | OPINFO_VAL_DISALLOWED;
break;
case ActionDesc.OP_GE:
info = 0;
break;
case ActionDesc.OP_GT:
info = 0;
break;
case ActionDesc.OP_IN:
case ActionDesc.OP_NOTIN:
info = OPINFO_FIELD_REQUIRED | OPINFO_VAL_REQUIRED;
break;
case ActionDesc.OP_LE:
info = 0;
break;
case ActionDesc.OP_LEFTJOIN:
info = 0;
break;
case ActionDesc.OP_LENGTH:
info = OPINFO_VAL_DISALLOWED;
break;
case ActionDesc.OP_LIKE:
info = 0;
break;
case ActionDesc.OP_LIKE_ESCAPE:
info = 0;
break;
case ActionDesc.OP_LT:
info = 0;
break;
case ActionDesc.OP_LTRIM:
info = OPINFO_VAL_DISALLOWED;
break;
case ActionDesc.OP_MUL:
info = 0;
break;
case ActionDesc.OP_OR:
info = 0;
break;
case ActionDesc.OP_ORDERBY:
info = 0;
break;
case ActionDesc.OP_ORDERBY_DESC:
info = 0;
break;
case ActionDesc.OP_PARAMETER_COUNT:
info = OPINFO_FIELD_DISALLOWED | OPINFO_VAL_REQUIRED | OPINFO_VAL_IS_PCOUNT | OPINFO_NO_OPERATION;
break;
case ActionDesc.OP_RIGHTJOIN:
info = 0;
break;
case ActionDesc.OP_RTRIM:
info = OPINFO_VAL_DISALLOWED;
break;
case ActionDesc.OP_SQRT:
info = OPINFO_VAL_DISALLOWED;
break;
case ActionDesc.OP_SUB:
info = 0;
break;
case ActionDesc.OP_SUBSTRING:
info = 0;
break;
case ActionDesc.OP_POSITION:
info = 0;
break;
case ActionDesc.OP_POSITION_START:
info = 0;
break;
case ActionDesc.OP_MAYBE_NULL:
info = OPINFO_FIELD_REQUIRED;
break;
case ActionDesc.OP_CONCAT:
info = 0;
break;
case ActionDesc.OP_VALUE:
info = OPINFO_FIELD_DISALLOWED | OPINFO_VAL_REQUIRED | OPINFO_NO_OPERATION;
break;
case ActionDesc.OP_PARAMETER:
info = OPINFO_FIELD_DISALLOWED | OPINFO_VAL_REQUIRED | OPINFO_NO_OPERATION;
break;
case OP_NULL:
case OP_NOTNULL:
info = 0;
break;
case ActionDesc.OP_MOD:
info = 0;
break;
default:
info = OPINFO_ILLEGAL;
break;
}
return info;
|
public int | getOptions()Returns the options of this retrieve descriptor.
return options;
|
public java.lang.Class | getPersistenceCapableClass()
return pcClass;
|
public com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.SelectQueryPlan | getPlan()
return plan;
|
private void | handleProjection()Sets the fetch group options for all retrieve descriptors in the
retrieve descriptor hierarchy. This is important for projection and
aggregate queries, as we don't want to select additional fields
from the data store. This is also important for queries where relationship
prefetch is involved, as we want to propagate user's choice to disable
relationship prefetch for a finder to all the retrieve descriptors in
the projection tree.
Also sets the projection on the candidate class in case of queries without
user projection.
// Prepare all the query options that need to be distributed to all the
// RetrieveDescs involved in the projection tree.
final int queryOptions = options & (OPT_AGGREGATE | OPT_DISABLE_RELATIONSHIP_PREFETCH);
RetrieveDescImpl projectedDesc = distributeQueryOptions(
queryOptions, aggregateResultType);
if (projectedDesc == null) {
// Set the default projection on the candidate retrieve descriptor.
options |= OPT_PROJECTION;
// Prepare fetch group options again after default projection has been set.
setFetchGroupOptions(queryOptions);
}
|
private void | setFetchGroupOptions(int queryOptions)Sets the fetch group policy for the projected retrieve descriptor.
The policy is based on the following rules:
- Fetchgroups are added for a projection w/o aggregates.
- Only keys are added for count(*) queries.
if ((queryOptions & OPT_AGGREGATE_NON_COUNT_PC) == 0) {
// Don't add fetch groups except for projections
// w/o aggregates or counts on persistence capable objects.
options |= OPT_ADD_FETCHGROUPS;
if (queryOptions == OPT_COUNT_PC) {
options |= OPT_ADD_KEYS_ONLY;
}
}
|
public void | setNavigationalId(java.lang.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.
this.navigationalId = navigationalId;
|
public void | setOption(int option)Sets option option . Only used to mark this
retrieve descriptor as internal. All valid options are defined
in this class.
this.options |= option;
|
public void | setPlan(com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.SelectQueryPlan plan)
this.plan = plan;
|
public void | setPrefetchEnabled(boolean prefetchEnabled){@inheritDoc}
if (!prefetchEnabled) {
options |= OPT_DISABLE_RELATIONSHIP_PREFETCH;
} else {
// options has the flag OPT_DISABLE_RELATIONSHIP_PREFETCH unset by default
}
|