Merge branch 'FOCONIS-bug/transactional-affects-query-cache'

This commit is contained in:
Rob Bygrave
2022-11-10 12:32:49 +13:00
3 changed files with 28 additions and 2 deletions
@@ -396,7 +396,7 @@ final class CQueryBuilder {
sql = nativeQueryPaging(query, sql);
}
query.setGeneratedSql(sql);
Connection connection = request.transaction().connection();
Connection connection = request.transaction().getInternalConnection();
BeanDescriptor<?> desc = request.descriptor();
try {
// For SqlServer we need either "selectMethod=cursor" in the connection string or fetch explicitly a cursorable
@@ -35,7 +35,7 @@ abstract class TransactionFactory {
*/
final SpiTransaction setIsolationLevel(SpiTransaction t, boolean explicit, int isolationLevel) {
if (isolationLevel > -1) {
Connection connection = t.connection();
Connection connection = t.getInternalConnection();
try {
connection.setTransactionIsolation(isolationLevel);
} catch (SQLException e) {
@@ -3,6 +3,8 @@ package org.tests.cache;
import io.ebean.CacheMode;
import io.ebean.DB;
import io.ebean.ExpressionList;
import io.ebean.annotation.Transactional;
import io.ebean.annotation.TxIsolation;
import io.ebean.bean.BeanCollection;
import io.ebean.cache.ServerCache;
import io.ebean.test.LoggedSql;
@@ -159,6 +161,30 @@ public class TestQueryCache extends BaseTestCase {
assertThat(count2).isEqualTo(count1);
sql = LoggedSql.stop();
assertThat(sql).hasSize(1);
LoggedSql.start();
findCountNoTxn();
sql = LoggedSql.stop();
assertThat(sql).hasSize(0);
LoggedSql.start();
findCountTxn();
sql = LoggedSql.stop();
assertThat(sql).hasSize(0);
}
private void findCountNoTxn() {
DB.find(EColAB.class)
.setUseQueryCache(CacheMode.ON)
.where()
.eq("columnB", "count")
.findCount();
}
@Transactional(isolation = TxIsolation.READ_UNCOMMITTED)
private void findCountTxn() {
findCountNoTxn();
}
@Test