org.hibernate.mapping.Table - java examples

Here are the examples of the java api org.hibernate.mapping.Table taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

87 Examples 7

19 View Complete Implementation : Mappings.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void addTableBinding(String schema, String catalog, String logicalName, String physicalName, Table denormalizedSuperTable) {
    String key = buildTableNameKey(schema, catalog, physicalName);
    TableDescription tableDescription = new TableDescription(logicalName, denormalizedSuperTable);
    TableDescription oldDescriptor = (TableDescription) tableNameBinding.put(key, tableDescription);
    if (oldDescriptor != null && !oldDescriptor.logicalName.equals(logicalName)) {
        // TODO possibly relax that
        throw new MappingException("Same physical table name reference several logical table names: " + physicalName + " => " + "'" + oldDescriptor.logicalName + "' and '" + logicalName + "'");
    }
}

19 View Complete Implementation : TableDependencyTracker.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
/**
 * Returns the list of tables that one must process before processing the provided {@code table}.
 *
 * @param table The table that you wish to process
 * @return the ordered {@link ArrayDeque} of tables to process before processing {@code table}
 */
public Collection<Table> getDependentTables(Table table) {
    ArrayDeque<Table> tableStack = new ArrayDeque<>();
    while (table != null && !processedTables.contains(table)) {
        tableStack.push(table);
        processedTables.add(table);
        table = tableDependencies.get(table);
    }
    return tableStack;
}

19 View Complete Implementation : DdlGenerator.java
Copyright GNU Lesser General Public License v3.0
Author : beangle
private void commentProperties(Clreplaced<?> clazz, Table table, Iterator<Property> ip) {
    while (ip.hasNext()) commentProperty(clazz, table, ip.next());
}

18 View Complete Implementation : AbstractDBUnitHibernateMemoryTest.java
Copyright GNU General Public License v3.0
Author : testIT-LivingDoc
protected String getTableName(Clreplaced<?> peristentClreplaced) {
    Table table = getMapping(peristentClreplaced).getTable();
    return table.getName();
}

18 View Complete Implementation : FixedDatabaseMetadata.java
Copyright Apache License 2.0
Author : Jasig
@Override
public boolean isTable(Object key) throws HibernateException {
    if (key instanceof String) {
        Table tbl = new Table((String) key);
        if (getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted()) != null) {
            return true;
        } else {
            String[] strings = StringHelper.split(".", (String) key);
            if (strings.length == 3) {
                tbl = new Table(strings[2]);
                tbl.setCatalog(strings[0]);
                tbl.setSchema(strings[1]);
                return getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted()) != null;
            } else if (strings.length == 2) {
                tbl = new Table(strings[1]);
                tbl.setSchema(strings[0]);
                return getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted()) != null;
            }
        }
    }
    return false;
}

18 View Complete Implementation : DatabaseMetadata.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public boolean isTable(Object key) throws HibernateException {
    if (key instanceof String) {
        Table tbl = new Table((String) key);
        if (getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted()) != null) {
            return true;
        } else {
            String[] strings = StringHelper.split(".", (String) key);
            if (strings.length == 3) {
                tbl = new Table(strings[2]);
                tbl.setCatalog(strings[0]);
                tbl.setSchema(strings[1]);
                return getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted()) != null;
            } else if (strings.length == 2) {
                tbl = new Table(strings[1]);
                tbl.setSchema(strings[0]);
                return getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted()) != null;
            }
        }
    }
    return false;
}

18 View Complete Implementation : TablesOnlyFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeForeignKey(Table table, ForeignKey fk) {
    return includeTable(table);
}

18 View Complete Implementation : AllDataHibernateMigrationFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeTable(Table table) {
    return true;
}

18 View Complete Implementation : AllDataHibernateMigrationFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeForeignKey(Table table, ForeignKey fk) {
    return true;
}

17 View Complete Implementation : TablesOnlyFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeUniqueKey(Table table, UniqueKey uk) {
    return includeTable(table);
}

17 View Complete Implementation : TablesOnlyFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeTable(Table table) {
    return tables.contains(table.getName());
}

17 View Complete Implementation : AbstractHibernateDatasource.java
Copyright GNU General Public License v2.0
Author : 52North
/**
 * Create quoted string with schema.table
 *
 * @param settings
 *            Datasource settings
 * @param conn
 *            SQL connection
 * @return {@link List} with table names
 * @throws SQLException
 *             If an error occurs while checking catalog/schema
 */
