-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: compare data of ada_pots table
- Loading branch information
1 parent
d3ee8eb
commit 7683ad8
Showing
16 changed files
with
494 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 51 additions & 51 deletions
102
...ava/org/cardanofoundation/ledgersync/verifier/data/app/config/DbSyncDatasourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
//package org.cardanofoundation.ledgersync.verifier.data.app.config; | ||
// | ||
//import lombok.RequiredArgsConstructor; | ||
//import org.springframework.beans.factory.annotation.Qualifier; | ||
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
//import org.springframework.context.annotation.Bean; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
//import org.springframework.orm.jpa.JpaTransactionManager; | ||
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
//import org.springframework.transaction.PlatformTransactionManager; | ||
//import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
// | ||
//import javax.sql.DataSource; | ||
//import java.util.Objects; | ||
// | ||
//@Configuration | ||
//@EnableTransactionManagement | ||
//@EnableJpaRepositories( | ||
// entityManagerFactoryRef = "dbSyncEntityManagerFactory", | ||
// transactionManagerRef = "dbSyncTransactionManager", | ||
// basePackages = {"org.cardanofoundation.ledgersync.verifier.data.app.repository.dbsync"}) | ||
//@RequiredArgsConstructor | ||
//public class DbSyncDatasourceConfig { | ||
// | ||
// private final MultiDataSourceProperties multiDataSourceProperties; | ||
// | ||
// @Bean(name = "dbSyncDataSource") | ||
// public DataSource ledgerSyncDataSource() { | ||
// return multiDataSourceProperties.buildDataSource( | ||
// multiDataSourceProperties.getDatasourceDbSync()); | ||
// } | ||
// | ||
// @Bean(name = "dbSyncEntityManagerFactory") | ||
// public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean( | ||
// EntityManagerFactoryBuilder builder, @Qualifier("dbSyncDataSource") DataSource dataSource) { | ||
// return builder | ||
// .dataSource(dataSource) | ||
// .packages( | ||
// "org.cardanofoundation.ledgersync.verifier.data.app.entity.dbsync") | ||
// .build(); | ||
// } | ||
// | ||
// @Bean(name = "dbSyncTransactionManager") | ||
// public PlatformTransactionManager dbSyncTransactionManager( | ||
// @Qualifier("dbSyncEntityManagerFactory") | ||
// LocalContainerEntityManagerFactoryBean ledgerSyncEntityManagerFactory) { | ||
// return new JpaTransactionManager( | ||
// Objects.requireNonNull(ledgerSyncEntityManagerFactory.getObject())); | ||
// } | ||
//} | ||
package org.cardanofoundation.ledgersync.verifier.data.app.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.Objects; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@EnableJpaRepositories( | ||
entityManagerFactoryRef = "dbSyncEntityManagerFactory", | ||
transactionManagerRef = "dbSyncTransactionManager", | ||
basePackages = {"org.cardanofoundation.ledgersync.verifier.data.app.repository.dbsync"}) | ||
@RequiredArgsConstructor | ||
public class DbSyncDatasourceConfig { | ||
|
||
private final MultiDataSourceProperties multiDataSourceProperties; | ||
|
||
@Bean(name = "dbSyncDataSource") | ||
public DataSource ledgerSyncDataSource() { | ||
return multiDataSourceProperties.buildDataSource( | ||
multiDataSourceProperties.getDatasourceDbSync()); | ||
} | ||
|
||
@Bean(name = "dbSyncEntityManagerFactory") | ||
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean( | ||
EntityManagerFactoryBuilder builder, @Qualifier("dbSyncDataSource") DataSource dataSource) { | ||
return builder | ||
.dataSource(dataSource) | ||
.packages( | ||
"org.cardanofoundation.ledgersync.verifier.data.app.entity.dbsync") | ||
.build(); | ||
} | ||
|
||
@Bean(name = "dbSyncTransactionManager") | ||
public PlatformTransactionManager dbSyncTransactionManager( | ||
@Qualifier("dbSyncEntityManagerFactory") | ||
LocalContainerEntityManagerFactoryBean ledgerSyncEntityManagerFactory) { | ||
return new JpaTransactionManager( | ||
Objects.requireNonNull(ledgerSyncEntityManagerFactory.getObject())); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...rc/main/java/org/cardanofoundation/ledgersync/verifier/data/app/entity/dbsync/AdaPot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.entity.dbsync; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "ada_pots") | ||
public class AdaPot { | ||
@Id | ||
@Column(name = "id", nullable = false) | ||
private Long id; | ||
|
||
@NotNull | ||
@Column(name = "slot_no", nullable = false) | ||
private Long slotNo; | ||
|
||
@Column(name = "epoch_no", columnDefinition = "word31type(0, 0) not null") | ||
private Long epochNo; | ||
|
||
@Column(name = "treasury", columnDefinition = "lovelace(0, 0) not null") | ||
private Long treasury; | ||
|
||
@Column(name = "reserves", columnDefinition = "lovelace(0, 0) not null") | ||
private Long reserves; | ||
|
||
@Column(name = "rewards", columnDefinition = "lovelace(0, 0) not null") | ||
private Long rewards; | ||
|
||
@Column(name = "utxo", columnDefinition = "lovelace(0, 0) not null") | ||
private Long utxo; | ||
|
||
@Column(name = "deposits", columnDefinition = "lovelace(0, 0) not null") | ||
private Long deposits; | ||
|
||
@Column(name = "fees", columnDefinition = "lovelace(0, 0) not null") | ||
private Long fees; | ||
|
||
@NotNull | ||
@Column(name = "block_id", nullable = false) | ||
private Long blockId; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...va/org/cardanofoundation/ledgersync/verifier/data/app/mapper/AdaPotsComparisonMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.mapper; | ||
|
||
import org.cardanofoundation.ledgersync.verifier.data.app.model.AdaPotsComparison; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.model.AdaPotsComparisonKey; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Component | ||
public interface AdaPotsComparisonMapper<T> { | ||
/** | ||
* Builds a map of Ada pots comparisons. | ||
* @param source The source data list. | ||
* @return A map of Ada pots comparisons. | ||
*/ | ||
Map<AdaPotsComparisonKey, AdaPotsComparison> buildMap(List<T> source); | ||
} |
37 changes: 37 additions & 0 deletions
37
...anofoundation/ledgersync/verifier/data/app/mapper/impl/AdaPotsComparisonMapperDbSync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.mapper.impl; | ||
|
||
import org.cardanofoundation.ledgersync.verifier.data.app.mapper.AdaPotsComparisonMapper; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.model.AdaPotsComparison; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.model.AdaPotsComparisonKey; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.projection.AdaPotsProjection; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Ada pots comparison mapper for the db sync implementation. | ||
*/ | ||
public class AdaPotsComparisonMapperDbSync implements AdaPotsComparisonMapper<AdaPotsProjection> { | ||
|
||
@Override | ||
public Map<AdaPotsComparisonKey, AdaPotsComparison> buildMap(List<AdaPotsProjection> source) { | ||
Map<AdaPotsComparisonKey, AdaPotsComparison> map = new HashMap<>(); | ||
|
||
source.forEach(adaPotsProjection -> { | ||
AdaPotsComparisonKey adaPotsComparisonKey = AdaPotsComparisonKey.builder() | ||
.epochNo(adaPotsProjection.getEpochNo()) | ||
.slotNo(adaPotsProjection.getSlotNo()) | ||
.build(); | ||
|
||
AdaPotsComparison adaPotsComparison = AdaPotsComparison.builder() | ||
.adaPotsComparisonKey(adaPotsComparisonKey) | ||
.treasury(adaPotsProjection.getTreasury()) | ||
.reserves(adaPotsProjection.getReserves()) | ||
.rewards(adaPotsProjection.getRewards()) | ||
.build(); | ||
map.put(adaPotsComparisonKey, adaPotsComparison); | ||
}); | ||
return map; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...cardanofoundation/ledgersync/verifier/data/app/mapper/impl/AdaPotsComparisonMapperLS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.mapper.impl; | ||
|
||
import org.cardanofoundation.ledgersync.verifier.data.app.mapper.AdaPotsComparisonMapper; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.model.AdaPotsComparison; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.model.AdaPotsComparisonKey; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.projection.AdaPotsProjection; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Ada pots comparison mapper for the ledger sync implementation. | ||
*/ | ||
public class AdaPotsComparisonMapperLS implements AdaPotsComparisonMapper<AdaPotsProjection> { | ||
|
||
@Override | ||
public Map<AdaPotsComparisonKey, AdaPotsComparison> buildMap(List<AdaPotsProjection> source) { | ||
Map<AdaPotsComparisonKey, AdaPotsComparison> map = new HashMap<>(); | ||
|
||
source.forEach(adaPotsProjection -> { | ||
AdaPotsComparisonKey adaPotsComparisonKey = AdaPotsComparisonKey.builder() | ||
.epochNo(adaPotsProjection.getEpochNo()) | ||
.slotNo(adaPotsProjection.getSlotNo()) | ||
.build(); | ||
|
||
AdaPotsComparison adaPotsComparison = AdaPotsComparison.builder() | ||
.adaPotsComparisonKey(adaPotsComparisonKey) | ||
.reserves(adaPotsProjection.getReserves()) | ||
.rewards(adaPotsProjection.getRewards()) | ||
.build(); | ||
map.put(adaPotsComparisonKey, adaPotsComparison); | ||
}); | ||
return map; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...main/java/org/cardanofoundation/ledgersync/verifier/data/app/model/AdaPotsComparison.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.FieldDefaults; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@FieldDefaults(level = AccessLevel.PRIVATE) | ||
public class AdaPotsComparison { | ||
AdaPotsComparisonKey adaPotsComparisonKey; | ||
BigInteger treasury; | ||
BigInteger reserves; | ||
BigInteger rewards; | ||
} |
31 changes: 31 additions & 0 deletions
31
...n/java/org/cardanofoundation/ledgersync/verifier/data/app/model/AdaPotsComparisonKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.FieldDefaults; | ||
|
||
import java.util.Objects; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@FieldDefaults(level = AccessLevel.PRIVATE) | ||
public class AdaPotsComparisonKey { | ||
Long slotNo; | ||
Long epochNo; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
AdaPotsComparisonKey that = (AdaPotsComparisonKey) o; | ||
return slotNo.equals(that.slotNo) && epochNo.equals(that.epochNo); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(slotNo, epochNo); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...java/org/cardanofoundation/ledgersync/verifier/data/app/projection/AdaPotsProjection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.projection; | ||
|
||
import java.math.BigInteger; | ||
|
||
public interface AdaPotsProjection { | ||
Long getSlotNo(); | ||
Long getEpochNo(); | ||
BigInteger getTreasury(); | ||
BigInteger getReserves(); | ||
BigInteger getRewards(); | ||
} |
10 changes: 10 additions & 0 deletions
10
.../main/java/org/cardanofoundation/ledgersync/verifier/data/app/repository/AdaPotsRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.repository; | ||
|
||
import org.cardanofoundation.ledgersync.verifier.data.app.projection.AdaPotsProjection; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Set; | ||
|
||
public interface AdaPotsRepo<T> extends JpaRepository<T, Long> { | ||
Set<AdaPotsProjection> findByEpochNoIn(Set<Long> epochs); | ||
} |
17 changes: 17 additions & 0 deletions
17
...g/cardanofoundation/ledgersync/verifier/data/app/repository/dbsync/AdaPotsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.repository.dbsync; | ||
|
||
import org.cardanofoundation.ledgersync.verifier.data.app.entity.dbsync.AdaPot; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.projection.AdaPotsProjection; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.repository.AdaPotsRepo; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Set; | ||
|
||
@Repository("dbSyncAdaPotsRepository") | ||
@Primary | ||
public interface AdaPotsRepository extends AdaPotsRepo<AdaPot> { | ||
@Query("select a from AdaPot a where a.epochNo in :epochs") | ||
Set<AdaPotsProjection> findByEpochNoIn(Set<Long> epochs); | ||
} |
15 changes: 15 additions & 0 deletions
15
...rdanofoundation/ledgersync/verifier/data/app/repository/ledgersync/AdaPotsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.cardanofoundation.ledgersync.verifier.data.app.repository.ledgersync; | ||
|
||
import org.cardanofoundation.ledgersync.consumercommon.entity.AdaPots; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.projection.AdaPotsProjection; | ||
import org.cardanofoundation.ledgersync.verifier.data.app.repository.AdaPotsRepo; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Set; | ||
|
||
@Repository("ledgerSyncAdaPotsRepository") | ||
public interface AdaPotsRepository extends AdaPotsRepo<AdaPots> { | ||
@Query("select a from AdaPots a where a.epochNo in :epochs") | ||
Set<AdaPotsProjection> findByEpochNoIn(Set<Long> epochs); | ||
} |
Oops, something went wrong.