Skip to content

Commit

Permalink
[#6162] Deprecate plain SQL DSL.sequence(String) constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Apr 26, 2017
1 parent 8970be8 commit 294b06a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
20 changes: 15 additions & 5 deletions jOOQ/src/main/java/org/jooq/Sequence.java
Expand Up @@ -56,33 +56,43 @@
public interface Sequence<T extends Number> extends QueryPart { public interface Sequence<T extends Number> extends QueryPart {


/** /**
* Get the sequence name * Get the sequence name.
*/ */
String getName(); String getName();


/**
* The qualified name of this sequence.
*/
Name getQualifiedName();

/**
* The unqualified name of this sequence.
*/
Name getUnqualifiedName();

/** /**
* Get the sequence catalog. * Get the sequence catalog.
*/ */
Catalog getCatalog(); Catalog getCatalog();


/** /**
* Get the sequence schema * Get the sequence schema.
*/ */
Schema getSchema(); Schema getSchema();


/** /**
* Get the sequence data type * Get the sequence data type.
*/ */
DataType<T> getDataType(); DataType<T> getDataType();


/** /**
* Get the current value of this sequence * Get the current value of this sequence.
*/ */
@Support({ CUBRID, FIREBIRD, H2, POSTGRES }) @Support({ CUBRID, FIREBIRD, H2, POSTGRES })
Field<T> currval(); Field<T> currval();


/** /**
* Increment the sequence and get the next value * Increment the sequence and get the next value.
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
Field<T> nextval(); Field<T> nextval();
Expand Down
9 changes: 8 additions & 1 deletion jOOQ/src/main/java/org/jooq/impl/DSL.java
Expand Up @@ -8642,7 +8642,9 @@ public static Table<Record> table(String sql, QueryPart... parts) {
* @param sql The SQL * @param sql The SQL
* @return A field wrapping the plain SQL * @return A field wrapping the plain SQL
* @see SQL * @see SQL
* @deprecated - 3.10 - [#6162] - Use {@link #sequence(Name)} instead.
*/ */
@Deprecated
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
@PlainSQL @PlainSQL
public static Sequence<BigInteger> sequence(String sql) { public static Sequence<BigInteger> sequence(String sql) {
Expand All @@ -8661,7 +8663,9 @@ public static Sequence<BigInteger> sequence(String sql) {
* @param type The field type * @param type The field type
* @return A field wrapping the plain SQL * @return A field wrapping the plain SQL
* @see SQL * @see SQL
* @deprecated - 3.10 - [#6162] - Use {@link #sequence(Name, Class)} instead.
*/ */
@Deprecated
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
@PlainSQL @PlainSQL
public static <T extends Number> Sequence<T> sequence(String sql, Class<T> type) { public static <T extends Number> Sequence<T> sequence(String sql, Class<T> type) {
Expand All @@ -8680,11 +8684,14 @@ public static <T extends Number> Sequence<T> sequence(String sql, Class<T> type)
* @param type The field type * @param type The field type
* @return A field wrapping the plain SQL * @return A field wrapping the plain SQL
* @see SQL * @see SQL
* @deprecated - 3.10 - [#6162] - Use {@link #sequence(Name, DataType)}
* instead.
*/ */
@Deprecated
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
@PlainSQL @PlainSQL
public static <T extends Number> Sequence<T> sequence(String sql, DataType<T> type) { public static <T extends Number> Sequence<T> sequence(String sql, DataType<T> type) {
return new SequenceImpl<T>(sql, null, type, true); return new SequenceImpl<T>(using(new DefaultConfiguration()).parser().parseName(sql), null, type);
} }


/** /**
Expand Down
30 changes: 21 additions & 9 deletions jOOQ/src/main/java/org/jooq/impl/SequenceImpl.java
Expand Up @@ -48,6 +48,7 @@
import org.jooq.Context; import org.jooq.Context;
import org.jooq.DataType; import org.jooq.DataType;
import org.jooq.Field; import org.jooq.Field;
import org.jooq.Name;
import org.jooq.RenderContext; import org.jooq.RenderContext;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
import org.jooq.Schema; import org.jooq.Schema;
Expand All @@ -69,27 +70,40 @@ public class SequenceImpl<T extends Number> extends AbstractQueryPart implements
private static final long serialVersionUID = 6224349401603636427L; private static final long serialVersionUID = 6224349401603636427L;
private static final Clause[] CLAUSES = { SEQUENCE, SEQUENCE_REFERENCE }; private static final Clause[] CLAUSES = { SEQUENCE, SEQUENCE_REFERENCE };


final String name; final Name name;
final boolean nameIsPlainSQL;
final Schema schema; final Schema schema;
final DataType<T> type; final DataType<T> type;


public SequenceImpl(String name, Schema schema, DataType<T> type) { public SequenceImpl(String name, Schema schema, DataType<T> type) {
this(name, schema, type, false); this(DSL.name(name), schema, type);
} }


SequenceImpl(String name, Schema schema, DataType<T> type, boolean nameIsPlainSQL) { public SequenceImpl(Name name, Schema schema, DataType<T> type) {
this.name = name; this.name = name;
this.schema = schema; this.schema =
schema != null
? schema
: name.qualified()
? DSL.schema(name.qualifier())
: null;
this.type = type; this.type = type;
this.nameIsPlainSQL = nameIsPlainSQL;
} }


@Override @Override
public final String getName() { public final String getName() {
return name.last();
}

@Override
public final Name getQualifiedName() {
return name; return name;
} }


@Override
public final Name getUnqualifiedName() {
return name.unqualifiedName();
}

@Override @Override
public final Catalog getCatalog() { public final Catalog getCatalog() {
return getSchema() == null ? null : getSchema().getCatalog(); return getSchema() == null ? null : getSchema().getCatalog();
Expand Down Expand Up @@ -244,10 +258,8 @@ private final void accept0(Context<?> ctx, boolean asStringLiterals) {


if (asStringLiterals) if (asStringLiterals)
ctx.visit(inline(name)); ctx.visit(inline(name));
else if (nameIsPlainSQL)
ctx.sql(name);
else else
ctx.literal(name); ctx.visit(name);
} }


@Override @Override
Expand Down

0 comments on commit 294b06a

Please sign in to comment.