protected List<String> getQuotedSchemaTableNames(Map<String, Object> settings, Connection conn) throws SQLException {
    String catalog = checkCatalog(conn);
    String schema = checkSchema((String) settings.get(SCHEMA_KEY), catalog, conn);
    Iterator<Table> tables = getMetadata(conn, settings).collectTableMappings().iterator();
    List<String> names = new LinkedList<String>();
    while (tables.hasNext()) {
        Table table = tables.next();
        if (table.isPhysicalTable()) {
            names.add(table.getQualifiedName(getDialectInternal(), catalog, schema));
        }
    }
    return names;
}

17 View Complete Implementation : Mappings.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void addColumnBinding(String logicalName, Column finalColumn, Table table) {
    ColumnNames binding = (ColumnNames) columnNameBindingPerTable.get(table);
    if (binding == null) {
        binding = new ColumnNames();
        columnNameBindingPerTable.put(table, binding);
    }
    String oldFinalName = (String) binding.logicalToPhysical.put(logicalName.toLowerCase(), finalColumn.getQuotedName());
    if (oldFinalName != null && !(finalColumn.isQuoted() ? oldFinalName.equals(finalColumn.getQuotedName()) : oldFinalName.equalsIgnoreCase(finalColumn.getQuotedName()))) {
        // TODO possibly relax that
        throw new MappingException("Same logical column name referenced by different physical ones: " + table.getName() + "." + logicalName + " => '" + oldFinalName + "' and '" + finalColumn.getQuotedName() + "'");
    }
    String oldLogicalName = (String) binding.physicalToLogical.put(finalColumn.getQuotedName(), logicalName);
    if (oldLogicalName != null && !oldLogicalName.equals(logicalName)) {
        // TODO possibly relax that
        throw new MappingException("Same physical column represented by different logical column names: " + table.getName() + "." + finalColumn.getQuotedName() + " => '" + oldLogicalName + "' and '" + logicalName + "'");
    }
}

17 View Complete Implementation : SpannerTableExporter.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
@Override
public String[] getSqlCreateStrings(Table currentTable, Metadata metadata) {
    initializeUniqueConstraints(currentTable);
    return buildSqlStrings(currentTable, metadata, Action.CREATE);
}

17 View Complete Implementation : AllDataHibernateMigrationFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeIndex(Table table, Index index) {
    return true;
}

17 View Complete Implementation : AllDataHibernateMigrationFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeUniqueKey(Table table, UniqueKey uk) {
    return true;
}

17 View Complete Implementation : TablesOnlyFilter.java
Copyright Apache License 2.0
Author : openequella
@Override
public boolean includeIndex(Table table, Index index) {
    return includeTable(table);
}

16 View Complete Implementation : AbstractHibernateDatasource.java
Copyright GNU General Public License v2.0
Author : 52North
@Override
public boolean checkIfSchemaExists(Map<String, Object> settings) {
    Connection conn = null;
    try {
        /* check if any of the needed tables is existing */
        conn = openConnection(settings);
        Iterator<Table> iter = getMetadata(conn, settings).collectTableMappings().iterator();
        String catalog = checkCatalog(conn);
        String schema = checkSchema((String) settings.get(SCHEMA_KEY), catalog, conn);
        Set<String> tableNames = getTableNames(conn, catalog, schema);
        while (iter.hasNext()) {
            Table table = iter.next();
            if (table.isPhysicalTable() && tableNames.contains(table.getName())) {
                return true;
            }
        }
        return false;
    } catch (SQLException ex) {
        throw new ConfigurationError(ex);
    } finally {
        close(conn);
    }
}

16 View Complete Implementation : Mappings.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public String getPhysicalColumnName(String logicalName, Table table) {
    logicalName = logicalName.toLowerCase();
    String finalName = null;
    Table currentTable = table;
    do {
        ColumnNames binding = (ColumnNames) columnNameBindingPerTable.get(currentTable);
        if (binding != null) {
            finalName = (String) binding.logicalToPhysical.get(logicalName);
        }
        String key = buildTableNameKey(currentTable.getSchema(), currentTable.getCatalog(), currentTable.getName());
        TableDescription description = (TableDescription) tableNameBinding.get(key);
        if (description != null)
            currentTable = description.denormalizedSupertable;
    } while (finalName == null && currentTable != null);
    if (finalName == null) {
        throw new MappingException("Unable to find column with logical name " + logicalName + " in table " + table.getName());
    }
    return finalName;
}

