diff --git a/jOOQ/src/main/java/org/jooq/Sequence.java b/jOOQ/src/main/java/org/jooq/Sequence.java index 4260982684..7b6b3cb6e7 100644 --- a/jOOQ/src/main/java/org/jooq/Sequence.java +++ b/jOOQ/src/main/java/org/jooq/Sequence.java @@ -56,33 +56,43 @@ import static org.jooq.SQLDialect.POSTGRES; public interface Sequence extends QueryPart { /** - * Get the sequence name + * Get the sequence name. */ String getName(); + /** + * The qualified name of this sequence. + */ + Name getQualifiedName(); + + /** + * The unqualified name of this sequence. + */ + Name getUnqualifiedName(); + /** * Get the sequence catalog. */ Catalog getCatalog(); /** - * Get the sequence schema + * Get the sequence schema. */ Schema getSchema(); /** - * Get the sequence data type + * Get the sequence data type. */ DataType getDataType(); /** - * Get the current value of this sequence + * Get the current value of this sequence. */ @Support({ CUBRID, FIREBIRD, H2, POSTGRES }) Field currval(); /** - * Increment the sequence and get the next value + * Increment the sequence and get the next value. */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) Field nextval(); diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 1037a1f316..0057c6a4b1 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -8642,7 +8642,9 @@ public class DSL { * @param sql The SQL * @return A field wrapping the plain SQL * @see SQL + * @deprecated - 3.10 - [#6162] - Use {@link #sequence(Name)} instead. */ + @Deprecated @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) @PlainSQL public static Sequence sequence(String sql) { @@ -8661,7 +8663,9 @@ public class DSL { * @param type The field type * @return A field wrapping the plain SQL * @see SQL + * @deprecated - 3.10 - [#6162] - Use {@link #sequence(Name, Class)} instead. */ + @Deprecated @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) @PlainSQL public static Sequence sequence(String sql, Class type) { @@ -8680,11 +8684,14 @@ public class DSL { * @param type The field type * @return A field wrapping the plain SQL * @see SQL + * @deprecated - 3.10 - [#6162] - Use {@link #sequence(Name, DataType)} + * instead. */ + @Deprecated @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) @PlainSQL public static Sequence sequence(String sql, DataType type) { - return new SequenceImpl(sql, null, type, true); + return new SequenceImpl(using(new DefaultConfiguration()).parser().parseName(sql), null, type); } /** diff --git a/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java b/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java index bb48fa906a..3404059b03 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java @@ -48,6 +48,7 @@ import org.jooq.Configuration; import org.jooq.Context; import org.jooq.DataType; import org.jooq.Field; +import org.jooq.Name; import org.jooq.RenderContext; import org.jooq.SQLDialect; import org.jooq.Schema; @@ -69,27 +70,40 @@ public class SequenceImpl extends AbstractQueryPart implements private static final long serialVersionUID = 6224349401603636427L; private static final Clause[] CLAUSES = { SEQUENCE, SEQUENCE_REFERENCE }; - final String name; - final boolean nameIsPlainSQL; + final Name name; final Schema schema; final DataType type; public SequenceImpl(String name, Schema schema, DataType type) { - this(name, schema, type, false); + this(DSL.name(name), schema, type); } - SequenceImpl(String name, Schema schema, DataType type, boolean nameIsPlainSQL) { + public SequenceImpl(Name name, Schema schema, DataType type) { this.name = name; - this.schema = schema; + this.schema = + schema != null + ? schema + : name.qualified() + ? DSL.schema(name.qualifier()) + : null; this.type = type; - this.nameIsPlainSQL = nameIsPlainSQL; } @Override public final String getName() { + return name.last(); + } + + @Override + public final Name getQualifiedName() { return name; } + @Override + public final Name getUnqualifiedName() { + return name.unqualifiedName(); + } + @Override public final Catalog getCatalog() { return getSchema() == null ? null : getSchema().getCatalog(); @@ -244,10 +258,8 @@ public class SequenceImpl extends AbstractQueryPart implements if (asStringLiterals) ctx.visit(inline(name)); - else if (nameIsPlainSQL) - ctx.sql(name); else - ctx.literal(name); + ctx.visit(name); } @Override