Example usage for org.hibernate.mapping RootClass setVersion

List of usage examples for org.hibernate.mapping RootClass setVersion

Introduction

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

Prototype

public void setVersion(Property version) 

Source Link

Usage

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

License:Apache License

protected void bindVersion(GrailsDomainClassProperty version, RootClass entity, Mappings mappings,
        String sessionFactoryBeanName) {

    SimpleValue val = new SimpleValue(mappings, entity.getTable());

    bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName);

    if (val.isTypeSpecified()) {
        if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType
                || val.getType() instanceof TimestampType)) {
            LOG.warn("Invalid version class specified in " + version.getDomainClass().getClazz().getName()
                    + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version.");
            return;
        }//from  ww  w  . j  a va 2  s  .c  o  m
    } else {
        val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp");
    }
    Property prop = new Property();
    prop.setValue(val);

    bindProperty(version, prop, mappings);
    val.setNullValue("undefined");
    entity.setVersion(prop);
    entity.setOptimisticLockMode(0); // 0 is to use version column
    entity.addProperty(prop);
}

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

License:Apache License

private static void bindVersion(GrailsDomainClassProperty version, RootClass entity, Mappings mappings,
        String sessionFactoryBeanName) {

    SimpleValue val = new SimpleValue(mappings, entity.getTable());

    bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName);

    if (val.isTypeSpecified()) {
        if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType
                || val.getType() instanceof TimestampType)) {
            LOG.warn("Invalid version class specified in " + version.getDomainClass().getClazz().getName()
                    + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version.");
            return;
        }/*from  w w  w .  j  a va 2  s. co m*/
    } else {
        val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp");
    }
    Property prop = new Property();
    prop.setValue(val);

    bindProperty(version, prop, mappings);
    val.setNullValue("undefined");
    entity.setVersion(prop);
    entity.addProperty(prop);
}

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

License:Apache License

protected void bindVersion(PersistentProperty version, RootClass entity, Mappings mappings,
        String sessionFactoryBeanName) {

    if (version != null) {

        SimpleValue val = new SimpleValue(mappings, entity.getTable());

        bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName);

        if (val.isTypeSpecified()) {
            if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType
                    || val.getType() instanceof TimestampType)) {
                LOG.warn("Invalid version class specified in " + version.getOwner().getName()
                        + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version.");
                return;
            }/*from ww w. j a va2 s. c  om*/
        } else {
            val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp");
        }
        Property prop = new Property();
        prop.setValue(val);

        bindProperty(version, prop, mappings);
        val.setNullValue("undefined");
        entity.setVersion(prop);
        entity.setOptimisticLockMode(0); // 0 is to use version column
        entity.addProperty(prop);
    }
}

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

License:Apache License

protected void bindVersion(PersistentProperty version, RootClass entity, InFlightMetadataCollector mappings,
        String sessionFactoryBeanName) {

    if (version != null) {

        SimpleValue val = new SimpleValue(mappings, entity.getTable());

        bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName);

        if (val.isTypeSpecified()) {
            if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType
                    || val.getType() instanceof TimestampType)) {
                LOG.warn("Invalid version class specified in " + version.getOwner().getName()
                        + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version.");
                return;
            }//w w  w. j  a va2  s .c  o  m
        } else {
            val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp");
        }
        Property prop = new Property();
        prop.setValue(val);
        bindProperty(version, prop, mappings);
        prop.setLazy(false);
        val.setNullValue("undefined");
        entity.setVersion(prop);
        entity.setOptimisticLockStyle(OptimisticLockStyle.VERSION);
        entity.addProperty(prop);
    }
}

From source file:org.infinispan.test.hibernate.cache.commons.functional.AbstractFunctionalTest.java

License:LGPL

@Override
protected void afterMetadataBuilt(Metadata metadata) {
    if (addVersions) {
        for (PersistentClass clazz : metadata.getEntityBindings()) {
            if (clazz.getVersion() != null) {
                continue;
            }//from   w  ww  .j ava 2s. co  m
            try {
                clazz.getMappedClass().getMethod("getVersion");
                clazz.getMappedClass().getMethod("setVersion", long.class);
            } catch (NoSuchMethodException e) {
                continue;
            }
            RootClass rootClazz = clazz.getRootClass();
            Property versionProperty = new Property();
            versionProperty.setName("version");
            SimpleValue value = new SimpleValue((MetadataImplementor) metadata, rootClazz.getTable());
            value.setTypeName("long");
            Column column = new Column();
            column.setValue(value);
            column.setName("version");
            value.addColumn(column);
            rootClazz.getTable().addColumn(column);
            versionProperty.setValue(value);
            rootClazz.setVersion(versionProperty);
            rootClazz.addProperty(versionProperty);
        }
    }
}