16 View Complete Implementation : Mappings.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public String getLogicalColumnName(String physicalName, Table table) {
    String logical = null;
    Table currentTable = table;
    TableDescription description = null;
    do {
        ColumnNames binding = (ColumnNames) columnNameBindingPerTable.get(currentTable);
        if (binding != null) {
            logical = (String) binding.physicalToLogical.get(physicalName);
        }
        String key = buildTableNameKey(currentTable.getSchema(), currentTable.getCatalog(), currentTable.getName());
        description = (TableDescription) tableNameBinding.get(key);
        if (description != null)
            currentTable = description.denormalizedSupertable;
    } while (logical == null && currentTable != null && description != null);
    if (logical == null) {
        throw new MappingException("Unable to find logical column name from physical name " + physicalName + " in table " + table.getName());
    }
    return logical;
}

16 View Complete Implementation : Mappings.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public String getLogicalTableName(Table table) {
    return getLogicalTableName(table.getQuotedSchema(), table.getCatalog(), table.getQuotedName());
}

16 View Complete Implementation : SchemaUtils.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
/**
 * Returns the {@link Interleaved} annotation on a table if it exists.
 */
public static Interleaved getInterleaveAnnotation(Table table, Metadata metadata) {
    for (PersistentClreplaced pc : metadata.getEnreplacedyBindings()) {
        if (pc.getTable().equals(table) && pc.getMappedClreplaced() != null) {
            Clreplaced<?> enreplacedyClreplaced = pc.getMappedClreplaced();
            return enreplacedyClreplaced.getAnnotation(Interleaved.clreplaced);
        }
    }
    return null;
}

16 View Complete Implementation : SpannerTableStatements.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
/**
 * Returns true if a table is generated by a Hibernate element collection.
 */
private boolean isElementCollection(Table table, Metadata metadata) {
    for (Collection collection : metadata.getCollectionBindings()) {
        if (collection.getCollectionTable().equals(table)) {
            return true;
        }
    }
    return false;
}

16 View Complete Implementation : SpannerTableExporter.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
@Override
public String[] getSqlDropStrings(Table currentTable, Metadata metadata) {
    initializeUniqueConstraints(currentTable);
    return buildSqlStrings(currentTable, metadata, Action.DROP);
}

16 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
public List<String> getDropTableSql(String... tables) {
    List<String> drops = new ArrayList<String>();
    for (String tableName : tables) {
        Table table = findTable(tableName);
        drops.add(table.sqlDropString(dialect, defaultCatalog, defaultSchema));
    }
    return drops;
}

16 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
private Table findTable(String tableName) {
    Map<String, Table> tableMap = configuration.getTableMap();
    Table table = tableMap.get(tableName);
    if (table == null) {
        throw new RuntimeException("Failed to find table: " + tableName);
    }
    return table;
}

16 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
public List<String> getAddIndexesForColumns(String tableName, String... columnNames) {
    Set<Column> colSet = new HashSet<Column>();
    for (String columnName : columnNames) {
        colSet.add(new Column(columnName));
    }
    List<String> sqlStrings = new ArrayList<String>();
    Table table = findTable(tableName);
    addIndexSQL(sqlStrings, table, colSet);
    return sqlStrings;
}

15 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
public List<String> getRenameColumnSQL(String tableName, String columnName, String newColumnName) {
    List<String> sqlStrings = new ArrayList<String>();
    Table table = findTable(tableName);
    Column column = table.getColumn(new Column(columnName));
    String alter = null;
    alter = extDialect.getRenameColumnSql(table.getQualifiedName(dialect, defaultCatalog, defaultSchema), column, newColumnName);
    sqlStrings.add(alter);
    return sqlStrings;
}

15 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
public List<String> getAddNotNullSQLIfRequired(Session session, String tableName, String... columns) {
    final Table table = findTable(tableName);
    final List<String> sqlStrings = new ArrayList<String>();
    final Set<String> colset = new HashSet<String>(Arrays.asList(columns));
    session.doWork(new Work() {

        @Override
        public void execute(Connection connection) throws SQLException {
            ResultSet colresult = connection.getMetaData().getColumns(getDefaultCatalog(), extDialect.getNameForMetadataQuery(getDefaultSchema(), false), extDialect.getNameForMetadataQuery(table.getName(), table.isQuoted()), "%");
            try {
                while (colresult.next()) {
                    String columnName = colresult.getString("COLUMN_NAME").toLowerCase();
                    if (colset.contains(columnName) && "yes".equals(colresult.getString("IS_NULLABLE").toLowerCase())) {
                        Column column = table.getColumn(new Column(columnName));
                        StringBuffer alter = new StringBuffer("alter table ").append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema)).append(' ').append(extDialect.getAddNotNullSql(mapping, column));
                        sqlStrings.add(alter.toString());
                    }
                }
            } finally {
                colresult.close();
            }
        }
    });
    return sqlStrings;
}

