[#2608] Error in code generator when the sqlite_sequence table is
missing
This commit is contained in:
parent
5888b36f65
commit
e60dc20866
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
1
jOOQ-codegen-maven-example/sqlite/.gitignore
vendored
Normal file
1
jOOQ-codegen-maven-example/sqlite/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/2608.db
|
||||
@ -0,0 +1,7 @@
|
||||
DROP TABLE IF EXISTS test;
|
||||
|
||||
CREATE TABLE test (
|
||||
x INT,
|
||||
|
||||
CONSTRAINT pk_test PRIMARY KEY (x)
|
||||
);
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6" javaProject="jOOQ-codegen" path="1" type="4"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="3" projectName="jOOU" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="3" projectName="jOOQ" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER" javaProject="jOOQ" path="3" type="4"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="3" projectName="jOOQ-codegen" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="3" projectName="jOOQ-test" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/commons-io-1.4.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/ojdbc6.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/db2jcc4.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/sqlite-jdbc-3.7.15-SNAPSHOT-2.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derby.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derbyclient.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derbynet.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derbytools.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derbyrun.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/postgresql-9.0-801.jdbc4.jar" path="3" sourceAttachmentPath="/jOOQ-sources/postgresql-jdbc-9.0-801.src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="3" projectName="jOOQ-meta" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/log4j-1.2.16.jar" path="3" type="2"/> "/>
|
||||
</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>
|
||||
Loading…
Reference in New Issue
Block a user