org.cardanofoundation.explorer.consumercommon.entity.AdaPots Maven / Gradle / Ivy
package org.cardanofoundation.explorer.consumercommon.entity;
import org.cardanofoundation.explorer.consumercommon.validation.Lovelace;
import org.cardanofoundation.explorer.consumercommon.validation.Word31Type;
import org.cardanofoundation.explorer.consumercommon.validation.Word63Type;
import java.math.BigInteger;
import java.util.Objects;
import jakarta.persistence.Column;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.Digits;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.hibernate.Hibernate;
@Entity
@Table(name = "ada_pots", uniqueConstraints = {
@UniqueConstraint(name = "unique_ada_pots", columnNames = {"block_id"})
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
public class AdaPots extends BaseEntity {
@Column(name = "slot_no", nullable = false)
@Word63Type
private Long slotNo;
@Column(name = "epoch_no", nullable = false)
@Word31Type
private Integer epochNo;
@Column(name = "treasury", nullable = false, precision = 20)
@Lovelace
@Digits(integer = 20, fraction = 0)
private BigInteger treasury;
@Column(name = "reserves", nullable = false, precision = 20)
@Lovelace
@Digits(integer = 20, fraction = 0)
private BigInteger reserves;
@Column(name = "rewards", nullable = false, precision = 20)
@Lovelace
@Digits(integer = 20, fraction = 0)
private BigInteger rewards;
@Column(name = "utxo", nullable = false, precision = 20)
@Lovelace
@Digits(integer = 20, fraction = 0)
private BigInteger utxo;
@Column(name = "deposits", nullable = false, precision = 20)
@Lovelace
@Digits(integer = 20, fraction = 0)
private BigInteger deposits;
@Column(name = "fees", nullable = false, precision = 20)
@Lovelace
@Digits(integer = 20, fraction = 0)
private BigInteger fees;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "block_id", nullable = false, unique = true,
foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT, name = "none"))
@EqualsAndHashCode.Exclude
private Block block;
@Column(name = "block_id", updatable = false, insertable = false)
private Long blockId;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
return false;
}
AdaPots adaPots = (AdaPots) o;
return id != null && Objects.equals(id, adaPots.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}