|
28 | 28 | import org.springframework.transaction.annotation.Transactional; |
29 | 29 |
|
30 | 30 | /** |
| 31 | + * Default implementation of the {@link org.springframework.data.repository.CrudRepository} interface. |
| 32 | + * |
31 | 33 | * @author Jens Schauder |
32 | 34 | * @author Oliver Gierke |
33 | 35 | */ |
34 | 36 | @RequiredArgsConstructor |
35 | 37 | @Transactional(readOnly = true) |
36 | 38 | public class SimpleJdbcRepository<T, ID> implements CrudRepository<T, ID> { |
37 | 39 |
|
38 | | - private final @NonNull |
39 | | - JdbcAggregateOperations entityOperations; |
40 | | - private final @NonNull |
41 | | - PersistentEntity<T, ?> entity; |
| 40 | + private final @NonNull JdbcAggregateOperations entityOperations; |
| 41 | + private final @NonNull PersistentEntity<T, ?> entity; |
42 | 42 |
|
43 | | - /* |
44 | | - * (non-Javadoc) |
45 | | - * @see org.springframework.data.repository.CrudRepository#save(S) |
46 | | - */ |
47 | | - @Override |
| 43 | + /* |
| 44 | + * (non-Javadoc) |
| 45 | + * @see org.springframework.data.repository.CrudRepository#save(S) |
| 46 | + */ |
48 | 47 | @Transactional |
49 | | - public <S extends T> S save(S instance) { |
50 | | - return entityOperations.save(instance); |
51 | | - } |
52 | | - |
53 | | - /* |
54 | | - * (non-Javadoc) |
55 | | - * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable) |
56 | | - */ |
57 | | - @Override |
| 48 | + @Override |
| 49 | + public <S extends T> S save(S instance) { |
| 50 | + return entityOperations.save(instance); |
| 51 | + } |
| 52 | + |
| 53 | + /* |
| 54 | + * (non-Javadoc) |
| 55 | + * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable) |
| 56 | + */ |
58 | 57 | @Transactional |
59 | | - public <S extends T> Iterable<S> saveAll(Iterable<S> entities) { |
60 | | - |
61 | | - return Streamable.of(entities).stream() // |
62 | | - .map(this::save) // |
63 | | - .collect(Collectors.toList()); |
64 | | - } |
65 | | - |
66 | | - /* |
67 | | - * (non-Javadoc) |
68 | | - * @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable) |
69 | | - */ |
70 | | - @Override |
71 | | - public Optional<T> findById(ID id) { |
72 | | - return Optional.ofNullable(entityOperations.findById(id, entity.getType())); |
73 | | - } |
74 | | - |
75 | | - /* |
76 | | - * (non-Javadoc) |
77 | | - * @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable) |
78 | | - */ |
79 | | - @Override |
80 | | - public boolean existsById(ID id) { |
81 | | - return entityOperations.existsById(id, entity.getType()); |
82 | | - } |
83 | | - |
84 | | - /* |
85 | | - * (non-Javadoc) |
86 | | - * @see org.springframework.data.repository.CrudRepository#findAll() |
87 | | - */ |
88 | | - @Override |
89 | | - public Iterable<T> findAll() { |
90 | | - return entityOperations.findAll(entity.getType()); |
91 | | - } |
92 | | - |
93 | | - /* |
94 | | - * (non-Javadoc) |
95 | | - * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) |
96 | | - */ |
97 | | - @Override |
98 | | - public Iterable<T> findAllById(Iterable<ID> ids) { |
99 | | - return entityOperations.findAllById(ids, entity.getType()); |
100 | | - } |
101 | | - |
102 | | - /* |
103 | | - * (non-Javadoc) |
104 | | - * @see org.springframework.data.repository.CrudRepository#count() |
105 | | - */ |
106 | | - @Override |
107 | | - public long count() { |
108 | | - return entityOperations.count(entity.getType()); |
109 | | - } |
110 | | - |
111 | | - /* |
112 | | - * (non-Javadoc) |
113 | | - * @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable) |
114 | | - */ |
115 | | - @Override |
| 58 | + @Override |
| 59 | + public <S extends T> Iterable<S> saveAll(Iterable<S> entities) { |
| 60 | + |
| 61 | + return Streamable.of(entities).stream() // |
| 62 | + .map(this::save) // |
| 63 | + .collect(Collectors.toList()); |
| 64 | + } |
| 65 | + |
| 66 | + /* |
| 67 | + * (non-Javadoc) |
| 68 | + * @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable) |
| 69 | + */ |
| 70 | + @Override |
| 71 | + public Optional<T> findById(ID id) { |
| 72 | + return Optional.ofNullable(entityOperations.findById(id, entity.getType())); |
| 73 | + } |
| 74 | + |
| 75 | + /* |
| 76 | + * (non-Javadoc) |
| 77 | + * @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable) |
| 78 | + */ |
| 79 | + @Override |
| 80 | + public boolean existsById(ID id) { |
| 81 | + return entityOperations.existsById(id, entity.getType()); |
| 82 | + } |
| 83 | + |
| 84 | + /* |
| 85 | + * (non-Javadoc) |
| 86 | + * @see org.springframework.data.repository.CrudRepository#findAll() |
| 87 | + */ |
| 88 | + @Override |
| 89 | + public Iterable<T> findAll() { |
| 90 | + return entityOperations.findAll(entity.getType()); |
| 91 | + } |
| 92 | + |
| 93 | + /* |
| 94 | + * (non-Javadoc) |
| 95 | + * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) |
| 96 | + */ |
| 97 | + @Override |
| 98 | + public Iterable<T> findAllById(Iterable<ID> ids) { |
| 99 | + return entityOperations.findAllById(ids, entity.getType()); |
| 100 | + } |
| 101 | + |
| 102 | + /* |
| 103 | + * (non-Javadoc) |
| 104 | + * @see org.springframework.data.repository.CrudRepository#count() |
| 105 | + */ |
| 106 | + @Override |
| 107 | + public long count() { |
| 108 | + return entityOperations.count(entity.getType()); |
| 109 | + } |
| 110 | + |
| 111 | + /* |
| 112 | + * (non-Javadoc) |
| 113 | + * @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable) |
| 114 | + */ |
116 | 115 | @Transactional |
117 | | - public void deleteById(ID id) { |
118 | | - entityOperations.deleteById(id, entity.getType()); |
119 | | - } |
120 | | - |
121 | | - /* |
122 | | - * (non-Javadoc) |
123 | | - * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object) |
124 | | - */ |
125 | | - @Override |
| 116 | + @Override |
| 117 | + public void deleteById(ID id) { |
| 118 | + entityOperations.deleteById(id, entity.getType()); |
| 119 | + } |
| 120 | + |
| 121 | + /* |
| 122 | + * (non-Javadoc) |
| 123 | + * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object) |
| 124 | + */ |
126 | 125 | @Transactional |
127 | | - public void delete(T instance) { |
128 | | - entityOperations.delete(instance, entity.getType()); |
129 | | - } |
130 | | - |
131 | | - /* |
132 | | - * (non-Javadoc) |
133 | | - * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) |
134 | | - */ |
135 | | - @Override |
| 126 | + @Override |
| 127 | + public void delete(T instance) { |
| 128 | + entityOperations.delete(instance, entity.getType()); |
| 129 | + } |
| 130 | + |
| 131 | + /* |
| 132 | + * (non-Javadoc) |
| 133 | + * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) |
| 134 | + */ |
136 | 135 | @Transactional |
137 | | - @SuppressWarnings("unchecked") |
138 | | - public void deleteAll(Iterable<? extends T> entities) { |
139 | | - entities.forEach(it -> entityOperations.delete(it, (Class<T>) it.getClass())); |
140 | | - } |
| 136 | + @Override |
| 137 | + @SuppressWarnings("unchecked") |
| 138 | + public void deleteAll(Iterable<? extends T> entities) { |
| 139 | + entities.forEach(it -> entityOperations.delete(it, (Class<T>) it.getClass())); |
| 140 | + } |
141 | 141 |
|
142 | | - @Override |
143 | 142 | @Transactional |
144 | | - public void deleteAll() { |
145 | | - entityOperations.deleteAll(entity.getType()); |
146 | | - } |
| 143 | + @Override |
| 144 | + public void deleteAll() { |
| 145 | + entityOperations.deleteAll(entity.getType()); |
| 146 | + } |
147 | 147 | } |
0 commit comments