Skip to content

Commit 8eb7edd

Browse files
committed
Remove unnecessary entity merges and save invocations
fixes #373
1 parent aa45626 commit 8eb7edd

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

spring-versions-jpa/src/main/java/org/springframework/versions/impl/LockingAndVersioningRepositoryImpl.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public <S extends T> S lock(S entity) {
9191

9292
if (lockingService.lock(id, authentication)) {
9393
BeanUtils.setFieldWithAnnotation(entity, LockOwner.class, authentication.getName());
94-
return this.save(entity);
94+
return entity;
9595
}
9696

9797
throw new LockingAndVersioningException(format("failed to lock %s", id));
@@ -118,7 +118,6 @@ public <S extends T> S unlock(S entity) {
118118
}
119119

120120
BeanUtils.setFieldWithAnnotation(entity, LockOwner.class, null);
121-
entity = this.save(entity);
122121

123122
if (lockingService.unlock(id, authentication)) {
124123
return entity;
@@ -180,7 +179,6 @@ public <S extends T> S workingCopy(S currentVersion) {
180179
S ancestorRoot;
181180
if (isAnestralRoot(currentVersion)) {
182181
currentVersion = (S)versioner.establishAncestralRoot(currentVersion);
183-
em.merge(currentVersion);
184182
ancestorRoot = currentVersion;
185183
} else {
186184
Object ancestorRootId = getAncestralRootId(currentVersion);
@@ -202,7 +200,7 @@ public <S extends T> S workingCopy(S currentVersion) {
202200
Object newId = getId(newVersion);
203201

204202
newVersion = this.lock(newVersion);
205-
newVersion = em.merge(newVersion);
203+
newVersion = em.merge(newVersion);
206204

207205
return newVersion;
208206
}
@@ -255,7 +253,7 @@ public <S extends T> S version(S currentVersion, VersionInfo info) {
255253
Object newId = getId(newVersion);
256254

257255
newVersion = this.lock(newVersion);
258-
newVersion = em.merge(newVersion);
256+
newVersion = em.merge(newVersion);
259257
} else {
260258

261259
newVersion = currentVersion;

0 commit comments

Comments
 (0)