|
|
| Re: get Information about locked database items [message #908518 is a reply to message #908126] |
Wed, 05 September 2012 10:09   |
Peter Parker Messages: 6 Registered: September 2012 |
Junior Member |
|
|
Thanks for your reply, your information was just what I needed.
I figured out how to get the information out of the database. It worked just as you described it, but of course I want to do it via JPA 
Of course I would like to find a good solution for this problem, so I looked a little bit into the whole JPA/Eclipselink story. I think I understand how it works, but all my approaches interact with the given database failed.
What I understood: To be able to access the database via JPA I need to get an Instance of the EntityManager class that comes from an EntityManagerFactory with the right persitence-unit name (org.eclipse.jubula). I additionally need information about the content stored in the database in a persistence.xml file that is located in the META-INF folder in my src directory.
Here is what I tried:
- Created a new plugin-project with an Activator
- added to the start method of the Activator the following code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.eclipse.jubula");
EntityManager em = emf.createEntityManager();
- obtained the persistence.xml file from the Jubula git repository (root/org.eclipse.jubula.client.core/META-INF/persistence.xml) and put it in src/META-INF/persistence.xml
- additionally I specified the plugins and starting order of the plugins as described here http://wiki.eclipse.org/EclipseLink/Examples/OSGi/Developing_with_EclipseLink_OSGi_in_PDE
When I execute the plugin-project the following Exception is thrown when the Activator is executed:
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.eclipse.jubula
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at jpatest.Activator.start(Activator.java:37)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
... 63 more
So now my question is: How do I get access to the EntityManager Jubula uses interally? or: How can i get an Instance of the EntityManager that can access the data stored in the database.
Thanks in advance,
Peter
[Updated on: Wed, 05 September 2012 10:13] Report message to a moderator
|
|
|
|
| Re: get Information about locked database items [message #908938 is a reply to message #908126] |
Thu, 06 September 2012 05:08   |
Peter Parker Messages: 6 Registered: September 2012 |
Junior Member |
|
|
Thanks for your hints. Yesterday I got the connection working.
Unfortunatelly I haven't found an easy way to obtain the data from the database. I don't know if it's because of my very basic understanding of JPQL or the task is just not that easy.
Seems like I would have to write dedicated code for every possible type of PO that is lockable.
Here is what i've got so far. If the lock locks a DataSet, it gives you the name of the Project the DataSet is from.
List<DbLockPO> locks = null;
List<ITestDataCategoryPO> cats = null;
List<INodePO> nodes = null;
try {
locks = em.createQuery("select lock from DbLockPO as lock").getResultList();
for (DbLockPO dbLockPo : locks) {
System.out.println("got item: "+dbLockPo.getPoId());
Query queryCats = em.createQuery("select cat from TestDataCategoryPO cat where cat.id = :catId", ITestDataCategoryPO.class);
queryCats.setParameter("catId", dbLockPo.getPoId());
cats= queryCats.getResultList();
for (ITestDataCategoryPO catPO : cats) {
Query queryNodes = em.createQuery("select node from NodePO node where node.id = :nodeId", INodePO.class);
queryNodes.setParameter("nodeId", catPO.getParentProjectId());
nodes = queryNodes.getResultList();
for (INodePO iNodePO : nodes) {
System.out.println("Locked Dataset belong to: "+iNodePO.getName());
}
}
}
}
catch(Exception e){
e.printStackTrace();
}
I know, that not all the loops are neccessary, but it helps to find issues when a ResultSet is supposed to have only one entry but has more.
I you have an easier solution to do this, please tell me. Would be helpful to have an example JPQL query with JOINS to see how it is done in Jubula context.
When I have this working I would really like to contribute the plugin to the community.
I really appreciate your help, thanks for your help so far.
Peter
[Updated on: Thu, 06 September 2012 05:10] Report message to a moderator
|
|
|
| Re: get Information about locked database items [message #909417 is a reply to message #908126] |
Fri, 07 September 2012 01:40   |
Peter Parker Messages: 6 Registered: September 2012 |
Junior Member |
|
|
Hey guys,
so I got almost everything working now. It is still not as fancy as I would like it to be, but for now I can live with that.
I still have one issue left that I don't know how to deal with yet: I want to use the database information (kind of database, url, username and pw) that is stored in the eclipse preferences and used by jubula itself.
As of now I'm doing it like this:
Persistor.setDbConnectionName(new DatabaseConnectionInfo(){
public String getDriverClassName(){ ... }
public String getConnectionUrl() {...}});
Persistor.setPw("password");
Persistor.setUser("username");
Persistor.setUrl("jdbc:mysql://server:3306/dbname");
Persistor.init();
EntityManager em = org.eclipse.jubula.client.core.persistence.Persistor.instance().openSession();
I know how to get the things like the URL and the drivername (DatabaseConnectionConverter.computeAvailableConnections()), but I don't know how to get Information about which one of the connections currently used and with what username and password.
The thing I don't understand here is why I even have to set username and pw myself. Persitence is a Singleton, but when I call instance() I get "null" and have to set the information myself.
I looked through the source code of jubula and what I think should get me username and pw just returns null:
List<DatabaseConnection> availableConns = DatabaseConnectionConverter.computeAvailableConnections();
for (DatabaseConnection databaseConnection : availableConns) {
System.out.println(databaseConnection.getConnectionInfo().getConnectionUrl());
System.out.println(databaseConnection.getConnectionInfo().getProperty(PersistenceUnitProperties.JDBC_URL));
System.out.println(databaseConnection.getConnectionInfo().getProperty(PersistenceUnitProperties.JDBC_PASSWORD));
System.out.println();
}
So, what am I doing wrong here? Can the credentials be accessed by a plugin that is not part the jubula modules?
Would be nice if you could help me out once again. Thanks for your help.
Greets
[Updated on: Fri, 07 September 2012 01:41] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11877 seconds