Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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??

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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

View solution in original post

5 Replies

Avatar

Level 10

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)

Avatar

Employee Advisor

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

Avatar

Level 2

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");

Avatar

Level 2

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

Avatar

Correct answer by
Employee Advisor

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