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:
@@ -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 <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> {
|
||||
|
||||
/*
|
||||
@@ -106,12 +108,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);
|
||||
@@ -324,16 +327,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);
|
||||
@@ -341,6 +347,7 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteAll() {
|
||||
delete(findAll());
|
||||
}
|
||||
|
||||
@@ -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<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
|
||||
*/
|
||||
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<T> extends PagingAndSortingRepository<T, Long> {
|
||||
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
|
||||
*/
|
||||
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
|
||||
* NOTE: the sorting is not yet implemented
|
||||
@@ -115,18 +51,8 @@ public interface CRUDRepository<T> extends PagingAndSortingRepository<T, Long> {
|
||||
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
|
||||
*/
|
||||
Page<T> findAll(Pageable pageable);
|
||||
|
||||
Class getStoredJavaType(Object entity);
|
||||
|
||||
|
||||
EndResult<T> query(String query, Map<String, Object> params);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user