public static CharacterSheetClone get(final SynchronizedEveAccount owner, final long time) { try { return EveKitUserAccountProvider.getFactory() .runTransaction( new RunInTransaction<CharacterSheetClone>() { @Override public CharacterSheetClone run() throws Exception { TypedQuery<CharacterSheetClone> getter = EveKitUserAccountProvider.getFactory() .getEntityManager() .createNamedQuery("CharacterSheetClone.get", CharacterSheetClone.class); getter.setParameter("owner", owner); getter.setParameter("point", time); try { return getter.getSingleResult(); } catch (NoResultException e) { return null; } } }); } catch (Exception e) { log.log(Level.SEVERE, "query error", e); } return null; }
public static List<CharacterSheetClone> accessQuery( final SynchronizedEveAccount owner, final long contid, final int maxresults, final boolean reverse, final AttributeSelector at, final AttributeSelector cloneJumpDate) { try { return EveKitUserAccountProvider.getFactory() .runTransaction( new RunInTransaction<List<CharacterSheetClone>>() { @Override public List<CharacterSheetClone> run() throws Exception { StringBuilder qs = new StringBuilder(); qs.append("SELECT c FROM CharacterSheetClone c WHERE "); // Constrain to specified owner qs.append("c.owner = :owner"); // Constrain lifeline AttributeSelector.addLifelineSelector(qs, "c", at); // Constrain attributes AttributeSelector.addLongSelector(qs, "c", "cloneJumpDate", cloneJumpDate); // Set CID constraint and ordering if (reverse) { qs.append(" and c.cid < ").append(contid); qs.append(" order by cid desc"); } else { qs.append(" and c.cid > ").append(contid); qs.append(" order by cid asc"); } // Return result TypedQuery<CharacterSheetClone> query = EveKitUserAccountProvider.getFactory() .getEntityManager() .createQuery(qs.toString(), CharacterSheetClone.class); query.setParameter("owner", owner); query.setMaxResults(maxresults); return query.getResultList(); } }); } catch (Exception e) { log.log(Level.SEVERE, "query error", e); } return Collections.emptyList(); }