Skip to content

Commit

Permalink
[#6602] Code generation for routines fails on MySQL 8
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Sep 20, 2017
1 parent 626bf74 commit dac3a60
Show file tree
Hide file tree
Showing 14 changed files with 1,600 additions and 947 deletions.
83 changes: 51 additions & 32 deletions jOOQ-meta/src/main/java/org/jooq/util/mysql/MySQLDatabase.java
Expand Up @@ -40,11 +40,11 @@
import static org.jooq.util.mysql.information_schema.Tables.COLUMNS; import static org.jooq.util.mysql.information_schema.Tables.COLUMNS;
import static org.jooq.util.mysql.information_schema.Tables.KEY_COLUMN_USAGE; import static org.jooq.util.mysql.information_schema.Tables.KEY_COLUMN_USAGE;
import static org.jooq.util.mysql.information_schema.Tables.REFERENTIAL_CONSTRAINTS; import static org.jooq.util.mysql.information_schema.Tables.REFERENTIAL_CONSTRAINTS;
import static org.jooq.util.mysql.information_schema.Tables.ROUTINES;
import static org.jooq.util.mysql.information_schema.Tables.SCHEMATA; import static org.jooq.util.mysql.information_schema.Tables.SCHEMATA;
import static org.jooq.util.mysql.information_schema.Tables.STATISTICS; import static org.jooq.util.mysql.information_schema.Tables.STATISTICS;
import static org.jooq.util.mysql.information_schema.Tables.TABLES; import static org.jooq.util.mysql.information_schema.Tables.TABLES;
import static org.jooq.util.mysql.mysql.tables.Proc.DB; import static org.jooq.util.mysql.mysql.Tables.PROC;
import static org.jooq.util.mysql.mysql.tables.Proc.PROC;


import java.io.StringReader; import java.io.StringReader;
import java.sql.SQLException; import java.sql.SQLException;
Expand Down Expand Up @@ -87,6 +87,7 @@
import org.jooq.util.mysql.information_schema.tables.Columns; import org.jooq.util.mysql.information_schema.tables.Columns;
import org.jooq.util.mysql.information_schema.tables.KeyColumnUsage; import org.jooq.util.mysql.information_schema.tables.KeyColumnUsage;
import org.jooq.util.mysql.information_schema.tables.ReferentialConstraints; import org.jooq.util.mysql.information_schema.tables.ReferentialConstraints;
import org.jooq.util.mysql.information_schema.tables.Routines;
import org.jooq.util.mysql.information_schema.tables.Schemata; import org.jooq.util.mysql.information_schema.tables.Schemata;
import org.jooq.util.mysql.information_schema.tables.Statistics; import org.jooq.util.mysql.information_schema.tables.Statistics;
import org.jooq.util.mysql.information_schema.tables.Tables; import org.jooq.util.mysql.information_schema.tables.Tables;
Expand All @@ -99,6 +100,7 @@
public class MySQLDatabase extends AbstractDatabase { public class MySQLDatabase extends AbstractDatabase {


private static final JooqLogger log = JooqLogger.getLogger(MySQLDatabase.class); private static final JooqLogger log = JooqLogger.getLogger(MySQLDatabase.class);
private static Boolean is8;


@Override @Override
protected List<IndexDefinition> getIndexes0() throws SQLException { protected List<IndexDefinition> getIndexes0() throws SQLException {
Expand Down Expand Up @@ -210,6 +212,22 @@ private String getKeyName(String tableName, String keyName) {
return "KEY_" + tableName + "_" + keyName; return "KEY_" + tableName + "_" + keyName;
} }


private boolean is8() {
if (is8 == null) {

// [#6602] The mysql.proc table got removed in MySQL 8.0
try {
create(true).fetchExists(PROC);
is8 = false;
}
catch (DataAccessException ignore) {
is8 = true;
}
}

return is8;
}

private Result<Record4<String, String, String, String>> fetchKeys(boolean primary) { private Result<Record4<String, String, String, String>> fetchKeys(boolean primary) {


// [#3560] It has been shown that querying the STATISTICS table is much faster on // [#3560] It has been shown that querying the STATISTICS table is much faster on
Expand All @@ -227,7 +245,7 @@ private Result<Record4<String, String, String, String>> fetchKeys(boolean primar
: falseCondition())) : falseCondition()))
.and(primary .and(primary
? Statistics.INDEX_NAME.eq(inline("PRIMARY")) ? Statistics.INDEX_NAME.eq(inline("PRIMARY"))
: Statistics.INDEX_NAME.ne(inline("PRIMARY")).and(Statistics.NON_UNIQUE.eq(inline(0L)))) : Statistics.INDEX_NAME.ne(inline("PRIMARY")).and(Statistics.NON_UNIQUE.eq(inline("0"))))
.orderBy( .orderBy(
Statistics.TABLE_SCHEMA, Statistics.TABLE_SCHEMA,
Statistics.TABLE_NAME, Statistics.TABLE_NAME,
Expand Down Expand Up @@ -433,31 +451,34 @@ protected List<ArrayDefinition> getArrays0() throws SQLException {
protected List<RoutineDefinition> getRoutines0() throws SQLException { protected List<RoutineDefinition> getRoutines0() throws SQLException {
List<RoutineDefinition> result = new ArrayList<RoutineDefinition>(); List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();


try { Result<Record6<String, String, String, byte[], byte[], ProcType>> records = is8()
create(true).fetchCount(PROC);
} ? create().select(
catch (DataAccessException e) { Routines.ROUTINE_SCHEMA,
log.warn("Table unavailable", "The `mysql`.`proc` table is unavailable. Stored procedures cannot be loaded. Check if you have sufficient grants"); Routines.ROUTINE_NAME,
return result; Routines.ROUTINE_COMMENT,
} inline(new byte[0]).as(Proc.PARAM_LIST),

inline(new byte[0]).as(Proc.RETURNS),
Result<Record6<String, String, String, byte[], byte[], ProcType>> records = Routines.ROUTINE_TYPE.coerce(Proc.TYPE).as(Routines.ROUTINE_TYPE))
create().select( .from(ROUTINES)
Proc.DB, .where(Routines.ROUTINE_SCHEMA.in(getInputSchemata()))
Proc.NAME, .orderBy(1, 2, 6)
Proc.COMMENT, .fetch()

: create().select(
Proc.DB.as(Routines.ROUTINE_SCHEMA),
Proc.NAME.as(Routines.ROUTINE_NAME),
Proc.COMMENT.as(Routines.ROUTINE_COMMENT),
Proc.PARAM_LIST, Proc.PARAM_LIST,
Proc.RETURNS, Proc.RETURNS,
Proc.TYPE) Proc.TYPE.as(Routines.ROUTINE_TYPE))
.from(PROC) .from(PROC)
.where(DB.in(getInputSchemata())) .where(Proc.DB.in(getInputSchemata()))
.orderBy( .orderBy(1, 2, 6)
DB,
Proc.NAME)
.fetch(); .fetch();


Map<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> groups = Map<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> groups =
records.intoGroups(new Field[] { Proc.DB, Proc.NAME }); records.intoGroups(new Field[] { Routines.ROUTINE_SCHEMA, Routines.ROUTINE_NAME });


// [#1908] This indirection is necessary as MySQL allows for overloading // [#1908] This indirection is necessary as MySQL allows for overloading
// procedures and functions with the same signature. // procedures and functions with the same signature.
Expand All @@ -467,19 +488,17 @@ protected List<RoutineDefinition> getRoutines0() throws SQLException {
for (int i = 0; i < overloads.size(); i++) { for (int i = 0; i < overloads.size(); i++) {
Record record = overloads.get(i); Record record = overloads.get(i);


SchemaDefinition schema = getSchema(record.get(DB)); SchemaDefinition schema = getSchema(record.get(Routines.ROUTINE_SCHEMA));
String name = record.get(Proc.NAME); String name = record.get(Routines.ROUTINE_NAME);
String comment = record.get(Proc.COMMENT); String comment = record.get(Routines.ROUTINE_COMMENT);
String params = new String(record.get(Proc.PARAM_LIST)); String params = is8() ? "" : new String(record.get(Proc.PARAM_LIST));
String returns = new String(record.get(Proc.RETURNS)); String returns = is8() ? "" : new String(record.get(Proc.RETURNS));
ProcType type = record.get(Proc.TYPE); ProcType type = record.get(Routines.ROUTINE_TYPE.coerce(Proc.TYPE).as(Routines.ROUTINE_TYPE));


if (overloads.size() > 1) { if (overloads.size() > 1)
result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, "_" + type.name())); result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, "_" + type.name()));
} else
else {
result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, null)); result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, null));
}
} }
} }


Expand Down
Expand Up @@ -57,10 +57,10 @@
*/ */
public class MySQLRoutineDefinition extends AbstractRoutineDefinition { public class MySQLRoutineDefinition extends AbstractRoutineDefinition {


private Boolean is55; private static Boolean is55;


private final String params; private final String params;
private final String returns; private final String returns;
private final ProcType procType; private final ProcType procType;


/** /**
Expand All @@ -81,12 +81,10 @@ public MySQLRoutineDefinition(SchemaDefinition schema, String name, String comme


@Override @Override
protected void init0() { protected void init0() {
if (is55()) { if (is55())
init55(); init55();
} else
else {
init54(); init54();
}
} }


private void init55() { private void init55() {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dac3a60

Please sign in to comment.