org.cardanofoundation.explorer.consumercommon.entity.AddressToken Maven / Gradle / Ivy
package org.cardanofoundation.explorer.consumercommon.entity;
import org.cardanofoundation.explorer.consumercommon.validation.Word128Type;
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.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 = "address_token")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
public class AddressToken extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "address_id", nullable = false,
foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
@EqualsAndHashCode.Exclude
private Address address;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "tx_id", nullable = false,
foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
@EqualsAndHashCode.Exclude
private Tx tx;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "ident", nullable = false,
foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
@EqualsAndHashCode.Exclude
private MultiAsset multiAsset;
@Column(name = "ident", updatable = false, insertable = false)
private Long multiAssetId;
@Column(name = "tx_id", updatable = false, insertable = false)
private Long txId;
@Column(name = "address_id", updatable = false, insertable = false)
private Long addressId;
@Column(name = "balance", nullable = false, precision = 39)
@Word128Type
@Digits(integer = 39, fraction = 0)
private BigInteger balance;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
return false;
}
AddressToken that = (AddressToken) o;
return id != null && Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}