Esempio n. 1
0
  @Override
  public Collection<LogEntry> get(AlarmDAOFilter filter) {
    PersistenceManager readManager = getManager();
    if (readManager == null) {
      return Collections.emptyList();
    }

    Transaction tx = readManager.currentTransaction();

    try {
      tx.begin();
      Collection<LogEntry> result = AlarmJDOUtils.execute(readManager, filter);

      logger.debug("got collection {}", result);
      Collection<LogEntry> detached = readManager.detachCopyAll(result);
      logger.debug("got detatched collection {}", detached);
      tx.commit();
      logger.debug("successfully executed get for filter {}", filter);
      return detached;
    } catch (JDOException t) {
      logJDOException("update", filter, t);
      return Collections.emptyList();
    } finally {
      try {
        rollbackIfActive(tx);
      } finally {
        readManager.close();
      }
    }
  }
Esempio n. 2
0
 @Override
 @Transactional(readOnly = true)
 public Collection<Pin> getPins(PnfsId pnfsId) {
   PersistenceManager pm = _pmf.getPersistenceManager();
   Query query = pm.newQuery(Pin.class, "_pnfsId == :pnfsId");
   Collection<Pin> pins = (Collection<Pin>) query.execute(pnfsId.toString());
   return pm.detachCopyAll(pins);
 }
Esempio n. 3
0
 @SuppressWarnings("unchecked")
 private <T> T detach(T results) {
   if (results instanceof Collection) {
     return (T) persistenceManager.detachCopyAll(results);
   } else {
     return persistenceManager.detachCopy(results);
   }
 }
Esempio n. 4
0
 @Override
 @Transactional(readOnly = true)
 public Collection<Pin> getPins() {
   PersistenceManager pm = _pmf.getPersistenceManager();
   Query query = pm.newQuery(Pin.class);
   Collection<Pin> pins = (Collection<Pin>) query.execute();
   return pm.detachCopyAll(pins);
 }
Esempio n. 5
0
 public Object service() {
   List<JsonResult> matches = new ArrayList<JsonResult>();
   if (type.equals("ANY") || type.equals("ARTIST")) {
     this.term = this.term.toLowerCase().trim();
     List<Artist> artistResults = this.artistDao.getArtistsThatStartWith(term);
     for (Artist a : artistResults) {
       matches.add(
           new JsonResult(
               a.getKey(), "ARTIST", a.getName(), null, null, a.getArtistArtKey(), null, null));
     }
   }
   if (type.equals("ANY") || type.equals("ALBUM")) {
     this.term = this.term.toLowerCase().trim();
     List<GaeAlbumImpl> albumResults = null;
     PersistenceManager pm = GAEModel.get().getPersistenceManager();
     try {
       Query q = pm.newQuery(GaeAlbumImpl.class);
       try {
         q.setFilter("name >= beginsWithParam && name < beginsWithMaxParam");
         q.setRange(0, 5);
         q.declareParameters("String beginsWithParam, String beginsWithMaxParam");
         albumResults = (List<GaeAlbumImpl>) q.execute(term, term + "\ufffd");
         pm.detachCopyAll(albumResults);
       } finally {
         q.closeAll();
       }
     } finally {
       pm.close();
     }
     for (GaeAlbumImpl a : albumResults) {
       matches.add(
           new JsonResult(
               a.getKey(),
               "ALBUM",
               a.getArtistName(),
               a.getName(),
               null,
               a.getAlbumArtKey(),
               null,
               null));
     }
   }
   if (type.equals("ANY") || type.equals("TRACK")) {
     this.term = this.term.toLowerCase().trim();
     List<GaeTrackImpl> trackResults = null;
     PersistenceManager pm = GAEModel.get().getPersistenceManager();
     try {
       Query q = pm.newQuery(GaeTrackImpl.class);
       try {
         q.setRange(0, 10);
         q.setFilter("title >= beginsWithParam && title < beginsWithMaxParam");
         q.declareParameters("String beginsWithParam, String beginsWithMaxParam");
         trackResults = (List<GaeTrackImpl>) q.execute(term, term + "\ufffd");
         pm.detachCopyAll(trackResults);
       } finally {
         q.closeAll();
       }
     } finally {
       pm.close();
     }
     for (GaeTrackImpl t : trackResults) {
       matches.add(
           new JsonResult(
               t.getKey(),
               "TRACK",
               t.getArtistName(),
               t.getAlbumName(),
               t.getTitle(),
               null,
               t.getYoutubeLocation(),
               Integer.toString(t.getTrackNumber())));
     }
   }
   return matches;
 }