From f026a628abb278af198815f72066b8fcb5e1ef53 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sat, 16 Feb 2013 15:11:21 +0100 Subject: [PATCH] Release 3.0.0-RC1 - Fixed tests against maven-generated resources --- jOOQ-codegen-maven-example/.classpath | 5 +- jOOQ-codegen-maven-example/pom.xml | 495 ++++++------------ .../util/maven/{TestASE.java => TestH2.java} | 30 +- .../org/jooq/test/util/maven/TestMySQL.java | 138 ----- .../jooq/test/util/maven/TestPostgres.java | 89 ---- .../org/jooq/test/util/spring/AuthorDao.java | 67 --- .../jooq/test/util/spring/AuthorDaoImpl.java | 152 ------ .../jooq/test/util/spring/AuthorDaoTest.java | 172 ------ .../jooq/test/util/spring/domain/Author.java | 70 --- .../src/test/resources/db-init.sql | 15 - .../src/test/resources/db.sql | 77 +++ .../src/test/resources/spring-context.xml | 35 -- jOOQ-scala/pom.xml | 2 +- .../src/org/jooq/test/jOOQAbstractTest.java | 2 - 14 files changed, 244 insertions(+), 1105 deletions(-) rename jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/{TestASE.java => TestH2.java} (78%) delete mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestMySQL.java delete mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestPostgres.java delete mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDao.java delete mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoImpl.java delete mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoTest.java delete mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/domain/Author.java delete mode 100644 jOOQ-codegen-maven-example/src/test/resources/db-init.sql create mode 100644 jOOQ-codegen-maven-example/src/test/resources/db.sql delete mode 100644 jOOQ-codegen-maven-example/src/test/resources/spring-context.xml diff --git a/jOOQ-codegen-maven-example/.classpath b/jOOQ-codegen-maven-example/.classpath index 422ff93e04..744d82d027 100644 --- a/jOOQ-codegen-maven-example/.classpath +++ b/jOOQ-codegen-maven-example/.classpath @@ -11,10 +11,7 @@ - - - - + diff --git a/jOOQ-codegen-maven-example/pom.xml b/jOOQ-codegen-maven-example/pom.xml index 422a229b72..225c3a6c1e 100644 --- a/jOOQ-codegen-maven-example/pom.xml +++ b/jOOQ-codegen-maven-example/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -9,358 +9,163 @@ 3.0.0-RC1 - org.jooq - jooq-codegen-maven-example - jOOQ Codegen Maven (Example) + org.jooq + jooq-codegen-maven-example + jOOQ Codegen Maven (Example) - - - org.springframework - spring-jdbc - 3.0.6.RELEASE - test - - - org.springframework - spring-beans - 3.0.6.RELEASE - test - - - org.springframework - spring-tx - 3.0.6.RELEASE - test - - - org.springframework - spring-test - 3.0.6.RELEASE - test - - - log4j - log4j - 1.2.16 - test - - - cglib - cglib - 2.2.2 - test - + + + log4j + log4j + 1.2.16 + test + - - org.jooq - jooq - - - junit - junit - 4.9 - jar - test - + + org.jooq + jooq + + + junit + junit + 4.9 + jar + test + + + + com.h2database + h2 + 1.3.168 + + + javax.persistence + persistence-api + 1.0.2 + jar + true + + - - org.hsqldb - hsqldb - 2.2.6 - jar - test - - - postgresql - postgresql - 9.0-801.jdbc4 - jar - test - - - net.sourceforge.jtds - jtds - 1.2.4 - jar - test - - - mysql - mysql-connector-java - 5.1.18 - jar - test - - - javax.persistence - persistence-api - 1.0.2 - jar - true - - + + UTF-8 + - - UTF-8 - + + - - + + + org.codehaus.mojo + sql-maven-plugin + 1.5 - - - org.jooq - jooq-codegen-maven - - - exec0 - - generate - - - - org.hsqldb.jdbcDriver - jdbc:hsqldb:hsql://localhost - sa - - - - org.jooq.util.DefaultGenerator - - org.jooq.util.hsqldb.HSQLDBDatabase - .* - - PUBLIC - - - false - - - org.jooq.util.maven.example.hsqldb - target/generated-sources/jooq-hsqldb - - - - + + + com.h2database + h2 + 1.3.168 + + - - exec1 - - generate - - - - org.postgresql.Driver - jdbc:postgresql:postgres - public - postgres - test - - - org.jooq.util.DefaultGenerator - - org.jooq.util.postgres.PostgresDatabase - .* - - true - - - false - false - true - - - org.jooq.util.maven.example.postgres - target/generated-sources/jooq-postgres - - - - + + + org.h2.Driver + jdbc:h2:~/maven-test + sa + + + ${maven.test.skip} + - - exec2 - - generate - - - - net.sourceforge.jtds.jdbc.Driver - jdbc:jtds:sybase://lukas-hp:5000/TEST - dbo - sa + + + create-database + generate-sources + + execute + + + true + + src/test/resources/db.sql + + + + + - - - - - org.jooq.util.DefaultGenerator - - org.jooq.util.ase.ASEDatabase - t_.*,x_.*,v_.*,V_.*,p_.*,f_.*,(f|p)[0-9]+,s_.* - - - - false - true - true - - - org.jooq.util.maven.example.ase - target/generated-sources/jooq-ase - - - - + + + org.jooq + jooq-codegen-maven + 3.0.0-RC1 + + + exec1 + + generate + + + + org.h2.Driver + jdbc:h2:~/maven-test + sa + + + + org.jooq.util.DefaultGenerator + + org.jooq.util.h2.H2Database + .* + + true + PUBLIC + + + false + true + true + + + org.jooq.maven.example.h2 + target/generated-sources/jooq-h2 + + + + + + + + com.h2database + h2 + 1.3.168 + + + + + - - exec3 - - generate - - - - com.mysql.jdbc.Driver - jdbc:mysql://localhost/test - root - - - - org.jooq.util.DefaultGenerator - - org.jooq.util.mysql.MySQLDatabase - .* - t_book_details - true - - - test - test2 - - - - - BOOLEAN_10 - 1,0 - - - BOOLEAN_YN_UC - "Y",N - - - BOOLEAN_YN_LC - y,"n" - - - BOOLEAN_YES_NO_UC - "YES","NO" - - - BOOLEAN_YES_NO_LC - yes,no - - - BOOLEAN_TRUE_FALSE_UC - TRUE,FALSE - - - BOOLEAN_TRUE_FALSE_LC - true,false - - - - - - - BOOLEAN_10 - (?i:(.*?\.)?T_BOOLEANS\.ONE_ZERO) - - - BOOLEAN_YN_UC - (?i:(.*?\.)?T_BOOLEANS\.Y_N_UC) - - - BOOLEAN_YN_LC - (?i:(.*?\.)?T_BOOLEANS\.Y_N_LC) - - - BOOLEAN_YES_NO_UC - (?i:(.*?\.)?T_BOOLEANS\.YES_NO_UC) - - - BOOLEAN_YES_NO_LC - (?i:(.*?\.)?T_BOOLEANS\.YES_NO_LC) - - - BOOLEAN_TRUE_FALSE_UC - (?i:(.*?\.)?T_BOOLEANS\.TRUE_FALSE_UC) - - - BOOLEAN_TRUE_FALSE_LC - (?i:(.*?\.)?T_BOOLEANS\.TRUE_FALSE_LC) - - - - - false - true - false - true - true - - - org.jooq.util.maven.example.mysql - target/generated-sources/jooq-mysql - - - - - - - - org.hsqldb - hsqldb - 2.2.6 - - - net.sourceforge.jtds - jtds - 1.2.4 - - - postgresql - postgresql - 8.4-702.jdbc4 - - - mysql - mysql-connector-java - 5.1.18 - - - - - - - - - release - - - - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - verify - - sign - - - - - - - - + + + release + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + \ No newline at end of file diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestASE.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestH2.java similarity index 78% rename from jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestASE.java rename to jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestH2.java index 94ed73b2b4..4623e06c2a 100644 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestASE.java +++ b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestH2.java @@ -37,42 +37,42 @@ package org.jooq.test.util.maven; import static junit.framework.Assert.assertEquals; import static org.jooq.impl.Factory.countDistinct; -import static org.jooq.util.maven.example.ase.Tables.T_AUTHOR; -import static org.jooq.util.maven.example.ase.Tables.T_BOOK; -import static org.jooq.util.maven.example.ase.Tables.T_BOOK_STORE; -import static org.jooq.util.maven.example.ase.Tables.T_BOOK_TO_BOOK_STORE; +import static org.jooq.maven.example.h2.Tables.T_AUTHOR; +import static org.jooq.maven.example.h2.Tables.T_BOOK; +import static org.jooq.maven.example.h2.Tables.T_BOOK_STORE; +import static org.jooq.maven.example.h2.Tables.T_BOOK_TO_BOOK_STORE; import java.sql.Connection; import java.sql.DriverManager; -import org.jooq.Record; +import org.jooq.Record3; import org.jooq.Result; import org.jooq.SQLDialect; -import org.jooq.impl.Factory; -import org.jooq.util.maven.example.ase.tables.TAuthor; -import org.jooq.util.maven.example.ase.tables.TBook; -import org.jooq.util.maven.example.ase.tables.TBookStore; -import org.jooq.util.maven.example.ase.tables.TBookToBookStore; +import org.jooq.impl.Executor; +import org.jooq.maven.example.h2.tables.TAuthor; +import org.jooq.maven.example.h2.tables.TBook; +import org.jooq.maven.example.h2.tables.TBookStore; +import org.jooq.maven.example.h2.tables.TBookToBookStore; import org.junit.Test; /** * @author Lukas Eder */ -public class TestASE { +public class TestH2 { @Test public void testInstanceModel() throws Exception { - Class.forName("net.sourceforge.jtds.jdbc.Driver"); - Connection connection = DriverManager.getConnection("jdbc:jtds:sybase://lukas-hp:5000/TEST", "sa", ""); - Factory create = new Factory(connection, SQLDialect.ASE); + Class.forName("org.h2.Driver"); + Connection connection = DriverManager.getConnection("jdbc:h2:~/maven-test", "sa", ""); + Executor create = new Executor(connection, SQLDialect.H2); TBook b = T_BOOK.as("b"); TAuthor a = T_AUTHOR.as("a"); TBookStore s = T_BOOK_STORE.as("s"); TBookToBookStore t = T_BOOK_TO_BOOK_STORE.as("t"); - Result result = + Result> result = create.select(a.FIRST_NAME, a.LAST_NAME, countDistinct(s.NAME)) .from(a) .join(b).on(b.AUTHOR_ID.equal(a.ID)) diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestMySQL.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestMySQL.java deleted file mode 100644 index b2b473ac2d..0000000000 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestMySQL.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.test.util.maven; - -import static junit.framework.Assert.assertEquals; -import static org.jooq.impl.Factory.countDistinct; -import static org.jooq.util.maven.example.mysql.Tables.T_AUTHOR; -import static org.jooq.util.maven.example.mysql.Tables.T_BOOK; -import static org.jooq.util.maven.example.mysql.Tables.T_BOOK_STORE; -import static org.jooq.util.maven.example.mysql.Tables.T_BOOK_TO_BOOK_STORE; -import static org.jooq.util.maven.example.mysql.Tables.T_BOOLEANS; - -import java.sql.Connection; -import java.sql.DriverManager; - -import org.jooq.Record; -import org.jooq.Result; -import org.jooq.SQLDialect; -import org.jooq.impl.Factory; -import org.jooq.util.maven.example.mysql.enums.BooleanTrueFalseLc; -import org.jooq.util.maven.example.mysql.enums.BooleanTrueFalseUc; -import org.jooq.util.maven.example.mysql.enums.BooleanYesNoLc; -import org.jooq.util.maven.example.mysql.enums.BooleanYesNoUc; -import org.jooq.util.maven.example.mysql.enums.BooleanYnLc; -import org.jooq.util.maven.example.mysql.enums.BooleanYnUc; -import org.jooq.util.maven.example.mysql.enums.Boolean_10; -import org.jooq.util.maven.example.mysql.tables.TAuthor; -import org.jooq.util.maven.example.mysql.tables.TBook; -import org.jooq.util.maven.example.mysql.tables.TBookStore; -import org.jooq.util.maven.example.mysql.tables.TBookToBookStore; -import org.jooq.util.maven.example.mysql.tables.records.TBooleansRecord; - -import org.junit.Test; - -/** - * @author Lukas Eder - */ -public class TestMySQL { - - @Test - public void testInstanceModel() throws Exception { - Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test2", "root", ""); - Factory create = new Factory(connection, SQLDialect.MYSQL); - - TBook b = T_BOOK.as("b"); - TAuthor a = T_AUTHOR.as("a"); - TBookStore s = T_BOOK_STORE.as("s"); - TBookToBookStore t = 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 testCustomEnum() throws Exception { - Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test2", "root", ""); - Factory create = new Factory(connection, SQLDialect.MYSQL); - - create.delete(T_BOOLEANS).execute(); - - assertEquals(1, - create.insertInto(T_BOOLEANS) - .set(T_BOOLEANS.ID, 1) - .set(T_BOOLEANS.ONE_ZERO, Boolean_10._0) - .set(T_BOOLEANS.TRUE_FALSE_LC, BooleanTrueFalseLc.true_) - .set(T_BOOLEANS.TRUE_FALSE_UC, BooleanTrueFalseUc.FALSE) - .set(T_BOOLEANS.Y_N_LC, BooleanYnLc.y) - .set(T_BOOLEANS.Y_N_UC, BooleanYnUc.N) - .set(T_BOOLEANS.YES_NO_LC, BooleanYesNoLc.yes) - .set(T_BOOLEANS.YES_NO_UC, BooleanYesNoUc.NO) - .execute()); - - TBooleansRecord bool = create.selectFrom(T_BOOLEANS).fetchOne(); - assertEquals(1, (int) bool.getId()); - assertEquals(Boolean_10._0, bool.getOneZero()); - assertEquals(BooleanTrueFalseLc.true_, bool.getTrueFalseLc()); - assertEquals(BooleanTrueFalseUc.FALSE, bool.getTrueFalseUc()); - assertEquals(BooleanYnLc.y, bool.getYNLc()); - assertEquals(BooleanYnUc.N, bool.getYNUc()); - assertEquals(BooleanYesNoLc.yes, bool.getYesNoLc()); - assertEquals(BooleanYesNoUc.NO, bool.getYesNoUc()); - - assertEquals(1, - create.delete(T_BOOLEANS).execute()); - } -} diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestPostgres.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestPostgres.java deleted file mode 100644 index 7196d388d7..0000000000 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestPostgres.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.test.util.maven; - -import static junit.framework.Assert.assertEquals; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.util.List; - -import org.jooq.Record; -import org.jooq.Result; -import org.jooq.SQLDialect; -import org.jooq.impl.Factory; -import org.jooq.util.maven.example.postgres.tables.TBook; -import org.jooq.util.maven.example.postgres.tables.records.TBookRecord; - -import org.junit.Test; - -/** - * @author Lukas Eder - */ -public class TestPostgres { - - @Test - public void testFetch() throws Exception { - Connection connection = DriverManager.getConnection("jdbc:postgresql:postgres", "postgres", "test"); - Factory create = new Factory(connection, SQLDialect.POSTGRES); - - Result books = - create.select(TBook.ID, TBook.TITLE) - .from(TBook.T_BOOK) - .orderBy(TBook.ID) - .fetch(); - - assertEquals(Data.BOOK_IDS, books.getValues(0)); - assertEquals(Data.BOOK_TITLES, books.getValues(1)); - } - - @Test - public void testFetchInto() throws Exception { - Connection connection = DriverManager.getConnection("jdbc:postgresql:postgres", "postgres", "test"); - Factory create = new Factory(connection, SQLDialect.POSTGRES); - - List books = - create.select(TBook.ID, TBook.TITLE) - .from(TBook.T_BOOK) - .orderBy(TBook.ID) - .fetchInto(TBookRecord.class); - - for (int i = 0; i < Data.BOOK_IDS.size(); i++) { - assertEquals(Data.BOOK_IDS.get(i), books.get(i).getId()); - assertEquals(Data.BOOK_TITLES.get(i), books.get(i).getTitle()); - } - } -} diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDao.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDao.java deleted file mode 100644 index 0a1b92e585..0000000000 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDao.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.test.util.spring; - -import java.util.List; - -import org.jooq.test.util.spring.domain.Author; - -/** - * @author Sergey Epik - */ -public interface AuthorDao { - - Integer add(Author author); - - void addBatch(List authors); - - void save(Author author); - - void delete(Author author); - - Author findById(Integer id); - - List findAll(); - - long countAuthors(); - - long countDistinctForLastName(String name); - - boolean authorExists(Integer id); - - boolean authorExists(Author c); - -} diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoImpl.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoImpl.java deleted file mode 100644 index b5405cbcee..0000000000 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoImpl.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.test.util.spring; - -import static org.jooq.impl.Factory.param; -import static org.jooq.util.maven.example.hsqldb.Sequences.S_AUTHOR_ID; -import static org.jooq.util.maven.example.hsqldb.Tables.T_AUTHOR; - -import java.util.List; - -import org.jooq.BatchBindStep; -import org.jooq.FactoryOperations; -import org.jooq.impl.Factory; -import org.jooq.test.util.spring.domain.Author; -import org.jooq.util.maven.example.hsqldb.tables.records.TAuthorRecord; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -/** - * @author Sergey Epik - */ -@Transactional(readOnly = true) -@Component -public class AuthorDaoImpl implements AuthorDao { - - private FactoryOperations factory; - - @Autowired - public void setFactoryOperations(FactoryOperations factory) { - this.factory = factory; - } - - @Override - public Author findById(Integer id) { - TAuthorRecord authorRecord = factory - .selectFrom(T_AUTHOR) - .where(T_AUTHOR.ID.equal(id)) - .fetchOne(); - - return authorRecord == null ? null : authorRecord.into(Author.class); - } - - @Override - public List findAll() { - return factory.selectFrom(T_AUTHOR).fetchInto(Author.class); - } - - @Override - public Integer add(Author author) { - Integer id = factory.nextval(S_AUTHOR_ID); - - factory.insertInto(T_AUTHOR) - .set(T_AUTHOR.ID, id) - .set(T_AUTHOR.FIRST_NAME, author.getFirstName()) - .set(T_AUTHOR.LAST_NAME, author.getLastName()) - .execute(); - - return id; - } - - @Override - public void addBatch(List authors) { - BatchBindStep step = factory.batch( - factory.insertInto(T_AUTHOR, T_AUTHOR.ID, T_AUTHOR.FIRST_NAME, T_AUTHOR.LAST_NAME) - .values(param("id"), param("first"), param("last"))); - - for (Author author : authors) { - Integer id = factory.nextval(S_AUTHOR_ID).intValue(); - step = step.bind(id, author.getFirstName(), author.getLastName()); - } - - step.execute(); - } - - @Override - public void save(Author author) { - factory.update(T_AUTHOR) - .set(T_AUTHOR.FIRST_NAME, author.getFirstName()) - .set(T_AUTHOR.LAST_NAME, author.getLastName()) - .where(T_AUTHOR.ID.equal(author.getId())) - .execute(); - } - - @Override - public void delete(Author author) { - factory.delete(T_AUTHOR) - .where(T_AUTHOR.ID.equal(author.getId())) - .execute(); - } - - @Override - public long countAuthors() { - return factory.selectCount().from(T_AUTHOR) - .fetchOne().getValue(0, Long.class); - } - - @Override - public long countDistinctForLastName(String name) { - return factory.select(Factory.countDistinct(T_AUTHOR.LAST_NAME)) - .from(T_AUTHOR) - .where(T_AUTHOR.LAST_NAME.like(name + "%")) - .fetchOne() - .getValue(0, Long.class); - } - - @Override - public boolean authorExists(Integer id) { - return factory.selectFrom(T_AUTHOR).where(T_AUTHOR.ID.equal(id)).fetchOne() != null; - } - - @Override - public boolean authorExists(Author author) { - return factory.selectFrom(T_AUTHOR) - .where(T_AUTHOR.ID.equal(author.getId())) - .fetchOne() != null; - } -} diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoTest.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoTest.java deleted file mode 100644 index 40dc193564..0000000000 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/AuthorDaoTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.test.util.spring; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; - -import org.jooq.test.util.spring.domain.Author; - -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; -import org.springframework.transaction.annotation.Transactional; - -/** - * @author Sergey Epik - */ -@ContextConfiguration(locations = "classpath:spring-context.xml") -@RunWith(SpringJUnit4ClassRunner.class) -public class AuthorDaoTest { - - @Autowired - private AuthorDao authorDao; - - @Test - public void testFindAll() { - List authors = authorDao.findAll(); - Assert.assertEquals(2, authors.size()); - } - - @Test - public void testFindById() { - Author a = authorDao.findById(1); - Assert.assertEquals("George", a.getFirstName()); - } - - @Transactional - @Test - public void testAdd() { - Author a = new Author(); - a.setFirstName("Lewis"); - a.setLastName("Carroll"); - authorDao.add(a); - List authors = authorDao.findAll(); - Assert.assertEquals(3, authors.size()); - } - - @Transactional - @Test - public void testAddBatch() { - List authors = new ArrayList(); - Author a1 = new Author(); - a1.setFirstName("Lewis"); - a1.setLastName("Carroll"); - authors.add(a1); - Author a2 = new Author(); - a2.setFirstName("Agatha"); - a2.setLastName("Christie"); - authors.add(a2); - Author a3 = new Author(); - a3.setFirstName("Charles"); - a3.setLastName("Dickens"); - authors.add(a3); - Author a4 = new Author(); - a4.setFirstName("Mark"); - a4.setLastName("Twain"); - authors.add(a4); - authorDao.addBatch(authors); - List results = authorDao.findAll(); - Assert.assertEquals(6, results.size()); - } - - @Transactional - @Test - public void testSaveAuthor() { - Author author = authorDao.findById(1); - author.setFirstName("Arthur Conan"); - author.setLastName("Doyle"); - authorDao.save(author); - Author found = authorDao.findById(1); - Assert.assertEquals("Arthur Conan", found.getFirstName()); - } - - @Transactional - @Test - public void testDeleteAuthor() { - Author c = authorDao.findById(1); - authorDao.delete(c); - List authors = authorDao.findAll(); - Assert.assertEquals(1, authors.size()); - } - - @Transactional - @Test - public void testCountAuthor() { - Author a = new Author(); - a.setFirstName("Lewis"); - a.setLastName("Carroll"); - authorDao.add(a); - long count = authorDao.countAuthors(); - List authors = authorDao.findAll(); - for (Author author : authors) { - System.out.println(author.getFirstName()); - } - Assert.assertEquals(3, count); - } - - @Transactional - @Test - public void testCountDistinctAuthor() { - Author a1 = new Author(); - a1.setFirstName("Calvin"); - a1.setLastName("Coolidge"); - authorDao.add(a1); - Author a2 = new Author(); - a2.setFirstName("James Fenimore"); - a2.setLastName("Cooper"); - authorDao.add(a2); - long count = authorDao.countDistinctForLastName("Coo"); - Assert.assertEquals(2, count); - } - - @Test - public void testAuthorExists() { - Author c = authorDao.findById(1); - boolean exists = authorDao.authorExists(c); - Assert.assertTrue(exists); - } - - @Test - public void testAuthorNotExists() { - boolean exists = authorDao.authorExists(1000); - Assert.assertFalse(exists); - } -} diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/domain/Author.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/domain/Author.java deleted file mode 100644 index 988f7701b3..0000000000 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/spring/domain/Author.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.test.util.spring.domain; - -/** - * @author Sergey Epik - */ -public class Author { - - private Integer id; - private String firstName; - private String lastName; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } -} diff --git a/jOOQ-codegen-maven-example/src/test/resources/db-init.sql b/jOOQ-codegen-maven-example/src/test/resources/db-init.sql deleted file mode 100644 index 13b8c87b6b..0000000000 --- a/jOOQ-codegen-maven-example/src/test/resources/db-init.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE t_author ( - ID INT, - 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 SEQUENCE s_author_id START WITH 1; - -INSERT INTO t_author (ID, FIRST_NAME, LAST_NAME) VALUES (next value for s_author_id, 'George', 'Orwell'); -INSERT INTO t_author (ID, FIRST_NAME, LAST_NAME) VALUES (next value for s_author_id, 'Paulo', 'Coelho'); diff --git a/jOOQ-codegen-maven-example/src/test/resources/db.sql b/jOOQ-codegen-maven-example/src/test/resources/db.sql new file mode 100644 index 0000000000..4867774a99 --- /dev/null +++ b/jOOQ-codegen-maven-example/src/test/resources/db.sql @@ -0,0 +1,77 @@ +DROP TABLE IF EXISTS t_book_to_book_store; +DROP TABLE IF EXISTS t_book_store; +DROP TABLE IF EXISTS t_book; +DROP TABLE IF EXISTS t_author; +DROP SEQUENCE IF EXISTS s_author_id; +CREATE SEQUENCE s_author_id START WITH 1; + +CREATE TABLE t_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 t_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 NOT NULL, + language_id INT NOT NULL, + 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 t_author(id), + CONSTRAINT fk_t_book_co_author_id FOREIGN KEY (co_author_id) REFERENCES t_author(id) +); + +CREATE TABLE t_book_store ( + name VARCHAR(400) NOT NULL, + + CONSTRAINT uk_t_book_store_name PRIMARY KEY(name) +); + +CREATE TABLE t_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 t_book_store (name) + ON DELETE CASCADE, + CONSTRAINT fk_b2bs_b_id FOREIGN KEY (book_id) + REFERENCES t_book (id) + ON DELETE CASCADE +); + +INSERT INTO t_author VALUES (next value for s_author_id, 'George', 'Orwell', '1903-06-25', 1903, null); +INSERT INTO t_author VALUES (next value for s_author_id, 'Paulo', 'Coelho', '1947-08-24', 1947, null); + +INSERT INTO t_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 t_book VALUES (2, 1, null, null, 'Animal Farm', 1945, 1, null, null, null, '2010-01-01 00:00:00'); +INSERT INTO t_book VALUES (3, 2, null, null, 'O Alquimista', 1988, 4, null, null, 1, null); +INSERT INTO t_book VALUES (4, 2, null, null, 'Brida', 1990, 2, null, null, null, null); + +INSERT INTO t_book_store (name) VALUES + ('Orell Füssli'), + ('Ex Libris'), + ('Buchhandlung im Volkshaus'); + +INSERT INTO t_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-codegen-maven-example/src/test/resources/spring-context.xml b/jOOQ-codegen-maven-example/src/test/resources/spring-context.xml deleted file mode 100644 index cbb480e17d..0000000000 --- a/jOOQ-codegen-maven-example/src/test/resources/spring-context.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - HSQLDB - - - - - - diff --git a/jOOQ-scala/pom.xml b/jOOQ-scala/pom.xml index b55db8f2bc..74bf8dbc8b 100644 --- a/jOOQ-scala/pom.xml +++ b/jOOQ-scala/pom.xml @@ -50,7 +50,7 @@ create-database - process-test-resources + generate-sources execute diff --git a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java index 5a29b56a5c..f149a8e7f6 100644 --- a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java +++ b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java @@ -61,8 +61,6 @@ import java.util.UUID; import javax.swing.UIManager; -import junit.framework.Assert; - import org.jooq.ArrayRecord; import org.jooq.DAO; import org.jooq.DataType;