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

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

There is a newer version: 1.17.5
Show newest version
package com.xlrit.gears.common.test_domain;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.google.common.base.MoreObjects;
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 = "AUTHOR", collectionName = "AUTHORS")
@Attributes({ "firstName", "lastName", "born", "isMale", "books" })
@Entity @Table(name="AUTHOR")
@Getter @Setter
@NoArgsConstructor
public class Author implements Identifiable {
	public static final Relation.OneToMany BOOKS = Relation.oneToMany(Book.class, Author::getBooks, Author::setBooks, Book::getAuthor, Book::setAuthor);

	@Id @Getter
	private String id;

	@Column(name="FIRST_NAME_", nullable=false)
	@Attribute(formalName = "first_name", label = "First name", type = DataType.TEXT)
	private String firstName;

	@Column(name="LAST_NAME_", nullable=false)
	@Attribute(formalName = "last_name", label = "Last name", type = DataType.TEXT)
	private String lastName;

	@Column(name="BORN_", nullable=true)
	@Attribute(formalName = "born", label = "Born", type = DataType.DATE)
	private LocalDate born;

	@Column(name="IS_MALE_")
	@Attribute(formalName = "is_male", label = "Is male", type = DataType.BOOLEAN)
	private Boolean isMale;

	@OneToMany(mappedBy = "author")
	@Attribute(formalName = "BOOKS", label = "Books", type = DataType.ENTITY)
	private List books = new ArrayList<>();

	public void setBooksBidi(List newBooks) {
		BOOKS.set(this, newBooks);
	}

	public Author(String id) {
		this.id = id;
	}

	@Override
	@Displayed
	public String toString() {
		return "Author[" + new DisplayedHelper()
			.excludeNulls()
			.add("id", id)
			.add("firstName", firstName)
			.add("lastName", lastName)
			.add("born", born)
			.add("isMale", isMale)
			.toString() + "]";
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
		Author author = (Author) o;
		return id != null && Objects.equals(id, author.id);
	}

	@Override
	public int hashCode() {
		return getClass().hashCode();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy