You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "flavio.donze" <fl...@gmail.com> on 2011/12/21 10:03:51 UTC
Jackrabbit JCA transaction handling
Hello
I’m using Jackrabbit handling transactions through JCA.
I’m not clear on how I should use the Jackrabbit API that it works correctly
with the rest of my framework, without any leaks and unnecessary work.
This is my spring application context where I declare the Jackrabbit beans,
plus “com.softmodeler.repository.service.impl.RepositoryService” which is my
own service.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<props>
<prop key="jcr.homeDir" />
<prop key="jcr.rmiPort" />
<prop key="jcr.type" />
</props>
</property>
<property name="systemPropertiesModeName">
<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
</bean>
<bean id="jcrConnectionManager"
class="org.jencks.factory.ConnectionManagerFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transaction" value="xa"/>
</bean>
<bean id="repositoryFactory"
class="org.apache.jackrabbit.core.RepositoryFactoryImpl"/>
<bean id="repositoryManagedConnectionFactory"
class="org.apache.jackrabbit.jca.JCAManagedConnectionFactory"
destroy-method="finalize">
<property name="configFile" value="classpath:${jcr.type}_repository.xml"/>
<property name="homeDir" value="${jcr.homeDir}"/>
</bean>
<bean id="repository"
class="org.jencks.factory.ConnectionFactoryFactoryBean">
<property name="managedConnectionFactory"
ref="repositoryManagedConnectionFactory"/>
<property name="connectionManager" ref="jcrConnectionManager"/>
</bean>
<bean id="repositoryService"
class="com.softmodeler.repository.service.impl.RepositoryService">
<property name="repository" ref="repository"/>
</bean>
<bean id="rmiRegistry"
class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="${jcr.rmiPort}"/>
</bean>
<bean id="rmiServer"
class="org.springframework.extensions.jcr.jackrabbit.RmiServerRepositoryFactoryBean">
<property name="repository" ref="repository"/>
<property name="remoteAdapterFactory">
<bean class="org.apache.jackrabbit.rmi.server.ServerAdapterFactory"/>
</property>
<property name="registry" ref="rmiRegistry"/>
<property name="rmiName" value="jackrabbit"/>
</bean>
</beans>
In the RepositoryService I then do the following:
/**
* returns the session handle
*
* @return
*/
protected Session getSession() {
try {
// login if session handle has not been created
Session session = repository.login(CREDENTIALS, WORKSPACE);
return session;
} catch (Exception e) {
logger.error("error receiving jcr session", e); //$NON-NLS-1$
throw new IllegalStateException(e);
}
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor =
Exception.class)
public void storeStream(String path, InputStream stream, STORE_TYPE type)
throws ServerException {
Assert.isNotNull(path);
Assert.isNotNull(stream);
Assert.isNotNull(type);
Session session = getSession();
try {
logger.debug("storing stream into {}", path); //$NON-NLS-1$
Node root = session.getRootNode();
Node typeNode = getOrCreateDirectoryNode(root, type.toString());
Node containerNode = createStructure(typeNode, path, true);
String name = path.substring(path.lastIndexOf(SEP) + 1, path.length());
createOrUpdateFileNode(containerNode, stream, name);
session.save();
} catch (Exception e) {
ServerUtil.throwServerException(e);
} finally {
session.logout();
}
}
Is this the right way to get a session? Is the session.logout() correct, is
it required or will it be done by the transaction handling.
Is there some documentation about this?
Greets
Flavio
--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Jackrabbit-JCA-transaction-handling-tp4220958p4220958.html
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.