use of org.datanucleus.plugin.ConfigurationElement 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.ConfigurationElement in project datanucleus-core by datanucleus.
the class MetaDataEntityResolver method getRegisteredSchemas.
/**
* The list of schemas registered in the plugin "metadata_entityresolver".
* @return the Sources pointing to the .xsd files
*/
public Source[] getRegisteredSchemas() {
ConfigurationElement[] elems = pluginMgr.getConfigurationElementsForExtension("org.datanucleus.metadata_entityresolver", null, null);
Set<Source> sources = new HashSet<>();
for (int i = 0; i < elems.length; i++) {
if (elems[i].getAttribute("type") == null) {
InputStream in = MetaDataParser.class.getResourceAsStream(elems[i].getAttribute("url"));
if (in == null) {
NucleusLogger.METADATA.warn("local resource \"" + elems[i].getAttribute("url") + "\" does not exist!!!");
}
sources.add(new StreamSource(in));
}
}
return sources.toArray(new Source[sources.size()]);
}
use of org.datanucleus.plugin.ConfigurationElement 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.ConfigurationElement in project datanucleus-core by datanucleus.
the class ValueGenerationManagerImpl method getTypeForValueGeneratorForMember.
/* (non-Javadoc)
* @see org.datanucleus.store.valuegenerator.ValueGenerationManager#getTypeForValueGeneratorForMember(java.lang.String, java.lang.String)
*/
@Override
public Class getTypeForValueGeneratorForMember(String strategyName, String memberKey) {
// Find the generator class for this strategy
Class generatorClass = null;
ValueGenerator generator = generatorsByMemberKey.get(memberKey);
if (generator == null) {
// No generator assigned to this member key, so check for a unique generator
generator = uniqueGeneratorsByName.get(strategyName);
}
if (generator != null) {
generatorClass = generator.getClass();
} else {
// Check the plugin mechanism for a generator for this strategy
try {
ConfigurationElement elem = storeMgr.getNucleusContext().getPluginManager().getConfigurationElementForExtension("org.datanucleus.store_valuegenerator", new String[] { "name", "datastore" }, new String[] { strategyName, storeMgr.getStoreManagerKey() });
generatorClass = (elem != null) ? storeMgr.getNucleusContext().getPluginManager().loadClass(elem.getExtension().getPlugin().getSymbolicName(), elem.getAttribute("class-name")) : null;
} catch (Exception e) {
}
}
if (generatorClass != null) {
Class valueGeneratedType = null;
try {
// Use "getStorageClass" method if available
valueGeneratedType = (Class) generatorClass.getMethod("getStorageClass").invoke(null);
} catch (Exception e) {
if (generatorClass.getGenericSuperclass() instanceof ParameterizedType) {
// TODO Improve this so it works always and so we don't need "getStorageClass" method (i.e what generic type is provided to AbstractGenerator?)
ParameterizedType parameterizedType = (ParameterizedType) generatorClass.getGenericSuperclass();
valueGeneratedType = (Class) parameterizedType.getActualTypeArguments()[0];
}
}
return valueGeneratedType;
}
return null;
}
Aggregations