Update to actually use defaultValues when inserting records - nulls become the default.

This commit is contained in:
2023-10-16 08:41:57 -05:00
parent af852b0612
commit d28426562a
2 changed files with 54 additions and 0 deletions

View File

@ -205,6 +205,8 @@ public class InsertAction extends AbstractQActionFunction<InsertInput, InsertOut
runPreInsertCustomizerIfItIsTime(insertInput, preInsertCustomizer, AbstractPreInsertCustomizer.WhenToRun.BEFORE_ALL_VALIDATIONS);
}
setDefaultValuesInRecords(table, insertInput.getRecords());
ValueBehaviorApplier.applyFieldBehaviors(insertInput.getInstance(), table, insertInput.getRecords());
runPreInsertCustomizerIfItIsTime(insertInput, preInsertCustomizer, AbstractPreInsertCustomizer.WhenToRun.BEFORE_UNIQUE_KEY_CHECKS);
@ -224,6 +226,32 @@ public class InsertAction extends AbstractQActionFunction<InsertInput, InsertOut
/*******************************************************************************
**
*******************************************************************************/
private void setDefaultValuesInRecords(QTableMetaData table, List<QRecord> records)
{
////////////////////////////////////////////////////////////////////////////////////////////////
// for all fields in the table - if any have a default value, then look at all input records, //
// and if they have null value, then apply the default //
////////////////////////////////////////////////////////////////////////////////////////////////
for(QFieldMetaData field : table.getFields().values())
{
if(field.getDefaultValue() != null)
{
for(QRecord record : records)
{
if(record.getValue(field.getName()) == null)
{
record.setValue(field.getName(), field.getDefaultValue());
}
}
}
}
}
/*******************************************************************************
**
*******************************************************************************/