Custom Value Generator is not working in 5.2


ponssaran@...
 

Hi Andy,

Pull Request created for this bug.
https://github.com/datanucleus/datanucleus-core/pull/406


Andy
 

It will be available in GitHub when I have time to translate what you have changed into something applyable. It won't be "released" until the next release, and since the last one was not long ago, that means at least 3 months.


ponssaran@...
 

Hi Andy,

Will this be available in 5.2.x release?


ponssaran@...
 
Edited

Hi Andy,

I don't have access to github.com. I have attached the files modified for this fix. Verified with our product it is working as expected.

Modified files in 5.2 branch
AbstractStoreManager.java
ValueGenerationManagerImpl.java


Andy
 

Right, so if that is important for you on 5.2 then please provide a Pull Request.


ponssaran@...
 

Hi Andy,

Thanks for the reply.
Following is the plugin.xml that we are using, it has unique=true.
<?xml version="1.0"?>
<plugin id="xyz" name="DataNucleus plug-ins" provider-name="XYZ">
<extension point="org.datanucleus.store_valuegenerator">
<valuegenerator name="XyzValueGenerator" class-name="com.xyz.datanucleus.util.XyzValueGenerator" unique="true"/>
</extension>
</plugin>
As I said earlier the same plugin.xml works fine in 5.0

After debugging, the link that you shared in the previous thread is where the bug is
In the Constructor of RDBMSStoreManager the AbstractStoreManger constructor is called
public RDBMSStoreManager(ClassLoaderResolver clr, PersistenceNucleusContext ctx, Map<String, Object> props)
{
super("rdbms", clr, ctx, props);

The AbstractStoreManger instantiates ValueGenerationManager before the nucleusContext is set in the constructor
protected ValueGenerationManager valueGenerationMgr = new ValueGenerationManagerImpl(this);

protected AbstractStoreManager(String key, ClassLoaderResolver clr, PersistenceNucleusContext nucleusContext, Map<String, Object> props) { this.storeManagerKey = key; this.nucleusContext = nucleusContext;

So in the constructor of ValueGenerationManagerImpl while loading the plugin there is always a NullPointerException (storeMgr.getNucleusContext() == null). Due to this the custom value generator is never added to uniqueGeneratorsByName map.
try
{
ConfigurationElement[] elems = storeMgr.getNucleusContext().getPluginManager().getConfigurationElementsForExtension("org.datanucleus.store_valuegenerator",
"unique", "true");
if (elems != null)
{
for (ConfigurationElement elem : elems)
{
// Assumed to not take any properties
generator = (ValueGenerator)storeMgr.getNucleusContext().getPluginManager().createExecutableExtension("org.datanucleus.store_valuegenerator",
new String[] {"name", "unique"}, new String[] {elem.getName(), "true"},
"class-name", new Class[] {StoreManager.class, String.class}, new Object[] {this, elem.getName()});
uniqueGeneratorsByName.put(elem.getName(), generator);
}
}
}
catch (Exception e)
{
}


Andy
 

Sure some classes have been refactored over the years, but then since people can't be bothered to "get involved" with open source then docs don't get updated sometimes.

As can be seen here, any plugin registered generators are loaded when "unique" is true. All built-in generators use the exact same API, so suggest that you use those for reference.


ponssaran@...
 

The Datanucleus Guide for Value Generator is old and does not correspond to 5.2 API
https://www.datanucleus.org/products/accessplatform_5_2/extensions/extensions.html#store_valuegenerator

There is no such Class org.datanucleus.store.valuegenerator.AbstractValueGenerator
The class that is available now is
org.datanucleus.store.valuegenerator.AbstractGenerator
The constructor of the class is also changed to
public AbstractGenerator(StoreManager storeMgr, String name)

After changing according to the current API when the application is started.
The Map 
ValueGenerationManager.uniqueGeneratorsByName of RDBMSStoreManager is not having the custom value generator.

In Datanucleus 5.0 this is working.

Is it a bug or the way of providing Custom Value Generator is changed?

Can you please help?