use of org.jooq.meta.AbstractIndexDefinition in project jOOQ by jOOQ.
the class H2Database method getIndexes0.
@Override
protected List<IndexDefinition> getIndexes0() throws SQLException {
List<IndexDefinition> result = new ArrayList<>();
// Same implementation as in HSQLDBDatabase and MySQLDatabase
Map<Record, Result<Record>> indexes = indexes().fetchGroups(new Field[] { INDEXES.TABLE_SCHEMA, INDEXES.TABLE_NAME, INDEXES.INDEX_NAME, INDEXES.NON_UNIQUE }, new Field[] { INDEXES.COLUMN_NAME, INDEXES.ORDINAL_POSITION });
indexLoop: for (Entry<Record, Result<Record>> entry : indexes.entrySet()) {
final Record index = entry.getKey();
final Result<Record> columns = entry.getValue();
final SchemaDefinition tableSchema = getSchema(index.get(INDEXES.TABLE_SCHEMA));
if (tableSchema == null)
continue indexLoop;
final String indexName = index.get(INDEXES.INDEX_NAME);
final String tableName = index.get(INDEXES.TABLE_NAME);
final TableDefinition table = getTable(tableSchema, tableName);
if (table == null)
continue indexLoop;
final boolean unique = !index.get(INDEXES.NON_UNIQUE, boolean.class);
// [#6310] [#6620] Function-based indexes are not yet supported
for (Record column : columns) if (table.getColumn(column.get(INDEXES.COLUMN_NAME)) == null)
continue indexLoop;
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
List<IndexColumnDefinition> indexColumns = new ArrayList<>();
{
for (Record column : columns) {
indexColumns.add(new DefaultIndexColumnDefinition(this, table.getColumn(column.get(INDEXES.COLUMN_NAME)), SortOrder.ASC, column.get(INDEXES.ORDINAL_POSITION, int.class)));
}
}
@Override
protected List<IndexColumnDefinition> getIndexColumns0() {
return indexColumns;
}
});
}
return result;
}
use of org.jooq.meta.AbstractIndexDefinition in project jOOQ by jOOQ.
the class SQLiteDatabase method getIndexes0.
@Override
protected List<IndexDefinition> getIndexes0() throws SQLException {
final List<IndexDefinition> result = new ArrayList<>();
final Field<String> fIndexName = field("il.name", String.class).as("index_name");
final Field<Boolean> fUnique = field("il.\"unique\"", boolean.class).as("unique");
final Field<Integer> fSeqno = field("ii.seqno", int.class).add(one()).as("seqno");
final Field<String> fColumnName = field("ii.name", String.class).as("column_name");
Map<Record, Result<Record>> indexes = create().select(SQLiteMaster.NAME, fIndexName, fUnique, fSeqno, fColumnName).from(SQLITE_MASTER, table("pragma_index_list({0})", SQLiteMaster.NAME).as("il"), table("pragma_index_info(il.name)").as("ii")).where(SQLiteMaster.TYPE.eq(inline("table"))).and(getIncludeSystemIndexes() ? noCondition() : field("il.origin", VARCHAR).notIn(inline("pk"), inline("u"))).orderBy(1, 2, 4).fetchGroups(new Field[] { SQLiteMaster.NAME, fIndexName, fUnique }, new Field[] { fColumnName, fSeqno });
indexLoop: for (Entry<Record, Result<Record>> entry : indexes.entrySet()) {
final Record index = entry.getKey();
final Result<Record> columns = entry.getValue();
final SchemaDefinition tableSchema = getSchemata().get(0);
if (tableSchema == null)
continue indexLoop;
final String indexName = index.get(fIndexName);
final String tableName = index.get(SQLiteMaster.NAME);
final TableDefinition table = getTable(tableSchema, tableName);
if (table == null)
continue indexLoop;
final boolean unique = index.get(fUnique);
// [#6310] [#6620] Function-based indexes are not yet supported
for (Record column : columns) if (table.getColumn(column.get(fColumnName)) == null)
continue indexLoop;
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
List<IndexColumnDefinition> indexColumns = new ArrayList<>();
{
for (Record column : columns) {
indexColumns.add(new DefaultIndexColumnDefinition(this, table.getColumn(column.get(fColumnName)), SortOrder.ASC, column.get(fSeqno, int.class)));
}
}
@Override
protected List<IndexColumnDefinition> getIndexColumns0() {
return indexColumns;
}
});
}
return result;
}
Aggregations