All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.common.test_domain.Book Maven / Gradle / Ivy

There is a newer version: 1.17.5
Show newest version
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 com.xlrit.gears.base.util.DisplayedHelper;
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[" + new DisplayedHelper()
			.excludeNulls()
			.add("id", id)
			.add("title", title)
			.add("isbn", isbn)
			.add("year", year)
			.add("score", score)
			.add("author", author)
			.toString() + "]";
	}

	@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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy