Search in sources :

Example 26 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.

the class PluginParserTest method testRequireBundleVersionLogged.

public void testRequireBundleVersionLogged() {
    final java.util.Set messages = new HashSet();
    Logger.getLogger("DataNucleus.General").addAppender(new Appender() {

        public void setName(String arg0) {
        }

        public void setLayout(Layout arg0) {
        }

        public void setErrorHandler(ErrorHandler arg0) {
        }

        public boolean requiresLayout() {
            return false;
        }

        public String getName() {
            return "testappender123";
        }

        public Layout getLayout() {
            return null;
        }

        public Filter getFilter() {
            return null;
        }

        public ErrorHandler getErrorHandler() {
            return null;
        }

        public void doAppend(LoggingEvent arg0) {
            if (arg0.getLevel() != Level.DEBUG) {
                messages.add(arg0.getRenderedMessage());
            }
        }

        public void close() {
        }

        public void clearFilters() {
        }

        public void addFilter(Filter arg0) {
        }
    });
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION", true);
    assertEquals(0, mgr.getExtensionPoints().length);
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST10.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST11.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST12.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST13.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST14.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST15.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST16.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST17.MF", null));
    mgr.resolveConstraints();
    try {
        assertEquals(3, messages.size());
        assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test12\" requires \"org.datanucleus.plugin.test11\" version \"(1.2.0.b2\" but the resolved bundle has version \"1.2.0.b2\" which is outside the expected range."));
        assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test13\" requires \"org.datanucleus.plugin.test11\" version \"(1.2.0.c1\" but the resolved bundle has version \"1.2.0.b2\" which is outside the expected range."));
        assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test15\" requires \"org.datanucleus.plugin.test11\" version \"(1.0.0.b2,1.2.0.b2)\" but the resolved bundle has version \"1.2.0.b2\" which is outside the expected range."));
    } finally {
        Logger.getLogger("DataNucleus.General").removeAppender("testappender123");
    }
}
Also used : Appender(org.apache.log4j.Appender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) ErrorHandler(org.apache.log4j.spi.ErrorHandler) Layout(org.apache.log4j.Layout) Filter(org.apache.log4j.spi.Filter) NonManagedPluginRegistry(org.datanucleus.plugin.NonManagedPluginRegistry) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) HashSet(java.util.HashSet) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 27 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.

the class MyConstructorClass method testClassesAreDescendents.

/**
 * Test for whether classes are descendents of each other.
 */
public void testClassesAreDescendents() {
    ClassLoaderResolver clr = new ClassLoaderResolverImpl(null);
    assertTrue("java.util.Collection and java.util.ArrayList should have been direct descendents but weren't", ClassUtils.classesAreDescendents(clr, "java.util.Collection", "java.util.ArrayList"));
    assertTrue("java.util.ArrayList and java.util.Collection should have been direct descendents but weren't", ClassUtils.classesAreDescendents(clr, "java.util.ArrayList", "java.util.Collection"));
    assertTrue("java.util.ArrayList and java.lang.String shouldn't have been direct descendents but were", !ClassUtils.classesAreDescendents(clr, "java.util.ArrayList", "java.lang.String"));
}
Also used : ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 28 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project hive by apache.

the class ObjectStore method clearClr.

private static void clearClr(ClassLoaderResolver clr) throws Exception {
    if (clr != null) {
        if (clr instanceof ClassLoaderResolverImpl) {
            ClassLoaderResolverImpl clri = (ClassLoaderResolverImpl) clr;
            long resourcesCleared = clearFieldMap(clri, "resources");
            long loadedClassesCleared = clearFieldMap(clri, "loadedClasses");
            long unloadedClassesCleared = clearFieldMap(clri, "unloadedClasses");
            LOG.debug("Cleared ClassLoaderResolverImpl: {}, {}, {}", resourcesCleared, loadedClassesCleared, unloadedClassesCleared);
        }
    }
}
Also used : ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 29 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project hive by apache.

the class PersistenceManagerProvider method clearClr.

private static void clearClr(ClassLoaderResolver clr) throws Exception {
    if (clr instanceof ClassLoaderResolverImpl) {
        ClassLoaderResolverImpl clri = (ClassLoaderResolverImpl) clr;
        int resourcesCleared = clearFieldMap(clri, "resources");
        int loadedClassesCleared = clearFieldMap(clri, "loadedClasses");
        int unloadedClassesCleared = clearFieldMap(clri, "unloadedClasses");
        LOG.debug("Cleared ClassLoaderResolverImpl: resources: {}, loaded classes: {}, unloaded classes: {}", resourcesCleared, loadedClassesCleared, unloadedClassesCleared);
    }
}
Also used : ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 30 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.

the class PluginParserTest method testParseSymbolicName.

public void testParseSymbolicName() {
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION", true);
    Bundle bundle1 = mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST1.MF", null));
    mgr.registerExtensionsForPlugin(clr.getResource("/org/datanucleus/samples/plugin/plugin1expoint.xml", null), bundle1);
    assertEquals(2, mgr.getExtensionPoints().length);
    assertNull(mgr.getExtensionPoint("testID"));
    assertNull(mgr.getExtensionPoint("testID2"));
    assertNotNull(mgr.getExtensionPoint("org.datanucleus.plugin.test1.testID"));
    assertNotNull(mgr.getExtensionPoint("org.datanucleus.plugin.test1.testID2"));
    Bundle bundle2 = mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST2.MF", null));
    mgr.registerExtensionsForPlugin(clr.getResource("/org/datanucleus/samples/plugin/plugin1expoint.xml", null), bundle2);
    assertEquals(4, mgr.getExtensionPoints().length);
    assertNotNull(mgr.getExtensionPoint("org.datanucleus.plugin.test2.testID"));
    assertNotNull(mgr.getExtensionPoint("org.datanucleus.plugin.test2.testID2"));
    Extension[] ex = mgr.getExtensionPoint("org.datanucleus.plugin.test2.testID").getExtensions();
    assertEquals(ex.length, 0);
/*assertEquals("org.datanucleus.plugin.test2",ex[ex.length-1].getPlugin().getSymbolicName());*/
}
Also used : Extension(org.datanucleus.plugin.Extension) NonManagedPluginRegistry(org.datanucleus.plugin.NonManagedPluginRegistry) Bundle(org.datanucleus.plugin.Bundle) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) 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