mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Add transaction to AggregateInput and CountInput
This commit is contained in:
@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.model.actions.tables.aggregate;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
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.AbstractTableActionInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
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
|
public class AggregateInput extends AbstractTableActionInput
|
||||||
{
|
{
|
||||||
|
private QBackendTransaction transaction;
|
||||||
|
|
||||||
private QQueryFilter filter;
|
private QQueryFilter filter;
|
||||||
private List<Aggregate> aggregates;
|
private List<Aggregate> aggregates;
|
||||||
private List<GroupBy> groupBys = new ArrayList<>();
|
private List<GroupBy> groupBys = new ArrayList<>();
|
||||||
@ -404,4 +407,35 @@ public class AggregateInput extends AbstractTableActionInput
|
|||||||
|
|
||||||
return (queryHints.contains(queryHint));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.model.actions.tables.count;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
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.AbstractTableActionInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
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
|
public class CountInput extends AbstractTableActionInput
|
||||||
{
|
{
|
||||||
private QQueryFilter filter;
|
private QBackendTransaction transaction;
|
||||||
|
private QQueryFilter filter;
|
||||||
|
|
||||||
private Integer timeoutSeconds;
|
private Integer timeoutSeconds;
|
||||||
|
|
||||||
@ -285,4 +287,35 @@ public class CountInput extends AbstractTableActionInput
|
|||||||
|
|
||||||
return (queryHints.contains(queryHint));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class MongoDBAggregateAction extends AbstractMongoDBAction implements Agg
|
|||||||
String backendTableName = getBackendTableName(table);
|
String backendTableName = getBackendTableName(table);
|
||||||
MongoDBBackendMetaData backend = (MongoDBBackendMetaData) aggregateInput.getBackend();
|
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());
|
MongoDatabase database = mongoClientContainer.getMongoClient().getDatabase(backend.getDatabaseName());
|
||||||
MongoCollection<Document> collection = database.getCollection(backendTableName);
|
MongoCollection<Document> collection = database.getCollection(backendTableName);
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class MongoDBCountAction extends AbstractMongoDBAction implements CountIn
|
|||||||
String backendTableName = getBackendTableName(table);
|
String backendTableName = getBackendTableName(table);
|
||||||
MongoDBBackendMetaData backend = (MongoDBBackendMetaData) countInput.getBackend();
|
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());
|
MongoDatabase database = mongoClientContainer.getMongoClient().getDatabase(backend.getDatabaseName());
|
||||||
MongoCollection<Document> collection = database.getCollection(backendTableName);
|
MongoCollection<Document> collection = database.getCollection(backendTableName);
|
||||||
|
|
||||||
|
@ -108,7 +108,19 @@ public class RDBMSAggregateAction extends AbstractRDBMSAction implements Aggrega
|
|||||||
|
|
||||||
Long mark = System.currentTimeMillis();
|
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);
|
statement = connection.prepareStatement(sql);
|
||||||
|
|
||||||
@ -185,6 +197,11 @@ public class RDBMSAggregateAction extends AbstractRDBMSAction implements Aggrega
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
logSQL(sql, params, mark);
|
logSQL(sql, params, mark);
|
||||||
|
|
||||||
|
if(needToCloseConnection)
|
||||||
|
{
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rs;
|
return rs;
|
||||||
|
@ -88,7 +88,19 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
|||||||
CountOutput rs = new CountOutput();
|
CountOutput rs = new CountOutput();
|
||||||
long mark = System.currentTimeMillis();
|
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);
|
statement = connection.prepareStatement(sql);
|
||||||
|
|
||||||
@ -130,6 +142,11 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
logSQL(sql, params, mark);
|
logSQL(sql, params, mark);
|
||||||
|
|
||||||
|
if(needToCloseConnection)
|
||||||
|
{
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rs;
|
return rs;
|
||||||
|
Reference in New Issue
Block a user