Search in sources :

Example 66 with ManagedConnection

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

the class SchemaTest method testEmbeddedPCInheritedSchema.

/**
 * Test the schema generation for embedded PC objects which have inheritance
 * Checks that the tables are correctly generated and the correct columns are present.
 */
public void testEmbeddedPCInheritedSchema() throws Exception {
    addClassesToSchema(new Class[] { FittedKitchen.class, Oven.class, MultifunctionOven.class });
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
    Connection conn = null;
    ManagedConnection mconn = null;
    try {
        tx.begin();
        HashSet embeddedColumnNames = new HashSet();
        embeddedColumnNames.add("KITCHEN_ID");
        embeddedColumnNames.add("MAKE");
        embeddedColumnNames.add("OVEN_DISCRIMINATOR");
        embeddedColumnNames.add("OVEN_MAKE");
        embeddedColumnNames.add("OVEN_MODEL");
        embeddedColumnNames.add("OVEN_CAPABILITIES");
        embeddedColumnNames.add("MULTIOVEN_MAKE");
        embeddedColumnNames.add("MULTIOVEN_MODEL");
        embeddedColumnNames.add("MULTIOVEN_CAPS");
        mconn = databaseMgr.getConnectionManager().getConnection(0);
        conn = (Connection) mconn.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        // Check container columns
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "KITCHEN", embeddedColumnNames);
        tx.commit();
    } catch (Exception e) {
        LOG.error(e);
        fail("Specification of table and column names for embedded PC object with inheritance 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 67 with ManagedConnection

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

the class SchemaTest method testOverridingColumnsBaseSubclassTableSubNewTable.

/**
 * Test for overriding of columns where the base class uses "subclass-table" and the sub class uses "new-table".
 * The expected result is for the subclass table to the columns for the base class but using the overridden names.
 */
public void testOverridingColumnsBaseSubclassTableSubNewTable() throws Exception {
    addClassesToSchema(new Class[] { MBase.class, MSub1.class, MSub2.class, MRelated.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("VALUE");
        columnNames.add("BASE_2A_NAME");
        columnNames.add("BASE_2A_RELATED_ID");
        // Check base table column names
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "M_SUB1_OVERRIDE", columnNames);
        columnNames = new HashSet();
        columnNames.add("ID");
        columnNames.add("VALUE");
        columnNames.add("BASE_2B_NAME");
        columnNames.add("BASE_2B_RELATED_ID");
        // Check sub table column names
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "M_SUB2_OVERRIDE", 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) JDOUserException(javax.jdo.JDOUserException) JDOFatalUserException(javax.jdo.JDOFatalUserException) SQLException(java.sql.SQLException) JDODataStoreException(javax.jdo.JDODataStoreException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Example 68 with ManagedConnection

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

the class SchemaTest method testEmbeddedPCSchema.

/**
 * Test the schema generation for embedded PC objects.
 * Checks that the tables are correctly generated and the correct columns are present.
 */
public void testEmbeddedPCSchema() throws Exception {
    addClassesToSchema(new Class[] { Computer.class });
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
    Connection conn = null;
    ManagedConnection mconn = null;
    try {
        tx.begin();
        HashSet embeddedColumnNames = new HashSet();
        embeddedColumnNames.add("COMPUTER_ID");
        embeddedColumnNames.add("OS_NAME");
        embeddedColumnNames.add("GRAPHICS_MAKER");
        embeddedColumnNames.add("GRAPHICS_TYPE");
        embeddedColumnNames.add("GRAPHICS_MANUFACTURER_ID");
        embeddedColumnNames.add("SOUND_MAKER");
        embeddedColumnNames.add("SOUND_TYPE");
        embeddedColumnNames.add("SOUND_MANUFACTURER_ID");
        mconn = databaseMgr.getConnectionManager().getConnection(0);
        conn = (Connection) mconn.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        // Check container columns
        RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "COMPUTER", embeddedColumnNames);
        tx.commit();
    } catch (Exception e) {
        LOG.error(e);
        fail("Specification of table and column names for embedded PC object 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) JDOUserException(javax.jdo.JDOUserException) JDOFatalUserException(javax.jdo.JDOFatalUserException) SQLException(java.sql.SQLException) JDODataStoreException(javax.jdo.JDODataStoreException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Example 69 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) JDOUserException(javax.jdo.JDOUserException) JDOFatalUserException(javax.jdo.JDOFatalUserException) SQLException(java.sql.SQLException) JDODataStoreException(javax.jdo.JDODataStoreException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) HashSet(java.util.HashSet)

Example 70 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) JDOUserException(javax.jdo.JDOUserException) JDOFatalUserException(javax.jdo.JDOFatalUserException) SQLException(java.sql.SQLException) JDODataStoreException(javax.jdo.JDODataStoreException) 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