mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Merge pull request #2770 from ebean-orm/feature/sqlquery-useTransaction
Add SqlQuery usingTransaction() for consistency and deprecate ExtendedServer API
This commit is contained in:
8 files changed
+169
-359
No files matched your search
@@ -25,6 +25,11 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public interface SpiEbeanServer extends SpiServer, ExtendedServer, BeanCollectionLoader {
|
||||
|
||||
/**
|
||||
* Return the NOW time from the Clock.
|
||||
*/
|
||||
long clockNow();
|
||||
|
||||
/**
|
||||
* Return true if the L2 cache has been disabled.
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package io.ebeaninternal.api;
|
||||
|
||||
import io.avaje.lang.Nullable;
|
||||
import io.ebean.SqlQuery;
|
||||
import io.ebean.Transaction;
|
||||
|
||||
/**
|
||||
* SQL query - Internal extension to SqlQuery.
|
||||
*/
|
||||
public interface SpiSqlQuery extends SqlQuery, SpiSqlBinding {
|
||||
|
||||
/**
|
||||
* Return the transaction explicitly associated to the query.
|
||||
*/
|
||||
@Nullable
|
||||
Transaction transaction();
|
||||
}
|
||||
@@ -1514,7 +1514,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
|
||||
private <P> P executeSqlQuery(Function<RelationalQueryRequest, P> fun, SpiSqlQuery query) {
|
||||
RelationalQueryRequest request = new RelationalQueryRequest(this, relationalQueryEngine, query, null);
|
||||
RelationalQueryRequest request = new RelationalQueryRequest(this, relationalQueryEngine, query, query.transaction());
|
||||
try {
|
||||
request.initTransIfRequired();
|
||||
return fun.apply(request);
|
||||
|
||||
@@ -22,9 +22,6 @@ public final class RelationalQueryRequest extends AbstractSqlQueryRequest {
|
||||
private int estimateCapacity;
|
||||
private int rows;
|
||||
|
||||
/**
|
||||
* Create the BeanFindRequest.
|
||||
*/
|
||||
RelationalQueryRequest(SpiEbeanServer server, RelationalQueryEngine engine, SqlQuery q, Transaction t) {
|
||||
super(server, (SpiSqlBinding) q, t);
|
||||
this.queryEngine = engine;
|
||||
|
||||
+33
-8
@@ -2,10 +2,7 @@ package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import io.avaje.lang.NonNullApi;
|
||||
import io.avaje.lang.Nullable;
|
||||
import io.ebean.RowConsumer;
|
||||
import io.ebean.RowMapper;
|
||||
import io.ebean.SqlQuery;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.*;
|
||||
import io.ebeaninternal.api.BindParams;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiSqlQuery;
|
||||
@@ -31,6 +28,7 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
|
||||
private int timeout;
|
||||
private int bufferFetchSizeHint;
|
||||
private final BindParams bindParams = new BindParams();
|
||||
private Transaction transaction;
|
||||
|
||||
/**
|
||||
* Additional supply a query detail object.
|
||||
@@ -40,19 +38,34 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transaction transaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlQuery usingTransaction(Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void transaction(Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findEach(Consumer<SqlRow> consumer) {
|
||||
server.findEach(this, consumer, null);
|
||||
server.findEach(this, consumer, transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findEachWhile(Predicate<SqlRow> consumer) {
|
||||
server.findEachWhile(this, consumer, null);
|
||||
server.findEachWhile(this, consumer, transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SqlRow> findList() {
|
||||
return server.findList(this, null);
|
||||
return server.findList(this, transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +75,7 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
|
||||
|
||||
@Override
|
||||
public SqlRow findOne() {
|
||||
return server.findOne(this, null);
|
||||
return server.findOne(this, transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,6 +229,12 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeQuery<T> usingTransaction(Transaction transaction) {
|
||||
transaction(transaction);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findOne() {
|
||||
return findSingleAttribute(type);
|
||||
@@ -249,6 +268,12 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeQuery<T> usingTransaction(Transaction transaction) {
|
||||
transaction(transaction);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public T findOne() {
|
||||
|
||||
Reference in new issue
Block a user