예제 #1
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();
   }
 }
예제 #2
0
  public void testAddToCollection() throws Exception {
    Company c1 = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    Contractor c2 = new Contractor();
    c1.setName("Michael");
    c2.setName("Albert");

    try {
      writer.store(c1);
      writer.store(c2);

      Company c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(0, c3.getContractors().size());

      writer.addToCollection(c1.getId(), Company.class, "contractors", c2.getId());

      c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(1, c3.getContractors().size());
      assertTrue(c3.getContractors().iterator().next() instanceof Contractor);
      assertEquals(c2.getId(), ((Contractor) c3.getContractors().iterator().next()).getId());
    } finally {
      writer.delete(c1);
      writer.delete(c2);
    }
  }
예제 #3
0
  public void testCreateBagTable() throws Exception {
    Collection bag = new HashSet();

    bag.add(new Integer(-10000));
    bag.add(new Integer(0));
    bag.add(new Integer(10000));
    bag.add(new Long(-10000));
    bag.add(new Long(0));
    bag.add(new Long(10000));
    bag.add(new Short((short) -10000));
    bag.add(new Short((short) 0));
    bag.add(new Short((short) 10000));
    bag.add(new BigDecimal(-10000.0));
    bag.add(new BigDecimal(0.0));
    bag.add(new BigDecimal(10000.0));
    bag.add(new Float(-10000.0));
    bag.add(new Float(0.0));
    bag.add(new Float(10000.0));
    bag.add(new Double(-10000.0));
    bag.add(new Double(0.0));
    bag.add(new Double(10000.0));
    bag.add(new String());
    bag.add(new String("a String with spaces"));
    bag.add(new String("123456"));
    bag.add(new String("123456.7"));
    bag.add(new Boolean(true));
    bag.add(new Boolean(false));
    bag.add(new Date(999999));
    bag.add(new Date(100));
    Employee employee = (Employee) DynamicUtil.createObject(Collections.singleton(Employee.class));
    employee.setId(new Integer(5000));
    bag.add(employee);
    Manager manager = (Manager) DynamicUtil.createObject(Collections.singleton(Manager.class));
    manager.setId(new Integer(5001));
    bag.add(manager);
    Company company = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    company.setId(new Integer(6000));
    bag.add(company);

    // this shouldn't appear in any table
    bag.add(BigInteger.ONE);

    DatabaseUtil.createBagTable(db, con, "integer_table", bag, Integer.class);
    DatabaseUtil.createBagTable(db, con, "long_table", bag, Long.class);
    DatabaseUtil.createBagTable(db, con, "short_table", bag, Short.class);
    DatabaseUtil.createBagTable(db, con, "bigdecimal_table", bag, BigDecimal.class);
    DatabaseUtil.createBagTable(db, con, "float_table", bag, Float.class);
    DatabaseUtil.createBagTable(db, con, "double_table", bag, Double.class);
    DatabaseUtil.createBagTable(db, con, "string_table", bag, String.class);
    DatabaseUtil.createBagTable(db, con, "boolean_table", bag, Boolean.class);
    DatabaseUtil.createBagTable(db, con, "date_table", bag, Date.class);
    DatabaseUtil.createBagTable(db, con, "intermineobject_table", bag, InterMineObject.class);
    DatabaseUtil.createBagTable(db, con, "employee_table", bag, Employee.class);

    Statement s = con.createStatement();
    ResultSet r = s.executeQuery("SELECT value FROM integer_table");
    Set result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    Set expected = new HashSet();
    expected.add(new Integer(-10000));
    expected.add(new Integer(0));
    expected.add(new Integer(10000));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM long_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Long(-10000));
    expected.add(new Long(0));
    expected.add(new Long(10000));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM short_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Integer((short) -10000));
    expected.add(new Integer((short) 0));
    expected.add(new Integer((short) 10000));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM double_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Double(-10000.0));
    expected.add(new Double(0.));
    expected.add(new Double(10000.0));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM float_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Float(-10000.0));
    expected.add(new Float(0.));
    expected.add(new Float(10000.0));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM string_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new String());
    expected.add(new String("a String with spaces"));
    expected.add(new String("123456"));
    expected.add(new String("123456.7"));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM boolean_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Boolean(true));
    expected.add(new Boolean(false));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM date_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Long(999999));
    expected.add(new Long(100));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM intermineobject_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(employee.getId());
    expected.add(manager.getId());
    expected.add(company.getId());

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM employee_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(employee.getId());
    expected.add(manager.getId());

    assertEquals(expected, result);
  }