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.
This commit is contained in:
Oliver Gierke
2013-11-13 09:53:06 +01:00
parent e765016eeb
commit 0031cc37fa
2 changed files with 16 additions and 90 deletions

View File

@@ -41,6 +41,7 @@ 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.data.neo4j.support.typerepresentation.LabelBasedNodeTypeRepresentationStrategy;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@@ -54,6 +55,7 @@ import static org.neo4j.helpers.collection.MapUtil.map;
* @param <T> GraphBacked target of this finder, enables the finder methods to return this concrete type
* @param <S> Type of backing state, either Node or Relationship
*/
@Transactional(readOnly = true)
public abstract class AbstractGraphRepository<S extends PropertyContainer, T> implements GraphRepository<T>, NamedIndexRepository<T>, SpatialRepository<T>, CypherDslRepository<T> {
/*
@@ -108,12 +110,13 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
}
@Override
@Transactional
public <U extends T> U save(U entity) {
return template.save(entity);
}
@SuppressWarnings("unchecked")
@Override
@Transactional
public <U extends T> Iterable<U> save(Iterable<U> entities) {
for (U entity : entities) {
save(entity);
@@ -326,16 +329,19 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> 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<? extends T> entities) {
for (T entity : entities) {
delete(entity);
@@ -343,6 +349,7 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
}
@Override
@Transactional
public void deleteAll() {
delete(findAll());
}

View File

@@ -16,98 +16,30 @@
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;
import java.util.Map;
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;
/**
* CRUD interface for graph repositories, used as base repository for crud operations
* CRUD interface for graph repositories, used as base repository for crud operations.
*
* @author Michael Hunger
* @author Oliver Gierke
*/
@NoRepositoryBean
public interface CRUDRepository<T> extends PagingAndSortingRepository<T, Long> {
/**
* 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 extends T> 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
<U extends T> Iterable<U> save(Iterable<U> entities);
/**
* @param id of the node or relationship-entity
* @return found instance or null
*/
@Transactional
T findOne(Long id);
/**
* @param id
* @return true if the entity with this id exists
*/
@Transactional
boolean exists(Long id);
/**
* uses the configured TypeRepresentationStrategy to load all entities, might return a large result
* @return all entities of the given type
* NOTE: please close the iterable if it is not fully looped through
*/
@Transactional
EndResult<T> 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
*/
@Transactional
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<? extends T> entities);
/**
* removes all entities of this type, use with care
*/
@Transactional
void deleteAll();
/**
* finder that takes the provided sorting into account
@@ -116,24 +48,11 @@ public interface CRUDRepository<T> extends PagingAndSortingRepository<T, Long> {
* @return all elements of the repository type, sorted according to the sort
* NOTE: please close the iterable if it is not fully looped through
*/
@Transactional
EndResult<T> 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
*/
@Transactional
Page<T> findAll(Pageable pageable);
@Transactional
Class getStoredJavaType(Object entity);
@Transactional
EndResult<T> query(String query, Map<String, Object> params);
}