Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Gemini + e4 +Injection Dependency
Gemini + e4 +Injection Dependency [message #797712] Mon, 13 February 2012 20:39 Go to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
Hi All,
juno is on the way, and i try to make injection from entityManager with pure gemini, eclipselink and DI. I don't understand how can i define entityManager without @Produces. I am not sure if i understand correctly, i have to make some Producer like
	@Produces
	public EntityManager create() {
		return emf.createEntityManager();
	}

and then i can call it like
@Inject EntityManager em;

I have no idea how to implement EntityManagerProducer

Any ideas or examples?
Thanks in advance!
Re: Gemini + e4 +Injection Dependency [message #797778 is a reply to message #797712] Mon, 13 February 2012 22:07 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Sorry, but I didn't quite understand your question. Are you using an environment that supports @Produces and want to know how to implement it using Gemini JPA, or are you looking to mimic what CDI would do but you are using some other environment?

Re: Gemini + e4 +Injection Dependency [message #797796 is a reply to message #797778] Mon, 13 February 2012 22:30 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
hmmm sorry, i don't understand myself Smile the idea is to use DI from juno (without extra libs) for my RCP program with structure like this:
Bundle A : Main App
Bundle B : Useful tools for Persistence (Gemini, Eclipselink persistence, javax.persistence etc.) and some magic Class with methods like lookupEntityManagerFactoryBuilder(String puName), getEntityManagerProperties() - with data from config, not from persistence.xml
Bundle C : Some App Plugin with Data Objects, and DAO, and PersistenceUnit names "PU1"
Bundle D : Some another App Plugin with Data Objects, and DAO, and PersistenceUnit names "PU2"
and i'll use in my UI components something like this:
@Inject pu1Dao;
...
pu1Dao.load(something);

in pu1Dao
class pu1Dao{
@PersistenceContext(unitName="PU1")
private EntityManager entityManager;

load(something){
...
}
}

and the question is, how to implement magic Class in osgi, that create entitymanager from gemini service with special config data and persistenceUnit and can be used for injection?
Re: Gemini + e4 +Injection Dependency [message #798403 is a reply to message #797796] Tue, 14 February 2012 16:54 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
@Mike,
i have made little implementation of my idea, and I hope, I am on the right way.

I have EntityManagerProducer
package org.e4.gemini.util;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.persistence.spi.PersistenceUnitTransactionType;

import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.jpa.EntityManagerFactoryBuilder;

public class EntityManagerProducer {

	BundleContext context;

	
	/**
	 * for future use
	 * Read config from preferences
	 * @Inject
	 * @Preference(value = "jdbc_driver")
	 */
	private String jdbc_driver = "org.gjt.mm.mysql.Driver";
	private String jdbc_url = "jdbc:mysql://127.0.0.1/test";
	private String jdbc_user = "test";
	private String jdbc_password = "test";
	private boolean ddl_drop_and_create_tables = true;
	private boolean ddl_create_tables = false;
	private int min_conn = 20;
	private String logging = "FINEST";
	
	
	@PersistenceUnit
	private EntityManagerFactory emf;
	private EntityManager em;
	
	@PostConstruct
	public void init() {
		System.out.println("createEMF()");
		Bundle bundle = FrameworkUtil.getBundle(getClass());
		context = bundle.getBundleContext();
		if(emf == null){			
			initEntityManager();
		}
		em = emf.createEntityManager();
		System.err.println("EntityManager: " + em);
	}

	@PreDestroy
    public void destroy(){
		if(em != null){
			try {
				em.close();
			}finally{
				em = null;
			}
		}
		if (emf != null){
			try {
				emf.close();

			}finally{
				emf = null;
				em = null;
			}
		}
    }
	
	private void initEntityManager() {
		EntityManagerFactoryBuilder emfb = lookupEntityManagerFactoryBuilder("puTest");
		if(emfb == null){
			System.err.println("EntityManagerFactoryBuilder is null...");
			return;
		}
		emf = emfb.createEntityManagerFactory(getEntityManagerProperties());
		System.err.println("entityManagerFactory is " + emf);
	}
      
	protected Map<String, Object> getEntityManagerProperties(){
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put(PersistenceUnitProperties.TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());
		properties.put(PersistenceUnitProperties.JDBC_DRIVER, jdbc_driver );
		properties.put(PersistenceUnitProperties.JDBC_URL, jdbc_url);
		properties.put(PersistenceUnitProperties.JDBC_USER, jdbc_user);
		properties.put(PersistenceUnitProperties.JDBC_PASSWORD, jdbc_password);
		if(ddl_drop_and_create_tables) {
			properties.put(PersistenceUnitProperties.DDL_GENERATION, "drop-and-create-tables");
		}
		if(ddl_create_tables) {
			properties.put(PersistenceUnitProperties.DDL_GENERATION, "create-tables");
		}
		properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, "database");
		properties.put(PersistenceUnitProperties.CONNECTION_POOL_MIN, min_conn);
			
		properties.put(PersistenceUnitProperties.TEMPORAL_MUTABLE, "true");
		
		// Logging
		properties.put(PersistenceUnitProperties.LOGGING_LEVEL, logging);
		properties.put(PersistenceUnitProperties.LOGGING_TIMESTAMP, "true");
		properties.put(PersistenceUnitProperties.LOGGING_SESSION, "true");
		properties.put(PersistenceUnitProperties.LOGGING_THREAD, "true");
		properties.put(PersistenceUnitProperties.LOGGING_EXCEPTIONS, "true");
		
		properties.put(PersistenceUnitProperties.WEAVING, "false");
		properties.put(PersistenceUnitProperties.WEAVING_INTERNAL, "false");
//		properties.put("eclipselink.weaving", "dynamic");

		System.out.println(properties.toString());
		return properties;
	}
	 public EntityManagerFactoryBuilder lookupEntityManagerFactoryBuilder(String puName) {
	        String filter = "(osgi.unit.name="+puName+")";
	        System.out.println(filter);
	        ServiceReference<?>[] refs = null;
	        try {
	            refs = context.getServiceReferences(EntityManagerFactoryBuilder.class.getName(), filter);
	        } catch (InvalidSyntaxException isEx) {
	            new RuntimeException("Bad filter", isEx);
	        }
	        System.out.println("EMF Builder Service refs looked up from registry: " + refs);
	        return (refs == null) ? null : (EntityManagerFactoryBuilder) context.getService(refs[0]);
	    }
	
	public EntityManagerFactory lookupEntityManagerFactory(String puName) {
		String filter = "(osgi.unit.name=" + puName + ")";
		ServiceReference<?>[] refs = null;
		try {
			refs = context.getServiceReferences(EntityManagerFactory.class.getName(), filter);
		} catch (InvalidSyntaxException isEx) {
			new RuntimeException("Bad filter", isEx);
		}
		return (refs == null) ? null : (EntityManagerFactory) context.getService(refs[0]);
	}
}


and I try to get EntityManager in my RCP App
public class OpenHandler {

	@Inject
	private EntityManagerProducer emp;	
	
	@PersistenceContext
	private EntityManager entityManager;
	
	@PersistenceContext(unitName="puTest")
	private EntityManager entityManager2;
	
	@Execute
	public void execute(
			IEclipseContext context,
			@Named(IServiceConstants.ACTIVE_SHELL) Shell shell)
			throws InvocationTargetException, InterruptedException {
//		FileDialog dialog = new FileDialog(shell);
//		dialog.open();
				
		System.out.println("emp:" + emp);
		
		
		System.out.println("entityManager:" + entityManager);
		System.out.println("entityManager2:" + entityManager2);

		
	}
}

but both entityManager and entityManager2 are null.

What do I wrong ?

If you have time, and want to see complete source code, you can download it from my dropbox http://db.tt/PlcsXi3y
Re: Gemini + e4 +Injection Dependency [message #798555 is a reply to message #798403] Tue, 14 February 2012 20:52 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Oh, so you are using DI from e4? I am not familiar with how e4 works or what its injection or lifecyle is, etc, so I can't help much, I'm afraid. You might want to first determine whether the failure is due to the lifecycle ordering, the EMFB service availability, or some other problem.

-Mike
Re: Gemini + e4 +Injection Dependency [message #798892 is a reply to message #798555] Wed, 15 February 2012 07:47 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
thank you anyway! i try to ask in e4 forum, may be somebody can help...
Re: Gemini + e4 +Injection Dependency [message #798935 is a reply to message #798555] Wed, 15 February 2012 08:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I already replied on the e4 forum but for my understanding (i have no
idea about gemini) - EntityManagerFactoryBuilder and
EntityManagerFactory are OSGi-Services (at least that's what i infer
from the code in EntityManagerProducer).

e4 injects the following stuff in an object:
* OSGi-Services
* Custom stuff pushed in the so call IEclipseContext

which means EntityManagerFactoryBuilder and EntityManagerFactory are
subject of injection out of the box.

One can enhance the e4-di container to understand other annotations like
the used @PersistenceContext but it doesn't know about it out of the box.

This is done using an OSGi-Service as shown in my e4 talk at EclipseCon
Europe "Eclipse 4 Application Platform: Not commonly known features of
the new platform".

Maybe a nice addon for Gemini or some external bundle. Let me know if
you need more help on this.

Tom

[1]http://tomsondev.bestsolution.at/2011/11/07/slides-from-latest-talks/

Am 14.02.12 21:52, schrieb Mike Keith:
> Oh, so you are using DI from e4? I am not familiar with how e4 works or
> what its injection or lifecyle is, etc, so I can't help much, I'm
> afraid. You might want to first determine whether the failure is due to
> the lifecycle ordering, the EMFB service availability, or some other
> problem.
>
> -Mike
Re: Gemini + e4 +Injection Dependency [message #799176 is a reply to message #798935] Wed, 15 February 2012 15:50 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
*Backlink to post in e4 forum http://www.eclipse.org/forums/index.php/t/291818/
Re: Gemini + e4 +Injection Dependency [message #799371 is a reply to message #798935] Wed, 15 February 2012 20:11 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Thanks, Tom.

Filipp, when you get it working, perhaps you could post what you did to make it work so others could see it and we could add the description to the wiki doc.

Thanks.
-Mike
Re: Gemini + e4 +Injection Dependency [message #800235 is a reply to message #799371] Thu, 16 February 2012 21:10 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
Mike, I am done. Download it from my dropbox - http://db.tt/MZSCnL1f
What I did:
plugin org.eclipse.gemini.ext.di with 2 DS geminiEMF & geminiEM. They have annotation @Component(immediate=true, servicefactory=true), thank them (I hope) bundle starts automatically with core start level. Services implements service tracker for EntityManagerFactory(gemini) (see org.eclipse.gemini.ext.di.impl.GeminiEMFSupplier.java#init()), and I think, we don't need to worry anymore about start level from plugins with persistence.xml.

yet we can invite EntityManagerFactory and EntityManager with annotations from any bundle.
@Inject
@GeminiPersistenceUnit(unitName="puTest")
EntityManagerFactory emf;

@Inject
@GeminiPersistenceContext(unitName="puTest")
EntityManager em;

unitName is required. An other feature is we can put properties for EMF/EM in annotation
@Inject
@GeminiPersistenceUnit(unitName="puTest", properties = { @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, value="org.gjt.mm.mysql.Driver"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL, value="jdbc:mysql://127.0.0.1/test"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER, value="test"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD, value="test"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.DDL_GENERATION, value=PersistenceUnitProperties.DROP_AND_CREATE),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.DDL_GENERATION_MODE, value=PersistenceUnitProperties.DDL_DATABASE_GENERATION),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.CONNECTION_POOL_MIN, value="20"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.TEMPORAL_MUTABLE, value="true"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.WEAVING, value="false"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.WEAVING_INTERNAL, value="false"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_LEVEL, value="FINEST"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_TIMESTAMP, value="true"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_SESSION, value="true"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_THREAD, value="true"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_EXCEPTIONS, value="true")
})
EntityManagerFactory emf;

but the best one is we can use properties from Eclipse Preferences
@Inject
@GeminiPersistenceUnit(unitName="puTest2", properties = {
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, valuePref=@Preference(value="jdbc_driver")),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL, valuePref=@Preference(value="jdbc_url")),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER, valuePref=@Preference(value="jdbc_user")),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD, valuePref=@Preference(value="jdbc_password"))
})
EntityManagerFactory emf1;

or we can mix it
@Inject
@GeminiPersistenceUnit(unitName="puTest", properties = {
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, value="org.gjt.mm.mysql.Driver"),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL, valuePref=@Preference(value="jdbc_url")),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER, valuePref=@Preference(value="jdbc_user")),
	@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD, valuePref=@Preference(value="jdbc_password"))
})
EntityManagerFactory emf;


