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
@@ -1,5 +1,6 @@
|
||||
package io.ebean;
|
||||
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
@@ -10,6 +11,9 @@ import io.ebeaninternal.api.SpiQuery;
|
||||
import io.ebeaninternal.server.core.HelpCreateQueryRequest;
|
||||
import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.expression.platform.DbExpressionHandler;
|
||||
import io.ebeaninternal.server.expression.platform.DbExpressionHandlerFactory;
|
||||
|
||||
import org.avaje.agentloader.AgentLoader;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
@@ -144,6 +148,10 @@ public abstract class BaseTestCase {
|
||||
public boolean isMySql() {
|
||||
return Platform.MYSQL == platform();
|
||||
}
|
||||
|
||||
public boolean isHana() {
|
||||
return Platform.HANA == platform();
|
||||
}
|
||||
|
||||
public boolean isPlatformBooleanNative() {
|
||||
return Types.BOOLEAN == spiEbeanServer().getDatabasePlatform().getBooleanDbType();
|
||||
@@ -152,6 +160,10 @@ public abstract class BaseTestCase {
|
||||
public boolean isPlatformOrderNullsSupport() {
|
||||
return isH2() || isPostgres();
|
||||
}
|
||||
|
||||
public boolean isPersistBatchOnCascade() {
|
||||
return spiEbeanServer().getDatabasePlatform().getPersistBatchOnCascade() != PersistBatch.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the L2 cache to propagate changes post-commit.
|
||||
@@ -205,6 +217,18 @@ public abstract class BaseTestCase {
|
||||
assertThat(sql).contains(containsIn+" not in ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform specific CONCAT clause.
|
||||
*/
|
||||
protected String concat(String property0, String separator, String property1) {
|
||||
return concat(property0, separator, property1, null);
|
||||
}
|
||||
|
||||
protected String concat(String property0, String separator, String property1, String suffix) {
|
||||
DbExpressionHandler dbExpressionHandler = DbExpressionHandlerFactory.from(spiEbeanServer().getDatabasePlatform());
|
||||
return dbExpressionHandler.concat(property0, separator, property1, suffix);
|
||||
}
|
||||
|
||||
protected <T> OrmQueryRequest<T> createQueryRequest(SpiQuery.Type type, Query<T> query, Transaction t) {
|
||||
return HelpCreateQueryRequest.create(server(), type, query, t);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.ebean;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaQueryMetric;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -43,17 +44,13 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
resetAllMetrics();
|
||||
|
||||
String[] prefix = {"Bl", "B", "Red", "jim"};
|
||||
String[] prefix = { "Bl", "B", "Red", "jim" };
|
||||
|
||||
for (String val : prefix) {
|
||||
List<ContactDto> list = Ebean.find(Contact.class)
|
||||
.select("email, concat(lastName,', ',firstName) as fullName")
|
||||
.where().istartsWith("concat(lastName,', ',firstName)", val)
|
||||
.orderBy().asc("lastName")
|
||||
.setMaxRows(10)
|
||||
.asDto(ContactDto.class)
|
||||
.setLabel("prefixLoop")
|
||||
.findList();
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where()
|
||||
.istartsWith(concat("lastName", ", ", "firstName"), val).orderBy().asc("lastName").setMaxRows(10)
|
||||
.asDto(ContactDto.class).setLabel("prefixLoop").findList();
|
||||
|
||||
System.out.println("List:" + list);
|
||||
}
|
||||
@@ -77,14 +74,10 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DtoQuery<ContactDto> query =
|
||||
Ebean.find(Contact.class)
|
||||
DtoQuery<ContactDto> query = Ebean.find(Contact.class)
|
||||
// we must explicitly add the id property for DTO query (if we want it)
|
||||
.select("id, email, concat(lastName,', ',firstName) as fullName")
|
||||
.where().isNotNull("email").isNotNull("lastName")
|
||||
.orderBy().asc("lastName")
|
||||
.asDto(ContactDto.class)
|
||||
.setLabel("explicitId")
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class).setLabel("explicitId")
|
||||
.setRelaxedMode();
|
||||
|
||||
List<ContactDto> dtos = query.findList();
|
||||
@@ -98,7 +91,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,12 +102,9 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DtoQuery<ContactDto> query =
|
||||
Ebean.find(Contact.class)
|
||||
.select("email, concat(lastName,', ',firstName) as fullName")
|
||||
.where().isNotNull("email").isNotNull("lastName")
|
||||
.orderBy().asc("lastName")
|
||||
.asDto(ContactDto.class);
|
||||
DtoQuery<ContactDto> query = Ebean.find(Contact.class)
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class);
|
||||
|
||||
List<ContactDto> dtos = query.findList();
|
||||
|
||||
@@ -126,10 +117,10 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void example() {
|
||||
|
||||
@@ -137,15 +128,9 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos
|
||||
= Ebean.find(Contact.class)
|
||||
.setLabel("emailFullName")
|
||||
.select("email, concat(lastName,', ',firstName) as fullName")
|
||||
.where().isNotNull("email").isNotNull("lastName")
|
||||
.orderBy().asc("lastName")
|
||||
.setMaxRows(10)
|
||||
.asDto(ContactDto.class)
|
||||
.findList();
|
||||
List<ContactDto> contactDtos = Ebean.find(Contact.class).setLabel("emailFullName")
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -158,10 +143,12 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql.get(0)).contains("select top 10 t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
assertThat(sql.get(0)).contains("select top 10 t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("select t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,14 +159,9 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos
|
||||
= Ebean.find(Contact.class)
|
||||
.select("id, email, concat(lastName,', ',firstName) as fullName")
|
||||
.where().isNotNull("email").isNotNull("lastName")
|
||||
.orderBy().asc("lastName")
|
||||
.setMaxRows(10)
|
||||
.asDto(ContactDto.class)
|
||||
.findList();
|
||||
List<ContactDto> contactDtos = Ebean.find(Contact.class)
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -192,9 +174,12 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql.get(0)).contains("select top 10 t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
assertThat(sql.get(0)).contains("select top 10 t0.id, t0.email, "
|
||||
+ concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,15 +190,9 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos
|
||||
= Ebean.find(Contact.class)
|
||||
.select("concat(lastName,', ',firstName) as fullName")
|
||||
.where().isNotNull("lastName")
|
||||
.orderBy().asc("lastName")
|
||||
.asDto(ContactDto.class)
|
||||
.setFirstRow(2)
|
||||
.setMaxRows(5)
|
||||
.findList();
|
||||
List<ContactDto> contactDtos = Ebean.find(Contact.class)
|
||||
.select(concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("lastName").orderBy()
|
||||
.asc("lastName").asDto(ContactDto.class).setFirstRow(2).setMaxRows(5).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -225,10 +204,10 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where");
|
||||
assertThat(sql.get(0))
|
||||
.contains("select " + concat("t0.last_name", ", ", "t0.first_name") + " fullName from contact t0 where");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void example_aggregate() {
|
||||
|
||||
@@ -236,14 +215,9 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactTotals> contactDtos
|
||||
= Ebean.find(Contact.class)
|
||||
.select("lastName, count(*) as totalCount")
|
||||
.where().isNotNull("lastName")
|
||||
.having().gt("count(*)", 1)
|
||||
.orderBy().desc("count(*)")
|
||||
.asDto(ContactTotals.class)
|
||||
.findList();
|
||||
List<ContactTotals> contactDtos = Ebean.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
.isNotNull("lastName").having().gt("count(*)", 1).orderBy().desc("count(*)").asDto(ContactTotals.class)
|
||||
.findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -253,7 +227,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
|
||||
assertThat(sql.get(0)).contains(
|
||||
"select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -261,12 +236,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<ContactTotals> contactDtos
|
||||
= Ebean.find(Contact.class)
|
||||
.select("lastName, count(*) as totalCount")
|
||||
.where().isNotNull("lastName")
|
||||
.asDto(ContactTotals.class)
|
||||
.findList();
|
||||
List<ContactTotals> contactDtos = Ebean.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
.isNotNull("lastName").asDto(ContactTotals.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public class SqlRowBooleanTest extends BaseTestCase {
|
||||
sqlQuery = Ebean.createSqlQuery("SELECT 1 AS ISNT_NULL from dual");
|
||||
} else if (isDb2()) {
|
||||
sqlQuery = Ebean.createSqlQuery("SELECT 1 AS ISNT_NULL from SYSIBM.SYSDUMMY1");
|
||||
} else if (isHana()) {
|
||||
sqlQuery = Ebean.createSqlQuery("SELECT 1 AS ISNT_NULL from sys.dummy");
|
||||
} else {
|
||||
sqlQuery = Ebean.createSqlQuery("SELECT 1 IS NOT NULL AS ISNT_NULL");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.ebean.config.dbplatform;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.ebean.config.dbplatform.hana.HanaHistorySupport;
|
||||
|
||||
public class HanaHistorySupportTest {
|
||||
|
||||
private HanaHistorySupport support = new HanaHistorySupport();
|
||||
|
||||
@Test
|
||||
public void getAsOfPredicate() {
|
||||
|
||||
String asOfPredicate = support.getAsOfPredicate("t0", "sys_period");
|
||||
assertNull(asOfPredicate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAsOfViewSuffix() {
|
||||
|
||||
String asOfViewSuffix = support.getAsOfViewSuffix("_with_history");
|
||||
assertEquals(asOfViewSuffix, " for system_time as of ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVersionsBetweenSuffix() {
|
||||
|
||||
String asOfViewSuffix = support.getVersionsBetweenSuffix("_with_history");
|
||||
assertEquals(asOfViewSuffix, " for system_time between ? and ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLower() throws Exception {
|
||||
|
||||
String lower = support.getSysPeriodLower("t0", "sys_period");
|
||||
assertEquals(lower, "t0.sys_period_start");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUpper() throws Exception {
|
||||
|
||||
String upper = support.getSysPeriodUpper("t0", "sys_period");
|
||||
assertEquals(upper, "t0.sys_period_end");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package io.ebean.config.dbplatform;
|
||||
|
||||
import io.ebean.config.PlatformConfig;
|
||||
import io.ebean.config.dbplatform.hana.HanaPlatform;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.platform.PlatformDdl;
|
||||
import io.ebeaninternal.server.core.PlatformDdlBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class HanaPlatformTest {
|
||||
|
||||
HanaPlatform platform = new HanaPlatform();
|
||||
|
||||
@Test
|
||||
public void testTypeConversion() {
|
||||
|
||||
PlatformDdl ddl = PlatformDdlBuilder.create(platform);
|
||||
|
||||
assertThat(ddl.convert("clob", false)).isEqualTo("nclob");
|
||||
assertThat(ddl.convert("blob", false)).isEqualTo("blob");
|
||||
assertThat(ddl.convert("json", false)).isEqualTo("nclob");
|
||||
assertThat(ddl.convert("jsonb", false)).isEqualTo("nclob");
|
||||
assertThat(ddl.convert("jsonvarchar", false)).isEqualTo("nvarchar(255)");
|
||||
|
||||
assertThat(ddl.convert("double", false)).isEqualTo("double");
|
||||
assertThat(ddl.convert("varchar(20)", false)).isEqualTo("nvarchar(20)");
|
||||
assertThat(ddl.convert("decimal(10)", false)).isEqualTo("decimal(10)");
|
||||
assertThat(ddl.convert("decimal(8,4)", false)).isEqualTo("decimal(8,4)");
|
||||
assertThat(ddl.convert("boolean", false)).isEqualTo("boolean");
|
||||
assertThat(ddl.convert("bit", false)).isEqualTo("smallint");
|
||||
assertThat(ddl.convert("tinyint", false)).isEqualTo("smallint");
|
||||
assertThat(ddl.convert("binary", false)).isEqualTo("varbinary(255)");
|
||||
assertThat(ddl.convert("binary(16)", false)).isEqualTo("varbinary(16)");
|
||||
|
||||
assertThat(ddl.convert("point", false)).isEqualTo("st_point");
|
||||
|
||||
assertThat(ddl.convert("multilinestring", false)).isEqualTo("st_geometry");
|
||||
assertThat(ddl.convert("multipolygon", false)).isEqualTo("st_geometry");
|
||||
assertThat(ddl.convert("multipoint", false)).isEqualTo("st_geometry");
|
||||
assertThat(ddl.convert("linestring", false)).isEqualTo("st_geometry");
|
||||
assertThat(ddl.convert("polygon", false)).isEqualTo("st_geometry");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uuid_default() {
|
||||
|
||||
HanaPlatform platform = new HanaPlatform();
|
||||
platform.configure(new PlatformConfig());
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
|
||||
assertThat(dbType.renderType(0, 0)).isEqualTo("varchar(40)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uuid_as_binary() {
|
||||
|
||||
HanaPlatform platform = new HanaPlatform();
|
||||
PlatformConfig config = new PlatformConfig();
|
||||
config.setDbUuid(PlatformConfig.DbUuid.AUTO_BINARY);
|
||||
|
||||
platform.configure(config);
|
||||
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
assertThat(dbType.renderType(0, 0)).isEqualTo("varbinary(16)");
|
||||
}
|
||||
}
|
||||
@@ -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