mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-22 11:43:09 +00:00
Merge pull request #2513 from FOCONIS/h2-backward-compat
Test against H2 1.4.199
This commit is contained in:
+5
@@ -7,6 +7,8 @@ import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
*/
|
||||
public class H2Ddl extends PlatformDdl {
|
||||
|
||||
private static boolean useV1Syntax = Boolean.getBoolean("ebean.h2.useV1Syntax");
|
||||
|
||||
public H2Ddl(DatabasePlatform platform) {
|
||||
super(platform);
|
||||
this.historyDdl = new H2HistoryDdl();
|
||||
@@ -22,6 +24,9 @@ public class H2Ddl extends PlatformDdl {
|
||||
|
||||
@Override
|
||||
protected String convertArrayType(String logicalArrayType) {
|
||||
if (useV1Syntax) {
|
||||
return "array";
|
||||
}
|
||||
int pos = logicalArrayType.indexOf('[');
|
||||
if (pos == -1) {
|
||||
return logicalArrayType;
|
||||
|
||||
+12
-2
@@ -18,6 +18,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
private static boolean useV1Syntax = Boolean.getBoolean("ebean.h2.useV1Syntax");
|
||||
|
||||
private final DatabaseConfig serverConfig = new DatabaseConfig();
|
||||
|
||||
private DdlHandler handler(DatabasePlatform platform) {
|
||||
@@ -107,7 +109,11 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
write = new DdlWrite();
|
||||
h2Handler().generate(write, Helper.getAlterTableAddDbArrayColumnWithLength());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_ninety varchar array;\n\n");
|
||||
if (useV1Syntax) {
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_ninety array;\n\n");
|
||||
} else {
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_ninety varchar array;\n\n");
|
||||
}
|
||||
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAlterTableAddDbArrayColumnWithLength());
|
||||
@@ -127,7 +133,11 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
write = new DdlWrite();
|
||||
h2Handler().generate(write, Helper.getAlterTableAddDbArrayColumnIntegerWithLength());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_integer integer array;\n\n");
|
||||
if (useV1Syntax) {
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_integer array;\n\n");
|
||||
} else {
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_integer integer array;\n\n");
|
||||
}
|
||||
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAlterTableAddDbArrayColumnIntegerWithLength());
|
||||
|
||||
+13
-4
@@ -25,6 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
private static boolean useV1Syntax = Boolean.getBoolean("ebean.h2.useV1Syntax");
|
||||
|
||||
private final PlatformDdl h2Ddl = PlatformDdlBuilder.create(new H2Platform());
|
||||
private final PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
|
||||
private final PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
|
||||
@@ -57,10 +59,17 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
@Test
|
||||
public void convertArrayType_h2() {
|
||||
assertThat(h2Ddl.convertArrayType("varchar[](90)")).isEqualTo("varchar array");
|
||||
assertThat(h2Ddl.convertArrayType("integer[](60)")).isEqualTo("integer array");
|
||||
assertThat(h2Ddl.convertArrayType("varchar[]")).isEqualTo("varchar array");
|
||||
assertThat(h2Ddl.convertArrayType("integer[]")).isEqualTo("integer array");
|
||||
if (useV1Syntax) {
|
||||
assertThat(h2Ddl.convertArrayType("varchar[](90)")).isEqualTo("array");
|
||||
assertThat(h2Ddl.convertArrayType("integer[](60)")).isEqualTo("array");
|
||||
assertThat(h2Ddl.convertArrayType("varchar[]")).isEqualTo("array");
|
||||
assertThat(h2Ddl.convertArrayType("integer[]")).isEqualTo("array");
|
||||
} else {
|
||||
assertThat(h2Ddl.convertArrayType("varchar[](90)")).isEqualTo("varchar array");
|
||||
assertThat(h2Ddl.convertArrayType("integer[](60)")).isEqualTo("integer array");
|
||||
assertThat(h2Ddl.convertArrayType("varchar[]")).isEqualTo("varchar array");
|
||||
assertThat(h2Ddl.convertArrayType("integer[]")).isEqualTo("integer array");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Automatically configure ServerConfig for testing purposes.
|
||||
* <p>
|
||||
@@ -47,6 +49,29 @@ public class AutoConfigureForTesting implements AutoConfigure {
|
||||
@Override
|
||||
public void postConfigure(DatabaseConfig config) {
|
||||
setupProviders(config);
|
||||
|
||||
if (org.h2.engine.Constants.VERSION_MAJOR == 1) {
|
||||
// This code may be removed later, when droppinv H2 1.xxx compatibility
|
||||
System.err.println("Running tests in H2 1.xxx compatibility mode");
|
||||
System.setProperty("ebean.h2.useV1Syntax", "true");
|
||||
makeV1Compatible(config.getDataSourceConfig());
|
||||
makeV1Compatible(config.getReadOnlyDataSourceConfig());
|
||||
}
|
||||
}
|
||||
|
||||
private void makeV1Compatible(DataSourceConfig ds) {
|
||||
if (ds == null) {
|
||||
return;
|
||||
}
|
||||
String url = ds.getUrl();
|
||||
if (url == null || !url.startsWith("jdbc:h2:")) {
|
||||
return;
|
||||
}
|
||||
// remove illegal URL options
|
||||
url = url.replace(";MODE=LEGACY", "");
|
||||
url = url.replace(";NON_KEYWORDS=KEY,VALUE", "");
|
||||
url = url.replace(";NON_KEYWORDS=KEY", "");
|
||||
ds.setUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,7 +112,7 @@ public class PlatformNoGeneratedKeysTest {
|
||||
config.setDdlRun(true);
|
||||
config.getClasses().add(EBasicVer.class);
|
||||
config.getClasses().add(BasicDraftableBean.class);
|
||||
|
||||
config.loadFromProperties(); // trigger auto config for H2 1.x
|
||||
|
||||
return DatabaseFactory.create(config);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestSqlUpdateUpsert extends BaseTestCase {
|
||||
|
||||
private static boolean useV1Syntax = Boolean.getBoolean("ebean.h2.useV1Syntax");
|
||||
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void h2Merge() throws InterruptedException {
|
||||
@@ -39,7 +41,11 @@ public class TestSqlUpdateUpsert extends BaseTestCase {
|
||||
.setParameter("online", false);
|
||||
|
||||
Object key2 = sqlUpdate2.executeGetKey();
|
||||
assertThat(key2).isEqualTo(key);
|
||||
if (useV1Syntax) {
|
||||
assertThat(key2).isNull();
|
||||
} else {
|
||||
assertThat(key2).isEqualTo(key);
|
||||
}
|
||||
|
||||
|
||||
EPersonOnline found2 = DB.find(EPersonOnline.class).where().eq("email", email).findOne();
|
||||
|
||||
Reference in New Issue
Block a user