Search in sources :

Example 6 with ConfigurationElement

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;
}
Also used : PluginManager(org.datanucleus.plugin.PluginManager) ConfigurationElement(org.datanucleus.plugin.ConfigurationElement)

Example 7 with ConfigurationElement

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()]);
}
Also used : ConfigurationElement(org.datanucleus.plugin.ConfigurationElement) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) HashSet(java.util.HashSet)

Example 8 with ConfigurationElement

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;
}
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 ConfigurationElement

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;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ConfigurationElement(org.datanucleus.plugin.ConfigurationElement) NucleusException(org.datanucleus.exceptions.NucleusException)

Aggregations

ConfigurationElement (org.datanucleus.plugin.ConfigurationElement)9 NucleusException (org.datanucleus.exceptions.NucleusException)5 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)3 PluginManager (org.datanucleus.plugin.PluginManager)3 HashSet (java.util.HashSet)2 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)2 Extension (org.datanucleus.plugin.Extension)2 StoreManager (org.datanucleus.store.StoreManager)2 InputStream (java.io.InputStream)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1