use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class GeneratedIdentityTest method testTableGenerator.
/**
* Test of table generator.
*/
public void testTableGenerator() {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
// This will create the table required by our TableGenerator specification
Account acc1 = new Account();
acc1.setEnabled(true);
acc1.setUsername("bill");
em.persist(acc1);
em.flush();
// Check the structure of the table
RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
Connection conn = (Connection) databaseMgr.getConnectionManager().getConnection(0).getConnection();
DatabaseMetaData dmd = conn.getMetaData();
// Check PAYMENTS table column names
HashSet<String> columnNames = new HashSet<String>();
columnNames.add("SEQUENCE_NAME");
columnNames.add("NEXT_VAL");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "SEQUENCE_TABLE", columnNames);
tx.rollback();
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown while checking TableGenerator table structure " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class SchemaTest method testEmbeddedMap.
/**
* Test for JPA embedded map keys/values.
*/
public void testEmbeddedMap() throws Exception {
addClassesToSchema(new Class[] { EmbeddedMapOwner.class, EmbeddedMapKey.class, EmbeddedMapValue.class });
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
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();
// Map with embedded value taking default value column names
Set<String> columnNames = new HashSet<String>();
// FK to owner
columnNames.add("JPA_MAP_EMB_OWNER_ID");
// Key
columnNames.add("MAPEMBEDDEDVALUE_KEY");
// Value "name"
columnNames.add("NAME");
// Value "value"
columnNames.add("VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_MAP_EMB_VALUE", columnNames);
// Map with embedded value overriding the value column names
Set<String> columnNames2 = new HashSet<String>();
// FK to owner
columnNames2.add("JPA_MAP_EMB_OWNER_ID");
// Key "name"
columnNames2.add("MAP_KEY");
// Value "name"
columnNames2.add("MAP_VALUE_NAME");
// Value "value"
columnNames2.add("MAP_VALUE_VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_MAP_EMB_VALUE_OVERRIDE", columnNames2);
// Map with embedded key taking default key column names
Set<String> columnNames3 = new HashSet<String>();
// FK to owner
columnNames3.add("JPA_MAP_EMB_OWNER_ID");
// Key "name"
columnNames3.add("NAME");
// Key "value"
columnNames3.add("VALUE");
// Value
columnNames3.add("MAPEMBEDDEDKEY_VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_MAP_EMB_KEY", columnNames3);
// Map with embedded key overriding the key column names
Set<String> columnNames4 = new HashSet<String>();
// FK to owner
columnNames4.add("JPA_MAP_EMB_OWNER_ID");
// Key "name"
columnNames4.add("MAP_KEY_NAME");
// Key "value"
columnNames4.add("MAP_KEY_VALUE");
// Value
columnNames4.add("MAPEMBEDDEDKEYOVERRIDE_VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_MAP_EMB_KEY_OVERRIDE", columnNames4);
} catch (Exception e) {
LOG.error("Exception thrown", e);
fail("Exception thrown : " + e.getMessage());
} finally {
if (conn != null) {
mconn.close();
}
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class SchemaTest method testEmbeddedCollection.
/**
* Test for JPA embedded collection elements.
*/
public void testEmbeddedCollection() throws Exception {
addClassesToSchema(new Class[] { EmbeddedCollectionOwner.class, EmbeddedCollElement.class });
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
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();
// Map with embedded value taking default value column names
Set<String> columnNames = new HashSet<String>();
// FK to owner
columnNames.add("JPA_COLL_EMB_OWNER_ID");
// Element "name"
columnNames.add("NAME");
// Element "value"
columnNames.add("VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_COLL_EMB", columnNames);
// Map with embedded value overriding the value column names
Set<String> columnNames2 = new HashSet<String>();
// FK to owner
columnNames2.add("JPA_COLL_EMB_OWNER_ID");
// Element "name"
columnNames2.add("COLL_ELEM_NAME");
// Element "value"
columnNames2.add("COLL_ELEM_VALUE");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_COLL_EMB_OVERRIDE", columnNames2);
} catch (Exception e) {
LOG.error("Exception thrown", e);
fail("Exception thrown : " + e.getMessage());
} finally {
if (conn != null) {
mconn.close();
}
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class SchemaTest method testInheritanceStrategyTablePerClass.
/**
* Test for JPA inheritance strategy "table-per-class" on a hierarchy of classes.
*/
public void testInheritanceStrategyTablePerClass() throws Exception {
addClassesToSchema(new Class[] { InheritB.class, InheritB1.class, InheritB2.class });
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
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<String> columnNames = new HashSet<String>();
columnNames.add("ID");
columnNames.add("NAME");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_INHERIT_B", columnNames);
columnNames = new HashSet<String>();
columnNames.add("ID");
columnNames.add("NAME");
columnNames.add("NAME1");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_INHERIT_B1", columnNames);
columnNames = new HashSet<String>();
columnNames.add("ID");
columnNames.add("NAME");
columnNames.add("NAME2");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_INHERIT_B2", 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();
}
em.close();
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class SchemaTest method testInheritanceStrategySingleTable.
/**
* Test for JPA inheritance strategy "single-table" on a hierarchy of classes.
*/
public void testInheritanceStrategySingleTable() throws Exception {
addClassesToSchema(new Class[] { InheritC.class, InheritC1.class, InheritC2.class });
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
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<String> columnNames = new HashSet<String>();
columnNames.add("ID");
columnNames.add("NAME");
columnNames.add("NAME1");
columnNames.add("NAME2");
columnNames.add("DTYPE");
// Check base table column names
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "JPA_INHERIT_C", 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();
}
em.close();
}
}
Aggregations