Added means to run separate transaction managers for neo4j and jdbc/jpa with @NeoTransactional
This commit is contained in:
@@ -23,6 +23,6 @@
|
||||
|
||||
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp"/>
|
||||
|
||||
<tx:annotation-driven mode="aspectj"/>
|
||||
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
|
||||
|
||||
</beans>
|
||||
@@ -15,6 +15,6 @@
|
||||
<neo4j:config storeDirectory="target/neo4j-db"/>
|
||||
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph" graph-database-context-ref="graphDatabaseContext"/>
|
||||
|
||||
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
|
||||
<tx:annotation-driven mode="aspectj" transaction-manager="neo4jTransactionManager"/>
|
||||
</beans>
|
||||
|
||||
|
||||
@@ -23,10 +23,12 @@ import org.neo4j.kernel.AbstractGraphDatabase;
|
||||
import org.neo4j.kernel.impl.transaction.SpringTransactionManager;
|
||||
import org.neo4j.kernel.impl.transaction.UserTransactionImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean;
|
||||
import org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory;
|
||||
@@ -34,6 +36,7 @@ import org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAcc
|
||||
import org.springframework.data.neo4j.mapping.Neo4jMappingContext;
|
||||
import org.springframework.data.neo4j.mapping.Neo4jNodeConverterImpl;
|
||||
import org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
|
||||
import org.springframework.data.neo4j.support.EntityInstantiator;
|
||||
import org.springframework.data.neo4j.support.EntityStateHandler;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
@@ -162,8 +165,9 @@ public abstract class Neo4jConfiguration {
|
||||
return new RelationshipDelegatingFieldAccessorFactory(graphDatabaseContext());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
@Bean(name = {"neo4jTransactionManager","transactionManager"})
|
||||
@Qualifier("neo4jTransactionManager")
|
||||
public PlatformTransactionManager neo4jTransactionManager() {
|
||||
return createJtaTransactionManager();
|
||||
}
|
||||
|
||||
@@ -181,9 +185,14 @@ public abstract class Neo4jConfiguration {
|
||||
return jtaTm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GraphDatabase graphDatabase() {
|
||||
return new DelegatingGraphDatabase(graphDatabaseService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigurationCheck configurationCheck() throws Exception {
|
||||
return new ConfigurationCheck(graphDatabaseContext(),transactionManager());
|
||||
return new ConfigurationCheck(graphDatabaseContext(),neo4jTransactionManager());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.neo4j.transaction;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation to mark transaction boundaries that should explicitely use the Neo4j Transaction Manager
|
||||
*/
|
||||
@Transactional("neo4jTransactionManager")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
public @interface Neo4jTransactional {
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
<context:annotation-config/>
|
||||
<neo4j:config storeDirectory="target/config-test"/>
|
||||
|
||||
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<bean name="neo4jTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user