working with dao is simple -
public class DataObjectDAO {
	@Inject
	@GeminiPersistenceContext(unitName="puTest")
	private EntityManager entityManager;

	public void saveDataObject(DataObject dataObj){
		EntityTransaction trx = entityManager.getTransaction();
		trx.begin();
		entityManager.persist(dataObj);
		trx.commit();
	}

	@PreDestroy
	public void destroy(){
		entityManager.close();
	}
}

and then we use it somewhere
class ... {

	@Inject
	DataObjectDAO dao;

	public void someMethod(){
		DataObject dataObj = new DataObject();
		dataObj.setDummy("bla bla");
		dao.saveDataObject(dataObj);
	}
}

that's all!

Look in sources:
org.eclipse.gemini.ext.di Annotations, DS

org.e4.gemini.rcp for implementation -
org.e4.gemini.rcp.handlers.OpenHandler.java
org.e4.gemini.rcp.handlers.SavePreferencesHandler.java
org.e4.gemini.rcp.dao.DataObjectDAO

all other plugins are only for test

it can be really nice extension for gemini!

P.S. I have test it in eclipse 4.2 IB M20120209-0900 (http://download.eclipse.org/eclipse/downloads/drops4/M20120209-0900/index.php)
Re: Gemini + e4 +Injection Dependency [message #800248 is a reply to message #800235] Thu, 16 February 2012 21:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Very cool!

Tom

Am 16.02.12 22:10, schrieb Filipp A.:
> Mike, I am done. Download it from my dropbox - http://db.tt/MZSCnL1f
> What I did:
> plugin org.eclipse.gemini.ext.di with 2 DS geminiEMF & geminiEM. They
> have annotation @Component(immediate=true, servicefactory=true), thank
> them (I hope) bundle starts automatically with core start level.
> Services implements service tracker for EntityManagerFactory(gemini)
> (see org.eclipse.gemini.ext.di.impl.GeminiEMFSupplier.java#init()), and
> I think, we don't need to worry anymore about start level from plugins
> with persistence.xml.
>
> yet we can invite EntityManagerFactory and EntityManager with
> annotations from any bundle.
>
> @Inject
> @GeminiPersistenceUnit(unitName="puTest")
> EntityManagerFactory emf;
>
> @Inject
> @GeminiPersistenceContext(unitName="puTest")
> EntityManager em;
>
> unitName is required. An other feature is we can put properties for
> EMF/EM in annotation
>
> @Inject
> @GeminiPersistenceUnit(unitName="puTest", properties = {
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER,
> value="org.gjt.mm.mysql.Driver"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL,
> value="jdbc:mysql://127.0.0.1/test"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER,
> value="test"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD,
> value="test"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.DDL_GENERATION,
> value=PersistenceUnitProperties.DROP_AND_CREATE),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.DDL_GENERATION_MODE,
> value=PersistenceUnitProperties.DDL_DATABASE_GENERATION),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.CONNECTION_POOL_MIN,
> value="20"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.TEMPORAL_MUTABLE,
> value="true"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.WEAVING,
> value="false"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.WEAVING_INTERNAL,
> value="false"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_LEVEL,
> value="FINEST"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_TIMESTAMP,
> value="true"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_SESSION,
> value="true"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_THREAD,
> value="true"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.LOGGING_EXCEPTIONS,
> value="true")
> })
> EntityManagerFactory emf;
>
> but the best one is we can use properties from Eclipse Preferences
>
> @Inject
> @GeminiPersistenceUnit(unitName="puTest2", properties = {
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER,
> valuePref=@Preference(value="jdbc_driver")),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL,
> valuePref=@Preference(value="jdbc_url")),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER,
> valuePref=@Preference(value="jdbc_user")),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD,
> valuePref=@Preference(value="jdbc_password"))
> })
> EntityManagerFactory emf1;
>
> or we can mix it
>
> @Inject
> @GeminiPersistenceUnit(unitName="puTest", properties = {
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER,
> value="org.gjt.mm.mysql.Driver"),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL,
> valuePref=@Preference(value="jdbc_url")),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER,
> valuePref=@Preference(value="jdbc_user")),
> @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD,
> valuePref=@Preference(value="jdbc_password"))
> })
> EntityManagerFactory emf;
>
>
> working with dao is simple -
>
> public class DataObjectDAO {
> @Inject
> @GeminiPersistenceContext(unitName="puTest")
> private EntityManager entityManager;
>
> public void saveDataObject(DataObject dataObj){
> EntityTransaction trx = entityManager.getTransaction();
> trx.begin();
> entityManager.persist(dataObj);
> trx.commit();
> }
>
> @PreDestroy
> public void destroy(){
> entityManager.close();
> }
> }
>
> and then we use it somewhere
>
> class ... {
>
> @Inject
> DataObjectDAO dao;
>
> public void someMethod(){
> DataObject dataObj = new DataObject();
> dataObj.setDummy("bla bla");
> dao.saveDataObject(dataObj);
> }
> }
>
> that's all!
>
> Look in sources:
> org.eclipse.gemini.ext.di Annotations, DS
>
> org.e4.gemini.rcp for implementation -
> org.e4.gemini.rcp.handlers.OpenHandler.java
> org.e4.gemini.rcp.handlers.SavePreferencesHandler.java
> org.e4.gemini.rcp.dao.DataObjectDAO
>
> all other plugins are only for test
>
> it can be really nice extension for gemini!
>
> P.S. I have test it in eclipse 4.2 IB M20120209-0900
> (http://download.eclipse.org/eclipse/downloads/drops4/M20120209-0900/index.php)
>
Re: Gemini + e4 +Injection Dependency [message #802204 is a reply to message #800248] Sun, 19 February 2012 15:46 Go to previous messageGo to next message
Nepomuk Seiler is currently offline Nepomuk SeilerFriend
Messages: 88
Registered: December 2010
Member
That's really awesome! Will this be in the main Gemini JPA repository?

[Update]
Filipp, do you have your gemini.ext.di in some repository?
If not, is it okay for you if I push it to
my GitHub repository? I would really like to see
this in Gemini JPA and do the best I can to achieve
this.

cheers,
Muki

[Updated on: Mon, 20 February 2012 11:05]

Report message to a moderator

Re: Gemini + e4 +Injection Dependency [message #803891 is a reply to message #802204] Wed, 22 February 2012 00:18 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
Muki,
at the moment it is only on dropbox, i'm waiting for Mikes feedback.
Sure, you can put in on GitHub, but first it must be updated with license note!
Of course it must be EPL, and you can feel free to use it and make some nice changes. If you want, you can add it, and then you can put it on the GitHub, or wait a little bit, and i make it.
Re: Gemini + e4 +Injection Dependency [message #804106 is a reply to message #803891] Wed, 22 February 2012 07:27 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Am 22.02.2012 01:18, schrieb Filipp A.:
> Muki,
> at the moment it is only on dropbox, i'm waiting for Mikes feedback.

Please open a bug and attach the code there. You also need to make a
comment in the bug that you wrote the code and are eligble to contribute
it to Eclipse. Sorry but thats currently the perfered way to contribute
code to non-Git projects.

-Gunnar


--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: Gemini + e4 +Injection Dependency [message #804221 is a reply to message #804106] Wed, 22 February 2012 10:33 Go to previous messageGo to next message
Nepomuk Seiler is currently offline Nepomuk SeilerFriend
Messages: 88
Registered: December 2010
Member
Quote:

If you want, you can add it, and then you can put it on the GitHub, or wait a little bit, and i make it.


I put it here https://github.com/muuki88/e4GeminiJPA. Hope it added all EPL informations
correctly.

However I'm one day to another the RCP sample application doesn't work anymore Sad
If I start the application without any modifications to the RunConfiguration this happens:

java.lang.RuntimeException: No driver was specified
	at org.eclipse.gemini.jpa.GeminiUtil.fatalError(GeminiUtil.java:109)
	at org.eclipse.gemini.jpa.provider.EclipseLinkOSGiProvider.acquireDataSource(EclipseLinkOSGiProvider.java:344)
	at org.eclipse.gemini.jpa.provider.EclipseLinkOSGiProvider.createEntityManagerFactory(EclipseLinkOSGiProvider.java:274)


I added all necessary information to the persistence.xml and also tried a configuration with "-DREFRESH_BUNDLES=false". However there a several errors that occur randomly, like

Caused by: java.lang.NullPointerException
	at org.eclipse.gemini.jpa.weaving.WeavingHookTransformer.weave(WeavingHookTransformer.java:111)
	at org.eclipse.osgi.internal.baseadaptor.weaving.WovenClassImpl.call(WovenClassImpl.java:140)


org.eclipse.e4.core.di.InjectionException: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:838)
	at org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:365)

...

Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1665)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.close(EntityManagerImpl.java:1529)
	at org.e4.gemini.rcp.dao.DataObjectDAO.destroy(DataObjectDAO.java:44)


or

org.osgi.framework.BundleException: The bundle's start level is not met.  Cannot transient start the bundle: org.e4.gemini.test.data.two_1.0.0.qualifier [64]
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:315)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)

