From 8e247e172b856d39d93396e9283a550c8894f17e Mon Sep 17 00:00:00 2001
From: Wynn Teo <49014791+wynnteo@users.noreply.github.com>
Date: Mon, 8 Apr 2024 10:30:35 +0800
Subject: [PATCH] Bael 7668 (#16257)
* BAEL-7490 read write file in separate thread
* Change the to try resources
* Update the code to sync with article
* jooq join table
* Fix the wildcard import
---
.../jooq/jointables/DefaultCatalog.java | 56 +++++
.../baeldung/jooq/jointables/JoinTables.java | 75 ++++++
.../jooq/jointables/public_/Keys.java | 34 +++
.../jooq/jointables/public_/Public.java | 69 +++++
.../jooq/jointables/public_/Tables.java | 32 +++
.../jooq/jointables/public_/tables/Book.java | 238 ++++++++++++++++++
.../jointables/public_/tables/Bookauthor.java | 228 +++++++++++++++++
.../jooq/jointables/public_/tables/Store.java | 223 ++++++++++++++++
.../public_/tables/records/BookRecord.java | 124 +++++++++
.../tables/records/BookauthorRecord.java | 94 +++++++
.../public_/tables/records/StoreRecord.java | 79 ++++++
.../jointables/JoinTablesIntegrationTest.java | 111 ++++++++
.../jooq/src/test/resources/jooq-config-2.xml | 19 ++
13 files changed, 1382 insertions(+)
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/DefaultCatalog.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/JoinTables.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Keys.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Public.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Tables.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Book.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Bookauthor.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Store.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookRecord.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookauthorRecord.java
create mode 100644 persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/StoreRecord.java
create mode 100644 persistence-modules/jooq/src/test/java/com/baeldung/jooq/jointables/JoinTablesIntegrationTest.java
create mode 100644 persistence-modules/jooq/src/test/resources/jooq-config-2.xml
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/DefaultCatalog.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/DefaultCatalog.java
new file mode 100644
index 0000000000..a730e9bfc6
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/DefaultCatalog.java
@@ -0,0 +1,56 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables;
+
+
+import com.baeldung.jooq.jointables.public_.Public;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.jooq.Constants;
+import org.jooq.Schema;
+import org.jooq.impl.CatalogImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class DefaultCatalog extends CatalogImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The reference instance of DEFAULT_CATALOG
+ */
+ public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog();
+
+ /**
+ * The schema public
.
+ */
+ public final Public PUBLIC = Public.PUBLIC;
+
+ /**
+ * No further instances allowed
+ */
+ private DefaultCatalog() {
+ super("");
+ }
+
+ @Override
+ public final List getSchemas() {
+ return Arrays.asList(
+ Public.PUBLIC
+ );
+ }
+
+ /**
+ * A reference to the 3.19 minor release of the code generator. If this
+ * doesn't compile, it's because the runtime library uses an older minor
+ * release, namely: 3.19. You can turn off the generation of this reference
+ * by specifying /configuration/generator/generate/jooqVersionReference
+ */
+ private static final String REQUIRE_RUNTIME_JOOQ_VERSION = Constants.VERSION_3_19;
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/JoinTables.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/JoinTables.java
new file mode 100644
index 0000000000..2c67ef2ad3
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/JoinTables.java
@@ -0,0 +1,75 @@
+package com.baeldung.jooq.jointables;
+
+import static org.jooq.impl.DSL.field;
+
+import org.jooq.DSLContext;
+import org.jooq.Record;
+import org.jooq.Result;
+import org.jooq.SelectJoinStep;
+
+import com.baeldung.jooq.jointables.public_.Tables;
+
+public class JoinTables {
+
+ public static Result usingJoinMethod(DSLContext context) {
+ SelectJoinStep query = context.select()
+ .from(Tables.BOOK)
+ .join(Tables.BOOKAUTHOR)
+ .on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
+ return query.fetch();
+ }
+
+ public static Result usingMultipleJoinMethod(DSLContext context) {
+ SelectJoinStep query = context.select()
+ .from(Tables.BOOK)
+ .join(Tables.BOOKAUTHOR)
+ .on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)))
+ .join(Tables.STORE)
+ .on(field(Tables.BOOK.STORE_ID).eq(field(Tables.STORE.ID)));
+ return query.fetch();
+ }
+
+ public static Result usingLeftOuterJoinMethod(DSLContext context) {
+ SelectJoinStep query = context.select()
+ .from(Tables.BOOK)
+ .leftOuterJoin(Tables.BOOKAUTHOR)
+ .on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
+ return query.fetch();
+ }
+
+ public static Result usingRightOuterJoinMethod(DSLContext context) {
+ SelectJoinStep query = context.select()
+ .from(Tables.BOOK)
+ .rightOuterJoin(Tables.BOOKAUTHOR)
+ .on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
+ return query.fetch();
+ }
+
+ public static Result usingFullOuterJoinMethod(DSLContext context) {
+ SelectJoinStep query = context.select()
+ .from(Tables.BOOK)
+ .fullOuterJoin(Tables.BOOKAUTHOR)
+ .on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
+ return query.fetch();
+ }
+
+ public static Result usingNaturalJoinMethod(DSLContext context) {
+ SelectJoinStep query = context.select()
+ .from(Tables.BOOK)
+ .naturalJoin(Tables.BOOKAUTHOR);
+ return query.fetch();
+ }
+
+ public static Result usingCrossJoinMethod(DSLContext context) {
+ SelectJoinStep query = context.select()
+ .from(Tables.STORE)
+ .crossJoin(Tables.BOOK);
+ return query.fetch();
+ }
+
+ public static void printResult(Result result) {
+ for (Record record : result) {
+ System.out.println(record);
+ }
+ }
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Keys.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Keys.java
new file mode 100644
index 0000000000..86c1939891
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Keys.java
@@ -0,0 +1,34 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_;
+
+
+import com.baeldung.jooq.jointables.public_.tables.Book;
+import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
+import com.baeldung.jooq.jointables.public_.tables.Store;
+import com.baeldung.jooq.jointables.public_.tables.records.BookRecord;
+import com.baeldung.jooq.jointables.public_.tables.records.BookauthorRecord;
+import com.baeldung.jooq.jointables.public_.tables.records.StoreRecord;
+
+import org.jooq.TableField;
+import org.jooq.UniqueKey;
+import org.jooq.impl.DSL;
+import org.jooq.impl.Internal;
+
+
+/**
+ * A class modelling foreign key relationships and constraints of tables in
+ * public.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class Keys {
+
+ // -------------------------------------------------------------------------
+ // UNIQUE and PRIMARY KEY definitions
+ // -------------------------------------------------------------------------
+
+ public static final UniqueKey BOOK_PKEY = Internal.createUniqueKey(Book.BOOK, DSL.name("Book_pkey"), new TableField[] { Book.BOOK.ID }, true);
+ public static final UniqueKey AUTHOR_PKEY = Internal.createUniqueKey(Bookauthor.BOOKAUTHOR, DSL.name("Author_pkey"), new TableField[] { Bookauthor.BOOKAUTHOR.ID }, true);
+ public static final UniqueKey STORE_PKEY = Internal.createUniqueKey(Store.STORE, DSL.name("Store_pkey"), new TableField[] { Store.STORE.ID }, true);
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Public.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Public.java
new file mode 100644
index 0000000000..1b2e8dda87
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Public.java
@@ -0,0 +1,69 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_;
+
+
+import com.baeldung.jooq.jointables.DefaultCatalog;
+import com.baeldung.jooq.jointables.public_.tables.Book;
+import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
+import com.baeldung.jooq.jointables.public_.tables.Store;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.jooq.Catalog;
+import org.jooq.Table;
+import org.jooq.impl.SchemaImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class Public extends SchemaImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The reference instance of public
+ */
+ public static final Public PUBLIC = new Public();
+
+ /**
+ * The table public.Book
.
+ */
+ public final Book BOOK = Book.BOOK;
+
+ /**
+ * The table public.BookAuthor
.
+ */
+ public final Bookauthor BOOKAUTHOR = Bookauthor.BOOKAUTHOR;
+
+ /**
+ * The table public.Store
.
+ */
+ public final Store STORE = Store.STORE;
+
+ /**
+ * No further instances allowed
+ */
+ private Public() {
+ super("public", null);
+ }
+
+
+ @Override
+ public Catalog getCatalog() {
+ return DefaultCatalog.DEFAULT_CATALOG;
+ }
+
+ @Override
+ public final List> getTables() {
+ return Arrays.asList(
+ Book.BOOK,
+ Bookauthor.BOOKAUTHOR,
+ Store.STORE
+ );
+ }
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Tables.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Tables.java
new file mode 100644
index 0000000000..789c131a25
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/Tables.java
@@ -0,0 +1,32 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_;
+
+
+import com.baeldung.jooq.jointables.public_.tables.Book;
+import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
+import com.baeldung.jooq.jointables.public_.tables.Store;
+
+
+/**
+ * Convenience access to all tables in public.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class Tables {
+
+ /**
+ * The table public.Book
.
+ */
+ public static final Book BOOK = Book.BOOK;
+
+ /**
+ * The table public.BookAuthor
.
+ */
+ public static final Bookauthor BOOKAUTHOR = Bookauthor.BOOKAUTHOR;
+
+ /**
+ * The table public.Store
.
+ */
+ public static final Store STORE = Store.STORE;
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Book.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Book.java
new file mode 100644
index 0000000000..4e21648cbd
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Book.java
@@ -0,0 +1,238 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_.tables;
+
+
+import com.baeldung.jooq.jointables.public_.Keys;
+import com.baeldung.jooq.jointables.public_.Public;
+import com.baeldung.jooq.jointables.public_.tables.records.BookRecord;
+
+import java.util.Collection;
+
+import org.jooq.Condition;
+import org.jooq.Field;
+import org.jooq.Name;
+import org.jooq.PlainSQL;
+import org.jooq.QueryPart;
+import org.jooq.SQL;
+import org.jooq.Schema;
+import org.jooq.Select;
+import org.jooq.Stringly;
+import org.jooq.Table;
+import org.jooq.TableField;
+import org.jooq.TableOptions;
+import org.jooq.UniqueKey;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+import org.jooq.impl.TableImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class Book extends TableImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The reference instance of public.Book
+ */
+ public static final Book BOOK = new Book();
+
+ /**
+ * The class holding records for this type
+ */
+ @Override
+ public Class getRecordType() {
+ return BookRecord.class;
+ }
+
+ /**
+ * The column public.Book.id
.
+ */
+ public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false), this, "");
+
+ /**
+ * The column public.Book.author_id
.
+ */
+ public final TableField AUTHOR_ID = createField(DSL.name("author_id"), SQLDataType.INTEGER, this, "");
+
+ /**
+ * The column public.Book.title
.
+ */
+ public final TableField TITLE = createField(DSL.name("title"), SQLDataType.VARCHAR, this, "");
+
+ /**
+ * The column public.Book.description
.
+ */
+ public final TableField DESCRIPTION = createField(DSL.name("description"), SQLDataType.VARCHAR, this, "");
+
+ /**
+ * The column public.Book.store_id
.
+ */
+ public final TableField STORE_ID = createField(DSL.name("store_id"), SQLDataType.INTEGER, this, "");
+
+ private Book(Name alias, Table aliased) {
+ this(alias, aliased, (Field>[]) null, null);
+ }
+
+ private Book(Name alias, Table aliased, Field>[] parameters, Condition where) {
+ super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table(), where);
+ }
+
+ /**
+ * Create an aliased public.Book
table reference
+ */
+ public Book(String alias) {
+ this(DSL.name(alias), BOOK);
+ }
+
+ /**
+ * Create an aliased public.Book
table reference
+ */
+ public Book(Name alias) {
+ this(alias, BOOK);
+ }
+
+ /**
+ * Create a public.Book
table reference
+ */
+ public Book() {
+ this(DSL.name("Book"), null);
+ }
+
+ @Override
+ public Schema getSchema() {
+ return aliased() ? null : Public.PUBLIC;
+ }
+
+ @Override
+ public UniqueKey getPrimaryKey() {
+ return Keys.BOOK_PKEY;
+ }
+
+ @Override
+ public Book as(String alias) {
+ return new Book(DSL.name(alias), this);
+ }
+
+ @Override
+ public Book as(Name alias) {
+ return new Book(alias, this);
+ }
+
+ @Override
+ public Book as(Table> alias) {
+ return new Book(alias.getQualifiedName(), this);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Book rename(String name) {
+ return new Book(DSL.name(name), null);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Book rename(Name name) {
+ return new Book(name, null);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Book rename(Table> name) {
+ return new Book(name.getQualifiedName(), null);
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Book where(Condition condition) {
+ return new Book(getQualifiedName(), aliased() ? this : null, null, condition);
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Book where(Collection extends Condition> conditions) {
+ return where(DSL.and(conditions));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Book where(Condition... conditions) {
+ return where(DSL.and(conditions));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Book where(Field condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Book where(SQL condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Book where(@Stringly.SQL String condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Book where(@Stringly.SQL String condition, Object... binds) {
+ return where(DSL.condition(condition, binds));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Book where(@Stringly.SQL String condition, QueryPart... parts) {
+ return where(DSL.condition(condition, parts));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Book whereExists(Select> select) {
+ return where(DSL.exists(select));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Book whereNotExists(Select> select) {
+ return where(DSL.notExists(select));
+ }
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Bookauthor.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Bookauthor.java
new file mode 100644
index 0000000000..9d828e9add
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Bookauthor.java
@@ -0,0 +1,228 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_.tables;
+
+
+import com.baeldung.jooq.jointables.public_.Keys;
+import com.baeldung.jooq.jointables.public_.Public;
+import com.baeldung.jooq.jointables.public_.tables.records.BookauthorRecord;
+
+import java.util.Collection;
+
+import org.jooq.Condition;
+import org.jooq.Field;
+import org.jooq.Name;
+import org.jooq.PlainSQL;
+import org.jooq.QueryPart;
+import org.jooq.SQL;
+import org.jooq.Schema;
+import org.jooq.Select;
+import org.jooq.Stringly;
+import org.jooq.Table;
+import org.jooq.TableField;
+import org.jooq.TableOptions;
+import org.jooq.UniqueKey;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+import org.jooq.impl.TableImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class Bookauthor extends TableImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The reference instance of public.BookAuthor
+ */
+ public static final Bookauthor BOOKAUTHOR = new Bookauthor();
+
+ /**
+ * The class holding records for this type
+ */
+ @Override
+ public Class getRecordType() {
+ return BookauthorRecord.class;
+ }
+
+ /**
+ * The column public.BookAuthor.id
.
+ */
+ public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false), this, "");
+
+ /**
+ * The column public.BookAuthor.name
.
+ */
+ public final TableField NAME = createField(DSL.name("name"), SQLDataType.VARCHAR.nullable(false), this, "");
+
+ /**
+ * The column public.BookAuthor.country
.
+ */
+ public final TableField COUNTRY = createField(DSL.name("country"), SQLDataType.VARCHAR, this, "");
+
+ private Bookauthor(Name alias, Table aliased) {
+ this(alias, aliased, (Field>[]) null, null);
+ }
+
+ private Bookauthor(Name alias, Table aliased, Field>[] parameters, Condition where) {
+ super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table(), where);
+ }
+
+ /**
+ * Create an aliased public.BookAuthor
table reference
+ */
+ public Bookauthor(String alias) {
+ this(DSL.name(alias), BOOKAUTHOR);
+ }
+
+ /**
+ * Create an aliased public.BookAuthor
table reference
+ */
+ public Bookauthor(Name alias) {
+ this(alias, BOOKAUTHOR);
+ }
+
+ /**
+ * Create a public.BookAuthor
table reference
+ */
+ public Bookauthor() {
+ this(DSL.name("BookAuthor"), null);
+ }
+
+ @Override
+ public Schema getSchema() {
+ return aliased() ? null : Public.PUBLIC;
+ }
+
+ @Override
+ public UniqueKey getPrimaryKey() {
+ return Keys.AUTHOR_PKEY;
+ }
+
+ @Override
+ public Bookauthor as(String alias) {
+ return new Bookauthor(DSL.name(alias), this);
+ }
+
+ @Override
+ public Bookauthor as(Name alias) {
+ return new Bookauthor(alias, this);
+ }
+
+ @Override
+ public Bookauthor as(Table> alias) {
+ return new Bookauthor(alias.getQualifiedName(), this);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Bookauthor rename(String name) {
+ return new Bookauthor(DSL.name(name), null);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Bookauthor rename(Name name) {
+ return new Bookauthor(name, null);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Bookauthor rename(Table> name) {
+ return new Bookauthor(name.getQualifiedName(), null);
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Bookauthor where(Condition condition) {
+ return new Bookauthor(getQualifiedName(), aliased() ? this : null, null, condition);
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Bookauthor where(Collection extends Condition> conditions) {
+ return where(DSL.and(conditions));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Bookauthor where(Condition... conditions) {
+ return where(DSL.and(conditions));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Bookauthor where(Field condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Bookauthor where(SQL condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Bookauthor where(@Stringly.SQL String condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Bookauthor where(@Stringly.SQL String condition, Object... binds) {
+ return where(DSL.condition(condition, binds));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Bookauthor where(@Stringly.SQL String condition, QueryPart... parts) {
+ return where(DSL.condition(condition, parts));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Bookauthor whereExists(Select> select) {
+ return where(DSL.exists(select));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Bookauthor whereNotExists(Select> select) {
+ return where(DSL.notExists(select));
+ }
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Store.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Store.java
new file mode 100644
index 0000000000..d97f3da21b
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/Store.java
@@ -0,0 +1,223 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_.tables;
+
+
+import com.baeldung.jooq.jointables.public_.Keys;
+import com.baeldung.jooq.jointables.public_.Public;
+import com.baeldung.jooq.jointables.public_.tables.records.StoreRecord;
+
+import java.util.Collection;
+
+import org.jooq.Condition;
+import org.jooq.Field;
+import org.jooq.Name;
+import org.jooq.PlainSQL;
+import org.jooq.QueryPart;
+import org.jooq.SQL;
+import org.jooq.Schema;
+import org.jooq.Select;
+import org.jooq.Stringly;
+import org.jooq.Table;
+import org.jooq.TableField;
+import org.jooq.TableOptions;
+import org.jooq.UniqueKey;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+import org.jooq.impl.TableImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class Store extends TableImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The reference instance of public.Store
+ */
+ public static final Store STORE = new Store();
+
+ /**
+ * The class holding records for this type
+ */
+ @Override
+ public Class getRecordType() {
+ return StoreRecord.class;
+ }
+
+ /**
+ * The column public.Store.id
.
+ */
+ public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false), this, "");
+
+ /**
+ * The column public.Store.name
.
+ */
+ public final TableField NAME = createField(DSL.name("name"), SQLDataType.VARCHAR.nullable(false), this, "");
+
+ private Store(Name alias, Table aliased) {
+ this(alias, aliased, (Field>[]) null, null);
+ }
+
+ private Store(Name alias, Table aliased, Field>[] parameters, Condition where) {
+ super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table(), where);
+ }
+
+ /**
+ * Create an aliased public.Store
table reference
+ */
+ public Store(String alias) {
+ this(DSL.name(alias), STORE);
+ }
+
+ /**
+ * Create an aliased public.Store
table reference
+ */
+ public Store(Name alias) {
+ this(alias, STORE);
+ }
+
+ /**
+ * Create a public.Store
table reference
+ */
+ public Store() {
+ this(DSL.name("Store"), null);
+ }
+
+ @Override
+ public Schema getSchema() {
+ return aliased() ? null : Public.PUBLIC;
+ }
+
+ @Override
+ public UniqueKey getPrimaryKey() {
+ return Keys.STORE_PKEY;
+ }
+
+ @Override
+ public Store as(String alias) {
+ return new Store(DSL.name(alias), this);
+ }
+
+ @Override
+ public Store as(Name alias) {
+ return new Store(alias, this);
+ }
+
+ @Override
+ public Store as(Table> alias) {
+ return new Store(alias.getQualifiedName(), this);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Store rename(String name) {
+ return new Store(DSL.name(name), null);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Store rename(Name name) {
+ return new Store(name, null);
+ }
+
+ /**
+ * Rename this table
+ */
+ @Override
+ public Store rename(Table> name) {
+ return new Store(name.getQualifiedName(), null);
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Store where(Condition condition) {
+ return new Store(getQualifiedName(), aliased() ? this : null, null, condition);
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Store where(Collection extends Condition> conditions) {
+ return where(DSL.and(conditions));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Store where(Condition... conditions) {
+ return where(DSL.and(conditions));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Store where(Field condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Store where(SQL condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Store where(@Stringly.SQL String condition) {
+ return where(DSL.condition(condition));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Store where(@Stringly.SQL String condition, Object... binds) {
+ return where(DSL.condition(condition, binds));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ @PlainSQL
+ public Store where(@Stringly.SQL String condition, QueryPart... parts) {
+ return where(DSL.condition(condition, parts));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Store whereExists(Select> select) {
+ return where(DSL.exists(select));
+ }
+
+ /**
+ * Create an inline derived table from this table
+ */
+ @Override
+ public Store whereNotExists(Select> select) {
+ return where(DSL.notExists(select));
+ }
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookRecord.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookRecord.java
new file mode 100644
index 0000000000..0636ff2fdf
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookRecord.java
@@ -0,0 +1,124 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_.tables.records;
+
+
+import com.baeldung.jooq.jointables.public_.tables.Book;
+
+import org.jooq.Record1;
+import org.jooq.impl.UpdatableRecordImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class BookRecord extends UpdatableRecordImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Setter for public.Book.id
.
+ */
+ public void setId(Integer value) {
+ set(0, value);
+ }
+
+ /**
+ * Getter for public.Book.id
.
+ */
+ public Integer getId() {
+ return (Integer) get(0);
+ }
+
+ /**
+ * Setter for public.Book.author_id
.
+ */
+ public void setAuthorId(Integer value) {
+ set(1, value);
+ }
+
+ /**
+ * Getter for public.Book.author_id
.
+ */
+ public Integer getAuthorId() {
+ return (Integer) get(1);
+ }
+
+ /**
+ * Setter for public.Book.title
.
+ */
+ public void setTitle(String value) {
+ set(2, value);
+ }
+
+ /**
+ * Getter for public.Book.title
.
+ */
+ public String getTitle() {
+ return (String) get(2);
+ }
+
+ /**
+ * Setter for public.Book.description
.
+ */
+ public void setDescription(String value) {
+ set(3, value);
+ }
+
+ /**
+ * Getter for public.Book.description
.
+ */
+ public String getDescription() {
+ return (String) get(3);
+ }
+
+ /**
+ * Setter for public.Book.store_id
.
+ */
+ public void setStoreId(Integer value) {
+ set(4, value);
+ }
+
+ /**
+ * Getter for public.Book.store_id
.
+ */
+ public Integer getStoreId() {
+ return (Integer) get(4);
+ }
+
+ // -------------------------------------------------------------------------
+ // Primary key information
+ // -------------------------------------------------------------------------
+
+ @Override
+ public Record1 key() {
+ return (Record1) super.key();
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create a detached BookRecord
+ */
+ public BookRecord() {
+ super(Book.BOOK);
+ }
+
+ /**
+ * Create a detached, initialised BookRecord
+ */
+ public BookRecord(Integer id, Integer authorId, String title, String description, Integer storeId) {
+ super(Book.BOOK);
+
+ setId(id);
+ setAuthorId(authorId);
+ setTitle(title);
+ setDescription(description);
+ setStoreId(storeId);
+ resetChangedOnNotNull();
+ }
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookauthorRecord.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookauthorRecord.java
new file mode 100644
index 0000000000..0e99b2d93b
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/BookauthorRecord.java
@@ -0,0 +1,94 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_.tables.records;
+
+
+import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
+
+import org.jooq.Record1;
+import org.jooq.impl.UpdatableRecordImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class BookauthorRecord extends UpdatableRecordImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Setter for public.BookAuthor.id
.
+ */
+ public void setId(Integer value) {
+ set(0, value);
+ }
+
+ /**
+ * Getter for public.BookAuthor.id
.
+ */
+ public Integer getId() {
+ return (Integer) get(0);
+ }
+
+ /**
+ * Setter for public.BookAuthor.name
.
+ */
+ public void setName(String value) {
+ set(1, value);
+ }
+
+ /**
+ * Getter for public.BookAuthor.name
.
+ */
+ public String getName() {
+ return (String) get(1);
+ }
+
+ /**
+ * Setter for public.BookAuthor.country
.
+ */
+ public void setCountry(String value) {
+ set(2, value);
+ }
+
+ /**
+ * Getter for public.BookAuthor.country
.
+ */
+ public String getCountry() {
+ return (String) get(2);
+ }
+
+ // -------------------------------------------------------------------------
+ // Primary key information
+ // -------------------------------------------------------------------------
+
+ @Override
+ public Record1 key() {
+ return (Record1) super.key();
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create a detached BookauthorRecord
+ */
+ public BookauthorRecord() {
+ super(Bookauthor.BOOKAUTHOR);
+ }
+
+ /**
+ * Create a detached, initialised BookauthorRecord
+ */
+ public BookauthorRecord(Integer id, String name, String country) {
+ super(Bookauthor.BOOKAUTHOR);
+
+ setId(id);
+ setName(name);
+ setCountry(country);
+ resetChangedOnNotNull();
+ }
+}
diff --git a/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/StoreRecord.java b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/StoreRecord.java
new file mode 100644
index 0000000000..f8628818e3
--- /dev/null
+++ b/persistence-modules/jooq/src/main/java/com/baeldung/jooq/jointables/public_/tables/records/StoreRecord.java
@@ -0,0 +1,79 @@
+/*
+ * This file is generated by jOOQ.
+ */
+package com.baeldung.jooq.jointables.public_.tables.records;
+
+
+import com.baeldung.jooq.jointables.public_.tables.Store;
+
+import org.jooq.Record1;
+import org.jooq.impl.UpdatableRecordImpl;
+
+
+/**
+ * This class is generated by jOOQ.
+ */
+@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
+public class StoreRecord extends UpdatableRecordImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Setter for public.Store.id
.
+ */
+ public void setId(Integer value) {
+ set(0, value);
+ }
+
+ /**
+ * Getter for public.Store.id
.
+ */
+ public Integer getId() {
+ return (Integer) get(0);
+ }
+
+ /**
+ * Setter for public.Store.name
.
+ */
+ public void setName(String value) {
+ set(1, value);
+ }
+
+ /**
+ * Getter for public.Store.name
.
+ */
+ public String getName() {
+ return (String) get(1);
+ }
+
+ // -------------------------------------------------------------------------
+ // Primary key information
+ // -------------------------------------------------------------------------
+
+ @Override
+ public Record1 key() {
+ return (Record1) super.key();
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create a detached StoreRecord
+ */
+ public StoreRecord() {
+ super(Store.STORE);
+ }
+
+ /**
+ * Create a detached, initialised StoreRecord
+ */
+ public StoreRecord(Integer id, String name) {
+ super(Store.STORE);
+
+ setId(id);
+ setName(name);
+ resetChangedOnNotNull();
+ }
+}
diff --git a/persistence-modules/jooq/src/test/java/com/baeldung/jooq/jointables/JoinTablesIntegrationTest.java b/persistence-modules/jooq/src/test/java/com/baeldung/jooq/jointables/JoinTablesIntegrationTest.java
new file mode 100644
index 0000000000..5396c27e14
--- /dev/null
+++ b/persistence-modules/jooq/src/test/java/com/baeldung/jooq/jointables/JoinTablesIntegrationTest.java
@@ -0,0 +1,111 @@
+package com.baeldung.jooq.jointables;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.jooq.DSLContext;
+import org.jooq.Record;
+import org.jooq.Result;
+import org.jooq.SQLDialect;
+import org.jooq.impl.DSL;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.baeldung.jooq.jointables.public_.Tables;
+import com.baeldung.jooq.jointables.public_.tables.Book;
+import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
+import com.baeldung.jooq.jointables.public_.tables.Store;
+
+public class JoinTablesIntegrationTest {
+
+ static DSLContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ // URL jooqConfigURL = getClass().getClassLoader().getResource("jooq-config-2.xml");
+ // File file = new File(jooqConfigURL.getFile());
+ // GenerationTool.generate(Files.readString(file.toPath()));
+
+ String url = "jdbc:postgresql://localhost:5432/postgres";
+ String username = "postgres";
+ String password = "";
+
+ Connection conn = DriverManager.getConnection(url, username, password);
+ context = DSL.using(conn, SQLDialect.POSTGRES);
+
+ context.insertInto(Tables.STORE, Store.STORE.ID, Store.STORE.NAME)
+ .values(1, "ABC Branch I ")
+ .values(2, "ABC Branch II")
+ .execute();
+
+ context.insertInto(Tables.BOOK, Book.BOOK.ID, Book.BOOK.TITLE, Book.BOOK.DESCRIPTION, Book.BOOK.AUTHOR_ID, Book.BOOK.STORE_ID)
+ .values(1, "Book 1", "This is book 1", 1, 1)
+ .values(2, "Book 2", "This is book 2", 2, 2)
+ .values(3, "Book 3", "This is book 3", 1, 2)
+ .values(4, "Book 4", "This is book 4", 5, 1)
+ .execute();
+
+ context.insertInto(Tables.BOOKAUTHOR, Bookauthor.BOOKAUTHOR.ID, Bookauthor.BOOKAUTHOR.NAME, Bookauthor.BOOKAUTHOR.COUNTRY)
+ .values(1, "John Smith", "Japan")
+ .values(2, "William Walce", "Japan")
+ .values(3, "Marry Sity", "South Korea")
+ .values(4, "Morry Toh", "England")
+ .execute();
+ }
+
+ @AfterClass
+ public static void cleanup() throws Exception {
+ context.truncateTable(Store.STORE)
+ .execute();
+ context.truncateTable(Book.BOOK)
+ .execute();
+ context.truncateTable(Bookauthor.BOOKAUTHOR)
+ .execute();
+ }
+
+ @Test
+ public void _whenUsingJoinMethod_thenQueryExecuted() {
+ Result result = JoinTables.usingJoinMethod(context);
+ assertEquals(3, result.size());
+ }
+
+ @Test
+ public void _whenUsingMultipleJoinMethod_thenQueryExecuted() {
+ Result result = JoinTables.usingMultipleJoinMethod(context);
+ assertEquals(3, result.size());
+ }
+
+ @Test
+ public void givenContext_whenUsingLeftOuterJoinMethod_thenQueryExecuted() {
+ Result result = JoinTables.usingLeftOuterJoinMethod(context);
+ assertEquals(4, result.size());
+ }
+
+ @Test
+ public void whenUsingRightOuterJoinMethod_thenQueryExecuted() {
+ Result result = JoinTables.usingRightOuterJoinMethod(context);
+ assertEquals(5, result.size());
+ }
+
+ @Test
+ public void whenUsingFullOuterJoinMethod_thenQueryExecuted() {
+ Result result = JoinTables.usingFullOuterJoinMethod(context);
+ assertEquals(6, result.size());
+ }
+
+ @Test
+ public void whenUsingNaturalJoinMethod_thenQueryExecuted() {
+ Result result = JoinTables.usingNaturalJoinMethod(context);
+ assertEquals(4, result.size());
+ }
+
+ @Test
+ public void whenUsingCrossJoinMethod_thenQueryExecuted() {
+ Result result = JoinTables.usingCrossJoinMethod(context);
+ assertEquals(8, result.size());
+ }
+}
diff --git a/persistence-modules/jooq/src/test/resources/jooq-config-2.xml b/persistence-modules/jooq/src/test/resources/jooq-config-2.xml
new file mode 100644
index 0000000000..a644e3fef5
--- /dev/null
+++ b/persistence-modules/jooq/src/test/resources/jooq-config-2.xml
@@ -0,0 +1,19 @@
+
+
+ org.postgresql.Driver
+ jdbc:postgresql://localhost:5432/postgres
+ postgres
+
+
+
+
+ org.jooq.meta.postgres.PostgresDatabase
+ Store|Book|BookAuthor
+
+
+
+ com.baeldung.jooq.jointables
+ src/main/java
+
+
+