mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-09-20 11:17:36 +00:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b627a3cef | ||
|
|
0af43db678 | ||
|
|
100d53fded | ||
|
|
f8964707d9 | ||
|
|
86c7de2de8 | ||
|
|
53b4d94933 | ||
|
|
b0ec23e53c | ||
|
|
20caae532c | ||
|
|
4369481c1a | ||
|
|
c94426b6b4 | ||
|
|
b2ff32e88c | ||
|
|
3bd8dfa7bf |
@@ -56,7 +56,7 @@ Work at the highest level of abstraction and drop down levels as needed.
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://www.foconis.de/" target="_blank">
|
||||
<img width="222px" src="https://www.foconis.de/templates/yootheme/cache/foconis_logo_322-709da1de.png">
|
||||
<img width="222px" src="https://group.foconis.com/download/ci/logo/png-72dpi/logo-quer/foconis-analytics-quer.png">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.stream.Stream;
|
||||
* @param <SELF> The type of the builder
|
||||
* @param <T> The entity bean type
|
||||
*/
|
||||
//public interface QueryBuilder<SELF extends QueryBuilder<SELF, T>, T> extends QueryBuilderProjection<SELF, T> {
|
||||
public interface QueryBuilder<SELF, T> extends QueryBuilderProjection<SELF, T> {
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,15 @@ public interface QueryBuilder<SELF, T> extends QueryBuilderProjection<SELF, T> {
|
||||
*/
|
||||
SELF alias(String alias);
|
||||
|
||||
/**
|
||||
* Apply changes to the query using a function.
|
||||
* <p>
|
||||
* This can be used to apply generic features to queries.
|
||||
*
|
||||
* @param apply The changes to apply to the query
|
||||
*/
|
||||
SELF also(Consumer<QueryBuilder<?, ?>> apply);
|
||||
|
||||
/**
|
||||
* Apply changes to the query conditional on the supplied predicate.
|
||||
* <p>
|
||||
|
||||
@@ -6,6 +6,7 @@ package io.ebean;
|
||||
* @param <SELF> The builder type
|
||||
* @param <T> The entity bean type
|
||||
*/
|
||||
//public interface QueryBuilderProjection<SELF extends QueryBuilderProjection<SELF, T>, T> {
|
||||
public interface QueryBuilderProjection<SELF, T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,30 +2,7 @@ package io.ebeaninternal.server.query;
|
||||
|
||||
import io.avaje.lang.NonNullApi;
|
||||
import io.avaje.lang.Nullable;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.CountDistinctOrder;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DtoQuery;
|
||||
import io.ebean.Expression;
|
||||
import io.ebean.ExpressionFactory;
|
||||
import io.ebean.ExpressionList;
|
||||
import io.ebean.FetchConfig;
|
||||
import io.ebean.FetchGroup;
|
||||
import io.ebean.FetchPath;
|
||||
import io.ebean.FutureIds;
|
||||
import io.ebean.FutureList;
|
||||
import io.ebean.FutureRowCount;
|
||||
import io.ebean.OrderBy;
|
||||
import io.ebean.PagedList;
|
||||
import io.ebean.PersistenceContextScope;
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.QueryIterator;
|
||||
import io.ebean.QueryType;
|
||||
import io.ebean.RawSql;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.UpdateQuery;
|
||||
import io.ebean.Version;
|
||||
import io.ebean.*;
|
||||
import io.ebean.service.SpiFetchGroupQuery;
|
||||
import io.ebeaninternal.api.SpiQueryFetch;
|
||||
import io.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
@@ -230,6 +207,11 @@ final class DefaultFetchGroupQuery<T> implements SpiFetchGroupQuery<T>, SpiQuery
|
||||
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> also(Consumer<QueryBuilder<?, ?>> apply) {
|
||||
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> alsoIf(BooleanSupplier predicate, Consumer<Query<T>> apply) {
|
||||
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
|
||||
|
||||
@@ -293,6 +293,12 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> also(Consumer<QueryBuilder<?, ?>> apply) {
|
||||
apply.accept(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> alsoIf(BooleanSupplier predicate, Consumer<Query<T>> consumer) {
|
||||
if (predicate.getAsBoolean()) {
|
||||
@@ -1367,7 +1373,9 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
|
||||
@Override
|
||||
public final Query<T> select(FetchGroup<T> fetchGroup) {
|
||||
this.detail = ((SpiFetchGroup<T>) fetchGroup).detail();
|
||||
if (fetchGroup != null) {
|
||||
this.detail = ((SpiFetchGroup<T>) fetchGroup).detail();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
ebean:
|
||||
dbSchema: mygisapp
|
||||
dbSchema: mynetgisapp
|
||||
geometrySRID: 4674
|
||||
|
||||
test:
|
||||
# useDocker: false
|
||||
# shutdown: stop # stop | remove
|
||||
platform: netpostgis
|
||||
platform: postgis
|
||||
ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
|
||||
dbName: mygisapp
|
||||
dbName: mynetgisapp
|
||||
|
||||
postgis:
|
||||
containerName: ebeanbuild_postgis
|
||||
port: 9432
|
||||
containerName: ebeanbuild_postgis2
|
||||
port: 9433
|
||||
image: ghcr.io/baosystems/postgis:15
|
||||
# extensions: postgis
|
||||
# url: jdbc:postgresql_lwgis://localhost:6432/mygisapp
|
||||
|
||||
@@ -44,6 +44,7 @@ import java.util.Collection;
|
||||
* @param <T> the entity bean type (normal entity bean type e.g. Customer)
|
||||
* @param <R> the specific query bean type (e.g. QCustomer)
|
||||
*/
|
||||
//public interface IQueryBean<T, R extends IQueryBean<T, R>> extends QueryBuilder<R, T> {
|
||||
public interface IQueryBean<T, R> extends QueryBuilder<R, T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,6 +57,7 @@ import java.util.stream.Stream;
|
||||
* @param <R> the specific root query bean type (e.g. QCustomer)
|
||||
*/
|
||||
@NonNullApi
|
||||
//public abstract class QueryBean<T, R extends QueryBean<T, R>> implements IQueryBean<T, R> {
|
||||
public abstract class QueryBean<T, R> implements IQueryBean<T, R> {
|
||||
|
||||
/**
|
||||
@@ -275,6 +276,13 @@ public abstract class QueryBean<T, R> implements IQueryBean<T, R> {
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public R also(Consumer<QueryBuilder<?, ?>> apply) {
|
||||
apply.accept(this);
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final R alsoIf(BooleanSupplier predicate, Consumer<R> apply) {
|
||||
if (predicate.getAsBoolean()) {
|
||||
|
||||
@@ -142,6 +142,22 @@ class QOrderTest {
|
||||
.findList();
|
||||
}
|
||||
|
||||
@Test
|
||||
void viaNullFetchGraph() {
|
||||
DB.getDefault();
|
||||
LoggedSql.start();
|
||||
|
||||
FetchGroup<Order> fg = null;
|
||||
new QOrder()
|
||||
.select(fg)
|
||||
.status.eq(Order.Status.NEW)
|
||||
.findList();
|
||||
|
||||
final List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("select /* QOrderTest.viaNullFetchGraph */ t0.id, ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void viaFetchGraph() {
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package org.querytest;
|
||||
|
||||
import io.ebean.QueryBuilder;
|
||||
import org.example.domain.Customer;
|
||||
import org.example.domain.query.QCustomer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.example.domain.query.QCustomer.Alias.name;
|
||||
|
||||
@@ -11,6 +14,32 @@ class QueryAlsoIfTest {
|
||||
|
||||
int dummy = 1;
|
||||
|
||||
@Test
|
||||
void also() {
|
||||
var myPager = new MyPager(10);
|
||||
var q = new QCustomer()
|
||||
.select(name)
|
||||
.also(myPager)
|
||||
.query();
|
||||
|
||||
q.findList();
|
||||
assertThat(q.getGeneratedSql()).contains("select /* QueryAlsoIfTest.also */ t0.id, t0.name from be_customer t0 limit 10");
|
||||
}
|
||||
|
||||
static class MyPager implements Consumer<QueryBuilder<?,?>> {
|
||||
|
||||
final int maxRows;
|
||||
|
||||
MyPager(int maxRows) {
|
||||
this.maxRows = maxRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(QueryBuilder<?, ?> queryBuilder) {
|
||||
queryBuilder.setMaxRows(maxRows);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
var q = new QCustomer()
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package io.ebean.test.config.platform;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* A variation of Postgres that expected Postgis extension support.
|
||||
*
|
||||
* Uses postgis/postgis image by default.
|
||||
*/
|
||||
class NetPostgisSetup implements PlatformSetup {
|
||||
|
||||
@Override
|
||||
public Properties setup(Config config) {
|
||||
int defaultPort = config.isUseDocker() ? 7432 : 5432;
|
||||
config.setDockerPlatform("postgis");
|
||||
config.ddlMode("dropCreate");
|
||||
config.setDefaultPort(defaultPort);
|
||||
config.setUsernameDefault();
|
||||
config.setPasswordDefault();
|
||||
config.setDriver("net.postgis.jdbc.DriverWrapperLW");
|
||||
config.setUrl("jdbc:postgresql_lwgis://${host}:${port}/${databaseName}");
|
||||
|
||||
String schema = config.getSchema();
|
||||
if (schema != null && !schema.equals(config.getUsername())) {
|
||||
config.urlAppend("?currentSchema=" + schema);
|
||||
}
|
||||
config.datasourceDefaults();
|
||||
return dockerProperties(config);
|
||||
}
|
||||
|
||||
private Properties dockerProperties(Config config) {
|
||||
if (!config.isUseDocker()) {
|
||||
return new Properties();
|
||||
}
|
||||
config.setExtensions("hstore,pgcrypto,postgis");
|
||||
config.setDockerContainerName("ut_postgis");
|
||||
config.setDockerVersion("14-3.2");
|
||||
return config.getDockerProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupExtraDbDataSource(Config config) {
|
||||
int defaultPort = config.isUseDocker() ? 7432 : 5432;
|
||||
config.setDefaultPort(defaultPort);
|
||||
config.setExtraUsernameDefault();
|
||||
config.setExtraDbPasswordDefault();
|
||||
config.setExtraUrl("jdbc:postgresql_lwgis://${host}:${port}/${databaseName}");
|
||||
config.extraDatasourceDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,6 @@ public class PlatformAutoConfig {
|
||||
KNOWN_PLATFORMS.put("sqlite", new SqliteSetup());
|
||||
KNOWN_PLATFORMS.put("postgres", new PostgresSetup());
|
||||
KNOWN_PLATFORMS.put("postgis", new PostgisSetup());
|
||||
KNOWN_PLATFORMS.put("netpostgis", new NetPostgisSetup());
|
||||
KNOWN_PLATFORMS.put("nuodb", new NuoDBSetup());
|
||||
KNOWN_PLATFORMS.put("mysql", new MySqlSetup());
|
||||
KNOWN_PLATFORMS.put("mariadb", new MariaDBSetup());
|
||||
|
||||
@@ -9,6 +9,9 @@ import java.util.Properties;
|
||||
*/
|
||||
class PostgisSetup implements PlatformSetup {
|
||||
|
||||
private static final String NET_POSTGIS_DRIVER = "net.postgis.jdbc.DriverWrapperLW";
|
||||
private static final String ORG_POSTGIS_DRIVER = "org.postgis.DriverWrapperLW";
|
||||
|
||||
@Override
|
||||
public Properties setup(Config config) {
|
||||
int defaultPort = config.isUseDocker() ? 7432 : 5432;
|
||||
@@ -17,9 +20,8 @@ class PostgisSetup implements PlatformSetup {
|
||||
config.setDefaultPort(defaultPort);
|
||||
config.setUsernameDefault();
|
||||
config.setPasswordDefault();
|
||||
config.setDriver("org.postgis.DriverWrapperLW");
|
||||
config.setDriver(driver(config));
|
||||
config.setUrl("jdbc:postgresql_lwgis://${host}:${port}/${databaseName}");
|
||||
|
||||
String schema = config.getSchema();
|
||||
if (schema != null && !schema.equals(config.getUsername())) {
|
||||
config.urlAppend("?currentSchema=" + schema);
|
||||
@@ -28,6 +30,19 @@ class PostgisSetup implements PlatformSetup {
|
||||
return dockerProperties(config);
|
||||
}
|
||||
|
||||
private String driver(Config config) {
|
||||
String driver = config.getPlatformKey("driver", "");
|
||||
if (!driver.isEmpty()) {
|
||||
return driver;
|
||||
}
|
||||
try {
|
||||
Class.forName(NET_POSTGIS_DRIVER);
|
||||
return NET_POSTGIS_DRIVER;
|
||||
} catch (ClassNotFoundException e){
|
||||
return ORG_POSTGIS_DRIVER;
|
||||
}
|
||||
}
|
||||
|
||||
private Properties dockerProperties(Config config) {
|
||||
if (!config.isUseDocker()) {
|
||||
return new Properties();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.test.LoggedSql;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.FutureIds;
|
||||
@@ -28,8 +29,13 @@ public class TestFetchId extends BaseTestCase {
|
||||
.gt("details.id", 0)
|
||||
.query();
|
||||
|
||||
LoggedSql.start();
|
||||
List<Object> ids = query.findIds();
|
||||
assertThat(ids).isNotEmpty();
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).doesNotContain("order by");
|
||||
assertThat(sql.get(0)).doesNotContain("join o_order_detail t1");
|
||||
|
||||
FutureIds<Order> futureIds = query.findFutureIds();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.ebean.BeanState;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Optional;
|
||||
@@ -16,7 +17,7 @@ public class TestTransient extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testTransient() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Customer cnew = new Customer();
|
||||
cnew.setName("testTrans");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.batchload;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
@@ -13,11 +14,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestBasicNavOnEmpty extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer c = new Customer();
|
||||
c.setName("HelloRob");
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.ebean.DB;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
@@ -18,6 +19,11 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TestBeanState extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalid() {
|
||||
assertThrows(IllegalArgumentException.class, () -> DB.beanState(new Object()));
|
||||
@@ -25,7 +31,6 @@ class TestBeanState extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
void loadErrors_when_empty() {
|
||||
ResetBasicData.reset();
|
||||
Customer one = DB.find(Customer.class).setMaxRows(1).findOne();
|
||||
BeanState beanState = DB.beanState(one);
|
||||
|
||||
@@ -34,8 +39,6 @@ class TestBeanState extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = DB.find(Customer.class).findList();
|
||||
|
||||
Customer customer = DB.find(Customer.class).setId(custs.get(0).getId()).select("name")
|
||||
@@ -69,8 +72,6 @@ class TestBeanState extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
void setDisableLazyLoad_expect_lazyLoadingDisabled() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = DB.find(Customer.class).order("id").findList();
|
||||
|
||||
Customer customer = DB.find(Customer.class)
|
||||
@@ -86,7 +87,6 @@ class TestBeanState extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
void changedProps_when_setManyProperty() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer customer = DB.find(Customer.class).order("id").setMaxRows(1).findOne();
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ package org.tests.batchload;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.xtest.base.TransactionalTestCase;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -230,5 +230,6 @@ public class TestQueryJoinToAssocOne extends BaseTestCase {
|
||||
String originQuery = trimSql(loggedSql.get(0), 5);
|
||||
assertThat(originQuery).contains("select t0.id, t0.status, t0.ship_date, t1.id, t1.order_qty, t1.unit_price");
|
||||
assertThat(originQuery).contains(" from o_order t0 left join o_order_detail t1 ");
|
||||
assertThat(originQuery).contains(" order by t0.id, t1.id asc, t1.order_qty asc, t1.cretime desc;");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.batchload;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
@@ -11,11 +12,13 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class TestSecondQueryNoRows extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer cnew = new Customer();
|
||||
cnew.setName("testSecQueryNoRows");
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@ package org.tests.cache;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
@@ -18,6 +20,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class TestBeanCacheContactLazyLoad extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test shows a wrong behaviour of the bean cache up to at least Ebean 12.4.*:
|
||||
* <ul>
|
||||
|
||||
-1
@@ -15,7 +15,6 @@ public class TestCacheInterceptSaveWhenLazyLoaded extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer customer = new Customer();
|
||||
|
||||
+6
-4
@@ -4,6 +4,7 @@ import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Contact;
|
||||
@@ -18,11 +19,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindCountOnDependent() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
ServerCache customerCache = DB.cacheManager().queryCache(Customer.class);
|
||||
customerCache.clear();
|
||||
|
||||
@@ -95,8 +99,6 @@ public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
@Test
|
||||
public void testFindCountOnOtherL2Cached() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer fi = DB.find(Customer.class).where().eq("name", "Fiona").findOne();
|
||||
|
||||
int custCount0 = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
|
||||
@@ -185,7 +185,7 @@ public class TestOrderedList extends BaseTestCase {
|
||||
DB.save(masterDb);
|
||||
|
||||
masterDb = DB.find(OmCacheOrderedMaster.class, master.getId());
|
||||
assertThat(masterDb.getDetails()).containsExactly(detail3, detail1);
|
||||
assertThat(masterDb.getDetails()).containsExactlyInAnyOrder(detail3, detail1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.tests.docstore;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.text.json.JsonReadOptions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Product;
|
||||
@@ -16,19 +17,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class CustomerReportTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testToJson() throws Exception {
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testToJson() {
|
||||
String json = server().json().toJson(getCustomerReport());
|
||||
assertThat(json).isEqualTo("{\"dtype\":\"CR\",\"friends\":[{\"id\":2},{\"id\":3}],\"customer\":{\"id\":1}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromJson() throws Exception {
|
||||
ResetBasicData.reset();
|
||||
public void testFromJson() {
|
||||
String json = "{\"dtype\":\"CR\",\"friends\":[{\"id\":2},{\"id\":3}],\"customer\":{\"id\":1}}";
|
||||
|
||||
JsonReadOptions opts = new JsonReadOptions();
|
||||
@@ -43,9 +44,7 @@ public class CustomerReportTest extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testEmbeddedDocs() throws Exception {
|
||||
ResetBasicData.reset();
|
||||
|
||||
public void testEmbeddedDocs() {
|
||||
CustomerReport report = getCustomerReport();
|
||||
report.getEmbeddedReports().add(getProductReport());
|
||||
|
||||
|
||||
@@ -14,10 +14,9 @@ public class ResetBasicData {
|
||||
|
||||
private static boolean runOnce;
|
||||
|
||||
private static Database server = DB.getDefault();
|
||||
private static final Database server = DB.getDefault();
|
||||
|
||||
public static synchronized void reset() {
|
||||
|
||||
if (runOnce) {
|
||||
int cnt1 = server.find(Customer.class).findCount();
|
||||
int cnt2 = server.find(Order.class).findCount();
|
||||
@@ -25,18 +24,9 @@ public class ResetBasicData {
|
||||
int cnt4 = server.find(Product.class).findCount();
|
||||
if (cnt1 == 4 && cnt2 == 5 && cnt3 == 2 && cnt4 == 4) {
|
||||
// OK, test data not modified
|
||||
outputCustomerIds();
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Customers:");
|
||||
server.find(Customer.class).findEach(c -> sb.append(' ').append(c.getId()));
|
||||
sb.append(", Orders:");
|
||||
server.find(Order.class).findEach(c -> sb.append(' ').append(c.getId()));
|
||||
sb.append(", Countries:");
|
||||
server.find(Country.class).findEach(c -> sb.append(' ').append(c.getCode()));
|
||||
sb.append(", Products:");
|
||||
server.find(Product.class).findEach(c -> sb.append(' ').append(c.getId()));
|
||||
System.err.println("WARNING: basic test data was modified. Current content:");
|
||||
System.err.println(sb.toString());
|
||||
outputState();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -55,9 +45,28 @@ public class ResetBasicData {
|
||||
me.insertProducts();
|
||||
me.insertTestCustAndOrders();
|
||||
});
|
||||
outputState();
|
||||
runOnce = true;
|
||||
}
|
||||
|
||||
private static void outputState() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("CustomerIds:");
|
||||
server.find(Customer.class).findEach(c -> sb.append(' ').append(c.getId()));
|
||||
sb.append(", Orders:");
|
||||
server.find(Order.class).findEach(c -> sb.append(' ').append(c.getId()));
|
||||
sb.append(", Countries:");
|
||||
server.find(Country.class).findEach(c -> sb.append(' ').append(c.getCode()));
|
||||
sb.append(", Products:");
|
||||
server.find(Product.class).findEach(c -> sb.append(' ').append(c.getId()));
|
||||
System.err.println("WARNING: basic test data was modified. Current content:");
|
||||
System.err.println(sb);
|
||||
}
|
||||
|
||||
private static void outputCustomerIds() {
|
||||
List<Object> ids = server.find(Customer.class).findIds();
|
||||
System.err.println("CustomerIds:" + ids);
|
||||
}
|
||||
|
||||
private void insertCountries() {
|
||||
Country c = new Country();
|
||||
|
||||
@@ -181,5 +181,6 @@ public class TestManyWhereJoin extends BaseTestCase {
|
||||
|
||||
// additional join for fetching the many details
|
||||
assertThat(sql).contains(" left join o_order_detail t1 on t1.order_id = t0.id");
|
||||
assertThat(sql).contains("order by t0.cretime, t0.id, t1.id asc, t1.order_qty asc, t1.cretime desc");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,49 @@ package org.tests.query;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.QueryBuilder;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestQueryAlsoIf {
|
||||
class TestQueryAlsoIf extends BaseTestCase {
|
||||
|
||||
int dummy = 1;
|
||||
|
||||
@Test
|
||||
void also() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
MyPager myPager = new MyPager(10);
|
||||
Query<Customer> query = DB.find(Customer.class)
|
||||
.select("name")
|
||||
.also(myPager);
|
||||
|
||||
query.findList();
|
||||
if (isLimitOffset()) {
|
||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.name from o_customer t0 limit 10");
|
||||
}
|
||||
}
|
||||
|
||||
static class MyPager implements Consumer<QueryBuilder<?, ?>> {
|
||||
|
||||
final int maxRows;
|
||||
|
||||
MyPager(int maxRows) {
|
||||
this.maxRows = maxRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(QueryBuilder<?, ?> queryBuilder) {
|
||||
queryBuilder.setMaxRows(maxRows);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -213,6 +213,7 @@ public class TestQueryFilterMany extends BaseTestCase {
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("from o_customer t0 left join o_order t1");
|
||||
assertThat(sql.get(0)).contains("where t1.order_date is not null");
|
||||
assertThat(sql.get(0)).contains("order by t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -269,6 +270,7 @@ public class TestQueryFilterMany extends BaseTestCase {
|
||||
List<String> sqlList = LoggedSql.stop();
|
||||
assertEquals(1, sqlList.size());
|
||||
assertThat(sqlList.get(0)).contains("select count(*) from o_customer");
|
||||
assertThat(sqlList.get(0)).doesNotContain("order by");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.test.LoggedSql;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.MUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestQueryFilterManyOnM2M extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
LoggedSql.start();
|
||||
DB.find(MUser.class).fetch("roles").filterMany("roles").ilike("roleName", "Jim%").findList();
|
||||
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("select t0.userid, t0.user_name, t0.user_type_id, t1.roleid, t1.role_name from muser t0 left join mrole_muser t1z_ on t1z_.muser_userid = t0.userid left join mrole t1 on t1.roleid = t1z_.mrole_roleid where lower(t1.role_name) like");
|
||||
assertThat(sql.get(0)).contains("order by t0.userid;");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.test.LoggedSql;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -10,6 +11,8 @@ import org.tests.model.basic.ResetBasicData;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestQueryFilterManySimple extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@@ -20,6 +23,7 @@ public class TestQueryFilterManySimple extends BaseTestCase {
|
||||
// not really last week :)
|
||||
Date lastWeek = Date.valueOf("2010-01-01");
|
||||
|
||||
LoggedSql.start();
|
||||
List<Customer> list = DB.find(Customer.class)
|
||||
// .join("orders", new JoinConfig().lazy())
|
||||
// .join("orders", new JoinConfig().query())
|
||||
@@ -29,5 +33,14 @@ public class TestQueryFilterManySimple extends BaseTestCase {
|
||||
|
||||
// invoke lazy loading
|
||||
list.get(0).getOrders().size();
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains("from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null left join o_customer t2 on t2.id = t1.kcustomer_id where");
|
||||
assertThat(sql.get(0)).contains("order by t0.id");
|
||||
if (isPostgresCompatible()) {
|
||||
assertThat(sql.get(1)).contains("from contact t0 where (t0.customer_id) = any(?) and t0.first_name is not null;");
|
||||
} else {
|
||||
assertThat(sql.get(1)).contains("from contact t0 where (t0.customer_id) in (?) and t0.first_name is not null;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.test.LoggedSql;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
@@ -19,6 +20,7 @@ public class TestRowCount extends BaseTestCase {
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
LoggedSql.start();
|
||||
|
||||
Query<Order> query = DB.find(Order.class)
|
||||
.fetch("details")
|
||||
@@ -32,6 +34,13 @@ public class TestRowCount extends BaseTestCase {
|
||||
List<Object> ids = query.findIds();
|
||||
|
||||
List<Order> list = query.findList();
|
||||
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(3);
|
||||
assertThat(sql.get(0)).doesNotContain("order by");
|
||||
assertThat(sql.get(1)).contains("order by");
|
||||
assertThat(sql.get(2)).contains("order by t0.id desc");
|
||||
|
||||
System.out.println(list);
|
||||
for (Order order : list) {
|
||||
order.getStatus();
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.ebean.xtest.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.*;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.EBasic;
|
||||
@@ -19,11 +20,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void a_runFirst_metricsAsJson_sqlInInitialCollectionOnly() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
runQueries();
|
||||
|
||||
StringBuilder buffer0 = new StringBuilder();
|
||||
@@ -55,18 +58,12 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_ref() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer customer = Customer.find.ref(1);
|
||||
assertThat(customer.getId()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_all_byId_byName() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> all = Customer.find.all();
|
||||
List<Customer> list = DB.find(Customer.class).findList();
|
||||
|
||||
@@ -93,7 +90,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void flush() {
|
||||
|
||||
Transaction transaction = DB.beginTransaction();
|
||||
try {
|
||||
Customer.find.currentTransaction().setBatchMode(true);
|
||||
@@ -114,7 +110,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_byName_deleteById() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setName("Newbie-879879897");
|
||||
|
||||
@@ -134,16 +129,12 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_update() {
|
||||
|
||||
int rowsUpdated = Customer.find.updateToInactive("Frankie Who");
|
||||
logger.debug("updated {}", rowsUpdated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_ormQuery() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> customers =
|
||||
Customer.find.byNameStatus("R", Customer.Status.NEW);
|
||||
|
||||
@@ -152,9 +143,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_nativeSingleAttribute() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<String> names = Customer.find.namesStartingWith("F");
|
||||
assertThat(names).isNotEmpty();
|
||||
}
|
||||
@@ -162,9 +150,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
@Test
|
||||
@IgnorePlatform(Platform.DB2) // no query plans yet, for DB2
|
||||
public void test_finders_queryPlans() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// change default collect query plan threshold to 20 micros
|
||||
QueryPlanInit init0 = new QueryPlanInit();
|
||||
init0.setAll(true);
|
||||
@@ -219,9 +204,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_metricsAsJson_withAll() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
runQueries();
|
||||
|
||||
String metricsJson = server().metaInfo()
|
||||
@@ -243,9 +225,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_metricsAsJson_minimal() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
runQueries();
|
||||
|
||||
String metricsJson = server().metaInfo()
|
||||
@@ -265,9 +244,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_metricsAsJson_write() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
runQueries();
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
@@ -283,9 +259,6 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_metricsAsJson_writeWithHeader() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
runQueries();
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.repository;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
@@ -14,12 +15,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestBeanRepository extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
DB.find(Customer.class).where().in("name", "c0", "c1").delete();
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
CustomerRepository repository = new CustomerRepository(server());
|
||||
|
||||
Customer customer = new Customer();
|
||||
@@ -52,9 +56,6 @@ public class TestBeanRepository extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void findByName() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
CustomerRepository repository = new CustomerRepository(server());
|
||||
|
||||
Customer blah = new Customer();
|
||||
@@ -80,6 +81,5 @@ public class TestBeanRepository extends BaseTestCase {
|
||||
|
||||
repository.deleteById(1099);
|
||||
repository.findAll();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,10 @@ import io.ebeaninternal.api.json.SpiJsonReader;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.json.ReadJson;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.ContactNote;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@@ -28,6 +26,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestJsonBeanDescriptorParse extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
Customer customer = new Customer();
|
||||
@@ -76,7 +79,7 @@ public class TestJsonBeanDescriptorParse extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonManyUpdate() throws IOException {
|
||||
public void testJsonManyUpdate() {
|
||||
|
||||
Customer customer = DB.find(Customer.class, 234);
|
||||
String json =
|
||||
@@ -108,7 +111,7 @@ public class TestJsonBeanDescriptorParse extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonUpdate() throws IOException {
|
||||
public void testJsonUpdate() {
|
||||
Customer customer = DB.find(Customer.class, 234);
|
||||
DB.json().toBean(customer, "{}");
|
||||
assertFalse(DB.beanState(customer).isDirty());
|
||||
@@ -184,8 +187,7 @@ public class TestJsonBeanDescriptorParse extends BaseTestCase {
|
||||
StringReader reader = new StringReader("{\"id\":123,\"name\":\"Hello Rob\"}");
|
||||
JsonParser parser = server.json().createParser(reader);
|
||||
|
||||
SpiJsonReader readJson = new ReadJson(descriptor, parser, null, null, false);
|
||||
return readJson;
|
||||
return new ReadJson(descriptor, parser, null, null, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,20 +10,25 @@ import io.ebean.annotation.Transactional;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.xtest.ForPlatform;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class TestExecuteComplete extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void execute_when_errorOnCommit_threadLocalIsCleared() {
|
||||
|
||||
try {
|
||||
DB.execute(TxScope.required().setBatch(PersistBatch.ALL), () -> {
|
||||
|
||||
@@ -43,7 +48,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void nestedExecute_when_errorOnCommit_threadLocalIsCleared() {
|
||||
|
||||
try {
|
||||
DB.execute(TxScope.required().setBatch(PersistBatch.ALL), () ->
|
||||
DB.execute(() -> {
|
||||
@@ -64,7 +68,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void transactional_errorOnCommit_expect_threadScopeCleanup() {
|
||||
|
||||
try {
|
||||
errorOnCommit();
|
||||
fail();
|
||||
@@ -85,7 +88,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void normal_expect_threadScopeCleanup() {
|
||||
|
||||
Transaction txn1 = server().beginTransaction();
|
||||
try {
|
||||
txn1.commit();
|
||||
@@ -99,7 +101,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void missingEnd_expect_threadScopeCleanup() {
|
||||
|
||||
Transaction txn1 = server().beginTransaction();
|
||||
try {
|
||||
txn1.commit();
|
||||
@@ -114,7 +115,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void missingEnd_withRollbackOnly_expect_threadScopeCleanup() {
|
||||
|
||||
Transaction txn1 = server().beginTransaction();
|
||||
try {
|
||||
txn1.rollback();
|
||||
@@ -129,7 +129,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void implicit_query_expect_threadScopeCleanup() {
|
||||
|
||||
DB.find(Customer.class).findList();
|
||||
|
||||
assertThat(getInScopeTransaction()).isNull();
|
||||
@@ -138,7 +137,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void implicit_save_expect_threadScopeCleanup() {
|
||||
|
||||
Customer cust = new Customer();
|
||||
cust.setName("Roland");
|
||||
DB.save(cust);
|
||||
@@ -149,7 +147,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void no_transaction_expect_threadScopeCleanup() {
|
||||
|
||||
try (Transaction txn = DB.beginTransaction(TxScope.notSupported())) {
|
||||
SpiTransaction txn2 = getInScopeTransaction();
|
||||
// The NoTransaction placeholder can normally only occur inside
|
||||
@@ -164,7 +161,6 @@ public class TestExecuteComplete extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void test_nested_userobjects() {
|
||||
|
||||
try (Transaction txn1 = DB.beginTransaction()) {
|
||||
assertThat(getInScopeTransaction()).isNotNull();
|
||||
getInScopeTransaction().putUserObject("foo", "bar");
|
||||
|
||||
@@ -7,12 +7,10 @@ import io.ebean.test.LoggedSql;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebeaninternal.api.SpiBeanTypeManager;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.EBasicVer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.OrderShipment;
|
||||
import org.tests.model.basic.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,6 +19,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestTransparentPersist extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertFlush_mutateFlush_expect_update() {
|
||||
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
package org.tests.unitinternal;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class TestEqualsOnEnhanced extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Customer c = new Customer();
|
||||
|
||||
Reference in New Issue
Block a user