use of org.eclipse.persistence.mappings.RelationTableMechanism in project eclipselink by eclipse-ee4j.
the class ObjectAccessor method processOwningMappingKeys.
/**
* INTERNAL:
* Process the the correct metadata for the owning side of a one to one
* mapping. Note, the order of checking is important, that is, check for
* a mapsId first.
*/
protected void processOwningMappingKeys(OneToOneMapping mapping) {
if (derivesId()) {
// We need to process the join columns as we normally would.
// Then we must update the fields from our derived id accessor.
processForeignKeyRelationship(mapping);
if (hasMapsId()) {
processMapsId(mapping);
} else {
processId(mapping);
}
} else if (isOneToOnePrimaryKeyRelationship()) {
processOneToOnePrimaryKeyRelationship(mapping);
} else if (hasJoinTable()) {
mapping.setRelationTableMechanism(new RelationTableMechanism());
processJoinTable(mapping, mapping.getRelationTableMechanism(), getJoinTableMetadata());
} else {
processForeignKeyRelationship(mapping);
}
}
use of org.eclipse.persistence.mappings.RelationTableMechanism in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildDeleteAllStatementsForMappings.
// Create SQLDeleteAllStatements for mappings that may be responsible for references
// to the objects to be deleted
// in the tables NOT mapped to any class: ManyToManyMapping and DirectCollectionMapping
/**
* NOTE: A similar pattern also used in method buildDeleteAllStatementsForMappingsWithTempTable:
* if you are updating this method consider applying a similar update to that method as well.
*
* @return {@code Vector<SQLDeleteAllStatement>}
*/
protected Vector buildDeleteAllStatementsForMappings(SQLCall selectCallForExist, SQLSelectStatement selectStatementForExist, boolean dontCheckDescriptor) {
Vector deleteStatements = new Vector();
ClassDescriptor descriptor = getDescriptor();
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (mapping.isForeignReferenceMapping()) {
Vector sourceFields = null;
Vector targetFields = null;
if (mapping.isDirectCollectionMapping()) {
if (shouldBuildDeleteStatementForMapping((DirectCollectionMapping) mapping, dontCheckDescriptor, descriptor)) {
sourceFields = ((DirectCollectionMapping) mapping).getSourceKeyFields();
targetFields = ((DirectCollectionMapping) mapping).getReferenceKeyFields();
}
} else if (mapping.isAggregateCollectionMapping()) {
if (shouldBuildDeleteStatementForMapping((AggregateCollectionMapping) mapping, dontCheckDescriptor, descriptor)) {
sourceFields = ((AggregateCollectionMapping) mapping).getSourceKeyFields();
targetFields = ((AggregateCollectionMapping) mapping).getTargetForeignKeyFields();
}
} else if (mapping.isManyToManyMapping()) {
if (shouldBuildDeleteStatementForMapping((ManyToManyMapping) mapping, dontCheckDescriptor, descriptor)) {
RelationTableMechanism relationTableMechanism = ((ManyToManyMapping) mapping).getRelationTableMechanism();
sourceFields = relationTableMechanism.getSourceKeyFields();
targetFields = relationTableMechanism.getSourceRelationKeyFields();
}
} else if (mapping.isOneToOneMapping()) {
RelationTableMechanism relationTableMechanism = ((OneToOneMapping) mapping).getRelationTableMechanism();
if (relationTableMechanism != null) {
if (shouldBuildDeleteStatementForMapping((OneToOneMapping) mapping, dontCheckDescriptor, descriptor)) {
sourceFields = relationTableMechanism.getSourceKeyFields();
targetFields = relationTableMechanism.getSourceRelationKeyFields();
}
}
}
if (sourceFields != null) {
deleteStatements.add(buildDeleteAllStatementForMapping(selectCallForExist, selectStatementForExist, sourceFields, targetFields));
}
}
}
return deleteStatements;
}
use of org.eclipse.persistence.mappings.RelationTableMechanism in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildDeleteAllStatementsForMappingsWithTempTable.
/**
* Build delete statements with temporary table for ManyToMany and DirectCollection mappings.
*
* NOTE: A similar pattern also used in method buildDeleteAllStatementsForMappings():
* if you are updating this method consider applying a similar update to that method as well.
*
* @return {@code Vector<SQLDeleteAllStatementForTempTable>}
*/
protected Vector buildDeleteAllStatementsForMappingsWithTempTable(ClassDescriptor descriptor, DatabaseTable rootTable, boolean dontCheckDescriptor) {
Vector deleteStatements = new Vector();
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (mapping.isForeignReferenceMapping()) {
List<DatabaseField> sourceFields = null;
List<DatabaseField> targetFields = null;
if (mapping.isDirectCollectionMapping()) {
if (shouldBuildDeleteStatementForMapping((DirectCollectionMapping) mapping, dontCheckDescriptor, descriptor)) {
sourceFields = ((DirectCollectionMapping) mapping).getSourceKeyFields();
targetFields = ((DirectCollectionMapping) mapping).getReferenceKeyFields();
}
} else if (mapping.isAggregateCollectionMapping()) {
if (shouldBuildDeleteStatementForMapping((AggregateCollectionMapping) mapping, dontCheckDescriptor, descriptor)) {
sourceFields = ((AggregateCollectionMapping) mapping).getSourceKeyFields();
targetFields = ((AggregateCollectionMapping) mapping).getTargetForeignKeyFields();
}
} else if (mapping.isManyToManyMapping()) {
if (shouldBuildDeleteStatementForMapping((ManyToManyMapping) mapping, dontCheckDescriptor, descriptor)) {
RelationTableMechanism relationTableMechanism = ((ManyToManyMapping) mapping).getRelationTableMechanism();
sourceFields = relationTableMechanism.getSourceKeyFields();
targetFields = relationTableMechanism.getSourceRelationKeyFields();
}
} else if (mapping.isOneToOneMapping()) {
RelationTableMechanism relationTableMechanism = ((OneToOneMapping) mapping).getRelationTableMechanism();
if (relationTableMechanism != null) {
if (shouldBuildDeleteStatementForMapping((OneToOneMapping) mapping, dontCheckDescriptor, descriptor)) {
sourceFields = relationTableMechanism.getSourceKeyFields();
targetFields = relationTableMechanism.getSourceRelationKeyFields();
}
}
}
if (sourceFields != null) {
DatabaseTable targetTable = targetFields.get(0).getTable();
SQLDeleteAllStatementForTempTable deleteStatement = buildDeleteAllStatementForTempTable(rootTable, sourceFields, targetTable, targetFields);
deleteStatements.addElement(deleteStatement);
}
}
}
return deleteStatements;
}
use of org.eclipse.persistence.mappings.RelationTableMechanism in project eclipselink by eclipse-ee4j.
the class DefaultTableGenerator method postInitTableSchema.
/**
* Build additional table/field definitions for the descriptor, like relation table
* and direct-collection, direct-map table, as well as reset LOB type for serialized
* object mapping and type conversion mapping for LOB usage
*/
protected void postInitTableSchema(ClassDescriptor descriptor) {
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (descriptor.isChildDescriptor() && descriptor.getInheritancePolicy().getParentDescriptor().getMappingForAttributeName(mapping.getAttributeName()) != null) {
// times for the same table.
continue;
} else if (mapping.isManyToManyMapping()) {
buildRelationTableDefinition((ManyToManyMapping) mapping, ((ManyToManyMapping) mapping).getRelationTableMechanism(), ((ManyToManyMapping) mapping).getListOrderField(), mapping.getContainerPolicy());
} else if (mapping.isDirectCollectionMapping()) {
buildDirectCollectionTableDefinition((DirectCollectionMapping) mapping, descriptor);
} else if (mapping.isDirectToFieldMapping()) {
Converter converter = ((DirectToFieldMapping) mapping).getConverter();
if (converter != null) {
if (converter instanceof TypeConversionConverter) {
resetFieldTypeForLOB((DirectToFieldMapping) mapping);
}
if (converter instanceof SerializedObjectConverter) {
// serialized object mapping field should be BLOB/IMAGE
getFieldDefFromDBField(mapping.getField()).setType(((SerializedObjectConverter) converter).getSerializer().getType());
}
}
} else if (mapping.isAggregateCollectionMapping()) {
// need to figure out the target foreign key field and add it into the aggregate target table
createAggregateTargetTable((AggregateCollectionMapping) mapping);
} else if (mapping.isForeignReferenceMapping()) {
if (mapping.isOneToOneMapping()) {
RelationTableMechanism relationTableMechanism = ((OneToOneMapping) mapping).getRelationTableMechanism();
if (relationTableMechanism == null) {
addForeignKeyFieldToSourceTargetTable((OneToOneMapping) mapping);
} else {
buildRelationTableDefinition((OneToOneMapping) mapping, relationTableMechanism, null, null);
}
} else if (mapping.isOneToManyMapping()) {
addForeignKeyFieldToSourceTargetTable((OneToManyMapping) mapping);
TableDefinition targTblDef = getTableDefFromDBTable(mapping.getReferenceDescriptor().getDefaultTable());
addFieldsForMappedKeyMapContainerPolicy(mapping.getContainerPolicy(), targTblDef);
}
} else if (mapping.isTransformationMapping()) {
resetTransformedFieldType((TransformationMapping) mapping);
} else if (mapping.isAggregateObjectMapping()) {
postInitTableSchema(mapping.getReferenceDescriptor());
}
}
processAdditionalTablePkFields(descriptor);
}
use of org.eclipse.persistence.mappings.RelationTableMechanism in project eclipselink by eclipse-ee4j.
the class OneToOneAccessor method process.
/**
* INTERNAL:
* Process a one to one setting into an EclipseLink OneToOneMapping.
*/
@Override
public void process() {
super.process();
// Initialize our mapping now with what we found.
ObjectReferenceMapping mapping = initOneToOneMapping();
if (hasMappedBy()) {
// Non-owning side, process the foreign keys from the owner.
DatabaseMapping owningMapping = getOwningMapping();
if (owningMapping.isOneToOneMapping()) {
OneToOneMapping ownerMapping = (OneToOneMapping) owningMapping;
// as we would for a many-to-many mapping.
if (ownerMapping.hasRelationTableMechanism()) {
// Put a relation table mechanism on our mapping.
((OneToOneMapping) mapping).setRelationTableMechanism(new RelationTableMechanism());
processMappedByRelationTable(ownerMapping.getRelationTableMechanism(), ((OneToOneMapping) mapping).getRelationTableMechanism());
} else {
Map<DatabaseField, DatabaseField> targetToSourceKeyFields;
Map<DatabaseField, DatabaseField> sourceToTargetKeyFields;
// the primary key field to point to our own database table.
if (getDescriptor().usesTablePerClassInheritanceStrategy()) {
targetToSourceKeyFields = new HashMap<DatabaseField, DatabaseField>();
sourceToTargetKeyFields = new HashMap<DatabaseField, DatabaseField>();
for (DatabaseField fkField : ownerMapping.getSourceToTargetKeyFields().keySet()) {
// We need to update the pk field to be to our table.
DatabaseField pkField = ownerMapping.getSourceToTargetKeyFields().get(fkField).clone();
pkField.setTable(getDescriptor().getPrimaryTable());
sourceToTargetKeyFields.put(fkField, pkField);
targetToSourceKeyFields.put(pkField, fkField);
}
} else {
targetToSourceKeyFields = ownerMapping.getTargetToSourceKeyFields();
sourceToTargetKeyFields = ownerMapping.getSourceToTargetKeyFields();
}
((OneToOneMapping) mapping).setSourceToTargetKeyFields(targetToSourceKeyFields);
((OneToOneMapping) mapping).setTargetToSourceKeyFields(sourceToTargetKeyFields);
}
} else {
// If improper mapping encountered, throw an exception.
throw ValidationException.invalidMapping(getJavaClass(), getReferenceClass());
}
} else if (mapping instanceof OneToOneMapping) {
// Owning side, look for JoinColumns or PrimaryKeyJoinColumns.
processOwningMappingKeys((OneToOneMapping) mapping);
} else {
processForeignKeyRelationship(mapping);
}
}
Aggregations