예제 #1
0
 protected InterMineBag createEmployeeList() throws Exception {
   ObjectStoreWriter osw = null;
   try {
     Profile superUser = im.getProfileManager().getSuperuserProfile();
     osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.unittest");
     Employee e1 = new Employee();
     e1.setName("Employee1");
     Employee e2 = new Employee();
     e2.setName("Employee2");
     Department d1 = new Department();
     d1.setName("department");
     Company company = new CompanyShadow();
     company.setName("company");
     Contractor contractor = new Contractor();
     contractor.setName("contractor");
     osw.store(contractor);
     company.addContractors(contractor);
     osw.store(company);
     d1.setCompany(company);
     osw.store(d1);
     e1.setDepartment(d1);
     e2.setDepartment(d1);
     osw.store(e1);
     osw.store(e2);
     InterMineBag list = superUser.createBag("employeeList", "Employee", "", im.getClassKeys());
     Collection<Integer> ids = new ArrayList<Integer>();
     ids.add(e1.getId());
     ids.add(e2.getId());
     list.addIdsToBag(ids, "Employee");
     return list;
   } finally {
     osw.close();
   }
 }
예제 #2
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");
  }
예제 #3
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);
  }
예제 #4
0
 protected InterMineBag createCompanyList() throws Exception {
   ObjectStoreWriter osw = null;
   try {
     osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.unittest");
     Profile superUser = im.getProfileManager().getSuperuserProfile();
     Company c1 = new CompanyShadow();
     c1.setName("CompanyA");
     Company c2 = new CompanyShadow();
     c2.setName("CompanyB");
     osw.store(c1);
     osw.store(c2);
     InterMineBag list = superUser.createBag("companyList", "Company", "", im.getClassKeys());
     Collection<Integer> ids = new ArrayList<Integer>();
     ids.add(c1.getId());
     ids.add(c2.getId());
     list.addIdsToBag(ids, "Company");
     return list;
   } finally {
     osw.close();
   }
 }
예제 #5
0
  /**
   * Run the task
   *
   * @throws BuildException if a problem occurs
   */
  @Override
  public void execute() {
    if (clsName == null) {
      throw new BuildException("clsName attribute is not set");
    }
    if (getOsName() == null) {
      throw new BuildException("osName attribute is not set");
    }
    if (getModelName() == null) {
      throw new BuildException("modelName attribute is not set");
    }
    if (dbAlias == null) {
      throw new BuildException("dbAlias attribute is not set");
    }
    try {
      ObjectStoreWriter osw = ObjectStoreWriterFactory.getObjectStoreWriter(getOsName());
      ObjectStoreItemWriter writer = new ObjectStoreItemWriter(osw);
      Database database = DatabaseFactory.getDatabase(dbAlias);

      Class<?> c = Class.forName(clsName);
      if (!DBConverter.class.isAssignableFrom(c)) {
        throw new IllegalArgumentException(
            "Class (" + clsName + ") is not a subclass of " + DBConverter.class.getName());
      }

      Constructor<?> m =
          c.getConstructor(new Class[] {Database.class, Model.class, ItemWriter.class});
      Model model = Model.getInstanceByName(getModelName());
      DBConverter converter = (DBConverter) m.newInstance(new Object[] {database, model, writer});
      configureDynamicAttributes(converter);
      converter.process();
      converter.close();
      converter.getItemWriter().close();
      osw.close();
    } catch (Exception e) {
      throw new BuildException("problem while running converter reading from db: " + dbAlias, e);
    }
  }
예제 #6
0
  /**
   * Run the task
   *
   * @throws org.apache.tools.ant.BuildException if a problem occurs
   */
  public void execute() {

    ObjectStoreWriter osw = null;

    try {
      osw = ObjectStoreWriterFactory.getObjectStoreWriter(osName);

      Class c = Class.forName(clsName);

      if (!PostProcessor.class.isAssignableFrom(c)) {
        throw new IllegalArgumentException(
            "Class ("
                + clsName
                + ") is not a subclass"
                + "of org.intermine.postprocess.PostProcessor!");
      }

      Constructor m = c.getConstructor(new Class[] {ObjectStoreWriter.class});

      PostProcessor pp = (PostProcessor) m.newInstance(new Object[] {osw});

      configureDynamicAttributes(pp);

      pp.postProcess();

    } catch (Exception e) {
      throw new BuildException(e);
    } finally {
      try {
        if (osw != null) {
          osw.close();
        }
      } catch (Exception e) {
        throw new BuildException(e);
      }
    }
  }
  /**
   * Run the task.
   *
   * @throws BuildException if a problem occurs
   */
  public void execute() {
    if (dataDir == null) {
      throw new BuildException("dataDir must be specified");
    }
    File dir = new File(dataDir);
    String directoryName = dir.getName();
    if (!dir.isDirectory()) {
      throw new BuildException("dataDir is not a directory:" + directoryName);
    }
    if (dir.listFiles().length == 0) {
      throw new BuildException("dataDir contains no files:" + directoryName);
    }
    if (clsName == null) {
      throw new BuildException("clsName attribute is not set");
    }
    if (getOsName() == null) {
      throw new BuildException("osName attribute is not set");
    }
    if (getModelName() == null) {
      throw new BuildException("modelName attribute is not set");
    }

    // Needed so that STAX can find its implementation classes
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

    ObjectStoreWriter osw = null;
    ItemWriter writer = null;
    try {
      Model model = Model.getInstanceByName(getModelName());
      osw = ObjectStoreWriterFactory.getObjectStoreWriter(getOsName());
      writer = new ObjectStoreItemWriter(osw);

      Class c = Class.forName(clsName);
      if (!DirectoryConverter.class.isAssignableFrom(c)) {
        throw new IllegalArgumentException(
            "Class ("
                + clsName
                + ") is not a subclass"
                + "of org.intermine.dataconversion.Directory.");
      }

      Constructor m = c.getConstructor(new Class[] {ItemWriter.class, Model.class});
      DirectoryConverter converter =
          (DirectoryConverter) m.newInstance(new Object[] {writer, model});

      try {
        configureDynamicAttributes(converter);

        File file = new File(dataDir);
        if (file.isDirectory()) {
          converter.process(file);
        } else {
          throw new IllegalArgumentException(dataDir + " is not a directory");
        }
      } finally {
        converter.close();
      }
    } catch (Exception e) {
      throw new BuildException(e);
    } finally {
      Thread.currentThread().setContextClassLoader(cl);
      try {
        if (writer != null) {
          writer.close();
        }
        if (writer != null) {
          osw.close();
        }
      } catch (Exception e) {
        throw new BuildException(e);
      }
    }

    try {
      doSQL(osw.getObjectStore());
    } catch (Exception e) {
      throw new BuildException(e);
    }
  }