use of org.datanucleus.metadata.QueryResultMetaData in project tests by datanucleus.
the class AnnotationTest method testSqlResultSetMapping.
/**
* Test of JPA @SqlResultSetMapping
*/
public void testSqlResultSetMapping() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(LoginAccount.class.getName(), clr);
QueryResultMetaData[] queryResultMappings = cmd.getQueryResultMetaData();
assertNotNull("LoginAccount has no QueryResultMetaData!", queryResultMappings);
assertEquals("LoginAccount has incorrect number of query result mappings", 4, queryResultMappings.length);
// Example 1 : Returning 2 entities
QueryResultMetaData qrmd = null;
for (int i = 0; i < queryResultMappings.length; i++) {
QueryResultMetaData md = queryResultMappings[i];
if (md.getName().equals("AN_LOGIN_PLUS_ACCOUNT")) {
qrmd = md;
break;
}
}
if (qrmd == null) {
fail("SQL ResultSet mapping AN_LOGIN_PLUS_ACCOUNT is not present!");
}
String[] scalarCols = qrmd.getScalarColumns();
assertNull("LoginAccount sql mapping has incorrect scalar cols", scalarCols);
PersistentTypeMapping[] sqlMappingEntities = qrmd.getPersistentTypeMappings();
assertNotNull("LoginAccount sql mapping has incorrect entities", sqlMappingEntities);
assertEquals("LoginAccount sql mapping has incorrect number of entities", 2, sqlMappingEntities.length);
// LoginAccount
assertEquals("LoginAccount sql mapping entity 0 has incorrect class", LoginAccount.class.getName(), sqlMappingEntities[0].getClassName());
assertNull("LoginAccount sql mapping entity 0 has incorrect discriminator", sqlMappingEntities[0].getDiscriminatorColumn());
// Login
assertEquals("LoginAccount sql mapping entity 1 has incorrect class", Login.class.getName(), sqlMappingEntities[1].getClassName());
assertNull("LoginAccount sql mapping entity 1 has incorrect discriminator", sqlMappingEntities[1].getDiscriminatorColumn());
// Example 2 : Returning 2 scalars
qrmd = null;
for (int i = 0; i < queryResultMappings.length; i++) {
QueryResultMetaData md = queryResultMappings[i];
if (md.getName().equals("AN_ACCOUNT_NAMES")) {
qrmd = md;
break;
}
}
if (qrmd == null) {
fail("SQL ResultSet mapping AN_ACCOUNT_NAMES is not present!");
}
scalarCols = qrmd.getScalarColumns();
assertNotNull("LoginAccount sql mapping has incorrect scalar cols", scalarCols);
assertEquals("LoginAccount sql mapping has incorrect column name", "FIRSTNAME", scalarCols[0]);
assertEquals("LoginAccount sql mapping has incorrect column name", "LASTNAME", scalarCols[1]);
sqlMappingEntities = qrmd.getPersistentTypeMappings();
assertNull("LoginAccount sql mapping has incorrect entities", sqlMappingEntities);
}
use of org.datanucleus.metadata.QueryResultMetaData in project tests by datanucleus.
the class XMLTest method testSqlResultSetMapping.
/**
* Test of JPA <sql-result-set-mapping>
*/
public void testSqlResultSetMapping() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(LoginAccount.class.getName(), clr);
QueryResultMetaData[] queryResultMappings = cmd.getQueryResultMetaData();
assertNotNull("LoginAccount has no QueryResultMetaData!", queryResultMappings);
assertEquals("LoginAccount has incorrect number of query result mappings", 2, queryResultMappings.length);
// Example 1 : Returning 2 entities
QueryResultMetaData qrmd = null;
for (int i = 0; i < queryResultMappings.length; i++) {
QueryResultMetaData md = queryResultMappings[i];
if (md.getName().equals("MD_LOGIN_PLUS_ACCOUNT")) {
qrmd = md;
break;
}
}
if (qrmd == null) {
fail("SQL ResultSet mapping MD_LOGIN_PLUS_ACCOUNT is not present!");
}
String[] scalarCols = qrmd.getScalarColumns();
assertNull("LoginAccount sql mapping has incorrect scalar cols", scalarCols);
PersistentTypeMapping[] sqlMappingEntities = qrmd.getPersistentTypeMappings();
assertNotNull("LoginAccount sql mapping has incorrect entities", sqlMappingEntities);
assertEquals("LoginAccount sql mapping has incorrect number of entities", 2, sqlMappingEntities.length);
// LoginAccount
assertEquals("LoginAccount sql mapping entity 0 has incorrect class", LoginAccount.class.getName(), sqlMappingEntities[0].getClassName());
assertNull("LoginAccount sql mapping entity 0 has incorrect discriminator", sqlMappingEntities[0].getDiscriminatorColumn());
// Login
assertEquals("LoginAccount sql mapping entity 1 has incorrect class", Login.class.getName(), sqlMappingEntities[1].getClassName());
assertNull("LoginAccount sql mapping entity 1 has incorrect discriminator", sqlMappingEntities[1].getDiscriminatorColumn());
// Example 2 : Returning 2 scalars
qrmd = null;
for (int i = 0; i < queryResultMappings.length; i++) {
QueryResultMetaData md = queryResultMappings[i];
if (md.getName().equals("MD_ACCOUNT_NAMES")) {
qrmd = md;
break;
}
}
if (qrmd == null) {
fail("SQL ResultSet mapping MD_ACCOUNT_NAMES is not present!");
}
scalarCols = qrmd.getScalarColumns();
assertNotNull("LoginAccount sql mapping has incorrect scalar cols", scalarCols);
assertEquals("LoginAccount sql mapping has incorrect column name", "FIRSTNAME", scalarCols[0]);
assertEquals("LoginAccount sql mapping has incorrect column name", "LASTNAME", scalarCols[1]);
sqlMappingEntities = qrmd.getPersistentTypeMappings();
assertNull("LoginAccount sql mapping has incorrect entities", sqlMappingEntities);
}
Aggregations