Example usage for org.hibernate.mapping DependantValue setUpdateable

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

Introduction

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

Prototype

public void setUpdateable(boolean updateable) 

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;
    Component component = new Component(mappings, set);
    component.setDynamic(manyMDTable.getActualJavaClass() == null);
    component.setEmbedded(true);//from   w  ww .ja  v  a2 s  . com
    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;
    Property refProp;// w  w  w  .j  a  va 2  s.  co m

    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

protected void bindListSecondPass(GrailsDomainClassProperty property, Mappings mappings,
        Map<?, ?> persistentClasses, org.hibernate.mapping.List list, String sessionFactoryBeanName) {

    bindCollectionSecondPass(property, mappings, persistentClasses, list, sessionFactoryBeanName);

    String columnName = getIndexColumnName(property, sessionFactoryBeanName);
    final boolean isManyToMany = property.isManyToMany();

    if (isManyToMany && !property.isOwningSide()) {
        throw new MappingException("Invalid association [" + property.getDomainClass().getName() + "->"
                + property.getName()/*w  ww.  j a  v a 2s. c  o  m*/
                + "]. List collection types only supported on the owning side of a many-to-many relationship.");
    }

    Table collectionTable = list.getCollectionTable();
    SimpleValue iv = new SimpleValue(mappings, collectionTable);
    bindSimpleValue("integer", iv, true, columnName, mappings);
    iv.setTypeName("integer");
    list.setIndex(iv);
    list.setBaseIndex(0);
    list.setInverse(false);

    Value v = list.getElement();
    v.createForeignKey();

    if (property.isBidirectional()) {

        String entityName;
        Value element = list.getElement();
        if (element instanceof ManyToOne) {
            ManyToOne manyToOne = (ManyToOne) element;
            entityName = manyToOne.getReferencedEntityName();
        } else {
            entityName = ((OneToMany) element).getReferencedEntityName();
        }

        PersistentClass referenced = mappings.getClass(entityName);

        Class<?> mappedClass = referenced.getMappedClass();
        Mapping m = getMapping(mappedClass);

        boolean compositeIdProperty = isCompositeIdProperty(m, property.getOtherSide());
        if (!compositeIdProperty) {
            Backref prop = new Backref();
            prop.setEntityName(property.getDomainClass().getFullName());
            prop.setName(UNDERSCORE
                    + addUnderscore(property.getDomainClass().getShortName(), property.getName()) + "Backref");
            prop.setSelectable(false);
            prop.setUpdateable(false);
            if (isManyToMany) {
                prop.setInsertable(false);
            }
            prop.setCollectionRole(list.getRole());
            prop.setValue(list.getKey());

            DependantValue value = (DependantValue) prop.getValue();
            if (!property.isCircular()) {
                value.setNullable(false);
            }
            value.setUpdateable(true);
            prop.setOptional(false);

            referenced.addProperty(prop);
        }

        if ((!list.getKey().isNullable() && !list.isInverse()) || compositeIdProperty) {
            IndexBackref ib = new IndexBackref();
            ib.setName(UNDERSCORE + property.getName() + "IndexBackref");
            ib.setUpdateable(false);
            ib.setSelectable(false);
            if (isManyToMany) {
                ib.setInsertable(false);
            }
            ib.setCollectionRole(list.getRole());
            ib.setEntityName(list.getOwner().getEntityName());
            ib.setValue(list.getIndex());
            referenced.addProperty(ib);
        }
    }
}

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//from www  . j  a  va  2s  .  co 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.GrailsDomainBinder.java

License:Apache License

