use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class ConvertersTest method testUseOfPersistentConverter.
/**
* Test the use of "@Persistent(converter="...")" annotation on a field.
*/
public void testUseOfPersistentConverter() {
try {
PersistenceNucleusContext nucCtx = ((JDOPersistenceManagerFactory) pmf).getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
AbstractClassMetaData cmd = nucCtx.getMetaDataManager().getMetaDataForClass(PersonWithConverters.class, clr);
// Check the converter is registered with metadata
AbstractMemberMetaData mmd = cmd.getMetaDataForMember("myBool1");
assertNotNull(mmd);
assertTrue(mmd.hasExtension("type-converter-name"));
String converterName = mmd.getValueForExtension("type-converter-name");
assertEquals("org.datanucleus.samples.converters.Boolean10Converter", converterName);
// Check the correct mapping is chosen for this field
RDBMSStoreManager storeMgr = (RDBMSStoreManager) nucCtx.getStoreManager();
DatastoreClass tbl = storeMgr.getDatastoreClass(PersonWithConverters.class.getName(), clr);
JavaTypeMapping mapping = tbl.getMemberMapping(mmd);
assertTrue(mapping instanceof TypeConverterMapping);
} catch (Exception e) {
LOG.error("Exception during test", e);
fail("Exception was thrown : " + e.getMessage());
} finally {
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class ConvertersTest method testUseOfConvert.
/**
* Test the use of "@Convert" annotation on a field.
*/
public void testUseOfConvert() {
try {
PersistenceNucleusContext nucCtx = ((JDOPersistenceManagerFactory) pmf).getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
AbstractClassMetaData cmd = nucCtx.getMetaDataManager().getMetaDataForClass(PersonWithConverters.class, clr);
// Check the converter is registered with metadata
AbstractMemberMetaData mmd = cmd.getMetaDataForMember("myBool2");
assertNotNull(mmd);
assertTrue(mmd.hasExtension("type-converter-name"));
String converterName = mmd.getValueForExtension("type-converter-name");
assertEquals("org.datanucleus.samples.converters.BooleanYNConverter", converterName);
// Check the correct mapping is chosen for this field
RDBMSStoreManager storeMgr = (RDBMSStoreManager) nucCtx.getStoreManager();
DatastoreClass tbl = storeMgr.getDatastoreClass(PersonWithConverters.class.getName(), clr);
JavaTypeMapping mapping = tbl.getMemberMapping(mmd);
assertTrue(mapping instanceof TypeConverterMapping);
} catch (Exception e) {
LOG.error("Exception during test", e);
fail("Exception was thrown : " + e.getMessage());
} finally {
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class IdentifierFactoryTest method testDataNucleus2.
/**
* Tests for DNIdentifierFactory
*/
public void testDataNucleus2() {
RDBMSStoreManager srm = (RDBMSStoreManager) storeMgr;
IdentifierFactory idFactory = srm.getIdentifierFactory();
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
// Table identifiers
// a). generated name shorter than max length
DatastoreIdentifier id = idFactory.newIdentifier(IdentifierType.TABLE, "MyClass");
assertTrue("newIdentifier(TABLE, String) has generated an incorrect name : " + id.getName(), "MYCLASS".equalsIgnoreCase(id.getName()));
// b). specified name shorter than max length
id = idFactory.newTableIdentifier("MY_TABLE_NAME");
assertTrue("newDatastoreContainerIdentifier(String) has returned an incorrect name when should have used the supplied name " + id.getName(), "MY_TABLE_NAME".equalsIgnoreCase(id.getName()));
// c). name specified via ClassMetaData
AbstractClassMetaData managerCMD = storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass("org.jpox.samples.models.company.Manager", clr);
id = idFactory.newTableIdentifier(managerCMD);
assertTrue("newDatastoreContainerIdentifier(clr, ClassMetaData) has returned an incorrect generated name " + id.getName(), "MANAGER".equalsIgnoreCase(id.getName()));
// d). name specified via ClassMetaData
AbstractMemberMetaData fmd = managerCMD.getMetaDataForMember("subordinates");
id = idFactory.newTableIdentifier(fmd);
assertTrue("newDatastoreContainerIdentifier(clr, AbstractMemberMetaData) has returned an incorrect generated name " + id.getName(), "MANAGER_SUBORDINATES".equalsIgnoreCase(id.getName()));
// Column identifiers
// a). generated name shorter than max length
id = idFactory.newIdentifier(IdentifierType.COLUMN, "myField");
assertTrue("newIdentifier(COLUMN, String) has generated an incorrect name : " + id.getName(), "MYFIELD".equalsIgnoreCase(id.getName()));
// b). specified name shorter than max length
id = idFactory.newColumnIdentifier("MYCOLUMNNAME");
assertTrue("newColumnIdentifier(String) has returned an incorrect name when should have used the supplied name " + id.getName(), "MYCOLUMNNAME".equalsIgnoreCase(id.getName()));
// c). Discriminator column identifier
id = idFactory.newDiscriminatorFieldIdentifier();
assertTrue("newDiscriminatorFieldIdentifier() has returned an incorrect name : " + id.getName(), "DISCRIMINATOR".equalsIgnoreCase(id.getName()));
// d). Version column identifier
id = idFactory.newVersionFieldIdentifier();
assertTrue("newVersionFieldIdentifier() has returned an incorrect name : " + id.getName(), "VERSION".equalsIgnoreCase(id.getName()));
// e). Index (ordering) column identifier
id = idFactory.newIndexFieldIdentifier(fmd);
assertTrue("newIndexFieldIdentifier() has returned an incorrect name : " + id.getName(), "IDX".equalsIgnoreCase(id.getName()));
// f). Adapter Index column identifier
id = idFactory.newAdapterIndexFieldIdentifier();
assertTrue("newAdapterIndexFieldIdentifier() has returned an incorrect name : " + id.getName(), "IDX".equalsIgnoreCase(id.getName()));
AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
// g). join table owner column identifier (1-N bi JoinTable)
DatastoreIdentifier destId = idFactory.newColumnIdentifier("MANAGER_ID");
id = idFactory.newJoinTableFieldIdentifier(fmd, relatedMmds != null ? relatedMmds[0] : null, destId, false, FieldRole.ROLE_OWNER);
assertTrue("newJoinTableFieldIdentifier(OWNER) has returned an incorrect generated name " + id.getName(), "MANAGER_ID_OID".equalsIgnoreCase(id.getName()));
// h). join table element column identifier (1-N bi JoinTable)
destId = idFactory.newColumnIdentifier("EMPLOYEE_ID");
id = idFactory.newJoinTableFieldIdentifier(fmd, relatedMmds != null ? relatedMmds[0] : null, destId, false, FieldRole.ROLE_COLLECTION_ELEMENT);
assertTrue("newJoinTableFieldIdentifier(ELEMENT) has returned an incorrect generated name " + id.getName(), "EMPLOYEE_ID_EID".equalsIgnoreCase(id.getName()));
// i). FK owner column identifier (1-N bi FK)
AbstractMemberMetaData deptsFMD = managerCMD.getMetaDataForMember("departments");
AbstractMemberMetaData[] deptsRelatedMmds = deptsFMD.getRelatedMemberMetaData(clr);
destId = idFactory.newColumnIdentifier("MANAGER_ID");
id = idFactory.newForeignKeyFieldIdentifier(deptsFMD, deptsRelatedMmds != null ? deptsRelatedMmds[0] : null, destId, false, FieldRole.ROLE_OWNER);
assertTrue("newForeignKeyFieldIdentifier(OWNER) has returned an incorrect generated name " + id.getName(), "MANAGER_MANAGER_ID_OID".equalsIgnoreCase(id.getName()));
// Primary key identifiers
// Index identifiers
// Foreign key identifiers
// Candidate key identifiers
// Sequence identifiers
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class JDOQLBasicTest method testOrderNullsFirstLast.
/**
* Tests the extension for location of NULLS within an ORDER BY clause.
*/
public void testOrderNullsFirstLast() {
RDBMSStoreManager srm = (RDBMSStoreManager) storeMgr;
if (!srm.getDatastoreAdapter().supportsOption(DatastoreAdapter.ORDERBY_NULLS_DIRECTIVES)) {
// Not supported so it passed :-)
return;
}
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Persist some simple objects (uses datastore id, or composite application id depending on suite)
tx.begin();
for (int i = 0; i < 3; i++) {
Office off = new Office(i, "Colour" + i, null);
pm.makePersistent(off);
}
Office o1 = new Office(3, "Green", "Big spacious office");
Office o2 = new Office(4, "Blue", "Pokey office at the back of the building");
Office o3 = new Office(5, "Yellow", "Massive open plan office");
pm.makePersistent(o1);
pm.makePersistent(o2);
pm.makePersistent(o3);
tx.commit();
tx.begin();
Query q = pm.newQuery("SELECT FROM " + Office.class.getName() + " ORDER BY description NULLS FIRST");
List<Office> offices = (List<Office>) q.execute();
assertEquals(6, offices.size());
Iterator<Office> it = offices.iterator();
assertNull("First result (NULLS FIRST) should have null description", it.next().getDescription());
assertNull("Second result (NULLS FIRST) should have null description", it.next().getDescription());
assertNull("Third result (NULLS FIRST) should have null description", it.next().getDescription());
assertNotNull("Fourth result (NULLS FIRST) should have not null description", it.next().getDescription());
assertNotNull("Fifth result (NULLS FIRST) should have not null description", it.next().getDescription());
assertNotNull("Sixth result (NULLS FIRST) should have not null description", it.next().getDescription());
q = pm.newQuery("SELECT FROM " + Office.class.getName() + " ORDER BY description NULLS LAST");
offices = (List<Office>) q.execute();
assertEquals(6, offices.size());
it = offices.iterator();
assertNotNull("First result (NULLS FIRST) should have not null description", it.next().getDescription());
assertNotNull("Second result (NULLS FIRST) should have not null description", it.next().getDescription());
assertNotNull("Third result (NULLS FIRST) should have not null description", it.next().getDescription());
assertNull("Fourth result (NULLS FIRST) should have null description", it.next().getDescription());
assertNull("Fifth result (NULLS FIRST) should have null description", it.next().getDescription());
assertNull("Sixth result (NULLS FIRST) should have null description", it.next().getDescription());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
// Clean out our data
clean(Office.class);
}
}
use of org.datanucleus.store.rdbms.RDBMSStoreManager in project tests by datanucleus.
the class SchemaTest method testArrayNonPC.
/**
* Test the schema generation for an array of primitives, stored serialised and stored in
* a join table.
*/
public void testArrayNonPC() throws Exception {
addClassesToSchema(new Class[] { IntArray.class });
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
Connection conn = null;
ManagedConnection mconn = null;
try {
tx.begin();
HashSet tableColumnNames = new HashSet();
mconn = databaseMgr.getConnectionManager().getConnection(0);
conn = (Connection) mconn.getConnection();
DatabaseMetaData dmd = conn.getMetaData();
// Main table with serialised int[]
tableColumnNames.add("INTARRAY_ID");
tableColumnNames.add("ARRAY1");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "INTARRAY", tableColumnNames);
tableColumnNames.clear();
// Join table for int[]
tableColumnNames.add("ARRAY_ID_OID");
tableColumnNames.add("INT_VALUE");
tableColumnNames.add("IDX");
RDBMSTestHelper.checkColumnsForTable(storeMgr, dmd, "ARRAY_INTARRAY", tableColumnNames);
tx.commit();
} catch (Exception e) {
LOG.error(e);
fail("Specification of table and column names for serialised array is incorrect. Exception was thrown : " + e.getMessage());
} finally {
if (conn != null) {
mconn.close();
}
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations