mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Try to make sure values that this backend stores are of the appropriate field types.
This commit is contained in:
@ -74,6 +74,7 @@ import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
|||||||
import com.kingsrook.qqq.backend.core.utils.ListingHash;
|
import com.kingsrook.qqq.backend.core.utils.ListingHash;
|
||||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||||
|
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -364,6 +365,9 @@ public class MemoryRecordStore
|
|||||||
// differently from other backends, because of having the same record variable in the backend store and in the user-code. //
|
// differently from other backends, because of having the same record variable in the backend store and in the user-code. //
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
QRecord recordToInsert = new QRecord(record);
|
QRecord recordToInsert = new QRecord(record);
|
||||||
|
|
||||||
|
makeValueTypesMatchFieldTypes(table, recordToInsert);
|
||||||
|
|
||||||
if(CollectionUtils.nullSafeHasContents(recordToInsert.getErrors()))
|
if(CollectionUtils.nullSafeHasContents(recordToInsert.getErrors()))
|
||||||
{
|
{
|
||||||
outputRecords.add(recordToInsert);
|
outputRecords.add(recordToInsert);
|
||||||
@ -414,6 +418,30 @@ public class MemoryRecordStore
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
private static void makeValueTypesMatchFieldTypes(QTableMetaData table, QRecord recordToInsert)
|
||||||
|
{
|
||||||
|
for(QFieldMetaData field : table.getFields().values())
|
||||||
|
{
|
||||||
|
Serializable value = recordToInsert.getValue(field.getName());
|
||||||
|
if(value != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
recordToInsert.setValue(field.getName(), ValueUtils.getValueAsFieldType(field.getType(), value));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
LOG.info("Error converting value to field's type", e, logPair("fieldName", field.getName()), logPair("value", value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@ -444,7 +472,19 @@ public class MemoryRecordStore
|
|||||||
QRecord recordToUpdate = tableData.get(primaryKeyValue);
|
QRecord recordToUpdate = tableData.get(primaryKeyValue);
|
||||||
for(Map.Entry<String, Serializable> valueEntry : record.getValues().entrySet())
|
for(Map.Entry<String, Serializable> valueEntry : record.getValues().entrySet())
|
||||||
{
|
{
|
||||||
recordToUpdate.setValue(valueEntry.getKey(), valueEntry.getValue());
|
String fieldName = valueEntry.getKey();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
// try to make field values match field type //
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
recordToUpdate.setValue(fieldName, ValueUtils.getValueAsFieldType(table.getField(fieldName).getType(), valueEntry.getValue()));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
LOG.info("Error converting value to field's type", e, logPair("fieldName", fieldName), logPair("value", valueEntry.getValue()));
|
||||||
|
recordToUpdate.setValue(fieldName, valueEntry.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(returnUpdatedRecords)
|
if(returnUpdatedRecords)
|
||||||
|
Reference in New Issue
Block a user