private static void bindListSecondPass(GrailsDomainClassProperty property, Mappings mappings,
        Map<?, ?> persistentClasses, org.hibernate.mapping.List list, String sessionFactoryBeanName) {

    bindCollectionSecondPass(property, mappings, persistentClasses, list, sessionFactoryBeanName);

    String columnName = getIndexColumnName(property, sessionFactoryBeanName);

    SimpleValue iv = new SimpleValue(mappings, list.getCollectionTable());
    bindSimpleValue("integer", iv, true, columnName, mappings);
    iv.setTypeName("integer");
    list.setIndex(iv);// w w  w.  j  a va 2s  . c  om
    list.setBaseIndex(0);
    list.setInverse(false);

    Value v = list.getElement();
    v.createForeignKey();

    if (property.isBidirectional()) {

        String entityName;
        Value element = list.getElement();
        if (element instanceof ManyToOne) {
            ManyToOne manyToOne = (ManyToOne) element;
            entityName = manyToOne.getReferencedEntityName();
        } else {
            entityName = ((OneToMany) element).getReferencedEntityName();
        }

        PersistentClass referenced = mappings.getClass(entityName);

        final boolean isManyToMany = property.isManyToMany();
        Class<?> mappedClass = referenced.getMappedClass();
        Mapping m = getMapping(mappedClass);

        boolean compositeIdProperty = isCompositeIdProperty(m, property.getOtherSide());
        if (!compositeIdProperty) {
            Backref prop = new Backref();
            prop.setEntityName(property.getDomainClass().getFullName());
            prop.setName(UNDERSCORE
                    + addUnderscore(property.getDomainClass().getShortName(), property.getName()) + "Backref");
            prop.setSelectable(false);
            prop.setUpdateable(false);
            if (isManyToMany) {
                prop.setInsertable(false);
            }
            prop.setCollectionRole(list.getRole());
            prop.setValue(list.getKey());

            DependantValue value = (DependantValue) prop.getValue();
            if (!property.isCircular()) {
                value.setNullable(false);
            }
            value.setUpdateable(true);
            prop.setOptional(false);

            referenced.addProperty(prop);
        }

        if ((!list.getKey().isNullable() && !list.isInverse()) || compositeIdProperty) {
            IndexBackref ib = new IndexBackref();
            ib.setName(UNDERSCORE + property.getName() + "IndexBackref");
            ib.setUpdateable(false);
            ib.setSelectable(false);
            if (isManyToMany) {
                ib.setInsertable(false);
            }
            ib.setCollectionRole(list.getRole());
            ib.setEntityName(list.getOwner().getEntityName());
            ib.setValue(list.getIndex());
            referenced.addProperty(ib);
        }
    }
}

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 w ww . j  a v  a2  s. c  o 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.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindListSecondPass(ToMany property, Mappings mappings, Map<?, ?> persistentClasses,
        org.hibernate.mapping.List list, String sessionFactoryBeanName) {

    bindCollectionSecondPass(property, mappings, persistentClasses, list, sessionFactoryBeanName);

    String columnName = getIndexColumnName(property, sessionFactoryBeanName);
    final boolean isManyToMany = property instanceof ManyToMany;

    if (isManyToMany && !property.isOwningSide()) {
        throw new MappingException("Invalid association [" + property
                + "]. List collection types only supported on the owning side of a many-to-many relationship.");
    }/*from  ww w.ja v a  2 s .  c o m*/

    Table collectionTable = list.getCollectionTable();
    SimpleValue iv = new SimpleValue(mappings, collectionTable);
    bindSimpleValue("integer", iv, true, columnName, mappings);
    iv.setTypeName("integer");
    list.setIndex(iv);
    list.setBaseIndex(0);
    list.setInverse(false);

    Value v = list.getElement();
    v.createForeignKey();

    if (property.isBidirectional()) {

        String entityName;
        Value element = list.getElement();
        if (element instanceof ManyToOne) {
            ManyToOne manyToOne = (ManyToOne) element;
            entityName = manyToOne.getReferencedEntityName();
        } else {
            entityName = ((OneToMany) element).getReferencedEntityName();
        }

        PersistentClass referenced = mappings.getClass(entityName);

        Class<?> mappedClass = referenced.getMappedClass();
        Mapping m = getMapping(mappedClass);

        boolean compositeIdProperty = isCompositeIdProperty(m, property.getInverseSide());
        if (!compositeIdProperty) {
            Backref prop = new Backref();
            final PersistentEntity owner = property.getOwner();
            prop.setEntityName(owner.getName());
            prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName())
                    + "Backref");
            prop.setSelectable(false);
            prop.setUpdateable(false);
            if (isManyToMany) {
                prop.setInsertable(false);
            }
            prop.setCollectionRole(list.getRole());
            prop.setValue(list.getKey());

            DependantValue value = (DependantValue) prop.getValue();
            if (!property.isCircular()) {
                value.setNullable(false);
            }
            value.setUpdateable(true);
            prop.setOptional(false);

            referenced.addProperty(prop);
        }

        if ((!list.getKey().isNullable() && !list.isInverse()) || compositeIdProperty) {
            IndexBackref ib = new IndexBackref();
            ib.setName(UNDERSCORE + property.getName() + "IndexBackref");
            ib.setUpdateable(false);
            ib.setSelectable(false);
            if (isManyToMany) {
                ib.setInsertable(false);
            }
            ib.setCollectionRole(list.getRole());
            ib.setEntityName(list.getOwner().getEntityName());
            ib.setValue(list.getIndex());
            referenced.addProperty(ib);
        }
    }
}

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/*ww  w  . j  a va  2  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, 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

protected void bindListSecondPass(ToMany property, InFlightMetadataCollector mappings,
        Map<?, ?> persistentClasses, org.hibernate.mapping.List list, String sessionFactoryBeanName) {

    bindCollectionSecondPass(property, mappings, persistentClasses, list, sessionFactoryBeanName);

    String columnName = getIndexColumnName(property, sessionFactoryBeanName);
    final boolean isManyToMany = property instanceof ManyToMany;

    if (isManyToMany && !property.isOwningSide()) {
        throw new MappingException("Invalid association [" + property
                + "]. List collection types only supported on the owning side of a many-to-many relationship.");
    }/*from  www  .  j  av  a2  s.c o  m*/

    Table collectionTable = list.getCollectionTable();
    SimpleValue iv = new SimpleValue(mappings, collectionTable);
    bindSimpleValue("integer", iv, true, columnName, mappings);
    iv.setTypeName("integer");
    list.setIndex(iv);
    list.setBaseIndex(0);
    list.setInverse(false);

    Value v = list.getElement();
    v.createForeignKey();

    if (property.isBidirectional()) {

        String entityName;
        Value element = list.getElement();
        if (element instanceof ManyToOne) {
            ManyToOne manyToOne = (ManyToOne) element;
            entityName = manyToOne.getReferencedEntityName();
        } else {
            entityName = ((OneToMany) element).getReferencedEntityName();
        }

        PersistentClass referenced = mappings.getEntityBinding(entityName);

        Class<?> mappedClass = referenced.getMappedClass();
        Mapping m = getMapping(mappedClass);

        boolean compositeIdProperty = isCompositeIdProperty(m, property.getInverseSide());
        if (!compositeIdProperty) {
            Backref prop = new Backref();
            final PersistentEntity owner = property.getOwner();
            prop.setEntityName(owner.getName());
            prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName())
                    + "Backref");
            prop.setSelectable(false);
            prop.setUpdateable(false);
            if (isManyToMany) {
                prop.setInsertable(false);
            }
            prop.setCollectionRole(list.getRole());
            prop.setValue(list.getKey());

            DependantValue value = (DependantValue) prop.getValue();
            if (!property.isCircular()) {
                value.setNullable(false);
            }
            value.setUpdateable(true);
            prop.setOptional(false);

            referenced.addProperty(prop);
        }

        if ((!list.getKey().isNullable() && !list.isInverse()) || compositeIdProperty) {
            IndexBackref ib = new IndexBackref();
            ib.setName(UNDERSCORE + property.getName() + "IndexBackref");
            ib.setUpdateable(false);
            ib.setSelectable(false);
            if (isManyToMany) {
                ib.setInsertable(false);
            }
            ib.setCollectionRole(list.getRole());
            ib.setEntityName(list.getOwner().getEntityName());
            ib.setValue(list.getIndex());
            referenced.addProperty(ib);
        }
    }
}

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/*from   ww w  .  java 2 s. c  o 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;
}