DefaultSaveOrUpdateOperator implements SaveOrUpdateOperator { @Override public SaveResultOperator execute(UpsertOperatorParameter parameter) { return new DefaultSaveResultOperator(() -> createUpsert(parameter)); } DefaultSaveOrUpdateOperator(RDBTableMetadata table); static DefaultSaveOrUpdateOperator of(RDBTableMetadata table); @Override SaveResultOperator execute(UpsertOperatorParameter parameter);  }
@Test public void testSync() { databaseOperator.ddl() .createOrAlter("upsert_test") .addColumn("id").defaultValueRuntime(() -> UUID.randomUUID().toString().replace("-", "")).primaryKey().varchar(32).commit() .addColumn("name").varchar(32).commit() .commit() .sync(); SaveResult result = databaseOperator .dml() .upsert("upsert_test") .value("id", "123") .value("name", "test") .execute() .sync(); Assert.assertEquals(result.getAdded(), 1); result = databaseOperator .dml() .upsert("upsert_test") .value("id", "123") .value("name", "test") .execute() .sync(); Assert.assertEquals(result.getUpdated(), 1); result = databaseOperator .dml() .upsert("upsert_test") .columns("id", "name") .values("123", "test") .values("234", "test2") .values("2345", "test3") .execute() .sync(); Assert.assertEquals(result.getUpdated(), 1); Assert.assertEquals(result.getAdded(), 2); result = databaseOperator .dml() .upsert("upsert_test") .columns("name") .values("test") .values("test2") .values("test3") .execute() .sync(); Assert.assertEquals(result.getAdded(), 3); }
@Test public void testReactive() { databaseOperator.ddl() .createOrAlter("upsert_test") .addColumn("id").defaultValueRuntime(() -> UUID.randomUUID().toString().replace("-", "")).primaryKey().varchar(32).commit() .addColumn("name").varchar(32).commit() .commit() .reactive() .as(StepVerifier::create) .expectNext(true) .verifyComplete(); databaseOperator .dml() .upsert("upsert_test") .value("id", "123") .value("name", "test") .execute() .reactive() .map(SaveResult::getAdded) .as(StepVerifier::create) .expectNext(1) .verifyComplete(); databaseOperator .dml() .upsert("upsert_test") .value("id", "123") .value("name", "test") .execute() .reactive() .map(SaveResult::getUpdated) .as(StepVerifier::create) .expectNext(1) .verifyComplete(); databaseOperator .dml() .upsert("upsert_test") .columns("id", "name") .values("123", "test") .values("234", "test2") .values("2345", "test3") .execute() .reactive() .map(SaveResult::getTotal) .as(StepVerifier::create) .expectNext(3) .verifyComplete(); databaseOperator .dml() .upsert("upsert_test") .columns("name") .values("test") .values("test2") .values("test3") .execute() .reactive() .map(SaveResult::getAdded) .as(StepVerifier::create) .expectNext(3) .verifyComplete(); }