...

org.eclipse.osgi.framework.internal.core.AbstractBundle$BundleStatusException: The bundle's start level is not met.  Cannot transient start the bundle: org.e4.gemini.test.data.two_1.0.0.qualifier [64]
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:315)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)



I'm running this on Ubuntu 11.10 64 bit, Java 7, Eclipse e4M5. I also tried EclipseLink 2.3.x and 2.4.0.
Hopefully I have time next week to dig deeper into e4 DI.

cheers,
Muki
Re: Gemini + e4 +Injection Dependency [message #804269 is a reply to message #804221] Wed, 22 February 2012 12:01 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
wow, nice thanks!
java.lang.RuntimeException: No driver was specified
	at org.eclipse.gemini.jpa.GeminiUtil.fatalError(GeminiUtil.java:109)
	at org.eclipse.gemini.jpa.provider.EclipseLinkOSGiProvider.acquireDataSource(EclipseLinkOSGiProvider.java:344)
	at org.eclipse.gemini.jpa.provider.EclipseLinkOSGiProvider.createEntityManagerFactory(EclipseLinkOSGiProvider.java:274)

take a look in OpenHandler --> PersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, valuePref=@Preference(value="jdbc_driver")), at this time you don't have any entry in Eclipse Preferences -> you can change it to something like @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, value="org.gjt.mm.mysql.Driver"), or add in Activator Properties init (see SavePreferencesHandler)

