Search in sources :

Example 1 with Customer

use of org.jpox.samples.models.referenceMapping.Customer in project tests by datanucleus.

the class ObjectsTest method testOneToOneXcalia.

/**
 * Test for 1-1 relations where 1 side is marked as an Object, though is
 * really PersistenceCapable using xcalia mapping
 */
public void testOneToOneXcalia() {
    try {
        Object folderId = null;
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        try {
            // Create some objects.
            tx.begin();
            Customer customer = new Customer(1);
            Folder folder = new Folder(1);
            folder.setCustomer(customer);
            pm.makePersistent(folder);
            tx.commit();
            folderId = pm.getObjectId(folder);
        } catch (JDOUserException ue) {
            assertTrue("Exception thrown during create of Folder and Customer.", false);
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        pm = pmf.getPersistenceManager();
        tx = pm.currentTransaction();
        try {
            tx.begin();
            Folder folder = (Folder) pm.getObjectById(folderId);
            assertTrue("Folder was not retrieved correctly", folder != null);
            Customer customer = (Customer) folder.getCustomer();
            assertTrue("Customer was not retrieved correctly", customer != null);
            tx.commit();
        } catch (JDOUserException ue) {
            assertTrue("Exception thrown during retrieval.", false);
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        // Clean out our data
        clean(Folder.class);
        clean(Customer.class);
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) Customer(org.jpox.samples.models.referenceMapping.Customer) Folder(org.jpox.samples.models.referenceMapping.Folder) JDOUserException(javax.jdo.JDOUserException)

Aggregations

JDOUserException (javax.jdo.JDOUserException)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 Customer (org.jpox.samples.models.referenceMapping.Customer)1 Folder (org.jpox.samples.models.referenceMapping.Folder)1