/** * INTERNAL: * Return the relation table associated with the mapping. */ public DatabaseTable getRelationTable() { return this.mechanism.getRelationTable(); }
/** * INTERNAL: * Return all the source key fields associated with the mapping. */ public Vector<DatabaseField> getSourceKeyFields() { return this.mechanism.getSourceKeyFields(); }
/** * PUBLIC: * Add the fields in the intermediate table that corresponds to the primary * key in the source table. This method is used if the keys are composite. */ public void addSourceRelationKeyField(DatabaseField sourceRelationKeyField, DatabaseField sourcePrimaryKeyField) { getSourceRelationKeyFields().addElement(sourceRelationKeyField); getSourceKeyFields().addElement(sourcePrimaryKeyField); }
/** * INTERNAL: * Create a row that contains source relation fields with values extracted from the source object * and target relation fields with values extracted from the target object. */ public AbstractRecord buildRelationTableSourceAndTargetRow(Object sourceObject, Object targetObject, AbstractSession session, ForeignReferenceMapping mapping) { AbstractRecord databaseRow = buildRelationTableSourceRow(sourceObject, session, mapping); databaseRow = addRelationTableTargetRow(targetObject, session, databaseRow, mapping); return databaseRow; }
/** * PUBLIC: * Add the fields in the intermediate table that corresponds to the primary * key in the target table. This method is used if the keys are composite. */ public void addTargetRelationKeyField(DatabaseField targetRelationKeyField, DatabaseField targetPrimaryKeyField) { getTargetRelationKeyFields().addElement(targetRelationKeyField); getTargetKeyFields().addElement(targetPrimaryKeyField); }
/** * Build relation table definitions for all many-to-many relationships in a EclipseLink descriptor. */ private void buildRelationTableDefinition(RelationTableMechanism relationTableMechanism, DatabaseField listOrderField, ContainerPolicy cp) { //first create relation table TableDefinition tblDef = getTableDefFromDBTable(relationTableMechanism.getRelationTable()); //add source foreign key fields into the relation table Vector srcFkFields = relationTableMechanism.getSourceRelationKeyFields(); Vector srcKeyFields = relationTableMechanism.getSourceKeyFields(); buildRelationTableFields(tblDef, srcFkFields, srcKeyFields); //add target foreign key fields into the relation table Vector targFkFields = relationTableMechanism.getTargetRelationKeyFields(); Vector targKeyFields = relationTableMechanism.getTargetKeyFields(); buildRelationTableFields(tblDef, targFkFields, targKeyFields); if (cp != null){ addFieldsForMappedKeyMapContainerPolicy(cp, tblDef); } if(listOrderField != null) { tblDef.addField(getFieldDefFromDBField(listOrderField, false)); } }
AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceRow(query.getTranslationRow()); Object wrappedObject = cp.nextEntry(iter, query.getSession()); Object object = cp.unwrapIteratorResult(wrappedObject); databaseRow = this.mechanism.addRelationTableTargetRow(object, query.getSession(), databaseRow, this); query.getSession().executeQuery(this.mechanism.getInsertQuery(), databaseRow); if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) { getHistoryPolicy().mappingLogicalInsert(this.mechanism.getInsertQuery(), databaseRow, query.getSession());
/** * INTERNAL: * Return all the target keys associated with the mapping. */ public Vector<DatabaseField> getTargetKeyFields() { return this.mechanism.getTargetKeyFields(); }
/** * INTERNAL: * All the source relation key field names are converted to DatabaseField and stored. */ protected void initializeSourceRelationKeys(AbstractSession session, ForeignReferenceMapping mapping) throws DescriptorException { if (getSourceRelationKeyFields().size() == 0) { throw DescriptorException.noSourceRelationKeysSpecified(mapping); } for (Enumeration entry = getSourceRelationKeyFields().elements(); entry.hasMoreElements();) { DatabaseField field = (DatabaseField)entry.nextElement(); if (field.hasTableName() && (!(field.getTableName().equals(getRelationTable().getName())))) { throw DescriptorException.relationKeyFieldNotProperlySpecified(field, mapping); } field.setTable(getRelationTable()); } }
/** * INTERNAL: * Set the table qualifier on the relation table if required */ protected void initializeRelationTable(AbstractSession session, ForeignReferenceMapping mapping) throws DescriptorException { Platform platform = session.getDatasourcePlatform(); // We need to look up the relation table name from the reference // descriptor if we are the non owning side of a bidirectional mapping // to a table per tenant descriptor. if (mapping.isReadOnly() && mapping.getReferenceDescriptor().hasTablePerMultitenantPolicy()) { setRelationTable(((TablePerMultitenantPolicy) mapping.getReferenceDescriptor().getMultitenantPolicy()).getTable(getRelationTable())); } if (!hasRelationTable()) { throw DescriptorException.noRelationTable(mapping); } if (platform.getTableQualifier().length() > 0) { if (getRelationTable().getTableQualifier().length() == 0) { getRelationTable().setTableQualifier(platform.getTableQualifier()); } } } /**
fkField.setTable(mechanism.getRelationTable()); mechanism.addSourceRelationKeyField(fkField, pkField); } else { mechanism.addTargetRelationKeyField(fkField, pkField);
/** * INTERNAL: * Return all the source relation key fields associated with the mapping. */ public Vector<DatabaseField> getSourceRelationKeyFields() { return this.mechanism.getSourceRelationKeyFields(); }
/** * INTERNAL: * Return all the target relation key fields associated with the mapping. */ public Vector<DatabaseField> getTargetRelationKeyFields() { return this.mechanism.getTargetRelationKeyFields(); }
/** * INTERNAL: * All the target relation key field names are converted to DatabaseField and stored. */ protected void initializeTargetRelationKeys(AbstractSession session, ForeignReferenceMapping mapping) { if (getTargetRelationKeyFields().size() == 0) { throw DescriptorException.noTargetRelationKeysSpecified(mapping); } for (Enumeration targetEnum = getTargetRelationKeyFields().elements(); targetEnum.hasMoreElements();) { DatabaseField field = (DatabaseField)targetEnum.nextElement(); if (field.hasTableName() && (!(field.getTableName().equals(getRelationTable().getName())))) { throw DescriptorException.relationKeyFieldNotProperlySpecified(field, mapping); } field.setTable(getRelationTable()); } }
/** * INTERNAL: * Set the table qualifier on the relation table if required */ protected void initializeRelationTable(AbstractSession session, ForeignReferenceMapping mapping) throws DescriptorException { Platform platform = session.getDatasourcePlatform(); if (!hasRelationTable()) { throw DescriptorException.noRelationTable(mapping); } if (platform.getTableQualifier().length() > 0) { if (getRelationTable().getTableQualifier().length() == 0) { getRelationTable().setTableQualifier(platform.getTableQualifier()); } } } /**
/** * INTERNAL: * Create a row that contains source relation fields with values extracted from the source object. */ public AbstractRecord buildRelationTableSourceRow(Object sourceObject, AbstractSession session, ForeignReferenceMapping mapping) { AbstractRecord databaseRow = new DatabaseRecord(); return addRelationTableSourceRow(sourceObject, session, databaseRow, mapping); }
/** * PUBLIC: * Add the fields in the intermediate table that corresponds to the primary * key in the source table. This method is used if the keys are composite. */ public void addSourceRelationKeyField(DatabaseField sourceRelationKeyField, DatabaseField sourcePrimaryKeyField) { this.mechanism.addSourceRelationKeyField(sourceRelationKeyField, sourcePrimaryKeyField); }
/** * PUBLIC: * Default constructor. */ public ManyToManyMapping() { this.mechanism = new RelationTableMechanism(); this.isListOrderFieldSupported = true; }
/** * PUBLIC: * Add the fields in the intermediate table that corresponds to the primary * key in the source table. This method is used if the keys are composite. */ public void addSourceRelationKeyFieldName(String sourceRelationKeyFieldName, String sourcePrimaryKeyFieldName) { this.mechanism.addSourceRelationKeyFieldName(sourceRelationKeyFieldName, sourcePrimaryKeyFieldName); }
/** * INTERNAL: * Perform the commit event. * This is used in the uow to delay data modifications. */ public void performDataModificationEvent(Object[] event, AbstractSession session) throws DatabaseException, DescriptorException { // Hey I might actually want to use an inner class here... ok array for now. if (event[0] == setObject) { AbstractRecord sourceAndTargetRow = this.mechanism.addRelationTableTargetRow(event[2], session, (AbstractRecord)event[1], this); session.executeQuery(this.mechanism.insertQuery, sourceAndTargetRow); } else { throw DescriptorException.invalidDataModificationEventCode(event[0], this); } }