com.github.gentity.test.test3.User Maven / Gradle / Ivy
package com.github.gentity.test.test3;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.Table;
import com.github.gentity.ToOneSide;
@Entity
@Table(name = "USER")
public class User implements Serializable
{
@Id
@Column(name = "ID")
protected Integer id;
@Column(name = "NAME", length = 100)
protected String name;
@ManyToOne
@JoinColumn(name = "CUSTOMER_ID")
protected Customer customer;
private transient boolean $removed;
final static ToOneSide relationTo$customer = ToOneSide.of((o -> o.$removed), (o -> o.customer), ((o,m) -> o.customer = m), Customer.relationTo$user);
public User(Integer id) {
this.id = id;
}
protected User() {
}
@PreRemove
private void $onPreRemove() {
$removed = true;
}
@PrePersist
private void $onPrePersist() {
$removed = false;
}
public static User.Builder builder() {
return new User.Builder();
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Customer getCustomer() {
return (relationTo$customer.get(this));
}
public void setCustomer(Customer customer) {
relationTo$customer.set(this, customer);
}
public static class Builder {
private User instance;
private String name;
private Customer customer;
protected User _initInstance(User instance) {
instance.name = this.name;
instance.relationTo$customer.set(instance, this.customer);
return instance;
}
public User.Builder name(String name) {
this.name = name;
return this;
}
public User.Builder customer(Customer customer) {
this.customer = customer;
return this;
}
public User buildWithId(Integer id) {
return this._initInstance(new User(id));
}
}
}