15 View Complete Implementation : Mappings.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public Table addTable(String schema, String catalog, String name, String subselect, boolean isAbstract) {
    String key = subselect == null ? Table.qualify(catalog, schema, name) : subselect;
    Table table = (Table) tables.get(key);
    if (table == null) {
        table = new Table();
        table.setAbstract(isAbstract);
        table.setName(name);
        table.setSchema(schema);
        table.setCatalog(catalog);
        table.setSubselect(subselect);
        tables.put(key, table);
    } else {
        if (!isAbstract)
            table.setAbstract(false);
    }
    return table;
}

15 View Complete Implementation : SpannerTableStatements.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
private static String getInterleavedClause(Table table, Metadata metadata) {
    Interleaved interleaved = SchemaUtils.getInterleaveAnnotation(table, metadata);
    if (interleaved != null) {
        Table parentTable = SchemaUtils.getTable(interleaved.parentEnreplacedy(), metadata);
        String interleaveClause = ", INTERLEAVE IN PARENT " + parentTable.getQuotedName();
        if (interleaved.cascadeDelete()) {
            interleaveClause += " ON DELETE CASCADE";
        }
        return interleaveClause;
    }
    return "";
}

15 View Complete Implementation : SpannerTableStatements.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
/**
 * Generates the statements needed to create a table.
 */
public List<String> createTable(Table table, Metadata metadata) {
    if (spannerDatabaseInfo.getAllTables().contains(table.getName())) {
        return Collections.EMPTY_LIST;
    }
    Iterable<Column> keyColumns;
    if (table.hasPrimaryKey()) {
        // a typical table that corresponds to an enreplacedy type
        keyColumns = getSortedPkColumns(table, metadata);
    } else if (isElementCollection(table, metadata)) {
        // a table that is actually an element collection property
        keyColumns = table::getColumnIterator;
    } else {
        // the case corresponding to a sequence-table that will only have 1 row.
        keyColumns = Collections.emptyList();
    }
    return getCreateTableStrings(table, metadata, keyColumns);
}

15 View Complete Implementation : BaseNeo4jSchemaDefiner.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void addConstraint(List<UniqueConstraintDetails> constraints, Table table, Label label, Constraint constraint) {
    if (constraint != null) {
        // Neo4j does not store properties representing foreign key columns, so we don't need to create unique
        // constraints for them
        if (!isAppliedToForeignColumns(table, constraint)) {
            if (constraint.getColumnSpan() == 1) {
                String propertyName = constraint.getColumn(0).getName();
                constraints.add(new UniqueConstraintDetails(label, propertyName));
            } else if (log.isEnabled(Level.WARN)) {
                logMultipleColumnsWarning(table, constraint);
            }
        }
    }
}

