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 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();
}
}
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();
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager 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();
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager 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();
}
}
Aggregations