use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.
the class SubQueryImpl method select.
/**
* Specify the item that is to be returned in the query result.
* Replaces the previously specified selection, if any.
* @param selection selection specifying the item that
* is to be returned in the query result
* @return the modified query
*/
@Override
public Subquery<T> select(Expression<T> selection) {
findRootAndParameters(selection);
for (Iterator<Root<?>> iterator = this.getRoots().iterator(); iterator.hasNext(); ) {
findJoins((FromImpl) iterator.next());
}
for (Iterator<Join<?, ?>> iterator = this.getCorrelatedJoins().iterator(); iterator.hasNext(); ) {
findJoins((FromImpl) iterator.next());
}
this.selection = (SelectionImpl) selection;
this.queryType = (Class<T>) selection.getJavaType();
this.subQuery.getItems().clear();
if (selection.isCompoundSelection()) {
int count = 0;
for (Selection select : selection.getCompoundSelectionItems()) {
this.subQuery.addItem(String.valueOf(count), ((InternalSelection) select).getCurrentNode());
++count;
}
this.subQuery.setExpressionBuilder(((InternalSelection) selection.getCompoundSelectionItems().get(0)).getCurrentNode().getBuilder());
} else {
TypeImpl<? extends T> type = ((MetamodelImpl) this.metamodel).getType(selection.getJavaType());
if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
this.subQuery.addAttribute("", new ConstantExpression(1, ((InternalSelection) selection).getCurrentNode().getBuilder()));
this.subQuery.addNonFetchJoinedAttribute(((InternalSelection) selection).getCurrentNode());
} else {
String itemName = selection.getAlias();
if (itemName == null) {
itemName = ((InternalSelection) selection).getCurrentNode().getName();
}
this.subQuery.addItem(itemName, ((InternalSelection) selection).getCurrentNode());
}
this.subQuery.setExpressionBuilder(((InternalSelection) selection).getCurrentNode().getBuilder());
}
return this;
}
use of org.eclipse.persistence.internal.expressions.ConstantExpression 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.ConstantExpression in project eclipselink by eclipse-ee4j.
the class ExistsNode method generateExpression.
/**
* INTERNAL
* Generate the EclipseLink expression for this node
*/
@Override
public Expression generateExpression(GenerationContext context) {
SubqueryNode subqueryNode = (SubqueryNode) getLeft();
ReportQuery reportQuery = subqueryNode.getReportQuery(context);
// Replace the SELECT clause of the exists subquery by SELECT 1 to
// avoid problems with databases not supporting multiple columns in the
// subquery SELECT clause in SQL.
// The original select clause expressions might include relationship
// navigations which should result in FK joins in the generated SQL,
// e.g. ... EXISTS (SELECT o.customer FROM Order o ...). Add the
// select clause expressions as non fetch join attributes to the
// ReportQuery representing the subquery. This make sure the FK joins
// get generated.
List<ReportItem> items = reportQuery.getItems();
for (Iterator<ReportItem> i = items.iterator(); i.hasNext(); ) {
ReportItem item = i.next();
Expression expr = item.getAttributeExpression();
reportQuery.addNonFetchJoinedAttribute(expr);
}
reportQuery.clearItems();
Expression one = new ConstantExpression(1, new ExpressionBuilder());
reportQuery.addItem("one", one);
reportQuery.dontUseDistinct();
Expression expr = context.getBaseExpression();
return notIndicated() ? expr.notExists(reportQuery) : expr.exists(reportQuery);
}
use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(KeywordExpression expression) {
String keyword = expression.getText();
Object value;
if (keyword == KeywordExpression.NULL) {
value = null;
type[0] = Object.class;
} else if (keyword == KeywordExpression.TRUE) {
value = Boolean.TRUE;
type[0] = Boolean.class;
} else {
value = Boolean.FALSE;
type[0] = Boolean.class;
}
queryExpression = queryContext.getBaseExpression();
queryExpression = new ConstantExpression(value, queryExpression);
}
use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(EntityTypeLiteral expression) {
ClassDescriptor descriptor = queryContext.getDescriptor(expression.getEntityTypeName());
type[0] = descriptor.getJavaClass();
queryExpression = new ConstantExpression(type[0], queryContext.getBaseExpression());
}
Aggregations