Example usage for org.hibernate.mapping Table isPhysicalTable

List of usage examples for org.hibernate.mapping Table isPhysicalTable

Introduction

In this page you can find the example usage for org.hibernate.mapping Table isPhysicalTable.

Prototype

public boolean isPhysicalTable() 

Source Link

Usage

From source file:corner.migration.services.impl.fragment.CreateTableFragment.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from www .ja va 2 s  . co m
public List<String> generateMigrationFragments(Table table, TableMetadata tableInfo) {
    List<String> script = new ArrayList<String>();
    if (table.isPhysicalTable()) {
        script.add(table.sqlCreateString(getDialect(), getSessionFactory(), defaultCatalog, defaultSchema));
        //
        Iterator<String> comments = table.sqlCommentStrings(getDialect(), defaultCatalog, defaultSchema);
        while (comments.hasNext()) {
            script.add(comments.next());
        }
    }
    return script;
}

From source file:kr.debop4j.data.ogm.test.datastore.DatastoreProviderGeneratingSchema.java

License:Apache License

@Override
public void start(Configuration configuration, SessionFactoryImplementor sessionFactoryImplementor) {
    Iterator<Table> tables = configuration.getTableMappings();
    while (tables.hasNext()) {
        Table table = tables.next();
        if (table.isPhysicalTable()) {
            String tableName = table.getQuotedName();
            // do something with table
            Iterator<Column> columns = (Iterator<Column>) table.getColumnIterator();
            while (columns.hasNext()) {
                Column column = columns.next();
                String columnName = column.getCanonicalName();
                // do something with column
            }// ww w .j a  va  2  s  .com
            //TODO handle unique constraints?
        }
    }
    throw new RuntimeException("STARTED!");
}

From source file:org.apereo.portal.tools.dbloader.HibernateDbLoader.java

License:Apache License

/** Generate the drop scripts and add them to the script list */
@SuppressWarnings("unchecked")
protected List<String> dropScript(Collection<Table> tables, Dialect dialect, String defaultCatalog,
        String defaultSchema) {//from   ww w. j a v  a  2 s .c om
    final List<String> script = new ArrayList<String>(tables.size() * 2);

    if (dialect.dropConstraints()) {
        for (final Table table : tables) {
            if (table.isPhysicalTable()) {
                for (final Iterator<ForeignKey> subIter = table.getForeignKeyIterator(); subIter.hasNext();) {
                    final ForeignKey fk = subIter.next();
                    if (fk.isPhysicalConstraint()) {
                        script.add(fk.sqlDropString(dialect, defaultCatalog, defaultSchema));
                    }
                }
            }
        }
    }

    for (final Table table : tables) {
        if (table.isPhysicalTable()) {
            script.add(table.sqlDropString(dialect, defaultCatalog, defaultSchema));
        }
    }

    return script;
}

From source file:org.apereo.portal.tools.dbloader.HibernateDbLoader.java

License:Apache License

/** Generate create scripts and add them to the script list */
@SuppressWarnings("unchecked")
protected List<String> createScript(Collection<Table> tables, Dialect dialect, Mapping mapping,
        String defaultCatalog, String defaultSchema) {
    final List<String> script = new ArrayList<String>(tables.size() * 2);

    for (final Table table : tables) {
        if (table.isPhysicalTable()) {
            script.add(table.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
        }// w ww .  j ava  2 s. co m
    }

    for (final Table table : tables) {
        if (table.isPhysicalTable()) {
            if (!dialect.supportsUniqueConstraintInCreateAlterTable()) {
                for (final Iterator<UniqueKey> subIter = table.getUniqueKeyIterator(); subIter.hasNext();) {
                    final UniqueKey uk = subIter.next();
                    final String constraintString = uk.sqlCreateString(dialect, mapping, defaultCatalog,
                            defaultSchema);
                    if (constraintString != null) {
                        script.add(constraintString);
                    }
                }
            }

            for (final Iterator<Index> subIter = table.getIndexIterator(); subIter.hasNext();) {
                final Index index = subIter.next();
                script.add(index.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
            }

            if (dialect.hasAlterTable()) {
                for (final Iterator<ForeignKey> subIter = table.getForeignKeyIterator(); subIter.hasNext();) {
                    final ForeignKey fk = subIter.next();
                    if (fk.isPhysicalConstraint()) {
                        script.add(fk.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
                    }
                }
            }
        }
    }

    return script;
}

From source file:org.beangle.commons.orm.hibernate.internal.SchemaValidator.java

License:Open Source License

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);
            }/*from w w w  .java  2s  .c om*/
        }
    }

    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;
}

