Search in sources :

Example 1 with FieldExpression

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));
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) Expression(org.eclipse.persistence.expressions.Expression) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ObjectBuilder(org.eclipse.persistence.internal.descriptors.ObjectBuilder) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression)

Example 2 with FieldExpression

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));
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) QueryKeyExpression(org.eclipse.persistence.internal.expressions.QueryKeyExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) ObjectBuilder(org.eclipse.persistence.internal.descriptors.ObjectBuilder) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression)

Example 3 with FieldExpression

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) InvalidObject(org.eclipse.persistence.internal.helper.InvalidObject) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) QueryKeyExpression(org.eclipse.persistence.internal.expressions.QueryKeyExpression)

Example 4 with FieldExpression

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);
    }
}
Also used : ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression)

Example 5 with FieldExpression

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;
}
Also used : ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) EISException(org.eclipse.persistence.eis.EISException) QueryKeyExpression(org.eclipse.persistence.internal.expressions.QueryKeyExpression) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) RelationExpression(org.eclipse.persistence.internal.expressions.RelationExpression) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) QueryKeyExpression(org.eclipse.persistence.internal.expressions.QueryKeyExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) LogicalExpression(org.eclipse.persistence.internal.expressions.LogicalExpression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) Expression(org.eclipse.persistence.expressions.Expression) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) List(java.util.List)

Aggregations

FieldExpression (org.eclipse.persistence.internal.expressions.FieldExpression)7 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)5 ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)4 QueryKeyExpression (org.eclipse.persistence.internal.expressions.QueryKeyExpression)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)3 Expression (org.eclipse.persistence.expressions.Expression)3 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)3 HashSet (java.util.HashSet)2 List (java.util.List)2 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)2 ObjectBuilder (org.eclipse.persistence.internal.descriptors.ObjectBuilder)2 ObjectExpression (org.eclipse.persistence.internal.expressions.ObjectExpression)2 InvalidObject (org.eclipse.persistence.internal.helper.InvalidObject)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1