|
Re: get Information about locked database items [message #908325 is a reply to message #908126] |
Wed, 05 September 2012 07:05 |
|
Hi Peter,
sorry, but the information you're looking for is not in the database. Locking is done using the OID of the object locked. The time of the lock acquisition is not needed and therefore not stored. You may use the OID and look into a few tables for the actual objects (most should be Node instances).
The DB scheme is not API (actually it's generated by EclipseLink) and may change without notice. You should access the data only by the model classes which provide a JPA interface.
You might consider proposing (and ideally writing) something along your requirements and add it to Jubula.
- Achim
|
|
|
|
Re: get Information about locked database items [message #908530 is a reply to message #908518] |
Wed, 05 September 2012 14:28 |
|
Peter,
just getting the persistence.xml file doesn't work. The JPA meta data is provided by annotations in the Java sources (in the org.eclipse.jubula.client.core.model package). If you want to write a plug-in which should run in the Jubula context, it would be easiest to define a dependency on o.e.j.client.core and use the Persistor class to get an EntityManager (That would take care of DB dependencies for you). All model access in Jubula is contained in *PM classes, so those would be a good starting point to look for sample code (see the o.e.j.client.cor.persistence package).
If you want a standalone application take a look at the Jubula dbtool sources to see how that might be done.
If you need help with implementing a plug-in the Jubula Developer mailing list would be a better place to discuss this.
- Achim
|
|
|
Re: get Information about locked database items [message #908938 is a reply to message #908126] |
Thu, 06 September 2012 09: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 09: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 05: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 05:41] Report message to a moderator
|
|
|
Re: get Information about locked database items [message #909508 is a reply to message #909417] |
Fri, 07 September 2012 08:58 |
|
It's sort of complicated and easy at the same time. If you are running a plug-in with Jubula and have a dependency on o.e.j.client.core you can use the infrastructure provided by Jubula and just get an instance of Persistor and call openSession() (and the commit and rollback methods). To make this work a few listeners and initial settings have to be in place. This is done by an Activator class. You shouldn't have to worry about those.
For a stand-alone application, especially without a GUI, you have to provide these listeners by yourself or initialize the Persistor programmatically. That's the code you've been looking at.
At the moment I don't have the time to go into deeper details. I might find some time over the weekend or on Monday, so stay tuned (and post all questions you run into to get the full batch of answers ).
- Achim
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02342 seconds