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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations