public Boolean update(EssayCount count) throws Exception { try { Query q = ds.createQuery(EssayCount.class).field("_id").equal(count.getId()); EssayCount app = (EssayCount) q.get(); if (app != null) { ds.save(count); return true; } else { return false; } } catch (Exception e) { throw e; } }
public void plusOne(String user) throws Exception { try { Query q = ds.createQuery(EssayCount.class).field("user").equal(user); EssayCount ec = (EssayCount) q.get(); if (ec == null) { ec = new EssayCount(); ec.setCount(1); ec.setLastRate(new Date()); ec.setUser(user); ds.save(ec); } else { ec.setCount(ec.getCount() + 1); ec.setLastRate(new Date()); ds.save(ec); } } catch (Exception e) { throw e; } }