Search in sources :

Example 1 with MappingRelationshipElementImpl

use of com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl 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);
        }
    }
}
Also used : MappingRelationshipElementImpl(com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl) MappingTableElement(com.sun.jdo.api.persistence.model.mapping.MappingTableElement) MappingRelationshipElement(com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement)

Example 2 with MappingRelationshipElementImpl

use of com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl 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);
}
Also used : MappingRelationshipElementImpl(com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl) MappingRelationshipElement(com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement)

Example 3 with MappingRelationshipElementImpl

use of com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl 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);
    }
}
Also used : MappingRelationshipElementImpl(com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl) MappingRelationshipElement(com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement)

Aggregations

MappingRelationshipElement (com.sun.jdo.api.persistence.model.mapping.MappingRelationshipElement)3 MappingRelationshipElementImpl (com.sun.jdo.api.persistence.model.mapping.impl.MappingRelationshipElementImpl)3 MappingTableElement (com.sun.jdo.api.persistence.model.mapping.MappingTableElement)1