Search in sources :

Example 1 with ObjectExpression

use of org.eclipse.persistence.internal.expressions.ObjectExpression in project blaze-persistence by Blazebit.

the class JpqlFunctionExpressionOperator method printCollection.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void printCollection(Vector items, ExpressionSQLPrinter printer) {
    prepare((List<Expression>) items, printer);
    // Certain functions don't allow binding on some platforms.
    if (printer.getPlatform().isDynamicSQLRequiredForFunctions() && !isBindingSupported()) {
        printer.getCall().setUsesBinding(false);
    }
    int dbStringIndex = 0;
    try {
        if (isPrefix()) {
            printer.getWriter().write(getDatabaseStrings()[0]);
            dbStringIndex = 1;
        } else {
            dbStringIndex = 0;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (argumentIndices == null) {
        argumentIndices = new int[items.size()];
        for (int i = 0; i < argumentIndices.length; i++) {
            argumentIndices[i] = i;
        }
    }
    for (int i = 0; i < argumentIndices.length; i++) {
        int index = argumentIndices[i];
        Expression item;
        if (index == -1) {
            item = (Expression) items.elementAt(i);
            Writer w = printer.getWriter();
            try {
                printer.setWriter(NULL_WRITER);
                item.printSQL(printer);
            } finally {
                printer.setWriter(w);
            }
            continue;
        }
        item = (Expression) items.elementAt(index);
        if ((this.selector == Ref) || ((this.selector == Deref) && (item.isObjectExpression()))) {
            DatabaseTable alias = ((ObjectExpression) item).aliasForTable(((ObjectExpression) item).getDescriptor().getTables().firstElement());
            printer.printString(alias.getNameDelimited(printer.getPlatform()));
        } else if ((this.selector == Count) && (item.isExpressionBuilder())) {
            printer.printString("*");
        } else {
            item.printSQL(printer);
        }
        if (dbStringIndex < getDatabaseStrings().length) {
            printer.printString(getDatabaseStrings()[dbStringIndex++]);
        }
    }
    for (; dbStringIndex < getDatabaseStrings().length; dbStringIndex++) {
        printer.printString(getDatabaseStrings()[dbStringIndex]);
    }
}
Also used : FromSubSelectExpression(org.eclipse.persistence.internal.expressions.FromSubSelectExpression) ClassTypeExpression(org.eclipse.persistence.internal.expressions.ClassTypeExpression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) 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) CompoundExpression(org.eclipse.persistence.internal.expressions.CompoundExpression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) Expression(org.eclipse.persistence.expressions.Expression) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) IOException(java.io.IOException) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) Writer(java.io.Writer)

Example 2 with ObjectExpression

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

the class FromImpl method fetch.

/**
 * Fetch join to the specified attribute using the given join type.
 *
 * @param assoc
 *            target of the join
 * @param jt
 *            join type
 * @return the resulting fetch join
 */
@Override
public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> assoc, JoinType jt) {
    if (((SingularAttribute) assoc).getType().getPersistenceType().equals(PersistenceType.BASIC)) {
        throw new IllegalStateException(ExceptionLocalization.buildMessage("CAN_NOT_JOIN_TO_BASIC"));
    }
    Class<Y> clazz = assoc.getBindableJavaType();
    Fetch<X, Y> join = null;
    ObjectExpression exp = ((ObjectExpression) this.currentNode).newDerivedExpressionNamed(assoc.getName());
    if (jt.equals(JoinType.LEFT)) {
        exp.doUseOuterJoin();
    } else if (jt.equals(JoinType.RIGHT)) {
        throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED"));
    } else {
        exp.doNotUseOuterJoin();
    }
    join = new JoinImpl<X, Y>(this, this.metamodel.managedType(clazz), this.metamodel, clazz, exp, assoc, jt);
    this.fetches.add(join);
    ((FromImpl) join).isFetch = true;
    return join;
}
Also used : SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression)

Example 3 with ObjectExpression

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

the class ExpressionOperator method printCollection.

/**
 * INTERNAL: Print the collection onto the SQL stream.
 */
public void printCollection(List items, ExpressionSQLPrinter printer) {
    // Certain functions don't allow binding on some platforms.
    if (printer.getPlatform().isDynamicSQLRequiredForFunctions() && !isBindingSupported()) {
        printer.getCall().setUsesBinding(false);
    }
    int dbStringIndex = 0;
    if (isPrefix()) {
        printer.printString(getDatabaseStrings()[0]);
        dbStringIndex = 1;
    }
    if (argumentIndices == null) {
        argumentIndices = new int[items.size()];
        for (int i = 0; i < argumentIndices.length; i++) {
            argumentIndices[i] = i;
        }
    }
    String[] dbStrings = getDatabaseStrings(items.size());
    for (final int index : argumentIndices) {
        Expression item = (Expression) items.get(index);
        if ((this.selector == Ref) || ((this.selector == Deref) && (item.isObjectExpression()))) {
            DatabaseTable alias = item.aliasForTable(((ObjectExpression) item).getDescriptor().getTables().firstElement());
            printer.printString(alias.getNameDelimited(printer.getPlatform()));
        } else if ((this.selector == Count) && (item.isExpressionBuilder())) {
            printer.printString("*");
        } else {
            item.printSQL(printer);
        }
        if (dbStringIndex < dbStrings.length) {
            printer.printString(dbStrings[dbStringIndex++]);
        }
    }
}
Also used : RelationExpression(org.eclipse.persistence.internal.expressions.RelationExpression) LogicalExpression(org.eclipse.persistence.internal.expressions.LogicalExpression) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable)

