Examples of HasOneToOneJDO


Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

  public void testUpdate_UpdateChild(StartEnd startEnd) throws EntityNotFoundException {
    Flight f = newFlight();
    HasKeyPkJDO hasKeyPk = new HasKeyPkJDO();
    HasOneToOneParentJDO hasParent = new HasOneToOneParentJDO();
    HasOneToOneParentKeyPkJDO hasParentKeyPk = new HasOneToOneParentKeyPkJDO();
    HasOneToOneJDO pojo = new HasOneToOneJDO();

    pojo.setFlight(f);
    pojo.setHasKeyPK(hasKeyPk);
    pojo.setHasParent(hasParent);
    hasParent.setParent(pojo);
    pojo.setHasParentKeyPK(hasParentKeyPk);
    hasParent.setParent(pojo);

    startEnd.start();
    pm.makePersistent(pojo);

    assertNotNull(f.getId());
    assertNotNull(hasKeyPk.getKey());
    assertNotNull(hasParentKeyPk.getKey());
    assertNotNull(hasParent.getKey());
    assertNotNull(pojo.getId());
    startEnd.end();

    startEnd.start();
    pojo = pm.getObjectById(HasOneToOneJDO.class, pojo.getId());
    pojo.getFlight().setOrigin("yam");
    pojo.getHasKeyPK().setStr("yar");
    pojo.getHasParent().setStr("yag");
    pojo.getHasParentKeyPK().setStr("yap");
    startEnd.end();

    Entity flightEntity = ds.get(KeyFactory.stringToKey(f.getId()));
    assertNotNull(flightEntity);
    assertEquals("yam", flightEntity.getProperty("origin"));
    assertKeyParentEquals(pojo.getId(), flightEntity, f.getId());

    Entity hasKeyPkEntity = ds.get(hasKeyPk.getKey());
    assertNotNull(hasKeyPkEntity);
    assertEquals("yar", hasKeyPkEntity.getProperty("str"));
    assertKeyParentEquals(pojo.getId(), hasKeyPkEntity, hasKeyPk.getKey());

    Entity hasParentEntity = ds.get(KeyFactory.stringToKey(hasParent.getKey()));
    assertNotNull(hasParentEntity);
    assertEquals("yag", hasParentEntity.getProperty("str"));
    assertKeyParentEquals(pojo.getId(), hasParentEntity, hasParent.getKey());

    Entity hasParentKeyPkEntity = ds.get(hasParentKeyPk.getKey());
    assertNotNull(hasParentKeyPkEntity);
    assertEquals("yap", hasParentKeyPkEntity.getProperty("str"));
    assertKeyParentEquals(pojo.getId(), hasParentKeyPkEntity, hasParentKeyPk.getKey());

    Entity pojoEntity = ds.get(KeyFactory.stringToKey(pojo.getId()));
    assertNotNull(pojoEntity);
    assertEquals(flightEntity.getKey(), pojoEntity.getProperty("flight_id_OID"));
    assertEquals(hasKeyPkEntity.getKey(), pojoEntity.getProperty("hasKeyPK_key_OID"));
    assertEquals(hasParentEntity.getKey(), pojoEntity.getProperty("hasParent_key_OID"));
    assertEquals(hasParentKeyPkEntity.getKey(), pojoEntity.getProperty("hasParentKeyPK_key_OID"));
View Full Code Here

Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

    Flight f = newFlight();
    HasKeyPkJDO hasKeyPk = new HasKeyPkJDO();
    HasOneToOneParentJDO hasParent = new HasOneToOneParentJDO();
    HasOneToOneParentKeyPkJDO hasParentKeyPk = new HasOneToOneParentKeyPkJDO();

    HasOneToOneJDO pojo = new HasOneToOneJDO();
    pojo.setFlight(f);
    pojo.setHasKeyPK(hasKeyPk);
    pojo.setHasParent(hasParent);
    hasParent.setParent(pojo);
    pojo.setHasParentKeyPK(hasParentKeyPk);
    hasParent.setParent(pojo);

    startEnd.start();
    pm.makePersistent(pojo);
    String flightId = f.getId();
    Key hasKeyPkKey = hasKeyPk.getKey();
    String hasParentKey = hasParent.getKey();
    Key hasParentKeyPkKey = hasParentKeyPk.getKey();
    startEnd.end();

    startEnd.start();
    try {
      pojo = pm.makePersistent(pojo);
      pojo.setFlight(null);
      pojo.setHasKeyPK(null);
      pojo.setHasParent(null);
      pojo.setHasParentKeyPK(null);
    } finally {
      startEnd.end();
    }

    try {
      ds.get(KeyFactory.stringToKey(flightId));
      fail("expected enfe");
    } catch (EntityNotFoundException enfe) {
      // good
    }

    try {
      ds.get(hasKeyPkKey);
      fail("expected enfe");
    } catch (EntityNotFoundException enfe) {
      // good
    }

    try {
      ds.get(KeyFactory.stringToKey(hasParentKey));
      fail("expected enfe");
    } catch (EntityNotFoundException enfe) {
      // good
    }

    try {
      ds.get(hasParentKeyPkKey);
      fail("expected enfe");
    } catch (EntityNotFoundException enfe) {
      // good
    }

    Entity parentEntity = ds.get(KeyFactory.stringToKey(pojo.getId()));
    assertEquals(6, parentEntity.getProperties().size());
    assertTrue(parentEntity.hasProperty("str"));
    assertTrue(parentEntity.hasProperty("flight_id_OID"));
    assertNull(parentEntity.getProperty("flight_id_OID"));
    assertTrue(parentEntity.hasProperty("hasKeyPK_key_OID"));
View Full Code Here

Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

        new Entity(HasOneToOneParentKeyPkJDO.class.getSimpleName(), pojoEntity.getKey());
    hasParentKeyPkEntity.setProperty("str", "yag");
    ds.put(hasParentKeyPkEntity);

    startEnd.start();
    HasOneToOneJDO pojo =
        pm.getObjectById(HasOneToOneJDO.class, KeyFactory.keyToString(pojoEntity.getKey()));
    assertNotNull(pojo);
    assertNotNull(pojo.getFlight());
    assertEquals("bos", pojo.getFlight().getOrigin());
    assertEquals("mia", pojo.getFlight().getDest());
    assertNotNull(pojo.getHasKeyPK());
    assertEquals("yar", pojo.getHasKeyPK().getStr());
    assertNotNull(pojo.getHasParent());
    assertEquals("yap", pojo.getHasParent().getStr());
    assertNotNull(pojo.getHasParentKeyPK());
    assertEquals(pojo, pojo.getHasParent().getParent());
    assertEquals("yag", pojo.getHasParentKeyPK().getStr());
    assertEquals(pojo, pojo.getHasParentKeyPK().getParent());
    startEnd.end();
  }
