[EMAIL PROTECTED] wrote:
Hi all,What do you expect instead? Another exception e.g. PersistenceBrokerException say that the object does not exists,
we use optimistic locking using timestamp. is there a best practice to not get the OptimisticLockException (returned by the method JdbcAccessImpl.executeDelete(ClassDescriptor cld, Object obj) ) when we try to delete a non-existent object in a database ?
or should the method return without any exception thrown (e.g. only
a log info message)?
Below you can find a workaround for your problem by adding a new method to JdbcAccessImpl class. When the statement does not match, check before throw an OptimisticLockingException if object does exist. But I don't know that this will be the best way to fix your problem.
regards, Armin
### change in excute delete (line ~132)
if (stmt.executeUpdate() == 0 && cld.isLocking()) //BRJ
{
if(checkExistence(cld, obj))
{
throw new OptimisticLockException("Object has been modified by someone else", obj);
}
else
{
logger.info("Seems Object "+obj+" does not exist, can't delete.");
}
}
### add method
private boolean checkExistence(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
{
boolean result = false;
PreparedStatement stmt = null;
ResultSet rs = null;
try
{
stmt = broker.serviceStatementManager().getSelectByPKStatement(cld);
broker.serviceStatementManager().bindSelect(stmt, new Identity(obj, broker), cld);
rs = stmt.executeQuery();
if(rs.next()) result = true;
}
catch (SQLException e)
{
throw new PersistenceBrokerSQLException("Can't check existence of object: " + obj, e);
}
finally
{
if(stmt != null)
{
broker.serviceStatementManager().closeResources(stmt, rs);
}
}
return result;
}
Obviously, we want to keep the locking='true' in the cld.
Thanks!
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
