public Count getCount(WorkoutContext con){
PersistenceManagerFactory pmf = PMF.get();
PersistenceManager pm = null;
try{
pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Count c = null;
try{
tx.begin();
try{
c = pm.getObjectById(Count.class, ViewConstants.PRIMARYKEY_ID);
}catch(Exception e){
log.log(Level.INFO, "Count 取得中例外", e);
c = new Count();
}
c.setTotal(c.getTotal() + 1);
if(con.getKingOrSolderScore()>con.getScholarOrCraftsmanScore()){
c.setKingOrSolder(c.getKingOrSolder() + 1);
if(con.getKingScore()>con.getSolderScore()){
c.setKing(c.getKing() + 1);
}else if(con.getKingScore()<con.getSolderScore()){
c.setSolder(c.getSolder() + 1);
}
}else if(con.getKingOrSolderScore()<con.getScholarOrCraftsmanScore()){
c.setScholarOrCraftsman(c.getScholarOrCraftsman() + 1);
if(con.getScholarScore()>con.getCraftsmanScore()){
c.setScholar(c.getScholar() + 1);
}else if(con.getScholarScore()<con.getCraftsmanScore()){
c.setCraftsman(c.getCraftsman() + 1);
}
}
pm.makePersistent(c);
tx.commit();
log.info("Count:" + c.toString());
return c;
}finally{
if(tx.isActive()) tx.rollback();
}
}finally{
if(pm!=null) pm.close();
}
}