Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cd3d0b1

Browse files
committed
Polishing.
Refactored the unit tests to include a negative case and to separate the different scenarios tested. Removed the default LockMode from the Lock annotation. I have the feeling that most users will assume an exclusive Lock when none is specified, but also don't want to request stronger locks than required. Original pull request #1158 See #1041
1 parent e68c355 commit cd3d0b1

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

‎spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/Lock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
/**
3535
* Defines which type of {@link LockMode} we want to use.
3636
*/
37-
LockMode value()defaultLockMode.PESSIMISTIC_READ;
37+
LockMode value();
3838

3939
}

‎spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public void findAllByQueryName() {
335335

336336
@Test
337337
void findAllByFirstnameWithLock() {
338+
338339
DummyEntity dummyEntity = createDummyEntity();
339340
repository.save(dummyEntity);
340341
assertThat(repository.findAllByName(dummyEntity.getName())).hasSize(1);

‎spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/JdbcQueryMethodUnitTests.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.jupiter.api.Test;
28-
2928
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
3029
import org.springframework.data.projection.ProjectionFactory;
3130
import org.springframework.data.relational.core.sql.LockMode;
@@ -123,28 +122,31 @@ public void returnsNullIfNoQueryIsFound() throws NoSuchMethodException {
123122
}
124123

125124
@Test // GH-1041
126-
void returnsQueryMethodWithLock() throws NoSuchMethodException {
125+
void returnsQueryMethodWithCorrectLockTypeWriteLock() throws NoSuchMethodException {
127126

128127
JdbcQueryMethod queryMethodWithWriteLock = createJdbcQueryMethod("queryMethodWithWriteLock");
129-
JdbcQueryMethod queryMethodWithReadLock = createJdbcQueryMethod("queryMethodWithReadLock");
130128

131-
assertThat(queryMethodWithWriteLock.hasLockMode()).isTrue();
132-
assertThat(queryMethodWithReadLock.hasLockMode()).isTrue();
129+
assertThat(queryMethodWithWriteLock.lookupLockAnnotation()).isPresent();
130+
assertThat(queryMethodWithWriteLock.lookupLockAnnotation().get().value()).isEqualTo(LockMode.PESSIMISTIC_WRITE);
133131
}
134132

135133
@Test // GH-1041
136-
void returnsQueryMethodWithCorrectLockType() throws NoSuchMethodException {
134+
void returnsQueryMethodWithCorrectLockTypeReadLock() throws NoSuchMethodException {
137135

138-
JdbcQueryMethod queryMethodWithWriteLock = createJdbcQueryMethod("queryMethodWithWriteLock");
139136
JdbcQueryMethod queryMethodWithReadLock = createJdbcQueryMethod("queryMethodWithReadLock");
140137

141-
assertThat(queryMethodWithWriteLock.lookupLockAnnotation()).isPresent();
142138
assertThat(queryMethodWithReadLock.lookupLockAnnotation()).isPresent();
143-
144-
assertThat(queryMethodWithWriteLock.lookupLockAnnotation().get().value()).isEqualTo(LockMode.PESSIMISTIC_WRITE);
145139
assertThat(queryMethodWithReadLock.lookupLockAnnotation().get().value()).isEqualTo(LockMode.PESSIMISTIC_READ);
146140
}
147141

142+
@Test // GH-1041
143+
void returnsQueryMethodWithCorrectLockTypeNoLock() throws NoSuchMethodException {
144+
145+
JdbcQueryMethod queryMethodWithWriteLock = createJdbcQueryMethod("queryMethodName");
146+
147+
assertThat(queryMethodWithWriteLock.lookupLockAnnotation()).isEmpty();
148+
}
149+
148150
@Lock(LockMode.PESSIMISTIC_WRITE)
149151
@Query
150152
private void queryMethodWithWriteLock() {}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /