[#1902] Duplicate SELECT API between Executor and Factory
This commit is contained in:
parent
9df9b9a4af
commit
ee0a230c7f
@ -35,6 +35,7 @@
|
||||
*/
|
||||
package org.jooq.examples;
|
||||
|
||||
import static org.jooq.impl.Factory.selectDistinct;
|
||||
import static org.jooq.test.mysql.generatedclasses.Tables.T_LANGUAGE;
|
||||
import static org.jooq.test.mysql.generatedclasses.tables.TAuthor.T_AUTHOR;
|
||||
import static org.jooq.test.mysql.generatedclasses.tables.TBook.T_BOOK;
|
||||
@ -171,15 +172,15 @@ public class Library {
|
||||
// WHERE T_BOOK.STATUS = 'SOLD OUT');
|
||||
|
||||
for (TAuthorRecord record : create().selectFrom(T_AUTHOR)
|
||||
.where(TAuthor.ID.in(create().selectDistinct(TBook.AUTHOR_ID)
|
||||
.where(TAuthor.ID.in(selectDistinct(TBook.AUTHOR_ID)
|
||||
.from(T_BOOK).where(TBook.STATUS.equal(TBookStatus.SOLD_OUT)))).fetch()) {
|
||||
|
||||
System.out.println("Author : " + record.getFirstName() + " " + record.getLastName() + " has sold out books");
|
||||
}
|
||||
|
||||
for (TAuthorRecord record : create().selectFrom(T_AUTHOR)
|
||||
.where(TAuthor.ID.in(create()
|
||||
.selectDistinct(TBook.AUTHOR_ID)
|
||||
.where(TAuthor.ID.in(
|
||||
selectDistinct(TBook.AUTHOR_ID)
|
||||
.from(T_BOOK)
|
||||
.where(TBook.LANGUAGE_ID.in(
|
||||
create().select(TLanguage.ID)
|
||||
|
||||
@ -49,6 +49,7 @@ import static org.jooq.impl.Factory.lower;
|
||||
import static org.jooq.impl.Factory.max;
|
||||
import static org.jooq.impl.Factory.one;
|
||||
import static org.jooq.impl.Factory.prior;
|
||||
import static org.jooq.impl.Factory.select;
|
||||
import static org.jooq.impl.Factory.substring;
|
||||
import static org.jooq.impl.Factory.sum;
|
||||
import static org.jooq.impl.Factory.sysConnectByPath;
|
||||
@ -213,8 +214,8 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
Field<Integer> lang = TBook_LANGUAGE_ID().cast(Integer.class).as("lang");
|
||||
Result<Record> result3 =
|
||||
create().select()
|
||||
.from(table(create().select(TBook_AUTHOR_ID(), lang)
|
||||
.from(TBook()))
|
||||
.from(table(select(TBook_AUTHOR_ID(), lang)
|
||||
.from(TBook()))
|
||||
.pivot(count())
|
||||
.on(lang)
|
||||
.in(1, 2, 3, 4))
|
||||
|
||||
@ -47,6 +47,7 @@ import static org.jooq.impl.Factory.groupingId;
|
||||
import static org.jooq.impl.Factory.groupingSets;
|
||||
import static org.jooq.impl.Factory.one;
|
||||
import static org.jooq.impl.Factory.rollup;
|
||||
import static org.jooq.impl.Factory.selectOne;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -140,7 +141,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
.groupBy(TAuthor_LAST_NAME())
|
||||
.having(count().equal(2))
|
||||
.or(count().greaterOrEqual(2))
|
||||
.andExists(create().selectOne())
|
||||
.andExists(selectOne())
|
||||
.fetch();
|
||||
|
||||
assertEquals(1, result.size());
|
||||
|
||||
@ -55,6 +55,8 @@ import static org.jooq.impl.Factory.castNull;
|
||||
import static org.jooq.impl.Factory.count;
|
||||
import static org.jooq.impl.Factory.inline;
|
||||
import static org.jooq.impl.Factory.max;
|
||||
import static org.jooq.impl.Factory.select;
|
||||
import static org.jooq.impl.Factory.selectOne;
|
||||
import static org.jooq.impl.Factory.val;
|
||||
import static org.jooq.impl.Factory.vals;
|
||||
|
||||
@ -364,14 +366,14 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
|
||||
Insert<A> i =
|
||||
create().insertInto(TAuthor())
|
||||
.select(create().select(vals(
|
||||
1000,
|
||||
val("Lukas")))
|
||||
.select(vals(
|
||||
"Eder",
|
||||
val(new Date(363589200000L)),
|
||||
castNull(Integer.class),
|
||||
nullField)));
|
||||
.select(select(vals(
|
||||
1000,
|
||||
val("Lukas")))
|
||||
.select(vals(
|
||||
"Eder",
|
||||
val(new Date(363589200000L)),
|
||||
castNull(Integer.class),
|
||||
nullField)));
|
||||
|
||||
assertEquals(1, i.execute());
|
||||
|
||||
@ -383,7 +385,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
|
||||
// [#1069] Run checks for INSERT INTO t(a, b) SELECT x, y syntax
|
||||
i = create().insertInto(TAuthor(), TAuthor_ID(), TAuthor_LAST_NAME())
|
||||
.select(create().select(vals(1001, "Hesse")));
|
||||
.select(select(vals(1001, "Hesse")));
|
||||
|
||||
assertEquals(1, i.execute());
|
||||
A author2 = create().fetchOne(TAuthor(), TAuthor_LAST_NAME().equal("Hesse"));
|
||||
@ -679,7 +681,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
// Always do an update of everything
|
||||
// --------------------------------
|
||||
create().mergeInto(TAuthor())
|
||||
.using(create().selectOne())
|
||||
.using(selectOne())
|
||||
.on("1 = 1")
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor_FIRST_NAME(), "Alfred")
|
||||
@ -695,7 +697,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
// Always do an update of the first author
|
||||
// --------------------------------
|
||||
create().mergeInto(TAuthor())
|
||||
.using(create().selectOne())
|
||||
.using(selectOne())
|
||||
.on(TAuthor_ID().equal(1))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor_FIRST_NAME(), "John")
|
||||
@ -715,7 +717,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
// --------------------------------
|
||||
MergeFinalStep<A> q =
|
||||
create().mergeInto(TAuthor())
|
||||
.using(create().select(f, l))
|
||||
.using(select(f, l))
|
||||
.on(TAuthor_LAST_NAME().equal(l))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor_FIRST_NAME(), "James")
|
||||
@ -841,8 +843,8 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
// in the system temporary table space, otherwise
|
||||
|
||||
// [#579] TODO: Aliasing shouldn't be necessary
|
||||
.select(create().select(val(3).as("a"), inline("Eder").as("b")).unionAll(
|
||||
create().select(val(4).as("a"), inline("Eder").as("b"))))
|
||||
.select(select(val(3).as("a"), inline("Eder").as("b")).unionAll(
|
||||
select(val(4).as("a"), inline("Eder").as("b"))))
|
||||
.execute());
|
||||
|
||||
Result<A> authors4 = create().selectFrom(TAuthor()).orderBy(TAuthor_ID()).fetch();
|
||||
|
||||
@ -49,6 +49,8 @@ import static org.jooq.impl.Factory.falseCondition;
|
||||
import static org.jooq.impl.Factory.field;
|
||||
import static org.jooq.impl.Factory.lower;
|
||||
import static org.jooq.impl.Factory.one;
|
||||
import static org.jooq.impl.Factory.select;
|
||||
import static org.jooq.impl.Factory.selectOne;
|
||||
import static org.jooq.impl.Factory.val;
|
||||
import static org.jooq.impl.Factory.zero;
|
||||
|
||||
@ -109,7 +111,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
create().select()
|
||||
.from(TAuthor())
|
||||
.join(TBook()).on(TAuthor_ID().equal(TBook_AUTHOR_ID()))
|
||||
.crossJoin(create().select(one().as("one")))
|
||||
.crossJoin(select(one().as("one")))
|
||||
.orderBy(TBook_ID())
|
||||
.fetch();
|
||||
|
||||
@ -173,10 +175,10 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
.from(TAuthor())
|
||||
.join(TBook())
|
||||
.on(TAuthor_ID().equal(TBook_AUTHOR_ID())
|
||||
.and(TBook_LANGUAGE_ID().in(create().select(field("id"))
|
||||
.from("t_language")
|
||||
.where("upper(cd) in (?, ?)", "DE", "EN")))
|
||||
.orExists(create().selectOne().from(TAuthor()).where(falseCondition())))
|
||||
.and(TBook_LANGUAGE_ID().in(select(field("id"))
|
||||
.from("t_language")
|
||||
.where("upper(cd) in (?, ?)", "DE", "EN")))
|
||||
.orExists(selectOne().from(TAuthor()).where(falseCondition())))
|
||||
.orderBy(TBook_ID()).fetch();
|
||||
|
||||
assertEquals(3, result.size());
|
||||
@ -191,10 +193,10 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
.from(author)
|
||||
.join(TBook())
|
||||
.on(author.getField(TAuthor_ID()).equal(TBook_AUTHOR_ID()))
|
||||
.and(TBook_LANGUAGE_ID().in(create().select(field("id"))
|
||||
.from("t_language")
|
||||
.where("upper(cd) in (?, ?)", "DE", "EN")))
|
||||
.orExists(create().selectOne().where(falseCondition()))
|
||||
.and(TBook_LANGUAGE_ID().in(select(field("id"))
|
||||
.from("t_language")
|
||||
.where("upper(cd) in (?, ?)", "DE", "EN")))
|
||||
.orExists(selectOne().where(falseCondition()))
|
||||
.orderBy(TBook_ID()).fetch();
|
||||
|
||||
assertEquals(3, result.size());
|
||||
@ -207,10 +209,11 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
.from(TAuthor())
|
||||
.join(book)
|
||||
.on(TAuthor_ID().equal(book.getField(TBook_AUTHOR_ID())))
|
||||
.and(book.getField(TBook_LANGUAGE_ID()).in(create().select(field("id"))
|
||||
.from("t_language")
|
||||
.where("upper(cd) in (?, ?)", "DE", "EN")))
|
||||
.orExists(create().selectOne().where(falseCondition()))
|
||||
.and(book.getField(TBook_LANGUAGE_ID()).in(
|
||||
select(field("id"))
|
||||
.from("t_language")
|
||||
.where("upper(cd) in (?, ?)", "DE", "EN")))
|
||||
.orExists(selectOne().where(falseCondition()))
|
||||
.orderBy(book.getField(TBook_ID())).fetch();
|
||||
|
||||
assertEquals(3, result.size());
|
||||
|
||||
@ -50,6 +50,7 @@ import static org.jooq.impl.Factory.currentDate;
|
||||
import static org.jooq.impl.Factory.inline;
|
||||
import static org.jooq.impl.Factory.not;
|
||||
import static org.jooq.impl.Factory.row;
|
||||
import static org.jooq.impl.Factory.select;
|
||||
import static org.jooq.impl.Factory.val;
|
||||
|
||||
import java.sql.Date;
|
||||
@ -129,15 +130,15 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
else {
|
||||
assertEquals(1, (int)
|
||||
create().selectOne()
|
||||
.where(row(1, 2, 3).in(create().select(val(1), val(2), val(3))))
|
||||
.and(row(1, 2, 3).notIn(create().select(val(3), val(2), val(1))))
|
||||
.where(row(1, 2, 3).in(select(val(1), val(2), val(3))))
|
||||
.and(row(1, 2, 3).notIn(select(val(3), val(2), val(1))))
|
||||
.fetchOne(0, Integer.class));
|
||||
|
||||
// CUBRID has a bug here http://jira.cubrid.org/browse/ENGINE-61
|
||||
if (!asList(CUBRID).contains(getDialect())) {
|
||||
assertEquals(1, (int)
|
||||
create().selectOne()
|
||||
.where(row(1, 2, 3).in(create().select(val(1), val(2), val(3))))
|
||||
.where(row(1, 2, 3).in(select(val(1), val(2), val(3))))
|
||||
.and(row(3, 2).notIn(
|
||||
create().select(val(2), val(3)).union(
|
||||
create().select(val(4), val(3)))))
|
||||
|
||||
@ -40,6 +40,8 @@ import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.jooq.impl.Factory.count;
|
||||
import static org.jooq.impl.Factory.countDistinct;
|
||||
import static org.jooq.impl.Factory.select;
|
||||
import static org.jooq.impl.Factory.selectOne;
|
||||
import static org.jooq.impl.Factory.trim;
|
||||
import static org.jooq.impl.Factory.val;
|
||||
|
||||
@ -162,8 +164,8 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
// ---------------------------------------------------------------------
|
||||
assertEquals(3,
|
||||
create().selectFrom(TBook())
|
||||
.where(TBook_TITLE().notIn(create()
|
||||
.select(TBook_TITLE())
|
||||
.where(TBook_TITLE().notIn(
|
||||
select(TBook_TITLE())
|
||||
.from(TBook())
|
||||
.where(TBook_TITLE().in("1984"))))
|
||||
.execute());
|
||||
@ -174,14 +176,14 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
assertEquals(3,
|
||||
create()
|
||||
.selectFrom(TBook())
|
||||
.whereNotExists(create()
|
||||
.selectOne()
|
||||
.whereNotExists(
|
||||
selectOne()
|
||||
.from(TAuthor())
|
||||
.where(TAuthor_YEAR_OF_BIRTH().greaterOrEqual(TBook_PUBLISHED_IN())))
|
||||
|
||||
// Add additional useless queries to check query correctness
|
||||
.orNotExists(create().select())
|
||||
.andExists(create().select()).execute());
|
||||
.orNotExists(select())
|
||||
.andExists(select()).execute());
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Testing selecting from a select
|
||||
|
||||
@ -323,6 +323,12 @@ public interface FactoryOperations extends Configuration {
|
||||
/**
|
||||
* Create a new DSL select statement.
|
||||
* <p>
|
||||
* This creates an attached, renderable and executable <code>SELECT</code>
|
||||
* statement from this {@link Executor}. If you don't need to render or
|
||||
* execute this <code>SELECT</code> statement (e.g. because you want to
|
||||
* create a subselect), consider using the static
|
||||
* {@link Factory#select(Field...)} instead.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
@ -333,13 +339,93 @@ public interface FactoryOperations extends Configuration {
|
||||
* .orderBy(field2)
|
||||
* .execute();
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#select(Field...)
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep select(Field<?>... fields);
|
||||
|
||||
/**
|
||||
* Create a new DSL select statement.
|
||||
* <p>
|
||||
* This creates an attached, renderable and executable <code>SELECT</code>
|
||||
* statement from this {@link Executor}. If you don't need to render or
|
||||
* execute this <code>SELECT</code> statement (e.g. because you want to
|
||||
* create a subselect), consider using the static
|
||||
* {@link Factory#select(Collection)} instead.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
* create.select(fields)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#select(Collection)
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep select(Collection<? extends Field<?>> fields);
|
||||
|
||||
/**
|
||||
* Create a new DSL select statement.
|
||||
* <p>
|
||||
* This creates an attached, renderable and executable <code>SELECT</code>
|
||||
* statement from this {@link Executor}. If you don't need to render or
|
||||
* execute this <code>SELECT</code> statement (e.g. because you want to
|
||||
* create a subselect), consider using the static
|
||||
* {@link Factory#selectDistinct(Field...)} instead.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
* create.selectDistinct(field1, field2)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#selectDistinct(Field...)
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep selectDistinct(Field<?>... fields);
|
||||
|
||||
/**
|
||||
* Create a new DSL select statement.
|
||||
* <p>
|
||||
* This creates an attached, renderable and executable <code>SELECT</code>
|
||||
* statement from this {@link Executor}. If you don't need to render or
|
||||
* execute this <code>SELECT</code> statement (e.g. because you want to
|
||||
* create a subselect), consider using the static
|
||||
* {@link Factory#selectDistinct(Collection)} instead.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
* create.selectDistinct(fields)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#selectDistinct(Collection)
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep selectDistinct(Collection<? extends Field<?>> fields);
|
||||
|
||||
/**
|
||||
* Create a new DSL select statement for constant <code>0</code> literal
|
||||
* <p>
|
||||
* This creates an attached, renderable and executable <code>SELECT</code>
|
||||
* statement from this {@link Executor}. If you don't need to render or
|
||||
* execute this <code>SELECT</code> statement (e.g. because you want to
|
||||
* create a subselect), consider using the static
|
||||
* {@link Factory#selectZero()} instead.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
@ -352,6 +438,7 @@ public interface FactoryOperations extends Configuration {
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#zero()
|
||||
* @see Factory#selectZero()
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep selectZero();
|
||||
@ -359,6 +446,12 @@ public interface FactoryOperations extends Configuration {
|
||||
/**
|
||||
* Create a new DSL select statement for constant <code>1</code> literal
|
||||
* <p>
|
||||
* This creates an attached, renderable and executable <code>SELECT</code>
|
||||
* statement from this {@link Executor}. If you don't need to render or
|
||||
* execute this <code>SELECT</code> statement (e.g. because you want to
|
||||
* create a subselect), consider using the static
|
||||
* {@link Factory#selectOne()} instead.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
@ -371,6 +464,7 @@ public interface FactoryOperations extends Configuration {
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#one()
|
||||
* @see Factory#selectOne()
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep selectOne();
|
||||
@ -378,6 +472,12 @@ public interface FactoryOperations extends Configuration {
|
||||
/**
|
||||
* Create a new DSL select statement for <code>COUNT(*)</code>
|
||||
* <p>
|
||||
* This creates an attached, renderable and executable <code>SELECT</code>
|
||||
* statement from this {@link Executor}. If you don't need to render or
|
||||
* execute this <code>SELECT</code> statement (e.g. because you want to
|
||||
* create a subselect), consider using the static
|
||||
* {@link Factory#selectCount()} instead.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
@ -388,58 +488,12 @@ public interface FactoryOperations extends Configuration {
|
||||
* .orderBy(field2)
|
||||
* .execute();
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#selectCount()
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep selectCount();
|
||||
|
||||
/**
|
||||
* Create a new DSL select statement.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
* create.selectDistinct(field1, field2)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep selectDistinct(Field<?>... fields);
|
||||
|
||||
/**
|
||||
* Create a new DSL select statement.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
* create.select(fields)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep select(Collection<? extends Field<?>> fields);
|
||||
|
||||
/**
|
||||
* Create a new DSL select statement.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* Factory create = new Factory();
|
||||
*
|
||||
* create.selectDistinct(fields)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*/
|
||||
@Support
|
||||
SelectSelectStep selectDistinct(Collection<? extends Field<?>> fields);
|
||||
|
||||
/**
|
||||
* Create a new {@link SelectQuery}
|
||||
*/
|
||||
|
||||
@ -37,12 +37,9 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.conf.SettingsTools.getRenderMapping;
|
||||
import static org.jooq.impl.Factory.count;
|
||||
import static org.jooq.impl.Factory.field;
|
||||
import static org.jooq.impl.Factory.fieldByName;
|
||||
import static org.jooq.impl.Factory.one;
|
||||
import static org.jooq.impl.Factory.trueCondition;
|
||||
import static org.jooq.impl.Factory.zero;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@ -114,6 +111,8 @@ import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.csv.CSVReader;
|
||||
|
||||
/**
|
||||
* TODO: Review this Javadoc
|
||||
* <p>
|
||||
* A factory providing implementations to the org.jooq interfaces
|
||||
* <p>
|
||||
* This factory is the main entry point for client code, to access jOOQ classes
|
||||
@ -1066,39 +1065,9 @@ public class Executor implements FactoryOperations {
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep select(Field<?>... fields) {
|
||||
return new SelectImpl(this).select(fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectZero() {
|
||||
return new SelectImpl(this).select(zero());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectOne() {
|
||||
return new SelectImpl(this).select(one());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectCount() {
|
||||
return new SelectImpl(this).select(count());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectDistinct(Field<?>... fields) {
|
||||
return new SelectImpl(this, true).select(fields);
|
||||
SelectSelectStep result = Factory.select(fields);
|
||||
result.attach(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1106,7 +1075,19 @@ public class Executor implements FactoryOperations {
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep select(Collection<? extends Field<?>> fields) {
|
||||
return new SelectImpl(this).select(fields);
|
||||
SelectSelectStep result = Factory.select(fields);
|
||||
result.attach(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectDistinct(Field<?>... fields) {
|
||||
SelectSelectStep result = Factory.selectDistinct(fields);
|
||||
result.attach(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1114,7 +1095,39 @@ public class Executor implements FactoryOperations {
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectDistinct(Collection<? extends Field<?>> fields) {
|
||||
return new SelectImpl(this, true).select(fields);
|
||||
SelectSelectStep result = Factory.selectDistinct(fields);
|
||||
result.attach(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectZero() {
|
||||
SelectSelectStep result = Factory.selectZero();
|
||||
result.attach(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectOne() {
|
||||
SelectSelectStep result = Factory.selectOne();
|
||||
result.attach(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final SelectSelectStep selectCount() {
|
||||
SelectSelectStep result = Factory.selectCount();
|
||||
result.attach(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -49,6 +49,7 @@ import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
import static org.jooq.impl.DefaultConfiguration.DEFAULT_CONFIGURATION;
|
||||
import static org.jooq.impl.Term.ROW_NUMBER;
|
||||
import static org.jooq.impl.Utils.combine;
|
||||
|
||||
@ -91,6 +92,7 @@ import org.jooq.RowN;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.SelectSelectStep;
|
||||
import org.jooq.Support;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.UDTRecord;
|
||||
@ -106,6 +108,230 @@ import org.jooq.types.DayToSecond;
|
||||
*/
|
||||
public class Factory {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX Static subselect factory methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new DSL subselect statement.
|
||||
* <p>
|
||||
* Unlike {@link Select} factory methods in the {@link Executor} API, this
|
||||
* creates an unattached, and thus not directly renderable or executable
|
||||
* <code>SELECT</code> statement. You can use this statement in two ways:
|
||||
* <ul>
|
||||
* <li>As a subselect within another select</li>
|
||||
* <li>As a statement, after attaching it using
|
||||
* {@link Select#attach(org.jooq.Configuration)}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* import static org.jooq.impl.Factory.*;
|
||||
*
|
||||
* // [...]
|
||||
*
|
||||
* select(field1, field2)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see FactoryOperations#select(Field...)
|
||||
*/
|
||||
@Support
|
||||
public static SelectSelectStep select(Field<?>... fields) {
|
||||
return new SelectImpl(DEFAULT_CONFIGURATION).select(fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL subselect statement.
|
||||
* <p>
|
||||
* Unlike {@link Select} factory methods in the {@link Executor} API, this
|
||||
* creates an unattached, and thus not directly renderable or executable
|
||||
* <code>SELECT</code> statement. You can use this statement in two ways:
|
||||
* <ul>
|
||||
* <li>As a subselect within another select</li>
|
||||
* <li>As a statement, after attaching it using
|
||||
* {@link Select#attach(org.jooq.Configuration)}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* import static org.jooq.impl.Factory.*;
|
||||
*
|
||||
* // [...]
|
||||
*
|
||||
* select(fields)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see FactoryOperations#select(Collection)
|
||||
*/
|
||||
@Support
|
||||
public static SelectSelectStep select(Collection<? extends Field<?>> fields) {
|
||||
return new SelectImpl(DEFAULT_CONFIGURATION).select(fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL subselect statement.
|
||||
* <p>
|
||||
* Unlike {@link Select} factory methods in the {@link Executor} API, this
|
||||
* creates an unattached, and thus not directly renderable or executable
|
||||
* <code>SELECT</code> statement. You can use this statement in two ways:
|
||||
* <ul>
|
||||
* <li>As a subselect within another select</li>
|
||||
* <li>As a statement, after attaching it using
|
||||
* {@link Select#attach(org.jooq.Configuration)}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* import static org.jooq.impl.Factory.*;
|
||||
*
|
||||
* // [...]
|
||||
*
|
||||
* selectDistinct(field1, field2)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see FactoryOperations#selectDistinct(Field...)
|
||||
*/
|
||||
@Support
|
||||
public static SelectSelectStep selectDistinct(Field<?>... fields) {
|
||||
return new SelectImpl(DEFAULT_CONFIGURATION, true).select(fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL subselect statement.
|
||||
* <p>
|
||||
* Unlike {@link Select} factory methods in the {@link Executor} API, this
|
||||
* creates an unattached, and thus not directly renderable or executable
|
||||
* <code>SELECT</code> statement. You can use this statement in two ways:
|
||||
* <ul>
|
||||
* <li>As a subselect within another select</li>
|
||||
* <li>As a statement, after attaching it using
|
||||
* {@link Select#attach(org.jooq.Configuration)}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* import static org.jooq.impl.Factory.*;
|
||||
*
|
||||
* // [...]
|
||||
*
|
||||
* selectDistinct(fields)
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see FactoryOperations#selectDistinct(Collection)
|
||||
*/
|
||||
@Support
|
||||
public static SelectSelectStep selectDistinct(Collection<? extends Field<?>> fields) {
|
||||
return new SelectImpl(DEFAULT_CONFIGURATION, true).select(fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL subselect statement.
|
||||
* <p>
|
||||
* Unlike {@link Select} factory methods in the {@link Executor} API, this
|
||||
* creates an unattached, and thus not directly renderable or executable
|
||||
* <code>SELECT</code> statement. You can use this statement in two ways:
|
||||
* <ul>
|
||||
* <li>As a subselect within another select</li>
|
||||
* <li>As a statement, after attaching it using
|
||||
* {@link Select#attach(org.jooq.Configuration)}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* import static org.jooq.impl.Factory.*;
|
||||
*
|
||||
* // [...]
|
||||
*
|
||||
* selectZero()
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#zero()
|
||||
* @see FactoryOperations#selectZero()
|
||||
*/
|
||||
@Support
|
||||
public static SelectSelectStep selectZero() {
|
||||
return new SelectImpl(DEFAULT_CONFIGURATION).select(zero());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL subselect statement.
|
||||
* <p>
|
||||
* Unlike {@link Select} factory methods in the {@link Executor} API, this
|
||||
* creates an unattached, and thus not directly renderable or executable
|
||||
* <code>SELECT</code> statement. You can use this statement in two ways:
|
||||
* <ul>
|
||||
* <li>As a subselect within another select</li>
|
||||
* <li>As a statement, after attaching it using
|
||||
* {@link Select#attach(org.jooq.Configuration)}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* import static org.jooq.impl.Factory.*;
|
||||
*
|
||||
* // [...]
|
||||
*
|
||||
* selectOne()
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#one()
|
||||
* @see FactoryOperations#selectOne()
|
||||
*/
|
||||
@Support
|
||||
public static SelectSelectStep selectOne() {
|
||||
return new SelectImpl(DEFAULT_CONFIGURATION).select(one());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL subselect statement.
|
||||
* <p>
|
||||
* Unlike {@link Select} factory methods in the {@link Executor} API, this
|
||||
* creates an unattached, and thus not directly renderable or executable
|
||||
* <code>SELECT</code> statement. You can use this statement in two ways:
|
||||
* <ul>
|
||||
* <li>As a subselect within another select</li>
|
||||
* <li>As a statement, after attaching it using
|
||||
* {@link Select#attach(org.jooq.Configuration)}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* import static org.jooq.impl.Factory.*;
|
||||
*
|
||||
* // [...]
|
||||
*
|
||||
* selectCount()
|
||||
* .from(table1)
|
||||
* .join(table2).on(field1.equal(field2))
|
||||
* .where(field1.greaterThan(100))
|
||||
* .orderBy(field2);
|
||||
* </pre></code>
|
||||
*
|
||||
* @see Factory#count()
|
||||
* @see FactoryOperations#selectCount()
|
||||
*/
|
||||
@Support
|
||||
public static SelectSelectStep selectCount() {
|
||||
return new SelectImpl(DEFAULT_CONFIGURATION).select(count());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX Quantified comparison predicate expressions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user