List of usage examples for org.hibernate.mapping Column setValue
public void setValue(Value value)
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 ww.j a va 2 s.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 w ww . j av a2s . com*/ 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 w ww .j a va 2 s . 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 {/*from w w w .j a v a 2 s. co 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/*from w ww .ja va 2 s . c om*/ * @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; }//from ww w. ja va2 s . c o 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.processbase.engine.bam.db.ScriptGenerator.java
License:Open Source License
public ArrayList<String> getCreateTableScript(MetaKpi metaKpi, int type) { try {/*from ww w . java 2 s.co m*/ Configuration config = new Configuration(); Dialect d = (Dialect) Class.forName(BAMConstants.BAM_DB_DIALECT).newInstance(); Mappings mappings = config.createMappings(); table = mappings.addTable(null, null, metaKpi.getCode(), null, false); Column id = new Column("ID"); SimpleValue idVal = new SimpleValue(table); idVal.setTypeName(TypeFactory.basic("long").getName()); id.setValue(idVal); Column kpiTimeStamp = new Column("KPI_TIMESTAMP"); kpiTimeStamp.setSqlType(TypeFactory.basic(java.util.Date.class.getName()).getName()); Column kpiYear = new Column("KPI_YEAR"); SimpleValue kpiYearVal = new SimpleValue(table); kpiYearVal.setTypeName(TypeFactory.basic("short").getName()); kpiYear.setLength(4); kpiYear.setValue(kpiYearVal); addIndex(kpiYear); Column kpiQuater = new Column("KPI_QUATER"); SimpleValue kpiQuaterVal = new SimpleValue(table); kpiQuaterVal.setTypeName(TypeFactory.basic("short").getName()); kpiQuater.setLength(4); kpiQuater.setValue(kpiQuaterVal); addIndex(kpiQuater); Column kpiMonth = new Column("KPI_MONTH"); SimpleValue kpiMonthVal = new SimpleValue(table); kpiMonthVal.setTypeName(TypeFactory.basic("short").getName()); kpiMonth.setLength(4); kpiMonth.setValue(kpiMonthVal); addIndex(kpiMonth); Column kpiWeek = new Column("KPI_WEEK"); SimpleValue kpiWeekVal = new SimpleValue(table); kpiWeekVal.setTypeName(TypeFactory.basic("short").getName()); kpiWeek.setLength(4); kpiWeek.setValue(kpiWeekVal); addIndex(kpiWeek); Column kpiDay = new Column("KPI_DAY"); SimpleValue kpiDayVal = new SimpleValue(table); kpiDayVal.setTypeName(TypeFactory.basic("short").getName()); kpiDay.setLength(4); kpiDay.setValue(kpiDayVal); addIndex(kpiDay); Column kpiHour = new Column("KPI_HOUR"); SimpleValue kpiHourVal = new SimpleValue(table); kpiHourVal.setTypeName(TypeFactory.basic("short").getName()); kpiHour.setLength(4); kpiHour.setValue(kpiHourVal); addIndex(kpiHour); Column kpiMinute = new Column("KPI_MINUTE"); SimpleValue kpiMinuteVal = new SimpleValue(table); kpiMinuteVal.setTypeName(TypeFactory.basic("short").getName()); kpiMinute.setLength(4); kpiMinute.setValue(kpiMinuteVal); addIndex(kpiMinute); Column kpiDayOfWeek = new Column("KPI_DAY_OF_WEEK"); SimpleValue kpiDayOfWeekVal = new SimpleValue(table); kpiDayOfWeekVal.setTypeName(TypeFactory.basic("short").getName()); kpiDayOfWeek.setLength(4); kpiDayOfWeek.setValue(kpiDayOfWeekVal); addIndex(kpiDayOfWeek); Column serverId = new Column("SERVER_ID"); SimpleValue serverIdVal = new SimpleValue(table); serverIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); serverId.setValue(serverIdVal); serverId.setLength(200); addIndex(serverId); Column eventId = new Column("EVENT_ID"); SimpleValue eventIdVal = new SimpleValue(table); eventIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); eventId.setValue(eventIdVal); eventId.setLength(200); addIndex(eventId); Column eventName = new Column("EVENT_NAME"); SimpleValue eventNameVal = new SimpleValue(table); eventNameVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); eventName.setValue(eventNameVal); eventName.setLength(200); addIndex(eventName); Column processDefinitionId = new Column("PROCESS_DEF_ID"); SimpleValue processDefinitionIdVal = new SimpleValue(table); processDefinitionIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processDefinitionId.setValue(processDefinitionIdVal); processDefinitionId.setLength(200); addIndex(processDefinitionId); Column processDefinitionName = new Column("PROCESS_DEF_NAME"); SimpleValue processDefinitionNameVal = new SimpleValue(table); processDefinitionNameVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processDefinitionName.setValue(processDefinitionNameVal); processDefinitionName.setLength(200); addIndex(processDefinitionName); Column processDefinitionVersion = new Column("PROCESS_DEF_VERSION"); SimpleValue processDefinitionVersionVal = new SimpleValue(table); processDefinitionVersionVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processDefinitionVersion.setValue(processDefinitionVersionVal); processDefinitionVersion.setLength(200); addIndex(processDefinitionVersion); Column processInstanceId = new Column("PROCESS_INST_ID"); SimpleValue processInstanceIdVal = new SimpleValue(table); processInstanceIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processInstanceId.setValue(processInstanceIdVal); processInstanceId.setLength(200); addIndex(processInstanceId); Column activityInstanceId = new Column("ACT_INST_ID"); SimpleValue activityInstanceIdVal = new SimpleValue(table); activityInstanceIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); activityInstanceId.setValue(activityInstanceIdVal); activityInstanceId.setLength(200); addIndex(activityInstanceId); Column activityInstanceName = new Column("ACT_INST_NAME"); SimpleValue activityInstanceNameVal = new SimpleValue(table); activityInstanceNameVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); activityInstanceName.setValue(activityInstanceNameVal); activityInstanceName.setLength(200); addIndex(activityInstanceName); Column activityInstanceIter = new Column("ACT_INST_ITER"); SimpleValue activityInstanceIterVal = new SimpleValue(table); activityInstanceIterVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); activityInstanceIter.setValue(activityInstanceIterVal); activityInstanceIter.setLength(200); addIndex(activityInstanceIter); PrimaryKey key = new PrimaryKey(); key.setName(metaKpi.getCode() + "_PK"); key.addColumn(id); table.setPrimaryKey(key); table.addColumn(id); table.addColumn(kpiTimeStamp); table.addColumn(kpiYear); table.addColumn(kpiQuater); table.addColumn(kpiMonth); table.addColumn(kpiWeek); table.addColumn(kpiDay); table.addColumn(kpiDayOfWeek); table.addColumn(kpiHour); table.addColumn(kpiMinute); table.addColumn(serverId); table.addColumn(eventId); table.addColumn(eventName); table.addColumn(processDefinitionId); table.addColumn(processDefinitionVersion); table.addColumn(processDefinitionName); table.addColumn(processInstanceId); table.addColumn(activityInstanceId); table.addColumn(activityInstanceName); table.addColumn(activityInstanceIter); for (Iterator<MetaDim> i = metaKpi.getMetaDims().iterator(); i.hasNext();) { MetaDim metaDim = i.next(); Column dim = new Column(metaDim.getCode()); SimpleValue dimVal = new SimpleValue(table); dimVal.setTypeName(TypeFactory.basic(metaDim.getValueType()).getName()); dim.setValue(dimVal); if (metaDim.getValueLength() != null) { dim.setLength(metaDim.getValueLength()); } table.addColumn(dim); addIndex(dim); } for (Iterator<MetaFact> i = metaKpi.getMetaFacts().iterator(); i.hasNext();) { MetaFact metaFact = i.next(); Column dim = new Column(metaFact.getCode()); SimpleValue dimVal = new SimpleValue(table); dimVal.setTypeName(TypeFactory.basic("java.math.BigDecimal").getName()); dim.setValue(dimVal); table.addColumn(dim); } if (type == CREATE_SCRIPT) { result.add(0, table.sqlCreateString(d, config.buildMapping(), null, null)); } else if (type == DROP_SCRIPT) { result.clear(); result.add(table.sqlDropString(d, null, null)); } } catch (Exception ex) { ex.printStackTrace(); } return result; }