Search in sources :

Example 6 with PluginManager

use of org.datanucleus.plugin.PluginManager in project datanucleus-core by datanucleus.

the class ValueGenerationManagerImpl method supportsStrategy.

/* (non-Javadoc)
     * @see org.datanucleus.store.valuegenerator.ValueGenerationManager#supportsStrategy(java.lang.String)
     */
@Override
public boolean supportsStrategy(String strategy) {
    if (StringUtils.isWhitespace(strategy)) {
        return false;
    }
    // Built-in unique ValueGenerators
    if ("timestamp".equalsIgnoreCase(strategy) || "timestamp-value".equalsIgnoreCase(strategy) || "auid".equalsIgnoreCase(strategy) || "uuid".equalsIgnoreCase(strategy) || "uuid-object".equalsIgnoreCase(strategy) || "uuid-hex".equalsIgnoreCase(strategy) || "uuid-string".equalsIgnoreCase(strategy)) {
        return true;
    }
    PluginManager pluginMgr = storeMgr.getNucleusContext().getPluginManager();
    // Try plugin mechanism "unique" generators
    ConfigurationElement elem = pluginMgr.getConfigurationElementForExtension("org.datanucleus.store_valuegenerator", new String[] { "name", "unique" }, new String[] { strategy, "true" });
    if (elem != null) {
        // Unique strategy so supported for all datastores
        return true;
    }
    // Try plugin mechanism "datastore" (non-unique) generators
    elem = pluginMgr.getConfigurationElementForExtension("org.datanucleus.store_valuegenerator", new String[] { "name", "datastore" }, new String[] { strategy, storeMgr.getStoreManagerKey() });
    if (elem != null) {
        return true;
    }
    return false;
}
Also used : PluginManager(org.datanucleus.plugin.PluginManager) ConfigurationElement(org.datanucleus.plugin.ConfigurationElement)

Example 7 with PluginManager

use of org.datanucleus.plugin.PluginManager in project datanucleus-core by datanucleus.

the class TypeManagerTest method setUp.

/**
 * Create a TypeManager for testing.
 */
protected void setUp() throws Exception {
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    Properties props = new Properties();
    props.setProperty("bundle-check-action", "EXCEPTION");
    PluginManager pluginMgr = new PluginManager(null, clr, props);
    NucleusContext nucCtx = new PersistenceNucleusContextImpl(null, null, pluginMgr);
    typeMgr = nucCtx.getTypeManager();
}
Also used : PluginManager(org.datanucleus.plugin.PluginManager) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) Properties(java.util.Properties) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 8 with PluginManager

use of org.datanucleus.plugin.PluginManager in project datanucleus-core by datanucleus.

the class ValueGenerationManagerImpl method createValueGenerator.

/* (non-Javadoc)
     * @see org.datanucleus.store.valuegenerator.ValueGenerationManager#createValueGenerator(java.lang.String, java.lang.Class, java.util.Properties, org.datanucleus.store.valuegenerator.ValueGenerationConnectionProvider)
     */
@Override
public ValueGenerator createValueGenerator(String strategyName, String seqName, Properties props, ValueGenerationConnectionProvider connectionProvider) {
    PluginManager pluginMgr = storeMgr.getNucleusContext().getPluginManager();
    ConfigurationElement elem = pluginMgr.getConfigurationElementForExtension("org.datanucleus.store_valuegenerator", new String[] { "name", "datastore" }, new String[] { strategyName, storeMgr.getStoreManagerKey() });
    Class generatorClass = (elem != null) ? pluginMgr.loadClass(elem.getExtension().getPlugin().getSymbolicName(), elem.getAttribute("class-name")) : null;
    if (generatorClass == null) {
        throw new NucleusException("Cannot create ValueGenerator for strategy " + seqName);
    }
    // Create the requested generator TODO If using plugin mechanism, should use createExecutableExtension
    ValueGenerator generator;
    try {
        if (NucleusLogger.VALUEGENERATION.isDebugEnabled()) {
            NucleusLogger.VALUEGENERATION.debug(Localiser.msg("040001", generatorClass.getName(), seqName));
        }
        Class[] argTypes = new Class[] { StoreManager.class, String.class, Properties.class };
        Object[] args = new Object[] { storeMgr, seqName, props };
        Constructor ctor = generatorClass.getConstructor(argTypes);
        generator = (ValueGenerator) ctor.newInstance(args);
    } catch (Exception e) {
        NucleusLogger.VALUEGENERATION.error(e);
        throw new ValueGenerationException(Localiser.msg("040000", generatorClass.getName(), e), e);
    }
    if (generator instanceof AbstractConnectedGenerator) {
        // Set the store manager and connection provider for any datastore-based generators
        ((AbstractConnectedGenerator) generator).setConnectionProvider(connectionProvider);
    }
    return generator;
}
Also used : ConfigurationElement(org.datanucleus.plugin.ConfigurationElement) Constructor(java.lang.reflect.Constructor) Properties(java.util.Properties) NucleusException(org.datanucleus.exceptions.NucleusException) StoreManager(org.datanucleus.store.StoreManager) PluginManager(org.datanucleus.plugin.PluginManager) NucleusException(org.datanucleus.exceptions.NucleusException)

