use of org.eclipse.persistence.internal.expressions.FieldExpression in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method postInitializeSourceAndTargetExpressions.
/**
* INTERNAL:
* Post-initialize source and target expression fields created when a mapping's selectionCriteria
* is created early with only partly initialized fields.
*/
@Override
public void postInitializeSourceAndTargetExpressions() {
// postInitialize and set source expression fields using my descriptor
if (this.sourceExpressionsToPostInitialize != null && this.sourceExpressionsToPostInitialize.size() > 0) {
ClassDescriptor descriptor = getDescriptor();
ObjectBuilder objectBuilder = descriptor.getObjectBuilder();
for (Iterator<Expression> expressions = this.sourceExpressionsToPostInitialize.iterator(); expressions.hasNext(); ) {
Expression expression = expressions.next();
DatabaseField field = null;
if (expression.isParameterExpression()) {
field = ((ParameterExpression) expression).getField();
} else if (expression.isFieldExpression()) {
field = ((FieldExpression) expression).getField();
}
if (field != null && (field.getType() == null || field.getTypeName() == null)) {
field.setType(objectBuilder.getFieldClassification(field));
}
}
}
// postInitialize and set target expression fields using my reference descriptor
if (this.targetExpressionsToPostInitialize != null && this.targetExpressionsToPostInitialize.size() > 0) {
ClassDescriptor descriptor = getReferenceDescriptor();
ObjectBuilder objectBuilder = descriptor.getObjectBuilder();
for (Iterator<Expression> expressions = this.targetExpressionsToPostInitialize.iterator(); expressions.hasNext(); ) {
Expression expression = expressions.next();
DatabaseField field = null;
if (expression.isParameterExpression()) {
field = ((ParameterExpression) expression).getField();
} else if (expression.isFieldExpression()) {
field = ((FieldExpression) expression).getField();
}
if (field != null && (field.getType() == null || field.getTypeName() == null)) {
field.setType(objectBuilder.getFieldClassification(field));
}
}
}
}
use of org.eclipse.persistence.internal.expressions.FieldExpression in project eclipselink by eclipse-ee4j.
the class OneToOneMapping method postInitializeSourceAndTargetExpressions.
/**
* INTERNAL:
* Post-initialize source and target expression fields created when a mapping's selectionCriteria
* is created early with only partly initialized fields.
*/
@Override
public void postInitializeSourceAndTargetExpressions() {
// postInitialize and set source expression fields using my descriptor
if (this.sourceExpressionsToPostInitialize != null && this.sourceExpressionsToPostInitialize.size() > 0) {
ClassDescriptor descriptor = getDescriptor();
ObjectBuilder objectBuilder = descriptor.getObjectBuilder();
for (Iterator<Expression> expressions = this.sourceExpressionsToPostInitialize.iterator(); expressions.hasNext(); ) {
Expression expression = expressions.next();
DatabaseField field = null;
if (expression.isParameterExpression()) {
field = ((ParameterExpression) expression).getField();
} else if (expression.isFieldExpression()) {
field = ((FieldExpression) expression).getField();
}
if (field != null && (field.getType() == null || field.getTypeName() == null)) {
field.setType(objectBuilder.getFieldClassification(field));
}
}
}
// postInitialize and set target expression fields using my reference descriptor
if (this.targetExpressionsToPostInitialize != null && this.targetExpressionsToPostInitialize.size() > 0) {
ClassDescriptor descriptor = getReferenceDescriptor();
ObjectBuilder objectBuilder = descriptor.getObjectBuilder();
for (Iterator<Expression> expressions = this.targetExpressionsToPostInitialize.iterator(); expressions.hasNext(); ) {
Expression expression = expressions.next();
DatabaseField field = null;
if (expression.isParameterExpression()) {
field = ((ParameterExpression) expression).getField();
} else if (expression.isFieldExpression()) {
field = ((FieldExpression) expression).getField();
}
if (field != null && (field.getType() == null || field.getTypeName() == null)) {
field.setType(objectBuilder.getFieldClassification(field));
}
}
}
}
use of org.eclipse.persistence.internal.expressions.FieldExpression 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.FieldExpression in project eclipselink by eclipse-ee4j.
the class ObjectLevelReadQuery method addSelectionFieldsForJoinedExpression.
/**
* INTERNAL:
* The method adds to the passed input vector the
* fields or expressions corresponding to the passed join expression.
*/
protected void addSelectionFieldsForJoinedExpression(List fields, boolean isCustomSQL, Expression expression) {
if (isCustomSQL) {
// Expression may not have been initialized.
ExpressionBuilder builder = expression.getBuilder();
builder.setSession(getSession().getRootSession(null));
builder.setQueryClass(getReferenceClass());
}
ForeignReferenceMapping mapping = (ForeignReferenceMapping) ((QueryKeyExpression) expression).getMapping();
ClassDescriptor referenceDescriptor = mapping.getReferenceDescriptor();
// Add the fields defined by the nested fetch group - if it exists.
ObjectLevelReadQuery nestedQuery = null;
if (referenceDescriptor != null && referenceDescriptor.hasFetchGroupManager()) {
nestedQuery = getJoinedAttributeManager().getNestedJoinedMappingQuery(expression);
FetchGroup nestedFetchGroup = nestedQuery.getExecutionFetchGroup();
if (nestedFetchGroup != null) {
List<DatabaseField> nestedFields = nestedQuery.getFetchGroupSelectionFields(mapping);
for (DatabaseField field : nestedFields) {
fields.add(new FieldExpression(field, expression));
}
return;
}
}
if (isCustomSQL) {
if (referenceDescriptor != null) {
if (nestedQuery == null) {
nestedQuery = getJoinedAttributeManager().getNestedJoinedMappingQuery(expression);
}
fields.addAll(referenceDescriptor.getAllSelectionFields(nestedQuery));
} else {
fields.add(expression);
}
} else {
fields.add(expression);
}
}
use of org.eclipse.persistence.internal.expressions.FieldExpression in project eclipselink by eclipse-ee4j.
the class MongoPlatform method extractValueFromExpression.
/**
* Extract the field or constant value from the comparison expression.
*/
protected Object extractValueFromExpression(Expression expression, DatabaseQuery query) {
Object value = null;
expression.getBuilder().setSession(query.getSession());
if (expression.isQueryKeyExpression()) {
QueryKeyExpression queryKeyExpression = (QueryKeyExpression) expression;
value = queryKeyExpression.getField();
if ((queryKeyExpression.getMapping() != null) && queryKeyExpression.getMapping().getDescriptor().isDescriptorTypeAggregate()) {
String name = queryKeyExpression.getField().getName();
while (queryKeyExpression.getBaseExpression().isQueryKeyExpression() && (((QueryKeyExpression) queryKeyExpression.getBaseExpression()).getMapping().isAbstractCompositeObjectMapping() || ((QueryKeyExpression) queryKeyExpression.getBaseExpression()).getMapping().isAbstractCompositeCollectionMapping() || ((QueryKeyExpression) queryKeyExpression.getBaseExpression()).getMapping().isAbstractCompositeDirectCollectionMapping())) {
queryKeyExpression = (QueryKeyExpression) queryKeyExpression.getBaseExpression();
if (queryKeyExpression.getMapping().isAbstractCompositeObjectMapping()) {
name = queryKeyExpression.getMapping().getField().getName() + "." + name;
} else if (queryKeyExpression.getMapping().isAbstractCompositeCollectionMapping()) {
name = queryKeyExpression.getMapping().getField().getName() + "." + name;
} else if (queryKeyExpression.getMapping().isAbstractCompositeDirectCollectionMapping()) {
name = queryKeyExpression.getMapping().getField().getName() + "." + name;
}
}
DatabaseField field = new DatabaseField();
field.setName(name);
value = field;
}
} else if (expression.isFieldExpression()) {
value = ((FieldExpression) expression).getField();
} else if (expression.isConstantExpression()) {
value = ((ConstantExpression) expression).getValue();
if (((ConstantExpression) expression).getLocalBase() != null) {
value = ((ConstantExpression) expression).getLocalBase().getFieldValue(value, query.getSession());
}
} else if (expression.isParameterExpression()) {
value = query.getTranslationRow().get(((ParameterExpression) expression).getField());
if (((ParameterExpression) expression).getLocalBase() != null) {
value = ((ParameterExpression) expression).getLocalBase().getFieldValue(value, query.getSession());
}
} else {
throw new EISException("Query too complex for Mongo translation, comparison of [" + expression + "] not supported in query: " + query);
}
if (value instanceof List) {
@SuppressWarnings({ "unchecked" }) List<Object> values = (List<Object>) value;
for (int index = 0; index < values.size(); index++) {
Object element = values.get(index);
if (element instanceof Expression) {
element = extractValueFromExpression((Expression) element, query);
values.set(index, element);
}
}
}
return value;
}
Aggregations