Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Jubula » get Information about locked database items(where can i find information about what content a specific lock locks)
icon14.gif  get Information about locked database items [message #908126] Tue, 04 September 2012 19:37 Go to next message
Peter Parker is currently offline Peter Parker
Messages: 6
Registered: September 2012
Junior Member
Hi folks,

we are using Jubula in a central MySQL database with multiple users. I like working with Jubula a lot, but there is one thing we really need to be able to work efficiently.

I would like to know what resources are locked at the moment. I looked at the database and found the table that is responsible for locking things: db_locks. Unfortunately it contains not all the information that I want to know about the locking situation.
What I want to know in addition is:
- Since when is the item locked?
- What exactly is locked? (DataSet, TestCase Nr. XXX)

Im sure the information is in there somewhere, but I don't know how to access it via SQL. Would be real nice, if someone could point me into the right direction.

Thank in advance for any helpful reply. Smile

Greetings,
Peter


Re: get Information about locked database items [message #908325 is a reply to message #908126] Wed, 05 September 2012 07:05 Go to previous messageGo to next message
Achim Loerke is currently offline Achim Loerke
Messages: 349
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

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 #908518 is a reply to message #908126] Wed, 05 September 2012 14:09 Go to previous messageGo to next message
Peter Parker is currently offline 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 Smile

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 14:13]

Report message to a moderator

Re: get Information about locked database items [message #908530 is a reply to message #908518] Wed, 05 September 2012 14:28 Go to previous messageGo to next message
Achim Loerke is currently offline Achim Loerke
Messages: 349
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

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 Go to previous messageGo to next message
Peter Parker is currently offline 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 Go to previous messageGo to next message
Peter Parker is currently offline 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 Go to previous messageGo to next message
Achim Loerke is currently offline Achim Loerke
Messages: 349
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

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 Wink).

- Achim
Re: get Information about locked database items [message #909523 is a reply to message #909508] Fri, 07 September 2012 09:14 Go to previous messageGo to next message
Peter Parker is currently offline Peter Parker
Messages: 6
Registered: September 2012
Junior Member
Alright, then I just leave it like this until I hear from you again. Smile

One more thing would be good to know though: What kind of objects get locked? I know that every type of PO theoretically can get locked, but (as I understand) only a few actually will get locked. For example: an AUT for itself will most likely never be locked, becuase when someone attemps to do so the complete properties of the Project get locked.

Thanks again Smile
Re: get Information about locked database items [message #911418 is a reply to message #908126] Tue, 11 September 2012 15:06 Go to previous message
Peter Parker is currently offline Peter Parker
Messages: 6
Registered: September 2012
Junior Member
So, I think I figured it out on my own. Thanks for the tip, that I have to do something with listeners Smile
I subscribed to DatabaseStateDispatcher as a IDatabaseStateListener and to DataEventDispatcher as a IProjectOpenedListener.
When these events fire, I grab the new EntityManager with GeneralStorage.getInstance().getEntityManager().
Should I better use getMasterSession() here? In the current Version of GeneralStorage in the git repository the getEntityManager() method is gone. How can I get the EntityManager in a future release of jubula?

Are these the only events I have to watch out for? Tried it out a few times and in my opinion it runs pretty good.
Once again: What objects can get locked? Here is what I check right now: NodePO, ProjectPropertiesPO, TestDataCategoryPO, ComponentNamePO, AUTMainPO

Thanks again for your help, again you pointed me into the right direction. Smile
Previous Topic:copy test cases or test steps?
Next Topic:How to start AUT which is JNLP
Goto Forum:
  


Current Time: Tue Oct 21 18:43:04 GMT 2014

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

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