Search in sources :

Example 1 with IndexType

use of org.umlg.sqlg.structure.topology.IndexType in project sqlg by pietermartin.

the class SqlgStartupManager method extractIndices.

private void extractIndices(DatabaseMetaData metadata, String catalog, String schema, String table, String label, boolean isVertex) throws SQLException {
    String lastIndexName = null;
    IndexType lastIndexType = null;
    List<String> lastColumns = new LinkedList<>();
    List<Triple<String, Boolean, String>> indexes = this.sqlDialect.getIndexInfo(metadata, catalog, schema, table, false, true);
    for (Triple<String, Boolean, String> index : indexes) {
        String indexName = index.getLeft();
        boolean nonUnique = index.getMiddle();
        String columnName = index.getRight();
        if (lastIndexName == null) {
            lastIndexName = indexName;
            lastIndexType = nonUnique ? IndexType.NON_UNIQUE : IndexType.UNIQUE;
        } else if (!lastIndexName.equals(indexName)) {
            if (!this.sqlDialect.isSystemIndex(lastIndexName)) {
                if (!Schema.GLOBAL_UNIQUE_INDEX_SCHEMA.equals(schema)) {
                    TopologyManager.addIndex(sqlgGraph, schema, label, isVertex, lastIndexName, lastIndexType, lastColumns);
                }
            }
            lastColumns.clear();
            lastIndexName = indexName;
            lastIndexType = nonUnique ? IndexType.NON_UNIQUE : IndexType.UNIQUE;
        }
        lastColumns.add(columnName);
    }
    if (!this.sqlDialect.isSystemIndex(lastIndexName)) {
        if (!Schema.GLOBAL_UNIQUE_INDEX_SCHEMA.equals(schema)) {
            TopologyManager.addIndex(sqlgGraph, schema, label, isVertex, lastIndexName, lastIndexType, lastColumns);
        }
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) IndexType(org.umlg.sqlg.structure.topology.IndexType)

Aggregations

Triple (org.apache.commons.lang3.tuple.Triple)1 IndexType (org.umlg.sqlg.structure.topology.IndexType)1