Add transaction to AggregateInput and CountInput

This commit is contained in:
2025-05-23 11:04:29 -05:00
parent ed91d3fdbe
commit 18232d5e80
6 changed files with 106 additions and 5 deletions

View File

@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.model.actions.tables.aggregate;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
@ -37,6 +38,8 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin;
*******************************************************************************/
public class AggregateInput extends AbstractTableActionInput
{
private QBackendTransaction transaction;
private QQueryFilter filter;
private List<Aggregate> aggregates;
private List<GroupBy> groupBys = new ArrayList<>();
@ -404,4 +407,35 @@ public class AggregateInput extends AbstractTableActionInput
return (queryHints.contains(queryHint));
}
/*******************************************************************************
** Getter for transaction
*******************************************************************************/
public QBackendTransaction getTransaction()
{
return (this.transaction);
}
/*******************************************************************************
** Setter for transaction
*******************************************************************************/
public void setTransaction(QBackendTransaction transaction)
{
this.transaction = transaction;
}
/*******************************************************************************
** Fluent setter for transaction
*******************************************************************************/
public AggregateInput withTransaction(QBackendTransaction transaction)
{
this.transaction = transaction;
return (this);
}
}

View File

@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.model.actions.tables.count;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
@ -37,7 +38,8 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin;
*******************************************************************************/
public class CountInput extends AbstractTableActionInput
{
private QQueryFilter filter;
private QBackendTransaction transaction;
private QQueryFilter filter;
private Integer timeoutSeconds;
@ -285,4 +287,35 @@ public class CountInput extends AbstractTableActionInput
return (queryHints.contains(queryHint));
}
/*******************************************************************************
** Getter for transaction
*******************************************************************************/
public QBackendTransaction getTransaction()
{
return (this.transaction);
}
/*******************************************************************************
** Setter for transaction
*******************************************************************************/
public void setTransaction(QBackendTransaction transaction)
{
this.transaction = transaction;
}
/*******************************************************************************
** Fluent setter for transaction
*******************************************************************************/
public CountInput withTransaction(QBackendTransaction transaction)
{
this.transaction = transaction;
return (this);
}
}

View File

@ -84,7 +84,7 @@ public class MongoDBAggregateAction extends AbstractMongoDBAction implements Agg
String backendTableName = getBackendTableName(table);
MongoDBBackendMetaData backend = (MongoDBBackendMetaData) aggregateInput.getBackend();
mongoClientContainer = openClient(backend, null); // todo - aggregate input has no transaction!?
mongoClientContainer = openClient(backend, aggregateInput.getTransaction());
MongoDatabase database = mongoClientContainer.getMongoClient().getDatabase(backend.getDatabaseName());
MongoCollection<Document> collection = database.getCollection(backendTableName);

View File

@ -72,7 +72,7 @@ public class MongoDBCountAction extends AbstractMongoDBAction implements CountIn
String backendTableName = getBackendTableName(table);
MongoDBBackendMetaData backend = (MongoDBBackendMetaData) countInput.getBackend();
mongoClientContainer = openClient(backend, null); // todo - count input has no transaction!?
mongoClientContainer = openClient(backend, countInput.getTransaction());
MongoDatabase database = mongoClientContainer.getMongoClient().getDatabase(backend.getDatabaseName());
MongoCollection<Document> collection = database.getCollection(backendTableName);

View File

@ -108,7 +108,19 @@ public class RDBMSAggregateAction extends AbstractRDBMSAction implements Aggrega
Long mark = System.currentTimeMillis();
try(Connection connection = getConnection(aggregateInput))
Connection connection;
boolean needToCloseConnection = false;
if(aggregateInput.getTransaction() != null && aggregateInput.getTransaction() instanceof RDBMSTransaction rdbmsTransaction)
{
connection = rdbmsTransaction.getConnection();
}
else
{
connection = getConnection(aggregateInput);
needToCloseConnection = true;
}
try
{
statement = connection.prepareStatement(sql);
@ -185,6 +197,11 @@ public class RDBMSAggregateAction extends AbstractRDBMSAction implements Aggrega
finally
{
logSQL(sql, params, mark);
if(needToCloseConnection)
{
connection.close();
}
}
return rs;

View File

@ -88,7 +88,19 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
CountOutput rs = new CountOutput();
long mark = System.currentTimeMillis();
try(Connection connection = getConnection(countInput))
Connection connection;
boolean needToCloseConnection = false;
if(countInput.getTransaction() != null && countInput.getTransaction() instanceof RDBMSTransaction rdbmsTransaction)
{
connection = rdbmsTransaction.getConnection();
}
else
{
connection = getConnection(countInput);
needToCloseConnection = true;
}
try
{
statement = connection.prepareStatement(sql);
@ -130,6 +142,11 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
finally
{
logSQL(sql, params, mark);
if(needToCloseConnection)
{
connection.close();
}
}
return rs;