/** * INTERNAL: * Find the alias for a given table */ public DatabaseTable aliasForTable(DatabaseTable table) { return getBaseExpression().aliasForTable(table); }
/** * INTERNAL: * Find the alias for a given table from the first or second child in the additionalOuterJoinCriteria */ public DatabaseTable aliasForTable(DatabaseTable table) { DatabaseTable alias = null; if (getFirstChild() != null) { alias = getFirstChild().aliasForTable(table); } if ((alias == null) && (getSecondChild() != null)) { alias = getSecondChild().aliasForTable(table); } return alias; }
/** * INTERNAL: * Find the alias for a given table */ public DatabaseTable aliasForTable(DatabaseTable table) { if (tableAliases == null) { if (getBaseExpression() == null) { return null; } return getBaseExpression().aliasForTable(table); } return tableAliases.keyAtValue(table); }
DatabaseTable table = orderByField.getTable(); if (exp.getFields().contains(orderByField) && (expression.aliasForTable(table).equals(exp.aliasForTable(table)))) {
DatabaseTable alias = onExpression.aliasForTable(table); outerJoinedAliases.addElement(alias); writer.write(alias.getQualifiedName());
DatabaseTable sourceAlias = outerExpression.getBaseExpression().aliasForTable(sourceTable); DatabaseTable targetAlias = outerExpression.aliasForTable(targetTable);
sourceAlias = outerExpression.getBaseExpression().aliasForTable(sourceTable); targetAlias = outerExpression.aliasForTable(targetTable); } else { targetTable = (DatabaseTable)((ClassDescriptor)getDescriptorsForMultitableInheritanceOnly().get(index)).getInheritancePolicy().getChildrenTables().get(0); Expression exp = (Expression)((Map)getOuterJoinedAdditionalJoinCriteria().elementAt(index)).get(targetTable); sourceAlias = exp.aliasForTable(sourceTable); targetAlias = exp.aliasForTable(targetTable); DatabaseTable newAlias = onExpression.aliasForTable(targetTable); writer.write(" LEFT OUTER JOIN "); writer.write(targetTable.getQualifiedName()); DatabaseTable relationAlias = ((Expression)getOuterJoinedMappingCriteria().elementAt(index)).aliasForTable(relationTable); writer.write(" LEFT OUTER JOIN (");
/** * INTERNAL: * Find the alias for a given table */ public DatabaseTable aliasForTable(DatabaseTable table) { if (isAttribute() || ((getMapping() != null) && (getMapping().isAggregateObjectMapping() || getMapping().isTransformationMapping()))) { return ((DataExpression)getBaseExpression()).aliasForTable(table); } //"ref" and "structure" mappings, no table printed in the FROM clause, need to get the table alias form the parent table if ((getMapping() != null) && (getMapping().isReferenceMapping() || getMapping().isStructureMapping())) { DatabaseTable alias = getBaseExpression().aliasForTable((DatabaseTable)getMapping().getDescriptor().getTables().firstElement()); alias.setName(alias.getName() + "." + getMapping().getField().getName()); return alias; } return super.aliasForTable(table); }
/** * INTERNAL: * Append the field name to the writer. Should be overriden for special operators such as functions. */ protected void writeField(ExpressionSQLPrinter printer, DatabaseField field, SQLSelectStatement statement) { //print ", " before each selected field except the first one if (printer.isFirstElementPrinted()) { printer.printString(", "); } else { printer.setIsFirstElementPrinted(true); } if (statement.requiresAliases()) { if (field.getTable() != lastTable) { lastTable = field.getTable(); currentAlias = aliasForTable(lastTable); } printer.printString(currentAlias.getQualifiedName()); printer.printString("."); printer.printString(field.getName()); } else { printer.printString(field.getName()); } }