View Full Code Here

Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

* @author Max Ross <maxr@google.com>
*/
public class JDOImplicitEntityGroupTest extends JDOTestCase {

  public void testOneToOnePersistCascadeAll() throws EntityNotFoundException {
    HasOneToOneJDO parent = new HasOneToOneJDO();
    HasOneToOneParentJDO child = new HasOneToOneParentJDO();
    parent.setHasParent(child);
    child.setParent(parent);

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

    Entity childEntity = ds.get(KeyFactory.stringToKey(child.getKey()));
    assertKeyParentEquals(parent.getId(), childEntity, childEntity.getKey());

    beginTxn();
    parent = pm.getObjectById(HasOneToOneJDO.class, parent.getId());
    assertNotNull(parent.getHasParent());
    assertNotNull(parent.getHasParent().getParent());
    commitTxn();
  }
View Full Code Here

Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

      // good
    }
  }

  public void testChildGoesIntoEntityGroupOfExistingParent() throws EntityNotFoundException {
    HasOneToOneJDO parent = new HasOneToOneJDO();

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

    beginTxn();
    HasOneToOneParentJDO child = new HasOneToOneParentJDO();
    parent.setHasParent(child);
    child.setParent(parent);

    pm.makePersistent(parent);
    commitTxn();
    beginTxn();
    parent = pm.getObjectById(HasOneToOneJDO.class, parent.getId());
    assertNotNull(parent.getHasParent());
    commitTxn();

    Entity childEntity = ds.get(KeyFactory.stringToKey(child.getKey()));
    assertKeyParentEquals(parent.getId(), childEntity, childEntity.getKey());
  }
