/** * */ public String getTableName() { return getTable().getName(); }
/** * 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: * Assumes there is one primary key field set. This method should be called * when qualifying any primary key field (from a join column) for this * descriptor. This method was created because in an inheritance hierarchy * with a joined strategy we can't use getPrimaryTableName() since it would * return the wrong table name. From the spec, the primary key must be * defined on the entity that is the root of the entity hierarchy or on a * mapped superclass of the entity hierarchy. The primary key must be * defined exactly once in an entity hierarchy. */ public String getPrimaryKeyTableName() { return ((DatabaseField)(getPrimaryKeyFields().iterator().next())).getTable().getQualifiedName(); }
/** * Reset the field's name and table from the qualified name. */ public void resetQualifiedName(String qualifiedName) { setIndex(-1); int index = qualifiedName.lastIndexOf('.'); if (index == -1) { setName(qualifiedName); getTable().setName(""); getTable().setTableQualifier(""); } else { setName(qualifiedName.substring(index + 1, qualifiedName.length())); getTable().setPossiblyQualifiedName(qualifiedName.substring(0, index)); } }
/** * INTERNAL: * Returns the foreign key relationships used for multiple tables which were specified by the user. Used * by the Project XML writer to output these associations * * @see #adjustMultipleTableInsertOrder() */ public Vector getMultipleTablePrimaryKeyAssociations() { Vector associations = new Vector(getAdditionalTablePrimaryKeyFields().size() * 2); Iterator tablesHashtable = getAdditionalTablePrimaryKeyFields().values().iterator(); while (tablesHashtable.hasNext()) { Map tableHash = (Map)tablesHashtable.next(); Iterator fieldEnumeration = tableHash.keySet().iterator(); while (fieldEnumeration.hasNext()) { DatabaseField keyField = (DatabaseField)fieldEnumeration.next(); //PRS#36802(CR#2057) contains() is changed to containsKey() if (!getMultipleTableForeignKeys().containsKey(keyField.getTable())) { Association association = new Association(keyField.getQualifiedName(), ((DatabaseField)tableHash.get(keyField)).getQualifiedName()); associations.addElement(association); } } } return associations; }
/** * INTERNAL: * Returns the foreign key relationships used for multiple tables which were specified by the user. Used * by the Project XML writer to output these associations * * @see #adjustMultipleTableInsertOrder() * @return java.util.Hashtable */ public Vector getMultipleTableForeignKeyAssociations() { Vector associations = new Vector(getAdditionalTablePrimaryKeyFields().size() * 2); Iterator tablesHashtable = getAdditionalTablePrimaryKeyFields().values().iterator(); while (tablesHashtable.hasNext()) { Map tableHash = (Map)tablesHashtable.next(); Iterator fieldEnumeration = tableHash.keySet().iterator(); while (fieldEnumeration.hasNext()) { DatabaseField keyField = (DatabaseField)fieldEnumeration.next(); //PRS#36802(CR#2057) contains() is changed to containsKey() if (getMultipleTableForeignKeys().containsKey(keyField.getTable())) { Association association = new Association(keyField.getQualifiedName(), ((DatabaseField)tableHash.get(keyField)).getQualifiedName()); associations.addElement(association); } } } return associations; }
/** * Add the foreign key to the aggregate collection mapping target table */ private void addForeignkeyFieldToAggregateTargetTable(AggregateCollectionMapping mapping) { //unlike normal one-to-many mapping, aggregate collection mapping does not have 1:1 back reference //mapping, so the target foreign key fields are not stored in the target descriptor. Iterator targFKIter = mapping.getTargetForeignKeyFields().iterator(); while (targFKIter.hasNext()) { DatabaseField dbField = (DatabaseField) targFKIter.next(); //retrive the target table denifition TableDefinition targTblDef = getTableDefFromDBTable(dbField.getTable()); //add the target foreign key field definition to the table definition targTblDef.addField(getFieldDefFromDBField(dbField, false)); } }
/** * Build field definitions and foreign key constraints for all many-to-many relation table. */ private void buildRelationTableFields(TableDefinition tblDef, Vector fkFields, Vector targetFields) { assert fkFields.size() > 0 && fkFields.size() == targetFields.size(); DatabaseField fkField = null; DatabaseField targetField = null; Vector<String> fkFieldNames = new Vector(); Vector<String> targetFieldNames = new Vector(); for (int index = 0; index < fkFields.size(); index++) { fkField = (DatabaseField) fkFields.get(index); targetField = (DatabaseField) targetFields.get(index); fkFieldNames.add(fkField.getName()); targetFieldNames.add(targetField.getName()); fkField = resolveDatabaseField(fkField, targetField); setFieldToRelationTable(fkField, tblDef); } // add a foreign key constraint from fk field to target field DatabaseTable targetTable = targetField.getTable(); TableDefinition targetTblDef = getTableDefFromDBTable(targetTable); addForeignKeyConstraint(tblDef, targetTblDef, fkFieldNames, targetFieldNames); }
/** * INTERNAL: * Add the multiple fields, if is a foreign key then add the tables to the * foreign keys ordering. */ protected void addMultipleTableForeignKeys(DatabaseField sourceField, DatabaseField targetField, boolean isForeignKey) throws DescriptorException { // Make sure that the table is fully qualified. if ((!sourceField.hasTableName()) || (!targetField.hasTableName())) { throw DescriptorException.multipleTablePrimaryKeyMustBeFullyQualified(this); } DatabaseTable sourceTable = sourceField.getTable(); DatabaseTable targetTable = targetField.getTable(); setAdditionalTablePrimaryKeyFields(targetTable, sourceField, targetField); if (isForeignKey) { getMultipleTableForeignKeys().put(sourceTable, targetTable); } }
/** * INTERNAL: */ protected void initializePrimaryKey(DatabaseField primaryKey) { buildField(primaryKey); if (!primaryKey.getTable().equals(getDefaultTable())) { getPrimaryKeyFields().remove(primaryKey); } }
/** * Do any required validation for this node. Throw an exception if it's incorrect. */ public void validateNode() { DataExpression base = (DataExpression)getBaseExpression(); if (getField().getTable().hasName()) { Vector tables = base.getOwnedTables(); if ((tables != null) && (!tables.contains((getField().getTable())))) { throw QueryException.invalidTableForFieldInExpression(getField()); } } }
/** * Return the qualified name of the field. */ public String getQualifiedName() { if (hasTableName()) { return getTable().getQualifiedName() + "." + getName(); } else { return getName(); } }
public void iterate(Expression each) { if(each instanceof DataExpression) { DataExpression dataExpression = (DataExpression)each; DatabaseField field = dataExpression.getField(); if(field != null) { if(dataExpression.getBaseExpression() != getStatement().getBuilder()) { ((Collection)getResult()).remove(dataExpression.getAliasedField().getTable()); } } } } public boolean shouldIterateOverSubSelects() {
protected SQLDeleteStatement buildDeleteAllStatementForMapping(SQLCall selectCallForExist, SQLSelectStatement selectStatementForExist, Vector sourceFields, Vector targetFields) { DatabaseTable targetTable = ((DatabaseField)targetFields.firstElement()).getTable(); if(selectCallForExist == null) { return buildDeleteStatementForDeleteAllQuery(targetTable); } SQLDeleteAllStatement deleteAllStatement = new SQLDeleteAllStatement(); deleteAllStatement.setTable(targetTable); deleteAllStatement.setTranslationRow(getTranslationRow()); deleteAllStatement.setSelectCallForExist(selectCallForExist); DatabaseTable sourceTable = ((DatabaseField)sourceFields.firstElement()).getTable(); if(selectStatementForExist != null) { deleteAllStatement.setTableAliasInSelectCallForExist(getAliasTableName(selectStatementForExist, sourceTable)); } deleteAllStatement.setAliasedFieldsForJoin(sourceFields); deleteAllStatement.setOriginalFieldsForJoin(targetFields); return deleteAllStatement; }
/** * Return the alias for our table */ private DatabaseTable getAliasedTable() { DataExpression base = (DataExpression)getBaseExpression(); if (!getField().hasTableName()) { base.getDescriptor().buildField(getField()); } DatabaseTable alias = base.aliasForTable(getField().getTable()); if (alias == null) { return getField().getTable(); } else { return alias; } }
/** * Build a foriegn key constraint using FieldDefinition.getForeignKeyFieldName(). */ protected ForeignKeyConstraint buildForeignKeyConstraint(FieldDefinition field, DatabasePlatform platform) { Vector sourceFields = new Vector(); Vector targetFields = new Vector(); ForeignKeyConstraint fkConstraint = new ForeignKeyConstraint(); DatabaseField tempTargetField = new DatabaseField(field.getForeignKeyFieldName()); DatabaseField tempSourceField = new DatabaseField(field.getName()); sourceFields.addElement(tempSourceField.getName()); targetFields.addElement(tempTargetField.getName()); fkConstraint.setSourceFields(sourceFields); fkConstraint.setTargetFields(targetFields); fkConstraint.setTargetTable(tempTargetField.getTable().getQualifiedName()); String tempName = buildForeignKeyConstraintName(this.getName(), tempSourceField.getName(), platform.getMaxForeignKeyNameSize()); fkConstraint.setName(tempName); return fkConstraint; }
/** * 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()); } }
/** * INTERNAL: * Return a select statement that will be used to query the class indicators required to query. * This is used in the abstract-multiple read. */ public SQLSelectStatement buildClassIndicatorSelectStatement(ObjectLevelReadQuery query) { SQLSelectStatement selectStatement; selectStatement = new SQLSelectStatement(); selectStatement.useDistinct(); selectStatement.addTable(classIndicatorField.getTable()); selectStatement.addField(getClassIndicatorField()); // 2612538 - the default size of IdentityHashtable (32) is appropriate IdentityHashtable clonedExpressions = new IdentityHashtable(); selectStatement.setWhereClause(((ExpressionQueryMechanism)query.getQueryMechanism()).buildBaseSelectionCriteria(false, clonedExpressions)); appendWithAllSubclassesExpression(selectStatement); selectStatement.setTranslationRow(query.getTranslationRow()); selectStatement.normalize(query.getSession(), getDescriptor(), clonedExpressions); ExpressionQueryMechanism m = (ExpressionQueryMechanism)query.getQueryMechanism(); return selectStatement; }