List of usage examples for org.hibernate.mapping SimpleValue setTypeParameters
public void setTypeParameters(Properties parameterMap)
From source file:com.klistret.cmdb.utility.spring.LocalSessionFactoryBean.java
License:Open Source License
protected void postProcessMappings(Configuration config) throws HibernateException { logger.debug("Overriding the postProcessMappings method in the Spring LocalSessionFactoryBean"); /**/*from ww w.j a v a 2 s .c om*/ * http://stackoverflow.com/questions/672063/creating-a-custom-hibernate-usertype-find-out-the-current-entity-table-name */ for (Iterator<PersistentClass> classMappingIterator = config.getClassMappings(); classMappingIterator .hasNext();) { PersistentClass persistentClass = (PersistentClass) classMappingIterator.next(); for (Iterator<?> propertyIterator = persistentClass.getPropertyIterator(); propertyIterator .hasNext();) { Property property = (Property) propertyIterator.next(); if (property.getType().getName().equals(JAXBUserType.class.getName())) { logger.debug("Setting ci context properties for Hibernate user type [{}]", JAXBUserType.class.getName()); SimpleValue simpleValue = (SimpleValue) property.getValue(); Properties parameterMap = new Properties(); parameterMap.setProperty("baseTypes", baseTypes); logger.debug("Base types [{}]", baseTypes); parameterMap.setProperty("assignablePackages", assignablePackages); logger.debug("Assignable packages [{}]", assignablePackages); simpleValue.setTypeParameters(parameterMap); } } } }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
public boolean setHibernateType(@Nullable SimpleValue value, com.manydesigns.portofino.model.database.Column column, Class javaType, final int jdbcType) { String typeName;/*from w w w . j a v a 2 s .c o m*/ Properties typeParams = null; if (javaType == null) { return false; } if (javaType == Long.class) { typeName = LongType.INSTANCE.getName(); } else if (javaType == Short.class) { typeName = ShortType.INSTANCE.getName(); } else if (javaType == Integer.class) { typeName = IntegerType.INSTANCE.getName(); } else if (javaType == Byte.class) { typeName = ByteType.INSTANCE.getName(); } else if (javaType == Float.class) { typeName = FloatType.INSTANCE.getName(); } else if (javaType == Double.class) { typeName = DoubleType.INSTANCE.getName(); } else if (javaType == Character.class) { typeName = CharacterType.INSTANCE.getName(); } else if (javaType == String.class) { typeName = StringType.INSTANCE.getName(); } else if (java.util.Date.class.isAssignableFrom(javaType)) { switch (jdbcType) { case Types.DATE: typeName = DateType.INSTANCE.getName(); break; case Types.TIME: typeName = TimeType.INSTANCE.getName(); break; case Types.TIMESTAMP: typeName = TimestampType.INSTANCE.getName(); break; default: typeName = null; } } else if (javaType == Boolean.class) { if (jdbcType == Types.BIT || jdbcType == Types.BOOLEAN) { typeName = BooleanType.INSTANCE.getName(); } else if (jdbcType == Types.NUMERIC || jdbcType == Types.DECIMAL || jdbcType == Types.INTEGER || jdbcType == Types.SMALLINT || jdbcType == Types.TINYINT || jdbcType == Types.BIGINT) { typeName = NumericBooleanType.INSTANCE.getName(); } else if (jdbcType == Types.CHAR || jdbcType == Types.VARCHAR) { typeName = StringBooleanType.class.getName(); typeParams = new Properties(); typeParams.setProperty("true", trueString != null ? trueString : StringBooleanType.NULL); typeParams.setProperty("false", falseString != null ? falseString : StringBooleanType.NULL); typeParams.setProperty("sqlType", String.valueOf(jdbcType)); } else { typeName = null; } } else if (javaType == BigDecimal.class) { typeName = BigDecimalType.INSTANCE.getName(); } else if (javaType == BigInteger.class) { typeName = BigIntegerType.INSTANCE.getName(); } else if (javaType == byte[].class) { typeName = BlobType.INSTANCE.getName(); } else { typeName = null; } if (typeName == null) { logger.error("Unsupported type (java type: {}, jdbc type: {}) " + "for column '{}'.", new Object[] { javaType, jdbcType, column.getColumnName() }); return false; } if (value != null) { value.setTypeName(typeName); if (typeParams != null) { value.setTypeParameters(typeParams); } } return true; }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindEnumType(GrailsDomainClassProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) {//from ww w .j ava2 s .co m PropertyConfig pc = getPropertyConfig(property); String typeName = getTypeName(property, getPropertyConfig(property), getMapping(property.getDomainClass())); 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.codehaus.groovy.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 [" + property.getDomainClass().getClazz().getName() + "]. Using defaults instead."); } } simpleValue.setTypeParameters(enumProperties); } else { simpleValue.setTypeName(typeName); } Table t = simpleValue.getTable(); Column column = new Column(); if (property.getDomainClass().isRoot()) { column.setNullable(property.isOptional()); } else { Mapping mapping = getMapping(property.getDomainClass()); 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.isOptional()); } } 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(column, propertyConfig.getColumns().get(0)); } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void setTypeForPropertyConfig(GrailsDomainClassProperty grailsProp, SimpleValue simpleValue, PropertyConfig config) {//from w w w. j a v a 2 s .c om final String typeName = getTypeName(grailsProp, getPropertyConfig(grailsProp), getMapping(grailsProp.getDomainClass())); if (typeName == null) { simpleValue.setTypeName(grailsProp.getType().getName()); } else { simpleValue.setTypeName(typeName); if (config != null) { simpleValue.setTypeParameters(config.getTypeParams()); } } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void bindEnumType(GrailsDomainClassProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) { Properties enumProperties = new Properties(); enumProperties.put(ENUM_CLASS_PROP, propertyType.getName()); PropertyConfig pc = getPropertyConfig(property); String enumType = pc != null ? pc.getEnumType() : DEFAULT_ENUM_TYPE; if (enumType.equals(DEFAULT_ENUM_TYPE) && IdentityEnumType.supports(propertyType)) { simpleValue.setTypeName(IdentityEnumType.class.getName()); } else {/*from w w w . j a v a2 s .co m*/ 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 [" + property.getDomainClass().getClazz().getName() + "]. Using defaults instead."); } } simpleValue.setTypeParameters(enumProperties); Table t = simpleValue.getTable(); Column column = new Column(); if (property.getDomainClass().isRoot()) { column.setNullable(property.isOptional()); } else { Mapping mapping = getMapping(property.getDomainClass()); 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.isOptional()); } } 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); } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void setTypeForPropertyConfig(GrailsDomainClassProperty grailsProp, SimpleValue simpleValue, PropertyConfig config) {/*ww w . java 2 s . c o m*/ final String typeName = getTypeName(grailsProp, getPropertyConfig(grailsProp), getMapping(grailsProp.getDomainClass())); if (typeName != null) { simpleValue.setTypeName(typeName); if (config != null) simpleValue.setTypeParameters(config.getTypeParams()); } else { simpleValue.setTypeName(grailsProp.getType().getName()); } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindEnumType(PersistentProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) {/* w w w . ja va 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 setTypeForPropertyConfig(PersistentProperty grailsProp, SimpleValue simpleValue, PropertyConfig config) {//from ww w .j a v a 2 s . co m final String typeName = getTypeName(grailsProp, getPropertyConfig(grailsProp), getMapping(grailsProp.getOwner())); if (typeName == null) { simpleValue.setTypeName(grailsProp.getType().getName()); } else { simpleValue.setTypeName(typeName); if (config != null) { simpleValue.setTypeParameters(config.getTypeParams()); } } }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void bindEnumType(PersistentProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) {/* w ww . ja va2s .co m*/ 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)); } }