Example usage for org.hibernate.mapping DependantValue DependantValue

List of usage examples for org.hibernate.mapping DependantValue DependantValue

Introduction

In this page you can find the example usage for org.hibernate.mapping DependantValue DependantValue.

Prototype

public DependantValue(MetadataBuildingContext buildingContext, Table table, KeyValue prototype) 

Source Link

Usage

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

private DependantValue createFKComposite(Mappings mappings,
        com.manydesigns.portofino.model.database.ForeignKey relationship,
        com.manydesigns.portofino.model.database.Table manyMDTable, PersistentClass clazzOne,
        PersistentClass clazzMany, Bag set, Table tableMany, Table tableOne, List<Column> oneColumns,
        List<Column> manyColumns) {
    DependantValue dv;/*from ww w  . j  a v  a2 s  . c  o  m*/
    Component component = new Component(mappings, set);
    component.setDynamic(manyMDTable.getActualJavaClass() == null);
    component.setEmbedded(true);
    dv = new DependantValue(mappings, clazzMany.getTable(), component);
    dv.setNullable(true);
    dv.setUpdateable(true);

    for (Reference ref : relationship.getReferences()) {
        String colToName = ref.getToColumn();
        String colToPropertyName = ref.getActualToColumn().getActualPropertyName();
        String colFromName = ref.getFromColumn();
        Iterator it = tableMany.getColumnIterator();
        while (it.hasNext()) {
            Column col = (Column) it.next();
            if (col.getName().equals(colFromName)) {
                dv.addColumn(col);
                manyColumns.add(col);
                break;
            }
        }

        Iterator it2 = tableOne.getColumnIterator();
        while (it2.hasNext()) {
            Column col = (Column) it2.next();
            if (col.getName().equals(colToName)) {
                oneColumns.add(col);
                break;
            }
        }
        Property refProp;
        refProp = getRefProperty(clazzOne, colToPropertyName);
        component.addProperty(refProp);
    }
    return dv;
}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

