Merge remote-tracking branch 'upstream/master' into issue-2774/encryption-support-for-in

This commit is contained in:
Roland Praml
2022-11-02 07:53:32 +01:00
794 changed files with 5256 additions and 4799 deletions
@@ -168,7 +168,7 @@ public abstract class BaseTestCase {
}
public boolean isPlatformCaseSensitive() {
return spiEbeanServer().databasePlatform().isCaseSensitiveCollation();
return spiEbeanServer().databasePlatform().caseSensitiveCollation();
}
public boolean isLimitOffset() {
@@ -248,7 +248,7 @@ public abstract class BaseTestCase {
}
public boolean isPlatformBooleanNative() {
return Types.BOOLEAN == spiEbeanServer().databasePlatform().getBooleanDbType();
return Types.BOOLEAN == spiEbeanServer().databasePlatform().booleanDbType();
}
public boolean isPlatformOrderNullsSupport() {
@@ -256,11 +256,11 @@ public abstract class BaseTestCase {
}
public boolean isPlatformSupportsDeleteTableAlias() {
return spiEbeanServer().databasePlatform().isSupportsDeleteTableAlias();
return spiEbeanServer().databasePlatform().supportsDeleteTableAlias();
}
public boolean isPersistBatchOnCascade() {
return spiEbeanServer().databasePlatform().getPersistBatchOnCascade() != PersistBatch.NONE;
return spiEbeanServer().databasePlatform().persistBatchOnCascade() != PersistBatch.NONE;
}
/**
@@ -279,11 +279,11 @@ public abstract class BaseTestCase {
}
protected Platform platform() {
return spiEbeanServer().databasePlatform().getPlatform().base();
return spiEbeanServer().databasePlatform().platform().base();
}
protected IdType idType() {
return spiEbeanServer().databasePlatform().getDbIdentity().getIdType();
return spiEbeanServer().databasePlatform().dbIdentity().getIdType();
}
protected SpiEbeanServer spiEbeanServer() {
@@ -54,37 +54,37 @@ public class ExtendedServerTest extends BaseTestCase {
@Test
public void mockClock() {
Database server = DB.getDefault();
Database database = DB.getDefault();
final Instant snapshot = Instant.now();
Instant backedSnapshot = snapshot.minus(1, ChronoUnit.DAYS);
Clock snapshotClock = Clock.fixed(backedSnapshot, Clock.systemUTC().getZone());
server.extended().setClock(snapshotClock);
database.extended().setClock(snapshotClock);
ResetBasicData.reset();
int count = server
int count = database
.find(Customer.class)
.where()
.gt("cretime", snapshot)
.findCount();
assertThat(count).isEqualTo(0);
int count2 = server
int count2 = database
.find(Customer.class)
.where()
.ge("cretime", backedSnapshot)
.findCount();
assertThat(count2).isGreaterThan(0);
int count3 = server
int count3 = database
.find(Customer.class)
.where()
.gt("updtime", snapshot)
.findCount();
assertThat(count3).isEqualTo(0);
int count4 = server
int count4 = database
.find(Customer.class)
.where()
.ge("updtime", backedSnapshot)
@@ -92,7 +92,7 @@ public class PlatformNoGeneratedKeysTest {
config.setName("h2_noGeneratedKeys");
OtherH2Platform platform = new OtherH2Platform();
DbIdentity dbIdentity = platform.getDbIdentity();
DbIdentity dbIdentity = platform.dbIdentity();
dbIdentity.setIdType(IdType.IDENTITY);
dbIdentity.setSupportsIdentity(true);
dbIdentity.setSupportsGetGeneratedKeys(false);
@@ -20,7 +20,7 @@ class DbTypeMapTest {
@Test
void testLookupRender_given_postgresPlatformType() {
PostgresPlatform pg = new PostgresPlatform();
DbPlatformTypeMapping dbTypeMap = pg.getDbTypeMap();
DbPlatformTypeMapping dbTypeMap = pg.dbTypeMap();
assertThat(dbTypeMap.lookup("clob", false).renderType(0, 0)).isEqualTo("text");
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("text");
@@ -36,7 +36,7 @@ class DbTypeMapTest {
@Test
void testLookupRender_given_mysql() {
DbPlatformTypeMapping dbTypeMap = new MySqlPlatform().getDbTypeMap();
DbPlatformTypeMapping dbTypeMap = new MySqlPlatform().dbTypeMap();
assertThat(dbTypeMap.lookup("clob", false).renderType(0, 0)).isEqualTo("longtext");
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("longtext");
@@ -52,7 +52,7 @@ class DbTypeMapTest {
@Test
void testLookupRender_given_sqlserver17() {
DbPlatformTypeMapping dbTypeMap = new SqlServer17Platform().getDbTypeMap();
DbPlatformTypeMapping dbTypeMap = new SqlServer17Platform().dbTypeMap();
assertThat(dbTypeMap.lookup("clob", false).renderType(0, 0)).isEqualTo("nvarchar(max)");
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("nvarchar(max)");
@@ -68,7 +68,7 @@ class DbTypeMapTest {
@Test
void testLookupRender_given_sqlserver16() {
DbPlatformTypeMapping dbTypeMap = new SqlServer16Platform().getDbTypeMap();
DbPlatformTypeMapping dbTypeMap = new SqlServer16Platform().dbTypeMap();
assertThat(dbTypeMap.lookup("clob", false).renderType(0, 0)).isEqualTo("text");
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("text");
@@ -84,7 +84,7 @@ class DbTypeMapTest {
@Test
void testLookupRender_given_oracle() {
DbPlatformTypeMapping dbTypeMap = new OraclePlatform().getDbTypeMap();
DbPlatformTypeMapping dbTypeMap = new OraclePlatform().dbTypeMap();
assertThat(dbTypeMap.lookup("clob", false).renderType(0, 0)).isEqualTo("clob");
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("clob");
@@ -100,7 +100,7 @@ class DbTypeMapTest {
@Test
void testLookupRender_given_h2() {
DbPlatformTypeMapping dbTypeMap = new H2Platform().getDbTypeMap();
DbPlatformTypeMapping dbTypeMap = new H2Platform().dbTypeMap();
assertThat(dbTypeMap.lookup("clob", false).renderType(0, 0)).isEqualTo("clob");
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("clob");
@@ -116,7 +116,7 @@ class DbTypeMapTest {
@Test
void testLookupRender_given_clickhouse() {
DbPlatformTypeMapping dbTypeMap = new ClickHousePlatform().getDbTypeMap();
DbPlatformTypeMapping dbTypeMap = new ClickHousePlatform().dbTypeMap();
assertThat(dbTypeMap.lookup("clob", false).renderType(0, 0)).isEqualTo("String");
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("String");
@@ -16,7 +16,7 @@ public class HanaPlatformTest {
HanaPlatform platform = new HanaPlatform();
platform.configure(new PlatformConfig());
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
DbPlatformType dbType = platform.dbTypeMap().get(DbPlatformType.UUID);
assertThat(dbType.renderType(0, 0)).isEqualTo("varchar(40)");
}
@@ -30,7 +30,7 @@ public class HanaPlatformTest {
platform.configure(config);
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
DbPlatformType dbType = platform.dbTypeMap().get(DbPlatformType.UUID);
assertThat(dbType.renderType(0, 0)).isEqualTo("varbinary(16)");
}
}
@@ -15,7 +15,7 @@ public class SqlserverPlatformTest {
public void uuid_default() {
platform.configure(new PlatformConfig());
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
DbPlatformType dbType = platform.dbTypeMap().get(DbPlatformType.UUID);
assertThat(dbType.renderType(0, 0)).isEqualTo("uniqueidentifier");
}
@@ -29,7 +29,7 @@ public class SqlserverPlatformTest {
platform.configure(config);
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
DbPlatformType dbType = platform.dbTypeMap().get(DbPlatformType.UUID);
assertThat(dbType.renderType(0, 0)).isEqualTo("binary(16)");
}
@@ -41,7 +41,7 @@ public class SqlserverPlatformTest {
platform.configure(config);
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
DbPlatformType dbType = platform.dbTypeMap().get(DbPlatformType.UUID);
assertThat(dbType.renderType(0, 0)).isEqualTo("nvarchar(40)");
}
}
@@ -14,6 +14,6 @@ public class SqlServer2016PlatformTest {
@Test
public void testHistorySupport() {
SqlServer17Platform platform = new SqlServer17Platform();
assertTrue(platform.getHistorySupport() instanceof SqlServerHistorySupport);
assertTrue(platform.historySupport() instanceof SqlServerHistorySupport);
}
}
@@ -201,7 +201,7 @@ public class DbMigrationTest extends BaseTestCase {
System.err.println("FIXME: Oracle history support seems to be broken");
return;
}
DbHistorySupport history = server().pluginApi().databasePlatform().getHistorySupport();
DbHistorySupport history = server().pluginApi().databasePlatform().historySupport();
if (history == null) {
return;
}
@@ -293,6 +293,7 @@ public class DbMigrationTest extends BaseTestCase {
table.setFrom("foo");
table.setTo("bar");
table.setIndex("id");
table.setTextfield("test");
tmpServer.save(table);
table = tmpServer.find(ETable.class).where().eq("index", "id").findOne();
assert table != null;
@@ -34,7 +34,7 @@ public class DocStoreBeanBaseAdapterTest extends BaseTestCase {
Assertions.assertThat(adapter.indexName()).isEqualTo("order");
Assertions.assertThat(adapter.indexType()).isEqualTo("order");
Assertions.assertThat(adapter.getQueueId()).isEqualTo("order");
Assertions.assertThat(adapter.queueId()).isEqualTo("order");
}
static class TDAdapter<T> extends DocStoreBeanBaseAdapter<T> {
@@ -51,7 +51,7 @@ public class DocStoreDeleteEventTest {
DocStoreUpdates updates = new DocStoreUpdates();
event.addToQueue(updates);
List<DocStoreQueueEntry> queueEntries = updates.getQueueEntries();
List<DocStoreQueueEntry> queueEntries = updates.queueEntries();
assertThat(queueEntries).hasSize(1);
DocStoreQueueEntry entry = queueEntries.get(0);
@@ -55,7 +55,7 @@ public class DocStoreIndexEventTest {
DocStoreUpdates updates = new DocStoreUpdates();
event.addToQueue(updates);
List<DocStoreQueueEntry> queueEntries = updates.getQueueEntries();
List<DocStoreQueueEntry> queueEntries = updates.queueEntries();
assertThat(queueEntries).hasSize(1);
DocStoreQueueEntry entry = queueEntries.get(0);
@@ -15,7 +15,6 @@ import io.ebean.meta.MetaInfoManager;
import io.ebean.meta.MetricVisitor;
import io.ebean.plugin.Property;
import io.ebean.plugin.SpiServer;
import io.ebean.text.csv.CsvReader;
import io.ebean.text.json.JsonContext;
import io.ebeaninternal.api.*;
import io.ebeaninternal.api.SpiQuery.Type;
@@ -356,10 +355,6 @@ public class TDSpiEbeanServer extends TDSpiServer implements SpiEbeanServer {
return null;
}
@Override
public <T> CsvReader<T> createCsvReader(Class<T> beanType) {
return null;
}
@Override
public <T> Query<T> createNamedQuery(Class<T> beanType, String namedQuery) {
@@ -13,7 +13,6 @@ import io.ebean.meta.MetaInfoManager;
import io.ebean.plugin.BeanType;
import io.ebean.plugin.Property;
import io.ebean.plugin.SpiServer;
import io.ebean.text.csv.CsvReader;
import io.ebean.text.json.JsonContext;
import javax.annotation.Nullable;
@@ -103,10 +102,6 @@ public class TDSpiServer implements SpiServer {
return null;
}
@Override
public <T> CsvReader<T> createCsvReader(Class<T> beanType) {
return null;
}
@Override
public <T> UpdateQuery<T> update(Class<T> beanType) {
@@ -30,7 +30,7 @@ public class TestFutureRowCountErrorHandling extends BaseTestCase {
FutureRowCount<Customer> futureRowCount = query.findFutureCount();
QueryFutureRowCount<Customer> internalRowCount = (QueryFutureRowCount<Customer>) futureRowCount;
Transaction t = internalRowCount.getTransaction();
Transaction t = internalRowCount.transaction();
try {
futureRowCount.get();
@@ -57,7 +57,7 @@ public class TestFutureRowCountErrorHandling extends BaseTestCase {
FutureIds<Customer> futureIds = query.findFutureIds();
QueryFutureIds<Customer> internalFuture = (QueryFutureIds<Customer>) futureIds;
Transaction t = internalFuture.getTransaction();
Transaction t = internalFuture.transaction();
try {
internalFuture.get();
@@ -85,7 +85,7 @@ public class TestFutureRowCountErrorHandling extends BaseTestCase {
FutureList<Customer> futureList = query.findFutureList();
QueryFutureList<Customer> internalFuture = (QueryFutureList<Customer>) futureList;
Transaction t = internalFuture.getTransaction();
Transaction t = internalFuture.transaction();
try {
internalFuture.get();
@@ -298,7 +298,7 @@ public class TestRawSqlBuilder extends BaseTestCase {
}
@Test
public void testBLobClosedConnection() throws Exception {
void testBLobClosedConnection() throws Exception {
final PersistentFileContent pfc = new PersistentFileContent();
final byte[] bytes = "This is the blob as String".getBytes(StandardCharsets.UTF_8);
pfc.setContent(bytes);
@@ -15,13 +15,11 @@ import org.tests.rawsql.ACustomer;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestRawSqlParsing extends BaseTestCase {
class TestRawSqlParsing extends BaseTestCase {
@Test
public void test() {
void test() {
String sql
= " select order_id, sum(order_qty*unit_price) as totalAmount"
+ " from o_order_detail "
@@ -35,13 +33,12 @@ public class TestRawSqlParsing extends BaseTestCase {
Sql rs = ((SpiRawSql)rawSql).getSql();
String s = rs.toString();
assertTrue(s.contains("[order_id, sum"));
assertThat(s).contains("select:order_id, sum");
}
@Test
@ForPlatform(Platform.POSTGRES)
public void testDoubleColon() {
void testDoubleColon() {
ResetBasicData.reset();
String sql = "select id, name from o_customer where name=:name and MD5(id::text) BETWEEN '00000000000000000000000000000000' AND 'ffffffffffffffffffffffffffffffff'";
@@ -59,8 +56,7 @@ public class TestRawSqlParsing extends BaseTestCase {
}
@Test
public void testWhere() {
void testWhere() {
ResetBasicData.reset();
RawSql sql = RawSqlBuilder.parse("SELECT id, name FROM o_customer ${where}").create();
@@ -75,8 +71,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testUnion() {
void testUnion() {
ResetBasicData.reset();
String sql =
@@ -100,10 +95,9 @@ public class TestRawSqlParsing extends BaseTestCase {
assertThat(sqlOf(query)).contains(") all_split limit 5 offset 1");
}
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testUnion_explicitWhere() {
void testUnion_explicitWhere() {
ResetBasicData.reset();
String sql =
@@ -135,7 +129,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testUnion_explicitAndhere() {
void testUnion_explicitAndhere() {
ResetBasicData.reset();
String sql =
@@ -167,8 +161,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testColumnName2() {
void testColumnName2() {
ResetBasicData.reset();
String sql = "select 42 custId, 'bar' customerName from o_customer";
@@ -189,8 +182,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testColumnAlias() {
void testColumnAlias() {
ResetBasicData.reset();
String sql = "select 43 custId, name as custName from o_customer";
@@ -211,8 +203,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testColumnNameMapping() {
void testColumnNameMapping() {
ResetBasicData.reset();
String sql = "select v.custId, v.customerName from (select id custId, name customerName from o_customer) v";
@@ -5,7 +5,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
import io.ebean.config.DatabaseConfig;
import io.ebean.platform.h2.H2Platform;
import io.ebeaninternal.server.core.bootup.BootupClasses;
import io.ebeaninternal.server.text.json.DJsonScalar;
import io.ebeaninternal.server.json.DJsonScalar;
import io.ebeaninternal.server.type.DefaultTypeManager;
import org.junit.jupiter.api.Test;
@@ -6,7 +6,7 @@ import io.ebean.DB;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.text.json.WriteJson;
import io.ebeaninternal.server.json.WriteJson;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
@@ -0,0 +1,76 @@
package io.ebean.xtest.platform;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.platform.cockroach.CockroachPlatform;
import io.ebean.platform.db2.DB2LuwPlatform;
import io.ebean.platform.h2.H2Platform;
import io.ebean.platform.hana.HanaPlatform;
import io.ebean.platform.mariadb.MariaDbPlatform;
import io.ebean.platform.mysql.MySql55Platform;
import io.ebean.platform.mysql.MySqlPlatform;
import io.ebean.platform.oracle.Oracle11Platform;
import io.ebean.platform.oracle.Oracle12Platform;
import io.ebean.platform.oracle.OraclePlatform;
import io.ebean.platform.postgres.Postgres9Platform;
import io.ebean.platform.postgres.PostgresPlatform;
import io.ebean.platform.sqlanywhere.SqlAnywherePlatform;
import io.ebean.platform.sqlite.SQLitePlatform;
import io.ebean.platform.sqlserver.SqlServer17Platform;
import io.ebean.platform.yugabyte.YugabytePlatform;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class PlatformLikeTest {
DatabasePlatform h2 = new H2Platform();
DatabasePlatform pg = new PostgresPlatform();
DatabasePlatform pg9 = new Postgres9Platform();
DatabasePlatform cockroach = new CockroachPlatform();
DatabasePlatform yugabyte = new YugabytePlatform();
DatabasePlatform mysql = new MySqlPlatform();
DatabasePlatform mysql55 = new MySql55Platform();
DatabasePlatform maria = new MariaDbPlatform();
DatabasePlatform sqlite = new SQLitePlatform();
DatabasePlatform sqlAnywhere = new SqlAnywherePlatform();
DatabasePlatform sqlServer17 = new SqlServer17Platform();
DatabasePlatform oracle = new OraclePlatform();
DatabasePlatform oracle11 = new Oracle11Platform();
DatabasePlatform oracle12 = new Oracle12Platform();
DatabasePlatform hana = new HanaPlatform();
DatabasePlatform db2Luw = new DB2LuwPlatform();
@Test
void rawLike_escapeEmpty() {
for (DatabasePlatform platform : List.of(h2, pg, pg9, yugabyte, cockroach, mysql, mysql55, maria)) {
assertThat(platform.likeClause(true)).isEqualTo("like ? escape''");
assertThat(platform.likeClause(false)).isEqualTo("like ? escape'|'");
}
}
@Test
void ansi_rawLike() {
for (DatabasePlatform platform : List.of(sqlite, sqlAnywhere, sqlServer17, oracle, oracle11, oracle12, hana, db2Luw)) {
assertThat(platform.likeClause(true)).isEqualTo("like ?");
}
}
@Test
void escapeLike_noEscape() {
for (DatabasePlatform platform : List.of(sqlite, sqlServer17)) {
assertThat(platform.likeClause(false)).isEqualTo("like ?");
}
}
@Test
void ansi_escapeLike() {
for (DatabasePlatform platform : List.of(sqlAnywhere, oracle, oracle11, oracle12, hana, db2Luw)) {
assertThat(platform.likeClause(false)).isEqualTo("like ? escape'|'");
}
}
}
@@ -5,11 +5,12 @@ import io.ebean.test.containers.MariaDBContainer;
public class StartMariaDb {
public static void main(String[] args) {
MariaDBContainer.builder("10.5")
MariaDBContainer.builder("10.6")
.dbName("unit")
.user("unit")
.password("unit")
.port(5306)
.build()
.startWithDropCreate();
.start();
}
}
@@ -3,6 +3,7 @@ package misc.migration.v1_0;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
import io.ebean.annotation.NotNull;
import javax.persistence.*;
import java.util.List;
@@ -36,6 +37,17 @@ public class ETable {
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
@NotNull
private String textfield;
public void setTextfield(String textfield) {
this.textfield = textfield;
}
public String getTextfield() {
return textfield;
}
public String getIndex() {
return index;
}
@@ -39,4 +39,9 @@ public class ETable {
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
private String textfield;
@Index
private String textfield2;
}
@@ -6,18 +6,19 @@ import io.ebean.core.type.ScalarType;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.TJodaEntity;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class TestJodaType extends BaseTestCase {
class TestJodaType extends BaseTestCase {
@Test
public void test() {
void test() {
SpiEbeanServer server = (SpiEbeanServer) DB.getDefault();
BeanDescriptor<TJodaEntity> beanDescriptor = server.descriptor(TJodaEntity.class);
BeanProperty beanProperty = beanDescriptor.beanProperty("localTime");
@@ -27,8 +28,7 @@ public class TestJodaType extends BaseTestCase {
}
@Test
public void test_insert_find() {
void test_insert_find() {
LocalTime now = new LocalTime().withMillisOfSecond(0);
TJodaEntity bean = new TJodaEntity();
@@ -40,4 +40,19 @@ public class TestJodaType extends BaseTestCase {
assertThat(foundBean.getLocalTime()).isEqualTo(bean.getLocalTime());
}
@Test
void toJson() {
LocalTime now = new LocalTime();
TJodaEntity bean = new TJodaEntity();
bean.setId(42);
bean.setLocalTime(now);
bean.setLocalDate(LocalDate.parse("2022-04-07"));
String json = DB.json().toJson(bean);
TJodaEntity bean1 = DB.json().toBean(TJodaEntity.class, json);
assertEquals(bean1.getLocalTime(), now);
assertEquals(bean1.getLocalDate(), LocalDate.parse("2022-04-07"));
}
}
@@ -136,7 +136,7 @@ public class TestEncrypt extends BaseTestCase {
assertEquals(EBasicEncrypt.Status.ONE, e2.getStatus());
SpiEbeanServer server = (SpiEbeanServer) DB.getDefault();
DbEncrypt dbEncrypt = server.databasePlatform().getDbEncrypt();
DbEncrypt dbEncrypt = server.databasePlatform().dbEncrypt();
if (dbEncrypt == null) {
// can not test the where clause
@@ -134,7 +134,7 @@ public class TestBatchInsertSimple extends BaseTestCase {
Transaction transaction = DB.beginTransaction();
try {
transaction.setBatchMode(true);
transaction.setBatchOnCascade(PersistBatch.ALL.equals(spiEbeanServer().databasePlatform().getPersistBatchOnCascade()));
transaction.setBatchOnCascade(PersistBatch.ALL.equals(spiEbeanServer().databasePlatform().persistBatchOnCascade()));
transaction.setBatchSize(20);
// escalate based on batchOnCascade value
@@ -90,7 +90,7 @@ public class TestBatchOnCascadeExceptionHandling extends BaseTestCase {
Transaction txn = server.beginTransaction();
try {
assertThat(txn.isBatchMode()).isFalse();
assertThat(txn.isBatchOnCascade()).isSameAs(PersistBatch.ALL.equals(spiEbeanServer().databasePlatform().getPersistBatchOnCascade()));
assertThat(txn.isBatchOnCascade()).isSameAs(PersistBatch.ALL.equals(spiEbeanServer().databasePlatform().persistBatchOnCascade()));
failingOperation.run();
Assertions.fail("PersistenceException expected");
@@ -15,19 +15,23 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestHistoryInsert extends BaseTestCase {
class TestHistoryInsert extends BaseTestCase {
private final Logger logger = LoggerFactory.getLogger(TestHistoryInsert.class);
private Timestamp currentDbSystemTime() {
return DB.sqlQuery("select current_timestamp(6)").mapToScalar(Timestamp.class).findOne();
}
/**
* Looks like we MUST use useLegacyDatetimeCode=false ... in order for
* the correct server timezone to be honored by the MariaDB JDBC driver.
*/
@Test
@ForPlatform({Platform.MARIADB})
public void mariadb_simple_history() {
void mariadb_simple_history() {
Timestamp t0 = new Timestamp(System.currentTimeMillis());
Timestamp t0 = currentDbSystemTime();
littleSleep(50);
User user = new User();
@@ -35,19 +39,19 @@ public class TestHistoryInsert extends BaseTestCase {
user.setEmail("one@email.com");
user.setPasswordHash("someHash");
DB.save(user);
Timestamp t1 = new Timestamp(System.currentTimeMillis());
Timestamp t1 = currentDbSystemTime();
littleSleep(100);
user.setName("NotJim");
user.save();
Timestamp t2 = new Timestamp(System.currentTimeMillis());
Timestamp t2 = currentDbSystemTime();
littleSleep(100);
user.setName("NotJimV2");
user.setEmail("two@email.com");
user.save();
littleSleep(50);
Timestamp t3 = new Timestamp(System.currentTimeMillis());
Timestamp t3 = currentDbSystemTime();
List<Version<User>> versions = DB.find(User.class).setId(user.getId()).findVersionsBetween(t0, t3);
assertThat(versions).hasSize(3);
@@ -73,7 +73,7 @@ public class TestGeneratedKeys extends BaseTestCase {
private long readSequenceValue(Transaction tx, String sequence) throws SQLException {
String sql;
switch (spiEbeanServer().databasePlatform().getPlatform().base()) {
switch (spiEbeanServer().databasePlatform().platform().base()) {
case H2 :
sql = "select currval('" + sequence + "')";
break;
@@ -92,7 +92,7 @@ public class TestGeneratedKeys extends BaseTestCase {
default :
throw new UnsupportedOperationException("reading sequence value from "
+ spiEbeanServer().databasePlatform().getPlatform()
+ spiEbeanServer().databasePlatform().platform()
+ " is not supported.");
}
@@ -1,16 +1,15 @@
package org.tests.insert;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.DuplicateKeyException;
import io.ebean.annotation.Transactional;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tests.model.draftable.Document;
import java.sql.SQLException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -92,14 +91,8 @@ public class TestInsertDuplicateKey extends BaseTestCase {
DB.getDefault().currentTransaction().flush();
} catch (DuplicateKeyException e) {
log.info("duplicate failed but just continue" + e.getMessage());
try {
// typically we would use transaction.commitAndContinue()
// ... this is a rollback and continue type scenario
// ... more sensible to use a second transaction that do this
DB.getDefault().currentTransaction().connection().rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
// rollback and continue using the transaction
DB.getDefault().currentTransaction().rollbackAndContinue();
}
Document doc0 = new Document();
@@ -42,13 +42,18 @@ public class EArrayBean {
List<BigDecimal> decimals;
@DbArray
List<Status> statuses;
List<Double> doubs;
@DbArray
List<Float> floats;
@DbArray(nullable = false)
List<Status> statuses = new ArrayList<>();
@DbArray
List<VarcharEnum> vcEnums = new ArrayList<>();
@DbArray
List<IntEnum> intEnums = new ArrayList<>();
@DbArray @NotNull
List<IntEnum> intEnums;
@DbArray
Set<Status> status2;
@@ -112,6 +117,22 @@ public class EArrayBean {
this.decimals = decimals;
}
public List<Double> getDoubs() {
return doubs;
}
public void setDoubs(List<Double> doubs) {
this.doubs = doubs;
}
public List<Float> getFloats() {
return floats;
}
public void setFloats(List<Float> floats) {
this.floats = floats;
}
public List<Status> getStatuses() {
return statuses;
}
@@ -28,6 +28,8 @@ class TestDbArray_basic extends BaseTestCase {
DB.find(EArrayBean.class).delete();
bean.setName("some stuff");
assertThat(bean.getStatuses()).as("DbArray is auto initialised").isNotNull();
assertThat(bean.getIntEnums()).as("DbArray is auto initialised").isNotNull();
assertThat(bean.getUids()).as("DbArray is auto initialised").isNotNull();
List<String> phNumbers = bean.getPhoneNumbers();
phNumbers.add("4321");
@@ -43,6 +45,8 @@ class TestDbArray_basic extends BaseTestCase {
bean.getOtherIds().add(96L);
bean.getOtherIds().add(97L);
bean.setDecimals(doubles);
bean.setDoubs(List.of(1.1d, 2.3d));
bean.setFloats(List.of(1.01f, 2.02f));
bean.setStatuses(new ArrayList<>());
bean.getStatuses().add(EArrayBean.Status.ONE);
bean.getStatuses().add(EArrayBean.Status.THREE);
@@ -60,6 +64,8 @@ class TestDbArray_basic extends BaseTestCase {
found = DB.find(EArrayBean.class, bean.getId());
assertThat(found.getPhoneNumbers()).containsExactly("4321", "9823");
assertThat(found.getDoubs()).hasSize(2);
assertThat(found.getFloats()).hasSize(2);
if (isPostgresCompatible()) {
Query<EArrayBean> query = DB.find(EArrayBean.class)
@@ -166,7 +172,26 @@ class TestDbArray_basic extends BaseTestCase {
bean.setOtherIds(null);
DB.save(bean);
DB.delete(bean);
EArrayBean found = DB.find(EArrayBean.class, bean.getId());
assertThat(found.getPhoneNumbers()).isNull();
assertThat(found.getStatuses()).isEmpty();
assertThat(found.getIntEnums()).isEmpty();
assertThat(found.getUids()).isEmpty();
found.setName("some nulls 2");
DB.save(found);
EArrayBean found2 = DB.find(EArrayBean.class)
.where()
.eq("id", bean.getId())
.isNull("phoneNumbers")
.findOne();
assertThat(found2).isNotNull();
assertThat(found2.getPhoneNumbers()).isNull();
DB.delete(found);
}
@Test
@@ -277,9 +302,12 @@ class TestDbArray_basic extends BaseTestCase {
List<String> phNumbers = bean.getPhoneNumbers();
phNumbers.add("4321");
phNumbers.add("9823");
List<BigDecimal> doubs = bean.getDecimals();
doubs.add(BigDecimal.valueOf(1.23));
doubs.add(BigDecimal.valueOf(4.56));
assertThat(bean.getDecimals()).isNull();
List<BigDecimal> decimals = new ArrayList<>();
decimals.add(BigDecimal.valueOf(1.23));
decimals.add(BigDecimal.valueOf(4.56));
bean.setDecimals(decimals);
DB.save(bean);
// Data is saved correctly
@@ -1,5 +1,6 @@
package org.tests.model.basic;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import javax.persistence.Entity;
@@ -12,6 +13,7 @@ public class TJodaEntity {
Integer id;
LocalTime localTime;
LocalDate localDate;
public Integer getId() {
return id;
@@ -29,4 +31,12 @@ public class TJodaEntity {
this.localTime = localTime;
}
public LocalDate getLocalDate() {
return localDate;
}
public TJodaEntity setLocalDate(LocalDate localDate) {
this.localDate = localDate;
return this;
}
}
@@ -92,6 +92,6 @@ public class TestElementCollectionBasicCache extends BaseTestCase {
@Override
public boolean isPersistBatchOnCascade() {
return ((SpiEbeanServer) DB.getDefault()).databasePlatform().getPersistBatchOnCascade() != PersistBatch.NONE;
return ((SpiEbeanServer) DB.getDefault()).databasePlatform().persistBatchOnCascade() != PersistBatch.NONE;
}
}
@@ -98,6 +98,6 @@ public class TestElementCollectionBasicMapCache extends BaseTestCase {
@Override
public boolean isPersistBatchOnCascade() {
return ((SpiEbeanServer) DB.getDefault()).databasePlatform().getPersistBatchOnCascade() != PersistBatch.NONE;
return ((SpiEbeanServer) DB.getDefault()).databasePlatform().persistBatchOnCascade() != PersistBatch.NONE;
}
}
@@ -4,7 +4,7 @@ import javax.persistence.Embeddable;
import java.util.Objects;
@Embeddable
public class UserInterestLiveKey {
public final class UserInterestLiveKey {
private long userId;
private long liveId;
@@ -14,13 +14,20 @@ public class UserInterestLiveKey {
this.liveId = liveId;
}
public long userId() {
return userId;
}
public long liveId() {
return liveId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserInterestLiveKey that = (UserInterestLiveKey) o;
return userId == that.userId &&
liveId == that.liveId;
return userId == that.userId && liveId == that.liveId;
}
@Override
@@ -70,11 +70,12 @@ public class TestQueryFindPagedList extends BaseTestCase {
.setMaxRows(3)
.findPagedList();
Future<Integer> rowCount = pagedList.getFutureCount();
pagedList.loadCount();
List<Order> orders = pagedList.getList();
// these are each getting the total row count
int totalRowCount = pagedList.getTotalCount();
Future<Integer> rowCount = pagedList.getFutureCount();
Integer totalRowCountWithTimeout = rowCount.get(30, TimeUnit.SECONDS);
Integer totalRowCountViaFuture = rowCount.get();
@@ -1,8 +1,8 @@
package org.tests.query;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.Query;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.*;
@@ -14,8 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestSubQuery extends BaseTestCase {
@Test
public void testId() {
void testId() {
ResetBasicData.reset();
List<Integer> productIds = new ArrayList<>();
@@ -26,7 +25,13 @@ public class TestSubQuery extends BaseTestCase {
Query<Order> sq = DB.find(Order.class).select("id").where()
.in("details.product.id", productIds).query();
DB.find(Order.class).where().in("id", sq).findList();
Query<Order> query = DB.find(Order.class).where().in("id", sq).query();
query.findList();
if (isPostgresCompatible()) {
assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.status, t0.order_date, t0.ship_date, t1.name, t0.cretime, t0.updtime, t0.kcustomer_id from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (t0.id) in (select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id and u1.id > 0 where u1.product_id = any(?))");
} else {
assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.status, t0.order_date, t0.ship_date, t1.name, t0.cretime, t0.updtime, t0.kcustomer_id from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (t0.id) in (select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id and u1.id > 0 where u1.product_id in (?,?,?))");
}
}
@Test
@@ -59,7 +59,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
*
* @author Roland Praml, FOCONIS AG
*/
public class SqlQueryCancelTest extends BaseTestCase {
class SqlQueryCancelTest extends BaseTestCase {
private final int timing = 20;
@@ -191,17 +191,13 @@ public class SqlQueryCancelTest extends BaseTestCase {
}
@Test
public void cancelOrmDtoDuringIterate() {
void cancelOrmDtoDuringIterate() {
DtoQuery<EBasicDto> query = DB.find(EBasic.class).select("id,status").asDto(EBasicDto.class);
QueryIterator<EBasicDto> iter = query.findIterate();
assertThat(iter.hasNext()).isTrue();
query.cancel();
if (isMariaDB()) {
assertThrows(PersistenceException.class, iter::next);
} else {
assertThat(iter.next()).isNotNull();
}
assertThat(iter.next()).isNotNull();
// We might have 100 entities in a buffer. So we must iterate through all.
assertThatThrownBy(() -> {
@@ -1,43 +0,0 @@
package org.tests.text.csv;
import io.ebean.DB;
import io.ebean.xtest.base.TransactionalTestCase;
import io.ebean.text.csv.CsvReader;
import io.ebean.util.IOUtils;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import java.io.Reader;
import java.net.URL;
import java.util.Locale;
public class TestCsvReader extends TransactionalTestCase {
@Test
public void test() throws Exception {
ResetBasicData.reset();
URL resource = TestCsvReaderWithCallback.class.getResource("/test1.csv");
try (Reader reader = IOUtils.newReader(resource.openStream())){
CsvReader<Customer> csvReader = DB.getDefault().createCsvReader(Customer.class);
csvReader.setPersistBatchSize(2);
csvReader.addIgnore();
// csvReader.addProperty("id");
csvReader.addProperty("status");
csvReader.addProperty("name");
csvReader.addDateTime("anniversary", "dd-MMM-yyyy", Locale.ENGLISH);
csvReader.addProperty("billingAddress.line1");
csvReader.addProperty("billingAddress.city");
csvReader.addProperty("billingAddress.country.code");
csvReader.process(reader);
}
}
}
@@ -1,59 +0,0 @@
package org.tests.text.csv;
import io.ebean.DB;
import io.ebean.xtest.base.TransactionalTestCase;
import io.ebean.text.csv.CsvReader;
import io.ebean.text.csv.DefaultCsvCallback;
import io.ebean.util.IOUtils;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import java.io.Reader;
import java.net.URL;
import java.util.Locale;
import static org.assertj.core.api.Assertions.assertThat;
public class TestCsvReaderWithCallback extends TransactionalTestCase {
@Test
public void test() throws Throwable {
URL resource = TestCsvReaderWithCallback.class.getResource("/test1.csv");
try (Reader reader = IOUtils.newReader(resource.openStream())) {
CsvReader<Customer> csvReader = DB.getDefault().createCsvReader(Customer.class);
csvReader.setPersistBatchSize(2);
csvReader.setLogInfoFrequency(3);
csvReader.addIgnore();
// csvReader.addProperty("id");
csvReader.addProperty("status");
csvReader.addProperty("name");
csvReader.addDateTime("anniversary", "dd-MMM-yyyy", Locale.ENGLISH);
csvReader.addProperty("billingAddress.line1");
csvReader.addProperty("billingAddress.city");
// processor.addReference("billingAddress.country.code");
csvReader.addProperty("billingAddress.country.code");
int before = DB.find(Customer.class).findCount();
csvReader.process(reader, new DefaultCsvCallback<Customer>() {
@Override
public void processBean(int row, String[] lineContent, Customer cust) {
server.save(cust.getBillingAddress(), transaction);
server.save(cust, transaction);
}
});
int after = DB.find(Customer.class).findCount();
assertThat(after).isEqualTo(before + 9);
}
}
}
@@ -1,38 +0,0 @@
package org.tests.text.csv;
import io.ebean.xtest.BaseTestCase;
import io.ebean.text.TimeStringParser;
import org.junit.jupiter.api.Test;
import java.sql.Time;
import static org.junit.jupiter.api.Assertions.*;
public class TestTimeStringParser extends BaseTestCase {
@Test
public void testSimple() {
Time t = (Time) TimeStringParser.get().parse("12:00");
assertNotNull(t);
t = (Time) TimeStringParser.get().parse("12:00:12");
assertNotNull(t);
expectError("12");
expectError("12:");
expectError("12:00:");
expectError("12:00::");
expectError("12:00:00:");
}
private void expectError(String value) {
try {
TimeStringParser.get().parse(value);
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
}
@@ -7,7 +7,7 @@ import io.ebean.xtest.BaseTestCase;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.json.SpiJsonReader;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.text.json.ReadJson;
import io.ebeaninternal.server.json.ReadJson;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -1,12 +1,17 @@
package org.tests.transaction;
import io.ebean.*;
import io.ebean.test.LoggedSql;
import io.ebean.xtest.BaseTestCase;
import io.ebean.xtest.IgnorePlatform;
import io.ebean.annotation.Platform;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.api.TransactionEvent;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.EBasic;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -60,6 +65,34 @@ public class TestNestedSubTransaction extends BaseTestCase {
}
}
@IgnorePlatform({Platform.SQLSERVER, Platform.MYSQL, Platform.HANA, Platform.ORACLE})
@Test
void nestedNested() {
LoggedSql.start();
try (Transaction txn0 = DB.beginTransaction()) {
runNestedMethod();
try (Transaction txnAfter = DB.beginTransaction()) {
DB.save(new EBasic("startAfter"));
}
}
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("insert into e_basic").contains("sp[");
assertThat(sql.get(1)).contains("insert into e_basic").doesNotContain("sp[");
assertThat(sql.get(2)).contains("insert into e_basic").doesNotContain("sp[");
}
void runNestedMethod() {
try (Transaction txn0 = DB.beginTransaction()) {
txn0.setNestedUseSavepoint();
try (Transaction nested = DB.beginTransaction()) {
DB.save(new EBasic("nested in sp"));
nested.commit();
}
DB.save(new EBasic("nested"));
txn0.commit();
}
}
@IgnorePlatform({Platform.SQLSERVER, Platform.MYSQL, Platform.HANA, Platform.ORACLE})
@Test
@@ -75,10 +108,15 @@ public class TestNestedSubTransaction extends BaseTestCase {
server.save(bean);
TransactionEvent event0 = ((SpiTransaction) txn0).getEvent();
try (Transaction txn1 = server.beginTransaction()) {
bean.setName("updateNested");
server.save(bean);
TransactionEvent event1 = ((SpiTransaction) txn1).getEvent();
assertThat(event1).isNotSameAs(event0);
try (Transaction txn2 = server.beginTransaction()) {
bean.setName("barney");
DB.save(bean);
@@ -9,7 +9,7 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestSqlUpdateExceptions extends BaseTestCase {
class TestSqlUpdateExceptions extends BaseTestCase {
private String sql = "insert into uuone (id, name, version) values (?,?,?)";
@@ -63,7 +63,7 @@ public class TestSqlUpdateExceptions extends BaseTestCase {
}
@Test
public void duplicateKey_inBatch() {
void duplicateKey_inBatch() {
UUID id = UUID.randomUUID();
assertThrows(DuplicateKeyException.class, () -> {
try (Transaction transaction = DB.beginTransaction()) {
@@ -85,7 +85,7 @@ public class TestSqlUpdateExceptions extends BaseTestCase {
}
@Test
public void duplicateKey_executeBatch() {
void duplicateKey_executeBatch() {
UUID id = UUID.randomUUID();
assertThrows(DuplicateKeyException.class, () -> {
try (Transaction transaction = DB.beginTransaction()) {