14 View Complete Implementation : BookstoreService.java
Copyright Apache License 2.0
Author : AnghelLeonard
private void displayTablesMetadata(Table table) {
    System.out.println("\nTable: " + table);
    Iterator it = table.getColumnIterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

14 View Complete Implementation : Mappings.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public Table addDenormalizedTable(String schema, String catalog, String name, boolean isAbstract, String subselect, Table includedTable) throws MappingException {
    String key = subselect == null ? Table.qualify(catalog, schema, name) : subselect;
    if (tables.containsKey(key)) {
        throw new DuplicateMappingException("table", name);
    }
    Table table = new DenormalizedTable(includedTable);
    table.setAbstract(isAbstract);
    table.setName(name);
    table.setSchema(schema);
    table.setCatalog(catalog);
    table.setSubselect(subselect);
    tables.put(key, table);
    return table;
}

14 View Complete Implementation : SpannerTableStatements.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
/**
 * Generates the statements needed to drop a table.
 */
public List<String> dropTable(Table table, Metadata metadata) {
    ArrayList<String> dropStrings = new ArrayList<>();
    for (String indexName : getTableIndices(table)) {
        if (spannerDatabaseInfo.getAllIndices().contains(indexName)) {
            dropStrings.add("drop index " + indexName);
        }
    }
    if (spannerDatabaseInfo.getAllTables().contains(table.getName())) {
        dropStrings.add(this.spannerDialect.getDropTableString(table.getQuotedName()));
    }
    return dropStrings;
}

14 View Complete Implementation : HibernateDataSource.java
Copyright GNU Affero General Public License v3.0
Author : KnowageLabs
protected void addDbLink(String modelName, Configuration srcCfg, Configuration dstCfg) {
    String dbLink = null;
    PersistentClreplaced srcPersistentClreplaced = null;
    PersistentClreplaced dstPersistentClreplaced = null;
    String targetEnreplacedyName = null;
    Table targetTable = null;
    dbLink = (String) getDbLinkMap().get(modelName);
    if (dbLink != null) {
        Iterator it = srcCfg.getClreplacedMappings();
        while (it.hasNext()) {
            srcPersistentClreplaced = (PersistentClreplaced) it.next();
            targetEnreplacedyName = srcPersistentClreplaced.getEnreplacedyName();
            dstPersistentClreplaced = dstCfg.getClreplacedMapping(targetEnreplacedyName);
            targetTable = dstPersistentClreplaced.getTable();
            targetTable.setName(targetTable.getName() + "@" + dbLink);
        }
    }
}

14 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
public Map<Set<String>, String> getExistingIndexes(final Table table, Session session) {
    final Map<String, Set<String>> indexMap = new HashMap<String, Set<String>>();
    // Query existing index
    session.doWork(new Work() {

        @Override
        public void execute(Connection connection) throws SQLException {
            ResultSet colresult = connection.getMetaData().getIndexInfo(getDefaultCatalog(), extDialect.getNameForMetadataQuery(getDefaultSchema(), false), extDialect.getNameForMetadataQuery(table.getName(), table.isQuoted()), false, false);
            try {
                while (colresult.next()) {
                    String indexName = colresult.getString("INDEX_NAME");
                    String columnName = colresult.getString("COLUMN_NAME");
                    if (columnName != null) {
                        columnName = columnName.toLowerCase();
                        Set<String> cols = indexMap.get(indexName);
                        if (cols == null) {
                            cols = new HashSet<String>();
                            indexMap.put(indexName, cols);
                        }
                        cols.add(columnName);
                    }
                }
            } finally {
                colresult.close();
            }
        }
    });
    // Change from (index -> cols) to (cols -> index)
    Map<Set<String>, String> revIndexMap = new HashMap<Set<String>, String>();
    for (Map.Entry<String, Set<String>> entry : indexMap.entrySet()) {
        revIndexMap.put(entry.getValue(), entry.getKey());
    }
    return revIndexMap;
}

13 View Complete Implementation : AbstractH2Datasource.java
Copyright GNU General Public License v2.0
Author : 52North
@Override
public void clear(Properties properties) {
    Map<String, Object> settings = parseDatasourceProperties(properties);
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = openConnection(settings);
        Iterator<Table> tables = getMetadata(conn, settings).collectTableMappings().iterator();
        stmt = conn.createStatement();
        stmt.execute("set referential_integrity false");
        while (tables.hasNext()) {
            Table table = tables.next();
            if (table.isPhysicalTable()) {
                stmt.execute("truncate table " + table.getQuotedName(new GeoDBDialect()));
            }
        }
        stmt.execute("set referential_integrity true");
        GeoDB.InitGeoDB(conn);
    } catch (SQLException ex) {
        throw new ConfigurationError(ex);
    } finally {
        close(stmt);
        close(conn);
    }
}

13 View Complete Implementation : SpannerTableStatements.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
private static List<Column> getSortedPkColumns(Table table, Metadata metadata) {
    Interleaved interleaved = SchemaUtils.getInterleaveAnnotation(table, metadata);
    if (interleaved == null) {
        return table.getPrimaryKey().getColumns();
    }
    Table parentTable = SchemaUtils.getTable(interleaved.parentEnreplacedy(), metadata);
    List<Column> sortedParentPkColumns = getSortedPkColumns(parentTable, metadata);
    List<Column> sortedCurrentPkColumns = table.getPrimaryKey().getColumns().stream().filter(column -> !sortedParentPkColumns.contains(column)).collect(Collectors.toList());
    ArrayList<Column> currentPkColumns = new ArrayList<>();
    currentPkColumns.addAll(sortedParentPkColumns);
    currentPkColumns.addAll(sortedCurrentPkColumns);
    return currentPkColumns;
}

13 View Complete Implementation : SpannerTableStatements.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
private Set<String> getTableIndices(Table table) {
    Set<String> tableIndices = new HashSet<>();
    Iterator<Index> indexIterator = table.getIndexIterator();
    while (indexIterator.hasNext()) {
        tableIndices.add(indexIterator.next().getName());
    }
    Iterator<UniqueKey> keyIterator = table.getUniqueKeyIterator();
    while (keyIterator.hasNext()) {
        tableIndices.add(keyIterator.next().getName());
    }
    return tableIndices;
}

13 View Complete Implementation : TableDependencyTracker.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
/**
 * Initializes the table dependency tracker.
 *
 * @param metadata the Hibernate metadata
 * @param schemaAction the kind of schema operation being done: {CREATE or DROP}.
 */
public void initializeDependencies(Metadata metadata, Action schemaAction) {
    HashMap<Table, Table> dependencies = new HashMap<>();
    for (Table childTable : metadata.collectTableMappings()) {
        Interleaved interleaved = SchemaUtils.getInterleaveAnnotation(childTable, metadata);
        if (interleaved != null) {
            if (schemaAction == Action.CREATE || schemaAction == Action.UPDATE) {
                // If creating tables, the parent blocks the child.
                dependencies.put(childTable, SchemaUtils.getTable(interleaved.parentEnreplacedy(), metadata));
            } else {
                // If dropping tables, the child blocks the parent.
                dependencies.put(SchemaUtils.getTable(interleaved.parentEnreplacedy(), metadata), childTable);
            }
        }
    }
    this.tableDependencies = dependencies;
    this.processedTables = new HashSet<>();
}

13 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
public List<String> getDropColumnSQL(String tableName, String... columns) {
    List<String> sqlStrings = new ArrayList<String>();
    Table table = findTable(tableName);
    for (String columnName : columns) {
        Column column = table.getColumn(new Column(columnName));
        if (column == null) {
            throw new RuntimeException("Could not find column " + columnName + " on table " + tableName);
        }
        sqlStrings.add(extDialect.getDropColumnSql(table.getQualifiedName(dialect, defaultCatalog, defaultSchema), column));
    }
    return sqlStrings;
}

13 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
/**
 * @param tableName
 * @param columnName
 * @param changeNotNull
 * @param nullable Preplaced in null to use the annotation on the column. This is not always possible
 *     (see Redmine #3329).
 * @param changeType
 * @return
 */
public List<String> getModifyColumnSQL(String tableName, String columnName, boolean changeNotNull, boolean changeType) {
    List<String> sqlStrings = new ArrayList<String>();
    Table table = findTable(tableName);
    Column column = table.getColumn(new Column(columnName));
    StringBuffer alter = new StringBuffer("alter table ").append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema)).append(' ').append(extDialect.getModifyColumnSql(mapping, column, changeNotNull, changeType));
    sqlStrings.add(alter.toString());
    return sqlStrings;
}

13 View Complete Implementation : HibernateMigrationHelper.java
Copyright Apache License 2.0
Author : openequella
public List<String> getAddNotNullSQL(String tableName, String... columns) {
    List<String> sqlStrings = new ArrayList<String>();
    Table table = findTable(tableName);
    for (String columnName : columns) {
        Column column = table.getColumn(new Column(columnName));
        StringBuffer alter = new StringBuffer("alter table ").append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema)).append(' ').append(extDialect.getAddNotNullSql(mapping, column));
        sqlStrings.add(alter.toString());
    }
    return sqlStrings;
}

12 View Complete Implementation : AbstractPostgresDatasource.java
Copyright GNU General Public License v2.0
Author : 52North
@Override
public void clear(Properties properties) {
    Map<String, Object> settings = parseDatasourceProperties(properties);
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = openConnection(settings);
        String catalog = checkCatalog(conn);
        String schema = checkSchema((String) settings.get(SCHEMA_KEY), catalog, conn);
        Iterator<Table> tables = getMetadata(conn, settings).collectTableMappings().iterator();
        List<String> names = new LinkedList<String>();
        while (tables.hasNext()) {
            Table table = tables.next();
            if (table.isPhysicalTable()) {
                names.add(table.getQualifiedName(createDialect(), null, schema));
            }
        }
        if (!names.isEmpty()) {
            stmt = conn.createStatement();
            stmt.execute(String.format("truncate %s restart idenreplacedy cascade", Joiner.on(", ").join(names)));
        }
    } catch (SQLException ex) {
        throw new ConfigurationError(ex);
    } finally {
        close(stmt);
        close(conn);
    }
}

