/** * INTERNAL: * Aggregate order by all their fields by default. */ @Override public List<Expression> getOrderByNormalizedExpressions(Expression base) { List<Expression> orderBys = new ArrayList(this.fields.size()); for (DatabaseField field : this.fields) { orderBys.add(base.getField(field)); } return orderBys; }
/** * INTERNAL: * Aggregate order by all their fields by default. */ @Override public List<Expression> getOrderByNormalizedExpressions(Expression base) { List<Expression> orderBys = new ArrayList(this.fields.size()); for (DatabaseField field : this.fields) { orderBys.add(base.getField(field)); } return orderBys; }
/** * Resolves a database column. * * @param expression The path expression representing an identification variable mapping to a * database table followed by the column name */ private void resolveColumn(AbstractPathExpression expression) { String path = expression.getPath(1); localExpression = localExpression.getField(path); }
/** * INTERNAL: * Rebuild against the base, with the values of parameters supplied by the context * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping) * into part of some larger expression. You normally would not call this directly, instead calling twist, * (see the comment there for more details). */ public Expression twistedForBaseAndContext(Expression newBase, Expression context) { return context.getField(getField()); }
/** * Resolves a database column. * * @param expression The path expression representing an identification variable mapping to a * database table followed by the column name */ private void resolveColumn(AbstractPathExpression expression) { String path = expression.getPath(1); localExpression = localExpression.getField(path); }
/** * INTERNAL: * Adds to the passed expression a single relation table field joined to source field. * Used to extend pessimistic locking clause in source query. */ public Expression joinRelationTableField(Expression expression, Expression baseExpression) { return baseExpression.getField(this.sourceKeyFields.get(0)).equal(baseExpression.getTable(relationTable).getField(this.sourceRelationKeyFields.get(0))).and(expression); }
/** * INTERNAL: * Adds to the passed expression a single relation table field joined to source field. * Used to extend pessimistic locking clause in source query. */ public Expression joinRelationTableField(Expression expression, Expression baseExpression) { return baseExpression.getField(this.sourceKeyFields.get(0)).equal(baseExpression.getTable(relationTable).getField(this.sourceRelationKeyFields.get(0))).and(expression); }
/** * INTERNAL: * Adds to the passed expression a single relation table field joined to source field. * Used to extend pessimistic locking clause in source query. */ public Expression joinRelationTableField(Expression expression, Expression baseExpression) { return baseExpression.getField(this.sourceKeyFields.get(0)).equal(baseExpression.getTable(relationTable).getField(this.sourceRelationKeyFields.get(0))).and(expression); }
/** * INTERNAL: * Relationships order by their target primary key fields by default. */ @Override public List<Expression> getOrderByNormalizedExpressions(Expression base) { List<Expression> orderBys = new ArrayList(this.referenceDescriptor.getPrimaryKeyFields().size()); for (DatabaseField field : this.referenceDescriptor.getPrimaryKeyFields()) { orderBys.add(base.getField(field)); } return orderBys; } }
/** * INTERNAL: * Relationships order by their target primary key fields by default. */ @Override public List<Expression> getOrderByNormalizedExpressions(Expression base) { List<Expression> orderBys = new ArrayList(this.referenceDescriptor.getPrimaryKeyFields().size()); for (DatabaseField field : this.referenceDescriptor.getPrimaryKeyFields()) { orderBys.add(base.getField(field)); } return orderBys; } }
/** * INTERNAL: * Override this method if the platform needs to use a custom function based on the DatabaseField * @return An expression for the given field set equal to a parameter matching the field */ public Expression createExpressionFor(DatabaseField field, Expression builder) { Expression subExp1 = builder.getField(field); Expression subExp2 = builder.getParameter(field); return subExp1.equal(subExp2); } }
/** * INTERNAL: * Add the addition join fields to the batch query. */ public void postPrepareNestedBatchQuery(ReadQuery batchQuery, ObjectLevelReadQuery query) { ReadAllQuery mappingBatchQuery = (ReadAllQuery)batchQuery; mappingBatchQuery.setShouldIncludeData(true); Expression linkTable = mappingBatchQuery.getExpressionBuilder().getTable(this.relationTable); for (DatabaseField relationField : this.sourceRelationKeyFields) { mappingBatchQuery.getAdditionalFields().add(linkTable.getField(relationField)); } }
/** * INTERNAL: * Creates expression for listOrderField * Precondition: listOrderField != null. */ public Expression getListOrderFieldExpression(Expression baseExpression) { if(shouldUseListOrderFieldTableExpression()) { baseExpression = baseExpression.getTable(this.listOrderField.getTable()); } return baseExpression.getField(this.listOrderField); }
/** * INTERNAL: * Rebuild myself against the base, with the values of parameters supplied by the context * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping) * into part of some larger expression. You normally would not call this directly, instead calling twist * See the comment there for more details" */ public Expression twistedForBaseAndContext(Expression newBase, Expression context) { Expression twistedBase = getBaseExpression().twistedForBaseAndContext(newBase, context); return twistedBase.getField(getField()); }
/** * INTERNAL: * Add the addition join fields to the batch query. */ public void postPrepareNestedBatchQuery(ReadQuery batchQuery, ObjectLevelReadQuery query) { ReadAllQuery mappingBatchQuery = (ReadAllQuery)batchQuery; mappingBatchQuery.setShouldIncludeData(true); Expression linkTable = mappingBatchQuery.getExpressionBuilder().getTable(this.relationTable); for (DatabaseField relationField : this.sourceRelationKeyFields) { mappingBatchQuery.getAdditionalFields().add(linkTable.getField(relationField)); } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map. * Called when the selection query is being initialized to add the fields for the map key to the query. */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ if (selectionQuery.isObjectLevelReadQuery()){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(getField())); } else if (selectionQuery.isDataReadQuery()){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(getField())); } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map. * Called when the selection query is being initialized to add the fields for the map key to the query. */ public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression){ if (selectionQuery.isObjectLevelReadQuery()){ ((ObjectLevelReadQuery)selectionQuery).addAdditionalField(baseExpression.getField(getField())); } else if (selectionQuery.isDataReadQuery()){ ((SQLSelectStatement)((DataReadQuery)selectionQuery).getSQLStatement()).addField(baseExpression.getField(getField())); } }
/** * INTERNAL: * Return relation table locking clause. */ public void setRelationTableLockingClause(ObjectLevelReadQuery targetQuery, ObjectBuildingQuery sourceQuery) { ForUpdateOfClause lockingClause = new ForUpdateOfClause(); lockingClause.setLockMode(sourceQuery.getLockMode()); FieldExpression exp = (FieldExpression)targetQuery.getExpressionBuilder().getTable(this.relationTable).getField(this.sourceRelationKeyFields.get(0)); lockingClause.addLockedExpression(exp); targetQuery.setLockingClause(lockingClause); // locking clause is not compatible with DISTINCT targetQuery.setShouldOuterJoinSubclasses(true); }
@Override public Expression createExpressionFor(DatabaseField field, Expression builder) { if (field.getType() == java.sql.Clob.class || field.getType() == java.sql.Blob.class) { Expression subExp1 = builder.getField(field); Expression subExp2 = builder.getParameter(field); subExp1 = subExp1.getFunction("dbms_lob.compare", subExp2); return subExp1.equal(0); } return super.createExpressionFor(field, builder); }
/** * INTERNAL: * Return relation table locking clause. */ public void setRelationTableLockingClause(ObjectLevelReadQuery targetQuery, ObjectBuildingQuery sourceQuery) { ForUpdateOfClause lockingClause = new ForUpdateOfClause(); lockingClause.setLockMode(sourceQuery.getLockMode()); FieldExpression exp = (FieldExpression)targetQuery.getExpressionBuilder().getTable(this.relationTable).getField(this.sourceRelationKeyFields.get(0)); lockingClause.addLockedExpression(exp); targetQuery.setLockingClause(lockingClause); // locking clause is not compatible with DISTINCT targetQuery.setShouldOuterJoinSubclasses(true); }