/** * Set the table name for this field. */ public void setTableName(String tableName) { setTable(new DatabaseTable(tableName)); }
/** * Alias the supplied fields with respect to the expression node. Return copies of the fields */ protected Vector aliasFields(ObjectExpression node, Vector fields) { Vector result = new Vector(fields.size()); for (Enumeration e = fields.elements(); e.hasMoreElements();) { DatabaseField eachField = (DatabaseField)((DatabaseField)e.nextElement()).clone(); eachField.setTable(node.aliasForTable(eachField.getTable())); result.addElement(eachField); } return result; }
/** * INTERNAL: * Alias the database field for our current environment */ protected void initializeAliasedField() { DatabaseField tempField = (DatabaseField)getField().clone(); DatabaseTable aliasedTable = getAliasedTable(); // Put in a special check here so that if the aliasing does nothing we don't cache the // result because it's invalid. This saves us from caching premature data if e.g. debugging // causes us to print too early" // if (aliasedTable.equals(getField().getTable())) { // return; // } else { aliasedField = tempField; aliasedField.setTable(aliasedTable); // } }
/** * INTERNAL: * Alias the database field for our current environment */ private void initializeAliasedField() { DatabaseField tempField = (DatabaseField)getField().clone(); DatabaseTable aliasedTable = getAliasedTable(); // Put in a special check here so that if the aliasing does nothing we don't cache the // result because it's invalid. This saves us from caching premature data if e.g. debugging // causes us to print too early" // if (aliasedTable.equals(getField().getTable())) { // return; // } else { aliasedField = tempField; aliasedField.setTable(aliasedTable); // } }
/** * INTERNAL: * All the source relation key field names are converted to DatabaseField and stored. */ protected void initializeSourceRelationKeys(AbstractSession session) throws DescriptorException { if (getSourceRelationKeyFields().size() == 0) { throw DescriptorException.noSourceRelationKeysSpecified(this); } for (Enumeration entry = getSourceRelationKeyFields().elements(); entry.hasMoreElements();) { DatabaseField field = (DatabaseField)entry.nextElement(); if (field.hasTableName() && (!(field.getTableName().equals(getRelationTable().getName())))) { throw DescriptorException.relationKeyFieldNotProperlySpecified(field, this); } field.setTable(getRelationTable()); } }
/** * The reference keys on the reference table are initalized */ protected void initializeReferenceKeys(AbstractSession session) throws DescriptorException { if (getReferenceKeyFields().size() == 0) { throw DescriptorException.noReferenceKeyIsSpecified(this); } for (Enumeration referenceEnum = getReferenceKeyFields().elements(); referenceEnum.hasMoreElements();) { DatabaseField field = (DatabaseField)referenceEnum.nextElement(); if (field.hasTableName() && (!(field.getTableName().equals(getReferenceTable().getName())))) { throw DescriptorException.referenceKeyFieldNotProperlySpecified(field, this); } field.setTable(getReferenceTable()); } }
/** * INTERNAL: * All the target relation key field names are converted to DatabaseField and stored. */ protected void initializeTargetRelationKeys(AbstractSession session) { if (getTargetRelationKeyFields().size() == 0) { throw DescriptorException.noTargetRelationKeysSpecified(this); } for (Enumeration targetEnum = getTargetRelationKeyFields().elements(); targetEnum.hasMoreElements();) { DatabaseField field = (DatabaseField)targetEnum.nextElement(); if (field.hasTableName() && (!(field.getTableName().equals(getRelationTable().getName())))) { throw DescriptorException.relationKeyFieldNotProperlySpecified(field, this); } field.setTable(getRelationTable()); } }
/** * INTERNAL: * Fully-qualify the databaseField if the table is known. * CR 3791 */ public Expression getField(String fieldName) { // we need to check for full table qualification DatabaseField field = new DatabaseField(fieldName); if (!field.hasTableName()) { field.setTable(getTable()); } return getField(field); }
/** * INTERNAL: * The table of the field is ensured to be unique from the descriptor's tables. * If the field has no table the default table is assigned. * This is used only in initialization. */ public void buildField(DatabaseField field) { DatabaseTable table; if (field.hasTableName()) { table = getTable(field.getTableName()); } else { table = getDefaultTable(); } field.setTable(table); }
/** * INTERNAL: * Initialize any information in the receiver that requires its descriptor. * Set the receiver's descriptor back reference. * @param descriptor is the owner descriptor of the receiver. */ public void initialize(ClassDescriptor descriptor) { super.initialize(descriptor); if (!getField().hasTableName()) { getField().setTable(descriptor.getDefaultTable()); } }
/** * The field name on the reference table is initialized and cached. */ protected void initializeDirectKeyField(AbstractSession session) throws DescriptorException { if (getDirectKeyField() == null) { throw DescriptorException.directFieldNameNotSet(this); } getDirectKeyField().setTable(getReferenceTable()); getDirectKeyField().setIndex(1); }
/** * The field name on the reference table is initialized and cached. */ protected void initializeDirectField(AbstractSession session) throws DescriptorException { if (getDirectField() == null) { throw DescriptorException.directFieldNameNotSet(this); } getDirectField().setTable(getReferenceTable()); getDirectField().setIndex(0); }
/** * INTERNAL: * If field names are different in the source and aggregate objects then the translation * is done here. The aggregate field name is converted to source field name from the * field name mappings stored. */ protected void translateFields(ClassDescriptor clonedDescriptor, AbstractSession session) { for (Enumeration entry = clonedDescriptor.getFields().elements(); entry.hasMoreElements();) { DatabaseField field = (DatabaseField)entry.nextElement(); String nameInAggregate = field.getName(); String nameInSource = (String)getAggregateToSourceFieldNames().get(nameInAggregate); // Do not modify non-translated fields. if (nameInSource != null) { DatabaseField fieldInSource = new DatabaseField(nameInSource); // Check if the translated field specified a table qualifier. if (fieldInSource.getName().equals(nameInSource)) { // No table so just set the field name. field.setName(nameInSource); } else { // There is a table, so set the name and table. field.setName(fieldInSource.getName()); field.setTable(clonedDescriptor.getTable(fieldInSource.getTable().getName())); } } } clonedDescriptor.rehashFieldDependancies(session); }
DatabaseField primaryKeyField = (DatabaseField)primaryKeyFields.get(pkIndex); DatabaseField secondaryKeyField = (DatabaseField)primaryKeyField.clone(); secondaryKeyField.setTable(table); newKeyMapping.put(primaryKeyField, secondaryKeyField);
/** * INTERNAL: * A DatabaseField is built from the given field name. */ // * added 9/7/00 by Les Davis // * bug fix for null pointer in initialization of mappings in remote session public DatabaseField buildField(String fieldName) { DatabaseField field = new DatabaseField(fieldName); DatabaseTable table; if (field.hasTableName()) { table = getTable(field.getTableName()); } else if (getDefaultTable() != null) { table = getDefaultTable(); } else { table = getTable(getTableName()); } field.setTable(table); return field; }
all.setTable(table); sqlStatement.addField(all); sqlStatement.normalize(session, null);
resolvedDatabaseField.setTable(childField.getTable());
/** * INTERNAL: * Print SQL onto the stream, using the ExpressionPrinter for context */ public void printSQL(ExpressionSQLPrinter printer) { if (isAttribute()) { printer.printField(getAliasedField()); } // If the mapping is a direct collection then this falls into a gray area. // It must be treated as an attribute at this moment for it has a direct field. // However it is not an attribute in the sense that it also represents a foreign // reference and a mapping criteria has been added. // For bug 2900974 these are now handled as non-attributes during normalize but // as attributes when printing SQL. // if ((getMapping() != null) && getMapping().isDirectCollectionMapping()) { DirectCollectionMapping directCollectionMapping = (DirectCollectionMapping)getMapping(); // The aliased table comes for free as it was a required part of the join criteria. TableExpression table = (TableExpression)getTable(directCollectionMapping.getReferenceTable()); DatabaseTable aliasedTable = table.aliasForTable(table.getTable()); DatabaseField aliasedField = (DatabaseField)directCollectionMapping.getDirectField().clone(); aliasedField.setTable(aliasedTable); printer.printField(aliasedField); } }