Package javax.jdo

Examples of javax.jdo.PersistenceManagerFactory


    testIllegalUpdatePermutation(pmf, NO_EXPLICIT_DEMARCATION, NON_TXN_OP_NOT_ALLOWED);
    pmf.close();
  }

  public void testIllegalReads() throws Exception {
    PersistenceManagerFactory pmf = getPersistenceManagerFactory(
        JDOTestCase.PersistenceManagerFactoryName.transactional.name());
    PersistenceManager pm = pmf.getPersistenceManager();
    testIllegalReadPermutation(pm, NO_EXPLICIT_DEMARCATION, NON_TXN_OP_NOT_ALLOWED);
    pm.close();
    pmf.close();
    pmf = getPersistenceManagerFactory(
        JDOTestCase.PersistenceManagerFactoryName.nontransactional.name());
    pm = pmf.getPersistenceManager();
    testIllegalReadPermutation(pm, NO_EXPLICIT_DEMARCATION, NON_TXN_OP_NOT_ALLOWED);
    pm.close();
    pmf.close();
  }
View Full Code Here


    }
  };

  @Inner("TODO -- see if we can avoid this tx mock check")
  public void testQueriesWithDatastoreTxn() throws Exception {
    PersistenceManagerFactory pmf = getPersistenceManagerFactory(
        JDOTestCase.PersistenceManagerFactoryName.transactional.name());
    PersistenceManager pm = pmf.getPersistenceManager();
    testQueryPermutationWithExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_ALLOWED, ANCESTOR);
    testQueryPermutationWithExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_NOT_ALLOWED, ANCESTOR);
    testQueryPermutationWithExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_ALLOWED, NON_ANCESTOR);
    testQueryPermutationWithExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_NOT_ALLOWED, NON_ANCESTOR);
    pm.close();
    pmf.close();
  }
View Full Code Here

    pm.close();
    pmf.close();
  }

  public void testQueriesWithoutDatastoreTxn() throws Exception {
    PersistenceManagerFactory pmf = getPersistenceManagerFactory(
        JDOTestCase.PersistenceManagerFactoryName.transactional.name());
    PersistenceManager pm = pmf.getPersistenceManager();
    testQueryPermutationWithoutExpectedDatastoreTxn(pm, NO_EXPLICIT_DEMARCATION, NON_TXN_OP_ALLOWED, ANCESTOR);
    pm.close();
    pmf.close();

    pmf = getPersistenceManagerFactory(
        JDOTestCase.PersistenceManagerFactoryName.nontransactional.name());
    pm = pmf.getPersistenceManager();
    testQueryPermutationWithoutExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_ALLOWED, ANCESTOR);
    testQueryPermutationWithoutExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_NOT_ALLOWED, ANCESTOR);
    testQueryPermutationWithoutExpectedDatastoreTxn(pm, NO_EXPLICIT_DEMARCATION, NON_TXN_OP_ALLOWED, ANCESTOR);
    testQueryPermutationWithoutExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_ALLOWED, NON_ANCESTOR);
    testQueryPermutationWithoutExpectedDatastoreTxn(pm, EXPLICIT_DEMARCATION, NON_TXN_OP_NOT_ALLOWED, NON_ANCESTOR);
    testQueryPermutationWithoutExpectedDatastoreTxn(pm, NO_EXPLICIT_DEMARCATION, NON_TXN_OP_ALLOWED, NON_ANCESTOR);

    pm.close();
    pmf.close();
  }
View Full Code Here

    pm.close();
    pmf.close();
  }

  public void testEmptyTxnBlock_Txn() {
    PersistenceManagerFactory pmf = getPersistenceManagerFactory(
        JDOTestCase.PersistenceManagerFactoryName.transactional.name());
    PersistenceManager pm = pmf.getPersistenceManager();
    try {
      EasyMock.expect(mockDatastoreService.beginTransaction(EasyMock.isA(TransactionOptions.class))).andReturn(mockTxn);
      EasyMock.expect(mockTxn.getId()).andAnswer(txnIdAnswer);
      EasyMock.expect(mockTxn.getId()).andAnswer(txnIdAnswer);
      mockTxn.commit();
      EasyMock.expectLastCall();
      EasyMock.replay(mockDatastoreService, mockTxn);
      pm.currentTransaction().begin();
      pm.currentTransaction().commit();
      EasyMock.verify(mockDatastoreService, mockTxn);
    } finally {
      if (pm.currentTransaction().isActive()) {
        pm.currentTransaction().rollback();
      }
      pm.close();
      pmf.close();
    }
  }
View Full Code Here

      pmf.close();
    }
  }

  public void testEmptyTxnBlock_NoTxn() {
    PersistenceManagerFactory pmf = getPersistenceManagerFactory(
        JDOTestCase.PersistenceManagerFactoryName.nontransactional.name());
    PersistenceManager pm = pmf.getPersistenceManager();
    try {
      EasyMock.replay(mockDatastoreService, mockTxn);
      pm.currentTransaction().begin();
      pm.currentTransaction().commit();
      EasyMock.verify(mockDatastoreService, mockTxn);
    } finally {
      if (pm.currentTransaction().isActive()) {
        pm.currentTransaction().rollback();
      }
      pm.close();
      pmf.close();
    }
  }
