[#5463] Add org.jooq.Meta.getSequences()

This commit is contained in:
lukaseder 2016-07-25 17:23:28 +02:00
parent 18d7071f8d
commit 601f11d011
3 changed files with 47 additions and 11 deletions

View File

@ -40,15 +40,31 @@
*/
package org.jooq;
import static org.jooq.SQLDialect.CUBRID;
// ...
import static org.jooq.SQLDialect.DERBY;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.H2;
// ...
import static org.jooq.SQLDialect.HSQLDB;
// ...
// ...
// ...
import static org.jooq.SQLDialect.POSTGRES;
// ...
// ...
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.jooq.exception.DataAccessException;
import org.jooq.util.xml.jaxb.InformationSchema;
/**
* A wrapping object for {@link DatabaseMetaData}
* A wrapping object for {@link DatabaseMetaData} or for other sources of
* database meta information (e.g. {@link InformationSchema})
* <p>
* This object can be obtained through {@link DSLContext#meta()} in order to
* provide convenient access to your database meta data. This abstraction has
@ -99,6 +115,15 @@ public interface Meta {
@Support
List<Table<?>> getTables() throws DataAccessException;
/**
* Get all sequence objects from the underlying {@link DatabaseMetaData}.
*
* @throws DataAccessException If something went wrong fetching the meta
* objects
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
List<Sequence<?>> getSequences() throws DataAccessException;
/**
* Get all primary keys from the underlying {@link DatabaseMetaData}.
*

View File

@ -238,6 +238,11 @@ final class InformationSchemaMetaImpl implements Meta {
return unmodifiableList(tables);
}
@Override
public final List<Sequence<?>> getSequences() {
return unmodifiableList(sequences);
}
@Override
public final List<UniqueKey<?>> getPrimaryKeys() {
return unmodifiableList(primaryKeys);

View File

@ -116,6 +116,7 @@ import org.jooq.Record;
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.Schema;
import org.jooq.Sequence;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.UniqueKey;
@ -184,15 +185,13 @@ final class MetaImpl implements Meta, Serializable {
}
});
for (String name : catalogs.getValues(0, String.class)) {
for (String name : catalogs.getValues(0, String.class))
result.add(new MetaCatalog(name));
}
}
// There should always be at least one (empty) catalog in a database
if (result.isEmpty()) {
if (result.isEmpty())
result.add(new MetaCatalog(""));
}
return result;
}
@ -201,9 +200,8 @@ final class MetaImpl implements Meta, Serializable {
public final List<Schema> getSchemas() {
List<Schema> result = new ArrayList<Schema>();
for (Catalog catalog : getCatalogs()) {
for (Catalog catalog : getCatalogs())
result.addAll(catalog.getSchemas());
}
return result;
}
@ -212,9 +210,18 @@ final class MetaImpl implements Meta, Serializable {
public final List<Table<?>> getTables() {
List<Table<?>> result = new ArrayList<Table<?>>();
for (Schema schema : getSchemas()) {
for (Schema schema : getSchemas())
result.addAll(schema.getTables());
}
return result;
}
@Override
public final List<Sequence<?>> getSequences() {
List<Sequence<?>> result = new ArrayList<Sequence<?>>();
for (Schema schema : getSchemas())
result.addAll(schema.getSequences());
return result;
}
@ -226,9 +233,8 @@ final class MetaImpl implements Meta, Serializable {
for (Table<?> table : getTables()) {
UniqueKey<?> pk = table.getPrimaryKey();
if (pk != null) {
if (pk != null)
result.add(pk);
}
}
return result;