Edit: and some step by step instruction:
add to target platform:
org.eclipse.gemini.jpa (Gemini JPA)
osgi.enterprise (from Gemini DB)

(from Eclipselink)
javax.persistence (v2.03 or later)
org.eclipse.persistence.asm
org.eclipse.persistence.antlr
org.eclipse.persistence.core
org.eclipse.persistence.jpa

be sure, that org.eclipse.gemini.jpa has startlevel 3 with auto-start
(see -> org.e4.gemini.rcp.product -> Configuration)
in this test you need to start data und data.two bundles too.

[Updated on: Wed, 22 February 2012 12:11]

Report message to a moderator

Re: Gemini + e4 +Injection Dependency [message #804346 is a reply to message #804269] Wed, 22 February 2012 14:14 Go to previous messageGo to next message
Nepomuk Seiler is currently offline Nepomuk SeilerFriend
Messages: 88
Registered: December 2010
Member
Filipp A. wrote on Wed, 22 February 2012 07:01
and some step by step instruction:
add to target platform:
org.eclipse.gemini.jpa (Gemini JPA)
osgi.enterprise (from Gemini DB)

(from Eclipselink)
javax.persistence (v2.03 or later)
org.eclipse.persistence.asm
org.eclipse.persistence.antlr
org.eclipse.persistence.core
org.eclipse.persistence.jpa

be sure, that org.eclipse.gemini.jpa has startlevel 3 with auto-start
(see -> org.e4.gemini.rcp.product -> Configuration)
in this test you need to start data und data.two bundles too.


Yeah, I already did these and played with the parameters. However two things really confuse me. Both VM arguments -DGEMINI_DEBUG=true and -DREFRESH_BUNDLES=true don't seem to have any effect?

And there's a infinite loop hidden somewhere. Bundles keep constantly being refreshed. The application
started two times after starting 10 times and bundles constantly keep refreshing.

Quote:

take a look in OpenHandler --> PersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, valuePref=@Preference(value="jdbc_driver")), at this time you don't have any entry in Eclipse Preferences -> you can change it to something like @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, value="org.gjt.mm.mysql.Driver"), or add in Activator Properties init (see SavePreferencesHandler)


