* @param instance The instance for which to add the work items.
*/
protected void addInsert(UnitOfWork uow, Instance instance)
{
RelationalMapping relMapping = (RelationalMapping)instance.getPersistenceMapping();
Table primaryTable = relMapping.getPrimaryTable();
SQLWork primaryWork = getWork(uow, SQLWork.INSERT, instance, primaryTable);
OID oid = instance.getOID();
if (oid != null)
{
primaryWork.setOID();
}
else
{
Component component = relMapping.getKeyGenerator();
if (component == RelationalMapping.KEY_GEN_IDENTITY)
{
primaryWork.setIdentity(true);
}
else if (component != null)
{
oid = ((OIDGenerator)component.getInstance(uow.getInvocationContext())).generateOID(instance, this);
Object[] values = oid.getValueArray();
Index pk = primaryTable.getPrimaryKey();
int nCount = pk.getIndexColumnCount();
if (nCount != values.length)
{
throw new PersistenceException("err.persistence.oidValueCount",
new Object[]{component.getName(), Primitive.createInteger(nCount),
Primitive.createInteger(values.length)});
}
for (int i = 0; i < nCount; ++i)
{
values[i] = pk.getIndexColumn(i).getColumn().getValueType().convert(values[i]);
}
instance.setOID(oid);
primaryWork.setOID();
}
else
{
Metaclass metaclass = instance.getMetaclass();
for (int i = 0, n = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
{
Attribute attribute = metaclass.getInstanceAttribute(i);
AttributeMapping mapping = relMapping.getAttributeMapping(attribute);
int nPrimaryColCount = primaryTable.getPrimaryKey().getIndexColumnCount();
if (mapping instanceof RelationalPrimitiveMapping)
{
Column column = ((RelationalPrimitiveMapping)mapping).getColumn();