private DependantValue createFKSingle(Mappings mappings, PersistentClass clazzOne, PersistentClass clazzMany,
        Table tableOne, List<Column> oneColumns, List<Column> manyColumns, List<Reference> refs) {
    DependantValue dv;//  w w  w .  ja v a  2s .  c o m
    Property refProp;

    Reference reference = refs.get(0);
    String colFromName = reference.getFromColumn();
    String colToName = reference.getToColumn();
    String colToPropertyName = reference.getActualToColumn().getActualPropertyName();
    refProp = getRefProperty(clazzOne, colToPropertyName);
    dv = new DependantValue(mappings, clazzMany.getTable(), refProp.getPersistentClass().getKey());
    dv.setNullable(true);
    dv.setUpdateable(true);

    Iterator it = clazzMany.getTable().getColumnIterator();
    while (it.hasNext()) {
        Column col = (Column) it.next();
        if (col.getName().equals(colFromName)) {
            dv.addColumn(col);
            manyColumns.add(col);
            break;
        }
    }

    Iterator it2 = tableOne.getColumnIterator();
    while (it2.hasNext()) {
        Column col = (Column) it2.next();
        if (col.getName().equals(colToName)) {
            oneColumns.add(col);
            break;
        }
    }
    return dv;
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Creates the DependentValue object that forms a primary key reference for the collection.
 *
 * @param mappings// w w  w  .  ja v a2  s  .c o m
 * @param property          The grails property
 * @param collection        The collection object
 * @param persistentClasses
 * @return The DependantValue (key)
 */
protected DependantValue createPrimaryKeyValue(Mappings mappings, GrailsDomainClassProperty property,
        Collection collection, Map<?, ?> persistentClasses) {
    KeyValue keyValue;
    DependantValue key;
    String propertyRef = collection.getReferencedPropertyName();
    // this is to support mapping by a property
    if (propertyRef == null) {
        keyValue = collection.getOwner().getIdentifier();
    } else {
        keyValue = (KeyValue) collection.getOwner().getProperty(propertyRef).getValue();
    }

    if (LOG.isDebugEnabled())
        LOG.debug("[GrailsDomainBinder] creating dependant key value  to table ["
                + keyValue.getTable().getName() + "]");

    key = new DependantValue(mappings, collection.getCollectionTable(), keyValue);

    key.setTypeName(null);
    // make nullable and non-updateable
    key.setNullable(true);
    key.setUpdateable(false);
    return key;
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Binds a joined sub-class mapping using table-per-subclass
 *
 * @param sub            The Grails sub class
 * @param joinedSubclass The Hibernate Subclass object
 * @param mappings       The mappings Object
 * @param gormMapping    The GORM mapping object
 * @param sessionFactoryBeanName  the session factory bean name
 *//*from w ww .j ava 2s .c om*/
protected void bindJoinedSubClass(GrailsDomainClass sub, JoinedSubclass joinedSubclass, Mappings mappings,
        Mapping gormMapping, String sessionFactoryBeanName) {
    bindClass(sub, joinedSubclass, mappings);

    if (joinedSubclass.getEntityPersisterClass() == null) {
        joinedSubclass.getRootClass()
                .setEntityPersisterClass(getGroovyAwareJoinedSubclassEntityPersisterClass());
    }

    Table mytable = mappings.addTable(mappings.getSchemaName(), mappings.getCatalogName(),
            getJoinedSubClassTableName(sub, joinedSubclass, null, mappings, sessionFactoryBeanName), null,
            false);

    joinedSubclass.setTable(mytable);
    LOG.info("Mapping joined-subclass: " + joinedSubclass.getEntityName() + " -> "
            + joinedSubclass.getTable().getName());

    SimpleValue key = new DependantValue(mappings, mytable, joinedSubclass.getIdentifier());
    joinedSubclass.setKey(key);
    GrailsDomainClassProperty identifier = sub.getIdentifier();
    String columnName = getColumnNameForPropertyAndPath(identifier, EMPTY_PATH, null, sessionFactoryBeanName);
    bindSimpleValue(identifier.getType().getName(), key, false, columnName, mappings);

    joinedSubclass.createPrimaryKey();

    // properties
    createClassProperties(sub, joinedSubclass, mappings, sessionFactoryBeanName);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Creates the DependentValue object that forms a primary key reference for the collection.
 *
 * @param mappings/*from   www  .  ja  v a 2s.co m*/
 * @param property          The grails property
 * @param collection        The collection object
 * @param persistentClasses
 * @return The DependantValue (key)
 */
private static DependantValue createPrimaryKeyValue(Mappings mappings,
        @SuppressWarnings("unused") GrailsDomainClassProperty property, Collection collection,
        @SuppressWarnings("unused") Map<?, ?> persistentClasses) {
    KeyValue keyValue;
    DependantValue key;
    String propertyRef = collection.getReferencedPropertyName();
    // this is to support mapping by a property
    if (propertyRef == null) {
        keyValue = collection.getOwner().getIdentifier();
    } else {
        keyValue = (KeyValue) collection.getOwner().getProperty(propertyRef).getValue();
    }

    if (LOG.isDebugEnabled())
        LOG.debug("[GrailsDomainBinder] creating dependant key value  to table ["
                + keyValue.getTable().getName() + "]");

    key = new DependantValue(mappings, collection.getCollectionTable(), keyValue);

    key.setTypeName(null);
    // make nullable and non-updateable
    key.setNullable(true);
    key.setUpdateable(false);
    return key;
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Binds a joined sub-class mapping using table-per-subclass
 *
 * @param sub            The Grails sub class
 * @param joinedSubclass The Hibernate Subclass object
 * @param mappings       The mappings Object
 * @param gormMapping    The GORM mapping object
 * @param sessionFactoryBeanName  the session factory bean name
 *//*w  ww.j  a  v  a  2 s.c o  m*/
private static void bindJoinedSubClass(GrailsDomainClass sub, JoinedSubclass joinedSubclass, Mappings mappings,
        @SuppressWarnings("unused") Mapping gormMapping, String sessionFactoryBeanName) {
    bindClass(sub, joinedSubclass, mappings);

    if (joinedSubclass.getEntityPersisterClass() == null) {
        joinedSubclass.getRootClass().setEntityPersisterClass(GroovyAwareJoinedSubclassEntityPersister.class);
    }

    Table mytable = mappings.addTable(mappings.getSchemaName(), mappings.getCatalogName(),
            getJoinedSubClassTableName(sub, joinedSubclass, null, mappings, sessionFactoryBeanName), null,
            false);

    joinedSubclass.setTable(mytable);
    LOG.info("Mapping joined-subclass: " + joinedSubclass.getEntityName() + " -> "
            + joinedSubclass.getTable().getName());

    SimpleValue key = new DependantValue(mappings, mytable, joinedSubclass.getIdentifier());
    joinedSubclass.setKey(key);
    GrailsDomainClassProperty identifier = sub.getIdentifier();
    String columnName = getColumnNameForPropertyAndPath(identifier, EMPTY_PATH, null, sessionFactoryBeanName);
    bindSimpleValue(identifier.getType().getName(), key, false, columnName, mappings);

    joinedSubclass.createPrimaryKey();

    // properties
    createClassProperties(sub, joinedSubclass, mappings, sessionFactoryBeanName);
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Creates the DependentValue object that forms a primary key reference for the collection.
 *
 * @param mappings//  w  ww .  j a va  2  s  .c  om
 * @param property          The grails property
 * @param collection        The collection object
 * @param persistentClasses
 * @return The DependantValue (key)
 */
protected DependantValue createPrimaryKeyValue(Mappings mappings, PersistentProperty property,
        Collection collection, Map<?, ?> persistentClasses) {
    KeyValue keyValue;
    DependantValue key;
    String propertyRef = collection.getReferencedPropertyName();
    // this is to support mapping by a property
    if (propertyRef == null) {
        keyValue = collection.getOwner().getIdentifier();
    } else {
        keyValue = (KeyValue) collection.getOwner().getProperty(propertyRef).getValue();
    }

    if (LOG.isDebugEnabled())
        LOG.debug("[GrailsDomainBinder] creating dependant key value  to table ["
                + keyValue.getTable().getName() + "]");

    key = new DependantValue(mappings, collection.getCollectionTable(), keyValue);

    key.setTypeName(null);
    // make nullable and non-updateable
    key.setNullable(true);
    key.setUpdateable(false);
    return key;
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Binds a joined sub-class mapping using table-per-subclass
 *
 * @param sub            The Grails sub class
 * @param joinedSubclass The Hibernate Subclass object
 * @param mappings       The mappings Object
 * @param gormMapping    The GORM mapping object
 * @param sessionFactoryBeanName  the session factory bean name
 */// ww  w  .j a v  a 2  s  .c  o  m
protected void bindJoinedSubClass(HibernatePersistentEntity sub, JoinedSubclass joinedSubclass,
        Mappings mappings, Mapping gormMapping, String sessionFactoryBeanName) {
    bindClass(sub, joinedSubclass, mappings);

    if (joinedSubclass.getEntityPersisterClass() == null) {
        joinedSubclass.getRootClass()
                .setEntityPersisterClass(getGroovyAwareJoinedSubclassEntityPersisterClass());
    }

    Table mytable = mappings.addTable(mappings.getSchemaName(), mappings.getCatalogName(),
            getJoinedSubClassTableName(sub, joinedSubclass, null, mappings, sessionFactoryBeanName), null,
            false);

    joinedSubclass.setTable(mytable);
    LOG.info("Mapping joined-subclass: " + joinedSubclass.getEntityName() + " -> "
            + joinedSubclass.getTable().getName());

    SimpleValue key = new DependantValue(mappings, mytable, joinedSubclass.getIdentifier());
    joinedSubclass.setKey(key);
    final PersistentProperty identifier = sub.getIdentity();
    String columnName = getColumnNameForPropertyAndPath(identifier, EMPTY_PATH, null, sessionFactoryBeanName);
    bindSimpleValue(identifier.getType().getName(), key, false, columnName, mappings);

    joinedSubclass.createPrimaryKey();

    // properties
    createClassProperties(sub, joinedSubclass, mappings, sessionFactoryBeanName);
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Creates the DependentValue object that forms a primary key reference for the collection.
 *
 * @param mappings// ww w .  ja v  a 2 s  .  co  m
 * @param property          The grails property
 * @param collection        The collection object
 * @param persistentClasses
 * @return The DependantValue (key)
 */
protected DependantValue createPrimaryKeyValue(InFlightMetadataCollector mappings, PersistentProperty property,
        Collection collection, Map<?, ?> persistentClasses) {
    KeyValue keyValue;
    DependantValue key;
    String propertyRef = collection.getReferencedPropertyName();
    // this is to support mapping by a property
    if (propertyRef == null) {
        keyValue = collection.getOwner().getIdentifier();
    } else {
        keyValue = (KeyValue) collection.getOwner().getProperty(propertyRef).getValue();
    }

    if (LOG.isDebugEnabled())
        LOG.debug("[GrailsDomainBinder] creating dependant key value  to table ["
                + keyValue.getTable().getName() + "]");

    key = new DependantValue(mappings, collection.getCollectionTable(), keyValue);

    key.setTypeName(null);
    // make nullable and non-updateable
    key.setNullable(true);
    key.setUpdateable(false);
    return key;
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Binds a joined sub-class mapping using table-per-subclass
 *
 * @param sub            The Grails sub class
 * @param joinedSubclass The Hibernate Subclass object
 * @param mappings       The mappings Object
 * @param gormMapping    The GORM mapping object
 * @param sessionFactoryBeanName  the session factory bean name
 *//* w  w  w.ja  va2  s . co  m*/
protected void bindJoinedSubClass(HibernatePersistentEntity sub, JoinedSubclass joinedSubclass,
        InFlightMetadataCollector mappings, Mapping gormMapping, String sessionFactoryBeanName) {
    bindClass(sub, joinedSubclass, mappings);

    String schemaName = getSchemaName(mappings);
    String catalogName = getCatalogName(mappings);

    Table mytable = mappings.addTable(schemaName, catalogName,
            getJoinedSubClassTableName(sub, joinedSubclass, null, mappings, sessionFactoryBeanName), null,
            false);

    joinedSubclass.setTable(mytable);
    LOG.info("Mapping joined-subclass: " + joinedSubclass.getEntityName() + " -> "
            + joinedSubclass.getTable().getName());

    SimpleValue key = new DependantValue(mappings, mytable, joinedSubclass.getIdentifier());
    joinedSubclass.setKey(key);
    final PersistentProperty identifier = sub.getIdentity();
    String columnName = getColumnNameForPropertyAndPath(identifier, EMPTY_PATH, null, sessionFactoryBeanName);
    bindSimpleValue(identifier.getType().getName(), key, false, columnName, mappings);

    joinedSubclass.createPrimaryKey();

    // properties
    createClassProperties(sub, joinedSubclass, mappings, sessionFactoryBeanName);
}