Example 9 with PluginManager

use of org.datanucleus.plugin.PluginManager in project datanucleus-core by datanucleus.

the class TransactionManagerFinder method getTransactionManager.

/**
 * Accessor for the accessible JTA transaction manager.
 * @param clr ClassLoader resolver
 * @return The JTA manager found (if any)
 */
public TransactionManager getTransactionManager(ClassLoaderResolver clr) {
    String jtaLocatorName = nucleusContext.getConfiguration().getStringProperty(PropertyNames.PROPERTY_TRANSACTION_JTA_LOCATOR);
    PluginManager pluginMgr = nucleusContext.getPluginManager();
    // TODO If the transactionManagerJNDI is specified then use that and don't look at transactionManagerLocator
    if ("autodetect".equalsIgnoreCase(jtaLocatorName) || jtaLocatorName == null) {
        // Cycle through all available locators and find one that returns a TransactionManager
        String[] builtinLocatorNames = new String[] { "jboss", "jonas", "jotm", "oc4j", "orion", "resin", "sap", "sun", "weblogic", "websphere", "custom_jndi", "atomikos", "bitronix" };
        for (String builtinLocatorName : builtinLocatorNames) {
            try {
                TransactionManagerLocator locator = getTransactionManagerLocatorForName(pluginMgr, builtinLocatorName);
                if (locator != null) {
                    TransactionManager tm = locator.getTransactionManager(clr);
                    if (tm != null) {
                        return tm;
                    }
                }
            } catch (Exception e) {
            // Ignore any errors
            }
        }
        // Fallback to the plugin mechanism
        String[] locatorNames = pluginMgr.getAttributeValuesForExtension("org.datanucleus.jta_locator", null, null, "name");
        if (locatorNames != null) {
            for (int i = 0; i < locatorNames.length; i++) {
                try {
                    TransactionManagerLocator locator = (TransactionManagerLocator) pluginMgr.createExecutableExtension("org.datanucleus.jta_locator", "name", locatorNames[i], "class-name", new Class[] { ClassConstants.NUCLEUS_CONTEXT }, new Object[] { nucleusContext });
                    if (locator != null) {
                        TransactionManager tm = locator.getTransactionManager(clr);
                        if (tm != null) {
                            return tm;
                        }
                    }
                } catch (Exception e) {
                // Ignore any errors
                }
            }
        }
    } else {
        // User has specified which locator to use
        TransactionManagerLocator locator = getTransactionManagerLocatorForName(pluginMgr, jtaLocatorName);
        return locator.getTransactionManager(clr);
    }
    return null;
}
Also used : PluginManager(org.datanucleus.plugin.PluginManager) TransactionManager(javax.transaction.TransactionManager)

Example 10 with PluginManager

use of org.datanucleus.plugin.PluginManager in project datanucleus-core by datanucleus.

the class AnnotationManagerImpl method getHandlerForClassAnnotation.

public ClassAnnotationHandler getHandlerForClassAnnotation(String annotationName) {
    if (classAnnotationHandlerAnnotations == null || !classAnnotationHandlerAnnotations.contains(annotationName)) {
        return null;
    }
    ClassAnnotationHandler handler = classAnnotationHandlers.get(annotationName);
    if (handler == null) {
        // Try to create this ClassAnnotationHandler
        try {
            PluginManager pluginMgr = metadataMgr.getNucleusContext().getPluginManager();
            handler = (ClassAnnotationHandler) pluginMgr.createExecutableExtension("org.datanucleus.class_annotation_handler", "annotation-class", annotationName, "handler", null, null);
            classAnnotationHandlers.put(annotationName, handler);
        } catch (Exception e) {
            NucleusLogger.METADATA.warn(Localiser.msg("MetaData.ClassAnnotationHandlerNotFound", annotationName));
            return null;
        }
    }
    return handler;
}
Also used : PluginManager(org.datanucleus.plugin.PluginManager)

Aggregations

PluginManager (org.datanucleus.plugin.PluginManager)10 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)3 NucleusException (org.datanucleus.exceptions.NucleusException)3 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)3 ConfigurationElement (org.datanucleus.plugin.ConfigurationElement)3 Properties (java.util.Properties)2 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)2 Annotation (java.lang.annotation.Annotation)1 Constructor (java.lang.reflect.Constructor)1 TransactionManager (javax.transaction.TransactionManager)1 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)1 NucleusContext (org.datanucleus.NucleusContext)1 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)1 InvocationEvaluator (org.datanucleus.query.inmemory.InvocationEvaluator)1 ArrayContainsMethod (org.datanucleus.query.inmemory.method.ArrayContainsMethod)1 ArraySizeMethod (org.datanucleus.query.inmemory.method.ArraySizeMethod)1 StoreManager (org.datanucleus.store.StoreManager)1 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)1 SQLMethod (org.datanucleus.store.rdbms.sql.method.SQLMethod)1 SQLOperation (org.datanucleus.store.rdbms.sql.operation.SQLOperation)1