From 601f11d011f8ad7bc80f5824c0b2fa1b50db06e5 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Mon, 25 Jul 2016 17:23:28 +0200 Subject: [PATCH] [#5463] Add org.jooq.Meta.getSequences() --- jOOQ/src/main/java/org/jooq/Meta.java | 27 ++++++++++++++++++- .../jooq/impl/InformationSchemaMetaImpl.java | 5 ++++ .../src/main/java/org/jooq/impl/MetaImpl.java | 26 +++++++++++------- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/Meta.java b/jOOQ/src/main/java/org/jooq/Meta.java index 1297fef701..c98a151747 100644 --- a/jOOQ/src/main/java/org/jooq/Meta.java +++ b/jOOQ/src/main/java/org/jooq/Meta.java @@ -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}) *

* 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> 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> getSequences() throws DataAccessException; + /** * Get all primary keys from the underlying {@link DatabaseMetaData}. * diff --git a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java index 8f47171720..a85b5a9e41 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java @@ -238,6 +238,11 @@ final class InformationSchemaMetaImpl implements Meta { return unmodifiableList(tables); } + @Override + public final List> getSequences() { + return unmodifiableList(sequences); + } + @Override public final List> getPrimaryKeys() { return unmodifiableList(primaryKeys); diff --git a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java index f8b13ac2b7..4ebb3e9c71 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java @@ -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 getSchemas() { List result = new ArrayList(); - 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> getTables() { List> result = new ArrayList>(); - for (Schema schema : getSchemas()) { + for (Schema schema : getSchemas()) result.addAll(schema.getTables()); - } + + return result; + } + + @Override + public final List> getSequences() { + List> result = new ArrayList>(); + + 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;