mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-21 03:47:30 +00:00
Remove readOnly from Query
This commit is contained in:
@@ -396,11 +396,6 @@ public interface QueryBuilder<SELF extends QueryBuilder<SELF, T>, T> extends Que
|
||||
*/
|
||||
SELF setUnmodifiable(boolean unmodifiable);
|
||||
|
||||
/**
|
||||
* When set to true when you want the returned beans to be read only.
|
||||
*/
|
||||
SELF setReadOnly(boolean readOnly);
|
||||
|
||||
/**
|
||||
* Set a timeout on this query.
|
||||
* <p>
|
||||
|
||||
@@ -779,11 +779,6 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
||||
*/
|
||||
CacheMode queryCacheMode();
|
||||
|
||||
/**
|
||||
* Return true if the beans returned by this query should be read only.
|
||||
*/
|
||||
Boolean isReadOnly();
|
||||
|
||||
/**
|
||||
* Return true if the beans returned by this query should be unmodifiable.
|
||||
*/
|
||||
|
||||
@@ -508,11 +508,6 @@ 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> setReadOnly(boolean readOnly) {
|
||||
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> setTimeout(int secs) {
|
||||
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
|
||||
|
||||
@@ -132,7 +132,6 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
private boolean usageProfiling = true;
|
||||
private CacheMode useBeanCache = CacheMode.AUTO;
|
||||
private CacheMode useQueryCache = CacheMode.OFF;
|
||||
private Boolean readOnly;
|
||||
private boolean unmodifiable;
|
||||
private PersistenceContextScope persistenceContextScope;
|
||||
|
||||
@@ -516,13 +515,8 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
createExtraJoinsToSupportManyWhereClause();
|
||||
}
|
||||
if (unmodifiable) {
|
||||
readOnly = Boolean.TRUE;
|
||||
disableLazyLoading = true;
|
||||
persistenceContextScope = PersistenceContextScope.QUERY;
|
||||
} else if (disableLazyLoading && Boolean.TRUE.equals(readOnly)) {
|
||||
// "upgrade" this to unmodifiable? hmmm.
|
||||
unmodifiable = true;
|
||||
persistenceContextScope = PersistenceContextScope.QUERY;
|
||||
}
|
||||
return markQueryJoins();
|
||||
}
|
||||
@@ -774,7 +768,6 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
copy.useBeanCache = useBeanCache;
|
||||
copy.useQueryCache = useQueryCache;
|
||||
copy.unmodifiable = unmodifiable;
|
||||
copy.readOnly = readOnly;
|
||||
if (detail != null) {
|
||||
copy.detail = detail.copy();
|
||||
}
|
||||
@@ -1295,25 +1288,11 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Boolean isReadOnly() {
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnmodifiable() {
|
||||
return unmodifiable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Query<T> setReadOnly(boolean readOnly) {
|
||||
if (unmodifiable && !readOnly) {
|
||||
throw new IllegalStateException("Not allowed to set readOnly false on query that is unmodifiable");
|
||||
}
|
||||
this.readOnly = readOnly;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isBeanCachePut() {
|
||||
return useBeanCache.isPut() && beanDescriptor.isBeanCaching();
|
||||
@@ -1356,9 +1335,6 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
public final Query<T> setUseQueryCache(CacheMode useQueryCache) {
|
||||
this.useQueryCache = useQueryCache;
|
||||
if (CacheMode.OFF != useQueryCache) {
|
||||
if (Boolean.FALSE.equals(readOnly)) {
|
||||
throw new IllegalStateException("Not allowed to use query cache with readOnly false");
|
||||
}
|
||||
unmodifiable = true;
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -499,12 +499,6 @@ public abstract class QueryBean<T, R extends QueryBean<T, R>> implements IQueryB
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final R setReadOnly(boolean readOnly) {
|
||||
query.setReadOnly(readOnly);
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final R setBeanCacheMode(CacheMode beanCacheMode) {
|
||||
query.setBeanCacheMode(beanCacheMode);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class TestBeanCache extends BaseTestCase {
|
||||
|
||||
// expect to hit the cache, no SQL
|
||||
LoggedSql.start();
|
||||
OCachedBean bean2 = DB.find(OCachedBean.class).setReadOnly(true).setId(String.valueOf(bean.getId())).findOne();
|
||||
OCachedBean bean2 = DB.find(OCachedBean.class).setUnmodifiable(true).setId(String.valueOf(bean.getId())).findOne();
|
||||
sql = LoggedSql.stop();
|
||||
assertNotNull(bean2);
|
||||
assertThat(sql).isEmpty();
|
||||
|
||||
@@ -40,7 +40,7 @@ public class TestBeanCacheWithDeleteQuery extends BaseTestCase {
|
||||
|
||||
// expect not to hit the cache, expect SQL
|
||||
LoggedSql.start();
|
||||
OCachedBean bean2 = DB.find(OCachedBean.class).setReadOnly(true).setId(String.valueOf(bean.getId())).findOne();
|
||||
OCachedBean bean2 = DB.find(OCachedBean.class).setUnmodifiable(true).setId(String.valueOf(bean.getId())).findOne();
|
||||
sql = LoggedSql.stop();
|
||||
assertNull(bean2);
|
||||
assertThat(sql).isNotEmpty();
|
||||
@@ -70,7 +70,7 @@ public class TestBeanCacheWithDeleteQuery extends BaseTestCase {
|
||||
|
||||
// expect not to hit the cache, expect SQL
|
||||
LoggedSql.start();
|
||||
OCachedBean bean2 = DB.find(OCachedBean.class).setReadOnly(true).setId(String.valueOf(bean.getId())).findOne();
|
||||
OCachedBean bean2 = DB.find(OCachedBean.class).setUnmodifiable(true).setId(String.valueOf(bean.getId())).findOne();
|
||||
sql = LoggedSql.stop();
|
||||
assertNotNull(bean2);
|
||||
assertThat(sql).isNotEmpty();
|
||||
|
||||
@@ -317,7 +317,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
assertThat(list).isNotEmpty();
|
||||
assertThat(DB.beanState(list.get(0)).isUnmodifiable()).isTrue();
|
||||
|
||||
List<Customer> list2 = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
List<Customer> list2 = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().ilike("name", "Rob")
|
||||
.findList();
|
||||
|
||||
@@ -330,7 +330,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
// readOnly defaults to true for query cache
|
||||
assertSame(list2, list2B);
|
||||
|
||||
List<Customer> list3 = DB.find(Customer.class).setUseQueryCache(true)//.setReadOnly(false)
|
||||
List<Customer> list3 = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(false)
|
||||
.where().ilike("name", "Rob")
|
||||
.findList();
|
||||
|
||||
|
||||
+10
-10
@@ -34,13 +34,13 @@ public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
.where().eq("line2", "St Lukes")
|
||||
.findList();
|
||||
|
||||
int custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
int custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lukes")
|
||||
.findCount();
|
||||
|
||||
assertThat(custs).isEqualTo(3);
|
||||
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lukes")
|
||||
.findCount();
|
||||
|
||||
@@ -50,14 +50,14 @@ public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
a1.setLine2("St Lucky");
|
||||
DB.save(a1);
|
||||
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lukes")
|
||||
.findCount();
|
||||
|
||||
assertThat(custs).isEqualTo(2);
|
||||
|
||||
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lucky")
|
||||
.findCount();
|
||||
|
||||
@@ -68,13 +68,13 @@ public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
.where().eq("line2", "St Lucky")
|
||||
.update();
|
||||
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lucky")
|
||||
.findCount();
|
||||
|
||||
assertThat(custs).isEqualTo(0);
|
||||
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lucky2")
|
||||
.findCount();
|
||||
assertThat(custs).isEqualTo(1);
|
||||
@@ -83,12 +83,12 @@ public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
.setParameters("St Lucky3", "St Lucky2")
|
||||
.execute();
|
||||
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lucky2")
|
||||
.findCount();
|
||||
assertThat(custs).isEqualTo(0);
|
||||
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
custs = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lucky3")
|
||||
.findCount();
|
||||
|
||||
@@ -101,7 +101,7 @@ public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
|
||||
Customer fi = DB.find(Customer.class).where().eq("name", "Fiona").findOne();
|
||||
|
||||
int custCount0 = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
int custCount0 = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where()
|
||||
.eq("name", "Fiona")
|
||||
.isNull("contacts.phone")
|
||||
@@ -117,7 +117,7 @@ public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
|
||||
assertThat(updateRows).isGreaterThan(0);
|
||||
|
||||
int custCount1 = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
int custCount1 = DB.find(Customer.class).setUseQueryCache(true) //.setReadOnly(true)
|
||||
.where()
|
||||
.eq("name", "Fiona")
|
||||
.isNull("contacts.phone")
|
||||
|
||||
@@ -138,9 +138,9 @@ public class TestQueryFindIterate extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSql.stop();
|
||||
|
||||
assertEquals(3, loggedSql.size());
|
||||
assertTrue(trimSql(loggedSql.get(0), 7).contains("select t0.id, t0.status, t0.order_date, t1.id, t1.name from o_order t0 join o_customer t1"));
|
||||
assertTrue(trimSql(loggedSql.get(1), 7).contains("select t0.order_id, t0.id, t0.order_qty, t0.ship_qty, t0.unit_price"));
|
||||
assertTrue(trimSql(loggedSql.get(2), 7).contains("select t0.order_id, t0.id, t0.ship_time, t0.cretime, t0.updtime, t0.version, t0.order_id from or_order_ship"));
|
||||
assertThat(trimSql(loggedSql.get(0), 7)).contains("select t0.id, t0.status, t0.order_date, t1.id, t1.name from o_order t0 join o_customer t1");
|
||||
assertThat(trimSql(loggedSql.get(1), 7)).contains("select t0.order_id, t0.id, t0.order_qty, t0.ship_qty, t0.unit_price");
|
||||
assertThat(trimSql(loggedSql.get(2), 7)).contains("select t0.order_id, t0.id, t0.ship_time, t0.cretime, t0.updtime, t0.version, t0.order_id from or_order_ship");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -160,7 +160,7 @@ class TestQueryOrderById extends BaseTestCase {
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> result = DB.find(Customer.class)
|
||||
.setReadOnly(true).setDisableLazyLoading(true)
|
||||
.setUnmodifiable(true) // .setDisableLazyLoading(true)
|
||||
.select("id,name")
|
||||
.fetch("contacts")
|
||||
.findList();
|
||||
@@ -185,7 +185,7 @@ class TestQueryOrderById extends BaseTestCase {
|
||||
.setFirstRow(1)
|
||||
.setMaxRows(5);
|
||||
|
||||
query.setReadOnly(true).setDisableLazyLoading(true);
|
||||
query.setUnmodifiable(true); //.setDisableLazyLoading(true);
|
||||
List<Customer> list = query.findList();
|
||||
if (isSqlServer() || isDb2()) {
|
||||
assertSql(query).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id offset 1 rows fetch next 5 rows only");
|
||||
|
||||
@@ -53,8 +53,8 @@ public class TestOrderByWithMany extends BaseTestCase {
|
||||
|
||||
String lazyLoadSql = loggedSql.get(1);
|
||||
// contains the foreign key back to the parent bean (t0.order_id)
|
||||
assertTrue(trimSql(lazyLoadSql, 2).contains("select t0.order_id, t0.id"));
|
||||
assertTrue(lazyLoadSql.contains("order by t0.order_id, t0.id, t0.order_qty, t0.cretime desc"));
|
||||
assertThat(trimSql(lazyLoadSql, 2)).contains("select t0.order_id, t0.id");
|
||||
assertThat(lazyLoadSql).contains("order by t0.order_id, t0.id, t0.order_qty, t0.cretime desc");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user