CE-1546 - feedback from code review

This commit is contained in:
t-samples
2024-08-26 12:14:01 -05:00
parent 20a5130757
commit fc4e69f059
2 changed files with 5 additions and 19 deletions

View File

@ -146,7 +146,7 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
// todo sql customization - can edit sql and/or param list
// todo - non-serial-id style tables
// todo - other generated values, e.g., createDate... maybe need to re-select?
List<Serializable> idList = QueryManager.executeInsertForGeneratedIds(connection, sql.toString(), params, table.getFields());
List<Serializable> idList = QueryManager.executeInsertForGeneratedIds(connection, sql.toString(), params, table.getField(table.getPrimaryKeyField()).getType());
int index = 0;
for(QRecord record : page)
{

View File

@ -51,10 +51,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.logging.QLogger;
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.possiblevalues.PossibleValueEnum;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
@ -529,7 +527,7 @@ public class QueryManager
/*******************************************************************************
** todo - needs (specific) unit test
*******************************************************************************/
public static List<Serializable> executeInsertForGeneratedIds(Connection connection, String sql, List<Object> params, Map<String, QFieldMetaData> fields) throws SQLException
public static List<Serializable> executeInsertForGeneratedIds(Connection connection, String sql, List<Object> params, QFieldType idType) throws SQLException
{
try(PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS))
{
@ -538,23 +536,11 @@ public class QueryManager
statement.executeUpdate();
/////////////////////////////////////////////////////////////
// We default to idType of INTEGER but if we are passed in //
// fields attempt to find the dataType of the id field //
// We default to idType of INTEGER if it was not passed in //
/////////////////////////////////////////////////////////////
QFieldType idType = QFieldType.INTEGER;
if(fields != null && !fields.isEmpty())
if(idType == null)
{
Optional<QFieldMetaData> field = fields.values().stream()
.filter(f -> f.getName().equals("id"))
.findFirst();
if(field.isPresent())
{
/////////////////////////////////////////////////////////
// if we find "id" field get the type and use it below //
/////////////////////////////////////////////////////////
idType = field.get().getType();
}
idType = QFieldType.INTEGER;
}
ResultSet generatedKeys = statement.getGeneratedKeys();