[jboss-cvs] JBossAS SVN: r108025 - branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/clusteredentity/classloader.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 7 15:42:03 EDT 2010
Author: pferraro
Date: 2010-09-07 15:42:02 -0400 (Tue, 07 Sep 2010)
New Revision: 108025
Modified:
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/clusteredentity/classloader/EntityQueryTestBean.java
Log:
Add listeners for all existing caches whose name starts with "persistence.unit"
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/clusteredentity/classloader/EntityQueryTestBean.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/clusteredentity/classloader/EntityQueryTestBean.java 2010-09-07 19:41:29 UTC (rev 108024)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/clusteredentity/classloader/EntityQueryTestBean.java 2010-09-07 19:42:02 UTC (rev 108025)
@@ -21,7 +21,6 @@
*/
package org.jboss.test.cluster.clusteredentity.classloader;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
@@ -34,6 +33,7 @@
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
+import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
@@ -74,7 +74,17 @@
try
{
listener = new MyListener();
- DefaultCacheContainerRegistry.getInstance().getCacheContainer("entity").addListener(listener);
+ log.info("Adding cache manager listener to entity cache container");
+ EmbeddedCacheManager container = DefaultCacheContainerRegistry.getInstance().getCacheContainer("entity");
+ container.addListener(listener);
+ for (String cacheName: container.getCacheNames())
+ {
+ if (cacheName.startsWith("persistence.unit"))
+ {
+ log.info("Adding cache listener to " + cacheName + " cache");
+ container.getCache(cacheName).addListener(listener);
+ }
+ }
}
catch (Exception e)
{
@@ -195,15 +205,12 @@
private int totalBalances(Query balanceQuery)
{
- List results = balanceQuery.getResultList();
+ List<?> results = balanceQuery.getResultList();
int total = 0;
- if (results != null)
+ for (Object result: results)
{
- for (Iterator it = results.iterator(); it.hasNext();)
- {
- total += ((Integer) it.next()).intValue();
- System.out.println("Total = " + total);
- }
+ total += ((Integer) result).intValue();
+ System.out.println("Total = " + total);
}
return total;
}
@@ -228,19 +235,15 @@
if (manager != null)
{
Query query = manager.createQuery("select account from Account as account");
- List accts = query.getResultList();
- if (accts != null)
+ List<?> accts = query.getResultList();
+ for (Object acct: accts)
{
- for (Iterator it = accts.iterator(); it.hasNext();)
+ try
{
- try
- {
- Account acct = (Account) it.next();
- log.info("Removing " + acct);
- manager.remove(acct);
- }
- catch (Exception ignored) {}
+ log.info("Removing " + acct);
+ manager.remove(acct);
}
+ catch (Exception ignored) {}
}
}
}
@@ -273,7 +276,7 @@
}
@Listener
- public class MyListener
+ public static class MyListener
{
Set<String> modified = new ConcurrentSkipListSet<String>();
Set<String> accessed = new ConcurrentSkipListSet<String>();
@@ -287,6 +290,7 @@
@CacheStarted
public void cacheStarted(CacheStartedEvent event)
{
+ log.info("Adding cache listener to " + event.getCacheName() + " cache (via CacheStarted event)");
event.getCacheManager().getCache(event.getCacheName()).addListener(this);
}
More information about the jboss-cvs-commits
mailing list