mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Merge remote-tracking branch 'upstream/master'
# Conflicts: # ebean-bom/pom.xml # ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java # ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DB2Ddl.java # ebean-ddl-generator/src/test/resources/dbmigration/migrationtest/db2/1.1.sql # ebean-ddl-generator/src/test/resources/dbmigration/migrationtest/db2/1.3.sql # ebean-ddl-generator/src/test/resources/dbmigration/migrationtest/db2/idx_db2.migrations # ebean-test/src/test/java/org/tests/basic/TestMetaAnnotation.java # ebean-test/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey3.java # tests/test-java16/pom.xml # tests/test-kotlin/pom.xml
This commit is contained in:
commit
090f3cddb8
56 files changed
+593
-597
No files matched your search
@@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Automatically configure ServerConfig for testing purposes.
|
||||
* <p>
|
||||
@@ -47,6 +49,29 @@ public class AutoConfigureForTesting implements AutoConfigure {
|
||||
@Override
|
||||
public void postConfigure(DatabaseConfig config) {
|
||||
setupProviders(config);
|
||||
|
||||
if (org.h2.engine.Constants.VERSION_MAJOR == 1) {
|
||||
// This code may be removed later, when droppinv H2 1.xxx compatibility
|
||||
System.err.println("Running tests in H2 1.xxx compatibility mode");
|
||||
System.setProperty("ebean.h2.useV1Syntax", "true");
|
||||
makeV1Compatible(config.getDataSourceConfig());
|
||||
makeV1Compatible(config.getReadOnlyDataSourceConfig());
|
||||
}
|
||||
}
|
||||
|
||||
private void makeV1Compatible(DataSourceConfig ds) {
|
||||
if (ds == null) {
|
||||
return;
|
||||
}
|
||||
String url = ds.getUrl();
|
||||
if (url == null || !url.startsWith("jdbc:h2:")) {
|
||||
return;
|
||||
}
|
||||
// remove illegal URL options
|
||||
url = url.replace(";MODE=LEGACY", "");
|
||||
url = url.replace(";NON_KEYWORDS=KEY,VALUE", "");
|
||||
url = url.replace(";NON_KEYWORDS=KEY", "");
|
||||
ds.setUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,18 +35,14 @@ public class PlatformAutoConfig {
|
||||
KNOWN_PLATFORMS.put("cockroach", new CockroachSetup());
|
||||
KNOWN_PLATFORMS.put("hana", new HanaSetup());
|
||||
KNOWN_PLATFORMS.put("db2", new Db2Setup());
|
||||
KNOWN_PLATFORMS.put("yugabyte", new YugabyteSetup());
|
||||
}
|
||||
|
||||
private final DatabaseConfig config;
|
||||
|
||||
private final Properties properties;
|
||||
|
||||
private String db;
|
||||
|
||||
private String platform;
|
||||
|
||||
private PlatformSetup platformSetup;
|
||||
|
||||
private String databaseName;
|
||||
|
||||
public PlatformAutoConfig(String db, DatabaseConfig config) {
|
||||
|
||||
@@ -6,41 +6,33 @@ class PostgresSetup implements PlatformSetup {
|
||||
|
||||
@Override
|
||||
public Properties setup(Config config) {
|
||||
|
||||
int defaultPort = config.isUseDocker() ? 6432 : 5432;
|
||||
|
||||
config.ddlMode("dropCreate");
|
||||
config.setDefaultPort(defaultPort);
|
||||
config.setUsernameDefault();
|
||||
config.setPasswordDefault();
|
||||
config.setUrl("jdbc:postgresql://${host}:${port}/${databaseName}");
|
||||
|
||||
String schema = config.getSchema();
|
||||
if (schema != null && !schema.equals(config.getUsername())) {
|
||||
config.urlAppend("?currentSchema=" + schema);
|
||||
}
|
||||
config.setDriver("org.postgresql.Driver");
|
||||
config.datasourceDefaults();
|
||||
|
||||
return dockerProperties(config);
|
||||
}
|
||||
|
||||
private Properties dockerProperties(Config config) {
|
||||
|
||||
if (!config.isUseDocker()) {
|
||||
return new Properties();
|
||||
}
|
||||
|
||||
config.setDockerVersion("12");
|
||||
config.setDockerVersion("14");
|
||||
config.setExtensions("hstore,pgcrypto");
|
||||
return config.getDockerProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupExtraDbDataSource(Config config) {
|
||||
|
||||
int defaultPort = config.isUseDocker() ? 6432 : 5432;
|
||||
|
||||
config.setDefaultPort(defaultPort);
|
||||
config.setExtraUsernameDefault();
|
||||
config.setExtraDbPasswordDefault();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.ebean.test.config.platform;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
class YugabyteSetup implements PlatformSetup {
|
||||
|
||||
@Override
|
||||
public Properties setup(Config config) {
|
||||
int defaultPort = config.isUseDocker() ? 6433 : 5433;
|
||||
config.ddlMode("dropCreate");
|
||||
config.setDefaultPort(defaultPort);
|
||||
config.setUsernameDefault();
|
||||
config.setPasswordDefault();
|
||||
config.setUrl("jdbc:postgresql://${host}:${port}/${databaseName}");
|
||||
String schema = config.getSchema();
|
||||
if (schema != null && !schema.equals(config.getUsername())) {
|
||||
config.urlAppend("?currentSchema=" + schema);
|
||||
}
|
||||
config.setDriver("org.postgresql.Driver");
|
||||
config.datasourceDefaults();
|
||||
return dockerProperties(config);
|
||||
}
|
||||
|
||||
private Properties dockerProperties(Config config) {
|
||||
if (!config.isUseDocker()) {
|
||||
return new Properties();
|
||||
}
|
||||
config.setDockerVersion("2.11.2.0-b89");
|
||||
config.setExtensions("pgcrypto");
|
||||
return config.getDockerProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupExtraDbDataSource(Config config) {
|
||||
int defaultPort = config.isUseDocker() ? 6433 : 5433;
|
||||
config.setDefaultPort(defaultPort);
|
||||
config.setExtraUsernameDefault();
|
||||
config.setExtraDbPasswordDefault();
|
||||
config.setUrl("jdbc:postgresql://${host}:${port}/${databaseName}");
|
||||
config.setDriver("org.postgresql.Driver");
|
||||
config.extraDatasourceDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -199,6 +199,10 @@ public abstract class BaseTestCase {
|
||||
return Platform.POSTGRES == platform().base();
|
||||
}
|
||||
|
||||
public boolean isYugabyte() {
|
||||
return Platform.YUGABYTE == platform().base();
|
||||
}
|
||||
|
||||
public boolean isMySql() {
|
||||
return Platform.MYSQL == platform();
|
||||
}
|
||||
|
||||
@@ -6,18 +6,39 @@ import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.OrderDetail;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class EbeanServer_refresh {
|
||||
class EbeanServer_refresh {
|
||||
|
||||
private Path createSqlFile() throws IOException {
|
||||
File f = File.createTempFile("test-script", ".sql");
|
||||
Path path = f.toPath();
|
||||
List<String> lines = new ArrayList<>();
|
||||
lines.add("select * from o_customer;");
|
||||
Files.write(path, lines, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
return path;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic() {
|
||||
void script_run_asFile() throws IOException {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Path path = createSqlFile();
|
||||
DB.script().run(path);
|
||||
DB.script().run(path, Collections.emptyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void basic() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("tableName", "e_basic");
|
||||
|
||||
@@ -47,8 +68,7 @@ public class EbeanServer_refresh {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refresh_when_oneToManyLoaded() {
|
||||
|
||||
void refresh_when_oneToManyLoaded() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order order = DB.find(Order.class, 1);
|
||||
@@ -59,8 +79,7 @@ public class EbeanServer_refresh {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refresh_when_oneToManyVanilla() {
|
||||
|
||||
void refresh_when_oneToManyVanilla() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order order = DB.find(Order.class, 1);
|
||||
@@ -71,8 +90,7 @@ public class EbeanServer_refresh {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refresh_when_oneToManyNull() {
|
||||
|
||||
void refresh_when_oneToManyNull() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order order = DB.find(Order.class, 1);
|
||||
@@ -82,15 +100,11 @@ public class EbeanServer_refresh {
|
||||
DB.refresh(order);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void refresh_on_details_new() {
|
||||
|
||||
void refresh_on_details_new() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order order = DB.find(Order.class, 1);
|
||||
|
||||
DB.refresh(order); // call refresh BEFORE first access on "getDetail";
|
||||
|
||||
assertThat(order.getDetails()).hasSize(3);
|
||||
@@ -100,13 +114,9 @@ public class EbeanServer_refresh {
|
||||
DB.save(detail);
|
||||
|
||||
try {
|
||||
|
||||
assertThat(order.getDetails()).hasSize(3);
|
||||
|
||||
DB.refresh(order);
|
||||
|
||||
assertThat(order.getDetails()).hasSize(4);
|
||||
|
||||
} finally {
|
||||
DB.delete(detail); // restore old state
|
||||
}
|
||||
@@ -116,13 +126,9 @@ public class EbeanServer_refresh {
|
||||
assertThat(order.getDetails()).hasSize(3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void refresh_on_details_changed() {
|
||||
|
||||
void refresh_on_details_changed() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order order = DB.find(Order.class, 1);
|
||||
|
||||
DB.refresh(order); // call refresh BEFORE first access on "getDetail"
|
||||
@@ -139,11 +145,8 @@ public class EbeanServer_refresh {
|
||||
|
||||
try {
|
||||
assertThat(order.getDetails().get(0).getOrderQty()).isEqualTo(5);
|
||||
|
||||
DB.refresh(order);
|
||||
|
||||
assertThat(order.getDetails().get(0).getOrderQty()).isEqualTo(42);
|
||||
|
||||
} finally {
|
||||
// restore old value
|
||||
detail.setOrderQty(5);
|
||||
@@ -151,8 +154,6 @@ public class EbeanServer_refresh {
|
||||
}
|
||||
|
||||
DB.refresh(order);
|
||||
|
||||
assertThat(order.getDetails().get(0).getOrderQty()).isEqualTo(5);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class PlatformNoGeneratedKeysTest {
|
||||
config.setDdlRun(true);
|
||||
config.getClasses().add(EBasicVer.class);
|
||||
config.getClasses().add(BasicDraftableBean.class);
|
||||
|
||||
config.loadFromProperties(); // trigger auto config for H2 1.x
|
||||
|
||||
return DatabaseFactory.create(config);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebean.test;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.etest.BSimpleFor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -11,10 +12,10 @@ import static io.ebean.test.DbJson.readResource;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class DbJsonTest {
|
||||
class DbJsonTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void of() {
|
||||
void of() {
|
||||
|
||||
DB.find(BSimpleFor.class).delete();
|
||||
|
||||
@@ -34,14 +35,19 @@ public class DbJsonTest {
|
||||
|
||||
final List<BSimpleFor> beans = DB.find(BSimpleFor.class).findList();
|
||||
|
||||
if (isH2() || isPostgres()) {
|
||||
DbJson.of(beans)
|
||||
//.withPlaceholder("_")
|
||||
.replace("id", "whenModified")
|
||||
.assertContentMatches("/bean/example-list-match.json");
|
||||
}
|
||||
|
||||
DbJson.of(beans)
|
||||
//.withPlaceholder("_")
|
||||
.replace("id", "whenModified")
|
||||
.assertContentMatches("/bean/example-list.json");
|
||||
.assertContainsResource("/bean/example-list-contains.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertContains_pass() {
|
||||
void assertContains_pass() {
|
||||
|
||||
BSimpleFor bean = new BSimpleFor("something-contains-me", "YeahNah");
|
||||
DB.save(bean);
|
||||
@@ -55,7 +61,7 @@ public class DbJsonTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asJson() {
|
||||
void asJson() {
|
||||
|
||||
BSimpleFor bean = new BSimpleFor("other");
|
||||
DB.save(bean);
|
||||
|
||||
@@ -11,9 +11,10 @@ public class StartYugabyte {
|
||||
YugabyteConfig config = new YugabyteConfig("2.11.2.0-b89");
|
||||
config.setDbName("unit");
|
||||
config.setUser("unit");
|
||||
config.setExtensions("pgcrypto");
|
||||
|
||||
YugabyteContainer container = new YugabyteContainer(config);
|
||||
container.start();
|
||||
container.startWithDropCreate();
|
||||
|
||||
// Run container ut_yugabyte with host:localhost port:6433 db:unit user:unit/test shutdown:None
|
||||
// docker run -d --name ut_yugabyte -p 6433:5433 -p 7000:7000 -p 9000:9000 -p 9042:9042 yugabytedb/yugabyte:2.11.2.0-b89 bin/yugabyted start --daemon=false
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TestMetaAnnotation extends BaseTestCase {
|
||||
* This test writes 101 spaces to "line1" which is annotated with @Size(max=100).
|
||||
*/
|
||||
@Test
|
||||
@IgnorePlatform({Platform.POSTGRES, Platform.SQLSERVER, Platform.MYSQL, Platform.MARIADB, Platform.DB2}) // pg & mssql does not fail if string is too long.
|
||||
@IgnorePlatform({Platform.POSTGRES, Platform.SQLSERVER, Platform.MYSQL, Platform.MARIADB, Platform.DB2, Platform.YUGABYTE}) // pg & mssql does not fail if string is too long.
|
||||
public void testWrite101SpacesToLine1() {
|
||||
|
||||
Address address = new Address();
|
||||
@@ -66,7 +66,7 @@ public class TestMetaAnnotation extends BaseTestCase {
|
||||
* This test writes 101 spaces to "line1" which is meta-annotated with {@link SizeMedium}.
|
||||
*/
|
||||
@Test
|
||||
@IgnorePlatform({Platform.POSTGRES, Platform.SQLSERVER, Platform.MYSQL, Platform.MARIADB, Platform.DB2})
|
||||
@IgnorePlatform({Platform.POSTGRES, Platform.SQLSERVER, Platform.MYSQL, Platform.MARIADB, Platform.DB2, Platform.YUGABYTE})
|
||||
public void testWrite101SpacesToLine2() {
|
||||
|
||||
Address address = new Address();
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TestInetAddressType extends TransactionalTestCase {
|
||||
@Test
|
||||
public void testIp6() throws UnknownHostException {
|
||||
|
||||
if (isPostgres()) {
|
||||
if (isPostgres() || isYugabyte()) {
|
||||
insertUpdateDeleteFind("2001:db8:85a3:0:0:8a2e:370:7334", "2001:db8:85a3::8a2e:370:7334", "2001:4f8:3:ba::/64", "2001:4f8:3:ba::/64");
|
||||
} else {
|
||||
insertUpdateDeleteFind("2001:db8:85a3:0:0:8a2e:370:7334", "2001:db8:85a3:0:0:8a2e:370:7334", "192.168.100.128/25", "192.168.100.128/25");
|
||||
|
||||
@@ -2,29 +2,21 @@ package org.tests.expression.bitwise;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestBitwiseExpressions extends BaseTestCase {
|
||||
class TestBitwiseExpressions extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void where() {
|
||||
|
||||
setup();
|
||||
bitwiseNot();
|
||||
bitwiseAnd();
|
||||
bitwiseAny();
|
||||
bitwiseAll();
|
||||
}
|
||||
|
||||
private void bitwiseNot() {
|
||||
|
||||
void bitwiseNot() {
|
||||
List<BwBean> notColour = DB.find(BwBean.class)
|
||||
// HAS_COLOUR not set ...
|
||||
.where().bitwiseNot("flags", BwFlags.HAS_COLOUR)
|
||||
.orderBy("name")
|
||||
.findList();
|
||||
|
||||
assertThat(notColour).hasSize(2);
|
||||
@@ -32,8 +24,8 @@ public class TestBitwiseExpressions extends BaseTestCase {
|
||||
assertThat(notColour.get(1).getName()).isEqualTo("SizeOnly");
|
||||
}
|
||||
|
||||
private void bitwiseAnd() {
|
||||
|
||||
@Test
|
||||
void bitwiseAnd() {
|
||||
List<BwBean> list = DB.find(BwBean.class)
|
||||
// not bulk set AND size set
|
||||
.where().bitwiseAnd("flags", BwFlags.HAS_BULK + BwFlags.HAS_SIZE, BwFlags.HAS_SIZE)
|
||||
@@ -59,10 +51,11 @@ public class TestBitwiseExpressions extends BaseTestCase {
|
||||
assertThat(list.get(0).getName()).isEqualTo("ColourOnly");
|
||||
}
|
||||
|
||||
private void bitwiseAny() {
|
||||
|
||||
@Test
|
||||
void bitwiseAny() {
|
||||
List<BwBean> list = DB.find(BwBean.class)
|
||||
.where().bitwiseAny("flags", BwFlags.HAS_BULK + BwFlags.HAS_SIZE)
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
assertThat(list).hasSize(3);
|
||||
@@ -70,21 +63,23 @@ public class TestBitwiseExpressions extends BaseTestCase {
|
||||
assertThat(list.get(1).getName()).isEqualTo("ColourAndBulk");
|
||||
assertThat(list.get(2).getName()).isEqualTo("Everything");
|
||||
|
||||
|
||||
list = DB.find(BwBean.class)
|
||||
.where().bitwiseAny("flags", BwFlags.HAS_BULK + BwFlags.HAS_SIZE + BwFlags.HAS_COLOUR)
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
assertThat(list).hasSize(4);
|
||||
|
||||
list = DB.find(BwBean.class)
|
||||
.where().bitwiseAny("flags", BwFlags.HAS_SIZE + BwFlags.HAS_COLOUR)
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
assertThat(list).hasSize(4);
|
||||
|
||||
list = DB.find(BwBean.class)
|
||||
.where().bitwiseAny("flags", BwFlags.HAS_SIZE)
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
assertThat(list).hasSize(2);
|
||||
@@ -93,6 +88,7 @@ public class TestBitwiseExpressions extends BaseTestCase {
|
||||
|
||||
list = DB.find(BwBean.class)
|
||||
.where().bitwiseAny("flags", BwFlags.HAS_COLOUR)
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
assertThat(list).hasSize(3);
|
||||
@@ -101,8 +97,8 @@ public class TestBitwiseExpressions extends BaseTestCase {
|
||||
assertThat(list.get(2).getName()).isEqualTo("Everything");
|
||||
}
|
||||
|
||||
private void bitwiseAll() {
|
||||
|
||||
@Test
|
||||
void bitwiseAll() {
|
||||
List<BwBean> list = DB.find(BwBean.class)
|
||||
.where().bitwiseAll("flags", BwFlags.HAS_BULK + BwFlags.HAS_SIZE)
|
||||
.findList();
|
||||
@@ -137,11 +133,10 @@ public class TestBitwiseExpressions extends BaseTestCase {
|
||||
assertThat(list.get(0).getName()).isEqualTo("ColourOnly");
|
||||
assertThat(list.get(1).getName()).isEqualTo("ColourAndBulk");
|
||||
assertThat(list.get(2).getName()).isEqualTo("Everything");
|
||||
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
DB.find(BwBean.class).delete();
|
||||
|
||||
new BwBean("Nothing", BwFlags.NOTHING).save();
|
||||
@@ -149,6 +144,5 @@ public class TestBitwiseExpressions extends BaseTestCase {
|
||||
new BwBean("SizeOnly", BwFlags.HAS_SIZE).save();
|
||||
new BwBean("ColourAndBulk", BwFlags.HAS_COLOUR + BwFlags.HAS_BULK).save();
|
||||
new BwBean("Everything", BwFlags.HAS_COLOUR + BwFlags.HAS_BULK + BwFlags.HAS_SIZE).save();
|
||||
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -369,7 +369,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
|
||||
if (isH2()) {
|
||||
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code) in (?,?) order by t0.sku desc; --bind(def,Array[2]={2-1000,3-1000})");
|
||||
} else if (isPostgres() || isOracle() || isDb2()) {
|
||||
} else if (isPostgres() || isOracle() || isDb2() || isYugabyte()) {
|
||||
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||'-'||t0.code)");
|
||||
} else if (isHana()) {
|
||||
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, '-'||t0.code)");
|
||||
@@ -412,7 +412,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
|
||||
if (isH2()) {
|
||||
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo') in (?,?) order by t0.sku desc; --bind(def,Array[2]={2:1000-foo,3:1000-foo})");
|
||||
} else if (isPostgres() || isOracle() || isDb2()){
|
||||
} else if (isPostgres() || isOracle() || isDb2() || isYugabyte()){
|
||||
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||':'||t0.code||'-foo')");
|
||||
} else if (isHana()){
|
||||
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, ':'||t0.code||'-foo')");
|
||||
|
||||
+6
-14
@@ -10,14 +10,14 @@ import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestElementCollectionBasic extends BaseTestCase {
|
||||
class TestElementCollectionBasic extends BaseTestCase {
|
||||
|
||||
private List<String> eventLog() {
|
||||
return EcPersonPersistAdapter.eventLog();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertThen_UpdateWhenNotChanged_expect_noChanges() {
|
||||
void insertThen_UpdateWhenNotChanged_expect_noChanges() {
|
||||
|
||||
EcPerson person = new EcPerson("Nothing021");
|
||||
person.getPhoneNumbers().add("021 1234");
|
||||
@@ -51,9 +51,10 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
|
||||
eventLog();
|
||||
DB.find(EcPerson.class).where().eq("name", "Fiona021").delete();
|
||||
LoggedSql.start();
|
||||
|
||||
EcPerson person = new EcPerson("Fiona021");
|
||||
@@ -95,8 +96,8 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
List<String> phoneNumbers1 = found.get(1).getPhoneNumbers();
|
||||
phoneNumbers0.size();
|
||||
|
||||
assertThat(phoneNumbers0).containsExactly("021 1234", "021 4321");
|
||||
assertThat(phoneNumbers1).containsExactly("09 1234", "09 4321");
|
||||
assertThat(phoneNumbers0).containsExactlyInAnyOrder("021 1234", "021 4321");
|
||||
assertThat(phoneNumbers1).containsExactlyInAnyOrder("09 1234", "09 4321");
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(2);
|
||||
@@ -126,7 +127,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void updateBasic(EcPerson bean) {
|
||||
|
||||
bean.setName("Fiona021-mod-0");
|
||||
DB.save(bean);
|
||||
|
||||
@@ -140,7 +140,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void updateBasicInBatch(EcPerson bean) {
|
||||
|
||||
try (Transaction txn = DB.beginTransaction()) {
|
||||
txn.setBatchMode(true);
|
||||
bean.setName("Fiona021-mod-0-batch");
|
||||
@@ -158,7 +157,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void updateBoth(EcPerson bean) {
|
||||
|
||||
bean.setName("Fiona021-mod-both");
|
||||
bean.getPhoneNumbers().add("01-22123");
|
||||
DB.save(bean);
|
||||
@@ -187,7 +185,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void updateBothInBatch(EcPerson bean) {
|
||||
|
||||
try (Transaction txn = DB.beginTransaction()) {
|
||||
txn.setBatchMode(true);
|
||||
bean.setName("Fiona021-mod-both-batch");
|
||||
@@ -210,7 +207,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void updateNothing(EcPerson bean) {
|
||||
|
||||
DB.save(bean);
|
||||
|
||||
List<String> sql = LoggedSql.collect();
|
||||
@@ -222,7 +218,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void updateOnlyCollectionInBatch(EcPerson bean) {
|
||||
|
||||
try (Transaction txn = DB.beginTransaction()) {
|
||||
txn.setBatchMode(true);
|
||||
bean.getPhoneNumbers().add("01-4321");
|
||||
@@ -243,7 +238,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void updateOnlyCollection(EcPerson bean) {
|
||||
|
||||
bean.getPhoneNumbers().add("01-4321");
|
||||
DB.save(bean);
|
||||
|
||||
@@ -272,7 +266,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void delete(EcPerson bean) {
|
||||
|
||||
DB.delete(bean);
|
||||
|
||||
List<String> sql = LoggedSql.collect();
|
||||
@@ -284,7 +277,6 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void jsonToFrom(EcPerson foundFirst) {
|
||||
|
||||
String asJson = DB.json().toJson(foundFirst);
|
||||
EcPerson fromJson = DB.json().toBean(EcPerson.class, asJson);
|
||||
assertThat(fromJson.getPhoneNumbers()).containsAll(foundFirst.getPhoneNumbers());
|
||||
|
||||
+2
-2
@@ -52,8 +52,8 @@ class TestElementCollectionBasicSet extends BaseTestCase {
|
||||
Set<String> phoneNumbers1 = found.get(1).getPhoneNumbers();
|
||||
phoneNumbers0.size();
|
||||
|
||||
assertThat(phoneNumbers0).containsExactly("021 1234", "021 4321");
|
||||
assertThat(phoneNumbers1).containsExactly("09 1234", "09 4321", "09 9876");
|
||||
assertThat(phoneNumbers0).containsExactlyInAnyOrder("021 1234", "021 4321");
|
||||
assertThat(phoneNumbers1).containsExactlyInAnyOrder("09 1234", "09 4321", "09 9876");
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(2);
|
||||
|
||||
+12
-4
@@ -15,8 +15,8 @@ class TestElementCollectionEmbeddedListCache extends BaseTestCase {
|
||||
void test() {
|
||||
|
||||
EcblPerson person = new EcblPerson("CacheL");
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021","1234"));
|
||||
person.getPhoneNumbers().add(new EcPhone("64","021","4321"));
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021", "1234"));
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021", "4321"));
|
||||
DB.save(person);
|
||||
|
||||
EcblPerson one = DB.find(EcblPerson.class)
|
||||
@@ -42,7 +42,7 @@ class TestElementCollectionEmbeddedListCache extends BaseTestCase {
|
||||
assertThat(sql).isEmpty(); // cache hit
|
||||
|
||||
two.getPhoneNumbers().add(new EcPhone("61", "07", "11"));
|
||||
two.getPhoneNumbers().remove(1);
|
||||
removeByNumber(two.getPhoneNumbers(), "4321");
|
||||
|
||||
DB.save(two);
|
||||
|
||||
@@ -72,7 +72,7 @@ class TestElementCollectionEmbeddedListCache extends BaseTestCase {
|
||||
|
||||
|
||||
three.setName("mod-3");
|
||||
three.getPhoneNumbers().remove(0);
|
||||
removeByNumber(three.getPhoneNumbers(), "1234");
|
||||
|
||||
DB.save(three);
|
||||
|
||||
@@ -92,4 +92,12 @@ class TestElementCollectionEmbeddedListCache extends BaseTestCase {
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
|
||||
private void removeByNumber(List<EcPhone> phoneNumbers, String num) {
|
||||
phoneNumbers
|
||||
.stream()
|
||||
.filter(ecPhone1 -> ecPhone1.number.equals(num))
|
||||
.findFirst()
|
||||
.ifPresent(phoneNumbers::remove);
|
||||
}
|
||||
}
|
||||
+16
-12
@@ -3,7 +3,6 @@ package org.tests.model.elementcollection;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,8 +16,8 @@ class TestElementCollectionEmbeddedListCache2 extends BaseTestCase {
|
||||
|
||||
EcblPerson2 person = new EcblPerson2();
|
||||
person.setName("CacheL");
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021","1234"));
|
||||
person.getPhoneNumbers().add(new EcPhone("64","021","4321"));
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021", "1234"));
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021", "4321"));
|
||||
DB.save(person);
|
||||
|
||||
EcblPerson2 one = DB.find(EcblPerson2.class)
|
||||
@@ -33,7 +32,7 @@ class TestElementCollectionEmbeddedListCache2 extends BaseTestCase {
|
||||
List<String> sql = LoggedSql.collect();
|
||||
assertThat(sql).isEmpty();
|
||||
|
||||
EcblPerson2 two = DB.find(EcblPerson2.class )
|
||||
EcblPerson2 two = DB.find(EcblPerson2.class)
|
||||
.setId(person.getId())
|
||||
.findOne();
|
||||
|
||||
@@ -44,7 +43,7 @@ class TestElementCollectionEmbeddedListCache2 extends BaseTestCase {
|
||||
assertThat(sql).isEmpty(); // cache hit
|
||||
|
||||
two.getPhoneNumbers().add(new EcPhone("61", "07", "11"));
|
||||
two.getPhoneNumbers().remove(1);
|
||||
removeByNumber(two.getPhoneNumbers(), "4321");
|
||||
|
||||
DB.save(two);
|
||||
|
||||
@@ -62,38 +61,43 @@ class TestElementCollectionEmbeddedListCache2 extends BaseTestCase {
|
||||
assertSql(sql.get(2)).contains("insert into ecbl_person2_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
|
||||
}
|
||||
|
||||
EcblPerson2 three = DB.find(EcblPerson2.class )
|
||||
EcblPerson2 three = DB.find(EcblPerson2.class)
|
||||
.setId(person.getId())
|
||||
.findOne();
|
||||
|
||||
assertThat(three.getPhoneNumbers().toString()).contains("61-07-11", "64-021-1234");
|
||||
assertThat(three.getPhoneNumbers()).hasSize(2);
|
||||
assertThat(three.getPhoneNumbers().toString()).contains("61-07-11", "64-021-1234");
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).isEmpty(); // cache hit
|
||||
|
||||
|
||||
three.setName("mod-3");
|
||||
three.getPhoneNumbers().remove(0);
|
||||
removeByNumber(three.getPhoneNumbers(), "1234");
|
||||
|
||||
DB.save(three);
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(5);
|
||||
|
||||
EcblPerson2 four = DB.find(EcblPerson2.class )
|
||||
EcblPerson2 four = DB.find(EcblPerson2.class)
|
||||
.setId(person.getId())
|
||||
.findOne();
|
||||
|
||||
assertThat(four.getPhoneNumbers().toString()).contains("61-07-11");
|
||||
assertThat(four.getPhoneNumbers()).hasSize(1);
|
||||
|
||||
|
||||
DB.delete(four);
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(2);
|
||||
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
|
||||
private void removeByNumber(List<EcPhone> phoneNumbers, String num) {
|
||||
phoneNumbers
|
||||
.stream()
|
||||
.filter(ecPhone1 -> ecPhone1.number.equals(num))
|
||||
.findFirst()
|
||||
.ifPresent(phoneNumbers::remove);
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,14 @@ import org.tests.model.m2m.MnyB;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TestCommitAndContinue extends BaseTestCase {
|
||||
class TestCommitAndContinue extends BaseTestCase {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("org.avaje.ebean.TXN");
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@IgnorePlatform({Platform.SQLSERVER, Platform.HSQLDB, Platform.COCKROACH}) // they will dead lock
|
||||
public void transactional_partialSuccess() {
|
||||
void transactional_partialSuccess() {
|
||||
|
||||
MnyB a = new MnyB("a100");
|
||||
MnyB b = new MnyB("b200");
|
||||
@@ -57,8 +57,8 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
* The @Transactional is nicer to me.
|
||||
*/
|
||||
@Test
|
||||
@IgnorePlatform({Platform.SQLSERVER, Platform.HSQLDB, Platform.COCKROACH}) // they will dead lock
|
||||
public void tryFinally_partialSuccess() {
|
||||
@IgnorePlatform({Platform.SQLSERVER, Platform.HSQLDB, Platform.COCKROACH, Platform.YUGABYTE}) // they will dead lock
|
||||
void tryFinally_partialSuccess() {
|
||||
|
||||
MnyB a = new MnyB("a100");
|
||||
MnyB b = new MnyB("b200");
|
||||
@@ -69,7 +69,6 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
a.save();
|
||||
// commit at this point
|
||||
txn.commitAndContinue();
|
||||
|
||||
try {
|
||||
b.save();
|
||||
|
||||
@@ -102,7 +101,7 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
@Test
|
||||
@Transactional
|
||||
@IgnorePlatform({Platform.SQLSERVER, Platform.HSQLDB, Platform.COCKROACH}) // they will dead lock
|
||||
public void transactional_partialSuccess_secondTransactionInsert() {
|
||||
void transactional_partialSuccess_secondTransactionInsert() {
|
||||
|
||||
MnyB a = new MnyB("a100");
|
||||
MnyB b = new MnyB("b200");
|
||||
@@ -150,8 +149,7 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic() {
|
||||
|
||||
void basic() {
|
||||
MnyB a = new MnyB("a");
|
||||
MnyB b = new MnyB("b");
|
||||
MnyB c = new MnyB("c");
|
||||
@@ -176,7 +174,7 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void runTransactional() {
|
||||
void runTransactional() {
|
||||
|
||||
new MnyB("a100").save();
|
||||
new MnyB("a101").save();
|
||||
|
||||
@@ -4,54 +4,42 @@ import io.ebean.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Country;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Product;
|
||||
|
||||
public class TestNestedBeginRequiresNew extends BaseTestCase {
|
||||
class TestNestedBeginRequiresNew extends BaseTestCase {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(TestNestedBeginRequiresNew.class);
|
||||
|
||||
Database server = DB.getDefault();
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
void test() {
|
||||
someOuterMethod();
|
||||
}
|
||||
|
||||
private void someOuterMethod() {
|
||||
|
||||
Transaction txn = server.beginTransaction(TxScope.requiresNew());
|
||||
try {
|
||||
|
||||
server.find(Country.class).findCount();
|
||||
|
||||
someInnerMethod();
|
||||
|
||||
server.find(Product.class).findCount();
|
||||
|
||||
someInnerMethod();
|
||||
server.find(Address.class).findCount();
|
||||
txn.commit();
|
||||
|
||||
} finally {
|
||||
txn.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void someInnerMethod() {
|
||||
|
||||
logger.debug("someInnerMethod() ...");
|
||||
Transaction txn = server.beginTransaction(TxScope.requiresNew());
|
||||
try {
|
||||
|
||||
server.find(Customer.class).findCount();
|
||||
server.find(Country.class).findCount();
|
||||
txn.commit();
|
||||
|
||||
} finally {
|
||||
txn.end();
|
||||
}
|
||||
logger.debug("someInnerMethod() ... done");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestSqlUpdateUpsert extends BaseTestCase {
|
||||
|
||||
private static boolean useV1Syntax = Boolean.getBoolean("ebean.h2.useV1Syntax");
|
||||
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void h2Merge() throws InterruptedException {
|
||||
@@ -39,7 +41,11 @@ public class TestSqlUpdateUpsert extends BaseTestCase {
|
||||
.setParameter("online", false);
|
||||
|
||||
Object key2 = sqlUpdate2.executeGetKey();
|
||||
assertThat(key2).isEqualTo(key);
|
||||
if (useV1Syntax) {
|
||||
assertThat(key2).isNull();
|
||||
} else {
|
||||
assertThat(key2).isEqualTo(key);
|
||||
}
|
||||
|
||||
|
||||
EPersonOnline found2 = DB.find(EPersonOnline.class).where().eq("email", email).findOne();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[ {
|
||||
"name": "something",
|
||||
"other": null,
|
||||
"version": 1
|
||||
}, {
|
||||
"name": "other",
|
||||
"other": null,
|
||||
"version": 1
|
||||
} ]
|
||||
File renamed without changes.
@@ -5,7 +5,7 @@
|
||||
drop view order_agg_vw if exists;
|
||||
</ddl-script>
|
||||
|
||||
<ddl-script name="order views" platforms="db2,h2,postgres,oracle,mysql,mariadb,nuodb">
|
||||
<ddl-script name="order views" platforms="db2,h2,postgres,oracle,mysql,mariadb,nuodb,yugabyte">
|
||||
create or replace view order_agg_vw as
|
||||
select d.order_id, sum(d.order_qty * d.unit_price) as order_total,
|
||||
sum(d.ship_qty * d.unit_price) as ship_total
|
||||
|
||||
Reference in new issue
Block a user