Exemplo n.º 1
0
  public void tearDown() throws Exception {
    LOG.info("in tear down");
    ObjectStoreWriter osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.unittest");

    if (osw.isInTransaction()) {
      osw.abortTransaction();
    }
    Query q = new Query();
    QueryClass qc = new QueryClass(InterMineObject.class);
    q.addFrom(qc);
    q.addToSelect(qc);
    SingletonResults res = osw.getObjectStore().executeSingleton(q);
    LOG.info("created results");
    Iterator resIter = res.iterator();
    osw.beginTransaction();
    while (resIter.hasNext()) {
      InterMineObject o = (InterMineObject) resIter.next();
      LOG.info("deleting: " + o.getId());
      osw.delete(o);
    }
    osw.commitTransaction();
    LOG.info("committed transaction");
    osw.close();
    LOG.info("closed objectstore");
  }
Exemplo n.º 2
0
  @AfterClass
  public static void shutdown() {
    int deleted = 0;
    if (osw != null) {
      try {
        osw.beginTransaction();
        PathQuery pq = new PathQuery(osw.getModel());
        pq.addView("Types.id");
        pq.addConstraint(Constraints.eq("Types.name", "histo*"));

        Query q = MainHelper.makeQuery(pq, new HashMap(), new HashMap(), null, new HashMap());

        Results res = osw.execute(q, 50000, true, false, true);
        for (Object row : res) {
          Types thing = (Types) ((List) row).get(0);
          osw.delete(thing);
          deleted++;
        }

        osw.commitTransaction();
      } catch (ObjectStoreException e) {
        LOG.warn(e);
      }
      try {
        osw.close();
      } catch (ObjectStoreException e) {
        LOG.warn(e);
      }
    }
    System.out.printf("\n[CLEAN UP] Deleted %d things\n", deleted);
  }
Exemplo n.º 3
0
 /**
  * Delete this bag from the userprofile database, bag should not be used after this method has
  * been called. Delete the ids from the production database too.
  *
  * @throws ObjectStoreException if problem deleting bag
  */
 @Override
 public void delete() throws ObjectStoreException {
   super.delete();
   if (!deleted) {
     SavedBag savedBag =
         (SavedBag) uosw.getObjectStore().getObjectById(savedBagId, SavedBag.class);
     uosw.delete(savedBag);
     deleteAllBagValues();
   }
   this.deleted = true;
 }
Exemplo n.º 4
0
  /** Delete all InterMineObjects from the objectstore. */
  private void cleanObjects(ObjectStoreWriter osw) throws ObjectStoreException {
    Query q = new Query();
    QueryClass queryClass = new QueryClass(InterMineObject.class);
    q.addToSelect(queryClass);
    q.addFrom(queryClass);

    SingletonResults r = osw.getObjectStore().executeSingleton(q);

    for (InterMineObject o : (List<InterMineObject>) ((List) r)) {
      osw.delete(o);
    }
  }
Exemplo n.º 5
0
 private int removeOrphanTags() {
   // Basically:
   //    select tag.id
   //    from tag, (select array(select id from userprofile) as ids) as sq
   //    where tag.userprofileid IS NULL OR tag.userprofileid <> ALL (sq.ids)
   //    order by tag.id
   ObjectStoreWriter osw = getUserProfile();
   Query q = new Query();
   QueryClass qc = new QueryClass(Tag.class);
   q.setConstraint(new SimpleConstraint(new QueryField(qc, "userProfile"), ConstraintOp.IS_NULL));
   Set<Object> res;
   try {
     res = osw.executeSingleton(q);
   } catch (Exception e) {
     throw new BuildException("Could not retrieve any tags", e);
   }
   try {
     osw.beginTransaction();
     for (Object o : res) {
       osw.delete((Tag) o);
     }
     osw.commitTransaction();
   } catch (Exception e) {
     throw new BuildException("Error deleting tags", e);
   } finally {
     if (osw != null) {
       try {
         if (osw.isInTransaction()) {
           osw.abortTransaction();
         }
       } catch (ObjectStoreException e) {
         throw new BuildException("Could not even manage transactions here...", e);
       }
     }
   }
   return res.size();
 }