mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 12:19:09 +00:00
Merge pull request #1840 from FOCONIS/exists-use-query-copy
exists() limits the max rows on the query, this should be done on a copy
This commit is contained in:
@@ -1351,8 +1351,9 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
@Override
|
||||
public <T> boolean exists(SpiQuery<?> ormQuery, SpiTransaction transaction) {
|
||||
|
||||
ormQuery.setMaxRows(1);
|
||||
SpiOrmQueryRequest<?> request = createQueryRequest(Type.ID_LIST, ormQuery, transaction);
|
||||
Query<?> ormQueryCopy = ormQuery.copy();
|
||||
ormQueryCopy.setMaxRows(1);
|
||||
SpiOrmQueryRequest<?> request = createQueryRequest(Type.ID_LIST, ormQueryCopy, transaction);
|
||||
try {
|
||||
request.initTransIfRequired();
|
||||
List<Object> ids = request.findIds();
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.tests.query;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import io.ebeantest.LoggedSql;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
@@ -23,10 +25,11 @@ public class TestQueryExists extends BaseTestCase {
|
||||
.where().gt("id", 1)
|
||||
.query();
|
||||
|
||||
LoggedSql.start();
|
||||
boolean check = query.exists();
|
||||
String sql = LoggedSql.stop().get(0);
|
||||
assertThat(check).isTrue();
|
||||
|
||||
String sql = sqlOf(query);
|
||||
if (isH2() || isPostgres()) {
|
||||
assertThat(sql).contains("select t0.id from o_order t0 where t0.id > ? limit 1");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user