use of org.eclipse.persistence.internal.expressions.QueryKeyExpression in project eclipselink by eclipse-ee4j.
the class ObjectBuilder method loadJoinedAttributes.
protected void loadJoinedAttributes(ClassDescriptor concreteDescriptor, Object sourceObject, CacheKey cacheKey, AbstractRecord databaseRow, JoinedAttributeManager joinManager, ObjectBuildingQuery query, boolean isTargetProtected) {
boolean useOnlyMappingsExcludedFromSOP = false;
if (concreteDescriptor.hasSerializedObjectPolicy() && query.shouldUseSerializedObjectPolicy()) {
// sopObject has not been deserialized, sourceObject must be cached
useOnlyMappingsExcludedFromSOP = databaseRow.get(concreteDescriptor.getSerializedObjectPolicy().getField()) != null;
}
Boolean isUntriggeredResultSetRecord = null;
List<Expression> joinExpressions = joinManager.getJoinedAttributeExpressions();
int size = joinExpressions.size();
for (int index = 0; index < size; index++) {
QueryKeyExpression queryKeyExpression = (QueryKeyExpression) joinExpressions.get(index);
QueryKeyExpression baseExpression = (QueryKeyExpression) joinManager.getJoinedAttributes().get(index);
DatabaseMapping mapping = joinManager.getJoinedAttributeMappings().get(index);
// Only worry about immediate (excluding aggregates) foreign reference mapping attributes.
if (queryKeyExpression == baseExpression) {
if (mapping == null) {
throw ValidationException.missingMappingForAttribute(concreteDescriptor, queryKeyExpression.getName(), toString());
} else {
if (!useOnlyMappingsExcludedFromSOP || mapping.isOutSopObject()) {
// get the intermediate objects between this expression node and the base builder
Object intermediateValue = joinManager.getValueFromObjectForExpression(query.getExecutionSession(), sourceObject, (ObjectExpression) baseExpression.getBaseExpression());
// Bug 4230655 - do not replace instantiated valueholders.
Object attributeValue = mapping.getAttributeValueFromObject(intermediateValue);
if ((attributeValue != null) && mapping.isForeignReferenceMapping() && ((ForeignReferenceMapping) mapping).usesIndirection() && (!((ForeignReferenceMapping) mapping).getIndirectionPolicy().objectIsInstantiated(attributeValue))) {
if (mapping.isObjectReferenceMapping() && ((ObjectReferenceMapping) mapping).isForeignKeyRelationship() && !mapping.isPrimaryKeyMapping()) {
if (isUntriggeredResultSetRecord == null) {
isUntriggeredResultSetRecord = databaseRow instanceof ResultSetRecord && ((ResultSetRecord) databaseRow).hasResultSet();
}
if (isUntriggeredResultSetRecord) {
for (DatabaseField field : mapping.getFields()) {
// extract the values from ResultSet into the row
databaseRow.get(field);
}
}
}
AbstractSession session = query.getExecutionSession();
mapping.readFromRowIntoObject(databaseRow, joinManager, intermediateValue, cacheKey, query, query.getExecutionSession(), isTargetProtected);
session.getIdentityMapAccessorInstance().getIdentityMap(concreteDescriptor).lazyRelationshipLoaded(intermediateValue, (ValueHolderInterface) ((ForeignReferenceMapping) mapping).getIndirectionPolicy().getOriginalValueHolder(attributeValue, session), (ForeignReferenceMapping) mapping);
}
}
}
}
}
}
use of org.eclipse.persistence.internal.expressions.QueryKeyExpression in project eclipselink by eclipse-ee4j.
the class ObjectBuilder method loadBatchReadAttributes.
protected void loadBatchReadAttributes(ClassDescriptor concreteDescriptor, Object sourceObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, boolean isTargetProtected) {
boolean useOnlyMappingsExcludedFromSOP = false;
if (concreteDescriptor.hasSerializedObjectPolicy() && query.shouldUseSerializedObjectPolicy()) {
// if true then sopObject has not been deserialized, that means sourceObject has been cached.
useOnlyMappingsExcludedFromSOP = databaseRow.get(concreteDescriptor.getSerializedObjectPolicy().getField()) != null;
}
boolean isUntriggeredResultSetRecord = databaseRow instanceof ResultSetRecord && ((ResultSetRecord) databaseRow).hasResultSet();
List<Expression> batchExpressions = ((ReadAllQuery) query).getBatchReadAttributeExpressions();
int size = batchExpressions.size();
for (int index = 0; index < size; index++) {
QueryKeyExpression queryKeyExpression = (QueryKeyExpression) batchExpressions.get(index);
// Only worry about immediate attributes.
if (queryKeyExpression.getBaseExpression().isExpressionBuilder()) {
DatabaseMapping mapping = getMappingForAttributeName(queryKeyExpression.getName());
if (mapping == null) {
throw ValidationException.missingMappingForAttribute(concreteDescriptor, queryKeyExpression.getName(), this.toString());
} else {
if (!useOnlyMappingsExcludedFromSOP || mapping.isOutSopObject()) {
// Bug 4230655 - do not replace instantiated valueholders.
Object attributeValue = mapping.getAttributeValueFromObject(sourceObject);
if ((attributeValue != null) && mapping.isForeignReferenceMapping() && ((ForeignReferenceMapping) mapping).usesIndirection() && (!((ForeignReferenceMapping) mapping).getIndirectionPolicy().objectIsInstantiated(attributeValue))) {
if (isUntriggeredResultSetRecord && mapping.isObjectReferenceMapping() && ((ObjectReferenceMapping) mapping).isForeignKeyRelationship() && !mapping.isPrimaryKeyMapping()) {
// still need to extract values from ResultSet for foreign key fields.
for (DatabaseField field : mapping.getFields()) {
// extract the values from ResultSet into the row
databaseRow.get(field);
}
}
AbstractSession session = query.getExecutionSession();
mapping.readFromRowIntoObject(databaseRow, joinManager, sourceObject, cacheKey, query, query.getExecutionSession(), isTargetProtected);
session.getIdentityMapAccessorInstance().getIdentityMap(concreteDescriptor).lazyRelationshipLoaded(sourceObject, (ValueHolderInterface) ((ForeignReferenceMapping) mapping).getIndirectionPolicy().getOriginalValueHolder(attributeValue, session), (ForeignReferenceMapping) mapping);
}
}
}
}
}
}
use of org.eclipse.persistence.internal.expressions.QueryKeyExpression in project eclipselink by eclipse-ee4j.
the class DatabaseMapping method extractNestedNonAggregateExpressions.
/**
* INTERNAL:
* Extract the nested attribute expressions that apply to this mapping.
* This is used for joining, and locking.
* For aggregates return the nested foreign reference mapping, not the aggregate, as the aggregates are not joined,
* and share their parent's query.
*
* @param expressions TODO
* @param newRoot TODO
* @param rootExpressionsAllowed true if newRoot itself can be one of the
* expressions returned (used for locking)
* @return TODO
*/
protected List<Expression> extractNestedNonAggregateExpressions(List<Expression> expressions, ExpressionBuilder newRoot, boolean rootExpressionsAllowed) {
List<Expression> nestedExpressions = new ArrayList<>(expressions.size());
/*
* need to work on all expressions with at least 2 nestings off the base expression builder, excluding
* aggregateObjectMapping expressions from the count (only ForeignReferenceMapping expressions count). For those
* expressions, If the expression closest to to the Builder is for this mapping, that expression is rebuilt using
* newRoot and added to the nestedExpressions list.
*/
for (Expression next : expressions) {
// the ForUpdateOfClause.
if (!next.isQueryKeyExpression()) {
continue;
}
QueryKeyExpression expression = (QueryKeyExpression) next;
ObjectExpression base = expression;
boolean afterBase = false;
boolean done = false;
ObjectExpression prevExpression = base;
while (!base.getBaseExpression().isExpressionBuilder() && !done) {
base = (ObjectExpression) base.getBaseExpression();
while (!base.isExpressionBuilder() && (base.getMapping() != null && base.getMapping().isAggregateObjectMapping())) {
base = (ObjectExpression) base.getBaseExpression();
}
if (base.isExpressionBuilder()) {
done = true;
// use the one closest to the expression builder that wasn't an aggregate
base = prevExpression;
} else {
prevExpression = base;
afterBase = true;
}
}
if (afterBase && base.getName().equals(getAttributeName())) {
nestedExpressions.add(expression.rebuildOn(base, newRoot));
} else if (rootExpressionsAllowed && expression.getBaseExpression().isExpressionBuilder() && expression.getName().equals(getAttributeName())) {
nestedExpressions.add(newRoot);
}
}
return nestedExpressions;
}
use of org.eclipse.persistence.internal.expressions.QueryKeyExpression in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method isFieldInUpdate.
private boolean isFieldInUpdate(Expression writeLock, HashMap updateClauses) {
if (!(writeLock instanceof FieldExpression)) {
return false;
}
final FieldExpression fe = (FieldExpression) writeLock;
final DatabaseField targetField = fe.getField();
final Set keys = updateClauses.keySet();
for (Object key : keys) {
if (!(key instanceof QueryKeyExpression)) {
continue;
}
QueryKeyExpression qke = (QueryKeyExpression) key;
DatabaseField qkField = getDescriptor().getObjectBuilder().getFieldForQueryKeyName(qke.getName());
if (qkField == targetField) {
return true;
}
}
return false;
}
use of org.eclipse.persistence.internal.expressions.QueryKeyExpression in project eclipselink by eclipse-ee4j.
the class JoinedAttributeManager method addExpressionAndBaseToGroupedList.
/**
* adds expression and its base expressions recursively to the expressionList in groups, so that an expression is never listed before
* its base expression
*/
protected Expression addExpressionAndBaseToGroupedList(Expression expression, List expressionlist, Expression lastJoinedAttributeBaseExpression) {
if (!expressionlist.contains(expression)) {
int baseExpressionIndex = -1;
// better than using instanceof BaseExpression. If its not an objectExpression, it will get an exception in prepare anyway
boolean sameBase = false;
if ((expression.isObjectExpression())) {
Expression baseExpression = ((BaseExpression) expression).getBaseExpression();
// filter out aggregate expressions between this and the next node.
while (!baseExpression.isExpressionBuilder() && ((QueryKeyExpression) baseExpression).getMapping().isAggregateMapping()) {
baseExpression = ((BaseExpression) baseExpression).getBaseExpression();
}
if (baseExpression != null && !baseExpression.isExpressionBuilder()) {
addExpressionAndBaseToGroupedList(baseExpression, expressionlist, lastJoinedAttributeBaseExpression);
// EL bug 307497
if (baseExpression != lastJoinedAttributeBaseExpression) {
baseExpressionIndex = getJoinedAttributeExpressions().indexOf(baseExpression);
} else {
sameBase = true;
}
}
}
// EL bug 307497
if (baseExpressionIndex == -1) {
expressionlist.add(expression);
if (!sameBase) {
lastJoinedAttributeBaseExpression = expression;
}
} else {
// Add attributeExpression at baseExpressionIndex + 1.
expressionlist.add(baseExpressionIndex + 1, expression);
}
}
return lastJoinedAttributeBaseExpression;
}
Aggregations