Search in sources :

Example 1 with ParameterExpression

use of org.eclipse.persistence.internal.expressions.ParameterExpression in project eclipselink by eclipse-ee4j.

the class DatasourceCall method getValueForInParameter.

/**
 * INTERNAL:
 * Returns value for IN parameter. Called by translate and translateSQLString methods.
 * In case shouldBind==true tries to return a DatabaseField with type instead of null,
 * returns null only in case no DatabaseField with type was found (case sensitive).
 */
protected Object getValueForInParameter(Object parameter, AbstractRecord translationRow, AbstractRecord modifyRow, AbstractSession session, boolean shouldBind) {
    Object value = parameter;
    DatabaseField field = null;
    boolean isNull = false;
    // Parameter expressions are used for nesting and correct mapping conversion of the value.
    if (parameter instanceof ParameterExpression) {
        value = ((ParameterExpression) parameter).getValue(translationRow, getQuery(), session);
        field = ((ParameterExpression) parameter).getField();
    } else if (parameter instanceof DatabaseField) {
        field = (DatabaseField) parameter;
        value = translationRow.get(field);
        // Must check for the modify row as well for custom SQL compatibility as only one # is required.
        if (modifyRow != null) {
            if (value == null) {
                value = modifyRow.get(field);
            }
            if (value != null) {
                DatabaseField modifyField = modifyRow.getField(field);
                if (modifyField != null) {
                    if (session.getDatasourcePlatform().shouldUseCustomModifyForCall(modifyField)) {
                        value = session.getDatasourcePlatform().getCustomModifyValueForCall(this, value, modifyField, shouldBind);
                    }
                }
            }
        }
        if (value == null && shouldBind) {
            isNull = true;
            if ((field.getType() != null) || (field.getSqlType() != DatabaseField.NULL_SQL_TYPE)) {
                value = field;
            } else if (modifyRow != null) {
                DatabaseField modifyField = modifyRow.getField(field);
                if ((modifyField != null) && (modifyField.getType() != null)) {
                    value = modifyField;
                }
            }
            if (value == null) {
                DatabaseField translationField = translationRow.getField(field);
                if (translationField == null) {
                    session.log(SessionLog.WARNING, SessionLog.SQL, "named_argument_not_found_in_query_parameters", new Object[] { field });
                }
                if ((translationField != null) && (translationField.getType() != null)) {
                    value = translationField;
                }
            }
        } else {
            if (parameter instanceof ObjectRelationalDatabaseField) {
                value = new InParameterForCallableStatement(value, (DatabaseField) parameter);
            }
        }
    }
    if ((value == null || isNull) && this.query.hasNullableArguments() && this.query.getNullableArguments().contains(field)) {
        return this;
    }
    return value;
}
Also used : ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression)

Example 2 with ParameterExpression

use of org.eclipse.persistence.internal.expressions.ParameterExpression in project eclipselink by eclipse-ee4j.

the class Expression method getProperty.

/**
 * ADVANCED:
 * Return an expression representing a property with the given name.
 */
public Expression getProperty(DatabaseField field) {
    ParameterExpression paramExpression = new ParameterExpression(field, this);
    paramExpression.setIsProperty(true);
    return paramExpression;
}
Also used : ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression)

Example 3 with ParameterExpression

use of org.eclipse.persistence.internal.expressions.ParameterExpression in project eclipselink by eclipse-ee4j.

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(CoalesceExpression expression) {
    List<Expression> expressions = new ArrayList<>();
    List<Class<?>> types = new LinkedList<>();
    // cache the type of the expression so untyped children have a default type
    Class<?> coalesceType = type[0];
    // Create the Expression for each scalar expression
    for (org.eclipse.persistence.jpa.jpql.parser.Expression child : expression.getExpression().children()) {
        child.accept(this);
        expressions.add(queryExpression);
        // get the expression type parsed from the child expression
        Class<?> childType = type[0];
        // This is to help provide a valid type for null parameter when binding JDBC parameter types
        if (queryExpression.isParameterExpression()) {
            ParameterExpression paramExpression = (ParameterExpression) queryExpression;
            if (paramExpression.getType() == null || paramExpression.getType().equals(Object.class)) {
                paramExpression.setType(coalesceType);
                childType = coalesceType;
            }
        }
        types.add(childType);
    }
    // Create the COALESCE expression
    queryExpression = queryContext.getBaseExpression();
    queryExpression = queryExpression.coalesce(expressions);
    // Set the expression type
    type[0] = queryContext.typeResolver().compareCollectionEquivalentTypes(types);
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) IndexExpression(org.eclipse.persistence.jpa.jpql.parser.IndexExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) UpperExpression(org.eclipse.persistence.jpa.jpql.parser.UpperExpression) ExistsExpression(org.eclipse.persistence.jpa.jpql.parser.ExistsExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) AllOrAnyExpression(org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) Expression(org.eclipse.persistence.expressions.Expression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression) LengthExpression(org.eclipse.persistence.jpa.jpql.parser.LengthExpression) MultiplicationExpression(org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) NullComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.NullComparisonExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) ComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression) InExpression(org.eclipse.persistence.jpa.jpql.parser.InExpression) NotExpression(org.eclipse.persistence.jpa.jpql.parser.NotExpression) DateConstantExpression(org.eclipse.persistence.internal.expressions.DateConstantExpression) BadExpression(org.eclipse.persistence.jpa.jpql.parser.BadExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) TableExpression(org.eclipse.persistence.jpa.jpql.parser.TableExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) AbstractPathExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) RegexpExpression(org.eclipse.persistence.jpa.jpql.parser.RegexpExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) TreatExpression(org.eclipse.persistence.jpa.jpql.parser.TreatExpression) TypeExpression(org.eclipse.persistence.jpa.jpql.parser.TypeExpression) EmptyCollectionComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.EmptyCollectionComparisonExpression) SubtractionExpression(org.eclipse.persistence.jpa.jpql.parser.SubtractionExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression)

Example 4 with ParameterExpression

use of org.eclipse.persistence.internal.expressions.ParameterExpression 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 5 with ParameterExpression

use of org.eclipse.persistence.internal.expressions.ParameterExpression 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)

Aggregations

ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)15 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)8 Expression (org.eclipse.persistence.expressions.Expression)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)4 FieldExpression (org.eclipse.persistence.internal.expressions.FieldExpression)4 QueryKeyExpression (org.eclipse.persistence.internal.expressions.QueryKeyExpression)4 Collection (java.util.Collection)3 ExpressionIterator (org.eclipse.persistence.internal.expressions.ExpressionIterator)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 ObjectBuilder (org.eclipse.persistence.internal.descriptors.ObjectBuilder)2 DataExpression (org.eclipse.persistence.internal.expressions.DataExpression)2 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)2 ObjectExpression (org.eclipse.persistence.internal.expressions.ObjectExpression)2 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)2 ObjectRelationalDatabaseField (org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField)2 EntityManager (jakarta.persistence.EntityManager)1