mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add SAP HANA support (#1511)
This commit is contained in:
committed by
Rob Bygrave
parent
b1410cc660
commit
158ee9a081
@@ -53,12 +53,14 @@ public class DbMigrationGenerateTest {
|
||||
migration.addPlatform(Platform.ORACLE, "oracle");
|
||||
migration.addPlatform(Platform.SQLITE, "sqlite");
|
||||
migration.addPlatform(Platform.SQLSERVER17, "sqlserver17");
|
||||
migration.addPlatform(Platform.HANA, "hana");
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
config.setName("migrationtest");
|
||||
config.loadFromProperties();
|
||||
config.setRegister(false);
|
||||
config.setDefaultServer(false);
|
||||
config.getProperties().put("ebean.hana.generateUniqueDdl", "true"); // need to generate unique statements to prevent them from being filtered out as duplicates by the DdlRunner
|
||||
|
||||
|
||||
config.setPackages(Arrays.asList("misc.migration.v1_0"));
|
||||
|
||||
@@ -7,7 +7,6 @@ import io.ebean.SqlUpdate;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.migration.MigrationConfig;
|
||||
import io.ebean.migration.ddl.DdlRunner;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.Helper;
|
||||
|
||||
@@ -90,7 +89,7 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
|
||||
runScript(false, "1.0__initial.sql");
|
||||
|
||||
if (isOracle()) {
|
||||
if (isOracle() || isHana()) {
|
||||
SqlUpdate update = server().createSqlUpdate("insert into migtest_e_basic (id, old_boolean, user_id) values (1, :false, 1)");
|
||||
update.setParameter("false", false);
|
||||
assertThat(server().execute(update)).isEqualTo(1);
|
||||
@@ -199,6 +198,7 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
for (String table : tables) {
|
||||
// simple and stupid try to execute all commands on all dialects.
|
||||
sb.append("alter table ").append(table).append(" set ( system_versioning = OFF );\n");
|
||||
sb.append("alter table ").append(table).append(" drop system versioning;\n");
|
||||
sb.append("drop table ").append(table).append(";\n");
|
||||
sb.append("drop table ").append(table).append(" cascade;\n");
|
||||
sb.append("drop table ").append(table).append("_history;\n");
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.ebean.Ebean;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.hana.HanaPlatform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
@@ -16,7 +17,6 @@ import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
private ServerConfig serverConfig = new ServerConfig();
|
||||
@@ -37,6 +37,10 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
return handler(new SqlServer17Platform());
|
||||
}
|
||||
|
||||
private DdlHandler hanaHandler() {
|
||||
return handler(new HanaPlatform());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addColumn_nullable_noConstraint() throws Exception {
|
||||
|
||||
@@ -47,6 +51,10 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAddColumn());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add added_to_foo nvarchar(20);\n\n");
|
||||
|
||||
write = new DdlWrite();
|
||||
hanaHandler().generate(write, Helper.getAddColumn());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add ( added_to_foo nvarchar(20));\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,10 +64,16 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
h2Handler().generate(write, Helper.getAlterTableAddColumnWithCheckConstraint());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column status integer;\n"
|
||||
+ "alter table foo add constraint ck_ordering_status check ( status in (0,1));\n\n");
|
||||
|
||||
write = new DdlWrite();
|
||||
hanaHandler().generate(write, Helper.getAlterTableAddColumnWithCheckConstraint());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add ( status integer);\n"
|
||||
+ "alter table foo add constraint ck_ordering_status check ( status in (0,1));\n\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the functionality of the Ebean {@literal @}DbArray extension during DDL generation.
|
||||
* Test the functionality of the Ebean {@literal @}DbArray extension during DDL
|
||||
* generation.
|
||||
*/
|
||||
@Test
|
||||
public void addColumn_dbarray() throws Exception {
|
||||
@@ -76,6 +90,12 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
DdlHandler sqlserverHandler = sqlserverHandler();
|
||||
sqlserverHandler.generate(write, Helper.getAlterTableAddDbArrayColumn());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add dbarray_added_to_foo varchar(1000);\n\n");
|
||||
|
||||
write = new DdlWrite();
|
||||
|
||||
DdlHandler hanaHandler = hanaHandler();
|
||||
hanaHandler.generate(write, Helper.getAlterTableAddDbArrayColumn());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add ( dbarray_added_to_foo nvarchar(255) array);\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,6 +113,10 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAlterTableAddDbArrayColumnWithLength());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add dbarray_ninety varchar(90);\n\n");
|
||||
|
||||
write = new DdlWrite();
|
||||
hanaHandler().generate(write, Helper.getAlterTableAddDbArrayColumnWithLength());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add ( dbarray_ninety nvarchar(255) array(90));\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,6 +137,14 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAlterTableAddDbArrayColumnInteger());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add dbarray_integer varchar(1000);\n\n");
|
||||
|
||||
write = new DdlWrite();
|
||||
hanaHandler().generate(write, Helper.getAlterTableAddDbArrayColumnIntegerWithLength());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add ( dbarray_integer integer array(90));\n\n");
|
||||
|
||||
write = new DdlWrite();
|
||||
hanaHandler().generate(write, Helper.getAlterTableAddDbArrayColumnInteger());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add ( dbarray_integer integer array);\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,7 +159,8 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
assertThat(buffer).contains("alter table foo add column some_id integer;");
|
||||
|
||||
String fkBuffer = write.applyForeignKeys().getBuffer();
|
||||
assertThat(fkBuffer).contains("alter table foo add constraint fk_foo_some_id foreign key (some_id) references bar (id) on delete restrict on update restrict;");
|
||||
assertThat(fkBuffer).contains(
|
||||
"alter table foo add constraint fk_foo_some_id foreign key (some_id) references bar (id) on delete restrict on update restrict;");
|
||||
assertThat(fkBuffer).contains("create index idx_foo_some_id on foo (some_id);");
|
||||
assertThat(write.dropAll().getBuffer()).isEqualTo("");
|
||||
}
|
||||
@@ -142,8 +175,15 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo drop column col2;\n\n");
|
||||
assertThat(write.dropAll().getBuffer()).isEqualTo("");
|
||||
}
|
||||
|
||||
write = new DdlWrite();
|
||||
DdlHandler hanaHandler = hanaHandler();
|
||||
|
||||
hanaHandler.generate(write, Helper.getDropColumn());
|
||||
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("CALL usp_ebean_drop_column('foo', 'col2');\n\n");
|
||||
assertThat(write.dropAll().getBuffer()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTable() throws Exception {
|
||||
@@ -157,6 +197,16 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
assertThat(write.apply().getBuffer()).isEqualTo(createTableDDL);
|
||||
assertThat(write.dropAll().getBuffer().trim()).isEqualTo("drop table if exists foo;");
|
||||
|
||||
write = new DdlWrite();
|
||||
DdlHandler hanaHandler = hanaHandler();
|
||||
|
||||
hanaHandler.generate(write, Helper.getCreateTable());
|
||||
|
||||
String createColumnTableDDL = Helper.asText(this, "/assert/create-column-table.txt");
|
||||
|
||||
assertThat(write.apply().getBuffer()).isEqualTo(createColumnTableDDL);
|
||||
assertThat(write.dropAll().getBuffer().trim()).isEqualTo("drop table foo cascade;");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,7 +224,6 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
assertThat(write.dropAll().getBuffer()).isEqualTo(rollbackLast);
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void generateChangeSetFromModel() throws Exception {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.ebean.config.dbplatform.hana.HanaPlatform;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
|
||||
import io.ebeaninternal.dbmigration.migration.Column;
|
||||
|
||||
public class HanaDdlTest {
|
||||
|
||||
@Test
|
||||
public void alterTableDropColumn() throws IOException {
|
||||
HanaColumnStoreDdl ddl = new HanaColumnStoreDdl(new HanaPlatform());
|
||||
DdlWrite write = new DdlWrite();
|
||||
ddl.alterTableDropColumn(write.apply(), "my_table", "my_column");
|
||||
assertEquals("CALL usp_ebean_drop_column('my_table', 'my_column');\n", write.apply().getBuffer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alterTableAddColumn() throws IOException {
|
||||
HanaColumnStoreDdl ddl = new HanaColumnStoreDdl(new HanaPlatform());
|
||||
DdlWrite write = new DdlWrite();
|
||||
Column column = new Column();
|
||||
column.setName("my_column");
|
||||
column.setComment("comment");
|
||||
column.setDefaultValue("1");
|
||||
column.setNotnull(Boolean.TRUE);
|
||||
column.setType("int");
|
||||
column.setUnique("unique");
|
||||
column.setPrimaryKey(Boolean.TRUE);
|
||||
column.setCheckConstraint("CHECK(my_column > 0)");
|
||||
column.setCheckConstraintName("check_constraint");
|
||||
column.setHistoryExclude(Boolean.TRUE);
|
||||
column.setIdentity(Boolean.TRUE);
|
||||
ddl.alterTableAddColumn(write.apply(), "my_table", column, false, "1");
|
||||
assertEquals("alter table my_table add ( my_column int default 1 not null);\nalter table my_table add constraint check_constraint CHECK(my_column > 0);\n", write.apply().getBuffer());
|
||||
}
|
||||
}
|
||||
+61
@@ -4,6 +4,7 @@ import io.ebean.Ebean;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.hana.HanaPlatform;
|
||||
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
|
||||
import io.ebean.config.dbplatform.oracle.OraclePlatform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
@@ -16,6 +17,8 @@ import org.junit.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
@@ -24,6 +27,7 @@ public class PlatformDdl_AlterColumnTest {
|
||||
private PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
|
||||
private PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
|
||||
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServer17Platform());
|
||||
private PlatformDdl hanaDdl = PlatformDdlBuilder.create(new HanaPlatform());
|
||||
|
||||
{
|
||||
ServerConfig serverConfig = Ebean.getDefaultServer().getPluginApi().getServerConfig();
|
||||
@@ -63,6 +67,14 @@ public class PlatformDdl_AlterColumnTest {
|
||||
assertThat(pgDdl.convertArrayType("varchar[]")).isEqualTo("varchar[]");
|
||||
assertThat(pgDdl.convertArrayType("integer[]")).isEqualTo("integer[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertArrayType_hana() {
|
||||
assertThat(hanaDdl.convertArrayType("varchar[](90)")).isEqualTo("nvarchar(255) array(90)");
|
||||
assertThat(hanaDdl.convertArrayType("integer[](60)")).isEqualTo("integer array(60)");
|
||||
assertThat(hanaDdl.convertArrayType("varchar[]")).isEqualTo("nvarchar(255) array");
|
||||
assertThat(hanaDdl.convertArrayType("integer[]")).isEqualTo("integer array");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlterColumnBaseAttributes() throws Exception {
|
||||
@@ -77,20 +89,32 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = sqlServerDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab alter column acol nvarchar(5) not null", sql);
|
||||
|
||||
sql = hanaDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab alter ( acol nvarchar(5) not null)", sql);
|
||||
|
||||
alterColumn.setNotnull(Boolean.FALSE);
|
||||
sql = mysqlDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab modify acol varchar(5)", sql);
|
||||
|
||||
sql = hanaDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab alter ( acol nvarchar(5))", sql);
|
||||
|
||||
alterColumn.setNotnull(null);
|
||||
alterColumn.setType("varchar(100)");
|
||||
|
||||
sql = mysqlDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab modify acol varchar(100)", sql);
|
||||
|
||||
sql = hanaDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab alter ( acol nvarchar(100))", sql);
|
||||
|
||||
alterColumn.setCurrentNotnull(Boolean.TRUE);
|
||||
sql = mysqlDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab modify acol varchar(100) not null", sql);
|
||||
|
||||
sql = hanaDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab alter ( acol nvarchar(100) not null)", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,6 +134,9 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = sqlServerDdl.alterColumnType("mytab", "acol", "varchar(20)");
|
||||
assertNull(sql);
|
||||
|
||||
sql = hanaDdl.alterColumnType("mytab", "acol", "varchar(20)");
|
||||
assertNull(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,6 +156,9 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = sqlServerDdl.alterColumnNotnull("mytab", "acol", true);
|
||||
assertNull(sql);
|
||||
|
||||
sql = hanaDdl.alterColumnNotnull("mytab", "acol", true);
|
||||
assertNull(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,6 +178,9 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = sqlServerDdl.alterColumnNotnull("mytab", "acol", false);
|
||||
assertNull(sql);
|
||||
|
||||
sql = hanaDdl.alterColumnNotnull("mytab", "acol", false);
|
||||
assertNull(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,6 +200,15 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = sqlServerDdl.alterColumnDefaultValue("mytab", "acol", "'hi'");
|
||||
assertEquals("alter table mytab add default 'hi' for acol", sql);
|
||||
|
||||
boolean exceptionCaught = false;
|
||||
try {
|
||||
hanaDdl.alterColumnDefaultValue("mytab", "acol", "'hi'");
|
||||
}
|
||||
catch (UnsupportedOperationException e) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
assertTrue(exceptionCaught);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,6 +228,15 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = sqlServerDdl.alterColumnDefaultValue("mytab", "acol", "DROP DEFAULT");
|
||||
assertEquals("EXEC usp_ebean_drop_default_constraint mytab, acol", sql);
|
||||
|
||||
boolean exceptionCaught = false;
|
||||
try {
|
||||
hanaDdl.alterColumnDefaultValue("mytab", "acol", "DROP DEFAULT");
|
||||
}
|
||||
catch (UnsupportedOperationException e) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
assertTrue(exceptionCaught);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,4 +277,14 @@ public class PlatformDdl_AlterColumnTest {
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.GENERATOR), IdType.GENERATOR);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.EXTERNAL), IdType.EXTERNAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useIdentityType_hana() {
|
||||
|
||||
assertEquals(hanaDdl.useIdentityType(null), IdType.IDENTITY);
|
||||
assertEquals(hanaDdl.useIdentityType(IdentityType.SEQUENCE), IdType.IDENTITY);
|
||||
assertEquals(hanaDdl.useIdentityType(IdentityType.IDENTITY), IdType.IDENTITY);
|
||||
assertEquals(hanaDdl.useIdentityType(IdentityType.GENERATOR), IdType.GENERATOR);
|
||||
assertEquals(hanaDdl.useIdentityType(IdentityType.EXTERNAL), IdType.EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-3
@@ -1,6 +1,8 @@
|
||||
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.hana.HanaPlatform;
|
||||
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
|
||||
import io.ebean.config.dbplatform.oracle.OraclePlatform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
@@ -12,12 +14,12 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PlatformDdl_dropUniqueConstraintTest {
|
||||
|
||||
|
||||
private PlatformDdl h2Ddl = PlatformDdlBuilder.create(new H2Platform());
|
||||
private PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
|
||||
private PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
|
||||
private PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
|
||||
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServer17Platform());
|
||||
private PlatformDdl hanaDdl = PlatformDdlBuilder.create(new HanaPlatform());
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
@@ -30,11 +32,22 @@ public class PlatformDdl_dropUniqueConstraintTest {
|
||||
assertEquals("alter table mytab drop constraint uq_name", sql);
|
||||
sql = sqlServerDdl.alterTableDropUniqueConstraint("mytab", "uq_name");
|
||||
assertEquals("IF (OBJECT_ID('uq_name', 'UQ') IS NOT NULL) alter table mytab drop constraint uq_name;\n"
|
||||
+ "IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('mytab','U') AND name = 'uq_name') drop index uq_name ON mytab", sql);
|
||||
|
||||
+ "IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('mytab','U') AND name = 'uq_name') drop index uq_name ON mytab",
|
||||
sql);
|
||||
|
||||
sql = mysqlDdl.alterTableDropUniqueConstraint("mytab", "uq_name");
|
||||
assertEquals("alter table mytab drop index uq_name", sql);
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
hanaDdl.configure(serverConfig);
|
||||
sql = hanaDdl.alterTableDropUniqueConstraint("mytab", "uq_name");
|
||||
assertEquals("delimiter $$\n" +
|
||||
"do\n" +
|
||||
"begin\n" +
|
||||
"declare exit handler for sql_error_code 397 begin end;\n" +
|
||||
"exec 'alter table mytab drop constraint uq_name';\n" +
|
||||
"end;\n" +
|
||||
"$$", sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.DefaultExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
public class HanaDbExpressionTest {
|
||||
private HanaDbExpression expression = new HanaDbExpression();
|
||||
|
||||
@Test
|
||||
public void testArrayContains() {
|
||||
SpiExpressionRequest request = new DefaultExpressionRequest(null);
|
||||
expression.arrayContains(request, "arrayproperty", true, "v1", "v2", "v3");
|
||||
assertEquals("(? member of arrayproperty) and (? member of arrayproperty) and (? member of arrayproperty)",
|
||||
request.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayNotContains() {
|
||||
SpiExpressionRequest request = new DefaultExpressionRequest(null);
|
||||
expression.arrayContains(request, "arrayproperty", false, "v1", "v2", "v3");
|
||||
assertEquals(
|
||||
"(? not member of arrayproperty) and (? not member of arrayproperty) and (? not member of arrayproperty)",
|
||||
request.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayContainsEmpty() {
|
||||
SpiExpressionRequest request = new DefaultExpressionRequest(null);
|
||||
expression.arrayContains(request, "arrayproperty", true);
|
||||
assertEquals("", request.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayIsEmpty() {
|
||||
SpiExpressionRequest request = new DefaultExpressionRequest(null);
|
||||
expression.arrayIsEmpty(request, "arrayproperty", true);
|
||||
assertEquals("cardinality(arrayproperty) = 0", request.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayIsNotEmpty() {
|
||||
SpiExpressionRequest request = new DefaultExpressionRequest(null);
|
||||
expression.arrayIsEmpty(request, "arrayproperty", false);
|
||||
assertEquals("cardinality(arrayproperty) <> 0", request.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcat() {
|
||||
String concat = expression.concat("property0", "separator", "property1", "suffix");
|
||||
assertEquals("concat(property0, 'separator'||property1||'suffix')", concat);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcatNullSuffix() {
|
||||
String concat = expression.concat("property0", "separator", "property1", null);
|
||||
assertEquals("concat(property0, 'separator'||property1)", concat);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJson() {
|
||||
SpiExpressionRequest request = new DefaultExpressionRequest(null);
|
||||
expression.json(request, "jsonproperty", "path", Op.EQ, "val");
|
||||
assertEquals("json_value(jsonproperty, '$.path') = ? ", request.getSql());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package io.ebeaninternal.server.grammer;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
@@ -11,6 +14,8 @@ import org.tests.model.basic.ResetBasicData;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.ws.RequestWrapper;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EqlParserTest extends BaseTestCase {
|
||||
@@ -127,6 +132,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnorePlatform(Platform.HANA) // The HANA JDBC driver checks the field length on binding and rejects 'NEW'
|
||||
public void where_or1() {
|
||||
|
||||
Query<Customer> query = parse("where name = 'Rob' or (status = 'NEW' and smallnote is null)");
|
||||
@@ -134,8 +140,19 @@ public class EqlParserTest extends BaseTestCase {
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null ) )");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.HANA)
|
||||
public void where_or1_hana() {
|
||||
|
||||
Query<Customer> query = parse("where name = 'Rob' or (status = 'N' and smallnote is null)");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null ) )");
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnorePlatform(Platform.HANA) // The HANA JDBC driver checks the field length on binding and rejects 'NEW'
|
||||
public void where_or2() {
|
||||
|
||||
Query<Customer> query = parse("where (name = 'Rob' or status = 'NEW') and smallnote is null");
|
||||
@@ -143,8 +160,19 @@ public class EqlParserTest extends BaseTestCase {
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where ((t0.name = ? or t0.status = ? ) and t0.smallnote is null )");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.HANA)
|
||||
public void where_or2_hana() {
|
||||
|
||||
Query<Customer> query = parse("where (name = 'Rob' or status = 'N') and smallnote is null");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where ((t0.name = ? or t0.status = ? ) and t0.smallnote is null )");
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnorePlatform(Platform.HANA) // The HANA JDBC driver checks the field length on binding and rejects 'NEW'
|
||||
public void test_simplifyExpressions() {
|
||||
|
||||
Query<Customer> query = parse("where not (name = 'Rob' and status = 'NEW')");
|
||||
@@ -159,6 +187,23 @@ public class EqlParserTest extends BaseTestCase {
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.HANA)
|
||||
public void test_simplifyExpressions_hana() {
|
||||
|
||||
Query<Customer> query = parse("where not (name = 'Rob' and status = 'N')");
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
|
||||
|
||||
query = parse("where not ((name = 'Rob' and status = 'N'))");
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
|
||||
|
||||
query = parse("where not (((name = 'Rob') and (status = 'N')))");
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user