public Iterator getTableMappings() { return cfg.getTableMappings(); }
public Set getJbpmTables() { Set jbpmTables = new HashSet(); for (Iterator i = configuration.getTableMappings(); i.hasNext();) { Table table = (Table) i.next(); if (table.isPhysicalTable()) { jbpmTables.add(table.getName()); } } return jbpmTables; }
/** * Convert Hibernate mappings to DbDiff RelationalDatabase * @return a RelationalDatabase representation of the hibernate mappings */ public RelationalDatabase convert() { List<RelationalTable> tables = new ArrayList<>(); Iterator<org.hibernate.mapping.Table> mappedTables = m_configuration.getTableMappings(); while (mappedTables.hasNext()) { tables.add(convertTable(mappedTables.next())); } return new RelationalDatabase(tables); }
private Table findTableMapping(String tableName) { for (Iterator i = configuration.getTableMappings(); i.hasNext();) { Table table = (Table) i.next(); if (tableName.equals(table.getName())) return table; } throw new JbpmException("no mapping found for table: " + tableName); }
Iterator iter = getTableMappings(); while ( iter.hasNext() ) { Table table = (Table) iter.next(); Iterator iter = getTableMappings(); while ( iter.hasNext() ) {
Iterator<Table> iter = cfg.getTableMappings(); while (iter.hasNext()) dropSQL.add("DROP TABLE " + iter.next().getName());
iter = getTableMappings(); Set done = new HashSet(); while ( iter.hasNext() ) secondPassCompileForeignKeys( ( Table ) iter.next(), done );
Iterator iter = getTableMappings(); while ( iter.hasNext() ) { Table table = ( Table ) iter.next(); Iterator iter = getTableMappings(); while ( iter.hasNext() ) {
itr = getTableMappings(); Set<ForeignKey> done = new HashSet<ForeignKey>(); while ( itr.hasNext() ) {
itr = getTableMappings(); Set<ForeignKey> done = new HashSet<ForeignKey>(); while ( itr.hasNext() ) {
public static void truncateTables(final DBConfig dbConfig) { System.out.println("TRUNCATE TABLES"); Configuration cfg = HibernateConnect.getConfiguration(dbConfig); SessionFactory sf = cfg.buildSessionFactory( new ServiceRegistryBuilder().applySettings( cfg.getProperties()).buildServiceRegistry()); Session session = sf.openSession(); try { session.createSQLQuery("SET FOREIGN_KEY_CHECKS=0").executeUpdate(); Iterator<Table> iter = cfg.getTableMappings(); while (iter.hasNext()) session.createSQLQuery("TRUNCATE TABLE " + iter.next().getName()).executeUpdate(); } finally { session.createSQLQuery("SET FOREIGN_KEY_CHECKS=1").executeUpdate(); session.disconnect(); session.close(); } }
public String validateSchema(Configuration config, Dialect dialect, DatabaseMetadata databaseMetadata) { String defaultCatalog = sessionFactoryBean.getHibernateProperties().getProperty( Environment.DEFAULT_CATALOG); String defaultSchema = sessionFactoryBean.getHibernateProperties() .getProperty(Environment.DEFAULT_SCHEMA); Mapping mapping = config.buildMapping(); Iterator<?> iter = config.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { TableMetadata tableInfo = databaseMetadata.getTableMetadata(table.getName(), (table.getSchema() == null) ? defaultSchema : table.getSchema(), (table.getCatalog() == null) ? defaultCatalog : table.getCatalog(), table.isQuoted()); if (tableInfo == null) { reporter.append("Missing table: " + table.getName() + "\n"); } else { validateColumns(table, dialect, mapping, tableInfo); } } } iter = iterateGenerators(config, dialect); while (iter.hasNext()) { PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next(); Object key = generator.generatorKey(); if (!databaseMetadata.isSequence(key) && !databaseMetadata.isTable(key)) { throw new HibernateException( "Missing sequence or table: " + key); } } return null; }
+ "initialized.table")); } else { for (final Iterator iter = configuration.getTableMappings(); iter.hasNext();) { Table t = (Table) iter.next(); if (t.isPhysicalTable()) {
public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata)throws HibernateException { secondPassCompile(); String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG ); String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA ); Iterator iter = getTableMappings(); while ( iter.hasNext() ) { Table table = (Table) iter.next(); if ( table.isPhysicalTable() ) { TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), ( table.getSchema() == null ) ? defaultSchema : table.getSchema(), ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog(), table.isQuoted()); if ( tableInfo == null ) { throw new HibernateException( "Missing table: " + table.getName() ); } else { table.validateColumns( dialect, mapping, tableInfo ); } } } iter = iterateGenerators( dialect ); while ( iter.hasNext() ) { PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next(); Object key = generator.generatorKey(); if ( !databaseMetadata.isSequence( key ) && !databaseMetadata.isTable( key ) ) { throw new HibernateException( "Missing sequence or table: " + key ); } } }
public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata)throws HibernateException { secondPassCompile(); String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG ); String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA ); Iterator iter = getTableMappings(); while ( iter.hasNext() ) { Table table = (Table) iter.next(); if ( table.isPhysicalTable() ) { TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.getName(), ( table.getSchema() == null ) ? defaultSchema : table.getSchema(), ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog(), table.isQuoted()); if ( tableInfo == null ) { throw new HibernateException( "Missing table: " + table.getName() ); } else { table.validateColumns( dialect, mapping, tableInfo ); } } } iter = iterateGenerators( dialect ); while ( iter.hasNext() ) { PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next(); Object key = generator.generatorKey(); if ( !databaseMetadata.isSequence( key ) && !databaseMetadata.isTable( key ) ) { throw new HibernateException( "Missing sequence or table: " + key ); } } }
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping()));
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity; boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity; boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(Table.class)) { return; } if (foundObject instanceof Schema) { Schema schema = (Schema) foundObject; HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase(); Configuration cfg = database.getConfiguration(); Iterator<org.hibernate.mapping.Table> tableMappings = cfg.getTableMappings(); while (tableMappings.hasNext()) { org.hibernate.mapping.Table hibernateTable = tableMappings.next(); if (hibernateTable.isPhysicalTable()) { Table table = new Table().setName(hibernateTable.getName()); table.setSchema(schema); LOG.info("Found table " + table.getName()); schema.addDatabaseObject(table); } } } } }
dschema = config.getProperty(Environment.DEFAULT_SCHEMA); config.setProperty(Environment.DEFAULT_SCHEMA, contextSchema); Iterator iter = config.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next();