/** * INTERNAL: * Assign aliases to any tables which I own. Start with t(initialValue), * and return the new value of the counter , i.e. if initialValue is one * and I have tables ADDRESS and EMPLOYEE I will assign them t1 and t2 respectively, and return 3. */ public int assignTableAliasesStartingAt(int initialValue) { //This assumes that the typeExpressionBase will alias its own tables, so we only need to handle //the extra's caused by this treat expression. if (hasBeenAliased()) { return initialValue; } int counter = initialValue; if (this.typeExpressionBase != null) { counter = this.typeExpressionBase.assignTableAliasesStartingAt(counter); } //Only difference between this and ObjectExpression's assignTableAliasesStartingAt is this uses getOwnedSubTables // instead of getOwnedTables which returns everything. List<DatabaseTable> ownedTables = getOwnedSubTables(); if (ownedTables != null) { for (DatabaseTable table : ownedTables) { assignAlias("t" + counter, table); counter++; } } this.hasBeenAliased = true; return counter; }
public ClassDescriptor getDescriptor() { if (isAttribute()) { //TODO: add support for treat on attributes throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression()); } if (descriptor == null) { ClassDescriptor rootDescriptor = typeExpressionBase.getDescriptor(); descriptor = convertToCastDescriptor(rootDescriptor, getSession()); } return descriptor; }
public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase) { if (oldBase == null || this.typeExpressionBase == oldBase) { Expression twistedBase = this.typeExpressionBase.twistedForBaseAndContext(newBase, context, oldBase); TreatAsExpression result = (TreatAsExpression)twistedBase.treat(this.castClass); if (shouldUseOuterJoin) { result.doUseOuterJoin(); } if (shouldQueryToManyRelationship) { result.doQueryToManyRelationship(); } return result; } return this; }
Expression typeExpression = getTypeClause(); typeExpression.normalize(normalizer); setBaseExpression(this.baseExpression.normalize(normalizer)); if (getAsOfClause() == null) { asOf(this.baseExpression.getAsOfClause()); validateNode(); boolean isSTI = getOwnedSubTables().isEmpty(); Expression treatJoinTableExpressions = getTreatCriteria(); if (getSession().getPlatform().isInformixOuterJoin()) { normalizer.addAdditionalLocalExpression(typeExpression.and(additionalTreatExpressionCriteria()).and(this.onClause)); return this; } else if (((!getSession().getPlatform().shouldPrintOuterJoinInWhereClause())) || (!getSession().getPlatform().shouldPrintInnerJoinInWhereClause())) { map.putAll(additionalTreatExpressionCriteriaMap()); } else { statement.getOuterJoinExpressionsHolders().get(postition).outerJoinedAdditionalJoinCriteria = additionalTreatExpressionCriteriaMap(); } else if (!getSession().getPlatform().shouldPrintOuterJoinInWhereClause() || (!getSession().getPlatform().shouldPrintInnerJoinInWhereClause())) { Map additionalExpMap = additionalTreatExpressionCriteriaMap(); if (additionalExpMap!=null && !additionalExpMap.isEmpty()) { statement.addOuterJoinExpressionsHolders(additionalExpMap, parentDescriptor);
/** * Return an expression that allows you to treat its base as if it were a subclass of the class returned by the base * This can only be called on an ExpressionBuilder, the result of expression.get(String), expression.getAllowingNull(String), * the result of expression.anyOf("String") or the result of expression.anyOfAllowingNull("String") * * downcast uses Expression.type() internally to guarantee the results are of the specified class. * <p>Example: * <pre><blockquote> * Expression: employee.get("project").as(LargeProject.class).get("budget").equal(1000) * Java: ((LargeProject)employee.getProjects().get(0)).getBudget() == 1000 * SQL: LPROJ.PROJ_ID (+)= PROJ.PROJ_ID AND L_PROJ.BUDGET = 1000 AND PROJ.TYPE = "L" * </blockquote></pre> */ @Override public Expression treat(Class castClass){ //to be used on expressionBuilders QueryKeyExpression clonedExpression = new TreatAsExpression(castClass, this); clonedExpression.shouldQueryToManyRelationship = false; clonedExpression.hasQueryKey = false; clonedExpression.hasMapping = false; this.addDerivedExpression(clonedExpression); return clonedExpression; }
throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression()); throw QueryException.castMustUseInheritance(getBaseExpression()); throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression());
Expression typeExpression = getTypeClause(); typeExpression.normalize(normalizer); setBaseExpression(this.baseExpression.normalize(normalizer)); if (getAsOfClause() == null) { asOf(this.baseExpression.getAsOfClause()); validateNode(); boolean isSTI = getOwnedSubTables().isEmpty(); Expression treatJoinTableExpressions = getTreatCriteria(); if (getSession().getPlatform().isInformixOuterJoin()) { normalizer.addAdditionalLocalExpression(typeExpression.and(additionalTreatExpressionCriteria()).and(this.onClause)); return this; } else if (((!getSession().getPlatform().shouldPrintOuterJoinInWhereClause())) || (!getSession().getPlatform().shouldPrintInnerJoinInWhereClause())) { map.putAll(additionalTreatExpressionCriteriaMap()); } else { statement.getOuterJoinExpressionsHolders().get(postition).outerJoinedAdditionalJoinCriteria = additionalTreatExpressionCriteriaMap(); } else if (!getSession().getPlatform().shouldPrintOuterJoinInWhereClause() || (!getSession().getPlatform().shouldPrintInnerJoinInWhereClause())) { Map additionalExpMap = additionalTreatExpressionCriteriaMap(); if (additionalExpMap!=null && !additionalExpMap.isEmpty()) { statement.addOuterJoinExpressionsHolders(additionalExpMap, parentDescriptor);
/** * Return an expression that allows you to treat its base as if it were a subclass of the class returned by the base * This can only be called on an ExpressionBuilder, the result of expression.get(String), expression.getAllowingNull(String), * the result of expression.anyOf("String") or the result of expression.anyOfAllowingNull("String") * * downcast uses Expression.type() internally to guarantee the results are of the specified class. * <p>Example: * <pre><blockquote> * Expression: employee.get("project").as(LargeProject.class).get("budget").equal(1000) * Java: ((LargeProject)employee.getProjects().get(0)).getBudget() == 1000 * SQL: LPROJ.PROJ_ID (+)= PROJ.PROJ_ID AND L_PROJ.BUDGET = 1000 AND PROJ.TYPE = "L" * </blockquote></pre> */ @Override public Expression treat(Class castClass){ //to be used on expressionBuilders QueryKeyExpression clonedExpression = new TreatAsExpression(castClass, this); clonedExpression.shouldQueryToManyRelationship = false; clonedExpression.hasQueryKey = false; clonedExpression.hasMapping = false; this.addDerivedExpression(clonedExpression); return clonedExpression; }
throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression()); throw QueryException.castMustUseInheritance(getBaseExpression()); throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression());
public ClassDescriptor getDescriptor() { if (isAttribute()) { //TODO: add support for treat on attributes throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression()); } if (descriptor == null) { ClassDescriptor rootDescriptor = typeExpressionBase.getDescriptor(); descriptor = convertToCastDescriptor(rootDescriptor, getSession()); } return descriptor; }
/** * INTERNAL: * Assign aliases to any tables which I own. Start with t(initialValue), * and return the new value of the counter , i.e. if initialValue is one * and I have tables ADDRESS and EMPLOYEE I will assign them t1 and t2 respectively, and return 3. */ public int assignTableAliasesStartingAt(int initialValue) { //This assumes that the typeExpressionBase will alias its own tables, so we only need to handle //the extra's caused by this treat expression. if (hasBeenAliased()) { return initialValue; } int counter = initialValue; if (this.typeExpressionBase != null) { counter = this.typeExpressionBase.assignTableAliasesStartingAt(counter); } //Only difference between this and ObjectExpression's assignTableAliasesStartingAt is this uses getOwnedSubTables // instead of getOwnedTables which returns everything. List<DatabaseTable> ownedTables = getOwnedSubTables(); if (ownedTables != null) { for (DatabaseTable table : ownedTables) { assignAlias("t" + counter, table); counter++; } } this.hasBeenAliased = true; return counter; }
public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase) { if (oldBase == null || this.typeExpressionBase == oldBase) { Expression twistedBase = this.typeExpressionBase.twistedForBaseAndContext(newBase, context, oldBase); TreatAsExpression result = (TreatAsExpression)twistedBase.treat(this.castClass); if (shouldUseOuterJoin) { result.doUseOuterJoin(); } if (shouldQueryToManyRelationship) { result.doQueryToManyRelationship(); } return result; } return this; }
/** * ADVANCED: * Return an expression that allows you to treat its base as if it were a subclass of the class returned by the base * This can only be called on an ExpressionBuilder, the result of expression.get(String), expression.getAllowingNull(String), * the result of expression.anyOf("String") or the result of expression.anyOfAllowingNull("String") * * downcast uses Expression.type() internally to guarantee the results are of the specified class. * <p>Example: * <pre><blockquote> * EclipseLink: employee.get("project").treat(LargeProject.class).get("budget").equal(1000) * Java: ((LargeProject)employee.getProjects().get(0)).getBudget() == 1000 * SQL: LPROJ.PROJ_ID (+)= PROJ.PROJ_ID AND L_PROJ.BUDGET = 1000 AND PROJ.TYPE = "L" * </blockquote></pre> */ @Override public Expression treat(Class castClass){ //to be used in 'where treat(t as PerformanceTireInfo).speedRating > 100' QueryKeyExpression clonedExpression = new TreatAsExpression(castClass, this); clonedExpression.shouldQueryToManyRelationship = this.shouldQueryToManyRelationship; //using shouldUseOuterJoin to indicate the join to use between the t and PerformanceTireInfo subclass. clonedExpression.hasQueryKey = this.hasQueryKey; clonedExpression.hasMapping = this.hasMapping; this.addDerivedExpression(clonedExpression); return clonedExpression; }
/** * ADVANCED: * Return an expression that allows you to treat its base as if it were a subclass of the class returned by the base * This can only be called on an ExpressionBuilder, the result of expression.get(String), expression.getAllowingNull(String), * the result of expression.anyOf("String") or the result of expression.anyOfAllowingNull("String") * * downcast uses Expression.type() internally to guarantee the results are of the specified class. * <p>Example: * <pre><blockquote> * EclipseLink: employee.get("project").treat(LargeProject.class).get("budget").equal(1000) * Java: ((LargeProject)employee.getProjects().get(0)).getBudget() == 1000 * SQL: LPROJ.PROJ_ID (+)= PROJ.PROJ_ID AND L_PROJ.BUDGET = 1000 AND PROJ.TYPE = "L" * </blockquote></pre> */ @Override public Expression treat(Class castClass){ //to be used in 'where treat(t as PerformanceTireInfo).speedRating > 100' QueryKeyExpression clonedExpression = new TreatAsExpression(castClass, this); clonedExpression.shouldQueryToManyRelationship = this.shouldQueryToManyRelationship; //using shouldUseOuterJoin to indicate the join to use between the t and PerformanceTireInfo subclass. clonedExpression.hasQueryKey = this.hasQueryKey; clonedExpression.hasMapping = this.hasMapping; this.addDerivedExpression(clonedExpression); return clonedExpression; }