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;
}
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;
}
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);
}
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));
}
}
}
}
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));
}
}
}
}
Aggregations