|
|
|
@ -28,6 +28,8 @@ import org.springframework.data.util.Streamable; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* Default implementation of the {@link org.springframework.data.repository.CrudRepository} interface. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Jens Schauder |
|
|
|
* @author Jens Schauder |
|
|
|
* @author Oliver Gierke |
|
|
|
* @author Oliver Gierke |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -35,113 +37,111 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
@Transactional(readOnly = true) |
|
|
|
@Transactional(readOnly = true) |
|
|
|
public class SimpleJdbcRepository<T, ID> implements CrudRepository<T, ID> { |
|
|
|
public class SimpleJdbcRepository<T, ID> implements CrudRepository<T, ID> { |
|
|
|
|
|
|
|
|
|
|
|
private final @NonNull |
|
|
|
private final @NonNull JdbcAggregateOperations entityOperations; |
|
|
|
JdbcAggregateOperations entityOperations; |
|
|
|
private final @NonNull PersistentEntity<T, ?> entity; |
|
|
|
private final @NonNull |
|
|
|
|
|
|
|
PersistentEntity<T, ?> entity; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
* (non-Javadoc) |
|
|
|
* (non-Javadoc) |
|
|
|
* @see org.springframework.data.repository.CrudRepository#save(S) |
|
|
|
* @see org.springframework.data.repository.CrudRepository#save(S) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public <S extends T> S save(S instance) { |
|
|
|
@Override |
|
|
|
return entityOperations.save(instance); |
|
|
|
public <S extends T> S save(S instance) { |
|
|
|
} |
|
|
|
return entityOperations.save(instance); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable) |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable) |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) { |
|
|
|
@Override |
|
|
|
|
|
|
|
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) { |
|
|
|
return Streamable.of(entities).stream() //
|
|
|
|
|
|
|
|
.map(this::save) //
|
|
|
|
return Streamable.of(entities).stream() //
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
.map(this::save) //
|
|
|
|
} |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable) |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable) |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
public Optional<T> findById(ID id) { |
|
|
|
@Override |
|
|
|
return Optional.ofNullable(entityOperations.findById(id, entity.getType())); |
|
|
|
public Optional<T> findById(ID id) { |
|
|
|
} |
|
|
|
return Optional.ofNullable(entityOperations.findById(id, entity.getType())); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable) |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable) |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
public boolean existsById(ID id) { |
|
|
|
@Override |
|
|
|
return entityOperations.existsById(id, entity.getType()); |
|
|
|
public boolean existsById(ID id) { |
|
|
|
} |
|
|
|
return entityOperations.existsById(id, entity.getType()); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#findAll() |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#findAll() |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
public Iterable<T> findAll() { |
|
|
|
@Override |
|
|
|
return entityOperations.findAll(entity.getType()); |
|
|
|
public Iterable<T> findAll() { |
|
|
|
} |
|
|
|
return entityOperations.findAll(entity.getType()); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
public Iterable<T> findAllById(Iterable<ID> ids) { |
|
|
|
@Override |
|
|
|
return entityOperations.findAllById(ids, entity.getType()); |
|
|
|
public Iterable<T> findAllById(Iterable<ID> ids) { |
|
|
|
} |
|
|
|
return entityOperations.findAllById(ids, entity.getType()); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#count() |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#count() |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
public long count() { |
|
|
|
@Override |
|
|
|
return entityOperations.count(entity.getType()); |
|
|
|
public long count() { |
|
|
|
} |
|
|
|
return entityOperations.count(entity.getType()); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable) |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable) |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public void deleteById(ID id) { |
|
|
|
@Override |
|
|
|
entityOperations.deleteById(id, entity.getType()); |
|
|
|
public void deleteById(ID id) { |
|
|
|
} |
|
|
|
entityOperations.deleteById(id, entity.getType()); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object) |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object) |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public void delete(T instance) { |
|
|
|
@Override |
|
|
|
entityOperations.delete(instance, entity.getType()); |
|
|
|
public void delete(T instance) { |
|
|
|
} |
|
|
|
entityOperations.delete(instance, entity.getType()); |
|
|
|
|
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
* (non-Javadoc) |
|
|
|
/* |
|
|
|
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) |
|
|
|
* (non-Javadoc) |
|
|
|
*/ |
|
|
|
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@Override |
|
|
|
public void deleteAll(Iterable<? extends T> entities) { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
entities.forEach(it -> entityOperations.delete(it, (Class<T>) it.getClass())); |
|
|
|
public void deleteAll(Iterable<? extends T> entities) { |
|
|
|
} |
|
|
|
entities.forEach(it -> entityOperations.delete(it, (Class<T>) it.getClass())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public void deleteAll() { |
|
|
|
@Override |
|
|
|
entityOperations.deleteAll(entity.getType()); |
|
|
|
public void deleteAll() { |
|
|
|
} |
|
|
|
entityOperations.deleteAll(entity.getType()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|