@Override public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = convertToCastDescriptor(getSession().getDescriptor(queryKey.getReferenceClass()), getSession()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getReferenceDescriptor(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } descriptor = convertToCastDescriptor(descriptor, getSession()); } return descriptor; }
@Override public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = convertToCastDescriptor(getSession().getDescriptor(queryKey.getReferenceClass()), getSession()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getReferenceDescriptor(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } descriptor = convertToCastDescriptor(descriptor, getSession()); } return descriptor; }
/** * 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" */ @Override public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase) { Expression twistedBase = this.baseExpression.twistedForBaseAndContext(newBase, context, oldBase); DatabaseField field = getField(); ClassDescriptor descriptor = null; // Check for possible table per class rebuild and translate fields to correct table. // TODO: JPA also allows for field to be renamed in subclasses, this needs to account for that (never has...). if (this.baseExpression.isExpressionBuilder() && newBase.isObjectExpression() && ((this.baseExpression == oldBase) || (oldBase == null))) { if (((ObjectExpression)newBase).getSession() != null) { descriptor = ((ObjectExpression)newBase).getDescriptor(); } if ((descriptor != null) && descriptor.hasTablePerClassPolicy()) { field = field.clone(); field.setTable(descriptor.getDefaultTable()); } } return twistedBase.getField(field); }
/** * 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" */ @Override public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase) { Expression twistedBase = this.baseExpression.twistedForBaseAndContext(newBase, context, oldBase); DatabaseField field = getField(); ClassDescriptor descriptor = null; // Check for possible table per class rebuild and translate fields to correct table. // TODO: JPA also allows for field to be renamed in subclasses, this needs to account for that (never has...). if (this.baseExpression.isExpressionBuilder() && newBase.isObjectExpression() && ((this.baseExpression == oldBase) || (oldBase == null))) { if (((ObjectExpression)newBase).getSession() != null) { descriptor = ((ObjectExpression)newBase).getDescriptor(); } if ((descriptor != null) && descriptor.hasTablePerClassPolicy()) { field = field.clone(); field.setTable(descriptor.getDefaultTable()); } } return twistedBase.getField(field); }
public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = getSession().getDescriptor(queryKey.getReferenceClass()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getReferenceDescriptor(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } } return descriptor; }
/** * INTERNAL: * Return the expression to join the main table of this node to any auxiliary tables. */ public Expression additionalExpressionCriteria() { if (getDescriptor() == null) { return null; } Expression criteria = getDescriptor().getQueryManager().getAdditionalJoinExpression(); if(getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) { if(isUsingOuterJoinForMultitableInheritance()) { Expression childrenCriteria = getDescriptor().getInheritancePolicy().getChildrenJoinExpression(); childrenCriteria = getBaseExpression().twist(childrenCriteria, this); childrenCriteria.convertToUseOuterJoin(); if(criteria == null) { criteria = childrenCriteria; } else { criteria = criteria.and(childrenCriteria); } } } return criteria; }
/** * INTERNAL: * Return the expression to join the main table of this node to any auxiliary tables. */ public Expression additionalExpressionCriteria() { if (getDescriptor() == null) { return null; } Expression criteria = getDescriptor().getQueryManager().getAdditionalJoinExpression(); if(getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) { if(isUsingOuterJoinForMultitableInheritance()) { Expression childrenCriteria = getDescriptor().getInheritancePolicy().getChildrenJoinExpression(); childrenCriteria = getBaseExpression().twist(childrenCriteria, this); childrenCriteria.convertToUseOuterJoin(); if(criteria == null) { criteria = childrenCriteria; } else { criteria = criteria.and(childrenCriteria); } } } return criteria; }
/** * INTERNAL: * This expression is built on a different base than the one we want. Rebuild it and * return the root of the new tree */ public Expression rebuildOn(Expression newBase) { DatabaseField field = getField(); ClassDescriptor descriptor = null; // Check for possible table per class rebuild and translate fields to correct table. // TODO: JPA also allows for field to be renamed in subclasses, this needs to account for that (never has...). if (getBaseExpression().isExpressionBuilder() && newBase.isObjectExpression()) { if (((ObjectExpression)newBase).getSession() != null) { descriptor = ((ObjectExpression)newBase).getDescriptor(); } if ((descriptor != null) && descriptor.hasTablePerClassPolicy()) { field = field.clone(); field.setTable(descriptor.getDefaultTable()); } } FieldExpression expression = new FieldExpression(field, getBaseExpression().rebuildOn(newBase)); expression.setSelectIfOrderedBy(selectIfOrderedBy()); return expression; }
/** * INTERNAL: * Return the expression to join the main table of this node to any auxiliary tables. */ public Expression additionalExpressionCriteria() { if (getDescriptor() == null) { return null; } Expression criteria = getDescriptor().getQueryManager().getAdditionalJoinExpression(); if(getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) { if(isUsingOuterJoinForMultitableInheritance()) { Expression childrenCriteria = getDescriptor().getInheritancePolicy().getChildrenJoinExpression(); childrenCriteria = getBaseExpression().twist(childrenCriteria, this); childrenCriteria.convertToUseOuterJoin(); if(criteria == null) { criteria = childrenCriteria; } else { criteria = criteria.and(childrenCriteria); } } } return criteria; }
/** * INTERNAL: * This expression is built on a different base than the one we want. Rebuild it and * return the root of the new tree */ public Expression rebuildOn(Expression newBase) { DatabaseField field = getField(); ClassDescriptor descriptor = null; // Check for possible table per class rebuild and translate fields to correct table. // TODO: JPA also allows for field to be renamed in subclasses, this needs to account for that (never has...). if (getBaseExpression().isExpressionBuilder() && newBase.isObjectExpression()) { if (((ObjectExpression)newBase).getSession() != null) { descriptor = ((ObjectExpression)newBase).getDescriptor(); } if ((descriptor != null) && descriptor.hasTablePerClassPolicy()) { field = field.clone(); field.setTable(descriptor.getDefaultTable()); } } FieldExpression expression = new FieldExpression(field, getBaseExpression().rebuildOn(newBase)); expression.setSelectIfOrderedBy(selectIfOrderedBy()); return expression; }
end = tableExp.getField(getEnd()); if (expression.shouldUseOuterJoin() && expression.getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) { join = start.isNull().or(start.lessThanEqual(value)); } else { end = expression.getField(getEnd(i)); if (expression.shouldUseOuterJoin() && expression.getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) { subJoin = start.isNull().or(start.lessThanEqual(value)); } else {