Example usage for org.hibernate.mapping Property getColumnSpan

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

Introduction

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

Prototype

public int getColumnSpan() 

Source Link

Usage

From source file:com.siemens.scr.avt.ad.query.common.DicomMappingDictionaryLoadingStrategy.java

License:Open Source License

private void loadProperty(DicomMappingDictionary dict, Property prop, Table table, String classPrefix) {
    String key = classPrefix + "." + prop.getName();
    Type type = prop.getType();/* w w  w .  j ava 2  s  .  c  om*/
    String tableName = table.getSchema() + "." + table.getName();
    if (type.isAssociationType() || type.isCollectionType()) {
        // do nothing
    } else if (type.isComponentType()) {
        Component component = (Component) prop.getValue();
        Iterator<Property> it = component.getPropertyIterator();
        while (it.hasNext()) {
            Property subProp = it.next();
            loadProperty(dict, subProp, table, component.getRoleName());
        }
    } else {
        int sqltype = sqlTypes(type);

        assert prop.getColumnSpan() == 1;
        Iterator<Column> it = prop.getColumnIterator();
        String column = it.next().getName();

        dict.addMappingEntry(key, tableName, column, sqltype);

        loadTag(dict, prop, key);
        loadDicomHeaderMetadata(dict, tableName, column, prop);
    }

}

From source file:com.tomitribe.reveng.codegen.FreemarkerObject.java

License:Apache License

public String generateManyToOneAnnotation(final BasicPOJOClass pojo, final Property p, String table) {

    // @ForeignKey(name="FK_recipe_tree_node")
    final Value value = p.getValue();
    final int span;
    final Iterator columnIterator;
    if (value != null && value instanceof Collection) {
        final Collection collection = (Collection) value;
        span = collection.getKey().getColumnSpan();
        columnIterator = collection.getKey().getColumnIterator();
    } else {/*from w  ww  .j a v  a  2  s .  c  om*/
        span = p.getColumnSpan();
        columnIterator = p.getColumnIterator();
    }
    final Selectable selectable = (Selectable) columnIterator.next();
    final Column column = (Column) selectable;
    table += "_" + column.getName(); // id_tree_node
    table = "FK_" + table.replace("_id_", "_");

    String s = EntityPOJOClass.class.cast(pojo).generateManyToOneAnnotation(p);
    s += "\n@ForeignKey(name=\"" + table + "\")";

    // log.info(s);

    return s;
}

From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void commentProperty(Class<?> clazz, Table table, Property p) {
    if (null == p)
        return;//from   w w w . ja  va2 s . co m
    if (p.getColumnSpan() == 1) {
        Column column = (Column) p.getColumnIterator().next();
        if (isForeignColumn(table, column)) {
            column.setComment(messages.get(clazz, p.getName()) + " ID");
        } else {
            column.setComment(messages.get(clazz, p.getName()));
        }
    } else if (p.getColumnSpan() > 1) {
        Component pc = ((Component) p.getValue());
        Class<?> columnOwnerClass = pc.getComponentClass();
        commentProperties(columnOwnerClass, table, pc.getPropertyIterator());
    }
}

From source file:org.beangle.orm.hibernate.tool.HbmGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
public void gen(String file) throws Exception {
    hbconfig = new OverrideConfiguration();
    hbconfig.getProperties().put(Environment.DIALECT, new Oracle10gDialect());
    ConfigBuilder.build(hbconfig);/*from   w w  w  . j a v a  2  s .  co m*/
    freemarkerConfig = new freemarker.template.Configuration();
    freemarkerConfig.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));

    Iterator<PersistentClass> iter = hbconfig.getClassMappings();
    List<PersistentClass> pcs = CollectUtils.newArrayList();
    while (iter.hasNext()) {
        PersistentClass pc = iter.next();
        Class<?> cls = pc.getMappedClass();
        Iterator<Property> pi = pc.getPropertyIterator();
        // For AnnotationBinder don't set column'length and nullable in ,let's we do it.
        while (pi.hasNext()) {
            Property p = pi.next();
            if (p.getColumnSpan() != 1)
                continue;
            Column column = (Column) p.getColumnIterator().next();
            if (column.getLength() == Column.DEFAULT_LENGTH) {
                Size size = findAnnotation(cls, Size.class, p.getName());
                if (null != size)
                    column.setLength(size.max());
            }
            if (column.isNullable()) {
                NotNull notnull = findAnnotation(cls, NotNull.class, p.getName());
                if (null != notnull)
                    column.setNullable(false);
            }
        }
        if (!pc.getClassName().contains(".example."))
            pcs.add(pc);
    }
    Map<String, Object> data = CollectUtils.newHashMap();
    data.put("classes", pcs);
    data.put("generator", this);
    Template freemarkerTemplate = freemarkerConfig.getTemplate("/hbm.ftl");
    FileWriter fw = new FileWriter("/tmp/hibernate.hbm.xml");
    freemarkerTemplate.process(data, fw);
}

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

License:Apache License

/**
 * Tests that single- and multi-column user type mappings work
 * correctly. Also Checks that the "sqlType" property is honoured.
 *///from  www .  ja  v a 2 s.  c o  m
public void testUserTypeMappings() {
    DefaultGrailsDomainConfiguration config = getDomainConfig(MULTI_COLUMN_USER_TYPE_DEFINITION);
    PersistentClass persistentClass = config.getClassMapping("Item");

    // First check the "name" property and its associated column.
    Property nameProperty = persistentClass.getProperty("name");
    assertEquals(1, nameProperty.getColumnSpan());
    assertEquals("name", nameProperty.getName());

    Column column = (Column) nameProperty.getColumnIterator().next();
    assertEquals("s_name", column.getName());
    assertEquals("text", column.getSqlType());

    // Next the "other" property.
    Property otherProperty = persistentClass.getProperty("other");
    assertEquals(1, otherProperty.getColumnSpan());
    assertEquals("other", otherProperty.getName());

    column = (Column) otherProperty.getColumnIterator().next();
    assertEquals("other", column.getName());
    assertEquals("wrapper-characters", column.getSqlType());
    assertEquals(MyUserType.class.getName(), column.getValue().getType().getName());
    assertTrue(column.getValue() instanceof SimpleValue);
    SimpleValue v = (SimpleValue) column.getValue();
    assertEquals("myParam1", v.getTypeParameters().get("param1"));
    assertEquals("myParam2", v.getTypeParameters().get("param2"));

    // And now for the "price" property, which should have two
    // columns.
    Property priceProperty = persistentClass.getProperty("price");
    assertEquals(2, priceProperty.getColumnSpan());
    assertEquals("price", priceProperty.getName());

    Iterator colIter = priceProperty.getColumnIterator();
    column = (Column) colIter.next();
    assertEquals("value", column.getName());
    assertNull("SQL type should have been 'null' for 'value' column.", column.getSqlType());

    column = (Column) colIter.next();
    assertEquals("currency_code", column.getName());
    assertEquals("text", column.getSqlType());
}