Example usage for org.hibernate.mapping Property setUpdateable

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

Introduction

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

Prototype

public void setUpdateable(boolean mutable) 

Source Link

Usage

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

License:Open Source License

protected void createPKSingle(Mappings mappings, com.manydesigns.portofino.model.database.Table mdTable,
        String pkName, RootClass clazz, Table tab,
        List<com.manydesigns.portofino.model.database.Column> columnPKList) {
    PrimaryKeyColumn pkcol = mdTable.getPrimaryKey().getPrimaryKeyColumns().get(0);
    com.manydesigns.portofino.model.database.Column column = columnPKList.get(0);
    final PrimaryKey primaryKey = new PrimaryKey();
    primaryKey.setName(pkName);/* w w w.j av a 2 s .co m*/
    primaryKey.setTable(tab);
    tab.setPrimaryKey(primaryKey);

    Column col = createColumn(mappings, tab, column);

    if (col == null) {
        // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare
        logger.error("Skipping primary key");
        return;
    }

    SimpleValue id = (SimpleValue) col.getValue();
    //Make the defaults explicit. See section 5.1.4.5. Assigned identifiers in the Hibernate reference
    //(http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html)
    id.setIdentifierGeneratorStrategy("assigned");
    id.setNullValue("undefined");

    tab.getPrimaryKey().addColumn(col);

    Property prop = createProperty(column, id);
    clazz.addProperty(prop);
    prop.setPropertyAccessorName(mappings.getDefaultAccess());
    //PropertyGeneration generation = PropertyGeneration.parse(null);
    //prop.setGeneration(generation);

    prop.setInsertable(false);
    prop.setUpdateable(false);

    Generator generator = pkcol.getGenerator();

    setPKColumnGenerator(mappings, clazz, tab, column, id, generator);

    tab.setIdentifierValue(id);
    clazz.setIdentifier(id);
    clazz.setIdentifierProperty(prop);
    clazz.setDiscriminatorValue(mdTable.getQualifiedName());

}

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

License:Open Source License

protected void createM2O(Configuration config, Mappings mappings, ForeignKey relationship) {
    com.manydesigns.portofino.model.database.Table manyMDTable = relationship.getFromTable();
    com.manydesigns.portofino.model.database.Table oneMDTable = relationship.getToTable();
    String manyMDQualifiedTableName = manyMDTable.getActualEntityName();
    String oneMDQualifiedTableName = oneMDTable.getActualEntityName();

    RootClass clazz = (RootClass) mappings.getClass(manyMDQualifiedTableName);
    if (clazz == null) {
        logger.error("Cannot find table '{}' as 'many' side of foreign key '{}'. Skipping relationship.",
                manyMDQualifiedTableName, relationship.getName());
        return;//  w  w  w  .  j a v  a2 s.c o  m
    }

    Table tab = clazz.getTable();
    List<String> columnNames = new ArrayList<String>();

    for (Reference ref : relationship.getReferences()) {
        if (ref.getActualFromColumn() == null) {
            logger.error("Missing from column {}, skipping relationship", ref.getFromColumn());
            return;
        }
        columnNames.add(ref.getFromColumn());
    }

    ManyToOne m2o = new ManyToOne(mappings, tab);
    m2o.setLazy(LAZY);
    final HashMap<String, PersistentClass> persistentClasses = new HashMap<String, PersistentClass>();
    persistentClasses.put(oneMDQualifiedTableName, config.getClassMapping(oneMDQualifiedTableName));
    m2o.setReferencedEntityName(oneMDQualifiedTableName);
    m2o.createPropertyRefConstraints(persistentClasses);

    PersistentClass manyClass = config.getClassMapping(manyMDQualifiedTableName);
    for (String columnName : columnNames) {
        Column col = new Column();
        col.setName(escapeName(columnName));
        //Recupero la colonna precedentemente associata alla tabella:
        //essa ha uno uniqueIdentifier generato al momento dell'associazione alla tabella;
        //questo viene utilizzato per disambiguare l'alias della colonna nelle query
        //SQL generate da Hibernate.
        col = manyClass.getTable().getColumn(col);
        if (col == null) {
            logger.error("Column not found in 'many' entity {}: {}, " + "skipping relationship",
                    manyClass.getEntityName(), columnName);
            return;
        }
        m2o.addColumn(col);
    }

    Property prop = new Property();
    prop.setName(relationship.getActualOnePropertyName());
    //prop.setNodeName(relationship.getActualOnePropertyName());
    prop.setValue(m2o);
    prop.setCascade("none"); //TODO era "all", capire
    prop.setInsertable(false);
    prop.setUpdateable(false);
    clazz.addProperty(prop);
}

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

