2

我让 Jackrabbit Oak 在 MongoDB 实例上运行。非常简单,非常直接来自文档(Sprint Boot 应用程序):

@PostConstruct
public void initRepository() {
    LOG.info("Initializing Oak repository");

    @SuppressWarnings({ "resource", "deprecation" })
    DB db = new MongoClient("127.0.0.1", 27017).getDB("tenantX" + System.currentTimeMillis());

    DocumentNodeStore ns = new DocumentMK.Builder().setMongoDB(db).getNodeStore();

    this.repository = new Jcr(new Oak(ns)).createRepository();

}

@Override
public Session getThreadLocalSession() throws RepositoryException {
    Session session = this.repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    return session;
}

现在,如果我想要交易,从这里到哪里?简单地将@Transactional 添加到服务方法不会改变任何东西。

在我们之前的“老派”Jackrabbit 应用程序中,我们使用了类似的东西

<bean id="transactionManager" class="org.jencks.factory.TransactionManagerFactoryBean" />

<bean id="jcrConnectionManager" class="org.jencks.factory.ConnectionManagerFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transaction" value="xa" />
    <property name="poolMinSize" value="1" />
    <property name="poolMaxSize" value="50" />
    <property name="connectionMaxIdleMinutes" value="5" />
    <property name="partitionStrategy" value="by-connector-properties" />
</bean>

<bean id="jcrManagedConnectionFactory"
    class="org.apache.jackrabbit.jca.JCAManagedConnectionFactory">
    <property name="configFile" value="classpath:repository.xml" />
    <property name="homeDir" value="/repository" />
</bean>

<bean id="repository"
    class="org.springframework.jca.support.LocalConnectionFactoryBean">
    <property name="managedConnectionFactory" ref="jcrManagedConnectionFactory" />
    <property name="connectionManager" ref="jcrConnectionManager" />
</bean>

但是 Oak 没有提供像 JCAManagedConnectionFactory 这样的类。

4

0 回答 0