Search in sources :

Example 1 with ConflictAssociation

use of org.datanucleus.samples.rdbms.application.ConflictAssociation in project tests by datanucleus.

the class SchemaTest method testDuplicateColumnNamesInSimpleAssociations.

/**
 * Test conflicts in naming between columns.
 */
public void testDuplicateColumnNamesInSimpleAssociations() {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        // Test conflicts in column naming in ConflictUser class.
        // 2 columns have been given the same name and should error
        boolean success = false;
        try {
            tx.begin();
            ConflictRole conflictRole = new ConflictRole();
            conflictRole.setRole("rolename");
            ConflictUser conflictUser = new ConflictUser();
            conflictUser.setUser("fred");
            conflictUser.setRole(conflictRole);
            conflictUser.setRoleid("blabla");
            pm.makePersistent(conflictUser);
            tx.commit();
        } catch (JDOFatalInternalException jdoex) {
            if (tx.isActive()) {
                tx.rollback();
            }
            success = true;
        }
        if (!success) {
            fail("completed an unexpected persistence of an object.");
        }
        // Test conflicts in column naming in ConflictAssociation class.
        // A column has been given the same name as the one JPOX will assign
        // to a different column
        success = false;
        try {
            tx.begin();
            ConflictRole conflictRole = new ConflictRole();
            conflictRole.setRole("rolename");
            ConflictAssociation conflictAssociation = new ConflictAssociation();
            conflictAssociation.setAssociation("assoc1");
            conflictAssociation.setRole(conflictRole);
            conflictAssociation.setRoleid("blabla");
            pm.makePersistent(conflictAssociation);
            tx.commit();
            fail("completed an unexpected persistence of an object");
        } catch (JDOFatalInternalException jdoex) {
            if (tx.isActive()) {
                tx.rollback();
            }
            success = true;
        }
    } catch (Exception e) {
        LOG.error("Exception thrown", e);
        fail(e.toString());
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : JDOFatalInternalException(javax.jdo.JDOFatalInternalException) Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) ConflictAssociation(org.datanucleus.samples.rdbms.application.ConflictAssociation) ConflictRole(org.datanucleus.samples.rdbms.application.ConflictRole) JDOFatalUserException(javax.jdo.JDOFatalUserException) JDOFatalInternalException(javax.jdo.JDOFatalInternalException) SQLException(java.sql.SQLException) ConflictUser(org.datanucleus.samples.rdbms.application.ConflictUser)

Aggregations

SQLException (java.sql.SQLException)1 JDOFatalInternalException (javax.jdo.JDOFatalInternalException)1 JDOFatalUserException (javax.jdo.JDOFatalUserException)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)1 ConflictAssociation (org.datanucleus.samples.rdbms.application.ConflictAssociation)1 ConflictRole (org.datanucleus.samples.rdbms.application.ConflictRole)1 ConflictUser (org.datanucleus.samples.rdbms.application.ConflictUser)1