Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE
[Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE [message #1016017] Mon, 04 March 2013 15:40 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

I am currently using an old version of Teneo (1.0.1 ish), I know it's old, but unfortunately I am not able to upgrade at this time. I found that if I did something like:

String tempDataStore = "TempName" + System.currentTimeMillis();
HbDataStore hbDataStore = HbHelper.INSTANCE.createRegisterDataStore(tempDataStore);
HbHelper.INSTANCE.deRegisterDataStore(tempDataStore);


Then the deRegisterDataStore call will throw a NullPointerException. I believe this is because it is always assumed that before deRegisterDataStore is called - the code is expecting initialize() to be called on the HbDataStore.

In my case I am not (in fact in the real code it is just using it to generate a hibernate mapping file).

I did have a look at the latest source - and I think this area has changed - so may no longer be a problem. (Unfortunately I do not have an environment available at the moment to test against the latest source).

The only way I have found of getting around this is to do something like:


if( hbDataStore.getEPackages() == null )
{
    hbDataStore.setEPackages( new EPackage[]{});
}
hbDataStore.setProperties(dataStore.getProperties());

final HbDataStore emfds = HbHelper.INSTANCE.getDataStore(name);
if( (emfds != null) && !emfds.isInitialized() )
{
    if( emfds instanceof HbSessionDataStore )
    {
	Configuration configuration = ((HbSessionDataStore)emfds).getConfiguration();
	if( configuration == null )
	{
		configuration = new Configuration();
		
		// Now need to force the configuration to be set
		Field hbSessDS = HbSessionDataStore.class.getDeclaredField("hbConfiguration");
		hbSessDS.setAccessible(true);
		hbSessDS.set(emfds, configuration);
	}
    }
}			
HbHelper.INSTANCE.deRegisterDataStore(tempDataStore);


I know it is not very nice - but it does seen to work.

I really just thought that I would mention it in case anyone else sees this - as I said - the current code for this area looks a fair bit different.

Thanks

Rob

Re: [Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE [message #1016027 is a reply to message #1016017] Mon, 04 March 2013 16:06 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Thanks Rob, HbHelper also has methods to directly generate a mapping, maybe your older version doesn't have it, maybe
you can copy the current content of the generate mapping method.

gr. Martin

On 03/04/2013 04:40 PM, Rob Mising name wrote:
> Hi Martin,
>
> I am currently using an old version of Teneo (1.0.1 ish), I know it's old, but unfortunately I am not able to upgrade at
> this time. I found that if I did something like:
>
> String tempDataStore = "TempName" + System.currentTimeMillis();
> HbDataStore hbDataStore = HbHelper.INSTANCE.createRegisterDataStore(tempDataStore);
> HbHelper.INSTANCE.deRegisterDataStore(tempDataStore);
>
>
> Then the deRegisterDataStore call will throw a NullPointerException. I believe this is because it is always assumed
> that before deRegisterDataStore is called - the code is expecting initialize() to be called on the HbDataStore.
>
> In my case I am not (in fact in the real code it is just using it to generate a hibernate mapping file).
>
> I did have a look at the latest source - and I think this area has changed - so may no longer be a problem.
> (Unfortunately I do not have an environment available at the moment to test against the latest source).
>
> The only way I have found of getting around this is to do something like:
>
>
> if( hbDataStore.getEPackages() == null )
> {
> hbDataStore.setEPackages( new EPackage[]{});
> }
> hbDataStore.setProperties(dataStore.getProperties());
>
> final HbDataStore emfds = HbHelper.INSTANCE.getDataStore(name);
> if( (emfds != null) && !emfds.isInitialized() )
> {
> if( emfds instanceof HbSessionDataStore )
> {
> Configuration configuration = ((HbSessionDataStore)emfds).getConfiguration();
> if( configuration == null )
> {
> configuration = new Configuration();
>
> // Now need to force the configuration to be set
> Field hbSessDS = HbSessionDataStore.class.getDeclaredField("hbConfiguration");
> hbSessDS.setAccessible(true);
> hbSessDS.set(emfds, configuration);
> }
> }
> }
> HbHelper.INSTANCE.deRegisterDataStore(tempDataStore);
>
> I know it is not very nice - but it does seen to work.
>
> I really just thought that I would mention it in case anyone else sees this - as I said - the current code for this area
> looks a fair bit different.
>
> Thanks
>
> Rob
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE [message #1016032 is a reply to message #1016027] Mon, 04 March 2013 16:19 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Thank you for the suggestion, at the moment we do:


String tempDataStore = "TEMP_DATA_STORE" + System.currentTimeMillis();
HbDataStore hbDataStore = HbHelper.INSTANCE.createRegisterDataStore(tempDataStore);

final ExtensionManager extensionManager = hbDataStore.getExtensionManager();

// Set some changes to the extensions such as Table Naming

String mapping = HbHelper.INSTANCE.generateMapping(new EPackage[]{/* some ePackages*/}, dataStore.getProperties(),
		extensionManager);


Is there a better way to get the extension manager instead of creating a new DataStore?

Any suggestions or assistance would be appreciated.

Thanks

Rob
Re: [Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE [message #1016041 is a reply to message #1016032] Mon, 04 March 2013 17:05 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Is it really as simple as using:

ExtensionManager extensionManager = ExtensionManagerFactory.getInstance().create();


To create the extension manager - and just using that instead of the Temp DataStore?

Thanks

Rob
Re: [Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE [message #1016147 is a reply to message #1016041] Tue, 05 March 2013 09:12 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rob,
Indeed, see below for the relevant methods in HbHelper for generating a mapping (note this line is also needed:
MappingUtil.registerHbExtensions(extensionManager)).


/**
* Separate utility method, generates a hibernate mapping for a set of epackages and options. The
* hibernate.hbm.xml is returned as a string. The mapping is not registered or used in any other
* way by Elver.
*/
public String generateMapping(EPackage[] epackages, Properties props) {
return generateMapping(epackages, props, ExtensionManagerFactory.getInstance().create());
}

/**
* Separate utility method, generates a hibernate mapping for a set of epackages and options. The
* hibernate.hbm.xml is returned as a string. The mapping is not registered or used in any other
* way by Elver.
*/
public String generateMapping(EPackage[] epackages, Properties props,
ExtensionManager extensionManager) {
MappingUtil.registerHbExtensions(extensionManager);

if (log.isDebugEnabled()) {
log.debug("Generating mapping file passed epackages");
}
// DCB: Use Hibernate-specific annotation processing mechanism. This
// allows use of
// Hibernate-specific annotations.
final PersistenceOptions po = extensionManager.getExtension(PersistenceOptions.class,
new Object[] { props });
final PAnnotatedModel paModel = extensionManager.getExtension(PersistenceMappingBuilder.class)
.buildMapping(epackages, po, extensionManager);
final HibernateMappingGenerator hmg = extensionManager
.getExtension(HibernateMappingGenerator.class);
hmg.setPersistenceOptions(po);

return hmg.generateToString(paModel);
}



gr. Martin

On 03/04/2013 06:05 PM, Rob Mising name wrote:
> Hi Martin,
>
> Is it really as simple as using:
>
> ExtensionManager extensionManager = ExtensionManagerFactory.getInstance().create();
>
> To create the extension manager - and just using that instead of the Temp DataStore?
>
> Thanks
>
> Rob
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:Different undo/redo stacks for different elements in the same resource
Next Topic:[EMF Compare] Compare editor return a text compare and not a model compare
Goto Forum:
  


Current Time: Tue Mar 19 05:59:29 GMT 2024

Powered by FUDForum. Page generated in 0.02159 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top