From da03f652f8d057a80d3338acd577c4bd8a0923e3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 13 Nov 2013 11:42:27 +0100 Subject: [PATCH] DATAGRAPH-409 - Improved default transaction configuration for repositories. Moved the default transaction configuration from CRUDRepository interface to AbstractGraphRepository to align with transaction configuration with other Spring Data Modules. Removed obsolete method re-declaration from CRUDRepository. CRUDRepository was missing a redeclaration of delete(Serializable id) so that deletes by id didn't trigger a default transaction. This caused e.g. DATAREST-184. --- .../repository/AbstractGraphRepository.java | 9 ++- .../data/neo4j/repository/CRUDRepository.java | 76 +------------------ 2 files changed, 9 insertions(+), 76 deletions(-) diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/AbstractGraphRepository.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/AbstractGraphRepository.java index c612ef6d3..5a1347e87 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/AbstractGraphRepository.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/AbstractGraphRepository.java @@ -39,6 +39,7 @@ import org.springframework.data.neo4j.support.Neo4jTemplate; import org.springframework.data.neo4j.support.index.NoSuchIndexException; import org.springframework.data.neo4j.support.index.NullReadableIndex; import org.springframework.data.neo4j.support.query.QueryEngine; +import org.springframework.transaction.annotation.Transactional; import java.util.*; @@ -52,6 +53,7 @@ import static org.neo4j.helpers.collection.MapUtil.map; * @param GraphBacked target of this finder, enables the finder methods to return this concrete type * @param Type of backing state, either Node or Relationship */ +@Transactional(readOnly = true) public abstract class AbstractGraphRepository implements GraphRepository, NamedIndexRepository, SpatialRepository, CypherDslRepository { /* @@ -106,12 +108,13 @@ public abstract class AbstractGraphRepository im } @Override + @Transactional public U save(U entity) { return template.save(entity); } - @SuppressWarnings("unchecked") @Override + @Transactional public Iterable save(Iterable entities) { for (U entity : entities) { save(entity); @@ -324,16 +327,19 @@ public abstract class AbstractGraphRepository im } @Override + @Transactional public void delete(T entity) { template.delete(entity); } @Override + @Transactional public void delete(Long id) { delete(findOne(id)); } @Override + @Transactional public void delete(Iterable entities) { for (T entity : entities) { delete(entity); @@ -341,6 +347,7 @@ public abstract class AbstractGraphRepository im } @Override + @Transactional public void deleteAll() { delete(findAll()); } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/CRUDRepository.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/CRUDRepository.java index b602a3e1d..8f1d22225 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/CRUDRepository.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/CRUDRepository.java @@ -16,7 +16,6 @@ package org.springframework.data.neo4j.repository; -import org.neo4j.helpers.collection.ClosableIterable; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -24,7 +23,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.neo4j.conversion.EndResult; import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.transaction.annotation.Transactional; import java.util.Map; @@ -34,37 +32,6 @@ import java.util.Map; @NoRepositoryBean public interface CRUDRepository extends PagingAndSortingRepository { - /** - * persists an entity by forwarding to entity.persist() - * @param entity to be persisted - * @return the saved entity (being the same reference as the parameter) - */ - @Transactional - U save(U entity); - - - /** - * persists the provided entities by forwarding to their entity.persist() methods - * @param entities to be persisted - * @return the input iterable - */ - @Transactional - Iterable save(Iterable entities); - - - /** - * @param id of the node or relationship-entity - * @return found instance or null - */ - T findOne(Long id); - - - /** - * @param id - * @return true if the entity with this id exists - */ - boolean exists(Long id); - /** * uses the configured TypeRepresentationStrategy to load all entities, might return a large result @@ -74,37 +41,6 @@ public interface CRUDRepository extends PagingAndSortingRepository { EndResult findAll(); - /** - * uses the configured TypeRepresentationStrategy, depending on the strategy this number might be an - * approximation - * @return number of entities of this type in the graph - */ - long count(); - - - /** - * deletes the given entity by calling its entity.remove() method - * @param entity to delete - */ - @Transactional - void delete(T entity); - - - /** - * deletes the given entities by calling their entity.remove() methods - * @param entities to delete - */ - @Transactional - void delete(Iterable entities); - - - /** - * removes all entities of this type, use with care - */ - @Transactional - void deleteAll(); - - /** * finder that takes the provided sorting into account * NOTE: the sorting is not yet implemented @@ -115,18 +51,8 @@ public interface CRUDRepository extends PagingAndSortingRepository { EndResult findAll(Sort sort); - /** - * finder that takes the provided sorting and paging into account - * NOTE: the sorting is not yet implemented - * - * @param pageable - * @return all elements of the repository type, sorted according to the sort - * NOTE: please close the iterable if it is not fully looped through - */ - Page findAll(Pageable pageable); - Class getStoredJavaType(Object entity); + EndResult query(String query, Map params); - } \ No newline at end of file