Skip to content

Commit

Permalink
[#7381] 3.11 code generator for H2 throws "Error while fetching enums…
Browse files Browse the repository at this point in the history
…" exception
  • Loading branch information
lukaseder committed Apr 5, 2018
1 parent 9cc13c4 commit e8f63e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
28 changes: 28 additions & 0 deletions jOOQ-meta/src/main/java/org/jooq/util/h2/H2Database.java
Expand Up @@ -37,6 +37,7 @@
*/
package org.jooq.util.h2;

import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.select;
import static org.jooq.util.h2.information_schema.tables.Columns.COLUMNS;
import static org.jooq.util.h2.information_schema.tables.Constraints.CONSTRAINTS;
Expand All @@ -62,6 +63,7 @@
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.SortOrder;
import org.jooq.exception.DataAccessException;
import org.jooq.impl.DSL;
import org.jooq.tools.csv.CSVReader;
import org.jooq.util.AbstractDatabase;
Expand Down Expand Up @@ -467,6 +469,9 @@ protected List<PackageDefinition> getPackages0() throws SQLException {
protected List<EnumDefinition> getEnums0() throws SQLException {
List<EnumDefinition> result = new ArrayList<EnumDefinition>();

if (!is1_4_197())
return result;

Result<Record4<String, String, String, String>> records = create()
.select(
Columns.TABLE_SCHEMA,
Expand Down Expand Up @@ -541,4 +546,27 @@ protected List<ArrayDefinition> getArrays0() throws SQLException {
List<ArrayDefinition> result = new ArrayList<ArrayDefinition>();
return result;
}

private static Boolean is1_4_197;

boolean is1_4_197() {
if (is1_4_197 == null) {

// [#5874] The COLUMNS.COLUMN_TYPE column was introduced in H2 1.4.197
try {
create(true)
.select(Columns.COLUMN_TYPE)
.from(COLUMNS)
.where(falseCondition())
.fetch();

is1_4_197 = true;
}
catch (DataAccessException e) {
is1_4_197 = false;
}
}

return is1_4_197;
}
}
28 changes: 1 addition & 27 deletions jOOQ-meta/src/main/java/org/jooq/util/h2/H2TableDefinition.java
Expand Up @@ -38,7 +38,6 @@
package org.jooq.util.h2;

import static org.jooq.impl.DSL.choose;
import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.zero;
Expand All @@ -51,7 +50,6 @@

import org.jooq.Param;
import org.jooq.Record;
import org.jooq.exception.DataAccessException;
import org.jooq.util.AbstractTableDefinition;
import org.jooq.util.ColumnDefinition;
import org.jooq.util.DataTypeDefinition;
Expand All @@ -68,8 +66,6 @@
*/
public class H2TableDefinition extends AbstractTableDefinition {

private static Boolean is1_4_197;

public H2TableDefinition(SchemaDefinition schema, String name, String comment) {
super(schema, name, comment);
}
Expand All @@ -89,7 +85,7 @@ public List<ColumnDefinition> getElements0() throws SQLException {
Columns.COLUMN_NAME,
Columns.ORDINAL_POSITION,
Columns.TYPE_NAME,
is1_4_197() ? Columns.COLUMN_TYPE : inline("").as(Columns.COLUMN_TYPE),
((H2Database) getDatabase()).is1_4_197() ? Columns.COLUMN_TYPE : inline("").as(Columns.COLUMN_TYPE),
choose().when(Columns.NUMERIC_PRECISION.eq(maxP).and(Columns.NUMERIC_SCALE.eq(maxS)), zero())
.otherwise(Columns.CHARACTER_MAXIMUM_LENGTH).as(Columns.CHARACTER_MAXIMUM_LENGTH),
Columns.NUMERIC_PRECISION.decode(maxP, zero(), Columns.NUMERIC_PRECISION).as(Columns.NUMERIC_PRECISION),
Expand Down Expand Up @@ -135,26 +131,4 @@ public List<ColumnDefinition> getElements0() throws SQLException {

return result;
}


boolean is1_4_197() {
if (is1_4_197 == null) {

// [#5874] The COLUMNS.COLUMN_TYPE column was introduced in H2 1.4.197
try {
create(true)
.select(Columns.COLUMN_TYPE)
.from(COLUMNS)
.where(falseCondition())
.fetch();

is1_4_197 = true;
}
catch (DataAccessException e) {
is1_4_197 = false;
}
}

return is1_4_197;
}
}

0 comments on commit e8f63e3

Please sign in to comment.