Methods Summary |
---|
public Customer | createCustomer()
Customer customer = new Customer();
customer.setName("JBoss");
Set<Contact> contacts = new HashSet<Contact>();
Contact kabir = new Contact();
kabir.setCustomer(customer);
kabir.setName("Kabir");
kabir.setTlf("1111");
contacts.add(kabir);
Contact bill = new Contact();
bill.setCustomer(customer);
bill.setName("Bill");
bill.setTlf("2222");
contacts.add(bill);
customer.setContacts(contacts);
manager.persist(customer);
return customer;
|
public Customer | findByCustomerId(java.lang.Long id)
return manager.find(Customer.class, id);
|
private org.jboss.cache.TreeCache | getCache()
MBeanServer server = MBeanServerLocator.locateJBoss();
TreeCacheMBean proxy = (TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class, new ObjectName("jboss.cache:service=EJB3EntityTreeCache"), server);
return proxy.getInstance();
|
public boolean | isContactInCache(java.lang.Long id)
try
{
TreeCache cache = getCache();
String key = "/org/jboss/tutorial/clusteredentity/bean/Contact/org.jboss.tutorial.clusteredentity.bean.Contact#" + id;
return isInCache(cache, key);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
|
public boolean | isCustomerContactsInCache(java.lang.Long id)
try
{
TreeCache cache = getCache();
String key = "/org/jboss/tutorial/clusteredentity/bean/Customer/contacts/org.jboss.tutorial.clusteredentity.bean.Customer.contacts#" + id;
return isInCache(cache, key);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
|
public boolean | isCustomerInCache(java.lang.Long id)
try
{
TreeCache cache = getCache();
String key = "/org/jboss/tutorial/clusteredentity/bean/Customer/org.jboss.tutorial.clusteredentity.bean.Customer#" + id;
return isInCache(cache, key);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
|
private boolean | isInCache(org.jboss.cache.TreeCache cache, java.lang.String key)
return isInCache(cache, null, key);
|
private boolean | isInCache(org.jboss.cache.TreeCache cache, org.jboss.cache.Node node, java.lang.String key)
//Not the best way to look up the cache entry, but how hibernate creates the cache entry
//and fqn seems to be buried deep deep down inside hibernate...
if (node == null)
{
node = cache.get("/");
}
Map map = node.getChildren();
for(Object child : map.values())
{
Node childNode = (Node)child;
Fqn fqn = childNode.getFqn();
if (fqn.toString().equals(key))
{
Object entry = childNode.getData().get("item");
return (entry != null) && (entry instanceof CacheEntry || entry instanceof CollectionCacheEntry);
}
Map children = childNode.getChildren();
if (children != null && children.size() > 0)
{
if (isInCache(cache, childNode, key))
{
return true;
}
}
}
return false;
|