Fix for Issue 32 Deleted bean not removed from PersistenceContext

This commit is contained in:
Robin Bygrave
2013-06-27 23:23:20 +12:00
parent 4bbbad9b3b
commit 4f2f9a2e99
3 changed files with 86 additions and 17 deletions
@@ -176,23 +176,26 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
return beanPersistListener != null;
}
public void notifyCache() {
if (notifyCache) {
switch (type) {
case INSERT:
beanDescriptor.cacheInsert(idValue, this);
break;
case UPDATE:
beanDescriptor.cacheUpdate(idValue, this);
break;
case DELETE:
beanDescriptor.cacheDelete(idValue, this);
break;
default:
throw new IllegalStateException("Invalid type "+type);
}
}
}
/**
* Notify/Update the local L2 cache after the transaction has successfully committed.
*/
public void notifyCache() {
if (notifyCache) {
switch (type) {
case INSERT:
beanDescriptor.cacheInsert(idValue, this);
break;
case UPDATE:
beanDescriptor.cacheUpdate(idValue, this);
break;
case DELETE:
// Bean deleted from cache early via postDelete()
break;
default:
throw new IllegalStateException("Invalid type " + type);
}
}
}
public void addToPersistMap(BeanPersistIdMap beanPersistMap) {
@@ -510,6 +513,14 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
}
}
public void postDelete() {
// Delete the bean from the PersistenceContent
transaction.getPersistenceContext().clear(beanDescriptor.getBeanType(), idValue);
// Delete from cache early even if transaction fails
beanDescriptor.cacheDelete(idValue, this);
}
/**
* Post processing.
*/
@@ -52,6 +52,9 @@ public class DeleteHandler extends DmlHandler {
public void execute() throws SQLException, OptimisticLockException {
int rowCount = dataBind.executeUpdate();
checkRowCount(rowCount);
// Deletes the bean from the PersistenceContext
persistRequest.postDelete();
}
@Override