Skip to content

Commit

Permalink
Fix bug in JDBC SaveMode.ON_GET_ATTRIBUTE
Browse files Browse the repository at this point in the history
  • Loading branch information
felixscheinost committed Apr 7, 2022
1 parent b8e9494 commit 3eaa127
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ public <T> T getAttribute(String attributeName) {
T attributeValue = supplier.get();
if (attributeValue != null
&& 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,20 @@ void saveWithSaveModeOnGetAttribute() {
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
void saveWithSaveModeAlways() {
this.repository.setSaveMode(SaveMode.ALWAYS);
Expand Down

0 comments on commit 3eaa127

Please sign in to comment.