String setStmt = getSetStmt();
String unsetStmt = getUnsetStmt();
try
{
ObjectManager om = sm.getObjectManager();
ManagedConnection mconn = storeMgr.getConnection(om);
SQLController sqlControl = storeMgr.getSQLController();
try
{
// Unset the existing object from this position
PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, unsetStmt, false);
try
{
int jdbcPosition = 1;
jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
if (orderMapping != null)
{
jdbcPosition = populateOrderInStatement(om, ps, index, jdbcPosition);
}
if (relationDiscriminatorMapping != null)
{
jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
}
sqlControl.executeStatementUpdate(mconn, unsetStmt, ps, true);
}
finally
{
sqlControl.closeStatement(mconn, ps);
}
// Set the new object at this position
PreparedStatement ps2 = sqlControl.getStatementForUpdate(mconn, setStmt, false);
try
{
int jdbcPosition = 1;
jdbcPosition = populateOwnerInStatement(sm, om, ps2, jdbcPosition);
if (orderMapping != null)
{
jdbcPosition = populateOrderInStatement(om, ps2, index, jdbcPosition);
}
if (relationDiscriminatorMapping != null)
{
jdbcPosition = populateRelationDiscriminatorInStatement(om, ps2, jdbcPosition);
}
jdbcPosition = populateElementInStatement(om, ps2, element, jdbcPosition);
sqlControl.executeStatementUpdate(mconn, setStmt, ps2, true);
}
finally
{
ps2.close();
}
}
finally
{
mconn.release();
}
}
catch (SQLException e)
{
throw new JPOXDataStoreException(LOCALISER.msg("056015", setStmt), e);