use of org.eclipse.persistence.internal.expressions.TableExpression 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.TableExpression in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method initializeSelectionCriteria.
protected void initializeSelectionCriteria(AbstractSession session) {
Expression criteria = null;
ExpressionBuilder base = new ExpressionBuilder();
TableExpression table = (TableExpression) base.getTable(getReferenceTable());
Iterator<DatabaseField> referenceKeys = getReferenceKeyFields().iterator();
Iterator<DatabaseField> sourceKeys = getSourceKeyFields().iterator();
while (referenceKeys.hasNext()) {
DatabaseField referenceKey = referenceKeys.next();
DatabaseField sourceKey = sourceKeys.next();
Expression expression = table.getField(referenceKey).equal(base.getParameter(sourceKey));
if (criteria == null) {
criteria = expression;
} else {
criteria = expression.and(criteria);
}
}
setSelectionCriteria(criteria);
}
use of org.eclipse.persistence.internal.expressions.TableExpression in project eclipselink by eclipse-ee4j.
the class ForeignReferenceQueryKey method getRelationTable.
/**
* PUBLIC:
* Returns the relation table.
* Currently only ManyToMany and OneToOne may have relation table.
* The method is overridden to return null for other subclasses.
* The returned relationTable still could be null.
*/
public DatabaseTable getRelationTable(ClassDescriptor referenceDescriptor) {
ExpressionIterator expIterator = new ExpressionIterator() {
@Override
public void iterate(Expression each) {
if (each.isTableExpression()) {
((Collection) this.getResult()).add(((TableExpression) each).getTable());
} else if (each.isDataExpression()) {
DatabaseField field = ((DataExpression) each).getField();
if (field != null && field.hasTableName()) {
((Collection) this.getResult()).add(field.getTable());
}
} else if (each.isParameterExpression()) {
DatabaseField field = ((ParameterExpression) each).getField();
if (field != null && field.hasTableName()) {
((Collection) this.getResult()).add(field.getTable());
}
}
}
};
expIterator.setResult(new HashSet());
expIterator.iterateOn(this.joinCriteria);
HashSet<DatabaseTable> tables = (HashSet) expIterator.getResult();
DatabaseTable relationTable = null;
Iterator<DatabaseTable> it = tables.iterator();
while (it.hasNext()) {
DatabaseTable table = it.next();
// neither source nor reference descriptor contains table - must be relationTable
if (!descriptor.getTables().contains(table) && !referenceDescriptor.getTables().contains(table)) {
relationTable = table;
break;
}
}
return relationTable;
}
Aggregations