Skip to content

Commit

Permalink
fix: 修复无法设置null问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed May 14, 2024
1 parent 9b57fd9 commit 74d7421
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,16 @@ protected void prepareUpdateInstance(List<Object> after, EventContext ctx) {
.get(ContextKeys.<DSLUpdate<?, ?>>source())
.orElse(null);
if (operator != null) {
//不更新设置为null的字段
for (String col : copy.keySet()) {
operator.excludes(col);
for (Map.Entry<String, Object> entry : copy.entrySet()) {
Object val = entry.getValue();
if (val instanceof NullValue || val instanceof NativeSql) {
continue;
}
for (String col : copy.keySet()) {
operator.excludes(col);
}
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public class EntityEventListenerTest {
private TestEntityListener listener;

@Before
public void before(){
public void before() {
listener.reset();
}

@Test
public void test() {
Mono.just(EventTestEntity.of("test", 1))
Expand All @@ -54,6 +55,35 @@ public void test() {

}

@Test
public void testPrepareModifySetNull() {
EventTestEntity entity = EventTestEntity.of("prepare-setNull", 20);
reactiveRepository
.insert(entity)
.as(StepVerifier::create)
.expectNext(1)
.verifyComplete();
Assert.assertEquals(listener.created.getAndSet(0), 1);

reactiveRepository
.createUpdate()
.set("name", "prepare-setNull-set")
.setNull("age")
.where("id", entity.getId())
.execute()
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();

reactiveRepository
.findById(entity.getId())
.mapNotNull(EventTestEntity::getAge)
.as(StepVerifier::create)
.expectComplete()
.verify();

}

@Test
public void testPrepareModify() {
EventTestEntity entity = EventTestEntity.of("prepare", 10);
Expand All @@ -66,9 +96,9 @@ public void testPrepareModify() {

reactiveRepository
.createUpdate()
.set("name","prepare-xx")
.set("age",20)
.where("id",entity.getId())
.set("name", "prepare-xx")
.set("age", 20)
.where("id", entity.getId())
.execute()
.as(StepVerifier::create)
.expectNextCount(1)
Expand Down

0 comments on commit 74d7421

Please sign in to comment.