Search in sources :

Example 1 with JDOReplicationManager

use of org.datanucleus.api.jdo.JDOReplicationManager in project tests by datanucleus.

the class ReplicationTest method testReplicateCleanToODF.

/**
 * Test that creates an Office+Computer(x2) in PMF1, replicates this to PMF2.
 */
public void testReplicateCleanToODF() {
    try {
        // Create RDBMS data
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        Object office1Id;
        try {
            tx.begin();
            Office office1 = new Office("Head Office");
            LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
            office1.addComputer(laptop1);
            DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
            office1.addComputer(desktop1);
            pm.makePersistent(office1);
            office1Id = pm.getObjectId(office1);
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        JDOReplicationManager replicator = new JDOReplicationManager(pmf, pmf2);
        replicator.replicate(office1Id);
        pm = pmf2.getPersistenceManager();
        tx = pm.currentTransaction();
        try {
            tx.begin();
            Office office1 = (Office) pm.getObjectById(office1Id);
            assertNotNull(office1);
            assertEquals("Office name is incorrect", "Head Office", office1.getName());
            assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        clean(pmf, Office.class);
        clean(pmf, LaptopComputer.class);
        clean(pmf, DesktopComputer.class);
        clean(pmf2, Office.class);
        clean(pmf2, LaptopComputer.class);
        clean(pmf2, DesktopComputer.class);
    }
}
Also used : Office(org.jpox.samples.one_many.unidir.Office) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) DesktopComputer(org.jpox.samples.one_many.unidir.DesktopComputer) LaptopComputer(org.jpox.samples.one_many.unidir.LaptopComputer) JDOReplicationManager(org.datanucleus.api.jdo.JDOReplicationManager)

Example 2 with JDOReplicationManager

use of org.datanucleus.api.jdo.JDOReplicationManager in project tests by datanucleus.

the class ReplicationTest method testReplicateCleanAllToODF.

/**
 * Test that creates an Office+Computer(x2) in PMF1, replicates using all registered classes this to PMF2.
 */
public void testReplicateCleanAllToODF() {
    try {
        // Create RDBMS data
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        Object office1Id;
        try {
            tx.begin();
            Office office1 = new Office("Head Office");
            LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
            office1.addComputer(laptop1);
            DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
            office1.addComputer(desktop1);
            pm.makePersistent(office1);
            office1Id = pm.getObjectId(office1);
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        JDOReplicationManager replicator = new JDOReplicationManager(pmf, pmf2);
        replicator.replicateRegisteredClasses();
        pm = pmf2.getPersistenceManager();
        tx = pm.currentTransaction();
        try {
            tx.begin();
            Office office1 = (Office) pm.getObjectById(office1Id);
            assertNotNull(office1);
            assertEquals("Office name is incorrect", "Head Office", office1.getName());
            assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        clean(pmf, Office.class);
        clean(pmf, LaptopComputer.class);
        clean(pmf, DesktopComputer.class);
        clean(pmf2, Office.class);
        clean(pmf2, LaptopComputer.class);
        clean(pmf2, DesktopComputer.class);
    }
}
Also used : Office(org.jpox.samples.one_many.unidir.Office) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) DesktopComputer(org.jpox.samples.one_many.unidir.DesktopComputer) LaptopComputer(org.jpox.samples.one_many.unidir.LaptopComputer) JDOReplicationManager(org.datanucleus.api.jdo.JDOReplicationManager)

Example 3 with JDOReplicationManager

use of org.datanucleus.api.jdo.JDOReplicationManager in project tests by datanucleus.

the class ReplicationTest method testReplicatePartialFromODF.

/**
 * Test that creates an Office+Computer in PMF1, and Office+Computer(x2) in PMF2.
 * Then replicates from PMF2 to PMF1 and checks that the other Computer is replicated.
 */
public void testReplicatePartialFromODF() throws IOException {
    try {
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        Object office1Id;
        try {
            tx.begin();
            Office office1 = new Office("Head Office");
            LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
            office1.addComputer(laptop1);
            pm.makePersistent(office1);
            office1Id = pm.getObjectId(office1);
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        pm = pmf2.getPersistenceManager();
        tx = pm.currentTransaction();
        try {
            tx.begin();
            Office office1 = new Office("Head Office");
            LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
            office1.addComputer(laptop1);
            DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
            office1.addComputer(desktop1);
            pm.makePersistent(office1);
            office1Id = pm.getObjectId(office1);
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        JDOReplicationManager replicator = new JDOReplicationManager(pmf2, pmf);
        replicator.replicate(office1Id);
        pm = pmf.getPersistenceManager();
        tx = pm.currentTransaction();
        try {
            tx.begin();
            Office office1 = (Office) pm.getObjectById(office1Id);
            assertNotNull(office1);
            assertEquals("Office name is incorrect", "Head Office", office1.getName());
            assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        clean(pmf, Office.class);
        clean(pmf, LaptopComputer.class);
        clean(pmf, DesktopComputer.class);
        clean(pmf2, Office.class);
        clean(pmf2, LaptopComputer.class);
        clean(pmf2, DesktopComputer.class);
    }
}
Also used : Office(org.jpox.samples.one_many.unidir.Office) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) DesktopComputer(org.jpox.samples.one_many.unidir.DesktopComputer) LaptopComputer(org.jpox.samples.one_many.unidir.LaptopComputer) JDOReplicationManager(org.datanucleus.api.jdo.JDOReplicationManager)

Example 4 with JDOReplicationManager

use of org.datanucleus.api.jdo.JDOReplicationManager in project tests by datanucleus.

the class ReplicationTest method testReplicateCleanFromODF.

/**
 * Test that creates an Office+Computer(x2) in PMF2, replicates this to PMF1.
 */
public void testReplicateCleanFromODF() throws IOException {
    try {
        PersistenceManager pm = pmf2.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        Object office1Id;
        try {
            tx.begin();
            Office office1 = new Office("Head Office");
            LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
            office1.addComputer(laptop1);
            DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
            office1.addComputer(desktop1);
            pm.makePersistent(office1);
            office1Id = pm.getObjectId(office1);
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        JDOReplicationManager replicator = new JDOReplicationManager(pmf2, pmf);
        replicator.replicate(office1Id);
        pm = pmf.getPersistenceManager();
        tx = pm.currentTransaction();
        try {
            tx.begin();
            Office office1 = (Office) pm.getObjectById(office1Id);
            assertNotNull(office1);
            assertEquals("Office name is incorrect", "Head Office", office1.getName());
            assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        clean(pmf, Office.class);
        clean(pmf, LaptopComputer.class);
        clean(pmf, DesktopComputer.class);
        clean(pmf2, Office.class);
        clean(pmf2, LaptopComputer.class);
        clean(pmf2, DesktopComputer.class);
    }
}
Also used : Office(org.jpox.samples.one_many.unidir.Office) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) DesktopComputer(org.jpox.samples.one_many.unidir.DesktopComputer) LaptopComputer(org.jpox.samples.one_many.unidir.LaptopComputer) JDOReplicationManager(org.datanucleus.api.jdo.JDOReplicationManager)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)4 Transaction (javax.jdo.Transaction)4 JDOReplicationManager (org.datanucleus.api.jdo.JDOReplicationManager)4 DesktopComputer (org.jpox.samples.one_many.unidir.DesktopComputer)4 LaptopComputer (org.jpox.samples.one_many.unidir.LaptopComputer)4 Office (org.jpox.samples.one_many.unidir.Office)4