Package com.google.appengine.datanucleus.test.jdo.AbstractBaseClassesJDO

Examples of com.google.appengine.datanucleus.test.jdo.AbstractBaseClassesJDO.Concrete3


  public void testConcrete() throws Exception {
    Concrete1 concrete = new Concrete1();
    concrete.setBase1Str("base 1");
    concrete.setConcrete1Str("concrete");
    Concrete3 concrete3 = new Concrete3();
    concrete3.setStr("str3");
    concrete.setConcrete3(concrete3);
    Concrete4 concrete4a = new Concrete4();
    concrete4a.setStr("str4a");
    Concrete4 concrete4b = new Concrete4();
    concrete4b.setStr("str4b");
    concrete.setConcrete4(Utils.newArrayList(concrete4a, concrete4b));

    beginTxn();
    pm.makePersistent(concrete);
    commitTxn();

    Entity concreteEntity = ds.get(KeyFactory.createKey(kindForObject(concrete), concrete.getId()));
    Entity concrete3Entity = ds.get(concrete3.getId());
    Entity concrete4aEntity = ds.get(concrete4a.getId());
    Entity concrete4bEntity = ds.get(concrete4b.getId());

    assertEquals(4, concreteEntity.getProperties().size());
    assertEquals("base 1", concreteEntity.getProperty("base1Str"));
    assertEquals(concrete3Entity.getKey(), concreteEntity.getProperty("concrete3_id_OID"));
    assertEquals(Utils.newArrayList(concrete4aEntity.getKey(), concrete4bEntity.getKey()),
                 concreteEntity.getProperty("concrete4"));

    assertEquals(1, concrete3Entity.getProperties().size());
    assertEquals("str3", concrete3Entity.getProperty("str"));

    if (getStorageVersion(pm).ordinal() < StorageVersion.READ_OWNED_CHILD_KEYS_FROM_PARENTS.ordinal()) {
      assertEquals(2, concrete4aEntity.getProperties().size());
      assertEquals("str4a", concrete4aEntity.getProperty("str"));
      assertEquals(0L, concrete4aEntity.getProperty("concrete4_INTEGER_IDX"));
      assertEquals(2, concrete4bEntity.getProperties().size());
      assertEquals("str4b", concrete4bEntity.getProperty("str"));
      assertEquals(1L, concrete4bEntity.getProperty("concrete4_INTEGER_IDX"));
    } else {
      // List index not present with latest storage version
      assertEquals(1, concrete4aEntity.getProperties().size());
      assertEquals("str4a", concrete4aEntity.getProperty("str"));
      assertEquals(1, concrete4bEntity.getProperties().size());
      assertEquals("str4b", concrete4bEntity.getProperty("str"));
    }

    beginTxn();
    concrete = pm.getObjectById(concrete.getClass(), concrete.getId());
    assertEquals("base 1", concrete.getBase1Str());
    assertEquals("concrete", concrete.getConcrete1Str());
    assertEquals(concrete3.getId(), concrete.getConcrete3().getId());
    assertEquals(concrete3.getStr(), concrete.getConcrete3().getStr());
    assertEquals(2, concrete.getConcrete4().size());
    assertEquals(concrete4a.getId(), concrete.getConcrete4().get(0).getId());
    assertEquals(concrete4a.getStr(), concrete.getConcrete4().get(0).getStr());
    assertEquals(concrete4b.getId(), concrete.getConcrete4().get(1).getId());
    Key concrete4bKey = concrete4b.getId();
    assertEquals(concrete4b.getStr(), concrete.getConcrete4().get(1).getStr());

    concrete.setBase1Str("not base 1");
    concrete.setConcrete1Str("not concrete");

    concrete.getConcrete3().setStr("blam3");
    concrete.getConcrete4().get(0).setStr("blam4");
    concrete.getConcrete4().remove(1);
    commitTxn();

    concreteEntity = ds.get(KeyFactory.createKey(kindForObject(concrete), concrete.getId()));
    concrete3Entity = ds.get(concrete3.getId());
    concrete4aEntity = ds.get(concrete4a.getId());

    assertEquals(4, concreteEntity.getProperties().size());
    assertEquals("not base 1", concreteEntity.getProperty("base1Str"));
    assertEquals("not concrete", concreteEntity.getProperty("concrete1Str"));
    assertEquals(concrete3Entity.getKey(), concreteEntity.getProperty("concrete3_id_OID"));
    assertEquals(Utils.newArrayList(concrete4aEntity.getKey()), concreteEntity.getProperty("concrete4"));

    assertEquals(1, concrete3Entity.getProperties().size());
    assertEquals("blam3", concrete3Entity.getProperty("str"));

    if (getStorageVersion(pm).ordinal() < StorageVersion.READ_OWNED_CHILD_KEYS_FROM_PARENTS.ordinal()) {
      assertEquals(2, concrete4aEntity.getProperties().size());
      assertEquals("blam4", concrete4aEntity.getProperty("str"));
      assertEquals(0L, concrete4aEntity.getProperty("concrete4_INTEGER_IDX"));
    } else {
      assertEquals(1, concrete4aEntity.getProperties().size());
      assertEquals("blam4", concrete4aEntity.getProperty("str"));
    }

    try {
      ds.get(concrete4bKey);
    } catch (EntityNotFoundException enfe) {
      // good
    }

    beginTxn();
    concrete = pm.getObjectById(concrete.getClass(), concrete.getId());
    assertEquals("not base 1", concrete.getBase1Str());
    assertEquals("not concrete", concrete.getConcrete1Str());
    assertEquals(concrete3.getId(), concrete.getConcrete3().getId());
    assertEquals("blam3", concrete.getConcrete3().getStr());
    assertEquals(1, concrete.getConcrete4().size());
    assertEquals(concrete4a.getId(), concrete.getConcrete4().get(0).getId());
    assertEquals("blam4", concrete.getConcrete4().get(0).getStr());

    assertEquals(1, ((Collection<Concrete2>) pm.newQuery(
        "select from " + concrete.getClass().getName() + " where base1Str == 'not base 1'").execute()).size());
    assertEquals(1, ((Collection<Concrete2>) pm.newQuery(
        "select from " + concrete.getClass().getName() + " where concrete1Str == 'not concrete'").execute()).size());

    pm.deletePersistent(concrete);
    commitTxn();

    assertEquals(0, countForClass(concrete.getClass()));
    assertEquals(0, countForClass(concrete3.getClass()));
    assertEquals(0, countForClass(concrete4a.getClass()));
  }
