Skip to content

Commit 327a0d3

Browse files
authored
Cherry Pick Migration Fix (#10308)
Use owner template (#10304) * use owner template --------- (cherry picked from commit 883b425) Signed-off-by: Jesse Nelson <[email protected]>
1 parent 000ef53 commit 327a0d3

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/migration/FixNodeTransactionsMigration.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.hedera.mirror.common.domain.transaction.Transaction;
2222
import com.hedera.mirror.common.domain.transaction.TransactionType;
2323
import com.hedera.mirror.importer.ImporterProperties;
24+
import com.hedera.mirror.importer.config.Owner;
2425
import com.hedera.mirror.importer.parser.record.entity.EntityProperties;
2526
import com.hedera.mirror.importer.parser.record.transactionhandler.AbstractNodeTransactionHandler;
2627
import com.hederahashgraph.api.proto.java.TransactionRecord;
@@ -39,8 +40,8 @@
3940
import org.springframework.core.env.Environment;
4041
import org.springframework.core.env.Profiles;
4142
import org.springframework.jdbc.core.DataClassRowMapper;
43+
import org.springframework.jdbc.core.JdbcTemplate;
4244
import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
43-
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
4445

4546
@Named
4647
public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
@@ -56,7 +57,7 @@ public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
5657
"""
5758
select consensus_timestamp, transaction_bytes, transaction_record_bytes
5859
from transaction
59-
where consensus_timestamp >= :startTimestamp and type in (54, 55, 56)
60+
where consensus_timestamp >= ? and type in (54, 55, 56)
6061
order by consensus_timestamp asc;
6162
""";
6263

@@ -66,7 +67,7 @@ public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
6667
values (?, ?, ?, ?, ?::int8range);
6768
""";
6869

69-
private final NamedParameterJdbcTemplate jdbcTemplate;
70+
private final JdbcTemplate jdbcTemplate;
7071
private final ObjectProvider<AbstractNodeTransactionHandler> nodeTransactionHandlers;
7172
private final EntityProperties entityProperties;
7273
private final Map<TransactionType, AbstractNodeTransactionHandler> nodeTransactionHandlerMap =
@@ -79,7 +80,7 @@ public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
7980
ObjectProvider<AbstractNodeTransactionHandler> nodeTransactionHandlers,
8081
ImporterProperties importerProperties,
8182
EntityProperties entityProperties,
82-
NamedParameterJdbcTemplate jdbcTemplate) {
83+
@Owner JdbcTemplate jdbcTemplate) {
8384
super(importerProperties.getMigration());
8485
this.v2 = environment.acceptsProfiles(Profiles.of("v2"));
8586
this.nodeTransactionHandlers = nodeTransactionHandlers;
@@ -122,14 +123,16 @@ protected void doMigrate() throws IOException {
122123
ps.setString(5, PostgreSQLGuavaRangeType.INSTANCE.asString(node.getTimestampRange()));
123124
};
124125

125-
jdbcTemplate.getJdbcTemplate().execute(DROP_DATA_SQL);
126-
jdbcTemplate
127-
.getJdbcTemplate()
128-
.batchUpdate(INSERT_SQL.formatted("node"), nodeState.values(), nodeState.size(), statementSetter);
129-
jdbcTemplate
130-
.getJdbcTemplate()
131-
.batchUpdate(
132-
INSERT_SQL.formatted("node_history"), historicalNodes, historicalNodes.size(), statementSetter);
126+
jdbcTemplate.execute(DROP_DATA_SQL);
127+
jdbcTemplate.batchUpdate(INSERT_SQL.formatted("node"), nodeState.values(), nodeState.size(), statementSetter);
128+
jdbcTemplate.batchUpdate(
129+
INSERT_SQL.formatted("node_history"), historicalNodes, historicalNodes.size(), statementSetter);
130+
131+
log.info(
132+
"Successfully processed {} node transactions producing {} rows and {} history rows",
133+
nodeRecordItems.size(),
134+
nodeState.size(),
135+
historicalNodes.size());
133136
}
134137

135138
private Node recordItemToNode(RecordItem recordItem) {
@@ -165,10 +168,7 @@ public String getDescription() {
165168

166169
private List<RecordItem> getRecordItems() {
167170
return jdbcTemplate
168-
.query(
169-
NODE_TRANSACTIONS_SQL,
170-
Map.of("startTimestamp", LOWER_TIMESTAMP),
171-
new DataClassRowMapper<>(Transaction.class))
171+
.query(NODE_TRANSACTIONS_SQL, new DataClassRowMapper<>(Transaction.class), LOWER_TIMESTAMP)
172172
.stream()
173173
.map(this::toRecordItem)
174174
.toList();

0 commit comments

Comments
 (0)