Fix bug in JDBC SaveMode.ON_GET_ATTRIBUTE
Closes gh-2040
This commit is contained in:
committed by
Eleftheria Stein
parent
63f7f7b0a9
commit
cde256e1a3
@@ -728,7 +728,8 @@ public class JdbcIndexedSessionRepository
|
|||||||
T attributeValue = supplier.get();
|
T attributeValue = supplier.get();
|
||||||
if (attributeValue != null
|
if (attributeValue != null
|
||||||
&& JdbcIndexedSessionRepository.this.saveMode.equals(SaveMode.ON_GET_ATTRIBUTE)) {
|
&& JdbcIndexedSessionRepository.this.saveMode.equals(SaveMode.ON_GET_ATTRIBUTE)) {
|
||||||
this.delta.put(attributeName, DeltaValue.UPDATED);
|
this.delta.merge(attributeName, DeltaValue.UPDATED, (oldDeltaValue,
|
||||||
|
deltaValue) -> (oldDeltaValue == DeltaValue.ADDED) ? oldDeltaValue : deltaValue);
|
||||||
}
|
}
|
||||||
return attributeValue;
|
return attributeValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -655,6 +655,20 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
verifyNoMoreInteractions(this.jdbcOperations);
|
verifyNoMoreInteractions(this.jdbcOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void saveWithSaveModeOnGetAttributeAndNewAttributeSetAndGet() {
|
||||||
|
this.repository.setSaveMode(SaveMode.ON_GET_ATTRIBUTE);
|
||||||
|
MapSession delegate = new MapSession();
|
||||||
|
delegate.setAttribute("attribute1", (Supplier<String>) () -> "value1");
|
||||||
|
JdbcSession session = this.repository.new JdbcSession(delegate, UUID.randomUUID().toString(), false);
|
||||||
|
session.setAttribute("attribute2", "value2");
|
||||||
|
session.getAttribute("attribute2");
|
||||||
|
this.repository.save(session);
|
||||||
|
verify(this.jdbcOperations, times(1)).update(startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES ("),
|
||||||
|
isA(PreparedStatementSetter.class));
|
||||||
|
verifyNoMoreInteractions(this.jdbcOperations);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveWithSaveModeAlways() {
|
void saveWithSaveModeAlways() {
|
||||||
this.repository.setSaveMode(SaveMode.ALWAYS);
|
this.repository.setSaveMode(SaveMode.ALWAYS);
|
||||||
|
|||||||
Reference in New Issue
Block a user