mirror of
https://github.com/valitydev/newway.git
synced 2024-11-06 01:15:20 +00:00
Ft/last version (#87)
* Added last_version_id table * Added last_version_id table * Fix script * Fix script (2) --------- Co-authored-by: Inal Arsanukaev <aiz@empayre.com>
This commit is contained in:
parent
36d3dc4d59
commit
d6a0ced73a
@ -5,4 +5,5 @@ import dev.vality.newway.exception.DaoException;
|
||||
|
||||
public interface DominantDao extends GenericDao {
|
||||
Long getLastVersionId() throws DaoException;
|
||||
void updateLastVersionId(Long versionId) throws DaoException;
|
||||
}
|
||||
|
@ -5,12 +5,10 @@ import dev.vality.newway.dao.dominant.iface.DominantDao;
|
||||
import dev.vality.newway.domain.Tables;
|
||||
import dev.vality.newway.exception.DaoException;
|
||||
import org.jooq.Query;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import static org.jooq.impl.DSL.max;
|
||||
|
||||
@Component
|
||||
public class DominantDaoImpl extends AbstractGenericDao implements DominantDao {
|
||||
@ -21,30 +19,16 @@ public class DominantDaoImpl extends AbstractGenericDao implements DominantDao {
|
||||
|
||||
@Override
|
||||
public Long getLastVersionId() throws DaoException {
|
||||
Query query = getDslContext().select(max(DSL.field("max"))).from(
|
||||
getDslContext().select(max(Tables.CALENDAR.VERSION_ID)).from(Tables.CALENDAR)
|
||||
.unionAll(getDslContext().select(max(Tables.CATEGORY.VERSION_ID)).from(Tables.CATEGORY))
|
||||
.unionAll(getDslContext().select(max(Tables.COUNTRY.VERSION_ID)).from(Tables.COUNTRY))
|
||||
.unionAll(getDslContext().select(max(Tables.CURRENCY.VERSION_ID)).from(Tables.CURRENCY))
|
||||
.unionAll(getDslContext().select(max(Tables.INSPECTOR.VERSION_ID)).from(Tables.INSPECTOR))
|
||||
.unionAll(getDslContext().select(max(Tables.PAYMENT_INSTITUTION.VERSION_ID))
|
||||
.from(Tables.PAYMENT_INSTITUTION))
|
||||
.unionAll(getDslContext().select(max(Tables.PAYMENT_METHOD.VERSION_ID))
|
||||
.from(Tables.PAYMENT_METHOD))
|
||||
.unionAll(getDslContext().select(max(Tables.PAYOUT_METHOD.VERSION_ID))
|
||||
.from(Tables.PAYOUT_METHOD))
|
||||
.unionAll(getDslContext().select(max(Tables.PROVIDER.VERSION_ID)).from(Tables.PROVIDER))
|
||||
.unionAll(getDslContext().select(max(Tables.PROXY.VERSION_ID)).from(Tables.PROXY))
|
||||
.unionAll(getDslContext().select(max(Tables.TERMINAL.VERSION_ID)).from(Tables.TERMINAL))
|
||||
.unionAll(getDslContext().select(max(Tables.TERM_SET_HIERARCHY.VERSION_ID))
|
||||
.from(Tables.TERM_SET_HIERARCHY))
|
||||
.unionAll(getDslContext().select(max(Tables.TRADE_BLOC.VERSION_ID))
|
||||
.from(Tables.TRADE_BLOC))
|
||||
.unionAll(getDslContext().select(max(Tables.WITHDRAWAL_PROVIDER.VERSION_ID))
|
||||
.from(Tables.WITHDRAWAL_PROVIDER))
|
||||
.unionAll(getDslContext().select(max(Tables.PAYMENT_ROUTING_RULE.VERSION_ID))
|
||||
.from(Tables.PAYMENT_ROUTING_RULE))
|
||||
);
|
||||
Query query = getDslContext()
|
||||
.select(Tables.DOMINANT_LAST_VERSION_ID.VERSION_ID)
|
||||
.from(Tables.DOMINANT_LAST_VERSION_ID);
|
||||
return fetchOne(query, Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLastVersionId(Long versionId) throws DaoException {
|
||||
Query query = getDslContext().update(Tables.DOMINANT_LAST_VERSION_ID)
|
||||
.set(Tables.DOMINANT_LAST_VERSION_ID.VERSION_ID, versionId);
|
||||
executeOne(query);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public class DominantPoller {
|
||||
try {
|
||||
versionId.set(e.getKey());
|
||||
dominantService.processCommit(versionId.get(), e);
|
||||
dominantService.updateLastVersionId(versionId.get());
|
||||
after.set(versionId.get());
|
||||
} catch (RuntimeException ex) {
|
||||
throw new RuntimeException(
|
||||
|
@ -51,4 +51,9 @@ public class DominantService {
|
||||
log.info("Last dominant versionId={}", lastVersionId);
|
||||
return lastVersionId;
|
||||
}
|
||||
|
||||
public void updateLastVersionId(Long lastVersionId) {
|
||||
dominantDao.updateLastVersionId(lastVersionId);
|
||||
log.info("Last dominant versionId={} is updated", lastVersionId);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
CREATE TABLE nw.dominant_last_version_id
|
||||
(
|
||||
version_id BIGINT NOT NULL,
|
||||
wtime TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT (now() at time zone 'utc')
|
||||
);
|
||||
|
||||
insert into nw.dominant_last_version_id(version_id) values((with max_ids as (
|
||||
select max(version_id) as id from nw.CALENDAR
|
||||
union all
|
||||
select max(version_id) as id from nw.CATEGORY
|
||||
union all
|
||||
select max(version_id) as id from nw.COUNTRY
|
||||
union all
|
||||
select max(version_id) as id from nw.CURRENCY
|
||||
union all
|
||||
select max(version_id) as id from nw.INSPECTOR
|
||||
union all
|
||||
select max(version_id) as id from nw.PAYMENT_INSTITUTION
|
||||
union all
|
||||
select max(version_id) as id from nw.PAYMENT_METHOD
|
||||
union all
|
||||
select max(version_id) as id from nw.PAYOUT_METHOD
|
||||
union all
|
||||
select max(version_id) as id from nw.PROVIDER
|
||||
union all
|
||||
select max(version_id) as id from nw.PROXY
|
||||
union all
|
||||
select max(version_id) as id from nw.TERMINAL
|
||||
union all
|
||||
select max(version_id) as id from nw.TERM_SET_HIERARCHY
|
||||
union all
|
||||
select max(version_id) as id from nw.TRADE_BLOC
|
||||
union all
|
||||
select max(version_id) as id from nw.WITHDRAWAL_PROVIDER
|
||||
union all
|
||||
select max(version_id) as id from nw.PAYMENT_ROUTING_RULE
|
||||
union all
|
||||
select max(version_id) as id from nw.CATEGORY)
|
||||
|
||||
select coalesce (max(id),0) from max_ids))
|
||||
;
|
||||
|
@ -174,8 +174,6 @@ public class DaoTests {
|
||||
termSetHierarchyDao.save(termSetHierarchy);
|
||||
termSetHierarchyDao.updateNotCurrent(termSetHierarchy.getTermSetHierarchyRefId());
|
||||
|
||||
Long lastVersionId = dominantDao.getLastVersionId();
|
||||
|
||||
OptionalLong maxVersionId = LongStream.of(
|
||||
calendar.getVersionId(),
|
||||
category.getVersionId(),
|
||||
@ -190,6 +188,9 @@ public class DaoTests {
|
||||
terminal.getVersionId(),
|
||||
termSetHierarchy.getVersionId()).max();
|
||||
|
||||
dominantDao.updateLastVersionId(maxVersionId.getAsLong());
|
||||
Long lastVersionId = dominantDao.getLastVersionId();
|
||||
|
||||
Assertions.assertEquals(maxVersionId.getAsLong(), lastVersionId.longValue());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user