How to use or manage UserTransaction API to persist jcr data in AEM nodes through OsGi service. | Community
Skip to main content
Level 2
Jan 4, 2018 6:56 PM UTC
Solved

How to use or manage UserTransaction API to persist jcr data in AEM nodes through OsGi service.

Hi people,

I am trying to initiate Javax.transaction on jcr resource and storing content on AEM localhost:4502, I just could not get the way out to initialize UserTransaction to jcr repository, Not sure whats the JNDI lookup context jn that case, because jcr repository is not the data source.i just want transactions to rollback/commit dependending on sucess/failure rates. Doea anyone have idea??

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
Jan 6, 2018 9:25 AM UTC

when you deal with JCR solely, you don't need JTA.

5 replies

joerghoh
joerghohAccepted solution
Employee
Jan 6, 2018 9:25 AM UTC

when you deal with JCR solely, you don't need JTA.

Translate
nupur_kAuthor
Level 2
Jan 6, 2018 6:19 AM UTC

yes agree.. I came across the link and I m facing issues with setting context to UserTransaction Object.

Translate
nupur_kAuthor
Level 2
Jan 6, 2018 6:18 AM UTC

No, I dont want to update JCR and data source simultaneously, I want to save all the JCR transactions once in the end, by utx.commit()  if there are no failure rates, and utx.rollback() in case of single failure. So I think if anyway we can make use of JTA transactions, to store transient data and submit and rollback as needed

repository = JcrUtils.getRepository("http://localhost:4502/crx/server");

   //Create a Session

javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));

  

   Object sling;

//final SlingRepository repository = sling.getService(SlingRepository.class);

//   Session session = repository.loginAdministrative(null);

   Node root = session.getRootNode();

   Hashtable env = new Hashtable();

   Context ctx = null;

   env.put(Context.PROVIDER_URL, "http://localhost:4502/crx/server");

   env.put(Context.INITIAL_CONTEXT_FACTORY,"jcr/repository");

   ctx = new InitialContext(env);

  

  

   UserTransaction utx = (UserTransaction)

     ctx.lookup("javax.transaction.UserTransaction");

Translate
joerghoh
Employee
Jan 5, 2018 8:59 PM UTC

Why would you use javax.transaction API? The JCR session API already offers transaction support. Of course you cannot span a transaction multiple datasources (for example a SQL database which should be updated in the same transaction as JCR).

It's that what you want to do?

Jörg

Translate
smacdonald2008
Level 10
Jan 5, 2018 12:51 PM UTC

Not a lot of transaction inforomation online about JCR and transactions. See this doc that may help -- JCR 2.0: 21 Transactions (Content Repository for Java Technology API v2.0)

Translate