// create the expressions index (columns index)
int parametersIndex[] = new int[m.getNumberOfDatastoreMappings()];
for (int j = 0; j < parametersIndex.length; j++)
{
// check if the column was not already assigned
Column c = (Column)m.getDatastoreMapping(j).getDatastoreField();
DatastoreIdentifier columnId = c.getIdentifier();
boolean columnExists = assignedColumns.containsKey(columnId.toString());
if (columnExists)
{
parametersIndex[j] = ((Integer)assignedColumns.get(c.getIdentifier().toString())).intValue();
}
// Either we are a field in a secondary table.
// Or we are a subclass table.
// Or we are not datastore attributed.
if (table instanceof SecondaryTable || !table.isBaseDatastoreClass() ||
(!table.getStoreManager().isStrategyDatastoreAttributed(fmd.getValueStrategy(), false) && !c.isIdentity()))
{
if (!columnExists)
{
if (columnNames.length() > 0)
{
columnNames.append(',');
columnValues.append(',');
}
columnNames.append(columnId);
columnValues.append(((RDBMSMapping)m.getDatastoreMapping(j)).getInsertionInputParameter());
}
if (((RDBMSMapping)m.getDatastoreMapping(j)).insertValuesOnInsert())
{
// only add fields to be replaced by the real values only if the param value has ?
Integer abs_field_num = Integer.valueOf(fmd.getAbsoluteFieldNumber());
if (fmd.isPrimaryKey())
{
if (!pkFields.contains(abs_field_num))
{
pkFields.add(abs_field_num);
}
}
else if (!insertFields.contains(abs_field_num))
{
insertFields.add(abs_field_num);
}
if (columnExists)
{
parametersIndex[j] = ((Integer)assignedColumns.get(c.getIdentifier().toString())).intValue();
}
else
{
parametersIndex[j] = paramIndex++;
}
}
if (!columnExists)
{
assignedColumns.put(c.getIdentifier().toString(), Integer.valueOf(fmd.getAbsoluteFieldNumber()));
}
}
else
{
hasIdentityColumn = true;