mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
CE-781 Refactoring of backend actions - moving openTransaction out of insert-action only (up to backendModule); re-using the exit-early-if-0 and set-default-create-and-modify-date logics;
This commit is contained in:
@ -23,6 +23,9 @@ package com.kingsrook.qqq.backend.core.actions;
|
|||||||
|
|
||||||
|
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
|
||||||
|
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -30,12 +33,26 @@ import com.kingsrook.qqq.backend.core.exceptions.QException;
|
|||||||
** part of a transaction.
|
** part of a transaction.
|
||||||
**
|
**
|
||||||
** Most obvious use-case would be a JDBC Connection. See subclass in rdbms module.
|
** Most obvious use-case would be a JDBC Connection. See subclass in rdbms module.
|
||||||
|
** Ditto MongoDB.
|
||||||
**
|
**
|
||||||
** Note: One would imagine that this class shouldn't ever implement Serializable...
|
** Note: One would imagine that this class shouldn't ever implement Serializable...
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class QBackendTransaction
|
public class QBackendTransaction
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public static QBackendTransaction openFor(AbstractTableActionInput input) throws QException
|
||||||
|
{
|
||||||
|
QBackendModuleDispatcher qBackendModuleDispatcher = new QBackendModuleDispatcher();
|
||||||
|
QBackendModuleInterface qModule = qBackendModuleDispatcher.getQBackendModule(input.getBackend());
|
||||||
|
QBackendTransaction transaction = qModule.openTransaction(input);
|
||||||
|
return (transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Commit the transaction.
|
** Commit the transaction.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -31,7 +31,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
|||||||
** Interface for the Insert action.
|
** Interface for the Insert action.
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public interface InsertInterface extends QActionInterface
|
public interface InsertInterface
|
||||||
{
|
{
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
|
@ -23,6 +23,7 @@ package com.kingsrook.qqq.backend.core.actions.tables;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -52,6 +53,7 @@ import com.kingsrook.qqq.backend.core.model.actions.audits.DMLAuditInput;
|
|||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
|
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
|
||||||
@ -116,21 +118,15 @@ public class InsertAction extends AbstractQActionFunction<InsertInput, InsertOut
|
|||||||
|
|
||||||
setAutomationStatusField(insertInput);
|
setAutomationStatusField(insertInput);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
// load the backend module and its insert interface //
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
QBackendModuleInterface qModule = getBackendModuleInterface(insertInput);
|
|
||||||
InsertInterface insertInterface = qModule.getInsertInterface();
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// run standard validators //
|
// run standard validators //
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
performValidations(insertInput, false);
|
performValidations(insertInput, false);
|
||||||
|
|
||||||
////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
// have the backend do the insert //
|
// use the backend module to actually do the insert //
|
||||||
////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
InsertOutput insertOutput = insertInterface.execute(insertInput);
|
InsertOutput insertOutput = runInsertInBackend(insertInput);
|
||||||
|
|
||||||
if(insertOutput.getRecords() == null)
|
if(insertOutput.getRecords() == null)
|
||||||
{
|
{
|
||||||
@ -195,6 +191,71 @@ public class InsertAction extends AbstractQActionFunction<InsertInput, InsertOut
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
private InsertOutput runInsertInBackend(InsertInput insertInput) throws QException
|
||||||
|
{
|
||||||
|
///////////////////////////////////
|
||||||
|
// exit early if 0 input records //
|
||||||
|
///////////////////////////////////
|
||||||
|
if(CollectionUtils.nullSafeIsEmpty(insertInput.getRecords()))
|
||||||
|
{
|
||||||
|
LOG.debug("Insert request called with 0 records. Returning with no-op", logPair("tableName", insertInput.getTableName()));
|
||||||
|
InsertOutput rs = new InsertOutput();
|
||||||
|
rs.setRecords(new ArrayList<>());
|
||||||
|
return (rs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
// set values in create date & modify date //
|
||||||
|
// todo .. better (not hard-coded names) //
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
Instant now = Instant.now();
|
||||||
|
for(QRecord record : insertInput.getRecords())
|
||||||
|
{
|
||||||
|
setValueIfTableHasField(record, insertInput.getTable(), "createDate", now);
|
||||||
|
setValueIfTableHasField(record, insertInput.getTable(), "modifyDate", now);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// load the backend module and its insert interface //
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
QBackendModuleInterface qModule = getBackendModuleInterface(insertInput.getBackend());
|
||||||
|
InsertInterface insertInterface = qModule.getInsertInterface();
|
||||||
|
|
||||||
|
////////////////////////////////////
|
||||||
|
// have the backend do the insert //
|
||||||
|
////////////////////////////////////
|
||||||
|
InsertOutput insertOutput = insertInterface.execute(insertInput);
|
||||||
|
return insertOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** If the table has a field with the given name, then set the given value in the
|
||||||
|
** given record.
|
||||||
|
*******************************************************************************/
|
||||||
|
private static void setValueIfTableHasField(QRecord record, QTableMetaData table, String fieldName, Serializable value)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(table.getFields().containsKey(fieldName))
|
||||||
|
{
|
||||||
|
record.setValue(fieldName, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// this means field doesn't exist, so, ignore. //
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@ -426,23 +487,11 @@ public class InsertAction extends AbstractQActionFunction<InsertInput, InsertOut
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
private QBackendModuleInterface getBackendModuleInterface(InsertInput insertInput) throws QException
|
private QBackendModuleInterface getBackendModuleInterface(QBackendMetaData backend) throws QException
|
||||||
{
|
{
|
||||||
ActionHelper.validateSession(insertInput);
|
|
||||||
QBackendModuleDispatcher qBackendModuleDispatcher = new QBackendModuleDispatcher();
|
QBackendModuleDispatcher qBackendModuleDispatcher = new QBackendModuleDispatcher();
|
||||||
QBackendModuleInterface qModule = qBackendModuleDispatcher.getQBackendModule(insertInput.getBackend());
|
QBackendModuleInterface qModule = qBackendModuleDispatcher.getQBackendModule(backend);
|
||||||
return (qModule);
|
return (qModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
public QBackendTransaction openTransaction(InsertInput insertInput) throws QException
|
|
||||||
{
|
|
||||||
QBackendModuleInterface qModule = getBackendModuleInterface(insertInput);
|
|
||||||
return (qModule.getInsertInterface().openTransaction(insertInput));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,9 +84,7 @@ public class ReplaceAction extends AbstractQActionFunction<ReplaceInput, Replace
|
|||||||
String primaryKeyField = table.getPrimaryKeyField();
|
String primaryKeyField = table.getPrimaryKeyField();
|
||||||
if(transaction == null)
|
if(transaction == null)
|
||||||
{
|
{
|
||||||
InsertInput insertInput = new InsertInput();
|
transaction = QBackendTransaction.openFor(new InsertInput(input.getTableName()));
|
||||||
insertInput.setTableName(input.getTableName());
|
|
||||||
transaction = new InsertAction().openTransaction(insertInput);
|
|
||||||
weOwnTheTransaction = true;
|
weOwnTheTransaction = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ public class UpdateAction
|
|||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// have the backend do the update //
|
// have the backend do the update //
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
UpdateOutput updateOutput = updateInterface.execute(updateInput);
|
UpdateOutput updateOutput = runUpdateInBackend(updateInput, updateInterface);
|
||||||
|
|
||||||
if(updateOutput.getRecords() == null)
|
if(updateOutput.getRecords() == null)
|
||||||
{
|
{
|
||||||
@ -203,6 +203,28 @@ public class UpdateAction
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
private UpdateOutput runUpdateInBackend(UpdateInput updateInput, UpdateInterface updateInterface) throws QException
|
||||||
|
{
|
||||||
|
///////////////////////////////////
|
||||||
|
// exit early if 0 input records //
|
||||||
|
///////////////////////////////////
|
||||||
|
if(CollectionUtils.nullSafeIsEmpty(updateInput.getRecords()))
|
||||||
|
{
|
||||||
|
LOG.debug("Update request called with 0 records. Returning with no-op", logPair("tableName", updateInput.getTableName()));
|
||||||
|
UpdateOutput rs = new UpdateOutput();
|
||||||
|
rs.setRecords(new ArrayList<>());
|
||||||
|
return (rs);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateOutput updateOutput = updateInterface.execute(updateInput);
|
||||||
|
return updateOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -34,7 +34,6 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QValueException;
|
import com.kingsrook.qqq.backend.core.exceptions.QValueException;
|
||||||
@ -104,7 +103,7 @@ public class QPossibleValueTranslator
|
|||||||
{
|
{
|
||||||
if(!transactionsPerTable.containsKey(tableName))
|
if(!transactionsPerTable.containsKey(tableName))
|
||||||
{
|
{
|
||||||
transactionsPerTable.put(tableName, new InsertAction().openTransaction(new InsertInput(tableName)));
|
transactionsPerTable.put(tableName, QBackendTransaction.openFor(new InsertInput(tableName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (transactionsPerTable.get(tableName));
|
return (transactionsPerTable.get(tableName));
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
package com.kingsrook.qqq.backend.core.modules.backend;
|
package com.kingsrook.qqq.backend.core.modules.backend;
|
||||||
|
|
||||||
|
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.AggregateInterface;
|
import com.kingsrook.qqq.backend.core.actions.interfaces.AggregateInterface;
|
||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.CountInterface;
|
import com.kingsrook.qqq.backend.core.actions.interfaces.CountInterface;
|
||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.DeleteInterface;
|
import com.kingsrook.qqq.backend.core.actions.interfaces.DeleteInterface;
|
||||||
@ -29,6 +30,8 @@ import com.kingsrook.qqq.backend.core.actions.interfaces.GetInterface;
|
|||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.InsertInterface;
|
import com.kingsrook.qqq.backend.core.actions.interfaces.InsertInterface;
|
||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.QueryInterface;
|
import com.kingsrook.qqq.backend.core.actions.interfaces.QueryInterface;
|
||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.UpdateInterface;
|
import com.kingsrook.qqq.backend.core.actions.interfaces.UpdateInterface;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableBackendDetails;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableBackendDetails;
|
||||||
|
|
||||||
@ -126,6 +129,14 @@ public interface QBackendModuleInterface
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
default QBackendTransaction openTransaction(AbstractTableActionInput input) throws QException
|
||||||
|
{
|
||||||
|
return (new QBackendTransaction());
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -23,7 +23,6 @@ package com.kingsrook.qqq.backend.core.modules.backend.implementations.memory;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.QActionInterface;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
@ -32,7 +31,7 @@ import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Base class for all core actions in the Memory backend module.
|
** Base class for all core actions in the Memory backend module.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public abstract class AbstractMemoryAction implements QActionInterface
|
public abstract class AbstractMemoryAction
|
||||||
{
|
{
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -22,13 +22,10 @@
|
|||||||
package com.kingsrook.qqq.backend.core.modules.backend.implementations.memory;
|
package com.kingsrook.qqq.backend.core.modules.backend.implementations.memory;
|
||||||
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import com.kingsrook.qqq.backend.core.actions.interfaces.InsertInterface;
|
import com.kingsrook.qqq.backend.core.actions.interfaces.InsertInterface;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -45,18 +42,6 @@ public class MemoryInsertAction extends AbstractMemoryAction implements InsertIn
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QTableMetaData table = insertInput.getTable();
|
|
||||||
Instant now = Instant.now();
|
|
||||||
|
|
||||||
for(QRecord record : insertInput.getRecords())
|
|
||||||
{
|
|
||||||
///////////////////////////////////////////
|
|
||||||
// todo .. better (not hard-coded names) //
|
|
||||||
///////////////////////////////////////////
|
|
||||||
setValueIfTableHasField(record, table, "createDate", now, false);
|
|
||||||
setValueIfTableHasField(record, table, "modifyDate", now, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
InsertOutput insertOutput = new InsertOutput();
|
InsertOutput insertOutput = new InsertOutput();
|
||||||
insertOutput.setRecords(MemoryRecordStore.getInstance().insert(insertInput, true));
|
insertOutput.setRecords(MemoryRecordStore.getInstance().insert(insertInput, true));
|
||||||
return (insertOutput);
|
return (insertOutput);
|
||||||
|
@ -27,7 +27,6 @@ import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
|||||||
import com.kingsrook.qqq.backend.core.actions.async.AsyncRecordPipeLoop;
|
import com.kingsrook.qqq.backend.core.actions.async.AsyncRecordPipeLoop;
|
||||||
import com.kingsrook.qqq.backend.core.actions.processes.BackendStep;
|
import com.kingsrook.qqq.backend.core.actions.processes.BackendStep;
|
||||||
import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe;
|
import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe;
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||||
@ -116,7 +115,7 @@ public class StreamedETLBackendStep implements BackendStep
|
|||||||
|
|
||||||
insertInput.setTableName(runBackendStepInput.getValueString(BasicETLProcess.FIELD_DESTINATION_TABLE));
|
insertInput.setTableName(runBackendStepInput.getValueString(BasicETLProcess.FIELD_DESTINATION_TABLE));
|
||||||
|
|
||||||
return new InsertAction().openTransaction(insertInput);
|
return QBackendTransaction.openFor(insertInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.DeleteAction;
|
import com.kingsrook.qqq.backend.core.actions.tables.DeleteAction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||||
@ -34,7 +33,6 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.InputSource;
|
|||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.QInputSource;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.QInputSource;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
|
|
||||||
|
|
||||||
@ -87,9 +85,8 @@ public class LoadViaDeleteStep extends AbstractLoadStep
|
|||||||
@Override
|
@Override
|
||||||
public Optional<QBackendTransaction> openTransaction(RunBackendStepInput runBackendStepInput) throws QException
|
public Optional<QBackendTransaction> openTransaction(RunBackendStepInput runBackendStepInput) throws QException
|
||||||
{
|
{
|
||||||
InsertInput insertInput = new InsertInput();
|
DeleteInput deleteInput = new DeleteInput();
|
||||||
insertInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
deleteInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||||
|
return (Optional.of(QBackendTransaction.openFor(deleteInput)));
|
||||||
return (Optional.of(new InsertAction().openTransaction(insertInput)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,8 +129,7 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
|||||||
{
|
{
|
||||||
InsertInput insertInput = new InsertInput();
|
InsertInput insertInput = new InsertInput();
|
||||||
insertInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
insertInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||||
|
return (Optional.of(QBackendTransaction.openFor(insertInput)));
|
||||||
return (Optional.of(new InsertAction().openTransaction(insertInput)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +88,6 @@ public class LoadViaInsertStep extends AbstractLoadStep
|
|||||||
{
|
{
|
||||||
InsertInput insertInput = new InsertInput();
|
InsertInput insertInput = new InsertInput();
|
||||||
insertInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
insertInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||||
|
return (Optional.of(QBackendTransaction.openFor(insertInput)));
|
||||||
return (Optional.of(new InsertAction().openTransaction(insertInput)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,12 @@ package com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwit
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
|
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.InputSource;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.InputSource;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.QInputSource;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.QInputSource;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
|
||||||
|
|
||||||
@ -81,9 +79,8 @@ public class LoadViaUpdateStep extends AbstractLoadStep
|
|||||||
@Override
|
@Override
|
||||||
public Optional<QBackendTransaction> openTransaction(RunBackendStepInput runBackendStepInput) throws QException
|
public Optional<QBackendTransaction> openTransaction(RunBackendStepInput runBackendStepInput) throws QException
|
||||||
{
|
{
|
||||||
InsertInput insertInput = new InsertInput();
|
UpdateInput updateInput = new UpdateInput();
|
||||||
insertInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
updateInput.setTableName(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||||
|
return (Optional.of(QBackendTransaction.openFor(updateInput)));
|
||||||
return (Optional.of(new InsertAction().openTransaction(insertInput)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class StoreScriptRevisionProcessStep implements BackendStep
|
|||||||
InsertAction insertAction = new InsertAction();
|
InsertAction insertAction = new InsertAction();
|
||||||
InsertInput insertInput = new InsertInput();
|
InsertInput insertInput = new InsertInput();
|
||||||
insertInput.setTableName(ScriptRevision.TABLE_NAME);
|
insertInput.setTableName(ScriptRevision.TABLE_NAME);
|
||||||
QBackendTransaction transaction = insertAction.openTransaction(insertInput);
|
QBackendTransaction transaction = QBackendTransaction.openFor(insertInput);
|
||||||
insertInput.setTransaction(transaction);
|
insertInput.setTransaction(transaction);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -156,10 +156,10 @@ class RunAssociatedScriptActionTest extends BaseTest
|
|||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
assertEquals(N, TestUtils.queryTable(ScriptLog.TABLE_NAME).size());
|
assertEquals(N, TestUtils.queryTable(ScriptLog.TABLE_NAME).size());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// and we should have just ran 2 inserts - for the log & logLines (even though empty) //
|
// and we should have just ran 1 inserts - for the log (no longer run one for empty insert of 0 log-lines) //
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
assertEquals(2, MemoryRecordStore.getStatistics().get(MemoryRecordStore.STAT_INSERTS_RAN));
|
assertEquals(1, MemoryRecordStore.getStatistics().get(MemoryRecordStore.STAT_INSERTS_RAN));
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// and we shouldn't have run N queries (which we would have (at least), if we would have built a new Action object inside the loop) //
|
// and we shouldn't have run N queries (which we would have (at least), if we would have built a new Action object inside the loop) //
|
||||||
|
@ -74,7 +74,7 @@ class GarbageCollectorTest extends BaseTest
|
|||||||
@Test
|
@Test
|
||||||
void testBasic() throws QException
|
void testBasic() throws QException
|
||||||
{
|
{
|
||||||
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_PERSON_MEMORY, "createDate", NowWithOffset.minus(30, ChronoUnit.DAYS), null);
|
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_PERSON_MEMORY, "timestamp", NowWithOffset.minus(30, ChronoUnit.DAYS), null);
|
||||||
QContext.getQInstance().addProcess(process);
|
QContext.getQInstance().addProcess(process);
|
||||||
|
|
||||||
new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_PERSON_MEMORY).withRecords(getPersonRecords()));
|
new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_PERSON_MEMORY).withRecords(getPersonRecords()));
|
||||||
@ -97,11 +97,11 @@ class GarbageCollectorTest extends BaseTest
|
|||||||
private static List<QRecord> getPersonRecords()
|
private static List<QRecord> getPersonRecords()
|
||||||
{
|
{
|
||||||
List<QRecord> records = List.of(
|
List<QRecord> records = List.of(
|
||||||
new QRecord().withValue("id", 1).withValue("createDate", Instant.now().minus(90, ChronoUnit.DAYS)),
|
new QRecord().withValue("id", 1).withValue("timestamp", Instant.now().minus(90, ChronoUnit.DAYS)),
|
||||||
new QRecord().withValue("id", 2).withValue("createDate", Instant.now().minus(31, ChronoUnit.DAYS)),
|
new QRecord().withValue("id", 2).withValue("timestamp", Instant.now().minus(31, ChronoUnit.DAYS)),
|
||||||
new QRecord().withValue("id", 3).withValue("createDate", Instant.now().minus(30, ChronoUnit.DAYS).minus(5, ChronoUnit.MINUTES)),
|
new QRecord().withValue("id", 3).withValue("timestamp", Instant.now().minus(30, ChronoUnit.DAYS).minus(5, ChronoUnit.MINUTES)),
|
||||||
new QRecord().withValue("id", 4).withValue("createDate", Instant.now().minus(29, ChronoUnit.DAYS).minus(23, ChronoUnit.HOURS)),
|
new QRecord().withValue("id", 4).withValue("timestamp", Instant.now().minus(29, ChronoUnit.DAYS).minus(23, ChronoUnit.HOURS)),
|
||||||
new QRecord().withValue("id", 5).withValue("createDate", Instant.now().minus(5, ChronoUnit.DAYS)));
|
new QRecord().withValue("id", 5).withValue("timestamp", Instant.now().minus(5, ChronoUnit.DAYS)));
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ class GarbageCollectorTest extends BaseTest
|
|||||||
@Test
|
@Test
|
||||||
void testOverrideDate() throws QException
|
void testOverrideDate() throws QException
|
||||||
{
|
{
|
||||||
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_PERSON_MEMORY, "createDate", NowWithOffset.minus(30, ChronoUnit.DAYS), null);
|
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_PERSON_MEMORY, "timestamp", NowWithOffset.minus(30, ChronoUnit.DAYS), null);
|
||||||
QContext.getQInstance().addProcess(process);
|
QContext.getQInstance().addProcess(process);
|
||||||
|
|
||||||
new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_PERSON_MEMORY).withRecords(getPersonRecords()));
|
new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_PERSON_MEMORY).withRecords(getPersonRecords()));
|
||||||
@ -157,7 +157,7 @@ class GarbageCollectorTest extends BaseTest
|
|||||||
@Test
|
@Test
|
||||||
void testWithDeleteAllJoins() throws QException
|
void testWithDeleteAllJoins() throws QException
|
||||||
{
|
{
|
||||||
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_ORDER, "createDate", NowWithOffset.minus(30, ChronoUnit.DAYS), "*");
|
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_ORDER, "timestamp", NowWithOffset.minus(30, ChronoUnit.DAYS), "*");
|
||||||
QContext.getQInstance().addProcess(process);
|
QContext.getQInstance().addProcess(process);
|
||||||
|
|
||||||
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE_ALL_ACCESS, true);
|
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE_ALL_ACCESS, true);
|
||||||
@ -192,7 +192,7 @@ class GarbageCollectorTest extends BaseTest
|
|||||||
@Test
|
@Test
|
||||||
void testWithDeleteSomeJoins() throws QException
|
void testWithDeleteSomeJoins() throws QException
|
||||||
{
|
{
|
||||||
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_ORDER, "createDate", NowWithOffset.minus(30, ChronoUnit.DAYS), TestUtils.TABLE_NAME_LINE_ITEM);
|
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_ORDER, "timestamp", NowWithOffset.minus(30, ChronoUnit.DAYS), TestUtils.TABLE_NAME_LINE_ITEM);
|
||||||
QContext.getQInstance().addProcess(process);
|
QContext.getQInstance().addProcess(process);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -232,7 +232,7 @@ class GarbageCollectorTest extends BaseTest
|
|||||||
@Test
|
@Test
|
||||||
void testWithDeleteNoJoins() throws QException
|
void testWithDeleteNoJoins() throws QException
|
||||||
{
|
{
|
||||||
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_ORDER, "createDate", NowWithOffset.minus(30, ChronoUnit.DAYS), null);
|
QProcessMetaData process = GarbageCollectorProcessMetaDataProducer.createProcess(TestUtils.TABLE_NAME_ORDER, "timestamp", NowWithOffset.minus(30, ChronoUnit.DAYS), null);
|
||||||
QContext.getQInstance().addProcess(process);
|
QContext.getQInstance().addProcess(process);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -270,11 +270,11 @@ class GarbageCollectorTest extends BaseTest
|
|||||||
private static List<QRecord> getOrderRecords()
|
private static List<QRecord> getOrderRecords()
|
||||||
{
|
{
|
||||||
List<QRecord> records = List.of(
|
List<QRecord> records = List.of(
|
||||||
new QRecord().withValue("id", 1).withValue("createDate", Instant.now().minus(90, ChronoUnit.DAYS)),
|
new QRecord().withValue("id", 1).withValue("timestamp", Instant.now().minus(90, ChronoUnit.DAYS)),
|
||||||
new QRecord().withValue("id", 2).withValue("createDate", Instant.now().minus(31, ChronoUnit.DAYS)),
|
new QRecord().withValue("id", 2).withValue("timestamp", Instant.now().minus(31, ChronoUnit.DAYS)),
|
||||||
new QRecord().withValue("id", 3).withValue("createDate", Instant.now().minus(30, ChronoUnit.DAYS).minus(5, ChronoUnit.MINUTES)),
|
new QRecord().withValue("id", 3).withValue("timestamp", Instant.now().minus(30, ChronoUnit.DAYS).minus(5, ChronoUnit.MINUTES)),
|
||||||
new QRecord().withValue("id", 4).withValue("createDate", Instant.now().minus(29, ChronoUnit.DAYS).minus(23, ChronoUnit.HOURS)),
|
new QRecord().withValue("id", 4).withValue("timestamp", Instant.now().minus(29, ChronoUnit.DAYS).minus(23, ChronoUnit.HOURS)),
|
||||||
new QRecord().withValue("id", 5).withValue("createDate", Instant.now().minus(5, ChronoUnit.DAYS)));
|
new QRecord().withValue("id", 5).withValue("timestamp", Instant.now().minus(5, ChronoUnit.DAYS)));
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,7 +549,9 @@ public class TestUtils
|
|||||||
.withField(new QFieldMetaData("cost", QFieldType.DECIMAL).withDisplayFormat(DisplayFormat.CURRENCY))
|
.withField(new QFieldMetaData("cost", QFieldType.DECIMAL).withDisplayFormat(DisplayFormat.CURRENCY))
|
||||||
.withField(new QFieldMetaData("price", QFieldType.DECIMAL).withDisplayFormat(DisplayFormat.CURRENCY))
|
.withField(new QFieldMetaData("price", QFieldType.DECIMAL).withDisplayFormat(DisplayFormat.CURRENCY))
|
||||||
.withField(new QFieldMetaData("ssn", QFieldType.STRING).withType(QFieldType.PASSWORD))
|
.withField(new QFieldMetaData("ssn", QFieldType.STRING).withType(QFieldType.PASSWORD))
|
||||||
.withField(new QFieldMetaData("superSecret", QFieldType.STRING).withType(QFieldType.PASSWORD).withIsHidden(true));
|
.withField(new QFieldMetaData("superSecret", QFieldType.STRING).withType(QFieldType.PASSWORD).withIsHidden(true))
|
||||||
|
.withField(new QFieldMetaData("timestamp", QFieldType.DATE_TIME)) // adding this for GC tests, so we can set a date-time (since CD & MD are owned by system)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -602,6 +604,7 @@ public class TestUtils
|
|||||||
.withField(new QFieldMetaData("id", QFieldType.INTEGER).withIsEditable(false))
|
.withField(new QFieldMetaData("id", QFieldType.INTEGER).withIsEditable(false))
|
||||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withIsEditable(false))
|
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||||
|
.withField(new QFieldMetaData("timestamp", QFieldType.DATE_TIME)) // adding this for GC tests, so we can set a date-time (since CD & MD are owned by system)
|
||||||
.withField(new QFieldMetaData("orderId", QFieldType.INTEGER))
|
.withField(new QFieldMetaData("orderId", QFieldType.INTEGER))
|
||||||
.withField(new QFieldMetaData("lineNumber", QFieldType.STRING))
|
.withField(new QFieldMetaData("lineNumber", QFieldType.STRING))
|
||||||
.withField(new QFieldMetaData("sku", QFieldType.STRING).withLabel("SKU"))
|
.withField(new QFieldMetaData("sku", QFieldType.STRING).withLabel("SKU"))
|
||||||
|
Reference in New Issue
Block a user