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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations