mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 01:07:49 +00:00
Merge pull request #2765 from ebean-orm/feature/2762-forUpdate-pagingList-count
#2762 - forUpdate is NOT included in query copy() method
This commit is contained in:
@@ -417,6 +417,8 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
||||
|
||||
/**
|
||||
* Return a copy of the query.
|
||||
* <p>
|
||||
* Note that this does NOT copy the forUpdate property. See #2762.
|
||||
*/
|
||||
@Override
|
||||
SpiQuery<T> copy();
|
||||
|
||||
@@ -708,6 +708,7 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
|
||||
@Override
|
||||
public SpiQuery<T> copy(SpiEbeanServer server) {
|
||||
// forUpdate is NOT copied - see #2762
|
||||
DefaultOrmQuery<T> copy = new DefaultOrmQuery<>(beanDescriptor, server, expressionFactory);
|
||||
copy.transaction = transaction;
|
||||
copy.m2mIncludeJoin = m2mIncludeJoin;
|
||||
@@ -748,7 +749,6 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
||||
copy.usageProfiling = usageProfiling;
|
||||
copy.autoTune = autoTune;
|
||||
copy.parentNode = parentNode;
|
||||
copy.forUpdate = forUpdate;
|
||||
copy.rawSql = rawSql;
|
||||
setCancelableQuery(copy); // required to cancel findId query
|
||||
return copy;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.PagedList;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
@@ -264,4 +265,27 @@ public class TestQueryFindPagedList extends BaseTestCase {
|
||||
assertThat(loggedSql.get(0)).contains("select count(*) from o_order b where b.id > 0");
|
||||
assertThat(trimSql(loggedSql.get(1), 3)).contains(" b.id, b.status, b.order_date");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_forUpdate() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
try (Transaction txn = DB.beginTransaction()) {
|
||||
PagedList<Order> pagedList = DB.find(Order.class).forUpdate().setMaxRows(2).findPagedList();
|
||||
|
||||
LoggedSql.start();
|
||||
int totalCount = pagedList.getTotalCount();
|
||||
assertThat(totalCount).isGreaterThan(2);
|
||||
|
||||
List<Order> list = pagedList.getList();
|
||||
assertThat(list).hasSize(2);
|
||||
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains("select count(*) from o_order t0;");
|
||||
if (isH2() || isPostgresCompatible()) {
|
||||
assertThat(sql.get(1)).contains(" limit 2 for update;");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user