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