use of com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement in project Payara by payara.
the class DatabaseGenerator method addInverseMappingRelationship.
/**
* Create and add MappingRelationship with local inverse column pair
* (for join table) or inverse column pair
* (for non join table) for referenced table.
* It is for column pairs between local table and join table
* or for column pairs between local table and foreign table (contains
* foreign key)
* The column pair for mappingRelationship is inverse order
* as the column pair from foreign key. Foreign key is not in the passing
* mapping class but in the inverse mapping class
* @param relationName a String for relation name
* @param mappingClass mapping class that holds the relationship
* @param fkeyForeign holding column pair information for the relationship
* @throws ModelException
* @throws DBException
*/
private void addInverseMappingRelationship(String relationName, MappingClassElement declaringClass, ForeignKeyElement fkey, boolean isJoin) throws ModelException, DBException {
MappingRelationshipElement impl = (MappingRelationshipElement) declaringClass.getField(relationName);
// for join table, need to add two MappingRelationshipElement
if (null == impl) {
impl = new MappingRelationshipElementImpl(relationName, declaringClass);
declaringClass.addField(impl);
}
TableElement declaringTbl = getPrimaryTable(declaringClass);
ColumnPairElement[] pairs = fkey.getColumnPairs();
// Column pair get inverted since adding to referenced table
for (int i = 0; i < pairs.length; i++) {
ColumnPairElement pair = pairs[i];
ColumnPairElement inversePair = DBElementFactory.createColumnPair(pair.getReferencedColumn(), pair.getLocalColumn(), declaringTbl);
if (isJoin) {
impl.addLocalColumn(inversePair);
} else {
impl.addColumn(inversePair);
}
}
}
use of com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement in project Payara by payara.
the class DatabaseGenerator method addMappingRelationship.
/**
* Create and add mapping relationship with column pairs to mapping class.
* The column pair for mappingRelationship is same order as the column
* pair from foreign key. It is used for 1-1 or 1-M relationship
* It is column pair between local table and foreign table
* @param relationName relationship name for the declaring mapping class
* @param mappingClass mapping class that holds the relationship
* @param foreign key which hold column pair for the relationship
* @throws ModelException
*/
private void addMappingRelationship(String relationName, MappingClassElement declaringClass, ForeignKeyElement fkey) throws ModelException {
MappingRelationshipElement impl = new MappingRelationshipElementImpl(relationName, declaringClass);
ColumnPairElement[] pairs = fkey.getColumnPairs();
for (int i = 0; i < pairs.length; i++) {
ColumnPairElement pair = pairs[i];
impl.addColumn(pair);
}
declaringClass.addField(impl);
}
use of com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement in project Payara by payara.
the class DatabaseGenerator method addAssocMappingRelationship.
/**
* Create and add MappingRelationship with associated column pairs
* for join table. The column pair for mappingRelationship is same
* order as the column pair from foreign key.
* It is for column pairs between the join table and the foreign table
* @param relationName a String for relation name
* @param mappingClass mapping class that holds the relationship
* @param fkeyForeign holding column pair information for the relationship
* @throws ModelException
*/
private void addAssocMappingRelationship(String relationName, MappingClassElement declaringClass, ForeignKeyElement fkeyForeign) throws ModelException {
MappingRelationshipElement impl = (MappingRelationshipElement) declaringClass.getField(relationName);
if (null == impl) {
impl = new MappingRelationshipElementImpl(relationName, declaringClass);
declaringClass.addField(impl);
}
// Add column pair for join table and foreign table
ColumnPairElement[] pairs = fkeyForeign.getColumnPairs();
for (int i = 0; i < pairs.length; i++) {
ColumnPairElement pair = pairs[i];
impl.addAssociatedColumn(pair);
}
}
use of com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement in project Payara by payara.
the class ClassDesc method initializeFields.
/**
* This method maps all the visible fields. It has the side-effect of computing
* the value for maxVisibleFields.
*/
private void initializeFields() {
ArrayList concurrencyGroups = new ArrayList();
persistentFields = pcElement.getFields();
for (int i = 0; i < persistentFields.length; i++) {
PersistenceFieldElement pcf = persistentFields[i];
MappingFieldElementImpl mdf = (MappingFieldElementImpl) mdConfig.getField(pcf.getName());
if (mdf == null) {
throw new JDOFatalUserException(I18NHelper.getMessage(messages, // NOI18N
"core.configuration.fieldnotmapped", pcf.getName(), pcElement.getName()));
}
FieldDesc f;
if (!(mdf instanceof MappingRelationshipElement)) {
f = createLocalField(mdf);
} else {
f = createForeignField((RelationshipElement) pcf, (MappingRelationshipElementImpl) mdf);
}
initializeFetchAndConcurrencyGroup(f, pcf, mdf, concurrencyGroups);
if (mdf.isReadOnly()) {
f.sqlProperties |= FieldDesc.PROP_READ_ONLY;
}
try {
f.setupDesc(pcClass, pcf.getName());
} catch (JDOException e) {
throw e;
} catch (Exception e) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
"core.configuration.loadfailed.field", pcf.getName(), pcElement.getName()), e);
}
f.absoluteID = pcf.getFieldNumber();
addField(f);
if (logger.isLoggable(Logger.FINEST)) {
Object[] items = new Object[] { f.getName(), new Integer(f.absoluteID) };
// NOI18N
logger.finest("sqlstore.model.classdesc.fieldinfo", items);
}
}
this.maxVisibleFields = fields.size();
}
Aggregations