You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Moritz Rebbert <mo...@udo.edu> on 2008/10/27 17:25:15 UTC

Jackrabbit on JBoss: Login outside of Transaction

Hi List,

i'm playing around with jackrabbit on jboss. My question is: Is it
possible or intended to start more than one transaction using the same
Session. My Code test code looks like this:[0]

In the first case is do the login within the Transaction. The action
will be rolled back an no node will be created. It is very close to the
example in the JackrabbitOnJBoss article of the jackrabbit wiki. 

But if i want to start the Session befor the utx.begin() like in the
second case. The rollback has no effect and the the node will be
created. But if i want to use more then one Transaction in a single
Session, i have to do the login before the utx.begin();

How can i do something like this.Or is it intend to login and create a
new session, every time i start a transaction? 

The config-property bindSessionToTransaction sounds for me like: If i
set it true, the first case would be supported: new login for every new
transaction. But what about setting it to false?

Regards
Moritz Rebbert

BTW:
My config looks like this:[1]
Im Using jboss-4.2.2.GA. and jackrabbit-jca-1.4.rar.

[0]
@Stateful
@TransactionManagement(TransactionManagementType.BEAN)
public class TestBean implements Test{
	@Resource
	UserTransaction utx;
	public void test(String str){
		Session session = null;
		try{
			//loginAfterBegin
			utx.begin();
			session = repository.login(new SimpleCredentials("asdf","safd".toCharArray()));
			session.getRootNode().addNode("loginAfterBegin()"+str);
			session.save();
			utx.rollback();
		
			//loginBefore begin
			session = repository.login(new SimpleCredentials("asdf","safd".toCharArray()));
			
			utx.begin();
			session.getRootNode().addNode("loginBeforeBegin1"+str);
			session.save();
			utx.rollback();
			
			utx.begin();
			session.getRootNode().addNode("loginBeforeBegin2"+str);
			session.save();
			utx.rollback();

		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}

[1]
jcr-ds.xml:
<connection-factories>
    <tx-connection-factory>
                <jndi-name>jcr/local</jndi-name>
                <xa-transaction/>
                <rar-name>jackrabbit-jca-1.4.rar</rar-name>
                <connection-definition>javax.jcr.Repository</connection-definition>
                <config-property name="homeDir" type="java.lang.String">/ldaphome/rebbert/var/jackrabbit</config-property>
                <config-property name="configFile" type="java.lang.String">classpath:repository.xml</config-property>
                <config-property name="bindSessionToTransaction" type="java.lang.Boolean">false</config-property>
    </tx-connection-factory>
</connection-factories>

repository.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN"
                           "http://jackrabbit.apache.org/dtd/repository-1.4.dtd">
<Repository>
   <FileSystem 
            class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
       <param name="path" value="${rep.home}/repository"/>
   </FileSystem>

   <Security appName="Jackrabbit">
       <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager"/>
       <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
          <param name="anonymousId" value="anonymous"/>
       </LoginModule>
   </Security>

   <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />

   <Workspace name="${wsp.name}">
       <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
           <param name="path" value="${wsp.home}"/>
       </FileSystem>

       <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager">
                    <param name="driver" value="org.postgresql.Driver"/>
                    <param name="url" value="jdbc:postgresql://localhost:5433/jackrabbit"/>
                    <param name="user" value="postgres"/>
                    <param name="password" value="postgres"/>
                    <param name="schema" value="postgresql"/>
                    <param name="schemaObjectPrefix" value="jcr_${wsp.name}_"/>
                    <param name="externalBLOBs" value="false"/>
       </PersistenceManager>



       <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
           <param name="path" value="${wsp.home}/index" />
       </SearchIndex>
   </Workspace>

   <Versioning rootPath="${rep.home}/versions">
       <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
           <param name="path" value="${rep.home}/versions"/>
       </FileSystem>
       <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager">
                    <param name="driver" value="org.postgresql.Driver"/>
                    <param name="url" value="jdbc:postgresql://localhost:5433/jackrabbit"/>
                    <param name="user" value="postgres"/>
                    <param name="password" value="postgres"/>
                    <param name="schema" value="postgresql"/>
                    <param name="schemaObjectPrefix" value="jcr_versioning_"/>
                    <param name="externalBLOBs" value="false"/>
       </PersistenceManager>
   </Versioning>

   <DataStore class="org.apache.jackrabbit.core.data.FileDataStore">
       <param name="path" value="${rep.home}/repository/datastore"/>
       <param name="minRecordLength" value="100"/>
   </DataStore>
</Repository>


Re: Jackrabbit on JBoss: Login outside of Transaction

Posted by Moritz Rebbert <mo...@udo.edu>.
Hi again,

after a bit of research i found another argument why my issue could be important.
The Sample Code for User Manager Transaction in the jsr170 specification[0] do
not work in the expected way. But it also possible that I did not get the point. 

Is it right, that the underlying XAResource will be only enlisted to the
Transaction, when the Repository.login() Methode is called between
utx.begin() and utx.commit()?

Regards
Moritz

[0] jsr-170-1.0.pdf from http://jcp.org/en/jsr/detail?id=170 page 227

"
// Get user transaction (for example, through JNDI) 
UserTransaction utx = ... 
 
// Get a node 
Node n = ... 
 
// Start a user transaction 
utx.begin(); 
 
// Do some work 
n.setProperty(n.save(); 

// Do some more work 
n.setProperty("myapp:author", "Charles Dickens") 
n.save(); 
 
// Commit the user transaction 
utx.commit(); 
"