Skip to content

Commit 3435ec6

Browse files
committed
Optimize code
Signed-off-by: sdimitrov9 <stoyan.dimitrov@limechain.tech>
1 parent 8c76d04 commit 3435ec6

57 files changed

Lines changed: 349 additions & 232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ configurations.all {
1010

1111
dependencies {
1212
val testClasses by configurations.registering
13-
annotationProcessor("jakarta.persistence:jakarta.persistence-api")
1413
api("org.postgresql:postgresql")
1514
api("org.springframework.data:spring-data-relational")
1615
api("org.springframework.boot:spring-boot-starter-data-jdbc")
@@ -21,7 +20,6 @@ dependencies {
2120
api("com.google.protobuf:protobuf-java")
2221
api("com.hedera.hashgraph:hedera-protobuf-java-api") { isTransitive = false }
2322
api("commons-codec:commons-codec")
24-
api("io.hypersistence:hypersistence-utils-hibernate-71")
2523
api("jakarta.servlet:jakarta.servlet-api")
2624
api("org.apache.commons:commons-lang3")
2725
api("org.apache.tuweni:tuweni-bytes")

common/src/main/java/org/hiero/mirror/common/CommonConfiguration.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
3636
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
3737
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
38-
import org.springframework.data.relational.core.mapping.NamingStrategy;
39-
import org.springframework.data.relational.core.mapping.Table;
4038

4139
@Configuration(proxyBeanMethods = false)
4240
@ConfigurationPropertiesScan("org.hiero.mirror")
@@ -66,25 +64,6 @@ HikariConfig hikariConfig() {
6664
return new HikariConfig();
6765
}
6866

69-
/**
70-
* Mirror Node Naming Strategy.
71-
* Ensures class 'AccountBalance' maps to 'account_balance' and
72-
* respects the @Table annotation values.
73-
*/
74-
@Bean
75-
public NamingStrategy namingStrategy() {
76-
return new NamingStrategy() {
77-
@Override
78-
public String getTableName(Class<?> type) {
79-
var table = type.getAnnotation(Table.class);
80-
if (table != null && !table.value().isEmpty()) {
81-
return table.value();
82-
}
83-
return NamingStrategy.super.getTableName(type);
84-
}
85-
};
86-
}
87-
8867
@Bean
8968
@ConditionalOnMissingBean(DataSource.class)
9069
@Lazy
@@ -138,8 +117,8 @@ public JdbcCustomConversions jdbcCustomConversions() {
138117
new PostgresHookJdbcConverters.PostgresHookTypeToPGobject(),
139118
new PostgresHookJdbcConverters.PGobjectToPostgresHookType(),
140119
new PostgresHookJdbcConverters.StringToPostgresHookType(),
141-
new RangeToPGobjectWritingConverter(), // Replaces @TypeRegistration
142-
new PGobjectToRangeReadingConverter(), // Replaces @TypeRegistration
120+
new RangeToPGobjectWritingConverter(),
121+
new PGobjectToRangeReadingConverter(),
143122
new JsonbWritingConverters.FixedFeesHolderToJsonb(),
144123
new JsonbWritingConverters.FractionalFeesHolderToJsonb(),
145124
new JsonbWritingConverters.RoyaltyFeesHolderToJsonb(),

common/src/main/java/org/hiero/mirror/common/converter/EntityIdSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import com.fasterxml.jackson.databind.JsonSerializer;
77
import com.fasterxml.jackson.databind.SerializerProvider;
88
import java.io.IOException;
9+
import lombok.AccessLevel;
910
import lombok.NoArgsConstructor;
1011
import org.hiero.mirror.common.domain.entity.EntityId;
1112

12-
@NoArgsConstructor()
13+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
1314
@SuppressWarnings("java:S6548")
1415
public class EntityIdSerializer extends JsonSerializer<EntityId> {
1516

common/src/main/java/org/hiero/mirror/common/converter/ObjectToStringSerializer.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.fasterxml.jackson.databind.SerializationFeature;
1010
import com.fasterxml.jackson.databind.SerializerProvider;
1111
import com.fasterxml.jackson.databind.module.SimpleModule;
12-
import io.hypersistence.utils.hibernate.type.util.JsonConfiguration;
1312
import java.io.IOException;
1413
import lombok.AccessLevel;
1514
import lombok.NoArgsConstructor;
@@ -35,13 +34,6 @@ public class ObjectToStringSerializer extends JsonSerializer<Object> {
3534
.registerModule(module)
3635
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
3736
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
38-
39-
// Optional: fails outside Hibernate (e.g. some JDBC-only modules); JsonBinaryType is JPA-specific.
40-
try {
41-
JsonConfiguration.INSTANCE.getObjectMapperWrapper().setObjectMapper(OBJECT_MAPPER);
42-
} catch (Throwable e) {
43-
LOG.debug("Skipping Hypersistence JsonConfiguration hook: {}", e.toString());
44-
}
4537
}
4638

4739
public static void init() {

common/src/main/java/org/hiero/mirror/common/converter/RangeToStringSerializer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public void serialize(Range<Long> range, JsonGenerator gen, SerializerProvider p
2626
String lower = range.hasLowerBound() ? range.lowerEndpoint().toString() : "";
2727
String upper = range.hasUpperBound() ? range.upperEndpoint().toString() : "";
2828

29-
// Mirror Node standard: [lower,upper)
30-
// This produces the same string format the Hibernate type used to generate
3129
gen.writeString(String.format("[%s,%s)", lower, upper));
3230
}
3331
}

common/src/main/java/org/hiero/mirror/common/domain/addressbook/AddressBook.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
@AllArgsConstructor(access = AccessLevel.PRIVATE)
2424
public class AddressBook {
2525

26-
// consensusTimestamp + 1ns of transaction containing final fileAppend operation
2726
@Id
2827
private Long startConsensusTimestamp;
2928

30-
// consensusTimestamp of transaction containing final fileAppend operation of next address book
3129
private Long endConsensusTimestamp;
3230

3331
@EqualsAndHashCode.Exclude
@@ -39,7 +37,6 @@ public class AddressBook {
3937
@ToString.Exclude
4038
private byte[] fileData;
4139

42-
// Converter removed. Handled by global EntityIdConverter bean.
4340
private EntityId fileId;
4441

4542
private Integer nodeCount;

common/src/main/java/org/hiero/mirror/common/domain/addressbook/AddressBookEntry.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class AddressBookEntry implements Persistable<AddressBookEntry.Id> {
4242

4343
private String memo;
4444

45-
// Converter removed. Handled by global EntityId Reading/Writing converters.
4645
private EntityId nodeAccountId;
4746

4847
@ToString.Exclude
@@ -53,7 +52,7 @@ public class AddressBookEntry implements Persistable<AddressBookEntry.Id> {
5352

5453
@EqualsAndHashCode.Exclude
5554
@ToString.Exclude
56-
@Transient // Spring Data version
55+
@Transient
5756
private PublicKey publicKeyObject;
5857

5958
@Builder.Default
@@ -64,17 +63,14 @@ public class AddressBookEntry implements Persistable<AddressBookEntry.Id> {
6463

6564
private Long stake;
6665

67-
// Convenience accessor so callers can use entry.getConsensusTimestamp() without going through getId()
6866
public long getConsensusTimestamp() {
6967
return id != null ? id.getConsensusTimestamp() : 0L;
7068
}
7169

72-
// Convenience accessor so callers can use entry.getNodeId() without going through getId()
7370
public long getNodeId() {
7471
return id != null ? id.getNodeId() : 0L;
7572
}
7673

77-
// Custom getter to maintain the logic for the transient field
7874
public PublicKey getPublicKeyObject() {
7975
if (publicKeyObject == null && publicKey != null) {
8076
publicKeyObject = parsePublicKey();
@@ -114,7 +110,6 @@ public static class Id implements Serializable {
114110
private long nodeId;
115111
}
116112

117-
// Custom builder methods so existing callers can use .consensusTimestamp(x).nodeId(y) without restructuring
118113
public static class AddressBookEntryBuilder {
119114
public AddressBookEntryBuilder consensusTimestamp(long consensusTimestamp) {
120115
if (this.id == null) this.id = new Id();

common/src/main/java/org/hiero/mirror/common/domain/addressbook/AddressBookServiceEndpoint.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ public Id getId() {
3636
@JsonIgnore
3737
@Override
3838
public boolean isNew() {
39-
// Natural IDs for service endpoints should always trigger an INSERT
4039
return true;
4140
}
4241

43-
// Convenience accessors so existing callers keep working without restructuring
44-
4542
public long getConsensusTimestamp() {
4643
return id != null ? id.getConsensusTimestamp() : 0L;
4744
}
@@ -107,7 +104,6 @@ public static class Id implements Serializable {
107104
private String domainName;
108105
}
109106

110-
// Custom builder methods so existing callers can set individual key fields directly
111107
public static class AddressBookServiceEndpointBuilder {
112108
public AddressBookServiceEndpointBuilder consensusTimestamp(long consensusTimestamp) {
113109
if (this.id == null) this.id = new Id();

common/src/main/java/org/hiero/mirror/common/domain/addressbook/NodeStake.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@AllArgsConstructor(access = AccessLevel.PRIVATE)
1818
@Builder(toBuilder = true)
1919
@Data
20-
@Table("node_stake") // Explicit naming is best practice
20+
@Table("node_stake")
2121
@NoArgsConstructor
2222
public class NodeStake implements Persistable<NodeStake.Id> {
2323

@@ -72,7 +72,6 @@ public Id getId() {
7272
@JsonIgnore
7373
@Override
7474
public boolean isNew() {
75-
// Keeps the optimization to skip the "SELECT" check before insert
7675
return true;
7776
}
7877

@@ -87,7 +86,6 @@ public static class Id implements Serializable {
8786
private long nodeId;
8887
}
8988

90-
/** Bridges {@link Builder} to the flattened {@link #consensusTimestamp} / {@link #nodeId} API. */
9189
public static class NodeStakeBuilder {
9290
public NodeStakeBuilder consensusTimestamp(long consensusTimestamp) {
9391
if (this.id == null) {

common/src/main/java/org/hiero/mirror/common/domain/balance/AccountBalance.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ public class AccountBalance implements Persistable<AccountBalance.Id>, StreamIte
3737
@Embedded(onEmpty = Embedded.OnEmpty.USE_NULL)
3838
private Id id;
3939

40-
// Convenience accessor so callers can use accountBalance.getConsensusTimestamp() without going through getId()
4140
public long getConsensusTimestamp() {
4241
return id != null ? id.getConsensusTimestamp() : 0L;
4342
}
4443

45-
// Convenience accessor so callers can use accountBalance.getAccountId() without going through getId()
4644
public EntityId getAccountId() {
4745
return id != null ? id.getAccountId() : null;
4846
}

0 commit comments

Comments
 (0)