use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
metaDataMgr = new JDOMetaDataManager(nucleusCtx);
clr = new ClassLoaderResolverImpl();
}
use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class IdentifierFactoryTest method testJPOXTruncate.
/**
* Verify that JPOXIdentifierFactory does truncation with a 2-character hashcode, as was done in JPOX
* 1.2.0 (this had been changed to 4-character hashcode in datanucleus)
*/
public void testJPOXTruncate() {
class SubclassForTesting extends JPOXIdentifierFactory {
private SubclassForTesting(DatastoreAdapter dba, ClassLoaderResolver clr, Map props) {
super(dba, clr, props);
}
public String publicTestTruncate(String string, int length) {
return truncate(string, length);
}
}
RDBMSStoreManager srm = (RDBMSStoreManager) storeMgr;
SubclassForTesting jpoxCompatibilityIdentifierFactory = new SubclassForTesting(srm.getDatastoreAdapter(), new ClassLoaderResolverImpl(), new Properties());
assertEquals("BIDIR_CONTAINED_LEVEL2_I2S", jpoxCompatibilityIdentifierFactory.publicTestTruncate("BIDIR_CONTAINED_LEVEL2_INTEGER", 26).toUpperCase());
}
use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class IdentifierFactoryTest method testJPA.
/**
* Tests for JPAIdentifierFactory.
*/
public void testJPA() {
RDBMSStoreManager srm = (RDBMSStoreManager) storeMgr;
IdentifierFactory idFactory = null;
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
try {
JDOPersistenceManagerFactory thePMF = (JDOPersistenceManagerFactory) pmf;
Map props = new HashMap();
Configuration conf = getConfigurationForPMF(thePMF);
if (conf.getStringProperty("datanucleus.mapping.Catalog") != null) {
props.put("DefaultCatalog", conf.getStringProperty("datanucleus.mapping.Catalog"));
}
if (conf.getStringProperty("datanucleus.mapping.Schema") != null) {
props.put("DefaultSchema", conf.getStringProperty("datanucleus.mapping.Schema"));
}
if (conf.getStringProperty("datanucleus.identifier.case") != null) {
props.put("RequiredCase", conf.getStringProperty("datanucleus.identifier.case"));
} else {
props.put("RequiredCase", srm.getDefaultIdentifierCase());
}
if (conf.getStringProperty("datanucleus.identifier.wordSeparator") != null) {
props.put("WordSeparator", conf.getStringProperty("datanucleus.identifier.wordSeparator"));
}
if (conf.getStringProperty("datanucleus.identifier.tablePrefix") != null) {
props.put("TablePrefix", conf.getStringProperty("datanucleus.identifier.tablePrefix"));
}
if (conf.getStringProperty("datanucleus.identifier.tableSuffix") != null) {
props.put("TableSuffix", conf.getStringProperty("datanucleus.identifier.tableSuffix"));
}
Class cls = Class.forName("org.datanucleus.store.rdbms.identifier.JPAIdentifierFactory");
Class[] argTypes = new Class[] { DatastoreAdapter.class, ClassLoaderResolver.class, Map.class };
Object[] args = new Object[] { srm.getDatastoreAdapter(), srm.getNucleusContext().getClassLoaderResolver(null), props };
idFactory = (IdentifierFactory) ClassUtils.newInstance(cls, argTypes, args);
} catch (Exception e) {
fail("Error creating JPAIdentifierFactory : " + e.getMessage());
}
// 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_EMPLOYEE".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("MY_COLUMN_NAME");
assertTrue("newColumnIdentifier(String) has returned an incorrect name when should have used the supplied name " + id.getName(), "MY_COLUMN_NAME".equalsIgnoreCase(id.getName()));
// c). Discriminator column identifier
id = idFactory.newDiscriminatorFieldIdentifier();
assertTrue("newDiscriminatorFieldIdentifier() has returned an incorrect name : " + id.getName(), "DTYPE".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(), "SUBORDINATES_ORDER".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_MANAGER_ID".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(), "SUBORDINATES_EMPLOYEE_ID".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, true, FieldRole.ROLE_OWNER);
assertTrue("newForeignKeyFieldIdentifier(OWNER) has returned an incorrect generated name " + id.getName(), "MANAGER_MANAGER_ID".equalsIgnoreCase(id.getName()));
// Primary key identifiers
// Index identifiers
// Foreign key identifiers
// Candidate key identifiers
// Sequence identifiers
}
Aggregations