12 View Complete Implementation : DdlGenerator.java
Copyright GNU Lesser General Public License v3.0
Author : beangle
@SuppressWarnings("unchecked")
private void commentProperty(Clreplaced<?> clazz, Table table, Property p) {
    if (null == p)
        return;
    if (p.getColumnSpan() == 1) {
        Column column = (Column) p.getColumnIterator().next();
        if (isForeignColumn(table, column)) {
            column.setComment(messages.get(clazz, p.getName()) + " ID");
        } else {
            column.setComment(messages.get(clazz, p.getName()));
        }
    } else if (p.getColumnSpan() > 1) {
        Component pc = ((Component) p.getValue());
        Clreplaced<?> columnOwnerClreplaced = pc.getComponentClreplaced();
        commentProperties(columnOwnerClreplaced, table, pc.getPropertyIterator());
    }
}

12 View Complete Implementation : SpannerTableExporter.java
Copyright GNU Lesser General Public License v2.1
Author : GoogleCloudPlatform
private String[] buildSqlStrings(Table currentTable, Metadata metadata, Action schemaAction) {
    Collection<Table> tablesToProcess = tableDependencyTracker.getDependentTables(currentTable);
    List<String> ddlStatements = tablesToProcess.stream().flatMap(table -> {
        if (schemaAction == Action.CREATE) {
            return spannerTableStatements.createTable(table, metadata).stream();
        } else {
            return spannerTableStatements.dropTable(table, metadata).stream();
        }
    }).collect(Collectors.toList());
    return ddlStatements.toArray(new String[ddlStatements.size()]);
}

12 View Complete Implementation : MongoDBSchemaDefiner.java
Copyright GNU Lesser General Public License v2.1
Author : hibernate
private void validateIndexSpecsForUniqueKeys(Table table, IndexOptions indexOptions, Set<String> forIndexNotReferenced, UniqueConstraintSchemaUpdateStrategy constraintMethod) {
    Iterator<UniqueKey> keys = table.getUniqueKeyIterator();
    while (keys.hasNext()) {
        UniqueKey uniqueKey = keys.next();
        forIndexNotReferenced.remove(uniqueKey.getName());
        if (constraintMethod != UniqueConstraintSchemaUpdateStrategy.SKIP) {
            MongoDBIndexSpec indexSpec = new MongoDBIndexSpec(uniqueKey, getIndexOptionDoreplacedent(table, indexOptions.getOptionForIndex(uniqueKey.getName())));
            if (validateIndexSpec(indexSpec)) {
                indexSpecs.add(indexSpec);
            }
        }
    }
}

12 View Complete Implementation : TableXmlHandler.java
Copyright Apache License 2.0
Author : Jasig
/**
 * Builds an object model of Hibernate mapping objects for tables based on an XML definition file.
 * Once parsing is complete the generated objects are availabe via {@link #getTables()}
 */
public clreplaced TableXmlHandler extends BaseDbXmlHandler implements ITableDataProvider {

    private final Mappings mappings = new Configuration().createMappings();

    private final Dialect dialect;

    public TableXmlHandler(Dialect dialect) {
        this.dialect = dialect;
    }

    @Override
    public Map<String, Table> getTables() {
        return this.tables;
    }

    @Override
    public Map<String, Map<String, Integer>> getTableColumnTypes() {
        return tableColumnTypes;
    }

    private Map<String, Table> tables = new LinkedHashMap<String, Table>();

    private Map<String, Map<String, Integer>> tableColumnTypes = new TreeMap<String, Map<String, Integer>>(String.CASE_INSENSITIVE_ORDER);

    private Table currentTable = null;

    private Map<String, Column> currentColumns = null;

    private Map<String, Integer> currentColumnTypes = null;

    private Column currentColumn = null;

    private PrimaryKey primaryKey = null;

    private Index currentIndex = null;

    private UniqueKey currentUnique = null;

    /* (non-Javadoc)
     * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
     */
    @Override
    public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
        if ("table".equals(name)) {
            this.currentColumns = new LinkedHashMap<String, Column>();
            this.currentColumnTypes = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
        } else if ("index".equals(name)) {
            this.currentIndex = new Index();
            this.currentIndex.setTable(this.currentTable);
        } else if ("unique".equals(name)) {
            this.currentUnique = new UniqueKey();
            this.currentUnique.setTable(this.currentTable);
        }
        this.chars = new StringBuilder();
    }

    /* (non-Javadoc)
     * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public void endElement(String uri, String localName, String name) throws SAXException {
        if ("table".equals(name)) {
            for (final Column column : this.currentColumns.values()) {
                this.currentTable.addColumn(column);
            }
            if (this.primaryKey != null) {
                this.currentTable.setPrimaryKey(this.primaryKey);
            }
            this.tables.put(this.currentTable.getName(), this.currentTable);
            this.tableColumnTypes.put(this.currentTable.getName(), this.currentColumnTypes);
            this.primaryKey = null;
            this.currentColumns = null;
            this.currentColumnTypes = null;
            this.currentTable = null;
        } else if ("column".equals(name)) {
            this.currentColumns.put(this.currentColumn.getName(), this.currentColumn);
            this.currentColumn = null;
        } else if ("name".equals(name)) {
            final String itemName = this.chars.toString().trim();
            if (this.currentIndex != null) {
                this.currentIndex.setName(itemName);
            } else if (this.currentUnique != null) {
                this.currentUnique.setName(itemName);
            } else if (this.currentTable == null) {
                this.currentTable = new Table(itemName);
            } else if (this.currentColumn == null) {
                this.currentColumn = new Column(itemName);
            }
        } else if ("type".equals(name)) {
            final String sqlTypeName = this.chars.toString().trim();
            final int sqlType = this.getSqlType(sqlTypeName);
            this.currentColumnTypes.put(this.currentColumn.getName(), sqlType);
            final String hibType = this.getHibernateType(sqlType);
            final SimpleValue value = new SimpleValue(this.mappings, this.currentTable);
            value.setTypeName(hibType);
            this.currentColumn.setValue(value);
        } else if ("param".equals(name)) {
            final String param = this.chars.toString().trim();
            final Integer length = Integer.valueOf(param);
            this.currentColumn.setLength(length);
        } else if ("primary-key".equals(name)) {
            final String columnName = this.chars.toString().trim();
            if (this.primaryKey == null) {
                this.primaryKey = new PrimaryKey();
            }
            final Column column = this.currentColumns.get(columnName);
            this.primaryKey.addColumn(column);
        } else if ("not-null".equals(name)) {
            final String columnName = this.chars.toString().trim();
            final Column column = this.currentColumns.get(columnName);
            column.setNullable(false);
        } else if ("column-ref".equals(name)) {
            final String columnName = this.chars.toString().trim();
            final Column column = this.currentColumns.get(columnName);
            if (this.currentIndex != null) {
                this.currentIndex.addColumn(column);
            } else if (this.currentUnique != null) {
                this.currentUnique.addColumn(column);
            }
        } else if ("index".equals(name)) {
            this.currentTable.addIndex(this.currentIndex);
            this.currentIndex = null;
        } else if ("unique".equals(name)) {
            this.currentTable.addUniqueKey(this.currentUnique);
            this.currentUnique = null;
        } else if ("key".equals(name)) {
            this.logger.warn("the 'key' element is ignored, use the table level 'primary-key' element instead");
        }
        this.chars = null;
    }

    protected int getSqlType(final String sqlTypeName) {
        try {
            final Field sqlTypeField = Types.clreplaced.getField(sqlTypeName);
            return sqlTypeField.getInt(null);
        } catch (SecurityException e) {
            throw new RuntimeException("Cannot access field '" + sqlTypeName + "' on " + Types.clreplaced + " for column '" + this.currentColumn.getName() + "'", e);
        } catch (NoSuchFieldException e) {
            throw new IllegalArgumentException("No SQL Type field '" + sqlTypeName + "' on " + Types.clreplaced + " for column '" + this.currentColumn.getName() + "'", e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("Cannot access field '" + sqlTypeName + "' on " + Types.clreplaced + " for column '" + this.currentColumn.getName() + "'", e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Cannot access field '" + sqlTypeName + "' on " + Types.clreplaced + " for column '" + this.currentColumn.getName() + "'", e);
        }
    }

    protected String getHibernateType(final int sqlType) {
        final String hibType;
        try {
            hibType = this.dialect.getHibernateTypeName(sqlType);
        } catch (MappingException e) {
            throw new IllegalArgumentException("No mapped hibernate type found for '" + sqlType + "' Types value=" + sqlType + " for column '" + this.currentColumn.getName() + "'", e);
        }
        return hibType;
    }
}