[#430] Add support for the Firebird database - Added SEQUENCE support

This commit is contained in:
Lukas Eder 2012-08-24 10:21:53 +02:00
parent 2de3f18021
commit 5cf50f1b55
6 changed files with 115 additions and 81 deletions

View File

@ -35,6 +35,7 @@
*/
package org.jooq.util.firebird;
import static org.jooq.util.firebird.rdb.Tables.RDB$GENERATORS;
import static org.jooq.util.firebird.rdb.Tables.RDB$INDEX_SEGMENTS;
import static org.jooq.util.firebird.rdb.Tables.RDB$REF_CONSTRAINTS;
import static org.jooq.util.firebird.rdb.Tables.RDB$RELATIONS;
@ -45,12 +46,14 @@ import java.util.ArrayList;
import java.util.List;
import org.jooq.Record;
import org.jooq.Result;
import org.jooq.impl.Factory;
import org.jooq.util.AbstractDatabase;
import org.jooq.util.ArrayDefinition;
import org.jooq.util.ColumnDefinition;
import org.jooq.util.DataTypeDefinition;
import org.jooq.util.DefaultDataTypeDefinition;
import org.jooq.util.DefaultRelations;
import org.jooq.util.DefaultSequenceDefinition;
import org.jooq.util.EnumDefinition;
import org.jooq.util.PackageDefinition;
import org.jooq.util.RoutineDefinition;
@ -131,7 +134,7 @@ public class FirebirdDatabase extends AbstractDatabase {
Rdb$indexSegments isp = RDB$INDEX_SEGMENTS.as("isp");
Rdb$indexSegments isf = RDB$INDEX_SEGMENTS.as("isf");
Result<Record> fetch = create()
for (Record record : create()
.selectDistinct(
fk.RDB$CONSTRAINT_NAME.trim().as("fk"),
fk.RDB$RELATION_NAME.trim().as("fkTable"),
@ -147,10 +150,7 @@ public class FirebirdDatabase extends AbstractDatabase {
.orderBy(
fk.RDB$CONSTRAINT_NAME.asc(),
isf.RDB$FIELD_POSITION.asc())
.fetch();
System.out.println(fetch.format(1000));
for (Record record : fetch) {
.fetch()) {
String pkName = record.getValue("pk", String.class);
String pkTable = record.getValue("pkTable", String.class);
@ -179,6 +179,20 @@ public class FirebirdDatabase extends AbstractDatabase {
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
for (String sequenceName : create()
.select(RDB$GENERATORS.RDB$GENERATOR_NAME.trim())
.from(RDB$GENERATORS)
.orderBy(1)
.fetch(RDB$GENERATORS.RDB$GENERATOR_NAME.trim())) {
SchemaDefinition schema = getSchemata().get(0);
DataTypeDefinition type = new DefaultDataTypeDefinition(
this, schema, FirebirdDataType.BIGINT.getTypeName(), 0, 0, 0);
result.add(new DefaultSequenceDefinition(schema, sequenceName, type ));
}
return result;
}
@ -186,13 +200,11 @@ public class FirebirdDatabase extends AbstractDatabase {
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<TableDefinition>();
for (Record recTableName : create()
for (String tableName : create()
.select(RDB$RELATIONS.RDB$RELATION_NAME.trim())
.from(RDB$RELATIONS)
.orderBy(1)
.fetch()) {
String tableName = recTableName.getValueAsString(0);
.fetch(0, String.class)) {
TableDefinition tableDef = new FirebirdTableDefinition(getSchemata().get(0), tableName, "");
result.add(tableDef);

View File

@ -12,16 +12,16 @@ package org.jooq.util.firebird.rdb;
comments = "This class is generated by jOOQ")
public final class Tables {
/**
* The table RDB$DEPENDENCIES
*/
public static final org.jooq.util.firebird.rdb.tables.Rdb$dependencies RDB$DEPENDENCIES = org.jooq.util.firebird.rdb.tables.Rdb$dependencies.RDB$DEPENDENCIES;
/**
* The table RDB$FIELDS
*/
public static final org.jooq.util.firebird.rdb.tables.Rdb$fields RDB$FIELDS = org.jooq.util.firebird.rdb.tables.Rdb$fields.RDB$FIELDS;
/**
* The table RDB$GENERATORS
*/
public static final org.jooq.util.firebird.rdb.tables.Rdb$generators RDB$GENERATORS = org.jooq.util.firebird.rdb.tables.Rdb$generators.RDB$GENERATORS;
/**
* The table RDB$INDEX_SEGMENTS
*/

View File

@ -1,65 +0,0 @@
/**
* This class is generated by jOOQ
*/
package org.jooq.util.firebird.rdb.tables;
/**
* This class is generated by jOOQ.
*/
@javax.annotation.Generated(value = {"http://www.jooq.org", "2.5.0"},
comments = "This class is generated by jOOQ")
public class Rdb$dependencies extends org.jooq.impl.TableImpl<org.jooq.Record> {
private static final long serialVersionUID = 2134234347;
/**
* The singleton instance of RDB$DEPENDENCIES
*/
public static final org.jooq.util.firebird.rdb.tables.Rdb$dependencies RDB$DEPENDENCIES = new org.jooq.util.firebird.rdb.tables.Rdb$dependencies();
/**
* The class holding records for this type
*/
@Override
public java.lang.Class<org.jooq.Record> getRecordType() {
return org.jooq.Record.class;
}
/**
* The table column <code>RDB$DEPENDENCIES.RDB$DEPENDENT_NAME</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.String> RDB$DEPENDENT_NAME = createField("RDB$DEPENDENT_NAME", org.jooq.impl.SQLDataType.CHAR, this);
/**
* The table column <code>RDB$DEPENDENCIES.RDB$DEPENDED_ON_NAME</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.String> RDB$DEPENDED_ON_NAME = createField("RDB$DEPENDED_ON_NAME", org.jooq.impl.SQLDataType.CHAR, this);
/**
* The table column <code>RDB$DEPENDENCIES.RDB$FIELD_NAME</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.String> RDB$FIELD_NAME = createField("RDB$FIELD_NAME", org.jooq.impl.SQLDataType.CHAR, this);
/**
* The table column <code>RDB$DEPENDENCIES.RDB$DEPENDENT_TYPE</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.Short> RDB$DEPENDENT_TYPE = createField("RDB$DEPENDENT_TYPE", org.jooq.impl.SQLDataType.SMALLINT, this);
/**
* The table column <code>RDB$DEPENDENCIES.RDB$DEPENDED_ON_TYPE</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.Short> RDB$DEPENDED_ON_TYPE = createField("RDB$DEPENDED_ON_TYPE", org.jooq.impl.SQLDataType.SMALLINT, this);
public Rdb$dependencies() {
super("RDB$DEPENDENCIES");
}
public Rdb$dependencies(java.lang.String alias) {
super(alias, null, org.jooq.util.firebird.rdb.tables.Rdb$dependencies.RDB$DEPENDENCIES);
}
@Override
public org.jooq.util.firebird.rdb.tables.Rdb$dependencies as(java.lang.String alias) {
return new org.jooq.util.firebird.rdb.tables.Rdb$dependencies(alias);
}
}

View File

@ -0,0 +1,60 @@
/**
* This class is generated by jOOQ
*/
package org.jooq.util.firebird.rdb.tables;
/**
* This class is generated by jOOQ.
*/
@javax.annotation.Generated(value = {"http://www.jooq.org", "2.5.0"},
comments = "This class is generated by jOOQ")
public class Rdb$generators extends org.jooq.impl.TableImpl<org.jooq.Record> {
private static final long serialVersionUID = 152901621;
/**
* The singleton instance of RDB$GENERATORS
*/
public static final org.jooq.util.firebird.rdb.tables.Rdb$generators RDB$GENERATORS = new org.jooq.util.firebird.rdb.tables.Rdb$generators();
/**
* The class holding records for this type
*/
@Override
public java.lang.Class<org.jooq.Record> getRecordType() {
return org.jooq.Record.class;
}
/**
* The table column <code>RDB$GENERATORS.RDB$GENERATOR_NAME</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.String> RDB$GENERATOR_NAME = createField("RDB$GENERATOR_NAME", org.jooq.impl.SQLDataType.CHAR, this);
/**
* The table column <code>RDB$GENERATORS.RDB$GENERATOR_ID</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.Short> RDB$GENERATOR_ID = createField("RDB$GENERATOR_ID", org.jooq.impl.SQLDataType.SMALLINT, this);
/**
* The table column <code>RDB$GENERATORS.RDB$SYSTEM_FLAG</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.Short> RDB$SYSTEM_FLAG = createField("RDB$SYSTEM_FLAG", org.jooq.impl.SQLDataType.SMALLINT, this);
/**
* The table column <code>RDB$GENERATORS.RDB$DESCRIPTION</code>
*/
public final org.jooq.TableField<org.jooq.Record, java.lang.String> RDB$DESCRIPTION = createField("RDB$DESCRIPTION", org.jooq.impl.SQLDataType.CLOB, this);
public Rdb$generators() {
super("RDB$GENERATORS");
}
public Rdb$generators(java.lang.String alias) {
super(alias, null, org.jooq.util.firebird.rdb.tables.Rdb$generators.RDB$GENERATORS);
}
@Override
public org.jooq.util.firebird.rdb.tables.Rdb$generators as(java.lang.String alias) {
return new org.jooq.util.firebird.rdb.tables.Rdb$generators(alias);
}
}

View File

@ -6,7 +6,7 @@ jdbc.Password=TEST
generator=org.jooq.util.DefaultGenerator
generator.database=org.jooq.util.firebird.FirebirdDatabase
generator.database.includes=RDB\\$RELATIONS,RDB\\$RELATION_FIELDS,RDB\\$FIELDS,RDB\\$RELATION_CONSTRAINTS,RDB\\$REF_CONSTRAINTS,RDB\\$DEPENDENCIES,RDB\\$INDEX_SEGMENTS
generator.database.includes=RDB\\$RELATIONS,RDB\\$RELATION_FIELDS,RDB\\$FIELDS,RDB\\$RELATION_CONSTRAINTS,RDB\\$REF_CONSTRAINTS,RDB\\$INDEX_SEGMENTS,RDB\\$GENERATORS
generator.database.excludes=
generator.generate.deprecated=false
generator.generate.fields=both

View File

@ -0,0 +1,27 @@
/**
* This class is generated by jOOQ
*/
package org.jooq.test.firebird.generatedclasses;
/**
* This class is generated by jOOQ.
*
* Convenience access to all sequences in
*/
public final class Sequences {
/**
* The sequence SQL$DEFAULT
*/
public static final org.jooq.Sequence<java.lang.Long> SQL$DEFAULT = new org.jooq.impl.SequenceImpl<java.lang.Long>("SQL$DEFAULT", null, org.jooq.impl.SQLDataType.BIGINT);
/**
* The sequence S_AUTHOR_ID
*/
public static final org.jooq.Sequence<java.lang.Long> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.lang.Long>("S_AUTHOR_ID", null, org.jooq.impl.SQLDataType.BIGINT);
/**
* No instances
*/
private Sequences() {}
}