use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.
the class SchemaTest method testOverridingColumnsBaseNewTableSubSuperclassTable.
/**
* Test for overriding of columns where the base class uses "new-table" and the sub class uses "superclass-table".
* The expected result is for the table to havecolumns using the overridden names.
*/
public void testOverridingColumnsBaseNewTableSubSuperclassTable() throws Exception {
addClassesToSchema(new Class[] { NBase.class, NSub.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("TYPE");
columnNames.add("LEVEL");
columnNames.add("VALUE");
columnNames.add("OVERRIDE_NAME");
// Check base table column names
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "N_BASE_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.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();
}
}
use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.
the class SchemaTest method testMap.
/**
* Test the schema generation for Sets with all possible types of declarations.
*/
public void testMap() throws Exception {
addClassesToSchema(new Class[] { MapHolder.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("MAPHOLDER_ID");
columnNames.add("NAME");
// Map<String,String> without join table, so serialised
columnNames.add("MAPNONNON");
// Map<String,String> serialised
columnNames.add("MAPSERIAL");
// FK for self-referring Map
columnNames.add("MAPHOLDER_FK2_ID_OID");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER", columnNames);
columnNames.clear();
// Map<Non,Non> using join table
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("KEY");
columnNames.add("VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER_NON_NON", columnNames);
columnNames.clear();
// Map<Non,Non> using join table and no schema info
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("KEY");
columnNames.add("VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER_NON_NON2", columnNames);
columnNames.clear();
// Map<Non,PC> using join table
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("KEY");
columnNames.add("VALUE_ID");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER_NON_PC", columnNames);
columnNames.clear();
// Map<Non,Non> using join table
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("KEY");
columnNames.add("VALUE_ID");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER_NON_PC", columnNames);
columnNames.clear();
// Map<PC,Non> using join table
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("KEY_ID");
columnNames.add("VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER_PC_NON", columnNames);
columnNames.clear();
// Map<PC,PC> using join table
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("KEY_ID");
columnNames.add("VALUE_ID");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER_PC_PC", columnNames);
columnNames.clear();
// Map<Non,PC> using join table with serialised value
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("KEY");
columnNames.add("VALUE_SERIAL");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPHOLDER_NON_PCSERIAL", columnNames);
columnNames.clear();
// Map<Non,PC> using FK with key stored in value
columnNames.add("MAPFKVALUEITEM_ID");
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("NAME");
columnNames.add("DESC");
columnNames.add("KEY");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPFKVALUEITEM", columnNames);
columnNames.clear();
// Map<PC,Non> using FK with value stored in key
columnNames.add("MAPFKKEYITEM_ID");
columnNames.add("MAPHOLDER_ID_OID");
columnNames.add("NAME");
columnNames.add("DESC");
columnNames.add("VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "MAPFKKEYITEM", columnNames);
columnNames.clear();
tx.commit();
} catch (Exception e) {
LOG.error(e);
fail("Specification of table and column names for various types of Map fields 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.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();
}
}
use of org.datanucleus.store.connection.ManagedConnection in project tests by datanucleus.
the class SchemaTest method test1To1UnidirectionalSchema.
/**
* Test the schema generation for a 1-1 unidirectional relationship.
* Checks that the tables are correctly generated.
*/
public void test1To1UnidirectionalSchema() throws Exception {
addClassesToSchema(new Class[] { Login.class, LoginAccount.class });
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
Connection conn = null;
ManagedConnection mconn = null;
try {
tx.begin();
HashSet accountColumnNames = new HashSet();
accountColumnNames.add("LOGINACCOUNT_ID");
accountColumnNames.add("FIRSTNAME");
accountColumnNames.add("LASTNAME");
accountColumnNames.add("LOGIN_ID_OID");
HashSet loginColumnNames = new HashSet();
loginColumnNames.add("LOGIN_ID");
loginColumnNames.add("USERNAME");
loginColumnNames.add("PASSWORD");
mconn = databaseMgr.getConnectionManager().getConnection(0);
conn = (Connection) mconn.getConnection();
DatabaseMetaData dmd = conn.getMetaData();
// Check LOGIN table names
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "LOGIN", loginColumnNames);
// Check LOGINACCOUNT table names
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "LOGINACCOUNT", accountColumnNames);
tx.commit();
} catch (Exception e) {
LOG.error(e);
fail("Specification of table and column names for 1-1 unidirectional is incorrect. Exception was thrown : " + e.getMessage());
} finally {
if (conn != null) {
mconn.close();
}
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations