new KTrans.Void(pm) {
@Override protected void run() {
Query query = pm.newQuery(Guess.class);
query.setFilter(String.format("userKey == %s && correctUser == %s", user.getKey(), correctUserKey));
Guess guess = CollUtils.getOneOrNull(Utils.<Collection<Guess>>cast(query.execute()));
if (guess == null) {
guess = new Guess();
guess.setUserKey(user.getKey());
guess.setCorrectUser(correctUserKey);
} else {
if (!Guess.guessAllowed(now, guess))
throw new IllegalStateException("Error, user " + user.getFullName() + " is not currently allowed to guess on " + correctUser.getFullName());
}
guess.registerGuess(now, correctGuess);
pm.makePersistent(guess);
}
}.go();
new KTrans.Void(pm) {