[#954] Add examples for source code generation of multiple schemata with Maven

This commit is contained in:
Lukas Eder 2011-11-18 14:52:21 +00:00
parent b25421cbf4
commit 93312a1f2f
5 changed files with 222 additions and 81 deletions

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="target/generated-sources/jooq-postgres"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="target/generated-sources/jooq-postgres"/>
<classpathentry kind="src" path="target/generated-sources/jooq-ase"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>

View File

@ -69,6 +69,13 @@
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.2.4</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
@ -80,17 +87,79 @@
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<!-- The jOOQ code generator plugin for Sybase ASE -->
<!-- [#951] This checks the possibility of empty passwords -->
<!-- The jOOQ code generator plugin for Postgres / Sybase ASE -->
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>2.0.0-SNAPSHOT</version>
<executions>
<execution>
<id>exec1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql:postgres</url>
<schema>public</schema>
<user>postgres</user>
<password>test</password>
</jdbc>
<generator>
<name>org.jooq.util.DefaultGenerator</name>
<database>
<name>org.jooq.util.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes></excludes>
</database>
<generate>
<relations>true</relations>
<deprecated>false</deprecated>
<instanceFields>false</instanceFields>
</generate>
<target>
<packageName>org.jooq.util.maven.example.postgres</packageName>
<directory>target/generated-sources/jooq-postgres</directory>
</target>
</generator>
</configuration>
</execution>
<execution>
<id>exec2</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jdbc>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<url>jdbc:jtds:sybase://lukas-hp:5000/TEST</url>
<schema>dbo</schema>
<user>sa</user>
<!-- [#951] This checks the possibility of empty passwords -->
<password></password>
</jdbc>
<generator>
<name>org.jooq.util.DefaultGenerator</name>
<database>
<name>org.jooq.util.ase.ASEDatabase</name>
<includes>t_.*,x_.*,v_.*,V_.*,p_.*,f_.*,(f|p)[0-9]+,s_.*</includes>
<excludes></excludes>
</database>
<generate>
<relations>true</relations>
<deprecated>false</deprecated>
<instanceFields>true</instanceFields>
</generate>
<target>
<packageName>org.jooq.util.maven.example.ase</packageName>
<directory>target/generated-sources/jooq-ase</directory>
</target>
</generator>
</configuration>
</execution>
</executions>
<dependencies>
@ -99,80 +168,12 @@
<artifactId>jtds</artifactId>
<version>1.2.4</version>
</dependency>
</dependencies>
<configuration>
<jdbc>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<url>jdbc:jtds:sybase://lukas-hp:5000/TEST</url>
<schema>dbo</schema>
<user>sa</user>
<password></password>
</jdbc>
<generator>
<name>org.jooq.util.DefaultGenerator</name>
<database>
<name>org.jooq.util.ase.ASEDatabase</name>
<includes>t_.*,x_.*,v_.*,V_.*,p_.*,f_.*,(f|p)[0-9]+,s_.*</includes>
<excludes></excludes>
</database>
<generate>
<relations>true</relations>
<deprecated>false</deprecated>
<instanceFields>true</instanceFields>
</generate>
<target>
<packageName>org.jooq.util.maven.example.ase</packageName>
<directory>target/generated-sources/jooq-ase</directory>
</target>
</generator>
</configuration>
</plugin>
<!-- The jOOQ code generator plugin for Postgres -->
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>2.0.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-702.jdbc4</version>
</dependency>
</dependencies>
<configuration>
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql:postgres</url>
<schema>public</schema>
<user>postgres</user>
<password>test</password>
</jdbc>
<generator>
<name>org.jooq.util.DefaultGenerator</name>
<database>
<name>org.jooq.util.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes></excludes>
</database>
<generate>
<relations>true</relations>
<deprecated>false</deprecated>
<instanceFields>false</instanceFields>
</generate>
<target>
<packageName>org.jooq.util.maven.example.postgres</packageName>
<directory>target/generated-sources/jooq-postgres</directory>
</target>
</generator>
</configuration>
</plugin>
<!-- Plugins used for Maven Central -->

View File

@ -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<Integer> BOOK_IDS = Arrays.asList(1, 2, 3, 4);
static final List<String> BOOK_TITLES = Arrays.asList("1984", "Animal Farm", "O Alquimista", "Brida");
}

View File

@ -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<Record> 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)));
}
}

View File

@ -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<Integer> BOOK_IDS = Arrays.asList(1, 2, 3, 4);
private static final List<String> 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());
}
}
}