Add revision to constatint

This commit is contained in:
k.struzhkin 2020-04-07 14:26:13 +03:00
parent afc3379e8e
commit 125b656e0d
4 changed files with 21 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import javax.sql.DataSource;
import java.util.List;
import static com.rbkmoney.newway.domain.Tables.CONTRACT;
import static com.rbkmoney.newway.domain.Tables.SHOP;
@Component
public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
@ -29,7 +30,10 @@ public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
@Override
public Long save(Contract contract) throws DaoException {
ContractRecord record = getDslContext().newRecord(CONTRACT, contract);
Query query = getDslContext().insertInto(CONTRACT).set(record).returning(CONTRACT.ID);
Query query = getDslContext().insertInto(CONTRACT).set(record)
.onConflict(CONTRACT.PARTY_ID, CONTRACT.SEQUENCE_ID, CONTRACT.CHANGE_ID, CONTRACT.CLAIM_EFFECT_ID, CONTRACT.REVISION)
.doNothing()
.returning(CONTRACT.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
executeOne(query, keyHolder);
return keyHolder.getKey().longValue();

View File

@ -29,7 +29,10 @@ public class ContractorDaoImpl extends AbstractGenericDao implements ContractorD
@Override
public Long save(Contractor contractor) throws DaoException {
ContractorRecord record = getDslContext().newRecord(CONTRACTOR, contractor);
Query query = getDslContext().insertInto(CONTRACTOR).set(record).returning(CONTRACTOR.ID);
Query query = getDslContext().insertInto(CONTRACTOR).set(record)
.onConflict(CONTRACTOR.PARTY_ID, CONTRACTOR.SEQUENCE_ID, CONTRACTOR.CHANGE_ID, CONTRACTOR.CLAIM_EFFECT_ID, CONTRACTOR.REVISION)
.doNothing()
.returning(CONTRACTOR.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
executeOne(query, keyHolder);
return keyHolder.getKey().longValue();

View File

@ -29,7 +29,10 @@ public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
@Override
public Long save(Shop shop) throws DaoException {
ShopRecord record = getDslContext().newRecord(SHOP, shop);
Query query = getDslContext().insertInto(SHOP).set(record).returning(SHOP.ID);
Query query = getDslContext().insertInto(SHOP).set(record)
.onConflict(SHOP.PARTY_ID, SHOP.SEQUENCE_ID, SHOP.CHANGE_ID, SHOP.CLAIM_EFFECT_ID, SHOP.REVISION)
.doNothing()
.returning(SHOP.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
executeOne(query, keyHolder);
return keyHolder.getKey().longValue();

View File

@ -0,0 +1,8 @@
ALTER TABLE nw.shop DROP CONSTRAINT shop_uniq
, ADD CONSTRAINT shop_uniq UNIQUE(party_id, sequence_id, change_id, claim_effect_id, revision);
ALTER TABLE nw.contract DROP CONSTRAINT contract_uniq
, ADD CONSTRAINT contract_uniq UNIQUE(party_id, sequence_id, change_id, claim_effect_id, revision);
ALTER TABLE nw.contractor DROP CONSTRAINT contractor_uniq
, ADD CONSTRAINT contractor_uniq UNIQUE(party_id, sequence_id, change_id, claim_effect_id, revision);