com.xlrit.gears.common.test_domain.Book Maven / Gradle / Ivy
package com.xlrit.gears.common.test_domain;
import java.math.BigDecimal;
import java.util.Objects;
import com.xlrit.gears.base.meta.*;
import com.xlrit.gears.base.model.Identifiable;
import jakarta.persistence.*;
import jakarta.persistence.Id;
import org.hibernate.Hibernate;
import lombok.*;
@EntityType(typeName = "BOOK", collectionName = "BOOKS")
@Attributes({ "title", "isbn", "year", "score", "author" })
@Entity @Table(name="BOOK")
@Getter @Setter
@NoArgsConstructor @AllArgsConstructor
public class Book implements Identifiable {
public static final Relation.ManyToOne AUTHOR = Relation.manyToOne(Author.class, Book::getAuthor, Book::setAuthor, Author::getBooks, Author::setBooks);
@Id @Getter
private String id;
@Column(name="TITLE_", length=64, nullable=false)
@Attribute(formalName = "title", label = "Title", type = DataType.TEXT)
private String title;
@Column(name="ISBN_", length=17, nullable=false, unique=true)
@Attribute(formalName = "isbn", label = "ISBN", type = DataType.TEXT)
private String isbn;
@Column(name="YEAR_", nullable=false)
@Attribute(formalName = "year", label = "Year", type = DataType.INTEGER)
private Long year;
@Column(name="SCORE_", nullable = false)
@Attribute(formalName = "score", label = "Score", type = DataType.DECIMAL)
private BigDecimal score;
@ManyToOne
@Attribute(formalName = "AUTHOR", label = "Author", type = DataType.ENTITY)
private Author author;
public Book(String id) {
this.id = id;
}
public void setAuthorBidi(Author newAuthor) {
AUTHOR.set(this, newAuthor);
}
@Override
@Displayed
public String toString() {
return "Book[" +
"id=" + id +
", title='" + title + "'" +
", isbn='" + isbn + "'" +
", year=" + year +
", score=" + score +
", author=" + author +
']';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
Book book = (Book) o;
return id != null && Objects.equals(id, book.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}