List of usage examples for org.hibernate.mapping Column getName
public String getName()
From source file:edu.wustl.common.util.dbManager.HibernateMetaData.java
License:BSD License
/** This function returns the role Id * from hibernate mapping and returns the value * @param attributeName/*from ww w. java 2s .c om*/ * @return roleKeyId * */ public static String getRoleKeyId(String attributeName) { org.hibernate.mapping.Collection col1 = cfg.getCollectionMapping(attributeName); Iterator colIt = col1.getElement().getColumnIterator(); while (colIt.hasNext()) { Column col = (Column) colIt.next(); return (col.getName()); } return ""; }
From source file:edu.wustl.dao.util.HibernateMetaData.java
License:BSD License
/** * This method will returns the column name associate to given property. * @param iter : holds the property object. * @param attributeName :attribute of the given class * @return returns the Column Name mapped to the attribute. *//* w w w . j a v a 2 s . c om*/ private static String getColumnName(String attributeName, Iterator<Object> iter) { String columnName = DAOConstants.TAILING_SPACES; Property property = (Property) iter.next(); if (property != null && property.getName().equals(attributeName)) { Iterator<Object> colIt = property.getColumnIterator(); if (colIt.hasNext()) { Column col = (Column) colIt.next(); columnName = col.getName(); } } return columnName; }
From source file:edu.wustl.dao.util.HibernateMetaData.java
License:BSD License
/** *This method will iterate the Identified property file and returns the column name. * @param classObj : Class of the object * @param attributeName :attribute of the given class * @return returns the Column Name mapped to the attribute. *//*from w w w. j a v a 2 s.com*/ private static String getColumName(Class classObj, String attributeName) { String columnName = DAOConstants.TAILING_SPACES; Property property = cfg.getClassMapping(classObj.getName()).getIdentifierProperty(); if (property.getName().equals(attributeName)) { Iterator<Object> colIt = property.getColumnIterator();//y("id").getColumnIterator(); if (colIt.hasNext()) { Column col = (Column) colIt.next(); columnName = col.getName(); } } return columnName; }
From source file:fr.keyconsulting.oliphant.postgresql.PostgreSQLListenerAuxiliary.java
License:Open Source License
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema) { StringBuilder sb = new StringBuilder(); for (Iterator i = config.getClassMappings(); i.hasNext();) { PersistentClass c = (PersistentClass) i.next(); Table table = c.getTable();/*from w ww .j av a 2s . c om*/ if (table.getPrimaryKey().getColumnSpan() > 1) { throw new HibernateException( "Oliphant does not support primary keys that span multiple columns. Objects of class " + c.getClassName() + " will not be monitored for changes."); } String tableName = table.getName().toLowerCase(); String idColName = table.getPrimaryKey().getColumn(0).getName(); Iterator verCols = c.getVersion().getColumnIterator(); if (!verCols.hasNext()) { throw new HibernateException( "Oliphant does not support version properties that span multiple columns. Objects of class " + c.getClassName() + " will not be monitored for changes."); } Column verCol = (Column) verCols.next(); String verColName = verCol.getName(); if (verCols.hasNext()) { throw new HibernateException("Oliphant does not support non versioned entities. Objects of class " + c.getClassName() + " will not be monitored for changes."); } sb.append("CREATE OR REPLACE FUNCTION oliphant_" + tableName + "() RETURNS TRIGGER AS $$\n"); sb.append(" DECLARE\n"); sb.append(" VERSION TEXT;\n"); sb.append(" BEGIN\n"); sb.append(" IF TG_OP = 'UPDATE' THEN\n"); sb.append(" VERSION := NEW." + verColName + ";\n"); sb.append(" ELSIF TG_OP = 'DELETE' THEN\n"); sb.append(" VERSION := -1;\n"); sb.append(" END IF;\n"); sb.append(" PERFORM send_notify('oliphant', '" + tableName + "#' || encode(text(OLD." + idColName + ")::bytea,'base64') || '###' || encode(text(VERSION)::bytea,'base64')); RETURN NULL;\n"); sb.append(" END;\n"); sb.append("$$ LANGUAGE 'plpgsql';\n"); sb.append("\n"); sb.append("CREATE TRIGGER oliphant_" + tableName + "_trg\n"); sb.append(" AFTER DELETE OR UPDATE ON " + tableName + "\n"); sb.append(" FOR EACH ROW EXECUTE PROCEDURE oliphant_" + tableName + "();\n"); sb.append("\n"); } return sb.toString(); }
From source file:it.eng.qbe.model.structure.builder.hibernate.HibernateModelStructureBuilder.java
License:Mozilla Public License
public List addNormalFields(IModelEntity dataMartEntity) { ClassMetadata classMetadata;//from w ww.ja va 2s .c o m PersistentClass classMapping; String[] propertyNames; Property property; Type propertyType; classMetadata = getDataSource().getHibernateSessionFactory().getClassMetadata(dataMartEntity.getType()); classMapping = getDataSource().getHibernateConfiguration().getClassMapping(dataMartEntity.getType()); propertyNames = classMetadata.getPropertyNames(); List subEntities = new ArrayList(); String propertyName = null; for (int i = 0; i < propertyNames.length; i++) { property = classMapping.getProperty(propertyNames[i]); // TEST if they are the same: if so use the first invocation propertyType = property.getType(); Iterator columnIterator = property.getColumnIterator(); Column column; if (propertyType instanceof ManyToOneType) { // chiave esterna ManyToOneType manyToOnePropertyType = (ManyToOneType) propertyType; String entityType = manyToOnePropertyType.getAssociatedEntityName(); String columnName = null; if (columnIterator.hasNext()) { column = (Column) columnIterator.next(); columnName = column.getName(); // ???? } propertyName = propertyNames[i]; //String entityName = getEntityNameFromEntityType(entityType); String entityName = propertyName; IModelEntity subentity = new ModelEntity(entityName, null, columnName, entityType, dataMartEntity.getStructure()); subEntities.add(subentity); } else if (propertyType instanceof CollectionType) { // chiave interna } else { // normal field propertyName = propertyNames[i]; String type = propertyType.getName(); int scale = 0; int precision = 0; if (columnIterator.hasNext()) { column = (Column) columnIterator.next(); scale = column.getScale(); precision = column.getPrecision(); } IModelField datamartField = dataMartEntity.addNormalField(propertyName); datamartField.setType(type); datamartField.setPrecision(precision); datamartField.setLength(scale); propertiesInitializer.addProperties(datamartField); } } return subEntities; }
From source file:net.chrisrichardson.ormunit.hibernate.HibernateAssertUtil.java
License:Apache License
public static void assertColumn(String idColumn, Value identifier) { Iterator columnIt = identifier.getColumnIterator(); Assert.assertTrue(columnIt.hasNext()); Column column = (Column) columnIt.next(); Assert.assertFalse(columnIt.hasNext()); if (!idColumn.equalsIgnoreCase(column.getName())) Assert.assertEquals(idColumn, column.getName()); }
From source file:net.lshift.hibernate.migrations.CreateTableBuilder.java
License:Apache License
private String createTableSql() { StringBuffer buffer = new StringBuffer(dialect.getCreateTableString()).append(' ') .append(dialect.quote(name)).append(" ("); for (Column col : columns) { int indexOfPrimaryKey = primaryKeys.indexOf(col.getName()); if (indexOfPrimaryKey == 0 && useNativeIdentityGenerator && dialect.supportsIdentityColumns()) { // only apply native identity generator to first column of primary key buffer.append(generateIdentityColumnString(dialect, col)); } else if (indexOfPrimaryKey >= 0) { buffer.append(generateNonIdentityColumnString(dialect, col)); } else {//from w w w . j av a2 s . co m buffer.append(generateColumnString(dialect, col, true)); } buffer.append(", "); } buffer.append(getPrimaryKey().sqlConstraintString(dialect)); buffer.append(")").append(dialect.getTableTypeString()); partitionHelper.appendPartitionString(buffer); return buffer.toString(); }
From source file:net.lshift.hibernate.migrations.CreateTableBuilder.java
License:Apache License
private void createSequences(Connection conn) throws SQLException { for (Column col : columns) { if (primaryKeys.contains(col.getName())) { for (String sql : dialect.getCreateSequenceStrings(dialect.quote(name + "_sequence"))) { prepareAndLogAndExecute(conn, sql); return; }//w ww . j a v a 2s . c o m } } }
From source file:net.lshift.hibernate.migrations.TransplantTableBuilder.java
License:Apache License
@Override public void apply(Connection conn) throws SQLException { // Create the temporary table tempTable.apply(conn);/*from w ww . jav a 2s . com*/ // Copy the data from the old table to the temporary table List<String> sourceCols = new ArrayList<String>(); List<String> destCols = new ArrayList<String>(); for (Column column : tempTable.getColumns()) { String name = column.getName(); destCols.add(name); if (renames != null && renames.containsKey(name)) { sourceCols.add(renames.get(name)); } else { sourceCols.add(name); } } CopyTableBuilder copyTableBuilder = new CopyTableBuilder(source, tempTable.getTableName(), sourceCols, destCols); copyTableBuilder.apply(conn); // Delete the source table DropTableBuilder dropTableBuilder = new DropTableBuilder(configuration, dialect, source); dropTableBuilder.apply(conn); // Rename the destination table to the source table's original name AlterTableBuilder alterTableBuilder = new AlterTableBuilder(configuration, dialect, dialectExtension, tempTable.getTableName()); alterTableBuilder.renameTo(source); alterTableBuilder.apply(conn); }
From source file:org.beangle.commons.orm.hibernate.internal.SchemaValidator.java
License:Open Source License
private void validateColumns(Table table, Dialect dialect, Mapping mapping, TableMetadata tableInfo) { Iterator<?> iter = table.getColumnIterator(); Set<ColumnMetadata> processed = CollectUtils.newHashSet(); String tableName = Table.qualify(tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()); while (iter.hasNext()) { Column col = (Column) iter.next(); ColumnMetadata columnInfo = tableInfo.getColumnMetadata(col.getName()); if (columnInfo == null) { reporter.append("Missing column: " + col.getName() + " in " + tableName); } else {/*from w w w . j a va 2 s . co m*/ final boolean typesMatch = col.getSqlType(dialect, mapping).toLowerCase() .startsWith(columnInfo.getTypeName().toLowerCase()) || columnInfo.getTypeCode() == col.getSqlTypeCode(mapping); if (!typesMatch) { reporter.append("Wrong column type in " + tableName + " for column " + col.getName() + ". Found: " + columnInfo.getTypeName().toLowerCase() + ", expected: " + col.getSqlType(dialect, mapping)); } processed.add(columnInfo); } } // try { Field field = tableInfo.getClass().getField("columns"); @SuppressWarnings("unchecked") Set<ColumnMetadata> allColumns = CollectUtils .newHashSet(((Map<String, ColumnMetadata>) field.get(tableInfo)).values()); allColumns.removeAll(processed); if (!allColumns.isEmpty()) { for (ColumnMetadata col : allColumns) { reporter.append("Extra column " + col.getName() + " in " + tableName); } } } catch (Exception e) { e.printStackTrace(); } }