/** * INTERNAL: */ public Expression newDerivedField(DatabaseField field) { FieldExpression result = new FieldExpression(field, this); addDerivedField(result); return result; }
/** * INTERNAL: * Find the alias for a given table. A TableEntry is a place holder and its base expression holds * all the relevant information. Get the alias from the baseExpression */ @Override public DatabaseTable aliasForTable(DatabaseTable table) { return ((DataExpression)getBaseExpression()).aliasForTable(table); }
/** * INTERNAL: * Normalize the expression into a printable structure. * Any joins must be added to form a new root. */ public Expression normalize(ExpressionNormalizer normalizer) { if (getBaseExpression() != null) { // First normalize the base. setBaseExpression(getBaseExpression().normalize(normalizer)); if (getAsOfClause() == null) { asOf(getBaseExpression().getAsOfClause()); } } return super.normalize(normalizer); }
/** * INTERNAL: * Used for cloning. */ protected void postCopyIn(Map alreadyDone) { super.postCopyIn(alreadyDone); clearAliases(); derivedFields = copyCollection(derivedFields, alreadyDone); derivedTables = copyCollection(derivedTables, alreadyDone); }
/** * INTERNAL: * Alias a particular table within this node */ @Override protected void assignAlias(String name, DatabaseTable table) { if (!getBuilder().getSession().getProject().hasGenericHistorySupport()) { assignAlias(new DecoratedDatabaseTable(name, getAsOfClause()), table); } else { assignAlias(new DatabaseTable(name), table); } }
} else if (fieldExpression != null) { if (fieldExpression.getBaseExpression() instanceof ExpressionBuilder) { field = getDescriptor().getObjectBuilder().getFieldForQueryKeyName(fieldExpression.getName()); DataExpression fieldExpressionClone = (DataExpression)fieldExpression.clone(); fieldExpressionClone.getBuilder().setQueryClass(getQuery().getReferenceClass()); fieldExpressionClone.getBuilder().setSession(getSession().getRootSession(null)); field = fieldExpressionClone.getField(); if(field == null) { throw QueryException.updateAllQueryAddUpdateDoesNotDefineField(getDescriptor(), getQuery(), fieldExpression.toString()); throw QueryException.updateAllQueryAddUpdateDefinesWrongField(getDescriptor(), getQuery(), attributeName, field.getQualifiedName()); } else { throw QueryException.updateAllQueryAddUpdateDefinesWrongField(getDescriptor(), getQuery(), fieldExpression.toString(), field.getQualifiedName());
/** * INTERNAL: * Normalize the expression into a printable structure. * Any joins must be added to form a new root. */ @Override public Expression normalize(ExpressionNormalizer normalizer) { if (this.hasBeenNormalized) { return this; } this.hasBeenNormalized = true; if (this.baseExpression != null) { // First normalize the base. setBaseExpression(this.baseExpression.normalize(normalizer)); if (getAsOfClause() == null) { asOf(this.baseExpression.getAsOfClause()); } } return super.normalize(normalizer); }
/** * Return the alias for our table */ private DatabaseTable getAliasedTable() { DataExpression base = (DataExpression)getBaseExpression(); DatabaseField field = getField(); if (!field.hasTableName()) { if (base.getDescriptor() != null){ field = base.getDescriptor().buildField(field); } } DatabaseTable alias = base.aliasForTable(field.getTable()); if (alias == null) { return field.getTable(); } else { return alias; } }
/** * INTERNAL: * Return if the expression is equal to the other. * This is used to allow dynamic expression's SQL to be cached. */ @Override public boolean equals(Object expression) { if (this == expression) { return true; } if (!super.equals(expression)) { return false; } if ((this.onClause != null) || (((ObjectExpression)expression).onClause != null)) { return false; } return this.shouldUseOuterJoin == ((ObjectExpression)expression).shouldUseOuterJoin; }
/** * INTERNAL: * Compute a consistent hash-code for the expression. * This is used to allow dynamic expression's SQL to be cached. */ public int computeHashCode() { int hashCode = super.computeHashCode(); if (getField() != null) { hashCode = hashCode + getField().hashCode(); } return hashCode; }
/** * INTERNAL: */ public void clearAliases() { super.clearAliases(); aliasedField = null; }
/** * INTERNAL: */ public Expression newDerivedTable(DatabaseTable table) { TableExpression result = new TableExpression(table); result.setBaseExpression(this); addDerivedTable(result); return result; }
/** * INTERNAL: * Alias a particular table within this node */ @Override protected void assignAlias(DatabaseTable alias, DatabaseTable table) { if (this.baseExpression.isQueryKeyExpression()){ QueryKeyExpression qkExpression = ((QueryKeyExpression)this.baseExpression); if (qkExpression.getTableAliases() != null && qkExpression.getTableAliases().keyAtValue(table) != null ) { return; } } super.assignAlias(alias, table); }
} else if (fieldExpression != null) { if (fieldExpression.getBaseExpression() instanceof ExpressionBuilder) { field = getDescriptor().getObjectBuilder().getFieldForQueryKeyName(fieldExpression.getName()); DataExpression fieldExpressionClone = (DataExpression)fieldExpression.clone(); fieldExpressionClone.getBuilder().setQueryClass(getQuery().getReferenceClass()); fieldExpressionClone.getBuilder().setSession(getSession().getRootSession(null)); field = fieldExpressionClone.getField(); if(field == null) { throw QueryException.updateAllQueryAddUpdateDoesNotDefineField(getDescriptor(), getQuery(), fieldExpression.toString()); throw QueryException.updateAllQueryAddUpdateDefinesWrongField(getDescriptor(), getQuery(), attributeName, field.getQualifiedName()); } else { throw QueryException.updateAllQueryAddUpdateDefinesWrongField(getDescriptor(), getQuery(), fieldExpression.toString(), field.getQualifiedName());
/** * INTERNAL: * Alias a particular table within this node */ protected void assignAlias(String name, DatabaseTable table) { if (!getBuilder().getSession().getProject().hasGenericHistorySupport()) { assignAlias(new DecoratedDatabaseTable(name, getAsOfClause()), table); } else { assignAlias(new DatabaseTable(name), table); } }
/** * INTERNAL: * Normalize the expression into a printable structure. * Any joins must be added to form a new root. */ @Override public Expression normalize(ExpressionNormalizer normalizer) { if (this.hasBeenNormalized) { return this; } this.hasBeenNormalized = true; if (this.baseExpression != null) { // First normalize the base. setBaseExpression(this.baseExpression.normalize(normalizer)); if (getAsOfClause() == null) { asOf(this.baseExpression.getAsOfClause()); } } return super.normalize(normalizer); }
/** * INTERNAL: * Used for cloning. */ @Override protected void postCopyIn(Map alreadyDone) { super.postCopyIn(alreadyDone); clearAliases(); this.derivedFields = copyCollection(this.derivedFields, alreadyDone); this.derivedTables = copyCollection(this.derivedTables, alreadyDone); }
/** * Return the alias for our table */ private DatabaseTable getAliasedTable() { DataExpression base = (DataExpression)getBaseExpression(); DatabaseField field = getField(); if (!field.hasTableName()) { if (base.getDescriptor() != null){ field = base.getDescriptor().buildField(field); } } DatabaseTable alias = base.aliasForTable(field.getTable()); if (alias == null) { return field.getTable(); } else { return alias; } }
/** * INTERNAL: * Return if the expression is equal to the other. * This is used to allow dynamic expression's SQL to be cached. */ @Override public boolean equals(Object expression) { if (this == expression) { return true; } if (!super.equals(expression)) { return false; } if ((this.onClause != null) || (((ObjectExpression)expression).onClause != null)) { return false; } return this.shouldUseOuterJoin == ((ObjectExpression)expression).shouldUseOuterJoin; }
/** * INTERNAL: * Compute a consistent hash-code for the expression. * This is used to allow dynamic expression's SQL to be cached. */ public int computeHashCode() { int hashCode = super.computeHashCode(); if (getTable() != null) { hashCode = hashCode + getTable().hashCode(); } return hashCode; }