List of usage examples for org.hibernate.mapping Table getName
public String getName()
From source file:org.n52.sos.ds.datasource.AbstractMySQLDatasource.java
License:Open Source License
@Override public void clear(Properties properties) { Map<String, Object> settings = parseDatasourceProperties(properties); CustomConfiguration config = getConfig(settings); Iterator<Table> tables = config.getTableMappings(); List<String> names = new LinkedList<String>(); while (tables.hasNext()) { Table table = tables.next(); if (table.isPhysicalTable()) { names.add(table.getName()); }/* www .j a v a2s . co m*/ } if (!names.isEmpty()) { Connection conn = null; Statement stmt = null; try { conn = openConnection(settings); stmt = conn.createStatement(); stmt.execute(String.format("truncate %s restart identity cascade", Joiner.on(", ").join(names))); } catch (SQLException ex) { throw new ConfigurationException(ex); } finally { close(stmt); close(conn); } } }
From source file:org.n52.sos.ds.datasource.AbstractOracleDatasource.java
License:Open Source License
@Override public void clear(Properties properties) { Map<String, Object> settings = parseDatasourceProperties(properties); CustomConfiguration config = getConfig(settings); Connection conn = null;//from ww w. j av a2 s .c o m Statement stmt = null; try { conn = openConnection(settings); stmt = conn.createStatement(); Iterator<Table> tables = config.getTableMappings(); List<String> names = new ArrayList<String>(); while (tables.hasNext()) { Table table = tables.next(); if (table.isPhysicalTable()) { names.add(table.getName()); } } while (names.size() > 0) { int clearedThisPass = 0; for (int i = names.size() - 1; i >= 0; i--) { try { stmt.execute("DELETE FROM " + names.get(i)); names.remove(i); clearedThisPass++; } catch (SQLException ex) { // ignore } } if (clearedThisPass == 0) { throw new RuntimeException("Cannot clear!"); } } conn.commit(); } catch (SQLException e) { throw new RuntimeException("Cannot clear!", e); } finally { close(stmt); close(conn); } }
From source file:org.n52.sos.ds.datasource.AbstractSqlServerDatasource.java
License:Open Source License
@Override public void clear(Properties properties) { Map<String, Object> settings = parseDatasourceProperties(properties); CustomConfiguration config = getConfig(settings); Iterator<Table> tables = config.getTableMappings(); List<String> names = new LinkedList<String>(); while (tables.hasNext()) { Table table = tables.next(); if (table.isPhysicalTable()) { names.add(table.getName()); }// w w w. j ava2s . c o m } if (!names.isEmpty()) { Connection conn = null; Statement stmt = null; try { conn = openConnection(settings); stmt = conn.createStatement(); StringBuffer statement = new StringBuffer(); // alter table MyOtherTable nocheck constraint all for (String table : names) { statement = statement.append("ALTER TABLE \"").append(table) .append("\" NOCHECK CONSTRAINT ALL;"); } // delete from MyTable for (String table : names) { statement = statement.append("DELETE from \"").append(table).append("\"; DBCC CHECKIDENT(\"") .append(table).append("\", RESEED, 0);"); } // alter table MyOtherTable check constraint all for (String table : names) { statement = statement.append("ALTER TABLE \"").append(table).append("\" CHECK CONSTRAINT ALL;"); } statement = statement.append("DBCC SHRINKDATABASE (").append(settings.get(DATABASE_KEY).toString()) .append(");"); stmt.execute(statement.toString()); } catch (SQLException ex) { throw new ConfigurationException(ex); } finally { close(stmt); close(conn); } } }
From source file:org.n52.sos.ds.datasource.CustomConfiguration.java
License:Open Source License
protected List<String> generateConstraintDropScript(final Dialect d, final String c, final String s, final DatabaseMetadata m) throws HibernateException { final List<String> script = new LinkedList<String>(); final Iterator<Table> itr = getTableMappings(); while (itr.hasNext()) { final Table table = itr.next(); // TODO remove because fails if table definition is quoted // final String tableName = table.getQualifiedName(d, c, s); if (checkTable(table, m)) { @SuppressWarnings("unchecked") final Iterator<ForeignKey> subItr = table.getForeignKeyIterator(); final TableMetadata tableMeta = m.getTableMetadata(table.getName(), s, c, table.isQuoted()); while (subItr.hasNext()) { final ForeignKey fk = subItr.next(); if (fk.isPhysicalConstraint() && tableMeta.getForeignKeyMetadata(fk) != null) { script.add(fk.sqlDropString(d, c, s)); }//from w ww .j av a 2s .c om } } } return script; }
From source file:org.n52.sos.ds.datasource.PostgresDatasource.java
License:Open Source License
@Override public void clear(Properties properties) { Map<String, Object> settings = parseDatasourceProperties(properties); CustomConfiguration config = getConfig(settings); Iterator<Table> tables = config.getTableMappings(); List<String> names = new LinkedList<String>(); while (tables.hasNext()) { Table table = tables.next(); if (table.isPhysicalTable()) { names.add(table.getName()); }// w w w .j ava 2 s. c om } if (!names.isEmpty()) { Connection conn = null; Statement stmt = null; try { conn = openConnection(settings); stmt = conn.createStatement(); stmt.execute(String.format("truncate %s restart identity cascade", StringHelper.join(", ", names))); } catch (SQLException ex) { throw new ConfigurationException(ex); } finally { close(stmt); close(conn); } } }
From source file:org.sns.tool.hibernate.struct.impl.DefaultTableStructure.java
License:Open Source License
public TableStructureNode getNodeForTable(Table table) { return (TableStructureNode) tableNodes.get(table.getName().toUpperCase()); }
From source file:org.sns.tool.hibernate.struct.impl.DefaultTableStructure.java
License:Open Source License
public TableStructureNode createNode(final PersistentClass mappedClass, final Table nodeForTable, final TableStructureNode parent, final int level) { final TableStructureNode existing = getNodeForTable(nodeForTable); if (existing == null) { final DefaultTableStructureNode newNode = new DefaultTableStructureNode(mappedClass, nodeForTable, this, parent, level);//ww w. ja v a 2 s. c o m tableNodes.put(nodeForTable.getName().toUpperCase(), newNode); newNode.resolveDependencies(); return newNode; } else return new LinkToOtherTableStructureNode(existing, parent, level); }
From source file:org.squashtest.tm.infrastructure.hibernate.TestStepPersister.java
License:Open Source License
private void createTableNamePattern(PersistentClass persistentClass, SessionFactoryImplementor factory) { Iterator joinIter = persistentClass.getJoinClosureIterator(); while (joinIter.hasNext()) { Table tab = ((Join) joinIter.next()).getTable(); if (tab.getName().equalsIgnoreCase(NONFORMATTED_TABLE_NAME)) { formattedTableName = tab.getQualifiedName(factory.getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName()); return; }/*w w w . j a va2 s. c o m*/ } throw new IllegalArgumentException( "TestStepPersister : could not find the join table " + NONFORMATTED_TABLE_NAME); }