[#2608] Error in code generator when the sqlite_sequence table is

missing
This commit is contained in:
Lukas Eder 2013-07-05 09:56:23 +02:00
parent 5888b36f65
commit e60dc20866
7 changed files with 129 additions and 69 deletions

View File

@ -12,6 +12,7 @@
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-test-sources/jooq-h2"/>
<classpathentry kind="src" path="target/generated-test-sources/jooq-sqlite"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>

View File

@ -48,6 +48,11 @@
<artifactId>h2</artifactId>
<version>1.3.168</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.15-M1</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
@ -156,39 +161,69 @@
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<!-- common configuration shared by all executions -->
<configuration>
<!--all executions are ignored if -Dmaven.test.skip=true -->
<skip>${maven.test.skip}</skip>
<forkMode>always</forkMode>
</configuration>
<executions>
<execution>
<id>create-database-h2</id>
<phase>generate-test-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<driver>org.h2.Driver</driver>
<url>jdbc:h2:~/maven-test</url>
<username>sa</username>
<password></password>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/test/resources/db-h2.sql</srcFile>
</srcFiles>
</configuration>
</execution>
<!-- TODO: Find out how database creation and code generation can be run at the same time
without running into native dll classloading problems
<execution>
<id>create-database-sqlite</id>
<phase>generate-test-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<driver>org.sqlite.JDBC</driver>
<url>jdbc:sqlite:sqlite/2608.db</url>
<username>sa</username>
<password></password>
<escapeProcessing>false</escapeProcessing>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/test/resources/db-sqlite.sql</srcFile>
</srcFiles>
</configuration>
</execution>
-->
</executions>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.15-M1</version>
</dependency>
</dependencies>
<!-- common configuration shared by all executions -->
<configuration>
<driver>org.h2.Driver</driver>
<url>jdbc:h2:~/maven-test</url>
<username>sa</username>
<password></password>
<!--all executions are ignored if -Dmaven.test.skip=true -->
<skip>${maven.test.skip}</skip>
</configuration>
<executions>
<execution>
<id>create-database</id>
<phase>generate-test-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/test/resources/db.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
<!-- The jOOQ code generator plugin for Postgres / Sybase ASE / MySQL -->
@ -196,9 +231,10 @@
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.2.0-SNAPSHOT</version>
<executions>
<execution>
<id>exec1</id>
<id>generate-h2</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generate</goal>
@ -231,6 +267,40 @@
</generator>
</configuration>
</execution>
<execution>
<id>generate-sqlite</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jdbc>
<driver>org.sqlite.JDBC</driver>
<url>jdbc:sqlite:sqlite/2608.db</url>
<user>sa</user>
<password></password>
</jdbc>
<generator>
<name>org.jooq.util.DefaultGenerator</name>
<database>
<name>org.jooq.util.sqlite.SQLiteDatabase</name>
<includes>.*</includes>
<excludes></excludes>
<dateAsTimestamp>true</dateAsTimestamp>
</database>
<generate>
<deprecated>false</deprecated>
<instanceFields>true</instanceFields>
<pojos>true</pojos>
</generate>
<target>
<packageName>org.jooq.maven.example.sqlite</packageName>
<directory>target/generated-test-sources/jooq-sqlite</directory>
</target>
</generator>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
@ -238,6 +308,11 @@
<artifactId>h2</artifactId>
<version>1.3.168</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.15-M1</version>
</dependency>
</dependencies>
</plugin>
</plugins>

View File

@ -0,0 +1 @@
/2608.db

View File

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS test;
CREATE TABLE test (
x INT,
CONSTRAINT pk_test PRIMARY KEY (x)
);

View File

@ -35,6 +35,8 @@
*/
package org.jooq.util.sqlite;
import static org.jooq.util.sqlite.sqlite_master.SQLiteMaster.SQLITE_MASTER;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@ -45,6 +47,7 @@ import org.jooq.util.ColumnDefinition;
import org.jooq.util.DefaultColumnDefinition;
import org.jooq.util.DefaultDataTypeDefinition;
import org.jooq.util.SchemaDefinition;
import org.jooq.util.sqlite.sqlite_master.SQLiteMaster;
/**
* SQLite table definition
@ -53,6 +56,8 @@ import org.jooq.util.SchemaDefinition;
*/
public class SQLiteTableDefinition extends AbstractTableDefinition {
private static Boolean existsSqliteSequence;
public SQLiteTableDefinition(SchemaDefinition schema, String name, String comment) {
super(schema, name, comment);
}
@ -74,7 +79,7 @@ public class SQLiteTableDefinition extends AbstractTableDefinition {
// SQLite identities are primary keys whose tables are mentioned in
// sqlite_sequence
boolean pk = record.getValue("pk", Boolean.class);
boolean identity = pk && create()
boolean identity = pk && existsSqliteSequence() && create()
.fetchOne("select count(*) from sqlite_sequence where name = ?", getName())
.getValue(0, Boolean.class);
@ -100,4 +105,16 @@ public class SQLiteTableDefinition extends AbstractTableDefinition {
return result;
}
private boolean existsSqliteSequence() {
if (existsSqliteSequence == null) {
existsSqliteSequence = create()
.selectCount()
.from(SQLITE_MASTER)
.where(SQLiteMaster.NAME.lower().eq("sqlite_sequence"))
.fetchOne(0, boolean.class);
}
return existsSqliteSequence;
}
}

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<stringAttribute key="bad_container_name" value="/jOOQ-codegen/launch"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6&quot; javaProject=&quot;jOOQ-codegen&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry path=&quot;3&quot; projectName=&quot;jOOU&quot; type=&quot;1&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry path=&quot;3&quot; projectName=&quot;jOOQ&quot; type=&quot;1&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER&quot; javaProject=&quot;jOOQ&quot; path=&quot;3&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry path=&quot;3&quot; projectName=&quot;jOOQ-codegen&quot; type=&quot;1&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry path=&quot;3&quot; projectName=&quot;jOOQ-test&quot; type=&quot;1&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/commons-io-1.4.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/ojdbc6.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/db2jcc4.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/sqlite-jdbc-3.7.15-SNAPSHOT-2.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/derby.jar&quot; path=&quot;3&quot; sourceAttachmentPath=&quot;/jOOQ-sources/db-derby-10.8.1.2-src.zip&quot; sourceRootPath=&quot;&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/derbyclient.jar&quot; path=&quot;3&quot; sourceAttachmentPath=&quot;/jOOQ-sources/db-derby-10.8.1.2-src.zip&quot; sourceRootPath=&quot;&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/derbynet.jar&quot; path=&quot;3&quot; sourceAttachmentPath=&quot;/jOOQ-sources/db-derby-10.8.1.2-src.zip&quot; sourceRootPath=&quot;&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/derbytools.jar&quot; path=&quot;3&quot; sourceAttachmentPath=&quot;/jOOQ-sources/db-derby-10.8.1.2-src.zip&quot; sourceRootPath=&quot;&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/derbyrun.jar&quot; path=&quot;3&quot; sourceAttachmentPath=&quot;/jOOQ-sources/db-derby-10.8.1.2-src.zip&quot; sourceRootPath=&quot;&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/postgresql-9.0-801.jdbc4.jar&quot; path=&quot;3&quot; sourceAttachmentPath=&quot;/jOOQ-sources/postgresql-jdbc-9.0-801.src.zip&quot; sourceRootPath=&quot;&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry path=&quot;3&quot; projectName=&quot;jOOQ-meta&quot; type=&quot;1&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/jOOQ-test/lib/log4j-1.2.16.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.jooq.util.GenerationTool"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="/org/jooq/configuration/${env_var:USERNAME}/sqlite/library.xml"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="jOOQ-codegen"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:jOOQ-test}"/>
</launchConfiguration>