use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.
the class SelectQueryPlan method addCorrelatedInQuery.
/**
* Creates and builds a correlated "In" subquery.
* Merges tables from the subquery plan to the current plan and adds
* the local fields corresponding to the subquery to the constaints.
* The subquery is added to the constraint stack.
*
* @param node subquery constraint.
*/
private void addCorrelatedInQuery(ConstraintFieldNameSubQuery node) {
FieldDesc field = config.getField(node.fieldName);
RetrieveDescImpl rd = (RetrieveDescImpl) node.desc;
if (field != null && field instanceof ForeignFieldDesc) {
ForeignFieldDesc ff = (ForeignFieldDesc) field;
if (ff.getComponentType() != rd.getPersistenceCapableClass()) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
"core.constraint.unknownfield", node.fieldName, rd.getPersistenceCapableClass().getName()));
}
SelectQueryPlan subqueryPlan = new CorrelatedInSelectPlan(rd, store, ff, this);
subqueryPlan.build();
// Make the tables involved in the subquery known to the parent query.
addQueryTables(subqueryPlan.tables);
// Push a new subquery constraint on the stack
ConstraintSubquery subqueryConstraint = new ConstraintSubquery();
subqueryConstraint.plan = subqueryPlan;
constraint.stack.add(subqueryConstraint);
ArrayList localFields = ff.getLocalFields();
// Add the local fields corresponding to the subquery to the stack.
for (int i = 0; i < localFields.size(); i++) {
constraint.addField((LocalFieldDesc) localFields.get(i), this);
}
} else {
// or the field is not present in the config.
throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
"core.constraint.unknownfield", node.fieldName, rd.getPersistenceCapableClass().getName()));
}
}
use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.
the class SelectQueryPlan method addFetchGroup.
/**
* Add the fields from the fetch group specified by <code>groupID</code>
* to the list of selected fields. The decision which fields are
* added is based on the following rules:
*
* <ol>
* <li>Local fields are added for all the queries and user
* projections, that aren't aggregates.</li>
* <li>Only key fields are added for aggregate queries counting persistence capable objects.</li>
* <li>Foreign fields are added only for the projected retrieve descriptor and for
* queries that do not have relationsip prefetch disabled. <li>
* </ol>
*
* @param groupID Fetch group id.
* @param localFields List of fields to be selected.
* @param foreignFields List of foreign fields connecting to foreign plans.
*/
private void addFetchGroup(int groupID, ArrayList localFields, ArrayList foreignFields) {
// We should enter this method only if OPT_ADD_FETCHGROUPS is set.
assert (options & RetrieveDescImpl.OPT_ADD_FETCHGROUPS) > 0;
ArrayList group = config.getFetchGroup(groupID);
setGroupMask(groupID);
if (group != null) {
for (int i = 0; i < group.size(); i++) {
FieldDesc f = (FieldDesc) group.get(i);
if (!getFieldMask(f.absoluteID)) {
final boolean isLocalField = f instanceof LocalFieldDesc;
// Prevent testing field again.
setFieldMask(f.absoluteID);
if (isLocalField) {
if ((options & RetrieveDescImpl.OPT_ADD_KEYS_ONLY) == 0 || f.isKeyField()) {
// pk fields are added before any other fields already
// present in localFields. This is because pk fields
// are the first to be read when resultset is processed.
// Please see IN=8852 for more details.
// All other fields are appended to the list.
int indexToInsert = (f.isKeyField() ? 0 : localFields.size());
localFields.add(indexToInsert, f);
}
} else {
// disabled by the user.
if (((options & RetrieveDescImpl.OPT_PROJECTION) > 0 || MULTILEVEL_PREFETCH) && (options & RetrieveDescImpl.OPT_ADD_KEYS_ONLY) == 0 && (options & RetrieveDescImpl.OPT_DISABLE_RELATIONSHIP_PREFETCH) == 0) {
// Add current field to foreignFields as ConstraintFieldName
ForeignFieldDesc ff = (ForeignFieldDesc) f;
RetrieveDescImpl desc = (RetrieveDescImpl) store.getRetrieveDesc(ff.foreignConfig.getPersistenceCapableClass());
foreignFields.add(new ConstraintFieldName(ff.getName(), desc, true));
}
}
}
}
}
}
use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.
the class SelectQueryPlan method addCorrelatedExistsQuery.
/**
* Adds a subquery constraint for a correlated exists query to the
* constraint stack. Also add the table alias from the subquery
* to the local table aliases.
*
* @param ff The relationship field for the subquery
* @param operation {@link ActionDesc#OP_NOTEXISTS}
* or {@link ActionDesc#OP_EXISTS}.
*/
private void addCorrelatedExistsQuery(ForeignFieldDesc ff, int operation) {
Class classType = (ff.cardinalityUPB > 1) ? ff.getComponentType() : ff.getType();
RetrieveDescImpl rd = (RetrieveDescImpl) store.getRetrieveDesc(classType);
SelectQueryPlan subqueryPlan = new CorrelatedExistSelectPlan(rd, store, ff, this);
subqueryPlan.build();
// Make the tables involved in the subquery known to the parent query.
addQueryTables(subqueryPlan.tables);
ConstraintSubquery subqueryConstraint = new ConstraintSubquery();
subqueryConstraint.operation = operation;
subqueryConstraint.plan = subqueryPlan;
constraint.stack.add(subqueryConstraint);
}
use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.
the class SelectQueryPlan method processLocalConstraints.
/**
* Asociates every local constraint on the stack with it's original plan
* and include any table that hasn't been added to the table list of the
* corresponding original plan.
*
* @see ConstraintFieldName#originalPlan
*/
private void processLocalConstraints() {
List stack = constraint.getConstraints();
for (int i = 0; i < stack.size(); i++) {
ConstraintNode node = (ConstraintNode) stack.get(i);
if (node instanceof ConstraintFieldName) {
ConstraintFieldName fieldNode = (ConstraintFieldName) node;
if (fieldNode.originalPlan == null) {
// The field has not been processed before
SelectQueryPlan thePlan = null;
if (fieldNode.desc == null) {
thePlan = this;
} else {
// If the field belongs to a different RetrieveDesc, we need
// to use the query plan associated with that RetrieveDesc.
RetrieveDescImpl rd = (RetrieveDescImpl) fieldNode.desc;
thePlan = newForeignConstraintPlan(rd, fieldNode.name);
}
fieldNode.originalPlan = thePlan;
// The name field is null for unrelated constraints.
if (fieldNode.name != null) {
FieldDesc field = thePlan.config.getField(fieldNode.name);
if (field instanceof LocalFieldDesc) {
// Adds the statement and table for the field.
// This is only required to process plans corresponding
// to query filters containing unbound variables
// e.g. setFilter("empid == d.deptid") on an employee query.
thePlan.addTable((LocalFieldDesc) field);
}
}
}
}
}
}
use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.
the class ClassDesc method getRetrieveDescForPKQuery.
/**
* Returns a RetrieveDescriptor which represent a SQL query selecting a pc
* instance by pk-fields. Please note that the RDs are cached, so the method
* first checks the cache. If there is no corresponding RetrieveDescriptor
* in the cache, it creates a new one and stores it in the cache. If the
* additionalField is not null, the method retrieves the field indicated by
* it along with the query. Fetch group fields will be added when the query
* plan is build.
*
* Note, the reason to introduce the RetrieveDesc cache in ClassDesc and not
* in the store manager is, that we can have the cache per class, where
* the store manager could only provide one big cache for all pc classes.
*
* @param additionalField The field to be retrieved in addition to the
* DFG fields.
* @param store The store manager.
* @return A RetrieveDescriptor selecting a pc instance by pk-fields.
* @see #getRetrieveDescForFKQuery
*/
public RetrieveDesc getRetrieveDescForPKQuery(FieldDesc additionalField, PersistenceStore store) {
RetrieveDescImpl rd = null;
String cacheKey = generateRDCacheKey(additionalField);
synchronized (retrieveDescCache) {
// Cache lookup.
rd = (RetrieveDescImpl) retrieveDescCache.get(cacheKey);
// Generate a new RD if there isn't one be found in the cache.
if (rd == null) {
rd = (RetrieveDescImpl) store.getRetrieveDesc(pcClass);
if (additionalField != null) {
RetrieveDesc frd = null;
String name = additionalField.getName();
// the field indicated by it along with the query.
if (additionalField instanceof ForeignFieldDesc) {
Class additionalClass = ((ForeignFieldDesc) additionalField).foreignConfig.getPersistenceCapableClass();
frd = store.getRetrieveDesc(additionalClass);
}
rd.addPrefetchedField(name, frd);
}
addPKConstraints(rd);
// Cache fillup.
retrieveDescCache.put(cacheKey, rd);
}
}
return rd;
}
Aggregations