I always delete the runconfiguration folder to really have a clean startup. I added all
necessary informations to the persistence.xml.


More confusion
The infinite loop only appears if I delete the persistence.xml in org.eclipse.gemini.test.data.two. Which seems reasonable as there are two (?) meta information in MANIFEST.MF

Meta-Persistence: META-INF/persistence.xml
JPA-PersistenceUnits: puTest2


(Which one is used for Gemini JPA? Are both needed?)

However. The application starts, when I set auto-start for both persistence.xml bundles to false.

I will add a new branch for the sample application to run with EmbeddedDerby so you can download
Gemini DBAccess and don't have to setup a local MySQL Server for instant testing.

cheers,
Muki
Re: Gemini + e4 +Injection Dependency [message #804467 is a reply to message #804346] Wed, 22 February 2012 16:59 Go to previous messageGo to next message
Filipp A. is currently offline Filipp A.Friend
Messages: 49
Registered: February 2010
Member
Muki, see PM
Re: Gemini + e4 +Injection Dependency [message #804562 is a reply to message #804467] Wed, 22 February 2012 19:34 Go to previous messageGo to next message
Nepomuk Seiler is currently offline Nepomuk SeilerFriend
Messages: 88
Registered: December 2010
Member
I created a bug report https://bugs.eclipse.org/bugs/show_bug.cgi?id=372278
Re: Gemini + e4 +Injection Dependency [message #1022355 is a reply to message #804562] Thu, 21 March 2013 18:17 Go to previous message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Filipp, can you please state in the bug that Muki filed above that you wrote the initial code and that you are willing to contribute it to Gemini JPA?

That will open the door to us legally being able to bring the contribution into the project.

Thanks.
-Mike
Previous Topic:Gemini Blueprint 2.0.0.M02
Next Topic: Gemini JPA: single persistence bundle too restrictive
Goto Forum:
  


Current Time: Thu Mar 28 16:58:35 GMT 2024

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

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

Back to the top