Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	ebean-core/src/main/java/io/ebeaninternal/server/deploy/TablespaceMeta.java
#	ebean-core/src/main/java/io/ebeaninternal/server/type/RsetDataReader.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
#	ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java
#	ebean-test/src/test/java/misc/migration/v1_0/EBasic.java
#	ebean-test/src/test/java/misc/migration/v1_1/MtmChild.java
#	ebean-test/src/test/java/misc/migration/v1_1/MtmMaster.java
#	ebean-test/src/test/java/org/tests/json/TestDbJson_List.java
#	ebean-test/src/test/resources/extra-ddl.xml
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/I__create_tablespaces.sql
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml
#	ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml
This commit is contained in:
Roland Praml
2022-03-24 09:20:28 +01:00
943 changed files with 2654 additions and 1723 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
name: JDK EA
name: ebean EA
on:
workflow_dispatch:
+14 -6
View File
@@ -3,7 +3,6 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/ebean-orm/ebean/blob/master/LICENSE)
[![Multi-JDK Build](https://github.com/ebean-orm/ebean/actions/workflows/multi-jdk-build.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/multi-jdk-build.yml)
[![JDK 18-ea](https://github.com/ebean-orm/ebean/actions/workflows/jdk-18-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/jdk-18-ea.yml)
[![JDK EA](https://github.com/ebean-orm/ebean/actions/workflows/jdk-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/jdk-ea.yml)
[![H2Database](https://github.com/ebean-orm/ebean/actions/workflows/h2database.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/h2database.yml)
[![Postgres](https://github.com/ebean-orm/ebean/actions/workflows/postgres.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/postgres.yml)
@@ -12,6 +11,15 @@
[![SqlServer](https://github.com/ebean-orm/ebean/actions/workflows/sqlserver.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/sqlserver.yml)
[![Yugabyte](https://github.com/ebean-orm/ebean/actions/workflows/yugabyte.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/yugabyte.yml)
#### Builds against EA (Early Access) versions of Java (19, Loom, panama etc)
[![ebean EA](https://github.com/ebean-orm/ebean/actions/workflows/jdk-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/jdk-ea.yml)
[![datasource EA](https://github.com/ebean-orm/ebean-datasource/actions/workflows/jdk-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean-datasource/actions/workflows/jdk-ea.yml)
[![migration EA](https://github.com/ebean-orm/ebean-migration/actions/workflows/jdk-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean-migration/actions/workflows/jdk-ea.yml)
[![test-docker EA](https://github.com/ebean-orm/ebean-test-docker/actions/workflows/jdk-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean-test-docker/actions/workflows/jdk-ea.yml)
# Sponsors
<table>
<tbody>
@@ -40,15 +48,15 @@
</tbody>
</table>
# Need help?
## Need help?
Post questions or issues to the Ebean google group - https://groups.google.com/forum/#!forum/ebean
# Documentation
## Documentation
Goto [https://ebean.io/docs/](https://ebean.io/docs/)
## Maven central links:
[Maven central - ebean](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22io.ebean%22%20AND%20a%3A%22ebean%22 "maven central ebean")
## Maven central
[Maven central - io.ebean](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22io.ebean%22%20)
[Maven central - all related projects](http://search.maven.org/#search%7Cga%7C1%7Cebean "maven central all related projects")
@@ -300,7 +300,7 @@ public interface Database {
* Create a new instance of T that is an EntityBean.
* <p>
* Useful if you use BeanPostConstructListeners or &#64;PostConstruct Annotations.
* In this case you should not use "new Bean...()". Making all bean construtors protected
* In this case you should not use "new Bean...()". Making all bean constructors protected
* could be a good idea here.
* </p>
*/
+2 -1
View File
@@ -10,13 +10,13 @@ module io.ebean.api {
requires transitive java.sql;
requires transitive io.avaje.config;
requires transitive io.avaje.lang;
requires transitive persistence.api;
requires transitive io.ebean.annotation;
requires transitive io.ebean.datasource.api;
requires transitive org.slf4j;
requires static io.ebean.types;
requires static io.avaje.jsr305x;
requires static com.fasterxml.jackson.core;
requires static javax.servlet.api;
requires static com.h2database;
@@ -41,6 +41,7 @@ module io.ebean.api {
exports io.ebean.config.dbplatform.sqlanywhere;
exports io.ebean.config.dbplatform.sqlite;
exports io.ebean.config.dbplatform.sqlserver;
exports io.ebean.config.dbplatform.yugabyte;
exports io.ebean.event;
exports io.ebean.event.readaudit;
exports io.ebean.event.changelog;
@@ -1,25 +1,12 @@
package io.ebean.text;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.FetchPath;
import io.ebean.Query;
import io.ebean.test.LoggedSql;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
public class PathPropertiesTests extends BaseTestCase {
private static final Logger log = LoggerFactory.getLogger(PathPropertiesTests.class);
public class PathPropertiesTests {
@Test
public void test_noParentheses() {
@@ -197,34 +184,4 @@ public class PathPropertiesTests extends BaseTestCase {
assertFalse(root.includesPath("customer", "shippingAddress"));
}
@Test
public void example_withQueryAndJson() {
ResetBasicData.reset();
PathProperties pathProps = PathProperties.parse("id,name,billingAddress(city),shippingAddress(*))");
Query<Customer> query = DB.find(Customer.class)
.where().lt("id", 2)
.query();
pathProps.apply(query);
List<Customer> list = query.findList();
String asJson = DB.json().toJson(list, pathProps);
log.info("Json: {}", asJson);
}
@Test
public void test_withAllPropsQuery() {
PathProperties root = PathProperties.parse("*,billingAddress(line1)");
LoggedSql.start();
Query<Customer> query = DB.find(Customer.class).apply(root);
query.findList();
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.id, t0.status, t0.name, t0.smallnote, t0.anniversary, t0.cretime, t0.updtime, t0.version, t0.shipping_address_id, t1.id, t1.line_1 from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id;");
}
}
@@ -3,8 +3,7 @@ package io.ebeaninternal.server.deploy;
import java.util.Objects;
/**
* Meta data for table spaces.
* If table space is configured, tablespaceName, indexTablespace, lobTablespace is never null;
* Meta data for table spaces. If table space is configured, tablespaceName, indexTablespace, lobTablespace is never null;
*
* @author Noemi Szemenyei, FOCONIS AG
*
@@ -15,7 +14,6 @@ public final class TablespaceMeta {
private final String indexTablespace;
private final String lobTablespace;
public TablespaceMeta(String tablespaceName, String indexTablespace, String lobTablespace) {
this.tablespaceName = tablespaceName;
this.indexTablespace = indexTablespace;
@@ -49,12 +47,10 @@ public final class TablespaceMeta {
return false;
TablespaceMeta other = (TablespaceMeta) obj;
return Objects.equals(indexTablespace, other.indexTablespace)
&& Objects.equals(tablespaceName, other.tablespaceName)
&& Objects.equals(lobTablespace, other.lobTablespace);
&& Objects.equals(tablespaceName, other.tablespaceName)
&& Objects.equals(lobTablespace, other.lobTablespace);
}
@Override
public String toString() {
return "tablespace=" + tablespaceName + ", indexTablespace=" + indexTablespace + ", lobTablespace=" + lobTablespace;
@@ -34,28 +34,28 @@ public class RsetDataReader implements DataReader {
}
@Override
public void pushJson(String json) {
public final void pushJson(String json) {
this.json = json;
}
@Override
public String popJson() {
public final String popJson() {
return json;
}
@Override
public void close() throws SQLException {
public final void close() throws SQLException {
rset.close();
}
@Override
public boolean next() throws SQLException {
public final boolean next() throws SQLException {
pos = 0;
return rset.next();
}
@Override
public void incrementPos(int increment) {
public final void incrementPos(int increment) {
pos += increment;
}
@@ -64,49 +64,49 @@ public class RsetDataReader implements DataReader {
}
@Override
public Array getArray() throws SQLException {
public final Array getArray() throws SQLException {
return rset.getArray(pos());
}
@Override
public Object getObject() throws SQLException {
public final Object getObject() throws SQLException {
return rset.getObject(pos());
}
@Override
public <T> T getObject(Class<T> cls) throws SQLException {
public final <T> T getObject(Class<T> cls) throws SQLException {
return rset.getObject(pos(), cls);
}
@Override
public BigDecimal getBigDecimal() throws SQLException {
public final BigDecimal getBigDecimal() throws SQLException {
return rset.getBigDecimal(pos());
}
@Override
public InputStream getBinaryStream() throws SQLException {
public final InputStream getBinaryStream() throws SQLException {
return rset.getBinaryStream(pos());
}
@Override
public Boolean getBoolean() throws SQLException {
public final Boolean getBoolean() throws SQLException {
boolean v = rset.getBoolean(pos());
return rset.wasNull() ? null : v;
}
@Override
public Byte getByte() throws SQLException {
public final Byte getByte() throws SQLException {
byte v = rset.getByte(pos());
return rset.wasNull() ? null : v;
}
@Override
public byte[] getBytes() throws SQLException {
public final byte[] getBytes() throws SQLException {
return rset.getBytes(pos());
}
@Override
public Date getDate() throws SQLException {
public final Date getDate() throws SQLException {
Calendar cal = dataTimeZone.getDateTimeZone();
if (cal != null) {
return rset.getDate(pos(), cal);
@@ -116,46 +116,46 @@ public class RsetDataReader implements DataReader {
}
@Override
public Double getDouble() throws SQLException {
public final Double getDouble() throws SQLException {
double v = rset.getDouble(pos());
return rset.wasNull() ? null : v;
}
@Override
public Float getFloat() throws SQLException {
public final Float getFloat() throws SQLException {
float v = rset.getFloat(pos());
return rset.wasNull() ? null : v;
}
@Override
public Integer getInt() throws SQLException {
public final Integer getInt() throws SQLException {
int v = rset.getInt(pos());
return rset.wasNull() ? null : v;
}
@Override
public Long getLong() throws SQLException {
public final Long getLong() throws SQLException {
long v = rset.getLong(pos());
return rset.wasNull() ? null : v;
}
public Ref getRef() throws SQLException {
public final Ref getRef() throws SQLException {
return rset.getRef(pos());
}
@Override
public Short getShort() throws SQLException {
public final Short getShort() throws SQLException {
short s = rset.getShort(pos());
return rset.wasNull() ? null : s;
}
@Override
public String getString() throws SQLException {
public final String getString() throws SQLException {
return rset.getString(pos());
}
@Override
public Time getTime() throws SQLException {
public final Time getTime() throws SQLException {
Calendar cal = dataTimeZone.getDateTimeZone();
if (cal != null) {
return rset.getTime(pos(), cal);
@@ -165,7 +165,7 @@ public class RsetDataReader implements DataReader {
}
@Override
public Timestamp getTimestamp() throws SQLException {
public final Timestamp getTimestamp() throws SQLException {
Calendar cal = dataTimeZone.getTimeZone();
if (cal != null) {
return rset.getTimestamp(pos(), cal);
@@ -175,12 +175,12 @@ public class RsetDataReader implements DataReader {
}
@Override
public String getStringFromStream() throws SQLException {
public final String getStringFromStream() throws SQLException {
Reader reader = rset.getCharacterStream(pos());
return reader == null ? null : readStringLob(reader);
}
protected String readStringLob(Reader reader) throws SQLException {
private String readStringLob(Reader reader) throws SQLException {
char[] buffer = new char[clobBufferSize];
int readLength;
StringBuilder out = new StringBuilder(stringInitialSize);
@@ -196,12 +196,12 @@ public class RsetDataReader implements DataReader {
}
@Override
public byte[] getBinaryBytes() throws SQLException {
public final byte[] getBinaryBytes() throws SQLException {
InputStream in = rset.getBinaryStream(pos());
return getBinaryLob(in);
}
protected byte[] getBinaryLob(InputStream in) throws SQLException {
private byte[] getBinaryLob(InputStream in) throws SQLException {
if (in == null) {
return null;
}
+6 -6
View File
@@ -38,13 +38,13 @@ module io.ebean.core {
requires static org.postgresql.jdbc;
requires static joda.time;
exports io.ebeaninternal.api;
exports io.ebeaninternal.server.cache;
// export these for io.ebean.ddl.generator (but that becomes unnamed module in maven test scope)
exports io.ebeaninternal.server.deploy;
exports io.ebeaninternal.server.deploy.visitor;
// exports io.ebeaninternal.server.deploy to io.ebean.autotune, io.ebean.ddl.generator;
// exports io.ebeaninternal.server.deploy.visitor to io.ebean.ddl.generator;
exports io.ebeaninternal.api to io.ebean.ddl.generator, io.ebean.querybean, io.ebean.autotune, io.ebean.postgis, io.ebean.test;
exports io.ebeaninternal.server.deploy to io.ebean.autotune, io.ebean.ddl.generator;
exports io.ebeaninternal.server.deploy.id to io.ebean.ddl.generator;
exports io.ebeaninternal.server.deploy.meta to io.ebean.ddl.generator;
exports io.ebeaninternal.server.deploy.visitor to io.ebean.ddl.generator;
exports io.ebeaninternal.server.el to io.ebean.autotune;
exports io.ebeaninternal.server.autotune to io.ebean.autotune;
@@ -1,8 +1,5 @@
package io.ebean.config.dbplatform;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.MatchingNamingConvention;
@@ -12,45 +9,9 @@ import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DatabasePlatformTest extends BaseTestCase {
@Test
@ForPlatform(Platform.H2)
public void h2_platform() {
final Platform platform = DB.getDefault().platform();
assertThat(platform).isSameAs(Platform.H2);
}
@Test
@ForPlatform(Platform.POSTGRES)
public void postgres_platform() {
final Platform platform = DB.getDefault().platform().base();
assertThat(platform).isSameAs(Platform.POSTGRES);
}
@Test
@ForPlatform(Platform.MYSQL)
public void mysql_platform() {
final Platform platform = DB.getDefault().platform().base();
assertThat(platform).isSameAs(Platform.MYSQL);
}
@Test
@ForPlatform(Platform.MARIADB)
public void mariadb_platform() {
final Platform platform = DB.getDefault().platform().base();
assertThat(platform).isSameAs(Platform.MARIADB);
}
@Test
@ForPlatform(Platform.SQLSERVER)
public void sqlserver_platform() {
final Platform platform = DB.getDefault().platform().base();
assertThat(platform).isSameAs(Platform.SQLSERVER);
}
class DatabasePlatformTest {
@Test
public void convertQuotedIdentifiers_when_allQuotedIdentifier_sqlServer() {
@@ -1,5 +1,6 @@
package io.ebean.config.dbplatform;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.sql.Types;
@@ -13,7 +14,7 @@ public class DbPlatformTypeLookupTest {
@Test
public void byName() throws Exception {
assertEquals(lookup.byName("DECIMAL"), DbType.DECIMAL);
Assertions.assertEquals(lookup.byName("DECIMAL"), DbType.DECIMAL);
assertEquals(lookup.byName("Decimal"), DbType.DECIMAL);
assertEquals(lookup.byName("decimal"), DbType.DECIMAL);
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.core;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -9,7 +10,7 @@ public class BasicTypeConverterTest {
@Test
public void toBoolean_when_1_long() throws Exception {
assertTrue(BasicTypeConverter.toBoolean(1L, "T"));
Assertions.assertTrue(BasicTypeConverter.toBoolean(1L, "T"));
}
@Test
@@ -1,6 +1,7 @@
package io.ebeaninternal.server.core;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -10,7 +11,7 @@ public class DtoQueryRequestTest {
@Test
public void testParse() {
assertEquals("foo", DtoQueryRequest.parseColumn("foo"));
Assertions.assertEquals("foo", DtoQueryRequest.parseColumn("foo"));
assertEquals("bar", DtoQueryRequest.parseColumn("zx__t0_bar"));
assertEquals("BAR", DtoQueryRequest.parseColumn("ZX__T0_BAR"));
assertEquals("baz", DtoQueryRequest.parseColumn("zx__t42_baz"));
@@ -4,16 +4,14 @@ import io.ebean.config.DatabaseConfig;
import io.ebean.datasource.DataSourceAlert;
import io.ebean.datasource.DataSourceConfig;
import io.ebean.datasource.pool.ConnectionPool;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.sql.SQLException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import java.sql.SQLException;
import javax.sql.DataSource;
public class InitDataSourceTest {
private DatabaseConfig newConfig(String readOnlyUrl) {
@@ -129,8 +127,8 @@ public class InitDataSourceTest {
assertNotNull(roConfig);
assertEquals("foo", roConfig.getUrl());
}
@Test
public void online() {
DatabaseConfig config = new DatabaseConfig();
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.deploy;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -10,7 +11,7 @@ public class DetermineAggPathTest {
@Test
public void path() throws Exception {
assertThat(DetermineAggPath.path("count(details)")).isEqualTo("details");
Assertions.assertThat(DetermineAggPath.path("count(details)")).isEqualTo("details");
assertThat(DetermineAggPath.path("count(details )")).isEqualTo("details");
assertThat(DetermineAggPath.path("count(person.contacts)")).isEqualTo("person.contacts");
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.deploy;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -14,7 +15,7 @@ public class IndexDefinitionTest {
@Test
public void isUniqueConstraint_TRUE_when_simpleMultiColumn() {
assertTrue(new IndexDefinition(simpleCol1).isUniqueConstraint());
Assertions.assertTrue(new IndexDefinition(simpleCol1).isUniqueConstraint());
assertTrue(new IndexDefinition(simpleCol2).isUniqueConstraint());
}
@@ -0,0 +1,34 @@
package io.ebeaninternal.server.deploy.generatedproperty;
import io.ebeaninternal.server.deploy.BeanProperty;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class GeneratedCounterLongTest {
private final GeneratedCounterLong counter = new GeneratedCounterLong();
@Test
void when_null_expect_IllegalStateException() {
BeanProperty beanProperty = mock(BeanProperty.class);
when(beanProperty.getValue(any())).thenReturn(null);
assertThrows(IllegalStateException.class, () -> counter.getUpdateValue(beanProperty, null, System.currentTimeMillis()));
}
@Test
void when_set_expect_incremented() {
BeanProperty beanProperty = mock(BeanProperty.class);
when(beanProperty.getValue(any())).thenReturn(7L);
Object value = counter.getUpdateValue(beanProperty, null, System.currentTimeMillis());
assertThat(value).isEqualTo(8L);
}
}
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.dto;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
@@ -34,7 +35,7 @@ public class DtoMetaBuilderTest {
Map<String, Method> methods = getIncludedMethodsFor(D0.class);
assertThat(methods).hasSize(2);
assertThat(DtoMetaProperty.propertyClass(methods.get("setName"))).isEqualTo(String.class);
Assertions.assertThat(DtoMetaProperty.propertyClass(methods.get("setName"))).isEqualTo(String.class);
assertThat(DtoMetaProperty.propertyClass(methods.get("setId"))).isEqualTo(long.class);
assertThat(DtoMetaProperty.propertyType(methods.get("setName"))).isEqualTo(String.class);
assertThat(DtoMetaProperty.propertyType(methods.get("setId"))).isEqualTo(long.class);
@@ -43,7 +44,7 @@ public class DtoMetaBuilderTest {
@Test
public void propertyName() {
assertThat(DtoMetaBuilder.propertyName("setName")).isEqualTo("name");
Assertions.assertThat(DtoMetaBuilder.propertyName("setName")).isEqualTo("name");
assertThat(DtoMetaBuilder.propertyName("setId")).isEqualTo("id");
assertThat(DtoMetaBuilder.propertyName("setI")).isEqualTo("i");
assertThat(DtoMetaBuilder.propertyName("setfoo")).isEqualTo("foo");
@@ -1,11 +1,10 @@
package io.ebeaninternal.server.executor;
import io.ebean.config.MdcBackgroundExecutorWrapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.MDC;
import io.ebean.config.MdcBackgroundExecutorWrapper;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -109,18 +108,18 @@ public class DefaultBackgroundExecutorTest {
es.submit(()->{
assertThat(MDC.get("hello")).isNull();
}).get();
MDC.put("hello", "there");
es.wrap(() -> {
assertThat(MDC.get("hello")).isEqualTo("there");
}).run(); // will clear the MDC. But this should be OK
MDC.put("hello", "there");
es.wrap(() -> {
assertThat(MDC.get("hello")).isEqualTo("there");
return "Callable";
}).call(); // will clear the MDC. But this should be OK
MDC.put("hello", "there");
CountDownLatch latch = new CountDownLatch(1);
@@ -136,7 +135,7 @@ public class DefaultBackgroundExecutorTest {
return "Callable";
}).get();
MDC.clear();
es.execute(()->{
assertThat(MDC.get("hello")).isNull();
});
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.expression.platform;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -10,7 +11,7 @@ public class PostgresCastTest {
@Test
public void cast() {
assertThat(PostgresCast.cast(1)).isEqualTo("::integer");
Assertions.assertThat(PostgresCast.cast(1)).isEqualTo("::integer");
assertThat(PostgresCast.cast(1L)).isEqualTo("::bigint");
assertThat(PostgresCast.cast(1.0D)).isEqualTo("::decimal");
assertThat(PostgresCast.cast("")).isEqualTo("");
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.profile;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -8,7 +9,7 @@ public class UtilLocationTest {
@Test
public void label() {
assertThat(UtilLocation.label("foo")).isEqualTo("foo");
Assertions.assertThat(UtilLocation.label("foo")).isEqualTo("foo");
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>")).isEqualTo("ProfileLocationTest$Other.init");
}
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.query;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -19,7 +20,7 @@ public class DbOrderByTrimTest {
}
private void test(String value, String suffix) {
assertEquals(value, DbOrderByTrim.trim(value + suffix));
Assertions.assertEquals(value, DbOrderByTrim.trim(value + suffix));
}
@Test
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.query;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -8,7 +9,7 @@ public class SqlTreeBuilderTest {
@Test
public void mergeOnDistinct_equal() {
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.id"), "t0.id");
Assertions.assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.id"), "t0.id");
}
@Test
@@ -1,13 +1,12 @@
package io.ebeaninternal.server.querydefn;
import io.ebean.BaseTestCase;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
public class OrmQueryDetailParserTest extends BaseTestCase {
public class OrmQueryDetailParserTest {
OrmQueryDetail parse(String query) {
return new OrmQueryDetailParser(query).parse();
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.querydefn;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -8,7 +9,7 @@ public class OrmUpdatePropertiesTest {
@Test
public void trim() {
assertEquals("ship_id", OrmUpdateProperties.trim("${}ship_id"));
Assertions.assertEquals("ship_id", OrmUpdateProperties.trim("${}ship_id"));
assertEquals("(ship_id)", OrmUpdateProperties.trim("(${}ship_id)"));
}
}
@@ -2,14 +2,26 @@ package io.ebeaninternal.server.rawsql;
import io.ebeaninternal.server.rawsql.SpiRawSql.ColumnMapping;
import io.ebeaninternal.server.rawsql.SpiRawSql.ColumnMapping.Column;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestRawSqlColumnParsing {
@Test
public void testDeriveProperty() {
Assertions.assertThat(SpiRawSql.ColumnMapping.Column.derivePropertyName("item_total", "some_other")).isEqualTo("itemTotal");
assertThat(SpiRawSql.ColumnMapping.Column.derivePropertyName(null, "some_other")).isEqualTo("someOther");
assertThat(SpiRawSql.ColumnMapping.Column.derivePropertyName(null, "alias.some_other")).isEqualTo("someOther");
assertThat(SpiRawSql.ColumnMapping.Column.derivePropertyName(null, "alias.someOther")).isEqualTo("someOther");
assertThat(SpiRawSql.ColumnMapping.Column.derivePropertyName(null, "some")).isEqualTo("some");
assertThat(SpiRawSql.ColumnMapping.Column.derivePropertyName(null, "someOther")).isEqualTo("someOther");
}
@Test
public void test_simple() {
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.rawsql;
import io.ebean.BaseTestCase;
import io.ebean.SqlRow;
import org.junit.jupiter.api.Test;
@@ -12,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestRawSqlService extends BaseTestCase {
public class TestRawSqlService {
@Test
public void testDistinctColumnNames() throws SQLException {
@@ -0,0 +1,4 @@
package org.tests.model.basic;
public class Contact {
}
@@ -0,0 +1,4 @@
package org.tests.model.basic;
public class Customer {
}
@@ -4,7 +4,6 @@ import io.ebean.annotation.Platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
import io.ebean.config.NamingConvention;
import io.ebean.config.dbplatform.DbHistorySupport;
import io.ebean.config.dbplatform.IdType;
import io.ebean.util.StringHelper;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
@@ -62,7 +61,7 @@ public class BaseTableDdl implements TableDdl {
private final boolean strictMode;
private final boolean alterHistoryTables;
private final PlatformHistoryDdl.TableBased tableHistory;
/**
* Helper class that is used to execute the migration ddl before and after the migration action.
@@ -181,11 +180,10 @@ public class BaseTableDdl implements TableDdl {
this.platformDdl = platformDdl;
this.platformDdl.configure(config);
this.strictMode = config.isDdlStrictMode();
DbHistorySupport hist = platformDdl.getPlatform().getHistorySupport();
if (hist == null) {
this.alterHistoryTables = false;
if (platformDdl.historyDdl instanceof PlatformHistoryDdl.TableBased) {
this.tableHistory = (PlatformHistoryDdl.TableBased) platformDdl.historyDdl;
} else {
this.alterHistoryTables = platformDdl.historyDdl.alterHistoryTables();
this.tableHistory = null;
}
}
@@ -237,9 +235,8 @@ public class BaseTableDdl implements TableDdl {
writeInlineForeignKeys(apply, createTable);
}
apply.newLine().append(")");
if (createTable.getTablespace() != null) {
platformDdl.addTablespace(apply, createTable.getTablespace(), createTable.getIndexTablespace(), createTable.getLobTablespace());
}
addTableTableSpaces(apply, createTable);
addTableStorageEngine(apply, createTable);
addTableCommentInline(apply, createTable);
if (partitionMode != null) {
@@ -271,6 +268,8 @@ public class BaseTableDdl implements TableDdl {
}
}
private String sequenceName(CreateTable createTable, List<Column> pk) {
return namingConvention.getSequenceName(createTable.getName(), pk.get(0).getName());
}
@@ -292,6 +291,19 @@ public class BaseTableDdl implements TableDdl {
}
}
/**
* Add tablespace declaration.
*/
protected void addTableTableSpaces(DdlBuffer apply, CreateTable createTable) {
String tableSpace = platformDdl.extract(createTable.getTablespace());
if (hasValue(tableSpace)) {
platformDdl.addTablespace(apply,
tableSpace,
platformDdl.extract(createTable.getIndexTablespace()),
platformDdl.extract(createTable.getLobTablespace()));
}
}
/**
* Add the table storage engine clause.
*/
@@ -621,8 +633,8 @@ public class BaseTableDdl implements TableDdl {
if (isTrue(addColumn.isWithHistory())) {
platformDdl.regenerateHistoryTriggers(writer, tableName);
// make same changes to the history table
if (alterHistoryTables) {
String historyTable = historyTable(tableName);
if (tableHistory != null) {
String historyTable = tableHistory.historyTableName(tableName);
for (Column column : columns) {
alterTableAddColumn(writer, historyTable, column, true, true);
}
@@ -656,14 +668,17 @@ public class BaseTableDdl implements TableDdl {
*/
@Override
public void generate(DdlWrite writer, AlterTable alterTable) {
if (hasValue(alterTable.getTablespace())
|| hasValue(alterTable.getIndexTablespace())
|| hasValue(alterTable.getLobTablespace())) {
String tableSpace = platformDdl.extract(alterTable.getTablespace());
String indexSpace = platformDdl.extract(alterTable.getIndexTablespace());
String lobSpace = platformDdl.extract(alterTable.getLobTablespace());
if (hasValue(tableSpace)
|| hasValue(indexSpace)
|| hasValue(lobSpace)) {
writer.apply().appendStatement(platformDdl.alterTableTablespace(alterTable.getName(),
DdlHelp.toTablespace(alterTable.getTablespace()),
DdlHelp.toTablespace(alterTable.getIndexTablespace()),
DdlHelp.toTablespace(alterTable.getLobTablespace())));
DdlHelp.toTablespace(tableSpace),
DdlHelp.toTablespace(indexSpace),
DdlHelp.toTablespace(lobSpace)));
}
}
@@ -678,8 +693,8 @@ public class BaseTableDdl implements TableDdl {
if (isTrue(dropColumn.isWithHistory())) {
platformDdl.regenerateHistoryTriggers(writer, tableName);
// also drop from the history table
if (alterHistoryTables) {
alterTableDropColumn(writer, historyTable(tableName), dropColumn.getColumnName());
if (tableHistory != null) {
alterTableDropColumn(writer, tableHistory.historyTableName(tableName), dropColumn.getColumnName());
}
}
}
@@ -757,13 +772,6 @@ public class BaseTableDdl implements TableDdl {
platformDdl.addColumnComment(writer.applyPostAlter(), alterColumn.getTableName(), alterColumn.getColumnName(), alterColumn.getComment());
}
/**
* Return the name of the history table given the base table name.
*/
protected String historyTable(String baseTable) {
return naming.normaliseTable(baseTable) + historyTableSuffix;
}
/**
* alter all the base attributes (type/default/notnull) of the column together.
* Some platforms (like mysql/sqlserver/hana) must do that in one statement,
@@ -784,9 +792,9 @@ public class BaseTableDdl implements TableDdl {
}
if (applyToHistory) {
platformDdl.regenerateHistoryTriggers(writer, alter.getTableName());
if (alterHistoryTables) {
if (tableHistory != null) {
AlterColumn alterHistoryColumn = new AlterColumn();
alterHistoryColumn.setTableName(historyTable(alter.getTableName()));
alterHistoryColumn.setTableName(tableHistory.historyTableName(alter.getTableName()));
alterHistoryColumn.setColumnName(alter.getColumnName());
// ignore default value (not needed on history tables)
alterHistoryColumn.setCurrentType(alter.getCurrentType());
@@ -104,15 +104,21 @@ public class DB2Ddl extends PlatformDdl {
+ "\n" + dropIndex(uniqueConstraintName, tableName);
}
private void assertNoSchema(String objName) {
if (objName.indexOf('.') != -1) {
throw new UnsupportedOperationException("Schemas are not yet supported. ObjectName: '" + objName + "'");
}
}
@Override
public String alterTableDropConstraint(String tableName, String constraintName) {
assertNoSchema(tableName);
StringBuilder sb = new StringBuilder(300);
sb.append("delimiter $$\n")
.append("begin\n")
.append("if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = '")
.append("if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = '")
.append(maxConstraintName(constraintName).toUpperCase())
.append("' and tabname = '").append(naming.normaliseTable(tableName).toUpperCase()).append("') then\n")
.append("' and ucase(tabname) = '").append(naming.normaliseTable(tableName).toUpperCase()).append("') then\n")
.append(" prepare stmt from 'alter table ").append(tableName)
.append(" drop constraint ").append(maxConstraintName(constraintName)).append("';\n")
@@ -126,10 +132,11 @@ public class DB2Ddl extends PlatformDdl {
@Override
public String dropIndex(String indexName, String tableName, boolean concurrent) {
assertNoSchema(indexName);
StringBuilder sb = new StringBuilder(300);
sb.append("delimiter $$\n")
.append("begin\n")
.append("if exists (select indname from syscat.indexes where indschema = current_schema and indname = '")
.append("if exists (select indname from syscat.indexes where indschema = current_schema and ucase(indname) = '")
.append(maxConstraintName(indexName).toUpperCase()).append("') then\n")
.append(" prepare stmt from 'drop index ").append(maxConstraintName(indexName)).append("';\n")
.append(" execute stmt;\n")
@@ -140,10 +147,11 @@ public class DB2Ddl extends PlatformDdl {
@Override
public String dropSequence(String sequenceName) {
assertNoSchema(sequenceName);
StringBuilder sb = new StringBuilder(300);
sb.append("delimiter $$\n");
sb.append("begin\n");
sb.append("if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = '")
sb.append("if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = '")
.append(maxConstraintName(sequenceName).toUpperCase()).append("') then\n");
sb.append(" prepare stmt from 'drop sequence ").append(maxConstraintName(sequenceName)).append("';\n");
sb.append(" execute stmt;\n");
@@ -1,7 +1,6 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
@@ -14,35 +13,41 @@ import io.ebeaninternal.dbmigration.model.MTable;
*
* @author Roland Praml, FOCONIS AG
*/
public class Db2HistoryDdl implements PlatformHistoryDdl {
public class Db2HistoryDdl extends DbTableBasedHistoryDdl implements PlatformHistoryDdl {
private String systemPeriodStart;
private String systemPeriodEnd;
private String transactionId;
private PlatformDdl platformDdl;
private DbConstraintNaming constraintNaming;
private String historySuffix;
@Override
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
super.configure(config, platformDdl);
this.systemPeriodStart = config.getAsOfSysPeriod() + "_start";
this.systemPeriodEnd = config.getAsOfSysPeriod() + "_end";
this.transactionId = config.getAsOfSysPeriod() + "_txn"; // required for DB2
this.platformDdl = platformDdl;
this.constraintNaming = config.getConstraintNaming();
this.historySuffix = config.getHistoryTableSuffix();
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) {
String tableName = table.getName();
String historyTableName = historyTable(tableName);
String historyTableName = historyTableName(tableName);
// DB2 requires an EXACT copy (same column types with null/non-null, same order)
addSysPeriodColumns(writer, tableName);
writer.applyPostAlter().append("create table ").append(historyTableName)
.append(" as (select * from ").append(tableName).append(") with no data").endOfStatement();
DdlBuffer tableBuf = writer.applyPostAlter();
tableBuf.append("create table ").append(historyTableName)
.append(" as (select * from ").append(tableName).append(") with no data");
if (table.getTablespaceMeta() != null) {
String tableSpace = platformDdl.extract(table.getTablespaceMeta().getTablespaceName());
if (tableSpace != null && !tableSpace.isEmpty()) {
platformDdl.addTablespace(tableBuf,
tableSpace,
platformDdl.extract(table.getTablespaceMeta().getIndexTablespace()),
platformDdl.extract(table.getTablespaceMeta().getLobTablespace()));
}
}
tableBuf.endOfStatement();
enableSystemVersioning(writer.applyPostAlter(), tableName);
platformDdl.alterTable(writer, tableName).setHistoryHandled();
@@ -74,7 +79,7 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
platformDdl.alterTableDropColumn(writer, baseTable, transactionId);
// drop the history table
writer.applyPostAlter().append("drop table ").append(historyTable(baseTable)).endOfStatement();
writer.applyPostAlter().append("drop table ").append(historyTableName(baseTable)).endOfStatement();
}
@Override
@@ -86,10 +91,6 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
createWithHistory(writer, table);
}
@Override
public boolean alterHistoryTables() {
return true;
}
@Override
public void updateTriggers(DdlWrite writer, String tableName) {
@@ -107,11 +108,7 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
}
public void enableSystemVersioning(DdlBuffer apply, String tableName) {
apply.append("alter table ").append(tableName).append(" add versioning use history table ").append(historyTable(tableName)).endOfStatement();
}
protected String historyTable(String tableName) {
return constraintNaming.normaliseTable(tableName) + historySuffix;
apply.append("alter table ").append(tableName).append(" add versioning use history table ").append(historyTableName(tableName)).endOfStatement();
}
}
@@ -0,0 +1,44 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
/**
* Base implementation for all histories, where we must maintain history table (trigger based, db2 and hana)
*
* @author Roland Praml, FOCONIS AG
*
*/
public abstract class DbTableBasedHistoryDdl implements PlatformHistoryDdl.TableBased {
private DbConstraintNaming constraintNaming;
private String historySuffix;
protected PlatformDdl platformDdl;
@Override
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
this.platformDdl = platformDdl;
this.historySuffix = config.getHistoryTableSuffix();
this.constraintNaming = config.getConstraintNaming();
}
@Override
public String historyTableName(String baseTableName) {
return normalise(baseTableName, historySuffix);
}
protected String normalise(String tableName, String suffix) {
String normalized = quote(normalise(tableName) + suffix);
int lastPeriod = tableName.lastIndexOf('.');
return tableName.substring(0, lastPeriod + 1) + normalized;
}
protected String normalise(String tableName) {
return constraintNaming.normaliseTable(tableName);
}
protected String quote(String dbName) {
return platformDdl.quote(dbName);
}
}
@@ -1,7 +1,6 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
@@ -15,18 +14,14 @@ import java.util.List;
/**
* Uses DB triggers to maintain a history table.
*/
public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
protected DbConstraintNaming constraintNaming;
protected PlatformDdl platformDdl;
public abstract class DbTriggerBasedHistoryDdl extends DbTableBasedHistoryDdl implements PlatformHistoryDdl {
protected String sysPeriod;
protected String sysPeriodStart;
protected String sysPeriodEnd;
protected String viewSuffix;
protected String historySuffix;
protected String sysPeriodType = "datetime(6)";
protected String now = "now(6)";
@@ -37,11 +32,9 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
@Override
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
this.platformDdl = platformDdl;
super.configure(config, platformDdl);
this.sysPeriod = config.getAsOfSysPeriod();
this.viewSuffix = config.getAsOfViewSuffix();
this.historySuffix = config.getHistoryTableSuffix();
this.constraintNaming = config.getConstraintNaming();
this.sysPeriodStart = sysPeriod + "_start";
this.sysPeriodEnd = sysPeriod + "_end";
@@ -121,33 +114,24 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
protected abstract void dropTriggers(DdlBuffer buffer, String baseTable);
protected String normalise(String tableName) {
return constraintNaming.normaliseTable(tableName);
}
protected String historyTableName(String baseTableName) {
return quote(normalise(baseTableName) + historySuffix);
}
protected String historyViewName(String baseTableName) {
return quote(normalise(baseTableName) + viewSuffix);
return normalise(baseTableName, viewSuffix);
}
protected String procedureName(String baseTableName) {
return normalise(baseTableName) + "_history_version";
return normalise(baseTableName, "_history_version");
}
protected String triggerName(String baseTableName) {
return normalise(baseTableName) + "_history_upd";
return normalise(baseTableName, "_history_upd");
}
protected String updateTriggerName(String baseTableName) {
return normalise(baseTableName) + "_history_upd";
return normalise(baseTableName, "_history_upd");
}
protected String deleteTriggerName(String baseTableName) {
return normalise(baseTableName) + "_history_del";
return normalise(baseTableName, "_history_del");
}
protected void addSysPeriodColumns(DdlWrite writer, String baseTableName, String whenCreatedColumn) {
@@ -163,6 +147,8 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
protected void createHistoryTable(DdlBuffer apply, MTable table) {
createHistoryTableAs(apply, table);
createHistoryTableWithPeriod(apply);
// TODO: add tablespace here (currently no DbTriggerBased platforms with tablespace support)
apply.endOfStatement();
}
protected void createHistoryTableAs(DdlBuffer apply, MTable table) {
@@ -183,7 +169,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
writeColumnDefinition(apply, sysPeriodStart, sysPeriodType);
apply.append(",").newLine();
writeColumnDefinition(apply, sysPeriodEnd, sysPeriodType);
apply.newLine().append(")").endOfStatement();
apply.newLine().append(")");
}
/**
@@ -264,12 +250,5 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
return table.allHistoryColumns(true);
}
@Override
public boolean alterHistoryTables() {
return true;
}
protected String quote(String dbName) {
return platformDdl.quote(dbName);
}
}
@@ -1,7 +1,6 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
@@ -12,21 +11,16 @@ import io.ebeaninternal.dbmigration.model.MTable;
import java.util.Collection;
public class HanaHistoryDdl implements PlatformHistoryDdl {
public class HanaHistoryDdl extends DbTableBasedHistoryDdl implements PlatformHistoryDdl {
private String systemPeriodStart;
private String systemPeriodEnd;
private PlatformDdl platformDdl;
private DbConstraintNaming constraintNaming;
private String historySuffix;
@Override
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
super.configure(config, platformDdl);
this.systemPeriodStart = config.getAsOfSysPeriod() + "_start";
this.systemPeriodEnd = config.getAsOfSysPeriod() + "_end";
this.platformDdl = platformDdl;
this.constraintNaming = config.getConstraintNaming();
this.historySuffix = config.getHistoryTableSuffix();
}
@Override
@@ -95,11 +89,6 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
createWithHistory(writer, table);
}
@Override
public boolean alterHistoryTables() {
return true;
}
@Override
public void updateTriggers(DdlWrite writer, String tableName) {
DdlAlterTable alter = platformDdl.alterTable(writer, tableName);
@@ -140,8 +129,5 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
apply.endOfStatement();
}
protected String historyTableName(String tableName) {
return constraintNaming.normaliseTable(tableName) + historySuffix;
}
}
@@ -317,10 +317,13 @@ public class PlatformDdl {
// if columnType is different for different platforms, use pattern
// @Column(columnDefinition = PLATFORM1;DEFINITION1;PLATFORM2;DEFINITON2;DEFINITON-DEFAULT)
// e.g. @Column(columnDefinition = "db2;blob(64M);sqlserver,h2;varchar(227);varchar(127)")
private String extract(String type) {
String[] tmp = type.split(";");
protected String extract(String type) {
if (type == null) {
return null;
}
String[] tmp = type.split(";", -1); // do not discard trailing empty strings
if (tmp.length % 2 == 0) {
throw new IllegalArgumentException("You need an odd number of arguments. See Issue #2559 for details");
throw new IllegalArgumentException("You need an odd number of arguments in '" + type + "'. See Issue #2559 for details");
}
for (int i = 0; i < tmp.length - 2; i += 2) {
String[] platforms = tmp[i].split(",");
@@ -518,13 +521,6 @@ public class PlatformDdl {
return "alter table " + quote(tableName) + " " + dropConstraintIfExists + " " + maxConstraintName(constraintName);
}
/**
* Moves the table to an other tablespace.
*/
public String alterTableTablespace(String tablename, String tableSpace, String indexSpace, String lobSpace) {
return null;
}
/**
* Add a unique constraint to the table.
* <p>
@@ -793,10 +789,19 @@ public class PlatformDdl {
/**
* Adds tablespace declaration. Now only supported for db2.
* @throws IOException
*/
public void addTablespace(DdlBuffer apply, String tablespaceName, String indexTablespace, String lobTablespace) {
// now only supported for db2
throw new UnsupportedOperationException("Tablespaces are not supported for this platform");
}
/**
* Moves the table to an other tablespace.
*/
public String alterTableTablespace(String tablename, String tableSpace, String indexSpace, String lobSpace) {
if (tableSpace != null || indexSpace != null || lobSpace != null) {
throw new UnsupportedOperationException("Tablespaces are not supported for this platform");
}
return null;
}
protected String quote(String dbName) {
@@ -31,14 +31,6 @@ public interface PlatformHistoryDdl {
*/
void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable);
/**
* Returns true, if alters on the live tables should be applied also to the history tables. This is required for DbTriggerBased
* histories or on platforms like Hana, which are not SQL2011 history compatible (at least from DDL perspective)
*/
default boolean alterHistoryTables() {
return false;
}
/**
* Regenerate the history triggers/stored function due to column added/dropped/included or excluded.
*
@@ -47,4 +39,15 @@ public interface PlatformHistoryDdl {
default void updateTriggers(DdlWrite writer, String tableName) {
// nop
}
/**
* When history is table based, then alters on the live tables are applied also to the history tables. This is required for
* DbTriggerBased histories or on platforms like Hana, which are not SQL2011 history compatible (at least from DDL perspective)
*/
interface TableBased extends PlatformHistoryDdl {
/**
* Returns the history table name with propert quotes.
*/
public String historyTableName(String baseTableName);
}
}
@@ -107,4 +107,23 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
buffer.append(");").newLine();
}
@Override
protected String procedureName(String baseTableName) {
return normalise(baseTableName) + "_history_version";
}
@Override
protected String triggerName(String baseTableName) {
return normalise(baseTableName) + "_history_upd";
}
@Override
protected String updateTriggerName(String baseTableName) {
return normalise(baseTableName) + "_history_upd";
}
@Override
protected String deleteTriggerName(String baseTableName) {
return normalise(baseTableName) + "_history_del";
}
}
@@ -4,6 +4,7 @@ import io.localtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.config.dbplatform.db2.DB2LuwPlatform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.hana.HanaPlatform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
@@ -42,6 +43,9 @@ public class BaseDdlHandlerTest extends BaseTestCase {
return handler(new HanaPlatform());
}
private DdlHandler db2Handler() {
return handler(new DB2LuwPlatform());
}
@Test
public void addColumn_nullable_noConstraint() throws Exception {
@@ -219,6 +223,19 @@ public class BaseDdlHandlerTest extends BaseTestCase {
assertThat(writer.dropAll().getBuffer().trim()).isEqualTo("drop table foo cascade;");
}
@Test
public void createTableWithTableSpace() throws Exception {
DdlWrite writer = new DdlWrite();
DdlHandler handler = db2Handler();
handler.generate(writer, Helper.getCreateTable());
assertThat(writer.toString())
.contains("create table foo (")
.contains(") in fooSpace index in fooIndexSpace long in fooLobSpace;");
}
@Test
public void generateChangeSet() throws Exception {
@@ -34,8 +34,9 @@ public class ModelContainerApplyTest {
MTable foo = model.getTable("foo");
assertThat(foo.getComment()).isEqualTo("comment");
assertThat(foo.getTablespaceMeta().getTablespaceName()).isEqualTo("fooSpace");
assertThat(foo.getTablespaceMeta().getIndexTablespace()).isEqualTo("fooIndexSpace");
assertThat(foo.getTablespaceMeta().getTablespaceName()).isEqualTo("db2;fooSpace;");
assertThat(foo.getTablespaceMeta().getIndexTablespace()).isEqualTo("db2;fooIndexSpace;");
assertThat(foo.getTablespaceMeta().getLobTablespace()).isEqualTo("db2;fooLobSpace;");
assertThat(foo.isWithHistory()).isEqualTo(false);
assertThat(foo.allColumns()).extracting("name").contains("col1", "col3", "added_to_foo");
}
@@ -4,7 +4,7 @@
<changeSet type="apply">
<createTable name="foo" pkName="pk_foo" withHistory="false" tablespace="fooSpace" indexTablespace="fooIndexSpace" comment="comment">
<createTable name="foo" pkName="pk_foo" withHistory="false" tablespace="db2;fooSpace;" indexTablespace="db2;fooIndexSpace;" lobTablespace="db2;fooLobSpace;" comment="comment">
<column name="col1" type="varchar(4)" notnull="true" primaryKey="true"/>
<column name="col2" type="varchar(30)" notnull="true"/>
<column name="col3" type="varchar(30)" notnull="true"/>
@@ -1,6 +1,7 @@
package io.ebean;
import io.ebean.annotation.ForPlatform;
import io.ebean.xtest.BaseTestCase;
import io.ebean.xtest.ForPlatform;
import io.ebean.annotation.Platform;
import org.junit.jupiter.api.Test;
@@ -1,44 +0,0 @@
package io.ebean;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class PropertyTest {
@Test
public void equals() throws Exception {
assertEquals(prop("foo", true), prop("foo", true));
}
@Test
public void diff_basic() throws Exception {
assertNotEquals(prop("foo", true), prop("bar", true));
assertNotEquals(prop("foo", true), prop("foo", false));
assertNotEquals(prop("foo", false), prop("foo", true));
}
@Test
public void diff_nulls() throws Exception {
assertEquals(prop("foo", true, "nulls", "high"), prop("foo", true, "nulls", "high"));
assertEquals(prop("foo", true, "nulls", "low"), prop("foo", true, "nulls", "low"));
assertNotEquals(prop("foo", true), prop("foo", true, "nulls", "high"));
assertNotEquals(prop("foo", true, "nulls", "high"), prop("foo", true));
assertNotEquals(prop("foo", true, "nulls", "high"), prop("foo", true, "nulls", "low"));
assertNotEquals(prop("foo", true, "nulls", "low"), prop("foo", true, "nulls", "high"));
}
private OrderBy.Property prop(String name, boolean asc) {
return new OrderBy.Property(name, asc, null, null);
}
private OrderBy.Property prop(String name, boolean asc, String nulls, String highLow) {
return new OrderBy.Property(name, asc, nulls, highLow);
}
}
@@ -3,10 +3,10 @@ package io.ebean.config;
import io.ebean.Database;
import io.ebean.DatabaseFactory;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import io.ebean.datasource.DataSourceAlert;
import io.ebean.datasource.DataSourceInitialiseException;
import io.ebean.xtest.ForPlatform;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.EBasicVer;
@@ -1,7 +1,7 @@
package io.ebean.test;
import com.fasterxml.jackson.databind.JsonNode;
import io.ebean.BaseTestCase;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.etest.BSimpleFor;
import org.junit.jupiter.api.Test;
@@ -1,5 +1,6 @@
package io.ebean;
package io.ebean.xtest;
import io.ebean.*;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import io.ebean.cache.ServerCacheStatistics;
@@ -7,6 +8,7 @@ import io.ebean.config.dbplatform.IdType;
import io.ebean.meta.MetaTimedMetric;
import io.ebean.meta.ServerMetrics;
import io.ebean.util.StringHelper;
import io.ebean.xtest.base.PlatformCondition;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.SpiTransaction;

Some files were not shown because too many files have changed in this diff Show More