From 93312a1f2f3426148ca7f328e3a265da154182d4 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 18 Nov 2011 14:52:21 +0000 Subject: [PATCH] [#954] Add examples for source code generation of multiple schemata with Maven --- jOOQ-codegen-maven-example/.classpath | 3 +- jOOQ-codegen-maven-example/pom.xml | 141 +++++++++--------- .../java/org/jooq/test/util/maven/Data.java | 49 ++++++ .../org/jooq/test/util/maven/TestASE.java | 94 ++++++++++++ ...eneratedSources.java => TestPostgres.java} | 16 +- 5 files changed, 222 insertions(+), 81 deletions(-) create mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/Data.java create mode 100644 jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestASE.java rename jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/{TestGeneratedSources.java => TestPostgres.java} (82%) diff --git a/jOOQ-codegen-maven-example/.classpath b/jOOQ-codegen-maven-example/.classpath index c3f4bb541e..547864417d 100644 --- a/jOOQ-codegen-maven-example/.classpath +++ b/jOOQ-codegen-maven-example/.classpath @@ -1,8 +1,9 @@ - + + diff --git a/jOOQ-codegen-maven-example/pom.xml b/jOOQ-codegen-maven-example/pom.xml index 630d21093c..ee88e3baad 100644 --- a/jOOQ-codegen-maven-example/pom.xml +++ b/jOOQ-codegen-maven-example/pom.xml @@ -69,6 +69,13 @@ jar test + + net.sourceforge.jtds + jtds + 1.2.4 + jar + test + @@ -80,17 +87,79 @@ ${project.artifactId}-${project.version} - - + + org.jooq jooq-codegen-maven 2.0.0-SNAPSHOT + exec1 generate + + + org.postgresql.Driver + jdbc:postgresql:postgres + public + postgres + test + + + org.jooq.util.DefaultGenerator + + org.jooq.util.postgres.PostgresDatabase + .* + + + + true + false + false + + + org.jooq.util.maven.example.postgres + target/generated-sources/jooq-postgres + + + + + + + exec2 + + generate + + + + net.sourceforge.jtds.jdbc.Driver + jdbc:jtds:sybase://lukas-hp:5000/TEST + dbo + sa + + + + + + org.jooq.util.DefaultGenerator + + org.jooq.util.ase.ASEDatabase + t_.*,x_.*,v_.*,V_.*,p_.*,f_.*,(f|p)[0-9]+,s_.* + + + + true + false + true + + + org.jooq.util.maven.example.ase + target/generated-sources/jooq-ase + + + @@ -99,80 +168,12 @@ jtds 1.2.4 - - - - net.sourceforge.jtds.jdbc.Driver - jdbc:jtds:sybase://lukas-hp:5000/TEST - dbo - sa - - - - org.jooq.util.DefaultGenerator - - org.jooq.util.ase.ASEDatabase - t_.*,x_.*,v_.*,V_.*,p_.*,f_.*,(f|p)[0-9]+,s_.* - - - - true - false - true - - - org.jooq.util.maven.example.ase - target/generated-sources/jooq-ase - - - - - - - - org.jooq - jooq-codegen-maven - 2.0.0-SNAPSHOT - - - - generate - - - - postgresql postgresql 8.4-702.jdbc4 - - - org.postgresql.Driver - jdbc:postgresql:postgres - public - postgres - test - - - org.jooq.util.DefaultGenerator - - org.jooq.util.postgres.PostgresDatabase - .* - - - - true - false - false - - - org.jooq.util.maven.example.postgres - target/generated-sources/jooq-postgres - - - diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/Data.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/Data.java new file mode 100644 index 0000000000..ff7cb4dcb0 --- /dev/null +++ b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/Data.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2009-2011, 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 java.util.Arrays; +import java.util.List; + +/** + * @author Lukas Eder + */ +class Data { + + static final List BOOK_IDS = Arrays.asList(1, 2, 3, 4); + static final List BOOK_TITLES = Arrays.asList("1984", "Animal Farm", "O Alquimista", "Brida"); + +} 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/TestASE.java new file mode 100644 index 0000000000..4f9c7e34af --- /dev/null +++ b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestASE.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2009-2011, 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.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 java.sql.Connection; +import java.sql.DriverManager; + +import org.jooq.Record; +import org.jooq.Result; +import org.jooq.util.maven.example.ase.DboFactory; +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.junit.Test; + +/** + * @author Lukas Eder + */ +public class TestASE { + + @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", ""); + DboFactory create = new DboFactory(connection); + + 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))); + } +} diff --git a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestGeneratedSources.java b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestPostgres.java similarity index 82% rename from jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestGeneratedSources.java rename to jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestPostgres.java index 25e48ed0a2..97166fc5b7 100644 --- a/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestGeneratedSources.java +++ b/jOOQ-codegen-maven-example/src/test/java/org/jooq/test/util/maven/TestPostgres.java @@ -39,7 +39,6 @@ import static junit.framework.Assert.assertEquals; import java.sql.Connection; import java.sql.DriverManager; -import java.util.Arrays; import java.util.List; import org.jooq.Record; @@ -53,10 +52,7 @@ import org.junit.Test; /** * @author Lukas Eder */ -public class TestGeneratedSources { - - private static final List BOOK_IDS = Arrays.asList(1, 2, 3, 4); - private static final List BOOK_TITLES = Arrays.asList("1984", "Animal Farm", "O Alquimista", "Brida"); +public class TestPostgres { @Test public void testFetch() throws Exception { @@ -69,8 +65,8 @@ public class TestGeneratedSources { .orderBy(TBook.ID) .fetch(); - assertEquals(BOOK_IDS, books.getValues(0)); - assertEquals(BOOK_TITLES, books.getValues(1)); + assertEquals(Data.BOOK_IDS, books.getValues(0)); + assertEquals(Data.BOOK_TITLES, books.getValues(1)); } @Test @@ -84,9 +80,9 @@ public class TestGeneratedSources { .orderBy(TBook.ID) .fetchInto(TBookRecord.class); - for (int i = 0; i < BOOK_IDS.size(); i++) { - assertEquals(BOOK_IDS.get(i), books.get(i).getId()); - assertEquals(BOOK_TITLES.get(i), books.get(i).getTitle()); + 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()); } } }