View Full Code Here

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

  public void testAllocationOfDuplicateNamedPMFAsSingleton() {
    PersistenceManagerFactory pmf1 = null;
    PersistenceManagerFactory pmf2 = null;
    try {
      pmf1 = JDOHelper.getPersistenceManagerFactory("nontransactional-singleton");

      pmf2 = JDOHelper.getPersistenceManagerFactory("nontransactional-singleton");

      assertTrue(pmf1 == pmf2);
    }
    catch (Exception e) {
      fail("Exception thrown during allocation of two PMFs with same name requiring singleton");
    }
    finally {
      if (pmf1 != pmf2) {
        if (pmf1 != null) {
          pmf1.close();
        }
        if (pmf2 != null) {
          pmf2.close();
        }
      }
      else {
        if (pmf1 != null) {
          pmf1.close();
View Full Code Here

      }
    }
  }

  public void testAllocationOfDuplicateNamedPMF() {
    PersistenceManagerFactory pmf1 = null;
    PersistenceManagerFactory pmf2 = null;
    try {
      pmf1 = JDOHelper.getPersistenceManagerFactory("nontransactional");

      pmf2 = JDOHelper.getPersistenceManagerFactory("nontransactional");

      assertTrue(pmf1 != pmf2);
    }
    catch (Exception e) {
      fail("Exception thrown during allocation of two PMFs with same name");
    }
    finally {
      if (pmf1 != pmf2) {
        if (pmf1 != null) {
          pmf1.close();
        }
        if (pmf2 != null) {
          pmf2.close();
        }
      }
      else {
        if (pmf1 != null) {
          pmf1.close();
View Full Code Here

@Inner("Solve the problem of lazy loading of classes; e.g. no SuperclassTableInheritanceJDO#ChildToParentWithoutDiscriminator")
public class MigratorTest extends JDOTestCase {

  public void testMigrateOneToOneUni() {
    // Persist Parent+Child (1-1 relation) to old storage version
    PersistenceManagerFactory oldPMF = JDOHelper.getPersistenceManagerFactory("originalStorageVersion");
    PersistenceManager oldPM = oldPMF.getPersistenceManager();
    MigratorOneToOneParent p = new MigratorOneToOneParent();
    p.setName("First Parent");
    MigratorOneToOneChild c = new MigratorOneToOneChild();
    c.setName("Child 1");
    p.setChild(c);
    beginTxn();
    oldPM.makePersistent(p);
    commitTxn();
    ObjectIdentity pId = (ObjectIdentity)oldPM.getObjectId(p);
    ObjectIdentity cId = (ObjectIdentity)oldPM.getObjectId(c);
    Key pIdKey = (Key)pId.getKey();
    Key cIdKey = (Key)cId.getKey();
    oldPM.close();

    // Migrate the data
    Migrator migrator = new Migrator(((JDOPersistenceManagerFactory)oldPMF).getNucleusContext());
    try {
      // Migrate the parent
      Entity pEntity = ds.get(pIdKey);
      boolean changed = migrator.migrate(pEntity, MigratorOneToOneParent.class);
      assertTrue("Parent entity should have been changed but wasnt", changed);
      if (changed) {
        ds.put(pEntity);
      }

      // Migrate the child
      Entity cEntity = ds.get(cIdKey);
      changed = migrator.migrate(cEntity, MigratorOneToOneChild.class);
      assertFalse("Child entity shouldnt have been changed but was", changed);
      if (changed) {
        ds.put(cEntity);
      }

      assertTrue("Child keys property not added to parent", pEntity.hasProperty("child_id_OID"));
      Object propValue = pEntity.getProperty("child_id_OID");
      assertNotNull(propValue);
      assertEquals("Child key property value is not the same as the child key", cIdKey, propValue);
    } catch (EntityNotFoundException enfe) {
      fail("Some entity was not found");
    }

    oldPMF.close();
  }
View Full Code Here

    oldPMF.close();
  }

  public void testMigrateOneToManyUni() {
    // Persist Parent+Child (1-N relation) to old storage version
    PersistenceManagerFactory oldPMF = JDOHelper.getPersistenceManagerFactory("originalStorageVersion");
    PersistenceManager oldPM = oldPMF.getPersistenceManager();
    MigratorOneToManyParent p = new MigratorOneToManyParent();
    p.setName("First Parent");
    MigratorOneToManyChild c = new MigratorOneToManyChild();
    c.setName("Child 1");
    p.addChild(c);
    beginTxn();
    oldPM.makePersistent(p);
    commitTxn();
    ObjectIdentity pId = (ObjectIdentity)oldPM.getObjectId(p);
    ObjectIdentity cId = (ObjectIdentity)oldPM.getObjectId(c);
    Key pIdKey = (Key)pId.getKey();
    Key cIdKey = (Key)cId.getKey();
    oldPM.close();

    // Migrate the data
    Migrator migrator = new Migrator(((JDOPersistenceManagerFactory)oldPMF).getNucleusContext());
    try {
      // Migrate the parent
      Entity pEntity = ds.get(pIdKey);
      boolean changed = migrator.migrate(pEntity, MigratorOneToManyParent.class);
      assertTrue("Parent entity should have been changed but wasnt", changed);
      if (changed) {
        ds.put(pEntity);
      }

      // Migrate the child
      Entity cEntity = ds.get(cIdKey);
      changed = migrator.migrate(cEntity, MigratorOneToManyChild.class);
      assertFalse("Child entity shouldnt have been changed but was", changed);
      if (changed) {
        ds.put(cEntity);
      }

      assertTrue("Child keys property not added to parent", pEntity.hasProperty("children"));
      Object propValue = pEntity.getProperty("children");
      assertNotNull(propValue);
      assertTrue("Child keys property in parent should be Collection!", propValue instanceof Collection);
      Collection<Key> childKeysProp = (Collection<Key>)propValue;
      assertEquals("Number of child keys stored is incorrect", 1, childKeysProp.size());
      assertEquals("Child key property value is not the same as the child key", cIdKey, childKeysProp.iterator().next());
    } catch (EntityNotFoundException enfe) {
      fail("Some entity was not found");
    }

    oldPMF.close();
  }
View Full Code Here

    assertNull(entity.getProperty("anotherFirst"));
    assertNull(entity.getProperty("anotherLast"));
  }

  public void testFetchOfCachedPojo() throws Exception {
    PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(
        PersistenceManagerFactoryName.nontransactional.name());
    PersistenceManager pm = pmf.getPersistenceManager();
    // TODO(maxr,bslatkin): Remove this next line once this test
    // is actually working properly.
    pm.currentTransaction().setRetainValues(false);
   
    try {
      HasPromotedTypesJDO pojo = new HasPromotedTypesJDO();
      pojo.setIntVal(33);
      pojo.setIntegerVal(34);
      pojo.setIntArray(new int[] {0, 1, 2});
      pojo.setIntegerArray(new Integer[] {3, 4, 5});
      pojo.setIntList(Utils.newArrayList(3, 4, 5));
      pojo.setIntSet(Utils.newHashSet(3, 4, 5));
      pojo.setIntLinkedList(Utils.newLinkedList(31, 41, 51));
      pojo.setIntLinkedHashSet(Utils.newLinkedHashSet(31, 41, 51));
      pojo.setLongPrimVal(35L);
      pojo.setLongVal(36L);
      pojo.setLongPrimArray(new long[] {6L, 7L, 8L});
      pojo.setLongArray(new Long[] {9L, 10L, 11L});
      pojo.setLongList(Utils.newArrayList(12L, 13L, 14L));
      pojo.setLongSet(Utils.newHashSet(12L, 13L, 14L));
      pojo.setLongLinkedList(Utils.newLinkedList(121L, 131L, 141L));
      pojo.setLongLinkedHashSet(Utils.newLinkedHashSet(121L, 131L, 141L));
      pm.currentTransaction().begin();
      pm.makePersistent(pojo);
      pm.currentTransaction().commit();

      pojo = pm.getObjectById(HasPromotedTypesJDO.class, pojo.getId());
      assertEquals(33, pojo.getIntVal());
      assertEquals(Integer.valueOf(34), pojo.getIntegerVal());
      assertTrue(Arrays.equals(new int[] {0, 1, 2}, pojo.getIntArray()));
      assertTrue(Arrays.equals(new Integer[] {3, 4, 5}, pojo.getIntegerArray()));
      assertEquals(Utils.newArrayList(3, 4, 5), pojo.getIntList());
      assertEquals(Utils.newHashSet(3, 4, 5), pojo.getIntSet());
      assertEquals(Utils.newLinkedList(31, 41, 51), pojo.getIntLinkedList());
      assertEquals(Utils.newLinkedHashSet(31, 41, 51), pojo.getIntLinkedHashSet());
      assertEquals(35L, pojo.getLongPrimVal());
      assertEquals(Long.valueOf(36L), pojo.getLongVal());
      assertTrue(Arrays.equals(new long[] {6L, 7L, 8L}, pojo.getLongPrimArray()));
      assertTrue(Arrays.equals(new Long[] {9L, 10L, 11L}, pojo.getLongArray()));
      assertEquals(Utils.newArrayList(12L, 13L, 14L), pojo.getLongList());
      assertEquals(Utils.newHashSet(12L, 13L, 14L), pojo.getLongSet());
      assertEquals(Utils.newLinkedList(121L, 131L, 141L), pojo.getLongLinkedList());
      assertEquals(Utils.newLinkedHashSet(121L, 131L, 141L), pojo.getLongLinkedHashSet());
    } finally {
      pm.close();
      pmf.close();
    }
  }
View Full Code Here

TOP

Related Classes of javax.jdo.PersistenceManagerFactory

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.