Search in sources :

Example 51 with ClassLoaderResolverImpl

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();
}
Also used : PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 52 with 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());
}
Also used : JPOXIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) DatastoreAdapter(org.datanucleus.store.rdbms.adapter.DatastoreAdapter) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 53 with ClassLoaderResolverImpl

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
}
Also used : Configuration(org.datanucleus.Configuration) HashMap(java.util.HashMap) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPOXIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory) IdentifierFactory(org.datanucleus.store.rdbms.identifier.IdentifierFactory) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) DatastoreIdentifier(org.datanucleus.store.rdbms.identifier.DatastoreIdentifier) DatastoreAdapter(org.datanucleus.store.rdbms.adapter.DatastoreAdapter) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)53 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)35 MetaDataManager (org.datanucleus.metadata.MetaDataManager)31 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)27 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)23 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)22 NucleusContext (org.datanucleus.NucleusContext)14 ClassMetaData (org.datanucleus.metadata.ClassMetaData)14 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)12 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)10 FetchPlan (org.datanucleus.FetchPlan)7 FetchPlanForClass (org.datanucleus.FetchPlanForClass)7 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)7 BitSet (java.util.BitSet)6 NonManagedPluginRegistry (org.datanucleus.plugin.NonManagedPluginRegistry)6 HashSet (java.util.HashSet)3 Properties (java.util.Properties)3 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)3 Bundle (org.datanucleus.plugin.Bundle)3 ArrayList (java.util.ArrayList)2