License:Apache License

protected void bindNaturalIdentifier(Table table, Mapping mapping, PersistentClass persistentClass) {
    Object o = mapping != null ? mapping.getIdentity() : null;
    if (!(o instanceof Identity)) {
        return;//w  w  w . j  a v a  2  s  .com
    }

    Identity identity = (Identity) o;
    final NaturalId naturalId = identity.getNatural();
    if (naturalId == null || naturalId.getPropertyNames().isEmpty()) {
        return;
    }

    UniqueKey uk = new UniqueKey();
    uk.setTable(table);

    boolean mutable = naturalId.isMutable();

    for (String propertyName : naturalId.getPropertyNames()) {
        Property property = persistentClass.getProperty(propertyName);

        property.setNaturalIdentifier(true);
        if (!mutable)
            property.setUpdateable(false);

        uk.addColumns(property.getColumnIterator());
    }

    setUniqueName(uk);

    table.addUniqueKey(uk);
}

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

License:Apache License

/**
 * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model
 *
 * @param grailsProperty The grails property instance
 * @param prop           The Hibernate property
 * @param mappings       The Hibernate mappings
 *///from   w w  w.  j a v a 2s  . c  o m
protected void bindProperty(GrailsDomainClassProperty grailsProperty, Property prop, Mappings mappings) {
    // set the property name
    prop.setName(grailsProperty.getName());
    if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) {
        prop.setInsertable(false);
        prop.setUpdateable(false);
    } else {
        prop.setInsertable(getInsertableness(grailsProperty));
        prop.setUpdateable(getUpdateableness(grailsProperty));
    }

    prop.setPropertyAccessorName(mappings.getDefaultAccess());
    prop.setOptional(grailsProperty.isOptional());

    setCascadeBehaviour(grailsProperty, prop);

    // lazy to true
    boolean isLazyable = grailsProperty.isOneToOne() || grailsProperty.isManyToOne()
            || grailsProperty.isEmbedded()
            || grailsProperty.isPersistent() && !grailsProperty.isAssociation() && !grailsProperty.isIdentity();

    if (isLazyable) {
        final boolean isLazy = getLaziness(grailsProperty);
        prop.setLazy(isLazy);

        if (isLazy && (grailsProperty.isManyToOne() || grailsProperty.isOneToOne())) {
            handleLazyProxy(grailsProperty.getDomainClass(), grailsProperty);
        }
    }
}

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

License:Apache License

private static void bindNaturalIdentifier(Table table, Mapping mapping, PersistentClass persistentClass) {
    Object o = mapping != null ? mapping.getIdentity() : null;
    if (o instanceof Identity) {
        Identity identity = (Identity) o;
        final NaturalId naturalId = identity.getNatural();
        if (naturalId != null && !naturalId.getPropertyNames().isEmpty()) {
            UniqueKey uk = new UniqueKey();
            uk.setName("_UniqueKey");
            uk.setTable(table);/*from   w  ww.j  ava 2  s .co  m*/

            boolean mutable = naturalId.isMutable();

            for (String propertyName : naturalId.getPropertyNames()) {
                Property property = persistentClass.getProperty(propertyName);

                property.setNaturalIdentifier(true);
                if (!mutable)
                    property.setUpdateable(false);

                uk.addColumns(property.getColumnIterator());
            }

            table.addUniqueKey(uk);
        }
    }
}

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

License:Apache License

/**
 * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model
 *
 * @param grailsProperty The grails property instance
 * @param prop           The Hibernate property
 * @param mappings       The Hibernate mappings
 *//*from   w  ww.jav  a2s  .co m*/
private static void bindProperty(GrailsDomainClassProperty grailsProperty, Property prop, Mappings mappings) {
    // set the property name
    prop.setName(grailsProperty.getName());
    if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) {
        prop.setInsertable(false);
        prop.setUpdateable(false);
    } else {
        prop.setInsertable(getInsertableness(grailsProperty));
        prop.setUpdateable(getUpdateableness(grailsProperty));
    }

    prop.setPropertyAccessorName(mappings.getDefaultAccess());
    prop.setOptional(grailsProperty.isOptional());

    setCascadeBehaviour(grailsProperty, prop);

    // lazy to true
    boolean isLazyable = grailsProperty.isOneToOne() || grailsProperty.isManyToOne()
            || grailsProperty.isEmbedded()
            || grailsProperty.isPersistent() && !grailsProperty.isAssociation() && !grailsProperty.isIdentity();

    if (isLazyable) {
        final boolean isLazy = getLaziness(grailsProperty);
        prop.setLazy(isLazy);

        if (isLazy && (grailsProperty.isManyToOne() || grailsProperty.isOneToOne())) {
            HibernatePluginSupport.handleLazyProxy(grailsProperty.getDomainClass(), grailsProperty);
        }
    }
}

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

