List of usage examples for org.hibernate.mapping Column Column
public Column()
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
private void assertColumnLength(ConstrainedProperty constrainedProperty, int expectedLength) { Column column = new Column(); GrailsDomainBinder.bindStringColumnConstraints(column, constrainedProperty); assertEquals(expectedLength, column.getLength()); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
private void assertColumnPrecisionAndScale(ConstrainedProperty constrainedProperty, int expectedPrecision, int expectedScale) { Column column = new Column(); GrailsDomainBinder.bindNumericColumnConstraints(column, constrainedProperty); assertEquals(expectedPrecision, column.getPrecision()); assertEquals(expectedScale, column.getScale()); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void linkValueUsingAColumnCopy(PersistentProperty prop, Column column, DependantValue key) { Column mappingColumn = new Column(); mappingColumn.setName(column.getName()); mappingColumn.setLength(column.getLength()); mappingColumn.setNullable(prop.isNullable()); mappingColumn.setSqlType(column.getSqlType()); mappingColumn.setValue(key);/*from ww w. j ava 2 s .co m*/ key.addColumn(mappingColumn); key.getTable().addColumn(mappingColumn); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindEnumType(PersistentProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) {//from ww w.ja v a 2s.c om PropertyConfig pc = getPropertyConfig(property); final PersistentEntity owner = property.getOwner(); String typeName = getTypeName(property, getPropertyConfig(property), getMapping(owner)); if (typeName == null) { Properties enumProperties = new Properties(); enumProperties.put(ENUM_CLASS_PROP, propertyType.getName()); String enumType = pc == null ? DEFAULT_ENUM_TYPE : pc.getEnumType(); if (enumType.equals(DEFAULT_ENUM_TYPE) && identityEnumTypeSupports(propertyType)) { simpleValue.setTypeName("org.grails.orm.hibernate.cfg.IdentityEnumType"); } else { simpleValue.setTypeName(ENUM_TYPE_CLASS); if (enumType.equals(DEFAULT_ENUM_TYPE) || "string".equalsIgnoreCase(enumType)) { enumProperties.put(ENUM_TYPE_PROP, String.valueOf(Types.VARCHAR)); } else if (!"ordinal".equalsIgnoreCase(enumType)) { LOG.warn("Invalid enumType specified when mapping property [" + property.getName() + "] of class [" + owner.getName() + "]. Using defaults instead."); } } simpleValue.setTypeParameters(enumProperties); } else { simpleValue.setTypeName(typeName); } Table t = simpleValue.getTable(); Column column = new Column(); if (owner.isRoot()) { column.setNullable(property.isNullable()); } else { Mapping mapping = getMapping(owner); if (mapping == null || mapping.getTablePerHierarchy()) { if (LOG.isDebugEnabled()) { LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name [" + column.getName() + "] set to nullable"); } column.setNullable(true); } else { column.setNullable(property.isNullable()); } } column.setValue(simpleValue); column.setName(columnName); if (t != null) t.addColumn(column); simpleValue.addColumn(column); PropertyConfig propertyConfig = getPropertyConfig(property); if (propertyConfig != null && !propertyConfig.getColumns().isEmpty()) { bindIndex(columnName, column, propertyConfig.getColumns().get(0), t); bindColumnConfigToColumn(property, column, propertyConfig.getColumns().get(0)); } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindSimpleValue(PersistentProperty grailsProp, PersistentProperty parentProperty, SimpleValue simpleValue, String path, PropertyConfig propertyConfig, String sessionFactoryBeanName) { setTypeForPropertyConfig(grailsProp, simpleValue, propertyConfig); final PropertyConfig mappedForm = (PropertyConfig) grailsProp.getMapping().getMappedForm(); if (mappedForm.isDerived()) { Formula formula = new Formula(); formula.setFormula(propertyConfig.getFormula()); simpleValue.addFormula(formula); } else {//from www. j av a 2 s .c o m Table table = simpleValue.getTable(); // Add the column definitions for this value/property. Note that // not all custom mapped properties will have column definitions, // in which case we still need to create a Hibernate column for // this value. List<?> columnDefinitions = propertyConfig != null ? propertyConfig.getColumns() : Arrays.asList(new Object[] { null }); if (columnDefinitions.isEmpty()) { columnDefinitions = Arrays.asList(new Object[] { null }); } for (Object columnDefinition : columnDefinitions) { ColumnConfig cc = (ColumnConfig) columnDefinition; Column column = new Column(); // Check for explicitly mapped column name and SQL type. if (cc != null) { if (cc.getName() != null) { column.setName(cc.getName()); } if (cc.getSqlType() != null) { column.setSqlType(cc.getSqlType()); } } column.setValue(simpleValue); if (cc != null) { if (cc.getLength() != -1) { column.setLength(cc.getLength()); } if (cc.getPrecision() != -1) { column.setPrecision(cc.getPrecision()); } if (cc.getScale() != -1) { column.setScale(cc.getScale()); } if (!mappedForm.isUniqueWithinGroup()) { column.setUnique(cc.isUnique()); } } bindColumn(grailsProp, parentProperty, column, cc, path, table, sessionFactoryBeanName); if (table != null) { table.addColumn(column); } simpleValue.addColumn(column); } } }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void bindEnumType(PersistentProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) {/*from ww w . j a v a 2s . com*/ PropertyConfig pc = getPropertyConfig(property); final PersistentEntity owner = property.getOwner(); String typeName = getTypeName(property, getPropertyConfig(property), getMapping(owner)); if (typeName == null) { Properties enumProperties = new Properties(); enumProperties.put(ENUM_CLASS_PROP, propertyType.getName()); String enumType = pc == null ? DEFAULT_ENUM_TYPE : pc.getEnumType(); boolean isDefaultEnumType = enumType.equals(DEFAULT_ENUM_TYPE); simpleValue.setTypeName(ENUM_TYPE_CLASS); if (isDefaultEnumType || "string".equalsIgnoreCase(enumType)) { enumProperties.put(EnumType.TYPE, String.valueOf(Types.VARCHAR)); enumProperties.put(EnumType.NAMED, Boolean.TRUE.toString()); } else if ("identity".equals(enumType)) { simpleValue.setTypeName(HibernateUtils.buildIdentityEnumTypeFactory().getName()); } else if (!"ordinal".equalsIgnoreCase(enumType)) { simpleValue.setTypeName(enumType); } simpleValue.setTypeParameters(enumProperties); } else { simpleValue.setTypeName(typeName); } Table t = simpleValue.getTable(); Column column = new Column(); if (owner.isRoot()) { column.setNullable(property.isNullable()); } else { Mapping mapping = getMapping(owner); if (mapping == null || mapping.getTablePerHierarchy()) { if (LOG.isDebugEnabled()) { LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name [" + column.getName() + "] set to nullable"); } column.setNullable(true); } else { column.setNullable(property.isNullable()); } } column.setValue(simpleValue); column.setName(columnName); if (t != null) t.addColumn(column); simpleValue.addColumn(column); PropertyConfig propertyConfig = getPropertyConfig(property); if (propertyConfig != null && !propertyConfig.getColumns().isEmpty()) { bindIndex(columnName, column, propertyConfig.getColumns().get(0), t); bindColumnConfigToColumn(property, column, propertyConfig.getColumns().get(0)); } }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void bindSimpleValue(PersistentProperty grailsProp, PersistentProperty parentProperty, SimpleValue simpleValue, String path, PropertyConfig propertyConfig, String sessionFactoryBeanName) { setTypeForPropertyConfig(grailsProp, simpleValue, propertyConfig); final PropertyConfig mappedForm = (PropertyConfig) grailsProp.getMapping().getMappedForm(); if (mappedForm.isDerived() && !(grailsProp instanceof TenantId)) { Formula formula = new Formula(); formula.setFormula(propertyConfig.getFormula()); simpleValue.addFormula(formula); } else {/*w w w . j a v a2 s . c o m*/ Table table = simpleValue.getTable(); boolean hasConfig = propertyConfig != null; String generator = hasConfig ? propertyConfig.getGenerator() : null; if (generator != null) { simpleValue.setIdentifierGeneratorStrategy(generator); Properties params = propertyConfig.getTypeParams(); if (params != null) { Properties generatorProps = new Properties(); generatorProps.putAll(params); if (generatorProps.containsKey(SEQUENCE_KEY)) { generatorProps.put(SequenceStyleGenerator.SEQUENCE_PARAM, generatorProps.getProperty(SEQUENCE_KEY)); } simpleValue.setIdentifierGeneratorProperties(generatorProps); } } // Add the column definitions for this value/property. Note that // not all custom mapped properties will have column definitions, // in which case we still need to create a Hibernate column for // this value. List<?> columnDefinitions = hasConfig ? propertyConfig.getColumns() : Arrays.asList(new Object[] { null }); if (columnDefinitions.isEmpty()) { columnDefinitions = Arrays.asList(new Object[] { null }); } for (Object columnDefinition : columnDefinitions) { ColumnConfig cc = (ColumnConfig) columnDefinition; Column column = new Column(); // Check for explicitly mapped column name and SQL type. if (cc != null) { if (cc.getName() != null) { column.setName(cc.getName()); } if (cc.getSqlType() != null) { column.setSqlType(cc.getSqlType()); } } column.setValue(simpleValue); if (cc != null) { if (cc.getLength() != -1) { column.setLength(cc.getLength()); } if (cc.getPrecision() != -1) { column.setPrecision(cc.getPrecision()); } if (cc.getScale() != -1) { column.setScale(cc.getScale()); } if (!mappedForm.isUniqueWithinGroup()) { column.setUnique(cc.isUnique()); } } bindColumn(grailsProp, parentProperty, column, cc, path, table, sessionFactoryBeanName); if (table != null) { table.addColumn(column); } simpleValue.addColumn(column); } } }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Binds a value for the specified parameters to the meta model. * * @param type The type of the property * @param simpleValue The simple value instance * @param nullable Whether it is nullable * @param columnName The property name// www . j av a2 s . co m * @param mappings The mappings */ protected void bindSimpleValue(String type, SimpleValue simpleValue, boolean nullable, String columnName, InFlightMetadataCollector mappings) { simpleValue.setTypeName(type); Table t = simpleValue.getTable(); Column column = new Column(); column.setNullable(nullable); column.setValue(simpleValue); column.setName(columnName); if (t != null) t.addColumn(column); simpleValue.addColumn(column); }
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; }/*ww w. j a va2 s . 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); } } }
From source file:org.openflexo.jdbc.hbn.MyDBTest.java
License:Open Source License
@Test @TestOrder(4)/* w w w .java2 s .com*/ public void testDeclareJDBCMetaData() { table = metadataCollector.addTable("", "", "T_Dynamic_Table_2", null, false); table.setName("T_Dynamic_Table_2"); col = new Column(); col.setName("pouet"); col.setLength(256); col.setSqlType("CHAR(32)"); col.setNullable(false); table.addColumn(col); PrimaryKey pk = new PrimaryKey(table); pk.addColumn(col); UniqueKey uk1 = new UniqueKey(); uk1.setName("Nom_Unique"); uk1.setTable(table); uk1.addColumn(col); table.addUniqueKey(uk1); col2 = new Column(); col2.setName("padam"); col2.setLength(256); col2.setSqlType("CHAR(32)"); col2.setNullable(true); table.addColumn(col2); // pour rire les couples "Nom + Prenom" doivent tre uniques UniqueKey uk = new UniqueKey(); uk.setName("Couple_Nom_Prenom_Unique"); uk.setTable(table); uk.addColumn(col); uk.addColumn(col2); table.addUniqueKey(uk); // une colonne de clef etrangre vers T_Adresse col3 = new Column(); col3.setName("id_addr"); col3.setLength(16); col3.setSqlType("INTEGER"); col3.setNullable(true); table.addColumn(col3); // ********** // Creation / Dfinition de la table T_Adresse table2 = metadataCollector.addTable("", "", "T_Adresse_2", null, false); table2.setName("T_Adresse_2"); col4 = new Column(); col4.setName("Id"); col4.setLength(16); col4.setSqlType("INTEGER"); col4.setNullable(false); table2.addColumn(col4); pk = new PrimaryKey(table2); pk.addColumn(col); uk1 = new UniqueKey(); uk1.setName("Id_Unique"); uk1.setTable(table2); uk1.addColumn(col4); table.addUniqueKey(uk1); col5 = new Column(); col5.setName("Adresse"); col5.setLength(512); col5.setSqlType("CHAR(512)"); col5.setNullable(true); table2.addColumn(col5); }