View Full Code Here

Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

  public void testMakePersistentAll_CascadeInsert_OneToOne_NoTxn() throws EntityNotFoundException {
    switchDatasource(JDOTestCase.PersistenceManagerFactoryName.nontransactional);
    Flight f1 = newFlight();
    Flight f2 = newFlight();
    HasOneToOneJDO parent1 = new HasOneToOneJDO();
    parent1.setFlight(f1);
    HasOneToOneJDO parent2 = new HasOneToOneJDO();
    parent2.setFlight(f2);
    pm.makePersistentAll(parent1, parent2);
    assertEquals(2, countForClass(HasOneToOneJDO.class));
    assertEquals(2, countForClass(Flight.class));
    assertEquals(1, batchRecorder.batchOps);

    Entity parent1Entity = ds.get(KeyFactory.stringToKey(parent1.getId()));
    Entity flight1Entity = ds.get(KeyFactory.stringToKey(f1.getId()));
    assertEquals(6, parent1Entity.getProperties().size());
    assertTrue(parent1Entity.hasProperty("hasKeyPK_key_OID"));
    assertNull(parent1Entity.getProperty("hasKeyPK_key_OID"));
    assertTrue(parent1Entity.hasProperty("hasParent_key_OID"));
    assertNull(parent1Entity.getProperty("hasParent_key_OID"));
    assertTrue(parent1Entity.hasProperty("hasParentKeyPK_key_OID"));
    assertNull(parent1Entity.getProperty("hasParentKeyPK_key_OID"));
    assertTrue(parent1Entity.hasProperty("notDependent_id_OID"));
    assertNull(parent1Entity.getProperty("notDependent_id_OID"));
    assertEquals(flight1Entity.getKey(), parent1Entity.getProperty("flight_id_OID"));
    Entity parent2Entity = ds.get(KeyFactory.stringToKey(parent2.getId()));
    Entity flight2Entity = ds.get(KeyFactory.stringToKey(f2.getId()));
    assertEquals(6, parent2Entity.getProperties().size());
    assertTrue(parent2Entity.hasProperty("hasKeyPK_key_OID"));
    assertNull(parent2Entity.getProperty("hasKeyPK_key_OID"));
    assertTrue(parent2Entity.hasProperty("hasParent_key_OID"));
View Full Code Here

Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

  public void testMakePersistentAll_CascadeInsert_OneToOne_MultipleEntityGroups_Txn() {
    switchDatasource(JDOTestCase.PersistenceManagerFactoryName.transactional);
    Flight f1 = newFlight();
    Flight f2 = newFlight();
    HasOneToOneJDO parent1 = new HasOneToOneJDO();
    parent1.setFlight(f1);
    HasOneToOneJDO parent2 = new HasOneToOneJDO();
    parent2.setFlight(f2);
    beginTxn();
    try {
      pm.makePersistentAll(parent1, parent2);
      fail("expected exception");
    } catch (JDOUserException nue) {
View Full Code Here

Examples of com.google.appengine.datanucleus.test.jdo.HasOneToOneJDO

  public void testMakePersistentAll_CascadeInsert_OneToOne_OneEntityGroup_Txn()
      throws EntityNotFoundException {
    switchDatasource(JDOTestCase.PersistenceManagerFactoryName.transactional);
    Flight f1 = newFlight();
    Flight f2 = newFlight();
    HasOneToOneJDO parent1 = new HasOneToOneJDO();
    parent1.setId(new KeyFactory.Builder("Yar", 43).addChild(HasOneToOneJDO.class.getSimpleName(), "k1").getString());
    parent1.setFlight(f1);
    HasOneToOneJDO parent2 = new HasOneToOneJDO();
    parent2.setId(new KeyFactory.Builder("Yar", 43).addChild(HasOneToOneJDO.class.getSimpleName(), "k2").getString());
    parent2.setFlight(f2);
    beginTxn();
    pm.makePersistentAll(parent1, parent2);
    commitTxn();
    assertEquals(2, countForClass(HasOneToOneJDO.class));
    assertEquals(2, countForClass(Flight.class));
    assertEquals(1, batchRecorder.batchOps);

    Entity parent1Entity = ds.get(KeyFactory.stringToKey(parent1.getId()));
    Entity flight1Entity = ds.get(KeyFactory.stringToKey(f1.getId()));
    assertEquals(6, parent1Entity.getProperties().size());
    assertTrue(parent1Entity.hasProperty("hasKeyPK_key_OID"));
    assertNull(parent1Entity.getProperty("hasKeyPK_key_OID"));
    assertTrue(parent1Entity.hasProperty("hasParent_key_OID"));
    assertNull(parent1Entity.getProperty("hasParent_key_OID"));
    assertTrue(parent1Entity.hasProperty("hasParentKeyPK_key_OID"));
    assertNull(parent1Entity.getProperty("hasParentKeyPK_key_OID"));
    assertTrue(parent1Entity.hasProperty("notDependent_id_OID"));
    assertNull(parent1Entity.getProperty("notDependent_id_OID"));
    assertEquals(flight1Entity.getKey(), parent1Entity.getProperty("flight_id_OID"));
    Entity parent2Entity = ds.get(KeyFactory.stringToKey(parent2.getId()));
    Entity flight2Entity = ds.get(KeyFactory.stringToKey(f2.getId()));
    assertEquals(6, parent2Entity.getProperties().size());
    assertTrue(parent2Entity.hasProperty("hasKeyPK_key_OID"));
    assertNull(parent2Entity.getProperty("hasKeyPK_key_OID"));
    assertTrue(parent2Entity.hasProperty("hasParent_key_OID"));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.