List of usage examples for org.hibernate.mapping Table getName
public String getName()
From source file:com.tomitribe.reveng.codegen.FreemarkerObject.java
License:Apache License
public String annotate(final BasicPOJOClass pojo, final Object pObj, final Object rootObj, final Object toolObj) { // public String annotate(final Object pojo, final Property p, final // RootClass root, final Cfg2HbmTool tool) { if (BasicPOJOClass.class.isInstance(pojo)) { } else {/*www .java 2s. com*/ // System.out.println(ob.class.getName()); } RootClass root = null; try { root = (RootClass) rootObj; } catch (final Exception e) { // TODO Auto-generated catch block // e.printStackTrace(); return ""; } final Property p = (Property) pObj; final Cfg2HbmTool tool = (Cfg2HbmTool) toolObj; final Table table = root.getTable(); Iterator it = table.getColumnIterator(); Column column = null; Column c; String name; while (it.hasNext()) { c = (Column) it.next(); name = c.getName().replace("_", "").toLowerCase(); if (name.equals(p.getName().toLowerCase())) { column = c; break; } } if (null != column) { System.out.print("FreemarkerObject.annotate: " + table.getName() + " - " + p.getName() + " - "); it = table.getIndexIterator(); org.hibernate.mapping.Index index; while (it.hasNext()) { final Object next = it.next(); if (org.hibernate.mapping.Index.class.isInstance(next)) { index = org.hibernate.mapping.Index.class.cast(next); if (index.containsColumn(column)) { System.out.print(index.getName()); return String.format("\n@Index(name = \"%1$s\", columnNames = {\"%2$s\"})", index.getName().toLowerCase(), column.getName()); } } } System.out.println(); } else { System.out.println("FreemarkerObject.annotate: " + table.getName() + " - " + p.getName() + " - " + p.getNodeName() + " - " + p.getPropertyAccessorName()); } return ""; }
From source file:com.vecna.dbDiff.hibernate.HibernateMappingsConverter.java
License:Apache License
/** * Extract the name of the table as it would appear in the database. * @param table hibernate table model./*from w w w.j av a 2 s.c o m*/ * @return the name of the table as it would appear in the database. */ private String getTableName(org.hibernate.mapping.Table table) { return m_dbSpecificMappingInfo.getTruncateInfo().truncateTableName(table.getName().toLowerCase()); }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Retrieve the list of table that store collections of the provided persisted class, and that need to be manually * updated, since no cascaded update has been added for them. * * @param pClass the persisted class to analyse * @return a list of dual string, the first is the table name, and the second is the key in that table. *///from w w w . ja v a 2 s .c o m private List<String[]> getCollectionProperties(PersistentClass pClass) { List<String[]> list = new ArrayList<String[]>(); if (pClass != null) { for (org.hibernate.mapping.Collection coll : getCollection(pClass)) { Table collTable = coll.getCollectionTable(); if (!this.fkTables.contains(collTable)) { list.add(new String[] { collTable.getName(), getKeyColumnName(coll) }); } } } return list; }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Retrieve the list of table that store collections of the provided persisted class. * * @param pClass the persisted class to analyse * @param all if false, return only collection that need manual updates, * see {@link #getCollectionProperties(PersistentClass pClass)} * @return a list of dual string, the first is the table name, and the second is the key in that table. *///from ww w. j a v a 2s .c o m private List<String[]> getCollectionProperties(PersistentClass pClass, boolean all) { List<String[]> list = new ArrayList<String[]>(); if (pClass != null) { for (org.hibernate.mapping.Collection coll : getCollection(pClass)) { Table collTable = coll.getCollectionTable(); if (all || !this.fkTables.contains(collTable)) { list.add(new String[] { collTable.getName(), getKeyColumnName(coll) }); } } } return list; }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Append a drop primary key constraint command for the given table. * * @param sb append the result into this string builder * @param table the table/* w w w. ja v a 2 s . c o m*/ */ private void appendDropPrimaryKey(StringBuilder sb, Table table) { final String tableName = table.getName(); String pkName = table.getPrimaryKey().getName(); // MS-SQL require a constraints name, and the one provided from the mapping is necessarily appropriate // since during database creation, that name has not been used, and a name has been assigned by the // database itself. We need to retrieve that name from the schema. if (this.isMSSQL) { try { pkName = getStore().failSafeExecuteRead(getXWikiContext(), new HibernateCallback<String>() { @Override public String doInHibernate(Session session) throws HibernateException { // Retrieve the constraint name from the database return (String) session .createSQLQuery("SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS" + " WHERE TABLE_NAME = :tableName AND CONSTRAINT_TYPE = 'PRIMARY KEY'") .setString("tableName", tableName).uniqueResult(); } }); } catch (Exception e) { // ignored since it is really unlikely to happen logger.debug("Fail retrieving the primary key constraints name", e); } } sb.append(" <dropPrimaryKey tableName=\"").append(tableName); if (pkName != null) { sb.append("\" constraintName=\"").append(pkName); } sb.append("\"/>\n"); }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Append a add primary key constraint command for the given table. * * @param sb append the result into this string builder * @param table the table name/*from w ww .java 2s. c o m*/ */ private void appendAddPrimaryKey(StringBuilder sb, Table table) { PrimaryKey pk = table.getPrimaryKey(); String pkName = pk.getName(); sb.append(" <addPrimaryKey tableName=\"").append(table.getName()).append("\" columnNames=\""); @SuppressWarnings("unchecked") Iterator<Column> columns = pk.getColumnIterator(); while (columns.hasNext()) { Column column = columns.next(); sb.append(column.getName()); if (columns.hasNext()) { sb.append(","); } } if (pkName != null) { sb.append("\" constraintName=\"").append(pkName); } sb.append("\"/>\n"); }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Create liquibase change log to modify the column type to BIGINT. * If the database is MSSQL, drop PK constraints and indexes during operation. * //from ww w . j a va 2 s.c om * @param sb append the result into this string builder * @param table the table name * @param column the column name */ private void appendDataTypeChangeLog(StringBuilder sb, Table table, String column) { String tableName = table.getName(); sb.append(" <changeSet id=\"R").append(this.getVersion().getVersion()).append('-') .append(Util.getHash(String.format("modifyDataType-%s-%s", table, column))) .append("\" author=\"xwiki\">\n").append(" <comment>Upgrade identifier [").append(column) .append("] from table [").append(tableName).append("] to BIGINT type</comment >\n"); // MS-SQL require that primary key constraints and all indexes related to the changed column be dropped before // changing the column type. if (this.isMSSQL) { if (table.hasPrimaryKey()) { appendDropPrimaryKey(sb, table); } // We drop all index related to the table, this is overkill, but does not hurt for (@SuppressWarnings("unchecked") Iterator<Index> it = table.getIndexIterator(); it.hasNext();) { Index index = it.next(); appendDropIndex(sb, index); } } appendModifyColumn(sb, tableName, column); // Add back dropped PK constraints and indexes for MS-SQL if (this.isMSSQL) { if (table.hasPrimaryKey()) { appendAddPrimaryKey(sb, table); } for (@SuppressWarnings("unchecked") Iterator<Index> it = table.getIndexIterator(); it.hasNext();) { Index index = it.next(); appendAddIndex(sb, index); } } sb.append(" </changeSet>\n"); this.logCount++; }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Append commands to drop all foreign keys of a given table. * * @param sb the string builder to append to * @param table the table to process//from w w w . j a v a 2 s . c o m */ @SuppressWarnings("unchecked") private void appendDropForeignKeyChangeLog(StringBuilder sb, Table table) { Iterator<ForeignKey> fki = table.getForeignKeyIterator(); // Preamble String tableName = table.getName(); sb.append(" <changeSet id=\"R").append(this.getVersion().getVersion()).append('-') .append(Util.getHash(String.format("dropForeignKeyConstraint-%s", tableName))) .append("\" author=\"xwiki\" runOnChange=\"true\" runAlways=\"true\" failOnError=\"false\">\n") .append(" <comment>Drop foreign keys on table [").append(tableName).append("]</comment>\n"); // Concrete Property types should each have a foreign key referencing the BaseProperty // Other classes don't have any foreign keys at all, in which case the fast exit path above was used while (fki.hasNext()) { ForeignKey fk = fki.next(); // Drop the old constraint if (fk.isReferenceToPrimaryKey()) { sb.append(" <dropForeignKeyConstraint baseTableName=\"").append(tableName) .append("\" constraintName=\"").append(fk.getName()).append("\" />\n"); } } // All done! sb.append(" </changeSet>\n"); this.logCount++; }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Append change log to add foreign keys with CASCADEd updates. * * @param sb the string builder to append to the add tasks * @param table the table to process//from w w w . j a v a 2s. co m */ @SuppressWarnings("unchecked") private void appendAddForeignKeyChangeLog(StringBuilder sb, Table table) { Iterator<ForeignKey> fki = table.getForeignKeyIterator(); // Preamble String tableName = table.getName(); sb.append(" <changeSet id=\"R").append(this.getVersion().getVersion()).append('-') .append(Util.getHash(String.format("addForeignKeyConstraint-%s", tableName))) .append("\" author=\"xwiki\" runOnChange=\"true\" runAlways=\"true\">\n") .append(" <comment>Add foreign keys on table [").append(tableName) .append("] to use ON UPDATE CASCADE</comment>\n"); // Concrete Property types should each have a foreign key referencing the BaseProperty // Other classes don't have any foreign keys at all, in which case the fast exit path above was used while (fki.hasNext()) { ForeignKey fk = fki.next(); if (fk.isReferenceToPrimaryKey()) { // Recreate the constraint sb.append(" <addForeignKeyConstraint constraintName=\"").append(fk.getName()) .append("\" baseTableName=\"").append(tableName).append("\" baseColumnNames=\""); // Reuse the data from the old foreign key // Columns in the current table Iterator<Column> columns = fk.getColumnIterator(); while (columns.hasNext()) { Column column = columns.next(); sb.append(column.getName()); if (columns.hasNext()) { sb.append(","); } } sb.append("\" referencedTableName=\"").append(fk.getReferencedTable().getName()) .append("\" referencedColumnNames=\""); // Columns in the referenced table columns = fk.getReferencedTable().getPrimaryKey().getColumnIterator(); while (columns.hasNext()) { Column column = columns.next(); sb.append(column.getName()); if (columns.hasNext()) { sb.append(","); } } // The important part: cascaded updates if (this.isOracle) { // Oracle doesn't support cascaded updates, but allow the constraint to be checked // at the commit level (normal checking is done at the statement level). sb.append("\" initiallyDeferred=\"true\"/>\n"); } else { sb.append("\" onUpdate=\"CASCADE\"/>\n"); } } } // All done! sb.append(" </changeSet>\n"); this.logCount++; }
From source file:com.zutubi.pulse.master.hibernate.MutableConfiguration.java
License:Apache License
private String getTableKey(Table table) { return table.getSubselect() == null ? Table.qualify(table.getCatalog(), table.getSchema(), table.getName()) : table.getSubselect();//w w w . j av a 2 s . c o m }