From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void generateTableSql(Table table) {
    if (!table.isPhysicalTable())
        return;//ww w  .  j a v  a  2s.  c  om
    Iterator<String> commentIter = table.sqlCommentStrings(dialect, defaultCatalog, defaultSchema);
    while (commentIter.hasNext()) {
        comments.add(commentIter.next());
    }

    if (processed.contains(table))
        return;
    processed.add(table);
    tables.add(table.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));

    Iterator<UniqueKey> subIter = table.getUniqueKeyIterator();
    while (subIter.hasNext()) {
        UniqueKey uk = subIter.next();
        String constraintString = uk.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema);
        if (constraintString != null)
            constraints.add(constraintString);
    }

    Iterator<Index> idxIter = table.getIndexIterator();
    while (idxIter.hasNext()) {
        final Index index = idxIter.next();
        indexes.add(index.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
    }

    if (dialect.hasAlterTable()) {
        Iterator<ForeignKey> fkIter = table.getForeignKeyIterator();
        while (fkIter.hasNext()) {
            ForeignKey fk = fkIter.next();
            if (fk.isPhysicalConstraint()) {
                constraints.add(fk.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
            }
        }
    }
}

From source file:org.codehaus.mojo.hibernate3.exporter.CustomHbm2DDLExporterMojo.java

License:Open Source License

private void processTableIndexNames(Table table) {
    if (table.isPhysicalTable()) {
        @SuppressWarnings("unchecked")
        Iterator<Index> subIter = table.getIndexIterator();
        while (subIter.hasNext()) {
            // for each index that has no name, generate a unique name
            Index index = subIter.next();
            if (index.getName().startsWith(GENERATE_INDEX_NAME_PREFIX)) {
                index.setName(gegenerateIndexName(table, index));
            }/*from w w w .  ja  va 2  s. co m*/
        }
    }
}

From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape.java

License:Open Source License

@Override
public Object getPropertyValue(Object propertyId) {
    Object res = null;//from  www.j a  v a2  s.  com
    RootClass rootClass = null;
    Table table = null;
    Object ormElement = getOrmElement();
    if (ormElement instanceof RootClass) {
        rootClass = (RootClass) ormElement;
    } else if (ormElement instanceof Subclass) {
        //rootClass = ((Subclass)ormElement).getRootClass();
    } else if (ormElement instanceof Table) {
        table = (Table) getOrmElement();
    }
    if (rootClass != null) {
        if (ENTITY_isAbstract.equals(propertyId)) {
            if (rootClass.isAbstract() != null) {
                res = rootClass.isAbstract().toString();
            }
        } else if (ENTITY_isCustomDeleteCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomDeleteCallable()).toString();
        } else if (ENTITY_isCustomInsertCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomInsertCallable()).toString();
        } else if (ENTITY_isCustomUpdateCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomUpdateCallable()).toString();
        } else if (ENTITY_isDiscriminatorInsertable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorInsertable()).toString();
        } else if (ENTITY_isDiscriminatorValueNotNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNotNull()).toString();
        } else if (ENTITY_isDiscriminatorValueNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNull()).toString();
        } else if (ENTITY_isExplicitPolymorphism.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isExplicitPolymorphism()).toString();
        } else if (ENTITY_isForceDiscriminator.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isForceDiscriminator()).toString();
        } else if (ENTITY_isInherited.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isInherited()).toString();
        } else if (ENTITY_isJoinedSubclass.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isJoinedSubclass()).toString();
        } else if (ENTITY_isLazy.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazy()).toString();
        } else if (ENTITY_isLazyPropertiesCacheable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazyPropertiesCacheable()).toString();
        } else if (ENTITY_isMutable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isMutable()).toString();
        } else if (ENTITY_isPolymorphic.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isPolymorphic()).toString();
        } else if (ENTITY_isVersioned.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isVersioned()).toString();
        } else if (ENTITY_batchSize.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getBatchSize()).toString();
        } else if (ENTITY_cacheConcurrencyStrategy.equals(propertyId)) {
            res = rootClass.getCacheConcurrencyStrategy();
        } else if (ENTITY_className.equals(propertyId)) {
            res = rootClass.getClassName();
        } else if (ENTITY_customSQLDelete.equals(propertyId)) {
            res = rootClass.getCustomSQLDelete();
        } else if (ENTITY_customSQLInsert.equals(propertyId)) {
            res = rootClass.getCustomSQLInsert();
        } else if (ENTITY_customSQLUpdate.equals(propertyId)) {
            res = rootClass.getCustomSQLUpdate();
        } else if (ENTITY_discriminatorValue.equals(propertyId)) {
            res = rootClass.getDiscriminatorValue();
        } else if (ENTITY_entityName.equals(propertyId)) {
            res = rootClass.getEntityName();
        } else if (ENTITY_loaderName.equals(propertyId)) {
            res = rootClass.getLoaderName();
        } else if (ENTITY_nodeName.equals(propertyId)) {
            res = rootClass.getNodeName();
        } else if (ENTITY_optimisticLockMode.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getOptimisticLockMode()).toString();
        } else if (ENTITY_table.equals(propertyId)) {
            if (rootClass.getTable() != null) {
                res = rootClass.getTable().getName();
            }
        } else if (ENTITY_temporaryIdTableDDL.equals(propertyId)) {
            res = rootClass.getTemporaryIdTableDDL();
        } else if (ENTITY_temporaryIdTableName.equals(propertyId)) {
            res = rootClass.getTemporaryIdTableName();
        } else if (ENTITY_where.equals(propertyId)) {
            res = rootClass.getWhere();
        }
    }
    if (table != null) {
        if (TABLE_catalog.equals(propertyId)) {
            res = table.getCatalog();
        } else if (TABLE_comment.equals(propertyId)) {
            res = table.getComment();
        } else if (TABLE_name.equals(propertyId)) {
            res = table.getName();
        } else if (TABLE_primaryKey.equals(propertyId)) {
            if (table.getPrimaryKey() != null) {
                res = table.getPrimaryKey().getName();
            }
        } else if (TABLE_rowId.equals(propertyId)) {
            res = table.getRowId();
        } else if (TABLE_schema.equals(propertyId)) {
            res = table.getSchema();
        } else if (TABLE_subselect.equals(propertyId)) {
            res = table.getSubselect();
        } else if (TABLE_hasDenormalizedTables.equals(propertyId)) {
            res = Boolean.valueOf(table.hasDenormalizedTables()).toString();
        } else if (TABLE_isAbstract.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstract()).toString();
        } else if (TABLE_isAbstractUnionTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstractUnionTable()).toString();
        } else if (TABLE_isPhysicalTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isPhysicalTable()).toString();
        }
    }
    if (res == null) {
        res = super.getPropertyValue(propertyId);
    }
    return toEmptyStr(res);
}

