Methods Summary |
---|
public void | cleanup()
Query query = manager.createQuery("select account from Account as account");
List accts = query.getResultList();
if (accts != null)
{
for (Iterator it = accts.iterator(); it.hasNext();)
{
try
{
Account acct = (Account) it.next();
log.info("Removing " + acct);
manager.remove(acct);
}
catch (Exception ignored) {}
}
}
|
public void | createAccount(AccountHolderPK pk, java.lang.Integer id, java.lang.Integer openingBalance, java.lang.String branch)
Account account = new Account();
account.setId(id);
account.setAccountHolder(pk);
account.setBalance(openingBalance);
account.setBranch(branch);
manager.persist(account);
|
public java.lang.String | getBranch(AccountHolderPK pk, boolean useNamed, boolean useRegion)
if (useNamed)
return getBranchViaNamedQuery(pk, useRegion);
else
return getBranchViaLocalQuery(pk, useRegion);
|
private java.lang.String | getBranchViaLocalQuery(AccountHolderPK pk, boolean useRegion)
Query query = manager.createQuery("select account.branch from Account as account where account.accountHolder = ?1");
query.setParameter(1, pk);
if (useRegion)
{
query.setHint("org.hibernate.cacheRegion", "AccountRegion");
}
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
return (String) query.getResultList().get(0);
|
private java.lang.String | getBranchViaNamedQuery(AccountHolderPK pk, boolean useRegion)
String queryName = useRegion ? "account.branch.namedregion"
: "account.branch.default";
Query query = manager.createNamedQuery(queryName);
query.setParameter(1, pk);
return (String) query.getResultList().get(0);
|
public void | getCache(boolean optimistic)
if (optimistic)
cacheObjectName = "jboss.cache:service=OptimisticEJB3EntityTreeCache";
else
cacheObjectName = "jboss.cache:service=EJB3EntityTreeCache";
try
{
//Just to initialise the cache with a listener
TreeCache cache = getCache();
listener = new MyListener();
cache.addTreeCacheListener(listener);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
|
private org.jboss.cache.TreeCache | getCache()
MBeanServer server = MBeanServerLocator.locateJBoss();
TreeCacheMBean proxy = (TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class, new ObjectName(cacheObjectName), server);
TreeCache cache = proxy.getInstance();
return cache;
|
public int | getCountForBranch(java.lang.String branch, boolean useNamed, boolean useRegion)
if (useNamed)
return getCountForBranchViaNamedQuery(branch, useRegion);
else
return getCountForBranchViaLocalQuery(branch, useRegion);
|
private int | getCountForBranchViaLocalQuery(java.lang.String branch, boolean useRegion)
Query query = manager.createQuery("select account from Account as account where account.branch = ?1");
query.setParameter(1, branch);
if (useRegion)
{
query.setHint("org.hibernate.cacheRegion", "AccountRegion");
}
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
return query.getResultList().size();
|
private int | getCountForBranchViaNamedQuery(java.lang.String branch, boolean useRegion)
String queryName = useRegion ? "account.bybranch.namedregion"
: "account.bybranch.default";
Query query = manager.createNamedQuery(queryName);
query.setParameter(1, branch);
return query.getResultList().size();
|
private boolean | getSawRegion(java.lang.String regionName, java.util.Set sawEvent)
boolean saw = false;
Fqn fqn = Fqn.fromString(regionName);
for (Iterator it = sawEvent.iterator(); it.hasNext();)
{
Fqn modified = (Fqn) it.next();
if (modified.isChildOf(fqn))
{
it.remove();
saw = true;
}
}
return saw;
|
public boolean | getSawRegionAccess(java.lang.String regionName)
return getSawRegion(regionName, listener.accessed);
|
public boolean | getSawRegionModification(java.lang.String regionName)
return getSawRegion(regionName, listener.modified);
|
public int | getTotalBalance(AccountHolderPK pk, boolean useNamed, boolean useRegion)
if (useNamed)
return getTotalBalanceViaNamedQuery(pk, useRegion);
else
return getTotalBalanceViaLocalQuery(pk, useRegion);
|
private int | getTotalBalanceViaLocalQuery(AccountHolderPK pk, boolean useRegion)
Query query = manager.createQuery("select account.balance from Account as account where account.accountHolder = ?1");
query.setParameter(1, pk);
query.setHint("org.hibernate.cacheable", Boolean.TRUE);
return totalBalances(query);
|
private int | getTotalBalanceViaNamedQuery(AccountHolderPK pk, boolean useRegion)
String queryName = useRegion ? "account.totalbalance.namedregion"
: "account.totalbalance.default";
Query query = manager.createNamedQuery(queryName);
query.setParameter(1, pk);
return totalBalances(query);
|
public void | remove()
cleanup();
listener.clear();
try
{
getCache().removeTreeCacheListener(listener);
}
catch (Exception e)
{
e.printStackTrace();
}
|
private int | totalBalances(javax.persistence.Query balanceQuery)
List results = balanceQuery.getResultList();
int total = 0;
if (results != null)
{
for (Iterator it = results.iterator(); it.hasNext();)
{
total += ((Integer) it.next()).intValue();
System.out.println("Total = " + total);
}
}
return total;
|
public void | updateAccountBalance(java.lang.Integer id, java.lang.Integer newBalance)
Account account = (Account) manager.find(Account.class, id);
account.setBalance(newBalance);
|
public void | updateAccountBranch(java.lang.Integer id, java.lang.String branch)
Account account = (Account) manager.find(Account.class, id);
account.setBranch(branch);
|