Example 4 with ObjectExpression

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

the class HistoryPolicy method additionalHistoryExpression.

/**
 * INTERNAL:
 * Add any temporal querying conditions to this object expression.
 * @param tableIndex not null indicates that only expression for a single table should be returned.
 */
public Expression additionalHistoryExpression(Expression context, Expression base, Integer tableIndex) {
    // 
    AsOfClause clause = base.getAsOfClause();
    Object value = clause.getValue();
    Expression join = null;
    Expression subJoin = null;
    Expression start = null;
    Expression end = null;
    if (value == null) {
        return null;
    // for now nothing as assume mirroring historical tables.
    } else {
        if (value instanceof Expression) {
            // Print AS OF TIMESTAMP (SYSDATE - 1000*60*10) not AS OF ('SYSDATE - 1000*60*10').
            if ((value instanceof ConstantExpression) && (((ConstantExpression) value).getValue() instanceof String)) {
                value = (((ConstantExpression) value).getValue());
            }
        } else {
            ConversionManager converter = ConversionManager.getDefaultManager();
            value = converter.convertObject(value, ClassConstants.TIMESTAMP);
        }
        if (getMapping() != null) {
            if (tableIndex != null && tableIndex > 0) {
                return null;
            }
            TableExpression tableExp = null;
            DatabaseTable historicalTable = getHistoricalTables().get(0);
            tableExp = (TableExpression) ((ObjectExpression) base).existingDerivedTable(historicalTable);
            start = tableExp.getField(getStart());
            end = tableExp.getField(getEnd());
            join = start.lessThanEqual(value).and(end.isNull().or(end.greaterThan(value)));
            // We also need to do step two here in advance.
            tableExp.setTable(historicalTable);
            return join;
        }
        int iFirst, iLast;
        if (tableIndex == null) {
            // loop through all history tables
            iFirst = 0;
            iLast = getHistoricalTables().size() - 1;
        } else {
            // only return expression for the specified table
            iFirst = tableIndex;
            iLast = iFirst;
        }
        for (int i = iFirst; i <= iLast; i++) {
            start = base.getField(getStart(i));
            end = base.getField(getEnd(i));
            subJoin = start.lessThanEqual(value).and(end.isNull().or(end.greaterThan(value)));
            join = ((join == null) ? subJoin : join.and(subJoin));
        }
        return join;
    }
}
Also used : ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) Expression(org.eclipse.persistence.expressions.Expression) TableExpression(org.eclipse.persistence.internal.expressions.TableExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) HistoricalDatabaseTable(org.eclipse.persistence.internal.history.HistoricalDatabaseTable) TableExpression(org.eclipse.persistence.internal.expressions.TableExpression) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression)

Example 5 with ObjectExpression

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

the class ExpressionBuilder method registerIn.

/**
 * INTERNAL:
 * Override Expression.registerIn to check if the new base expression
 * has already been provided for the clone.
 * @see org.eclipse.persistence.expressions.Expression#cloneUsing(Expression)
 */
@Override
protected Expression registerIn(Map alreadyDone) {
    // bug  2637484 INVALID QUERY KEY EXCEPTION THROWN USING BATCH READS AND PARALLEL EXPRESSIONS
    // Here do a special check to see if this a cloneUsing(newBase) call.
    Object value = alreadyDone.get(alreadyDone);
    if ((value == null) || (value == alreadyDone)) {
        // This is a normal cloning operation.
        return super.registerIn(alreadyDone);
    }
    ObjectExpression copy = (ObjectExpression) value;
    // copy is actually the newBase of a cloneUsing.
    alreadyDone.put(alreadyDone, alreadyDone);
    alreadyDone.put(this, copy);
    // Now need to copy over the derived expressions, etc.
    if (this.derivedExpressions != null) {
        if (copy.derivedExpressions == null) {
            copy.derivedExpressions = copyDerivedExpressions(alreadyDone);
        } else {
            copy.derivedExpressions.addAll(copyDerivedExpressions(alreadyDone));
        }
    }
    // Do the same for these protected fields.
    copy.postCopyIn(alreadyDone, this.derivedFields, this.derivedTables);
    return copy;
}
Also used : ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression)

Aggregations

ObjectExpression (org.eclipse.persistence.internal.expressions.ObjectExpression)21 Expression (org.eclipse.persistence.expressions.Expression)11 QueryKeyExpression (org.eclipse.persistence.internal.expressions.QueryKeyExpression)10 ArrayList (java.util.ArrayList)7 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)5 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)3 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)3 BaseExpression (org.eclipse.persistence.internal.expressions.BaseExpression)3 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)3 FieldExpression (org.eclipse.persistence.internal.expressions.FieldExpression)3 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)3 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)3 SingularAttribute (jakarta.persistence.metamodel.SingularAttribute)2 Iterator (java.util.Iterator)2 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)2 ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)2 TableExpression (org.eclipse.persistence.internal.expressions.TableExpression)2 FetchGroup (org.eclipse.persistence.queries.FetchGroup)2 IOException (java.io.IOException)1