while(itMappings.hasNext()) { DatabaseMapping mapping = (DatabaseMapping)itMappings.next(); if(mapping.isManyToManyMapping() || mapping.isDirectCollectionMapping()) { if(dontCheckDescriptor || mapping.getDescriptor().equals(descriptor)) { Vector sourceFields = null; sourceFields = ((ManyToManyMapping)mapping).getSourceKeyFields(); targetFields = ((ManyToManyMapping)mapping).getSourceRelationKeyFields(); } else if(mapping.isDirectCollectionMapping()) { sourceFields = ((DirectCollectionMapping)mapping).getSourceKeyFields(); targetFields = ((DirectCollectionMapping)mapping).getReferenceKeyFields();
while(itMappings.hasNext()) { DatabaseMapping mapping = (DatabaseMapping)itMappings.next(); if(mapping.isManyToManyMapping() || mapping.isDirectCollectionMapping()) { if(dontCheckDescriptor || mapping.getDescriptor().equals(getDescriptor())) { Vector sourceFields = null; sourceFields = ((ManyToManyMapping)mapping).getSourceKeyFields(); targetFields = ((ManyToManyMapping)mapping).getSourceRelationKeyFields(); } else if(mapping.isDirectCollectionMapping()) { sourceFields = ((DirectCollectionMapping)mapping).getSourceKeyFields(); targetFields = ((DirectCollectionMapping)mapping).getReferenceKeyFields();
if (outerExpression.getMapping().isDirectCollectionMapping()) { targetTable = ((DirectCollectionMapping)outerExpression.getMapping()).getReferenceTable(); } else { outerJoinedAliases.addElement(newAlias); writer.write(newAlias.getQualifiedName()); } else if (outerExpression.getMapping().isDirectCollectionMapping()) {// for many to many mappings, you need to do some funky stuff to get the relation table's alias DatabaseTable newTarget = ((DirectCollectionMapping)outerExpression.getMapping()).getReferenceTable(); DatabaseTable newAlias = relationExpression.aliasForTable(newTarget);
/** * Build additional table/field definitions for the dscriptor, like relation table * and direct-collection, direct-map table, as well as reset LOB type for serialized * object mapping and type conversion maping for LOB usage */ private void postInitTableSchema(ClassDescriptor desc) { Iterator mappingIter = desc.getMappings().iterator(); while (mappingIter.hasNext()) { DatabaseMapping mapping = (DatabaseMapping) mappingIter.next(); if (mapping.isManyToManyMapping()) { buildRelationTableDefinition((ManyToManyMapping) mapping); } else if (mapping.isDirectCollectionMapping()) { buildDirectCollectionTableDefinition((DirectCollectionMapping) mapping, desc); } else if (mapping.isAggregateCollectionMapping()) { //need to figure out the target foreign key field and add it into the aggregate target table addForeignkeyFieldToAggregateTargetTable((AggregateCollectionMapping) mapping); } else if (mapping.isForeignReferenceMapping()) { if (mapping.isOneToOneMapping()) addForeignKeyFieldToSourceTargetTable((OneToOneMapping) mapping); else if (mapping.isOneToManyMapping()) addForeignKeyFieldToSourceTargetTable((OneToManyMapping) mapping); } } processAdditionalTablePkFields(desc); }
DatabaseTable targetAlias = null; if(outerExpression != null) { if (outerExpression.getMapping().isDirectCollectionMapping()) { targetTable = ((DirectCollectionMapping)outerExpression.getMapping()).getReferenceTable(); } else { } else if (outerExpression.getMapping().isDirectCollectionMapping()) {
validateMappingType(mapping); mapping.initialize(session); if (mapping.isAggregateObjectMapping() || ((mapping.isForeignReferenceMapping() && (!mapping.isDirectCollectionMapping())) && (!((ForeignReferenceMapping)mapping).usesIndirection()))) { getLockableMappings().add(mapping); iterator.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)iterator.next(); if (mapping.isAggregateObjectMapping() || ((mapping.isForeignReferenceMapping() && (!mapping.isDirectCollectionMapping())) && (!((ForeignReferenceMapping)mapping).usesIndirection()))) {
/** * INTERNAL: * Return if the represents an object comparison. */ protected boolean isObjectComparison() { if ((!getFirstChild().isObjectExpression()) || ((ObjectExpression)getFirstChild()).isAttribute()) { return false; } DatabaseMapping mapping = ((ObjectExpression)getFirstChild()).getMapping(); if ((mapping != null) && (mapping.isDirectCollectionMapping())) { return false; } return getSecondChild().isObjectExpression() || (getSecondChild().isValueExpression() || (getSecondChild().isFunctionExpression() && ((FunctionExpression)getSecondChild()).getOperator().isAnyOrAll())); }
/** * 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); } }
if (shouldUseOuterJoin && (!(mapping.isOneToOneMapping() || mapping.isOneToManyMapping() || mapping.isManyToManyMapping() || mapping.isAggregateCollectionMapping() || mapping.isDirectCollectionMapping()))) { throw QueryException.outerJoinIsOnlyValidForOneToOneMappings(getMapping());