From 213ba8d3115e54d6cedb344fe281b952dab92eea Mon Sep 17 00:00:00 2001 From: lukaseder Date: Mon, 14 May 2018 09:40:31 +0200 Subject: [PATCH] [#7484] Add DSLContext.selectFrom(Name) and selectFrom(String) overloads --- jOOQ/src/main/java/org/jooq/DSLContext.java | 87 +++++++++++ jOOQ/src/main/java/org/jooq/WithStep.java | 87 +++++++++++ jOOQ/src/main/java/org/jooq/impl/DSL.java | 142 ++++++++++++++++++ .../java/org/jooq/impl/DefaultDSLContext.java | 25 +++ .../src/main/java/org/jooq/impl/WithImpl.java | 27 ++++ 5 files changed, 368 insertions(+) diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index e2522b38af..ca2e7c0648 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -5518,6 +5518,93 @@ public interface DSLContext extends Scope , AutoCloseable { @Support SelectWhereStep selectFrom(Table table); + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ * + * @see DSL#table(Name) + */ + @Support + SelectWhereStep selectFrom(Name table); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(SQL) + * @see SQL + */ + @Support + SelectWhereStep selectFrom(SQL sql); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String) + * @see DSL#sql(String) + * @see SQL + */ + @Support + SelectWhereStep selectFrom(String sql); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see SQL + */ + @Support + SelectWhereStep selectFrom(String sql, Object... bindings); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see SQL + */ + @Support + SelectWhereStep selectFrom(String sql, QueryPart... parts); + /** * Create a new DSL select statement. *

diff --git a/jOOQ/src/main/java/org/jooq/WithStep.java b/jOOQ/src/main/java/org/jooq/WithStep.java index d56f968c8f..8fcf4203ff 100644 --- a/jOOQ/src/main/java/org/jooq/WithStep.java +++ b/jOOQ/src/main/java/org/jooq/WithStep.java @@ -484,6 +484,93 @@ public interface WithStep extends QueryPart { @Support({ FIREBIRD, H2, HSQLDB, MYSQL_8_0, POSTGRES }) SelectWhereStep selectFrom(Table table); + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ * + * @see DSL#table(Name) + */ + @Support({ FIREBIRD, H2, HSQLDB, MYSQL_8_0, POSTGRES }) + SelectWhereStep selectFrom(Name table); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(SQL) + * @see SQL + */ + @Support({ FIREBIRD, H2, HSQLDB, MYSQL_8_0, POSTGRES }) + SelectWhereStep selectFrom(SQL sql); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String) + * @see DSL#sql(String) + * @see SQL + */ + @Support({ FIREBIRD, H2, HSQLDB, MYSQL_8_0, POSTGRES }) + SelectWhereStep selectFrom(String sql); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see SQL + */ + @Support({ FIREBIRD, H2, HSQLDB, MYSQL_8_0, POSTGRES }) + SelectWhereStep selectFrom(String sql, Object... bindings); + + /** + * Create a new DSL select statement. + *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see SQL + */ + @Support({ FIREBIRD, H2, HSQLDB, MYSQL_8_0, POSTGRES }) + SelectWhereStep selectFrom(String sql, QueryPart... parts); + /** * Create a new DSL select statement. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 3b8f40d0ba..edb8d9710c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -2647,6 +2647,148 @@ public class DSL { return dsl().selectFrom(table); } + /** + * Create a new DSL select statement. + *

+ * Unlike {@link Select} factory methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * SELECT statement. You can use this statement in two ways: + *

    + *
  • As a subselect within another select
  • + *
  • As a statement, after attaching it using + * {@link Select#attach(org.jooq.Configuration)}
  • + *
+ *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ * + * @see DSL#table(Name) + */ + @Support + public static SelectWhereStep selectFrom(Name table) { + return dsl().selectFrom(table); + } + + /** + * Create a new DSL select statement. + *

+ * Unlike {@link Select} factory methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * SELECT statement. You can use this statement in two ways: + *

    + *
  • As a subselect within another select
  • + *
  • As a statement, after attaching it using + * {@link Select#attach(org.jooq.Configuration)}
  • + *
+ *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(SQL) + * @see SQL + */ + @Support + public static SelectWhereStep selectFrom(SQL sql) { + return dsl().selectFrom(sql); + } + + /** + * Create a new DSL select statement. + *

+ * Unlike {@link Select} factory methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * SELECT statement. You can use this statement in two ways: + *

    + *
  • As a subselect within another select
  • + *
  • As a statement, after attaching it using + * {@link Select#attach(org.jooq.Configuration)}
  • + *
+ *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String) + * @see DSL#sql(String) + * @see SQL + */ + @Support + public static SelectWhereStep selectFrom(String sql) { + return dsl().selectFrom(sql); + } + + /** + * Create a new DSL select statement. + *

+ * Unlike {@link Select} factory methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * SELECT statement. You can use this statement in two ways: + *

    + *
  • As a subselect within another select
  • + *
  • As a statement, after attaching it using + * {@link Select#attach(org.jooq.Configuration)}
  • + *
+ *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see SQL + */ + @Support + public static SelectWhereStep selectFrom(String sql, Object... bindings) { + return dsl().selectFrom(sql, bindings); + } + + /** + * Create a new DSL select statement. + *

+ * Unlike {@link Select} factory methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * SELECT statement. You can use this statement in two ways: + *

    + *
  • As a subselect within another select
  • + *
  • As a statement, after attaching it using + * {@link Select#attach(org.jooq.Configuration)}
  • + *
+ *

+ * Example:

+     * SELECT * FROM [table] WHERE [conditions] ORDER BY [ordering] LIMIT [limit clause]
+     * 
+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see SQL + */ + @Support + public static SelectWhereStep selectFrom(String sql, QueryPart... parts) { + return dsl().selectFrom(sql, parts); + } + /** * Create a new DSL subselect statement. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index fb0ea3ffe7..ff11ce5787 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -2115,6 +2115,31 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new SelectImpl(configuration(), null).from(table); } + @Override + public SelectWhereStep selectFrom(Name table) { + return new SelectImpl(configuration(), null).from(table); + } + + @Override + public SelectWhereStep selectFrom(SQL sql) { + return new SelectImpl(configuration(), null).from(sql); + } + + @Override + public SelectWhereStep selectFrom(String sql) { + return new SelectImpl(configuration(), null).from(sql); + } + + @Override + public SelectWhereStep selectFrom(String sql, Object... bindings) { + return new SelectImpl(configuration(), null).from(sql, bindings); + } + + @Override + public SelectWhereStep selectFrom(String sql, QueryPart... parts) { + return new SelectImpl(configuration(), null).from(sql, parts); + } + @Override public SelectSelectStep select(Collection fields) { return new SelectImpl(configuration(), null).select(fields); diff --git a/jOOQ/src/main/java/org/jooq/impl/WithImpl.java b/jOOQ/src/main/java/org/jooq/impl/WithImpl.java index a35d299bde..110be89afd 100644 --- a/jOOQ/src/main/java/org/jooq/impl/WithImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/WithImpl.java @@ -64,6 +64,7 @@ import org.jooq.Field; import org.jooq.InsertSetStep; import org.jooq.MergeUsingStep; import org.jooq.Name; +import org.jooq.QueryPart; import org.jooq.Record; import org.jooq.Record1; import org.jooq.Record10; @@ -87,6 +88,7 @@ import org.jooq.Record6; import org.jooq.Record7; import org.jooq.Record8; import org.jooq.Record9; +import org.jooq.SQL; import org.jooq.SQLDialect; import org.jooq.Select; import org.jooq.SelectField; @@ -514,6 +516,31 @@ implements return new SelectImpl(configuration, this).from(table); } + @Override + public final SelectWhereStep selectFrom(Name table) { + return new SelectImpl(configuration, this).from(table); + } + + @Override + public final SelectWhereStep selectFrom(SQL sql) { + return new SelectImpl(configuration, this).from(sql); + } + + @Override + public final SelectWhereStep selectFrom(String sql) { + return new SelectImpl(configuration, this).from(sql); + } + + @Override + public final SelectWhereStep selectFrom(String sql, Object... bindings) { + return new SelectImpl(configuration, this).from(sql, bindings); + } + + @Override + public final SelectWhereStep selectFrom(String sql, QueryPart... parts) { + return new SelectImpl(configuration, this).from(sql, parts); + } + @Override public final SelectSelectStep select(Collection fields) { return new SelectImpl(configuration, this).select(fields);