mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
sprint-14: minor updates to allow flexibility when extending loadviainsertorupdatestep
This commit is contained in:
@ -37,6 +37,7 @@ 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.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -49,6 +50,9 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
||||
{
|
||||
public static final String FIELD_DESTINATION_TABLE = "destinationTable";
|
||||
|
||||
protected List<QRecord> recordsToInsert = null;
|
||||
protected List<QRecord> recordsToUpdate = null;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -59,21 +63,9 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
||||
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||
{
|
||||
QTableMetaData tableMetaData = runBackendStepInput.getInstance().getTable(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||
List<QRecord> recordsToInsert = new ArrayList<>();
|
||||
List<QRecord> recordsToUpdate = new ArrayList<>();
|
||||
for(QRecord record : runBackendStepInput.getRecords())
|
||||
{
|
||||
if(record.getValue(tableMetaData.getPrimaryKeyField()) == null)
|
||||
{
|
||||
recordsToInsert.add(record);
|
||||
}
|
||||
else
|
||||
{
|
||||
recordsToUpdate.add(record);
|
||||
}
|
||||
}
|
||||
evaluateRecords(runBackendStepInput);
|
||||
|
||||
if(!recordsToInsert.isEmpty())
|
||||
if(CollectionUtils.nullSafeHasContents(recordsToInsert))
|
||||
{
|
||||
InsertInput insertInput = new InsertInput(runBackendStepInput.getInstance());
|
||||
insertInput.setSession(runBackendStepInput.getSession());
|
||||
@ -84,7 +76,7 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
||||
runBackendStepOutput.getRecords().addAll(insertOutput.getRecords());
|
||||
}
|
||||
|
||||
if(!recordsToUpdate.isEmpty())
|
||||
if(CollectionUtils.nullSafeHasContents(recordsToUpdate))
|
||||
{
|
||||
UpdateInput updateInput = new UpdateInput(runBackendStepInput.getInstance());
|
||||
updateInput.setSession(runBackendStepInput.getSession());
|
||||
@ -110,4 +102,27 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
||||
|
||||
return (Optional.of(new InsertAction().openTransaction(insertInput)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
protected void evaluateRecords(RunBackendStepInput runBackendStepInput) throws QException
|
||||
{
|
||||
QTableMetaData tableMetaData = runBackendStepInput.getInstance().getTable(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||
recordsToInsert = new ArrayList<>();
|
||||
recordsToUpdate = new ArrayList<>();
|
||||
for(QRecord record : runBackendStepInput.getRecords())
|
||||
{
|
||||
if(record.getValue(tableMetaData.getPrimaryKeyField()) == null)
|
||||
{
|
||||
recordsToInsert.add(record);
|
||||
}
|
||||
else
|
||||
{
|
||||
recordsToUpdate.add(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ public class BaseAPIActionUtil
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private JSONObject getJsonObject(HttpResponse response) throws IOException
|
||||
protected JSONObject getJsonObject(HttpResponse response) throws IOException
|
||||
{
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
LOG.debug(statusCode);
|
||||
|
Reference in New Issue
Block a user