{
oldValue = null;
exists = false;
}
ObjectManager om = sm.getObjectManager();
if (exists)
{
try
{
ManagedConnection mconn = storeMgr.getConnection(om);
SQLController sqlControl = storeMgr.getSQLController();
try
{
PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, removeStmt, false);
try
{
int jdbcPosition = 1;
jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
jdbcPosition = populateKeyInStatement(om, ps, key, jdbcPosition);
sqlControl.executeStatementUpdate(mconn, removeStmt, ps, true);
}
finally
{
sqlControl.closeStatement(mconn, ps);
}
}
finally
{
mconn.release();
}
}
catch (SQLException e)
{
throw new JPOXDataStoreException(LOCALISER.msg("056012",removeStmt),e);
}
}
MapMetaData mapmd = ownerMemberMetaData.getMap();
ApiAdapter api = om.getApiAdapter();
if (mapmd.isDependentKey() && !mapmd.isEmbeddedKey() && api.isPersistable(key))
{
// Delete the key if it is dependent
om.deleteObjectInternal(key);
}
if (mapmd.isDependentValue() && !mapmd.isEmbeddedValue() && api.isPersistable(oldValue))
{
if (!containsValue(sm, oldValue))
{
// Delete the value if it is dependent and is not keyed by another key
om.deleteObjectInternal(oldValue);
}
}
return oldValue;
}