Search in sources :

Example 96 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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 97 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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 98 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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 99 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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 100 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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

RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)197 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)84 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)82 SQLException (java.sql.SQLException)78 Connection (java.sql.Connection)76 HashSet (java.util.HashSet)72 DatabaseMetaData (java.sql.DatabaseMetaData)62 PersistenceManager (javax.jdo.PersistenceManager)61 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)56 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)55 Transaction (javax.jdo.Transaction)52 ArrayList (java.util.ArrayList)49 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)49 JDOFatalUserException (javax.jdo.JDOFatalUserException)48 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)44 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)42 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)41 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)38 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)28 JDOFatalInternalException (javax.jdo.JDOFatalInternalException)25