Exemple #1
0
  @Ignore("alias property not supported yet")
  public void testBCollection() throws Exception {
    CompassSession session = openSession();

    A a = new A();
    a.id = 1;
    a.value = "value";
    a.bs = new ArrayList<B>();
    B b = new B();
    b.value = "bvalue11";
    b.value2 = "bvalue12";
    a.bs.add(b);
    b = new B();
    b.value = "bvalue21";
    b.value = "bvalue22";
    a.bs.add(b);
    session.save(a);

    Resource resource = session.loadResource(A.class, 1);
    assertNotNull(resource);
    assertEquals(7, resource.getProperties().length);
    assertEquals("A", resource.getAlias());
    assertEquals(4, resource.getProperties("value").length);

    session.close();
  }
Exemple #2
0
  @Ignore("alias property not supported yet")
  public void testBwoValues() throws Exception {
    CompassSession session = openSession();

    A a = new A();
    a.id = 1;
    a.value = "value";
    B b = new B();
    b.value = "bvalue";
    b.value2 = "bvalue2";
    a.b = b;
    session.save(a);

    Resource resource = session.loadResource(A.class, 1);
    assertNotNull(resource);
    assertEquals(6, resource.getProperties().length);
    assertEquals("A", resource.getAlias());
    assertEquals(3, resource.getProperties("value").length);

    a = (A) session.load(A.class, 1);
    assertEquals(1, a.id.longValue());
    assertNull(a.value);
    assertNull(a.b);

    session.close();
  }
 public Object unmarshall(Resource resource, MarshallingContext context) throws CompassException {
   ResourceMapping resourceMapping = mapping.getRootMappingByAlias(resource.getAlias());
   if (resourceMapping == null) {
     throw new MarshallingException(
         "No mapping is defined for alias [ " + resource.getAlias() + "]");
   }
   return resourceMapping.getConverter().unmarshall(resource, resourceMapping, context);
 }
  public void testSimpleExtendsWithNoOverride() throws Exception {
    CompassSession session = openSession();
    CompassTransaction tr = session.beginTransaction();

    Long id = new Long(1);
    ExtendsA extendsA = new ExtendsA();
    extendsA.setId(id);
    extendsA.setValue("value");
    extendsA.setExtendsValue("evalue");

    session.save("override1", extendsA);

    extendsA = (ExtendsA) session.load("override1", id);
    assertEquals("value", extendsA.getValue());

    Resource r = session.loadResource("override1", id);
    assertNotNull(r.getProperty("mvalue"));
    assertNotNull(r.getProperty("mvalue1"));

    tr.commit();
    session.close();
  }