View Full Code Here


  public void testConcrete2() throws Exception {
    Concrete2 concrete = new Concrete2();
    concrete.setBase1Str("base 1");
    concrete.setBase2Str("base 2");
    concrete.setConcrete2Str("concrete");
    Concrete3 concrete3 = new Concrete3();
    concrete3.setStr("str3");
    concrete.setConcrete3(concrete3);
    Concrete4 concrete4a = new Concrete4();
    concrete4a.setStr("str4a");
    Concrete4 concrete4b = new Concrete4();
    concrete4b.setStr("str4b");
    concrete.setConcrete4(Utils.newArrayList(concrete4a, concrete4b));

    beginTxn();
    pm.makePersistent(concrete);
    commitTxn();

    Entity concreteEntity = ds.get(KeyFactory.createKey(kindForObject(concrete), concrete.getId()));
    Entity concrete3Entity = ds.get(concrete3.getId());
    Entity concrete4aEntity = ds.get(concrete4a.getId());
    Entity concrete4bEntity = ds.get(concrete4b.getId());

    assertEquals(5, concreteEntity.getProperties().size());
    assertEquals("base 1", concreteEntity.getProperty("base1Str"));
    assertEquals("base 2", concreteEntity.getProperty("base2Str"));
    assertEquals("concrete", concreteEntity.getProperty("concrete2Str"));
    assertEquals(concrete3Entity.getKey(), concreteEntity.getProperty("concrete3_id_OID"));
    assertEquals(Utils.newArrayList(concrete4aEntity.getKey(), concrete4bEntity.getKey()),
                 concreteEntity.getProperty("concrete4"));

    assertEquals(1, concrete3Entity.getProperties().size());
    assertEquals("str3", concrete3Entity.getProperty("str"));

    if (getStorageVersion(pm).ordinal() < StorageVersion.READ_OWNED_CHILD_KEYS_FROM_PARENTS.ordinal()) {
      assertEquals(2, concrete4aEntity.getProperties().size());
      assertEquals("str4a", concrete4aEntity.getProperty("str"));
      assertEquals(0L, concrete4aEntity.getProperty("concrete4_INTEGER_IDX"));
      assertEquals(2, concrete4bEntity.getProperties().size());
      assertEquals("str4b", concrete4bEntity.getProperty("str"));
      assertEquals(1L, concrete4bEntity.getProperty("concrete4_INTEGER_IDX"));
    } else {
      // List index not present with latest storage version
      assertEquals(1, concrete4aEntity.getProperties().size());
      assertEquals("str4a", concrete4aEntity.getProperty("str"));
      assertEquals(1, concrete4bEntity.getProperties().size());
      assertEquals("str4b", concrete4bEntity.getProperty("str"));
    }

    beginTxn();
    concrete = pm.getObjectById(concrete.getClass(), concrete.getId());
    assertEquals("base 1", concrete.getBase1Str());
    assertEquals("base 2", concrete.getBase2Str());
    assertEquals("concrete", concrete.getConcrete2Str());

    assertEquals(concrete3.getId(), concrete.getConcrete3().getId());
    assertEquals(concrete3.getStr(), concrete.getConcrete3().getStr());
    assertEquals(2, concrete.getConcrete4().size());
    assertEquals(concrete4a.getId(), concrete.getConcrete4().get(0).getId());
    assertEquals(concrete4a.getStr(), concrete.getConcrete4().get(0).getStr());
    assertEquals(concrete4b.getId(), concrete.getConcrete4().get(1).getId());
    assertEquals(concrete4b.getStr(), concrete.getConcrete4().get(1).getStr());
    Key concrete4bKey = concrete4b.getId();

    concrete.setBase1Str("not base 1");
    concrete.setBase2Str("not base 2");
    concrete.setConcrete2Str("not concrete");

    concrete.getConcrete3().setStr("blam3");
    concrete.getConcrete4().get(0).setStr("blam4");
    concrete.getConcrete4().remove(1);
    commitTxn();

    concreteEntity = ds.get(KeyFactory.createKey(kindForObject(concrete), concrete.getId()));
    concrete3Entity = ds.get(concrete3.getId());
    concrete4aEntity = ds.get(concrete4a.getId());

    assertEquals(5, concreteEntity.getProperties().size());
    assertEquals("not base 1", concreteEntity.getProperty("base1Str"));
    assertEquals("not base 2", concreteEntity.getProperty("base2Str"));
    assertEquals("not concrete", concreteEntity.getProperty("concrete2Str"));
    assertEquals(concrete3Entity.getKey(), concreteEntity.getProperty("concrete3_id_OID"));
    assertEquals(Utils.newArrayList(concrete4aEntity.getKey()),
                 concreteEntity.getProperty("concrete4"));

    assertEquals(1, concrete3Entity.getProperties().size());
    assertEquals("blam3", concrete3Entity.getProperty("str"));

    if (getStorageVersion(pm).ordinal() < StorageVersion.READ_OWNED_CHILD_KEYS_FROM_PARENTS.ordinal()) {
      assertEquals(2, concrete4aEntity.getProperties().size());
      assertEquals("blam4", concrete4aEntity.getProperty("str"));
      assertEquals(0L, concrete4aEntity.getProperty("concrete4_INTEGER_IDX"));
    } else {
      assertEquals(1, concrete4aEntity.getProperties().size());
      assertEquals("blam4", concrete4aEntity.getProperty("str"));
    }

    try {
      ds.get(concrete4bKey);
    } catch (EntityNotFoundException enfe) {
      // good
    }

    beginTxn();
    concrete = pm.getObjectById(concrete.getClass(), concrete.getId());
    assertEquals("not base 1", concrete.getBase1Str());
    assertEquals("not base 2", concrete.getBase2Str());
    assertEquals("not concrete", concrete.getConcrete2Str());
    assertEquals(concrete3.getId(), concrete.getConcrete3().getId());
    assertEquals("blam3", concrete.getConcrete3().getStr());
    assertEquals(1, concrete.getConcrete4().size());
    assertEquals(concrete4a.getId(), concrete.getConcrete4().get(0).getId());
    assertEquals("blam4", concrete.getConcrete4().get(0).getStr());

    assertEquals(1, ((Collection<Concrete2>) pm.newQuery(
        "select from " + concrete.getClass().getName() + " where base1Str == 'not base 1'").execute()).size());
    assertEquals(1, ((Collection<Concrete2>) pm.newQuery(
        "select from " + concrete.getClass().getName() + " where base2Str == 'not base 2'").execute()).size());
    assertEquals(1, ((Collection<Concrete2>) pm.newQuery(
        "select from " + concrete.getClass().getName() + " where concrete2Str == 'not concrete'").execute()).size());

    pm.deletePersistent(concrete);
    commitTxn();

    assertEquals(0, countForClass(concrete.getClass()));
    assertEquals(0, countForClass(concrete3.getClass()));
    assertEquals(0, countForClass(concrete4a.getClass()));
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jdo.AbstractBaseClassesJDO.Concrete3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.