• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Toplink Cache removing on delete objects from database manually

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using Toplink 9.0.3,SoftCacheWeakIdentityMap and JMS cache coordination. Is there any way we can delete the objects from cache when objects manually deleting from DB directly. We were able to succeed for DB manual updates but not for delete.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The UnitOfWorkChangeSet has a set of deleted objects that you can register an ObjectChangeSet with to have it deleted in the cluster.

You could also invalidate the object, but this is not available in 9.0.3.
 
allareddy suneel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks James for the response.
I have tried and it is not functioning as expected. Basically delete objects will remove the objects from session.removeFromIdentityMap(), we are using SoftCacheWeakIdentityMap as a policy so i am assuming it will not remove the object immediately (though from DB it is deleted the object but not from other applications in which object is in session). Please let me know if my understanding correct.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you broadcast the UnitOfWorkChangeSet with the deleted objects yourself, it should remove them from the cache of all of the other applications.

Perhaps include the code you are using?

Note that since the remove object is removed on the database, the only way to find it on another server would be to query it by Id and get a cache hit.
 
allareddy suneel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,
Please find the code for updates as well as deletes.

public static boolean cacheInvalidate(String entityName, String entityId)
throws Exception {

Class baseTableName = Class.forName(entityName);

Session session = getSession();
UnitOfWork uow = session.acquireUnitOfWork();
Object objectTobeRefreshed = null;
Object objectBackup = null;
Vector primaryKeysList = new Vector();
primaryKeysList.add(entityId);
if (session.containsObjectInIdentityMap(primaryKeysList, baseTableName)) {
objectTobeRefreshed = session.getFromIdentityMap(primaryKeysList,
baseTableName);
}else{
objectTobeRefreshed = findByIdByCacheRefresh(baseTableName,
getPrimaryKey(session, entityName), entityId);
}

if(objectTobeRefreshed==null) return false;

Descriptor descriptor = getDescriptor(session, entityName);
objectBackup = descriptor.getObjectBuilder().instantiateClone(
objectTobeRefreshed,
(oracle.toplink.publicinterface.Session) uow);

objectTobeRefreshed = findByIdByCacheRefresh(baseTableName,
getPrimaryKey(session, entityName), entityId);

UnitOfWorkChangeSet changeSet = new UnitOfWorkChangeSet();
ObjectChangeSet objectChangeSet = null;
if(objectTobeRefreshed==null){//for delete
objectChangeSet = descriptor.getObjectBuilder().createObjectChangeSet(objectBackup, changeSet, false, (oracle.toplink.publicinterface.Session) uow);

changeSet.getDeletedObjects().put(objectChangeSet, objectChangeSet);

}else{//for updates
objectChangeSet = descriptor.getObjectBuilder()
.compareForChange(objectTobeRefreshed, objectBackup, changeSet,
(oracle.toplink.publicinterface.Session) uow);
changeSet.addObjectChangeSet(objectChangeSet, objectTobeRefreshed);
}


if(!changeSet.hasChanges()) return false;

Session severSession = getServerSession();
severSession.getCacheSynchronizationManager().propagateChanges(
changeSet);

return true;

}
--------------------------------------------------------------------------------------------------------------------------
Interesting one is i tried deleting the object from front end UI using following code then also object not removed from not only same session but other applications too. As i mentioned earlier we are using softweakidentitymap for our cache.

public static boolean cacheDeleteObject(String entityName, String entityId)
throws Exception {


Session session = getSession();
UnitOfWork uow = session.acquireUnitOfWork();
Class baseTableName = Class.forName(entityName);

Object objectTobeRefreshed = findByIdByCacheRefresh(baseTableName,
getPrimaryKey(session, entityName), entityId);

if(objectTobeRefreshed==null) return false;

uow.deleteObject(objectTobeRefreshed);
try {
uow.commit();
}
catch(TopLinkException te) {
throw new ResourceException("Exception in cacheDelete()");
}
return true;
}
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you determining the object was not removed?

If you execute a find() using the object's id, do you get anything back?
 
allareddy suneel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,
As i mentioned earlier, we are accessing the object in 2 different applications. We are not using findbyid but we are querying the record using other columns in forms. For admin screen alone, i given entity and pk to delete/update the cache. After i deleted from admin screen, i went to the forms in both applications and checked object coming (though physically record deleted from DB). I am able to see the JMS messages when i deleted the object.
You mean to say though we use Softweakidentiymap, system removes the object immediately from session?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are not querying by Id, then even if you don't broadcast the deletion you should still not get the object back.
All non-Id queries go to the database, if the object is truly deleted on your database, your should not get it back.

Try enabling logging. Also ensure you are not using a query cache, or caching the query results in your application. Try executing the same SQL, and see if the database returns the object.
 
reply
    Bookmark Topic Watch Topic
  • New Topic