Example usage for org.hibernate.mapping SimpleValue getType

List of usage examples for org.hibernate.mapping SimpleValue getType

Introduction

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

Prototype

public Type getType() throws MappingException 

Source Link

Usage

From source file:com.oy.shared.lm.ext.HBMCtoGRAPH.java

License:Open Source License

private Attribute addSimpleProp(SimpleValue val, String name) {
    if (!val.isSimpleValue()) {
        throw new RuntimeException("Expected SimpleValue.");
    }//from w  w  w  .  ja  v  a2s .  c  o  m

    Attribute attr = new Attribute();
    attr.name = name;
    if (attr.name == null) {
        Iterator iter = val.getColumnIterator();
        while (iter.hasNext()) {
            Column col = (Column) iter.next();
            attr.name = col.getName();
            break;
        }
    }
    if (val instanceof Component) {
        attr.type = ((Component) val).getComponentClassName();
    } else {
        attr.type = val.getType().getName();
    }

    return attr;
}

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   w  w  w.  j a va2  s .  com*/
    } 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;
        }/*  ww w .  j  a v  a 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.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 w w w . j  a  v  a2 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;
            }//www. j  av  a 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);
        prop.setLazy(false);
        val.setNullValue("undefined");
        entity.setVersion(prop);
        entity.setOptimisticLockStyle(OptimisticLockStyle.VERSION);
        entity.addProperty(prop);
    }
}