Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Where and When does the Driver get instantiated?(When using Gemini JPA and Gemini DBAccess, where does driver get instantiated)
Where and When does the Driver get instantiated? [message #834434] Mon, 02 April 2012 00:12 Go to next message
John Steele is currently offline John SteeleFriend
Messages: 50
Registered: January 2010
Member
I'm fairly new to using a persistence provider (e.g., EclipseLink, Hibernate) within OSGi, and I'm trying to understand how the EntityManagerFactory gets tied to a specific driver (e.g., EmbeddedDriver), or does it at all?

Lets say I'm using Gemini JPA and Gemini DBAccess, and I have a persistence bundle with a META-INF/persitence.xml file, which specifies the driver as org.apache.derby.jdbc.EmbeddedDriver.

My understanding is that the Gemini JPA bundle is a consumer of the DataSourceFactory services provided by the Gemini DBAccess bundle. The Gemini JPA bundle will then use the javax.persistence.jdbc.driver property within the persistence.xml to decide which DataSourceFactory to use.

Assuming that the Gemini JPA bundle finds the EmbeddedDataSourceFactory, how does it then go about making the actual connection to the database?

It seems like the driver name is only used for locating the correct DataSourceFactory, but is the actual driver ever used? It's a stupid question, because I'm sure it's used to do the actual connecting to the database, but I'm not finding where this happens in the Gemini JPA source. I'm assuming it occurs within GeminiUtil, PUnitInfo, and the specific OSGiJpaProvider.

Where does the driver get instantiated, and how does the specific DataSourceFactory use it?

I appreciate the feedback.

=============
UPDATE
=============
I found where the Driver is instantiated (PlainDriverDataSource), now how does this DataSource get tied to the EntityManagerFactory? The EMF takes the name of the persistence unit and properties as parameters. Does it use one of the properties (e.g., javax.persistence.jdbc.driver) to bind to the database connection?





[Updated on: Mon, 02 April 2012 00:28]

Report message to a moderator

Re: Where and When does the Driver get instantiated? [message #834870 is a reply to message #834434] Mon, 02 April 2012 13:58 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Hi John,

The EclipseLinkOSGiProvider.createEntityManagerFactory() method passes a data source property to the native EclipseLink provider. EclipseLink holds on to the datasource (PlainDriverDataSource) and associates it with the EMF that it returns back.

HTH,
-Mike
Re: Where and When does the Driver get instantiated? [message #834878 is a reply to message #834870] Mon, 02 April 2012 14:12 Go to previous messageGo to next message
Eduardo Frazão is currently offline Eduardo FrazãoFriend
Messages: 123
Registered: January 2012
Senior Member
Mike Keith wrote on Mon, 02 April 2012 09:58

The EclipseLinkOSGiProvider.createEntityManagerFactory() method passes a data source property to the native EclipseLink provider.
-Mike


This datasource, is a javax.sql.Datasource? If Yes, can I create a external Datasource Pool, and inject it somehow, even using the EntitiManagerFactoryBuilder service?

Att,
Eduardo Frazão
Re: Where and When does the Driver get instantiated? [message #834952 is a reply to message #834878] Mon, 02 April 2012 15:48 Go to previous messageGo to next message
John Steele is currently offline John SteeleFriend
Messages: 50
Registered: January 2010
Member
Eduardo Frazão wrote on Mon, 02 April 2012 10:12

This datasource, is a javax.sql.Datasource?


The org.osgi.service.jdbc.DataSourceFactory service has the following methods:
    public abstract javax.sql.DataSource createDataSource(...);
    public abstract javax.sql.ConnectionPoolDataSource createConnectionPoolDataSource(...);
    public abstract javax.sql.XADataSource createXADataSource(...);


Yes, it's javax.sql.DataSource.

Eduardo Frazão wrote on Mon, 02 April 2012 10:12

If Yes, can I create a external Datasource Pool, and inject it somehow, even using the EntitiManagerFactoryBuilder service?


I'd take a look at this: wiki.eclipse.org/Gemini/JPA/Documentation/JPAServices#Using_the_EntityManagerFactoryBuilder_Service
"The EntityManagerFactoryBuilder service is registered regardless of whether the JDBC driver or datasource is accessible, and is used when the user wants to create an EMF and dynamically specify the JDBC properties at runtime. It is less commonly used and the user must rely on their own knowledge that the JDBC datasource they specify, or that is specified in the persistence descriptor, is available."


John Steele
Re: Where and When does the Driver get instantiated? [message #834965 is a reply to message #834870] Mon, 02 April 2012 16:12 Go to previous messageGo to next message
John Steele is currently offline John SteeleFriend
Messages: 50
Registered: January 2010
Member
Mike Keith wrote on Mon, 02 April 2012 09:58
Hi John,

The EclipseLinkOSGiProvider.createEntityManagerFactory() method passes a data source property to the native EclipseLink provider. EclipseLink holds on to the datasource (PlainDriverDataSource) and associates it with the EMF that it returns back.

HTH,
-Mike


That's exactly what I was looking for. Thanks Mike.

I suppose the best way to figure out how the EMF uses the DataSource is to look at the provider's implementation. It would be nice to find documentation that describes the process of how an EMF uses the DataSource to obtain connections, etc. The process of how the EMF creates EntityManagers and how they work is well documented, especially in Pro JPA 2, so I have a good conceptual of the process. I can't say the same thing about how an EMF uses it's DataSource to obtain connections, transactions, etc.

John Steele
Re: Where and When does the Driver get instantiated? [message #834984 is a reply to message #834952] Mon, 02 April 2012 16:40 Go to previous messageGo to next message
Eduardo Frazão is currently offline Eduardo FrazãoFriend
Messages: 123
Registered: January 2012
Senior Member
Hi Jhon! Thanks for answer!

Im already using the EntityManagerFactoryBuilder service, and its working as expected, but I can't find the corret property name in

org.eclipse.persistence.config.PersistenceUnitProperties

when I can pass a ready javax.sql.Datasource to build the EMF.

For now, the datasource is being created automatically, but I wanna use a datasource pool of my choice.

Att,
Eduardo
Re: Where and When does the Driver get instantiated? [message #835011 is a reply to message #834984] Mon, 02 April 2012 17:27 Go to previous messageGo to next message
John Steele is currently offline John SteeleFriend
Messages: 50
Registered: January 2010
Member
Hi Eduardo,

I think you can use this property:
	properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, getDataSource());


And then create the data source:
	private DataSource getDataSource() {
		DataSource dataSource = new ...;
		dataSource.setServerName("localhost");
		dataSource.setPortNumber(1527);
		dataSource.setDatabaseName("MyDB");
		dataSource.setUser("app");
		dataSource.setPassword("app");
		return dataSource;
	}


I think this is how you would do it. Hope it helps.

[Updated on: Mon, 02 April 2012 17:27]

Report message to a moderator

Re: Where and When does the Driver get instantiated? [message #835031 is a reply to message #835011] Mon, 02 April 2012 17:59 Go to previous message
Eduardo Frazão is currently offline Eduardo FrazãoFriend
Messages: 123
Registered: January 2012
Senior Member
Thanks Jhon. I will try that, with a BoneCP Datasource!
Previous Topic:[Gemini JPA] - Unmanaged EntityManagerFactory
Next Topic:[Gemini JPA] How would be the best way to implement fetch pagination in a OSGi Persistence service
Goto Forum:
  


Current Time: Fri Apr 19 19:39:25 GMT 2024

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

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

Back to the top