From source file:org.jbpm.db.JbpmSchema.java

License:Open Source License

public String[] getCleanSql() {
    if (cleanSql == null) {
        // loop over all foreign key constraints
        List dropForeignKeysSql = new ArrayList();
        List createForeignKeysSql = new ArrayList();
        Iterator iter = configuration.getTableMappings();
        while (iter.hasNext()) {
            Table table = (Table) iter.next();
            if (table.isPhysicalTable()) {
                Iterator subIter = table.getForeignKeyIterator();
                while (subIter.hasNext()) {
                    ForeignKey fk = (ForeignKey) subIter.next();
                    if (fk.isPhysicalConstraint()) {
                        // collect the drop foreign key constraint sql
                        dropForeignKeysSql.add(
                                fk.sqlDropString(dialect, properties.getProperty(Environment.DEFAULT_CATALOG),
                                        properties.getProperty(Environment.DEFAULT_SCHEMA)));
                        // and collect the create foreign key constraint sql
                        createForeignKeysSql.add(fk.sqlCreateString(dialect, mapping,
                                properties.getProperty(Environment.DEFAULT_CATALOG),
                                properties.getProperty(Environment.DEFAULT_SCHEMA)));
                    }//  w w  w  . j  av a2 s  .c  om
                }
            }
        }

        List deleteSql = new ArrayList();
        iter = configuration.getTableMappings();
        while (iter.hasNext()) {
            Table table = (Table) iter.next();
            deleteSql.add("delete from " + table.getName());
        }

        // glue
        //  - drop foreign key constraints
        //  - delete contents of all tables
        //  - create foreign key constraints
        // together to form the clean script
        List cleanSqlList = new ArrayList();
        cleanSqlList.addAll(dropForeignKeysSql);
        cleanSqlList.addAll(deleteSql);
        cleanSqlList.addAll(createForeignKeysSql);

        cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
    }
    return cleanSql;
}

From source file:org.jbpm.identity.hibernate.IdentitySchema.java

License:Open Source License

public String[] getCleanSql() {
    if (cleanSql == null) {
        // loop over all foreign key constraints
        List dropForeignKeysSql = new ArrayList();
        List createForeignKeysSql = new ArrayList();
        Iterator iter = configuration.getTableMappings();
        while (iter.hasNext()) {
            Table table = (Table) iter.next();
            if (table.isPhysicalTable()) {
                Iterator subIter = table.getForeignKeyIterator();
                while (subIter.hasNext()) {
                    ForeignKey fk = (ForeignKey) subIter.next();
                    if (fk.isPhysicalConstraint()) {
                        // collect the drop key constraint
                        dropForeignKeysSql.add(
                                fk.sqlDropString(dialect, properties.getProperty(Environment.DEFAULT_CATALOG),
                                        properties.getProperty(Environment.DEFAULT_SCHEMA)));
                        createForeignKeysSql.add(fk.sqlCreateString(dialect, mapping,
                                properties.getProperty(Environment.DEFAULT_CATALOG),
                                properties.getProperty(Environment.DEFAULT_SCHEMA)));
                    }/*  w  w w. j  a  va  2 s  . c o  m*/
                }
            }
        }

        List deleteSql = new ArrayList();
        iter = configuration.getTableMappings();
        while (iter.hasNext()) {
            Table table = (Table) iter.next();
            deleteSql.add("delete from " + table.getName());
        }

        List cleanSqlList = new ArrayList();
        cleanSqlList.addAll(dropForeignKeysSql);
        cleanSqlList.addAll(deleteSql);
        cleanSqlList.addAll(createForeignKeysSql);

        cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
    }
    return cleanSql;
}