#1814 - Support older MySQL 5.5

This commit is contained in:
rob bygrave
2019-09-11 21:37:52 +12:00
parent c1487daea8
commit 46eeee68c9
10 changed files with 48 additions and 8 deletions
+2 -2
View File
@@ -118,7 +118,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-annotation</artifactId>
<version>4.12</version>
<version>4.13</version>
</dependency>
<dependency>
@@ -330,7 +330,7 @@
<plugin>
<groupId>io.ebean</groupId>
<artifactId>ebean-maven-plugin</artifactId>
<version>11.44.1</version>
<version>11.45.1</version>
<executions>
<execution>
<id>test</id>
@@ -0,0 +1,14 @@
package io.ebean.config.dbplatform.mysql;
import io.ebean.annotation.Platform;
import io.ebean.config.dbplatform.DbPlatformType;
import io.ebean.config.dbplatform.DbType;
public class MySql55Platform extends MySqlPlatform {
public MySql55Platform() {
super();
this.platform = Platform.MYSQL55;
dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime"));
}
}
@@ -14,6 +14,7 @@ import io.ebean.config.dbplatform.db2.DB2Platform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.hana.HanaPlatform;
import io.ebean.config.dbplatform.hsqldb.HsqldbPlatform;
import io.ebean.config.dbplatform.mysql.MySql55Platform;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebean.config.dbplatform.nuodb.NuoDbPlatform;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
@@ -787,6 +788,8 @@ public class DefaultDbMigration implements DbMigration {
return new HsqldbPlatform();
case POSTGRES:
return new PostgresPlatform();
case MYSQL55:
return new MySql55Platform();
case MYSQL:
return new MySqlPlatform();
case ORACLE:
@@ -8,6 +8,7 @@ import io.ebean.config.dbplatform.db2.DB2Platform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.hana.HanaPlatform;
import io.ebean.config.dbplatform.hsqldb.HsqldbPlatform;
import io.ebean.config.dbplatform.mysql.MySql55Platform;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebean.config.dbplatform.nuodb.NuoDbPlatform;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
@@ -82,6 +83,9 @@ public class DatabasePlatformFactory {
if (dbName.equals("mysql")) {
return new MySqlPlatform();
}
if (dbName.equals("mysql55")) {
return new MySql55Platform();
}
if (dbName.equals("postgres") || dbName.equals("postgres9")) {
return new PostgresPlatform();
}
@@ -147,15 +151,16 @@ public class DatabasePlatformFactory {
*/
private DatabasePlatform byDatabaseMeta(DatabaseMetaData metaData, Connection connection) throws SQLException {
String dbProductName = metaData.getDatabaseProductName();
dbProductName = dbProductName.toLowerCase();
String dbProductName = metaData.getDatabaseProductName().toLowerCase();
final int majorVersion = metaData.getDatabaseMajorVersion();
final int minorVersion = metaData.getDatabaseMinorVersion();
if (dbProductName.contains("oracle")) {
return new OraclePlatform();
} else if (dbProductName.contains("microsoft")) {
throw new IllegalArgumentException("For SqlServer please explicitly choose either sqlserver16 or sqlserver17 as the platform via ServerConfig.setDatabasePlatformName. Refer to issue #1340 for more details");
} else if (dbProductName.contains("mysql")) {
return new MySqlPlatform();
return mysqlVersion(majorVersion, minorVersion);
} else if (dbProductName.contains("h2")) {
return new H2Platform();
} else if (dbProductName.contains("hsql database engine")) {
@@ -180,6 +185,13 @@ public class DatabasePlatformFactory {
return new DatabasePlatform();
}
private DatabasePlatform mysqlVersion(int majorVersion, int minorVersion) {
if (majorVersion <= 5 && minorVersion <= 5) {
return new MySql55Platform();
}
return new MySqlPlatform();
}
/**
* Use a select version() query as it could be Postgres or CockroachDB.
*/
@@ -514,7 +514,7 @@ public class InternalConfiguration {
String tz = serverConfig.getDataTimeZone();
if (tz == null) {
if (getPlatform() == Platform.MYSQL) {
if (isMySql(getPlatform())) {
return new LocalDataTimeZone();
}
return new NoDataTimeZone();
@@ -526,6 +526,10 @@ public class InternalConfiguration {
}
}
private boolean isMySql(Platform platform) {
return platform == Platform.MYSQL || platform == Platform.MYSQL55;
}
public DataTimeZone getDataTimeZone() {
return dataTimeZone;
}
@@ -30,6 +30,7 @@ public class PlatformDdlBuilder {
return new H2Ddl(platform);
case DB2:
return new DB2Ddl(platform);
case MYSQL55:
case MYSQL:
return new MySqlDdl(platform);
case HSQLDB:
@@ -17,6 +17,7 @@ public class DbExpressionHandlerFactory {
return new H2DbExpression();
case POSTGRES:
return new PostgresDbExpression();
case MYSQL55:
case MYSQL:
return new MySqlDbExpression();
case ORACLE:
@@ -141,7 +141,7 @@ class CQueryBuilder {
if (dbPlatform.isSupportsDeleteTableAlias()) {
// delete from table <alias> ...
return aliasReplace(buildSql("delete", request, predicates, sqlTree).getSql(), alias);
} else if (dbPlatform.getPlatform() == Platform.MYSQL) {
} else if (isMySql(dbPlatform.getPlatform())) {
return aliasReplace(buildSql("delete " + alias, request, predicates, sqlTree).getSql(), alias);
} else {
// simple - delete from table ...
@@ -155,6 +155,10 @@ class CQueryBuilder {
return sql;
}
private boolean isMySql(Platform platform) {
return platform == Platform.MYSQL || platform == Platform.MYSQL55;
}
private String alias(String rootTableAlias) {
return (rootTableAlias == null) ? "t0" : rootTableAlias;
}
+1 -1
View File
@@ -183,7 +183,7 @@ public abstract class BaseTestCase {
}
public boolean isMySql() {
return Platform.MYSQL == platform();
return Platform.MYSQL == platform() || Platform.MYSQL55 == platform();
}
public boolean isHana() {
@@ -49,6 +49,7 @@ public class DbMigrationGenerateTest {
migration.addPlatform(Platform.H2, "h2");
migration.addPlatform(Platform.HSQLDB, "hsqldb");
migration.addPlatform(Platform.MYSQL, "mysql");
migration.addPlatform(Platform.MYSQL55, "mysql55");
migration.addPlatform(Platform.POSTGRES, "postgres");
migration.addPlatform(Platform.ORACLE, "oracle");
migration.addPlatform(Platform.SQLITE, "sqlite");