use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class MariaDBDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : create().select(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME).from(TABLES).where(TABLES.TABLE_TYPE.eq("SEQUENCE"))) {
SchemaDefinition schema = getSchema(record.get(TABLES.TABLE_SCHEMA));
if (schema != null) {
String name = record.get(TABLES.TABLE_NAME);
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, BIGINT.getTypeName());
Field<Long> startWith = nullif(field("start_value", BIGINT), inline(1L));
Field<Long> incrementBy = nullif(field("increment", BIGINT), inline(1L));
Field<Long> minValue = inline(field("minimum_value", BIGINT), inline(1L));
Field<Long> maxValue = nullif(field("maximum_value", BIGINT), inline(DEFAULT_SEQUENCE_MAXVALUE));
Field<Boolean> cycle = field("cycle_option", BOOLEAN);
Field<Long> cache = nullif(field("cache_size", BIGINT), inline(DEFAULT_SEQUENCE_CACHE));
Record flags = create().select(startWith, incrementBy, minValue, maxValue, cycle, cache).from(name(schema.getName(), name)).fetchOne();
result.add(new DefaultSequenceDefinition(schema, name, type, null, flags.get(startWith), flags.get(incrementBy), flags.get(minValue), flags.get(maxValue), flags.get(cycle), flags.get(cache)));
}
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class XMLDatabase method getSchemata0.
@Override
protected List<SchemaDefinition> getSchemata0() {
List<SchemaDefinition> result = new ArrayList<>();
for (Schema schema : info().getSchemata()) {
String schemaName = schema.getSchemaName();
result.add(new SchemaDefinition(this, StringUtils.defaultIfNull(schemaName, ""), schema.getComment()));
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class XMLDatabase method getTables0.
@Override
protected List<TableDefinition> getTables0() {
List<TableDefinition> result = new ArrayList<>();
for (Table table : info().getTables()) {
if (getInputSchemata().contains(table.getTableSchema())) {
SchemaDefinition schema = getSchema(table.getTableSchema());
TableType tableType;
switch(table.getTableType()) {
case GLOBAL_TEMPORARY:
tableType = TableType.TEMPORARY;
break;
case VIEW:
tableType = TableType.VIEW;
break;
case BASE_TABLE:
default:
tableType = TableType.TABLE;
break;
}
String source = null;
if (tableType == TableType.VIEW) {
viewLoop: for (View view : info().getViews()) {
if (StringUtils.equals(defaultIfNull(table.getTableCatalog(), ""), defaultIfNull(view.getTableCatalog(), "")) && StringUtils.equals(defaultIfNull(table.getTableSchema(), ""), defaultIfNull(view.getTableSchema(), "")) && StringUtils.equals(defaultIfNull(table.getTableName(), ""), defaultIfNull(view.getTableName(), ""))) {
source = view.getViewDefinition();
break viewLoop;
}
}
}
result.add(new XMLTableDefinition(schema, info(), table, table.getComment(), tableType, source));
}
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class XMLDatabase method getPackages0.
@Override
protected List<PackageDefinition> getPackages0() {
List<PackageDefinition> result = new ArrayList<>();
Set<String> packages = new HashSet<>();
for (Routine routine : info().getRoutines()) {
String schemaName = defaultIfBlank(routine.getSpecificSchema(), routine.getRoutineSchema());
if (getInputSchemata().contains(schemaName)) {
SchemaDefinition schema = getSchema(schemaName);
String packageName = defaultIfBlank(routine.getSpecificPackage(), routine.getRoutinePackage());
if (!isBlank(packageName) && packages.add(packageName)) {
result.add(new XMLPackageDefinition(schema, info(), packageName));
}
}
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class XMLDatabase method getIndexes0.
@Override
protected List<IndexDefinition> getIndexes0() throws SQLException {
List<IndexDefinition> result = new ArrayList<>();
final Map<Name, SortedSet<IndexColumnUsage>> indexColumnUsage = new HashMap<>();
for (IndexColumnUsage ic : info().getIndexColumnUsages()) {
Name name = name(ic.getIndexCatalog(), ic.getIndexSchema(), ic.getTableName(), ic.getIndexName());
SortedSet<IndexColumnUsage> list = indexColumnUsage.computeIfAbsent(name, k -> new TreeSet<>((o1, o2) -> {
int r = 0;
r = defaultIfNull(o1.getIndexCatalog(), "").compareTo(defaultIfNull(o2.getIndexCatalog(), ""));
if (r != 0)
return r;
r = defaultIfNull(o1.getIndexSchema(), "").compareTo(defaultIfNull(o2.getIndexSchema(), ""));
if (r != 0)
return r;
r = defaultIfNull(o1.getTableName(), "").compareTo(defaultIfNull(o2.getTableName(), ""));
if (r != 0)
return r;
r = defaultIfNull(o1.getIndexName(), "").compareTo(defaultIfNull(o2.getIndexName(), ""));
if (r != 0)
return r;
return Integer.compare(o1.getOrdinalPosition(), o2.getOrdinalPosition());
}));
list.add(ic);
}
indexLoop: for (Index i : info().getIndexes()) {
if (getInputSchemata().contains(i.getTableSchema())) {
final SchemaDefinition schema = getSchema(i.getTableSchema());
final TableDefinition table = getTable(schema, i.getTableName());
if (table == null)
continue indexLoop;
final Name name = name(i.getIndexCatalog(), i.getIndexSchema(), i.getTableName(), i.getIndexName());
IndexDefinition index = new AbstractIndexDefinition(schema, i.getIndexName(), table, Boolean.TRUE.equals(i.isIsUnique()), i.getComment()) {
private final List<IndexColumnDefinition> indexColumns;
{
indexColumns = new ArrayList<>();
SortedSet<IndexColumnUsage> list = indexColumnUsage.get(name);
if (list != null)
for (IndexColumnUsage ic : list) {
ColumnDefinition column = table.getColumn(ic.getColumnName());
if (column != null)
indexColumns.add(new DefaultIndexColumnDefinition(this, column, Boolean.TRUE.equals(ic.isIsDescending()) ? SortOrder.DESC : SortOrder.ASC, ic.getOrdinalPosition()));
else
log.error(String.format("Column %s not found in table %s.", ic.getColumnName(), table));
}
else
log.error(String.format("No columns found for index %s.", name));
}
@Override
protected List<IndexColumnDefinition> getIndexColumns0() {
return indexColumns;
}
};
result.add(index);
}
}
return result;
}
Aggregations