org.cardanofoundation.explorer.consumercommon.entity.SlotLeader Maven / Gradle / Ivy
package org.cardanofoundation.explorer.consumercommon.entity;
import org.cardanofoundation.explorer.consumercommon.validation.Hash28Type;
import java.util.List;
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.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
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 = "slot_leader", uniqueConstraints = {
@UniqueConstraint(name = "unique_slot_leader",
columnNames = {"hash"}
)
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
public class SlotLeader extends BaseEntity {
@Column(name = "hash", nullable = false, length = 56)
@Hash28Type
private String hash;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pool_hash_id",
foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT, name = "none"))
@EqualsAndHashCode.Exclude
private PoolHash poolHash;
@Column(name = "pool_hash_id", updatable = false, insertable = false)
private Long poolHashId;
@Column(name = "description", nullable = false, length = 65535)
private String description;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "slot_leader_id", referencedColumnName = "id"
, foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT, name = "none"))
private List blocks;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
return false;
}
SlotLeader that = (SlotLeader) o;
return id != null && Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}