Search in sources :

Example 61 with ManagedConnection

use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.

the class SchemaTest method testArrayPC.

/**
 * Test the schema generation for an array of PC objects, stored serialised and stored in
 * a join table.
 */
public void testArrayPC() throws Exception {
    try {
        addClassesToSchema(new Class[] { PersistableArray.class, ArrayElement.class });
    } catch (Exception e) {
        e.printStackTrace();
    }
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
    Connection conn = null;
    ManagedConnection mconn = null;
    try {
        tx.begin();
        mconn = databaseMgr.getConnectionManager().getConnection(0);
        conn = (Connection) mconn.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        HashSet tableColumnNames = new HashSet();
        // Check column names for main table
        tableColumnNames.add("PERSISTABLEARRAY_ID");
        tableColumnNames.add("ARRAY1");
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "PERSISTABLEARRAY", tableColumnNames);
        tableColumnNames.clear();
        // Check column names for join table
        tableColumnNames.add("ARRAY_ID_OID");
        tableColumnNames.add("ELEMENT_ID_EID");
        tableColumnNames.add("IDX");
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "ARRAY_PERSISTABLEARRAY", tableColumnNames);
        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
        LOG.error(e);
        fail("Specification of table and column names for PC array is incorrect. Exception was thrown : " + e.getMessage());
    } finally {
        if (conn != null) {
            mconn.close();
        }
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Connection(java.sql.Connection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) DatabaseMetaData(java.sql.DatabaseMetaData) JDOFatalUserException(javax.jdo.JDOFatalUserException) JDOFatalInternalException(javax.jdo.JDOFatalInternalException) SQLException(java.sql.SQLException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Example 62 with ManagedConnection

use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.

the class SchemaTest method testOverridingColumnsBaseNewTableSubNewTable.

/**
 * Test for overriding of columns where the base class uses "new-table" and the sub class uses "new-table".
 * The expected result is for the subclass table to have extra columns for the overridden fields.
 */
public void testOverridingColumnsBaseNewTableSubNewTable() throws Exception {
    addClassesToSchema(new Class[] { LBase.class, LSub.class });
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
    Connection conn = null;
    ManagedConnection mconn = null;
    try {
        tx.begin();
        mconn = databaseMgr.getConnectionManager().getConnection(0);
        conn = (Connection) mconn.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        HashSet columnNames = new HashSet();
        columnNames.add("ID");
        columnNames.add("NAME");
        columnNames.add("LEVEL");
        // Check base table column names
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "L_BASE", columnNames);
        columnNames = new HashSet();
        columnNames.add("ID");
        columnNames.add("OVERRIDE_NAME");
        columnNames.add("VALUE");
        // Check sub table column names
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "L_SUB", columnNames);
        tx.commit();
    } catch (Exception e) {
        LOG.error(e);
        fail("Specification of table and column names must have been ignored when creating the schema for " + "inheritance case where the fields were overridden. Exception was thrown : " + e.getMessage());
    } finally {
        if (conn != null) {
            mconn.close();
        }
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Connection(java.sql.Connection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) DatabaseMetaData(java.sql.DatabaseMetaData) JDOFatalUserException(javax.jdo.JDOFatalUserException) JDOFatalInternalException(javax.jdo.JDOFatalInternalException) SQLException(java.sql.SQLException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Example 63 with ManagedConnection

use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.

the class SchemaTest method testInterfacesMappingStrategyIdentity.

/**
 * Test of the specification of table and column names for Interface types when using the
 * mapping-strategy of "identity.
 */
public void testInterfacesMappingStrategyIdentity() throws Exception {
    addClassesToSchema(new Class[] { Diet.class });
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
    Connection conn = null;
    ManagedConnection mconn = null;
    try {
        tx.begin();
        mconn = databaseMgr.getConnectionManager().getConnection(0);
        conn = (Connection) mconn.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        HashSet columnNames = new HashSet();
        // Check table column names
        columnNames.add("DIET_ID");
        columnNames.add("FAVOURITE");
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "DIET", columnNames);
        columnNames.clear();
        // Check Set join table
        columnNames.add("DIET_ID_OID");
        columnNames.add("FOOD");
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "DIET_FOODS", columnNames);
        columnNames.clear();
        tx.commit();
    } catch (Exception e) {
        LOG.error(e);
        fail("Specification of table and column names was incorrect when using Interface type fields. Exception was thrown : " + e.getMessage());
    } finally {
        if (conn != null) {
            mconn.close();
        }
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Connection(java.sql.Connection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) DatabaseMetaData(java.sql.DatabaseMetaData) JDOFatalUserException(javax.jdo.JDOFatalUserException) JDOFatalInternalException(javax.jdo.JDOFatalInternalException) SQLException(java.sql.SQLException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Example 64 with ManagedConnection

use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.

the class SchemaTest method testObjectFields.

/**
 * Test of the specification of table and column names for Object 1-1, 1-N relations.
 */
public void testObjectFields() throws Exception {
    addClassesToSchema(new Class[] { ObjectHolder.class });
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
    Connection conn = null;
    ManagedConnection mconn = null;
    try {
        tx.begin();
        mconn = databaseMgr.getConnectionManager().getConnection(0);
        conn = (Connection) mconn.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        // Check primary table
        HashSet columnNames = new HashSet();
        columnNames.add("ID");
        columnNames.add("NAME");
        columnNames.add("EMBEDDEDOBJECT");
        columnNames.add("SERIALISEDOBJECT");
        columnNames.add("NONSERIALISED_IMPL1_ID");
        columnNames.add("NONSERIALISED_IMPL2_ID");
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "OBJECT_HOLDER", columnNames);
        // Check join table
        columnNames.clear();
        columnNames.add("HOLDER_ID");
        columnNames.add("OBJECT_IMPL_1_ID");
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "OBJECT_SET1_OBJECTS", columnNames);
        tx.commit();
    } catch (Exception e) {
        LOG.error(e);
        fail("Specification of table and column names was incorrect when using Object collection fields. Exception was thrown : " + e.getMessage());
    } finally {
        if (conn != null) {
            mconn.close();
        }
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Connection(java.sql.Connection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) DatabaseMetaData(java.sql.DatabaseMetaData) JDOFatalUserException(javax.jdo.JDOFatalUserException) JDOFatalInternalException(javax.jdo.JDOFatalInternalException) SQLException(java.sql.SQLException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Example 65 with ManagedConnection

use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.

the class SchemaTest method testEmbeddedPCCollectionSchema.

/**
 * Test the schema generation for an object with collection of embedded PC objects.
 */
public void testEmbeddedPCCollectionSchema() throws Exception {
    addClassesToSchema(new Class[] { Network.class });
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
    Connection conn = null;
    ManagedConnection mconn = null;
    try {
        tx.begin();
        HashSet networkColumnNames = new HashSet();
        networkColumnNames.add("NETWORK_ID");
        networkColumnNames.add("NAME");
        HashSet joinColumnNames = new HashSet();
        joinColumnNames.add("NETWORK_ID");
        joinColumnNames.add("IDX");
        joinColumnNames.add("DESCRIPTION");
        joinColumnNames.add("DEVICE_IP_ADDR");
        joinColumnNames.add("DEVICE_NAME");
        mconn = databaseMgr.getConnectionManager().getConnection(0);
        conn = (Connection) mconn.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        // Check NETWORK table names
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "NETWORK", networkColumnNames);
        // Check NETWORK_DEVICES join table names
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "NETWORK_DEVICES", joinColumnNames);
        tx.commit();
    } catch (Exception e) {
        LOG.error(e);
        fail("Specification of table and column names for embedded PC collection is incorrect. Exception was thrown : " + e.getMessage());
    } finally {
        if (conn != null) {
            mconn.close();
        }
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Connection(java.sql.Connection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) DatabaseMetaData(java.sql.DatabaseMetaData) JDOFatalUserException(javax.jdo.JDOFatalUserException) JDOFatalInternalException(javax.jdo.JDOFatalInternalException) SQLException(java.sql.SQLException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Aggregations

ManagedConnection (org.datanucleus.store.connection.ManagedConnection)157 SQLException (java.sql.SQLException)125 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)80 Connection (java.sql.Connection)75 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)74 PreparedStatement (java.sql.PreparedStatement)70 ExecutionContext (org.datanucleus.ExecutionContext)64 SQLController (org.datanucleus.store.rdbms.SQLController)63 HashSet (java.util.HashSet)62 DatabaseMetaData (java.sql.DatabaseMetaData)58 PersistenceManager (javax.jdo.PersistenceManager)46 Transaction (javax.jdo.Transaction)46 JDOFatalUserException (javax.jdo.JDOFatalUserException)45 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)45 ResultSet (java.sql.ResultSet)37 JDOFatalInternalException (javax.jdo.JDOFatalInternalException)24 JDODataStoreException (javax.jdo.JDODataStoreException)21 JDOUserException (javax.jdo.JDOUserException)21 MappedDatastoreException (org.datanucleus.store.rdbms.exceptions.MappedDatastoreException)21 EntityTransaction (javax.persistence.EntityTransaction)19