Example #1
0
 @Override
 @Transactional
 public void expirePins() {
   Date now = new Date();
   PersistenceManager pm = _pmf.getPersistenceManager();
   Query query = pm.newQuery(Pin.class, "_expirationTime < :now && _state != 'UNPINNING'");
   query.addExtension("datanucleus.rdbms.query.resultSetType", "scroll-insensitive");
   query.addExtension("datanucleus.query.resultCacheType", "none");
   query.getFetchPlan().setFetchSize(FetchPlan.FETCH_SIZE_OPTIMAL);
   try {
     for (Pin pin : (Collection<Pin>) query.execute(now)) {
       pin.setState(Pin.State.UNPINNING);
     }
   } finally {
     query.closeAll();
   }
 }
Example #2
0
 @Override
 @Transactional
 public boolean all(Pin.State state, Predicate<Pin> f) {
   PersistenceManager pm = _pmf.getPersistenceManager();
   Query query = pm.newQuery(Pin.class, "_state == :state");
   query.addExtension("datanucleus.rdbms.query.resultSetType", "scroll-insensitive");
   query.addExtension("datanucleus.query.resultCacheType", "none");
   query.getFetchPlan().setFetchSize(FetchPlan.FETCH_SIZE_OPTIMAL);
   try {
     for (Pin pin : (Collection<Pin>) query.execute(state)) {
       if (!f.apply(pm.detachCopy(pin))) {
         return false;
       }
     }
   } finally {
     query.closeAll();
   }
   return true;
 }