List of usage examples for org.hibernate.mapping Column getName
public String 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) {// ww w .jav a 2 s . 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(); 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
/** * Binds a Column instance to the Hibernate meta model * * @param property The Grails domain class property * @param parentProperty/* w w w .j a va2 s . c om*/ * @param column The column to bind * @param path * @param table The table name * @param sessionFactoryBeanName the session factory bean name */ protected void bindColumn(PersistentProperty property, PersistentProperty parentProperty, Column column, ColumnConfig cc, String path, Table table, String sessionFactoryBeanName) { if (cc != null) { column.setComment(cc.getComment()); column.setDefaultValue(cc.getDefaultValue()); column.setCustomRead(cc.getRead()); column.setCustomWrite(cc.getWrite()); } Class<?> userType = getUserType(property); String columnName = getColumnNameForPropertyAndPath(property, path, cc, sessionFactoryBeanName); if ((property instanceof Association) && userType == null) { Association association = (Association) property; // Only use conventional naming when the column has not been explicitly mapped. if (column.getName() == null) { column.setName(columnName); } if (property instanceof ManyToMany) { column.setNullable(false); } else if (property instanceof org.grails.datastore.mapping.model.types.OneToOne && association.isBidirectional() && !association.isOwningSide()) { if (isHasOne(((Association) property).getInverseSide())) { column.setNullable(false); } else { column.setNullable(true); } } else if ((property instanceof ToOne) && association.isCircular()) { column.setNullable(true); } else { column.setNullable(property.isNullable()); } } else { column.setName(columnName); column.setNullable(property.isNullable() || (parentProperty != null && parentProperty.isNullable())); // Use the constraints for this property to more accurately define // the column's length, precision, and scale if (String.class.isAssignableFrom(property.getType()) || byte[].class.isAssignableFrom(property.getType())) { bindStringColumnConstraints(column, property); } if (Number.class.isAssignableFrom(property.getType())) { bindNumericColumnConstraints(column, property, cc); } } handleUniqueConstraint(property, column, path, table, columnName, sessionFactoryBeanName); bindIndex(columnName, column, cc, table); final PersistentEntity owner = property.getOwner(); if (!owner.isRoot()) { 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()); } } if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] bound property [" + property.getName() + "] to column name [" + column.getName() + "] in table [" + table.getName() + "]"); }
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 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(); 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.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape.java
License:Open Source License
public Shape getChild(Column ormElement) { if (ormElement == null) { return null; }/*from w w w. ja va2s .c om*/ Iterator<Shape> it = getChildrenIterator(); while (it.hasNext()) { final Shape child = it.next(); Object childElement = child.getOrmElement(); if (childElement instanceof Column && ormElement.getName().equals(((Column) childElement).getName())) { return child; } } return null; }
From source file:org.jooq.meta.extensions.jpa.AttributeConverterExtractor.java
License:Apache License
@SuppressWarnings("unchecked") final Map<Name, AttributeConverter<?, ?>> extract() { Map<Name, AttributeConverter<?, ?>> result = new LinkedHashMap<>(); initEntityManagerFactory();/* ww w.j a va 2s . c o m*/ for (PersistentClass persistentClass : meta.getEntityBindings()) { Table table = persistentClass.getTable(); Iterator<Property> propertyIterator = persistentClass.getPropertyIterator(); propertyLoop: while (propertyIterator.hasNext()) { Property property = propertyIterator.next(); Type type = property.getValue().getType(); if (type instanceof AttributeConverterTypeAdapter) { AttributeConverter<?, ?> converter = ((AttributeConverterTypeAdapter<?>) type) .getAttributeConverter().getConverterBean().getBeanInstance(); Iterator<Column> columnIterator = property.getColumnIterator(); if (columnIterator.hasNext()) { Column column = columnIterator.next(); if (columnIterator.hasNext()) { log.info("AttributeConverter", "Cannot apply AttributeConverter of property " + property + " on several columns."); continue propertyLoop; } result.put(name(table.getCatalog(), table.getSchema(), table.getName(), column.getName()), converter); } } } } return result; }
From source file:org.ow2.bonita.util.DbTool.java
License:Open Source License
@SuppressWarnings("unchecked") public static void updateDatabaseSchema(Configuration configuration) { if (isOnDb("mysql", configuration)) { LOG.severe("Running on MySQL database, updating schema..."); final PersistentClass pc = configuration.getClassMapping(Lob.class.getName()); final Table table = pc.getTable(); final Iterator<Column> columns = (Iterator<Column>) table.getColumnIterator(); while (columns.hasNext()) { final Column column = columns.next(); final String columnName = "BLOB_VALUE_"; if (column.getName().equals(columnName)) { LOG.severe("Updating " + columnName + " column..."); column.setSqlType("LONGBLOB"); column.setLength(518576); }/*from w w w . j av a 2s.c o m*/ } } else if (DbTool.isOnDb("oracle", configuration)) { LOG.severe("Running on Oracle database, updating schema..."); final Iterator<Table> tables = (Iterator<Table>) configuration.getTableMappings(); while (tables.hasNext()) { final Table table = tables.next(); final Iterator<Column> columns = (Iterator<Column>) table.getColumnIterator(); while (columns.hasNext()) { final Column column = columns.next(); final Value value = column.getValue(); // Prevent ORA-01754: a table may contain only one column of type LONG if (value.getType() instanceof TextType) { column.setSqlType("CLOB"); } } } } /*else if (isOnDb("sybase", config)) { LOG.severe("Running on Sybase DB, updating schema..."); //iterate over all tables and all columns to replace type=text final Iterator<Table> tables = (Iterator<Table>) config.getTableMappings(); while (tables.hasNext()) { final Table table = tables.next(); final Iterator<Column> columns = table.getColumnIterator(); while (columns.hasNext()) { final Column column = columns.next(); System.err.println("Column.name=" + column.getName() + ", column=" + column.getDefaultValue()); if (!column.getName().equals("BLOB_VALUE_") && column.getSqlType() != null && column.getSqlType().equals("CLOB")) { LOG.severe("Updating " + column.getName() + " column..."); column.setSqlType("LONGVARCHAR"); } } } } */ }
From source file:org.processbase.engine.bam.db.ScriptGenerator.java
License:Open Source License
private void addIndex(Column column) { try {// w w w. ja v a2 s .co m Dialect dialect = (Dialect) Class.forName(BAMConstants.BAM_DB_DIALECT).newInstance(); dimColumns.add(column); result.add(Index.buildSqlCreateIndexString(dialect, table.getName() + "_IDX_" + column.getName(), table, dimColumns.iterator(), false, null, null)); dimColumns.clear(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.squale.jraf.provider.persistence.hibernate.MetaDataImpl.java
License:Open Source License
/** * Retourne la colonne columnName de la table table * @param table Table sur laquelle il faut chercher * @param columnName Nm de la colonne a chercher * @return La colonne ColumnName de la table table *//* w w w.j av a2 s. c o m*/ public Column getColumn(Table table, String columnName) { Column column = null; Iterator iter = table.getColumnIterator(); while (iter.hasNext()) { column = (Column) iter.next(); if (column.getName().equals(columnName)) { return column; } } return null; }
From source file:org.zht.framework.zhtdao.hibernate.HibernateConfigurationUtil.java
License:Apache License
/** * ?? /*from w w w . j a v a 2 s .co m*/ * * @param clazz * Class * @param propertyName * ?? * @return ?? */ public static <T> String getColumnName(Class<T> clazz, String propertyName) { String columnName = ""; PersistentClass persistentClass = getPersistentClass(clazz); Property property = persistentClass.getProperty(propertyName); Iterator<?> iterator = property.getColumnIterator(); if (iterator.hasNext()) { Column column = (Column) iterator.next(); columnName += column.getName(); } return columnName; }