From 673230c0b614d3ad3cf02eb7ec5726762ed8e0a4 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Mon, 13 Jun 2022 14:18:52 +0200 Subject: [PATCH] [jOOQ/jOOQ#8997] Remove jOOQ-spring-example --- jOOQ-examples/jOOQ-spring-example/.gitignore | 2 - jOOQ-examples/jOOQ-spring-example/LICENSE.txt | 19 -- jOOQ-examples/jOOQ-spring-example/README.md | 26 --- jOOQ-examples/jOOQ-spring-example/pom.xml | 218 ------------------ .../org/jooq/example/spring/BookService.java | 59 ----- .../example/spring/SpringTransaction.java | 50 ---- .../spring/SpringTransactionProvider.java | 87 ------- .../spring/exception/ExceptionTranslator.java | 80 ------- .../spring/impl/DefaultBookService.java | 69 ------ .../src/main/resources/META-INF/LICENSE.txt | 19 -- .../src/main/resources/META-INF/README.txt | 5 - .../src/main/resources/config.properties | 11 - .../src/main/resources/db-h2.sql | 78 ------- .../src/main/resources/jooq-spring.xml | 66 ------ .../src/main/resources/log4j2.xml | 34 --- .../org/jooq/example/JdbcTemplateTest.java | 128 ---------- .../test/java/org/jooq/example/QueryTest.java | 109 --------- .../org/jooq/example/TransactionTest.java | 217 ----------------- jOOQ-examples/pom.xml | 1 - 19 files changed, 1278 deletions(-) delete mode 100644 jOOQ-examples/jOOQ-spring-example/.gitignore delete mode 100644 jOOQ-examples/jOOQ-spring-example/LICENSE.txt delete mode 100644 jOOQ-examples/jOOQ-spring-example/README.md delete mode 100644 jOOQ-examples/jOOQ-spring-example/pom.xml delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/BookService.java delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransaction.java delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransactionProvider.java delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/impl/DefaultBookService.java delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/LICENSE.txt delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/README.txt delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/resources/config.properties delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/resources/db-h2.sql delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/resources/jooq-spring.xml delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/main/resources/log4j2.xml delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/JdbcTemplateTest.java delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/QueryTest.java delete mode 100644 jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/TransactionTest.java diff --git a/jOOQ-examples/jOOQ-spring-example/.gitignore b/jOOQ-examples/jOOQ-spring-example/.gitignore deleted file mode 100644 index 9df5d49712..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -/*.iml \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/LICENSE.txt b/jOOQ-examples/jOOQ-spring-example/LICENSE.txt deleted file mode 100644 index d090694f44..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/LICENSE.txt +++ /dev/null @@ -1,19 +0,0 @@ -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Other licenses: ------------------------------------------------------------------------------ -Commercial licenses for this work are available. These replace the above -ASL 2.0 and offer limited warranties, support, maintenance, and commercial -database integrations. - -For more information, please visit: http://www.jooq.org/licenses \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/README.md b/jOOQ-examples/jOOQ-spring-example/README.md deleted file mode 100644 index b3c1464cc8..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/README.md +++ /dev/null @@ -1,26 +0,0 @@ -### What does the example do? - -This example shows how to integrate jOOQ in a classic Spring application, showing how to work with: - -- Spring's transactions -- Spring's JdbcTemplate -- and more - -If you're setting up Spring with Spring Boot, please also have a look at the [jOOQ-spring-boot-example](https://github.com/jOOQ/jOOQ/tree/main/jOOQ-examples/jOOQ-spring-boot-example) - -This example was inspired by Petri Kainulainen's excellent blog post: -http://www.petrikainulainen.net/programming/jooq/using-jooq-with-spring-configuration/ - -### How to run the example? - -As all examples in this repository, this assumes you have either installed the latest snapshot version of the jOOQ Open Source Edition, or you patch the `pom.xml` files to use the jOOQ version that you're interested in. - -To install and run this example, simply check it out and run the following Maven command - -``` -$ pwd -/path/to/checkout/dir -$ cd jOOQ-examples/jOOQ-spring-example -... -$ mvn clean install -``` diff --git a/jOOQ-examples/jOOQ-spring-example/pom.xml b/jOOQ-examples/jOOQ-spring-example/pom.xml deleted file mode 100644 index 805f8423ba..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/pom.xml +++ /dev/null @@ -1,218 +0,0 @@ - - - 4.0.0 - - - org.jooq - jooq-examples - 3.17.0-SNAPSHOT - - - jooq-spring-example - jOOQ Spring Example - - - - Apache License, Version 2.0 - http://www.jooq.org/inc/LICENSE.txt - repo - - - - - UTF-8 - - - - - - - org.jooq - jooq - - - commons-dbcp - commons-dbcp - 1.4 - - - com.h2database - h2 - - - - - org.apache.logging.log4j - log4j-slf4j18-impl - - - - - org.springframework - spring-context - - - org.springframework - spring-jdbc - - - - - junit - junit - jar - test - - - org.springframework - spring-test - test - - - - - - - - - true - src/main/resources - - **/*.xml - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - 1024m - 256m - UTF-8 - - 17 - - - - 17 - 17 - - true - lines,vars,source - - - -Xlint:varargs - - - - - - - org.codehaus.mojo - properties-maven-plugin - 1.0.0 - - - initialize - - read-project-properties - - - - src/main/resources/config.properties - - - - - - - - - org.codehaus.mojo - sql-maven-plugin - - - ${maven.test.skip} - always - - - - - create-database-h2 - generate-sources - - execute - - - ${db.driver} - ${db.url} - ${db.username} - ${db.password} - - true - - src/main/resources/db-h2.sql - - - - - - - - com.h2database - h2 - ${h2.version} - - - - - - - org.jooq - jooq-codegen-maven - - - - generate-h2 - generate-sources - - generate - - - - ${db.driver} - ${db.url} - ${db.username} - ${db.password} - - - - PUBLIC - - - true - true - true - true - - - org.jooq.example.db.h2 - target/generated-sources/jooq-h2 - - - - - - - - - \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/BookService.java b/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/BookService.java deleted file mode 100644 index 4e0f5e18cc..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/BookService.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example.spring; - -import org.springframework.transaction.annotation.Transactional; - -/** - * This Book Service (or DAO or Repository) is used by this example to interact - * with the library's T_BOOK table. - * - * @author Lukas Eder - */ -public interface BookService { - - /** - * Create a new book. - *

- * The implementation of this method has a bug, which causes this method to - * fail and roll back the transaction. - */ - @Transactional - void create(int id, int authorId, String title); - -} diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransaction.java b/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransaction.java deleted file mode 100644 index c36937e75a..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransaction.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example.spring; - -import org.jooq.Transaction; - -import org.springframework.transaction.TransactionStatus; - -class SpringTransaction implements Transaction { - final TransactionStatus tx; - - SpringTransaction(TransactionStatus tx) { - this.tx = tx; - } -} \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransactionProvider.java b/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransactionProvider.java deleted file mode 100644 index 3b2900d5d7..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/SpringTransactionProvider.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example.spring; - -import static org.springframework.transaction.TransactionDefinition.PROPAGATION_NESTED; - -import org.jooq.TransactionContext; -import org.jooq.TransactionProvider; -import org.jooq.tools.JooqLogger; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.DefaultTransactionDefinition; - -/** - * An example TransactionProvider implementing the - * {@link TransactionProvider} contract for use with Spring. - * - * @author Lukas Eder - */ -public class SpringTransactionProvider implements TransactionProvider { - - private static final JooqLogger log = JooqLogger.getLogger(SpringTransactionProvider.class); - - @Autowired - DataSourceTransactionManager txMgr; - - @Override - public void begin(TransactionContext ctx) { - log.info("Begin transaction"); - - // This TransactionProvider behaves like jOOQ's DefaultTransactionProvider, - // which supports nested transactions using Savepoints - TransactionStatus tx = txMgr.getTransaction(new DefaultTransactionDefinition(PROPAGATION_NESTED)); - ctx.transaction(new SpringTransaction(tx)); - } - - @Override - public void commit(TransactionContext ctx) { - log.info("commit transaction"); - - txMgr.commit(((SpringTransaction) ctx.transaction()).tx); - } - - @Override - public void rollback(TransactionContext ctx) { - log.info("rollback transaction"); - - txMgr.rollback(((SpringTransaction) ctx.transaction()).tx); - } -} diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java b/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java deleted file mode 100644 index 9b3a977d3b..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example.spring.exception; - -import org.jooq.ExecuteContext; -import org.jooq.ExecuteListener; -import org.jooq.SQLDialect; - -import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; -import org.springframework.jdbc.support.SQLExceptionTranslator; -import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; - -/** - * This class transforms SQLException into a Spring specific - * DataAccessException. The idea behind this is borrowed from Adam Zell's Gist - * - * @author Petri Kainulainen - * @author Adam Zell - * @author Lukas Eder - * @see http://www.petrikainulainen.net/programming/jooq/using-jooq-with-spring-configuration/ - * @see https://gist.github.com/azell/5655888 - */ -public class ExceptionTranslator implements ExecuteListener { - - /** - * Generated UID - */ - private static final long serialVersionUID = -2450323227461061152L; - - @Override - public void exception(ExecuteContext ctx) { - - // [#4391] Translate only SQLExceptions - if (ctx.sqlException() != null) { - SQLDialect dialect = ctx.dialect(); - SQLExceptionTranslator translator = (dialect != null) - ? new SQLErrorCodeSQLExceptionTranslator(dialect.thirdParty().springDbName()) - : new SQLStateSQLExceptionTranslator(); - - ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException())); - } - } -} diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/impl/DefaultBookService.java b/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/impl/DefaultBookService.java deleted file mode 100644 index 7c272606ce..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/impl/DefaultBookService.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example.spring.impl; - -import static org.jooq.example.db.h2.Tables.BOOK; - -import org.jooq.DSLContext; -import org.jooq.example.spring.BookService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -/** - * @author Lukas Eder - */ -public class DefaultBookService implements BookService { - - @Autowired - DSLContext dsl; - - @Override - @Transactional - public void create(int id, int authorId, String title) { - - // This method has a "bug". It creates the same book twice. The second insert - // should lead to a constraint violation, which should roll back the whole transaction - for (int i = 0; i < 2; i++) - dsl.insertInto(BOOK) - .set(BOOK.ID, id) - .set(BOOK.AUTHOR_ID, authorId) - .set(BOOK.TITLE, title) - .execute(); - } -} diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/LICENSE.txt b/jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/LICENSE.txt deleted file mode 100644 index d090694f44..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/LICENSE.txt +++ /dev/null @@ -1,19 +0,0 @@ -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Other licenses: ------------------------------------------------------------------------------ -Commercial licenses for this work are available. These replace the above -ASL 2.0 and offer limited warranties, support, maintenance, and commercial -database integrations. - -For more information, please visit: http://www.jooq.org/licenses \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/README.txt b/jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/README.txt deleted file mode 100644 index bf250b0c0c..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/resources/META-INF/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -Thanks for downloading jOOQ. -Please visit http://www.jooq.org for more information. - -This example was inspired by Petri Kainulainen's excellent blog post: -http://www.petrikainulainen.net/programming/jooq/using-jooq-with-spring-configuration/ \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/resources/config.properties b/jOOQ-examples/jOOQ-spring-example/src/main/resources/config.properties deleted file mode 100644 index 0546a8cc5e..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/resources/config.properties +++ /dev/null @@ -1,11 +0,0 @@ -#Database Configuration -db.driver=org.h2.Driver -db.url=jdbc:h2:~/jooq-spring-example-2 -db.username=sa -db.password= - -#jOOQ Configuration -jooq.sql.dialect=H2 - -#DB Schema -db.schema.script=db-h2.sql \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/resources/db-h2.sql b/jOOQ-examples/jOOQ-spring-example/src/main/resources/db-h2.sql deleted file mode 100644 index 3a7c5a379e..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/resources/db-h2.sql +++ /dev/null @@ -1,78 +0,0 @@ -DROP TABLE IF EXISTS book_to_book_store; -DROP TABLE IF EXISTS book_store; -DROP TABLE IF EXISTS book; -DROP TABLE IF EXISTS author; - -DROP SEQUENCE IF EXISTS s_author_id; -CREATE SEQUENCE s_author_id START WITH 1; - -CREATE TABLE author ( - id INT NOT NULL, - first_name VARCHAR(50), - last_name VARCHAR(50) NOT NULL, - date_of_birth DATE, - year_of_birth INT, - address VARCHAR(50), - - CONSTRAINT pk_t_author PRIMARY KEY (ID) -); - -CREATE TABLE book ( - id INT NOT NULL, - author_id INT NOT NULL, - co_author_id INT, - details_id INT, - title VARCHAR(400) NOT NULL, - published_in INT, - language_id INT, - content_text CLOB, - content_pdf BLOB, - - rec_version INT, - rec_timestamp TIMESTAMP, - - CONSTRAINT pk_t_book PRIMARY KEY (id), - CONSTRAINT fk_t_book_author_id FOREIGN KEY (author_id) REFERENCES author(id), - CONSTRAINT fk_t_book_co_author_id FOREIGN KEY (co_author_id) REFERENCES author(id) -); - -CREATE TABLE book_store ( - name VARCHAR(400) NOT NULL, - - CONSTRAINT uk_t_book_store_name PRIMARY KEY(name) -); - -CREATE TABLE book_to_book_store ( - book_store_name VARCHAR(400) NOT NULL, - book_id INTEGER NOT NULL, - stock INTEGER, - - CONSTRAINT pk_b2bs PRIMARY KEY(book_store_name, book_id), - CONSTRAINT fk_b2bs_bs_name FOREIGN KEY (book_store_name) - REFERENCES book_store (name) - ON DELETE CASCADE, - CONSTRAINT fk_b2bs_b_id FOREIGN KEY (book_id) - REFERENCES book (id) - ON DELETE CASCADE -); - -INSERT INTO author VALUES (next value for s_author_id, 'George', 'Orwell', '1903-06-25', 1903, null); -INSERT INTO author VALUES (next value for s_author_id, 'Paulo', 'Coelho', '1947-08-24', 1947, null); - -INSERT INTO book VALUES (1, 1, null, null, '1984', 1948, 1, 'To know and not to know, to be conscious of complete truthfulness while telling carefully constructed lies, to hold simultaneously two opinions which cancelled out, knowing them to be contradictory and believing in both of them, to use logic against logic, to repudiate morality while laying claim to it, to believe that democracy was impossible and that the Party was the guardian of democracy, to forget, whatever it was necessary to forget, then to draw it back into memory again at the moment when it was needed, and then promptly to forget it again, and above all, to apply the same process to the process itself -- that was the ultimate subtlety; consciously to induce unconsciousness, and then, once again, to become unconscious of the act of hypnosis you had just performed. Even to understand the word ''doublethink'' involved the use of doublethink..', null, 1, '2010-01-01 00:00:00'); -INSERT INTO book VALUES (2, 1, null, null, 'Animal Farm', 1945, 1, null, null, null, '2010-01-01 00:00:00'); -INSERT INTO book VALUES (3, 2, null, null, 'O Alquimista', 1988, 4, null, null, 1, null); -INSERT INTO book VALUES (4, 2, null, null, 'Brida', 1990, 2, null, null, null, null); - -INSERT INTO book_store (name) VALUES - ('Orell Füssli'), - ('Ex Libris'), - ('Buchhandlung im Volkshaus'); - -INSERT INTO book_to_book_store VALUES - ('Orell Füssli', 1, 10), - ('Orell Füssli', 2, 10), - ('Orell Füssli', 3, 10), - ('Ex Libris', 1, 1), - ('Ex Libris', 3, 2), - ('Buchhandlung im Volkshaus', 3, 1); diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/resources/jooq-spring.xml b/jOOQ-examples/jOOQ-spring-example/src/main/resources/jooq-spring.xml deleted file mode 100644 index 27c85a5dd0..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/resources/jooq-spring.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - H2 - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/resources/log4j2.xml b/jOOQ-examples/jOOQ-spring-example/src/main/resources/log4j2.xml deleted file mode 100644 index 565e879dd7..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/main/resources/log4j2.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/JdbcTemplateTest.java b/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/JdbcTemplateTest.java deleted file mode 100644 index a7fc858f6c..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/JdbcTemplateTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example; - -import static org.jooq.example.db.h2.Tables.AUTHOR; -import static org.jooq.example.db.h2.Tables.BOOK; -import static org.jooq.example.db.h2.Tables.BOOK_STORE; -import static org.jooq.example.db.h2.Tables.BOOK_TO_BOOK_STORE; -import static org.jooq.impl.DSL.countDistinct; -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import javax.sql.DataSource; - -import org.jooq.DSLContext; -import org.jooq.Record3; -import org.jooq.ResultQuery; -import org.jooq.example.db.h2.tables.Author; -import org.jooq.example.db.h2.tables.Book; -import org.jooq.example.db.h2.tables.BookStore; -import org.jooq.example.db.h2.tables.BookToBookStore; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author Lukas Eder - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"/jooq-spring.xml"}) -public class JdbcTemplateTest { - - @Autowired - DSLContext create; - - @Autowired - DataSource dataSource; - - @Test - public void testExecuteQueryWithJdbcTemplate() throws Exception { - // All of these tables were generated by jOOQ's Maven plugin - Book b = BOOK.as("b"); - Author a = AUTHOR.as("a"); - BookStore s = BOOK_STORE.as("s"); - BookToBookStore t = BOOK_TO_BOOK_STORE.as("t"); - - ResultQuery> query = - create.select(a.FIRST_NAME, a.LAST_NAME, countDistinct(s.NAME)) - .from(a) - .join(b).on(b.AUTHOR_ID.equal(a.ID)) - .join(t).on(t.BOOK_ID.equal(b.ID)) - .join(s).on(t.BOOK_STORE_NAME.equal(s.NAME)) - .groupBy(a.FIRST_NAME, a.LAST_NAME) - .orderBy(countDistinct(s.NAME).desc()); - - JdbcTemplate template = new JdbcTemplate(dataSource); - List result = template.query( - query.getSQL(), - query.getBindValues().toArray(), - (r, i) -> new A( - r.getString(1), - r.getString(2), - r.getInt(3) - )); - - assertEquals(2, result.size()); - assertEquals("Paulo", result.get(0).firstName); - assertEquals("George", result.get(1).firstName); - - assertEquals("Coelho", result.get(0).lastName); - assertEquals("Orwell", result.get(1).lastName); - - assertEquals(3, result.get(0).books); - assertEquals(2, result.get(1).books); - } - - static class A { - final String firstName; - final String lastName; - final int books; - - A(String firstName, String lastName, int books) { - this.firstName = firstName; - this.lastName = lastName; - this.books = books; - } - } -} diff --git a/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/QueryTest.java b/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/QueryTest.java deleted file mode 100644 index d093f6bf12..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/QueryTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example; - -import static java.util.Arrays.asList; -import static org.jooq.example.db.h2.Tables.AUTHOR; -import static org.jooq.example.db.h2.Tables.BOOK; -import static org.jooq.example.db.h2.Tables.BOOK_STORE; -import static org.jooq.example.db.h2.Tables.BOOK_TO_BOOK_STORE; -import static org.jooq.impl.DSL.countDistinct; -import static org.junit.Assert.assertEquals; - -import org.jooq.DSLContext; -import org.jooq.Record3; -import org.jooq.Result; -import org.jooq.example.db.h2.tables.Author; -import org.jooq.example.db.h2.tables.Book; -import org.jooq.example.db.h2.tables.BookStore; -import org.jooq.example.db.h2.tables.BookToBookStore; -import org.jooq.example.db.h2.tables.records.BookRecord; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author Lukas Eder - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"/jooq-spring.xml"}) -public class QueryTest { - - @Autowired - DSLContext create; - - @Test - public void testJoin() throws Exception { - // All of these tables were generated by jOOQ's Maven plugin - Book b = BOOK.as("b"); - Author a = AUTHOR.as("a"); - BookStore s = BOOK_STORE.as("s"); - BookToBookStore t = BOOK_TO_BOOK_STORE.as("t"); - - Result> result = - create.select(a.FIRST_NAME, a.LAST_NAME, countDistinct(s.NAME)) - .from(a) - .join(b).on(b.AUTHOR_ID.equal(a.ID)) - .join(t).on(t.BOOK_ID.equal(b.ID)) - .join(s).on(t.BOOK_STORE_NAME.equal(s.NAME)) - .groupBy(a.FIRST_NAME, a.LAST_NAME) - .orderBy(countDistinct(s.NAME).desc()) - .fetch(); - - assertEquals(2, result.size()); - assertEquals("Paulo", result.getValue(0, a.FIRST_NAME)); - assertEquals("George", result.getValue(1, a.FIRST_NAME)); - - assertEquals("Coelho", result.getValue(0, a.LAST_NAME)); - assertEquals("Orwell", result.getValue(1, a.LAST_NAME)); - - assertEquals(Integer.valueOf(3), result.getValue(0, countDistinct(s.NAME))); - assertEquals(Integer.valueOf(2), result.getValue(1, countDistinct(s.NAME))); - } - - @Test - public void testActiveRecords() throws Exception { - Result result = create.selectFrom(BOOK).orderBy(BOOK.ID).fetch(); - - assertEquals(4, result.size()); - assertEquals(asList(1, 2, 3, 4), result.getValues(0)); - } -} diff --git a/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/TransactionTest.java b/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/TransactionTest.java deleted file mode 100644 index 8243a18145..0000000000 --- a/jOOQ-examples/jOOQ-spring-example/src/test/java/org/jooq/example/TransactionTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.example; - -import static org.jooq.example.db.h2.Tables.BOOK; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.jooq.DSLContext; -import org.jooq.example.spring.BookService; -import org.jooq.example.spring.SpringTransactionProvider; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.DefaultTransactionDefinition; - -/** - * @author Petri Kainulainen - * @author Lukas Eder - * - * @see http://www.petrikainulainen.net/programming/jooq/using-jooq-with-spring-configuration/ - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "/jooq-spring.xml" }) -public class TransactionTest { - - @Autowired DSLContext dsl; - @Autowired DataSourceTransactionManager txMgr; - @Autowired SpringTransactionProvider txProvider; - @Autowired BookService books; - - @After - public void teardown() { - - // Delete all books that were created in any test - dsl.delete(BOOK).where(BOOK.ID.gt(4)).execute(); - } - - @Test - public void testExplicitTransactions() { - boolean rollback = false; - - TransactionStatus tx = txMgr.getTransaction(new DefaultTransactionDefinition()); - try { - - // This is a "bug". The same book is created twice, resulting in a - // constraint violation exception - for (int i = 0; i < 2; i++) - dsl.insertInto(BOOK) - .set(BOOK.ID, 5) - .set(BOOK.AUTHOR_ID, 1) - .set(BOOK.TITLE, "Book 5") - .execute(); - - Assert.fail(); - } - - // Upon the constraint violation, we explicitly roll back the transaction. - catch (DataAccessException e) { - txMgr.rollback(tx); - rollback = true; - } - - assertEquals(4, dsl.fetchCount(BOOK)); - assertTrue(rollback); - } - - @Test - public void testDeclarativeTransactions() { - boolean rollback = false; - - try { - books.create(5, 1, "Book 5"); - Assert.fail(); - } - catch (DataAccessException ignore) { - rollback = true; - } - - assertEquals(4, dsl.fetchCount(BOOK)); - assertTrue(rollback); - } - - @Test - public void testjOOQTransactionsSimple() { - boolean rollback = false; - - try { - dsl.transaction(c -> { - - // This is a "bug". The same book is created twice, resulting in a - // constraint violation exception - for (int i = 0; i < 2; i++) - dsl.insertInto(BOOK) - .set(BOOK.ID, 5) - .set(BOOK.AUTHOR_ID, 1) - .set(BOOK.TITLE, "Book 5") - .execute(); - - Assert.fail(); - }); - } - - // Upon the constraint violation, the transaction must already have been rolled back - catch (DataAccessException e) { - rollback = true; - } - - assertEquals(4, dsl.fetchCount(BOOK)); - assertTrue(rollback); - } - - @Test - public void testjOOQTransactionsNested() { - AtomicBoolean rollback1 = new AtomicBoolean(false); - AtomicBoolean rollback2 = new AtomicBoolean(false); - - try { - - // If using Spring transactions, we don't need the c1 reference - dsl.transaction(c1 -> { - - // The first insertion will work - dsl.insertInto(BOOK) - .set(BOOK.ID, 5) - .set(BOOK.AUTHOR_ID, 1) - .set(BOOK.TITLE, "Book 5") - .execute(); - - assertEquals(5, dsl.fetchCount(BOOK)); - - try { - - // Nest transactions using Spring. This should create a savepoint, right here - // If using Spring transactions, we don't need the c2 reference - dsl.transaction(c2 -> { - - // The second insertion shouldn't work - for (int i = 0; i < 2; i++) - dsl.insertInto(BOOK) - .set(BOOK.ID, 6) - .set(BOOK.AUTHOR_ID, 1) - .set(BOOK.TITLE, "Book 6") - .execute(); - - Assert.fail(); - }); - } - - catch (DataAccessException e) { - rollback1.set(true); - } - - // We should've rolled back to the savepoint - assertEquals(5, dsl.fetchCount(BOOK)); - - throw new org.jooq.exception.DataAccessException("Rollback"); - }); - } - - // Upon the constraint violation, the transaction must already have been rolled back - catch (org.jooq.exception.DataAccessException e) { - assertEquals("Rollback", e.getMessage()); - rollback2.set(true); - } - - assertEquals(4, dsl.fetchCount(BOOK)); - assertTrue(rollback2.get()); - assertTrue(rollback2.get()); - } -} diff --git a/jOOQ-examples/pom.xml b/jOOQ-examples/pom.xml index 9483abd36a..a7fba933bc 100644 --- a/jOOQ-examples/pom.xml +++ b/jOOQ-examples/pom.xml @@ -77,7 +77,6 @@ jOOQ-flyway-example jOOQ-flyway-ddl-example jOOQ-kotlin-example - jOOQ-spring-example jOOQ-spring-boot-example jOOQ-jpa-example-entities jOOQ-jpa-example