コード例 #1
0
  public void testTranslateFromDbObject() throws Exception {
    Item dbItem = new Item();
    dbItem.setClassName("Department");
    dbItem.setImplementations("Broke");
    dbItem.setIdentifier("fish_1");
    Attribute dbAttr1 = new Attribute();
    dbAttr1.setName("name");
    dbAttr1.setValue("Department1");
    dbAttr1.setItem(dbItem);
    dbItem.addAttributes(dbAttr1);
    Attribute dbAttr2 = new Attribute();
    dbAttr2.setName("debt");
    dbAttr2.setValue("10");
    dbAttr2.setItem(dbItem);
    dbItem.addAttributes(dbAttr2);
    Reference dbRef1 = new Reference();
    dbRef1.setName("company");
    dbRef1.setRefId("2");
    dbRef1.setItem(dbItem);
    dbItem.addReferences(dbRef1);
    ReferenceList dbCol1 = new ReferenceList();
    dbCol1.setName("employees");
    dbCol1.setRefIds("3 4");
    dbCol1.setItem(dbItem);
    dbItem.addCollections(dbCol1);

    InterMineObject result = (InterMineObject) translator.translateFromDbObject(dbItem);
    assertTrue(result instanceof Department);
    assertTrue(result instanceof Broke);

    assertEquals("Department1", ((Department) result).getName());
    assertEquals(10, ((Broke) result).getDebt());

    Map fieldMap = ((DynamicBean) ((net.sf.cglib.proxy.Factory) result).getCallback(0)).getMap();
    ProxyReference o = (ProxyReference) fieldMap.get("Company");
    assertNotNull(o);
    assertEquals(new Integer(2), o.getId());

    Collection c = ((Department) result).getEmployees();
    assertTrue(c instanceof SingletonResults);
    Query expected = new Query();
    QueryClass qc = new QueryClass(InterMineObject.class);
    expected.addFrom(qc);
    expected.addToSelect(qc);
    QueryField qf = new QueryField(qc, "id");
    Set ids = new HashSet();
    ids.add(new Integer(3));
    ids.add(new Integer(4));
    BagConstraint bc = new BagConstraint(qf, ConstraintOp.IN, ids);
    expected.setConstraint(bc);
    assertEquals(expected, ((SingletonResults) c).getQuery());
  }
コード例 #2
0
  public void setUp() throws Exception {
    os = ObjectStoreFactory.getObjectStore("os.unittest");

    item = new Item();
    item.setClassName("Department");
    item.setImplementations("Broke");
    item.setIdentifier("1");
    Attribute attr1 = new Attribute();
    attr1.setName("name");
    attr1.setValue("Department1");
    item.addAttribute(attr1);
    Attribute attr2 = new Attribute();
    attr2.setName("debt");
    attr2.setValue("10");
    item.addAttribute(attr2);
    Reference ref1 = new Reference();
    ref1.setName("address");
    ref1.setRefId("2");
    item.addReference(ref1);
    ReferenceList col1 = new ReferenceList();
    col1.setName("employees");
    col1.addRefId("3");
    col1.addRefId("4");
    item.addCollection(col1);

    dbItem = new org.intermine.model.fulldata.Item();
    dbItem.setClassName("Department");
    dbItem.setImplementations("Broke");
    dbItem.setIdentifier("1");
    dbItem.setId(1001);
    org.intermine.model.fulldata.Attribute dbAttr1 = new org.intermine.model.fulldata.Attribute();
    dbAttr1.setName("name");
    dbAttr1.setValue("Department1");
    dbAttr1.setItem(dbItem);
    dbItem.addAttributes(dbAttr1);
    org.intermine.model.fulldata.Attribute dbAttr2 = new org.intermine.model.fulldata.Attribute();
    dbAttr2.setName("debt");
    dbAttr2.setValue("10");
    dbAttr2.setItem(dbItem);
    dbItem.addAttributes(dbAttr2);
    org.intermine.model.fulldata.Reference dbRef1 = new org.intermine.model.fulldata.Reference();
    dbRef1.setName("address");
    dbRef1.setRefId("2");
    dbRef1.setItem(dbItem);
    dbItem.addReferences(dbRef1);
    org.intermine.model.fulldata.ReferenceList dbCol1 =
        new org.intermine.model.fulldata.ReferenceList();
    dbCol1.setName("employees");
    dbCol1.setRefIds("3 4");
    dbCol1.setItem(dbItem);
    dbItem.addCollections(dbCol1);

    referenceList = new ReferenceList();
    referenceList.setName("employees");
    referenceList.setRefIds(Arrays.asList("3", "4"));

    dbReferenceList = new org.intermine.model.fulldata.ReferenceList();
    dbReferenceList.setName("employees");
    dbReferenceList.setRefIds("3 4");
    departmentProxy = new ProxyReference(os, 1, Department.class);
    dbReferenceList.proxyItem(departmentProxy);
    // dbReferenceList.setId(2002);
  }
コード例 #3
0
 /** {@inheritDoc} */
 public void store(Attribute att, Integer itemId) {
   Item item = storedItemIds.get(itemId);
   att.setItem(item);
   item.addAttributes(att);
 }