• Help with Transactions

  • He we will discuss about how to make customization and improvement to the OpenKM source code.
He we will discuss about how to make customization and improvement to the OpenKM source code.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #19635  by noxious
 
Hello, I haven't got any experience in Transactions and I would appreciate it if someone could give me a hint:
I have noticed in the OpenKM source code that you implement transactions when working with repository or communicating with database using Hibernation.
Let's say that I have a method that does these actions:
-query the database using jdbc connection (not Hibernate)
-update the database using jdbc connection (not Hibernate)
-grant a user on a document using OKMAuth class
-revoke an other user from the same document using OKMAuth class
Can I include all these things inside a single global transaction so that If something goes wrong everything will rollback?
Is OKMAuth compatible with com.openkm.util.Transaction? Can i do something like this? :
Code: Select all
XASession session = (XASession) JCRUtils.getSession();
			Transaction t = new Transaction(session);
			t.start();
                        OKMAuth.getInstance().grantUser()...
                        OKMAuth.getInstance().revokeUser()...
                        t.end();
			t.commit();
                        
If not, is there a way I can make my jdbc connector and OKMAuth be handled from a global transaction manager using an XA interface or something like this?
Sorry for the sillyness of my question but I have only worked with local database Transactions. JTA is something new for me and I am trying to figure out how your transactions work :oops:
 #19677  by jllort
 
First your database should be transaction, for example if you're on mysql should be ensure you're on transactional engine like inodb ( not with myisam )
Second as any transaction database you open transaction and then commit, if you take a look in source code you can see how is doing it with hibernate.
If you want to doing the same with jdbc or sql I suggest you google for "mysql transaction example"

Actually we're not using older JCRUtils. You should take a look at AuthDao http://doxygen.openkm.com/6.2.x/d6/dbe/ ... d_a_o.html

Note: Here I suppose you have configured mysql, otherside you got default hypersonic database.
 #19696  by noxious
 
I am indeed using MySQL with innodb and I can do transactions for multiple MySQL queries.
My problem is that I have created a method that:
a. Connects the database and inserts a record
b. Grants a role at a document using OKMAuth.getInstance().grantRole(...);
c. Revokes a role from the document using OKMAuth.getInstance().revokeRole(...);
So, I would like to have a transaction ,like that:
transaction.begin();
try{
a. Connects the database and inserts a record
b. Grants a role at a document using OKMAuth.getInstance().grantRole(...);
c. Revokes a role from the document using OKMAuth.getInstance().revokeRole(...);
transaction.commit();
} catch (Exception e){
transaction.rollback;
}
So, if a or b or c throws an exception all a,b,c will rollback.
I understand AuthDAO but there you just use hibernate transactions.
I need a transaction manager that can control database queries and java methods like OKMAuth.grantRole inside the same block of code...
Thanks for the answer!
 #19732  by jllort
 
The api directly controls tractaction on their own methods. I will try explain better, the problem is that each method you use from api has begin / end transaction ( OKMAuth.getInstance().grantRole(...) -> has their own transaction into method ).

That mean what you want to doing it not possible at this level access of the API. Now should go in more deep control NodeBaseDAO.grantRolePermissions ( etc... ), and create your own unified method. Not seems good solution too. I not see and easy way to implement it.

Anyway is strange you get exception with OKMAuth.getInstance().grantRole or revoke ( very strange ). On which kind of logic you get exception here ?
 #19740  by noxious
 
No, I don't get any exceptions, everything works fine.
I just thought that it would be very nice if I could do that and I asked your opinion.
By the way, there is a posibility me contributing in the greek translations in the next months when I will be having more free time.
Again, thank you for your answers.
 #19746  by pavila
 
First of all, the provided sample code:
Code: Select all
XASession session = (XASession) JCRUtils.getSession();
Works with Jacrabbit (OpenKM 5.1.x) not are transactions related to Hibernate. As I can understand you want to group several OpenKM API calls into an atomic operation. This can't work because Hibernate transactions are used inside the API calls to ensure atomicity: open transaction, fo the SQL modifications and make commit or rollback.

I read sometime ago about global transactions which can be use as you need but never tried. If you find anything about them, please share with us.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.