License:Apache License

protected void bindNaturalIdentifier(Table table, Mapping mapping, PersistentClass persistentClass) {
    Object o = mapping != null ? mapping.getIdentity() : null;
    if (!(o instanceof Identity)) {
        return;/* w ww  . j  av a  2 s .  co m*/
    }

    Identity identity = (Identity) o;
    final NaturalId naturalId = identity.getNatural();
    if (naturalId == null || naturalId.getPropertyNames().isEmpty()) {
        return;
    }

    UniqueKey uk = new UniqueKey();
    uk.setTable(table);

    boolean mutable = naturalId.isMutable();

    for (String propertyName : naturalId.getPropertyNames()) {
        Property property = persistentClass.getProperty(propertyName);

        property.setNaturalIdentifier(true);
        if (!mutable)
            property.setUpdateable(false);

        uk.addColumns(property.getColumnIterator());
    }

    setGeneratedUniqueName(uk);

    table.addUniqueKey(uk);
}

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

License:Apache License

/**
 * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model
 *
 * @param grailsProperty The grails property instance
 * @param prop           The Hibernate property
 * @param mappings       The Hibernate mappings
 */// w  ww. j  a v  a2 s .  com
protected void bindProperty(PersistentProperty grailsProperty, Property prop, Mappings mappings) {
    // set the property name
    prop.setName(grailsProperty.getName());
    if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) {
        prop.setInsertable(false);
        prop.setUpdateable(false);
    } else {
        prop.setInsertable(getInsertableness(grailsProperty));
        prop.setUpdateable(getUpdateableness(grailsProperty));
    }

    prop.setPropertyAccessorName(mappings.getDefaultAccess());
    prop.setOptional(grailsProperty.isNullable());

    setCascadeBehaviour(grailsProperty, prop);

    // lazy to true
    final boolean isToOne = grailsProperty instanceof ToOne;
    boolean isLazyable = isToOne || !(grailsProperty instanceof Association)
            && !grailsProperty.equals(grailsProperty.getOwner().getIdentity());

    if (isLazyable) {
        final boolean isLazy = getLaziness(grailsProperty);
        prop.setLazy(isLazy);

        if (isLazy && isToOne) {
            handleLazyProxy(grailsProperty.getOwner(), grailsProperty);
        }
    }
}

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

License:Apache License

/**
 * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model
 *
 * @param grailsProperty The grails property instance
 * @param prop           The Hibernate property
 * @param mappings       The Hibernate mappings
 *///from  w  w  w  . ja va2s  .  com
protected void bindProperty(PersistentProperty grailsProperty, Property prop,
        InFlightMetadataCollector mappings) {
    // set the property name
    prop.setName(grailsProperty.getName());
    if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) {
        prop.setInsertable(false);
        prop.setUpdateable(false);
    } else {
        prop.setInsertable(getInsertableness(grailsProperty));
        prop.setUpdateable(getUpdateableness(grailsProperty));
    }

    AccessType accessType = AccessType
            .getAccessStrategy(grailsProperty.getMapping().getMappedForm().getAccessType());
    prop.setPropertyAccessorName(accessType.getType());
    prop.setOptional(grailsProperty.isNullable());

    setCascadeBehaviour(grailsProperty, prop);

    // lazy to true
    final boolean isToOne = grailsProperty instanceof ToOne;
    PersistentEntity propertyOwner = grailsProperty.getOwner();
    boolean isLazyable = isToOne
            || !(grailsProperty instanceof Association) && !grailsProperty.equals(propertyOwner.getIdentity());

    if (isLazyable) {
        final boolean isLazy = getLaziness(grailsProperty);
        prop.setLazy(isLazy);

        if (isLazy && isToOne
                && !(PersistentAttributeInterceptable.class.isAssignableFrom(propertyOwner.getJavaClass()))) {
            handleLazyProxy(propertyOwner, grailsProperty);
        }
    }
}