#2104 - Refactor rename ebean-ddlgen module to ebean-ddl-generator

This commit is contained in:
rob bygrave committed 2020-11-18 22:28:33 +13:00
1 parent e5b0b31da6
commit 6ecd849499
418 files changed
+59 -59

No files matched your search

@@ -0,0 +1,61 @@
package org.tests.inheritance.company.domain;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
/**
* @author Per-Ingemar Andersson, It-huset i Norden AB
*/
@Entity
@Table(name = "bar")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "bar_type", discriminatorType = DiscriminatorType.STRING)
//@MappedSuperclass
public abstract class AbstractBar {
@Id
@GeneratedValue
private int barId;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "foo_id", nullable = false)
private Foo foo;
@Version
private int version;
public void setBarId(int barId) {
this.barId = barId;
}
public int getBarId() {
return barId;
}
public Foo getFoo() {
return foo;
}
public void setFoo(Foo foo) {
this.foo = foo;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}
@@ -0,0 +1,12 @@
package org.tests.inheritance.company.domain;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
/**
* @author Per-Ingemar Andersson, It-huset i Norden AB
*/
@Entity
@DiscriminatorValue("ConcreteBar")
public class ConcreteBar extends AbstractBar {
}
@@ -0,0 +1,47 @@
package org.tests.inheritance.company.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
/**
* @author Per-Ingemar Andersson, It-huset i Norden AB
*/
@Entity
@Table(name = "foo")
public class Foo {
@Id
@GeneratedValue
private int fooId;
private String importantText;
@Version
private int version;
public void setFooId(int fooId) {
this.fooId = fooId;
}
public int getFooId() {
return fooId;
}
public String getImportantText() {
return importantText;
}
public void setImportantText(String importantText) {
this.importantText = importantText;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}
@@ -0,0 +1,52 @@
package org.tests.inheritance.company.domain;
import io.ebean.Ebean;
import io.ebean.EbeanServer;
import junit.framework.TestCase;
import org.junit.Assert;
import java.util.List;
public class TestInheritAbstract extends TestCase {
public void testMe() {
EbeanServer server = Ebean.getServer(null);
List<AbstractBar> list0 = server.find(AbstractBar.class)
.findList();
Assert.assertNotNull(list0);
List<AbstractBar> list1 = server.find(AbstractBar.class)
.fetch("foo", "importantText")
.findList();
Assert.assertNotNull(list1);
Foo f = new Foo();
f.setImportantText("blah");
server.save(f);
ConcreteBar cb = new ConcreteBar();
cb.setFoo(f);
server.save(cb);
List<AbstractBar> list2 = server.find(AbstractBar.class)
.fetch("foo", "importantText")
.findList();
Assert.assertNotNull(list2);
Assert.assertTrue(!list2.isEmpty());
for (AbstractBar abstractBar : list2) {
Foo foo = abstractBar.getFoo();
String importantText = foo.getImportantText();
Assert.assertNotNull(importantText);
}
}
}
@@ -0,0 +1,16 @@
package org.tests.inheritance.model;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public class AbstractBaseClass {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,55 @@
package org.tests.inheritance.model;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class CalculationResult {
@Id
@Column(name = "id")
private Integer id;
private double charge;
@ManyToOne(cascade = CascadeType.PERSIST)
private ProductConfiguration productConfiguration;
@ManyToOne(cascade = CascadeType.PERSIST)
private GroupConfiguration groupConfiguration;
public double getCharge() {
return charge;
}
public void setCharge(double charge) {
this.charge = charge;
}
public ProductConfiguration getProductConfiguration() {
return productConfiguration;
}
public void setProductConfiguration(ProductConfiguration productConfiguration) {
this.productConfiguration = productConfiguration;
}
public GroupConfiguration getGroupConfiguration() {
return groupConfiguration;
}
public void setGroupConfiguration(GroupConfiguration groupConfiguration) {
this.groupConfiguration = groupConfiguration;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
@@ -0,0 +1,50 @@
package org.tests.inheritance.model;
import io.ebean.annotation.Cache;
import io.ebean.annotation.ChangeLog;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
@ChangeLog
@Entity
@Cache(enableQueryCache = true)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, columnDefinition = "varchar(21)")
public class Configuration extends AbstractBaseClass {
@Id
@Column(name = "id")
private Integer id;
@ManyToOne
private Configurations configurations;
public Configuration() {
super();
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Configurations getConfigurations() {
return configurations;
}
public void setConfigurations(Configurations configurations) {
this.configurations = configurations;
}
}
@@ -0,0 +1,64 @@
package org.tests.inheritance.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
public class Configurations {
@Id
@Column(name = "id")
private Integer id;
private String name;
@OneToMany
private List<GroupConfiguration> groupConfigurations;
@OneToMany
private List<ProductConfiguration> productConfigurations;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<GroupConfiguration> getGroupConfigurations() {
return groupConfigurations;
}
public void setGroupConfigurations(List<GroupConfiguration> groupConfigurations) {
this.groupConfigurations = groupConfigurations;
}
public void addGroupConfiguration(GroupConfiguration groupConfiguration) {
groupConfiguration.setConfigurations(this);
groupConfigurations.add(groupConfiguration);
}
public List<ProductConfiguration> getProductConfigurations() {
return productConfigurations;
}
public void setProductConfigurations(List<ProductConfiguration> productConfigurations) {
this.productConfigurations = productConfigurations;
}
public void addProductConfiguration(ProductConfiguration productConfiguration) {
productConfiguration.setConfigurations(this);
productConfigurations.add(productConfiguration);
}
}
@@ -0,0 +1,40 @@
package org.tests.inheritance.model;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
@DiscriminatorValue("2")
public class GroupConfiguration extends Configuration {
private String groupName;
@OneToMany(mappedBy = "groupConfiguration")
private List<CalculationResult> results;
public GroupConfiguration() {
super();
}
public GroupConfiguration(String name) {
super();
this.groupName = name;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public List<CalculationResult> getResults() {
return results;
}
public void setResults(List<CalculationResult> results) {
this.results = results;
}
}
@@ -0,0 +1,35 @@
package org.tests.inheritance.model;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
@DiscriminatorValue("1")
public class ProductConfiguration extends Configuration {
private String productName;
@OneToMany(mappedBy = "productConfiguration")
private List<CalculationResult> results;
public ProductConfiguration() {
super();
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public List<CalculationResult> getResults() {
return results;
}
public void setResults(List<CalculationResult> results) {
this.results = results;
}
}
@@ -0,0 +1,59 @@
package org.tests.model;
import io.ebean.Model;
import io.ebean.annotation.WhenCreated;
import io.ebean.annotation.WhenModified;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import java.sql.Timestamp;
@MappedSuperclass
public class BaseModel extends Model {
@Id
Long id;
@Version
Long version;
@WhenCreated
Timestamp whenCreated;
@WhenModified
Timestamp whenModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public Timestamp getWhenCreated() {
return whenCreated;
}
public void setWhenCreated(Timestamp whenCreated) {
this.whenCreated = whenCreated;
}
public Timestamp getWhenModified() {
return whenModified;
}
public void setWhenModified(Timestamp whenModified) {
this.whenModified = whenModified;
}
}
@@ -0,0 +1,129 @@
package org.tests.model.basic;
import io.ebean.annotation.InvalidateQueryCache;
import org.tests.model.metaannotation.SizeMedium;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.Size;
import java.sql.Timestamp;
/**
* Address entity bean.
*/
// Address is not L2 cached directly but it is joined to queries that are cached
// What InvalidateQueryCache means is that we propagate a table modification event
// when address is changed ... and cached queries that join to address will be
// invalidated accordingly.
@InvalidateQueryCache
@Entity
@Table(name = "o_address")
public class Address {
@Id
Integer id;
@Size(max = 100)
@Column(name = "line_1")
String line1;
@SizeMedium
@Column(name = "line_2")
String line2;
@SizeMedium
String city;
Timestamp cretime;
@Version
Timestamp updtime;
/**
* Return id.
*/
public Integer getId() {
return id;
}
/**
* Set id.
*/
public void setId(Integer id) {
this.id = id;
}
/**
* Return line 1.
*/
public String getLine1() {
return line1;
}
/**
* Set line 1.
*/
public void setLine1(String line1) {
this.line1 = line1;
}
/**
* Return line 2.
*/
public String getLine2() {
return line2;
}
/**
* Set line 2.
*/
public void setLine2(String line2) {
this.line2 = line2;
}
/**
* Return city.
*/
public String getCity() {
return city;
}
/**
* Set city.
*/
public void setCity(String city) {
this.city = city;
}
/**
* Return cretime.
*/
public Timestamp getCretime() {
return cretime;
}
/**
* Set cretime.
*/
public void setCretime(Timestamp cretime) {
this.cretime = cretime;
}
/**
* Return updtime.
*/
public Timestamp getUpdtime() {
return updtime;
}
/**
* Set updtime.
*/
public void setUpdtime(Timestamp updtime) {
this.updtime = updtime;
}
}
@@ -0,0 +1,30 @@
package org.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class CKeyAssoc {
@Id
Integer id;
String assocOne;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAssocOne() {
return assocOne;
}
public void setAssocOne(String assocOne) {
this.assocOne = assocOne;
}
}
@@ -0,0 +1,55 @@
package org.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class CKeyDetail {
@Id
Integer id;
String something;
@ManyToOne
// @JoinColumns({
// @JoinColumn(name="parent_one_key", referencedColumnName="one_key"),
// @JoinColumn(name="parent_two_key", referencedColumnName="two_key")
// })
CKeyParent parent;
public CKeyDetail() {
}
public CKeyDetail(String something) {
this.something = something;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
public CKeyParent getParent() {
return parent;
}
public void setParent(CKeyParent parent) {
this.parent = parent;
}
}
@@ -0,0 +1,79 @@
package org.tests.model.basic;
import io.ebean.annotation.Cache;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import java.util.ArrayList;
import java.util.List;
@Entity
@Cache
public class CKeyParent {
@EmbeddedId
CKeyParentId id;
String name;
@Version
int version;
@ManyToOne(cascade = CascadeType.PERSIST)
CKeyAssoc assoc;
@OneToMany(cascade = CascadeType.PERSIST, mappedBy = "parent")
List<CKeyDetail> details;
public CKeyParentId getId() {
return id;
}
public void setId(CKeyParentId id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public CKeyAssoc getAssoc() {
return assoc;
}
public void setAssoc(CKeyAssoc assoc) {
this.assoc = assoc;
}
public List<CKeyDetail> getDetails() {
return details;
}
public void setDetails(List<CKeyDetail> details) {
this.details = details;
}
public void add(CKeyDetail detail) {
if (details == null) {
details = new ArrayList<>();
}
details.add(detail);
}
}
@@ -0,0 +1,58 @@
package org.tests.model.basic;
import javax.persistence.Embeddable;
import javax.validation.constraints.Size;
@Embeddable
public class CKeyParentId {
Integer oneKey;
@Size(max = 127)
String twoKey;
public CKeyParentId() {
}
public CKeyParentId(Integer oneKey, String twoKey) {
this.oneKey = oneKey;
this.twoKey = twoKey;
}
public Integer getOneKey() {
return oneKey;
}
public void setOneKey(Integer oneKey) {
this.oneKey = oneKey;
}
public String getTwoKey() {
return twoKey;
}
public void setTwoKey(String twoKey) {
this.twoKey = twoKey;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CKeyParentId)) {
return false;
}
CKeyParentId otherKey = (CKeyParentId) o;
return otherKey.hashCode() == hashCode();
}
@Override
public int hashCode() {
int hc = getClass().getName().hashCode();
hc = 31 * hc + oneKey;
hc = 31 * hc + twoKey.hashCode();
return hc;
}
}
@@ -0,0 +1,71 @@
package org.tests.model.basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.List;
@Entity(name = "Person")
@Table(name = "PERSONS")
public class Person implements Serializable {
private static final long serialVersionUID = 495045977245770183L;
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
@SequenceGenerator(name = "PERSONS_SEQ", initialValue = 1000, allocationSize = 40)
@Column(name = "ID", unique = true, nullable = false)
private Long id;
@Column(name = "SURNAME", nullable = false, unique = false, columnDefinition = "varchar(64)")
private String surname;
@Column(name = "NAME", nullable = false, unique = false, columnDefinition = "varchar(64)")
private String name;
@OneToMany(targetEntity = Phone.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "person")
private List<Phone> phones;
public Person() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Phone> getPhones() {
return phones;
}
public void setPhones(List<Phone> phones) {
this.phones = phones;
}
}
@@ -0,0 +1,61 @@
package org.tests.model.basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@Entity(name = "Phone")
@Table(name = "PHONES")
public class Phone implements Serializable {
private static final long serialVersionUID = -326610269092956952L;
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Long id;
@Column(name = "phone_number", nullable = false, unique = true, columnDefinition = "varchar(7)")
private String phoneNumber;
@ManyToOne(targetEntity = Person.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "person_id", nullable = false)
private Person person;
public Phone() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@NotNull
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
@@ -0,0 +1,66 @@
package org.tests.model.basic;
import io.ebean.annotation.DbEnumValue;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.ManyToOne;
@Entity
@Inheritance
@DiscriminatorValue("T")
public class Truck extends Vehicle {
private static final long serialVersionUID = 9195535931523211134L;
public enum Size {
SMALL("S"),
MEDIUM("M"),
LARGE("L"),
HUGE("H");
String value;
Size(String value) {
this.value = value;
}
@DbEnumValue(length = 3)
public String value() {
return value;
}
}
@Column(name = "siz")
private Size size;
@ManyToOne
TruckRef truckRef;
private Double capacity;
public Double getCapacity() {
return capacity;
}
public void setCapacity(Double capacity) {
this.capacity = capacity;
}
public TruckRef getTruckRef() {
return truckRef;
}
public void setTruckRef(TruckRef truckRef) {
this.truckRef = truckRef;
}
public Size getSize() {
return size;
}
public void setSize(Size size) {
this.size = size;
}
}
@@ -0,0 +1,30 @@
package org.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class TruckRef {
@Id
Integer id;
String something;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
}
@@ -0,0 +1,57 @@
package org.tests.model.basic;
import org.tests.model.BaseModel;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.ManyToOne;
import java.util.Date;
@Entity
@Inheritance
@DiscriminatorColumn(length = 3)
public abstract class Vehicle extends BaseModel {
private String licenseNumber;
private Date registrationDate;
// @Transient
private transient String testTransient;
@ManyToOne
private VehicleLease lease;
public String getLicenseNumber() {
return licenseNumber;
}
public void setLicenseNumber(String licenseNumber) {
this.licenseNumber = licenseNumber;
}
public Date getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
}
public String getTestTransient() {
return testTransient;
}
public void setTestTransient(String testTransient) {
this.testTransient = testTransient;
}
public VehicleLease getLease() {
return lease;
}
public void setLease(VehicleLease lease) {
this.lease = lease;
}
}
@@ -0,0 +1,56 @@
package org.tests.model.basic;
import org.tests.model.BaseModel;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.util.Date;
@Entity
public class VehicleDriver extends BaseModel {
private static final long serialVersionUID = 1L;
private String name;
@ManyToOne(optional = true)
private Vehicle vehicle;
@ManyToOne(optional = true)
private Address address;
private Date licenseIssuedOn;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Vehicle getVehicle() {
return vehicle;
}
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Date getLicenseIssuedOn() {
return licenseIssuedOn;
}
public void setLicenseIssuedOn(Date licenseIssuedOn) {
this.licenseIssuedOn = licenseIssuedOn;
}
}
@@ -0,0 +1,64 @@
package org.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.Version;
import java.time.LocalDate;
@Entity
@Inheritance
public abstract class VehicleLease {
@Id
long id;
String name;
LocalDate activeStart;
LocalDate activeEnd;
@Version
long version;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getActiveStart() {
return activeStart;
}
public void setActiveStart(LocalDate activeStart) {
this.activeStart = activeStart;
}
public LocalDate getActiveEnd() {
return activeEnd;
}
public void setActiveEnd(LocalDate activeEnd) {
this.activeEnd = activeEnd;
}
}
@@ -0,0 +1,32 @@
package org.tests.model.basic;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import java.math.BigDecimal;
@Entity
@Inheritance
@DiscriminatorValue("LONG")
public class VehicleLeaseLong extends VehicleLease {
BigDecimal bond;
int minDuration;
public BigDecimal getBond() {
return bond;
}
public void setBond(BigDecimal bond) {
this.bond = bond;
}
public int getMinDuration() {
return minDuration;
}
public void setMinDuration(int minDuration) {
this.minDuration = minDuration;
}
}
@@ -0,0 +1,33 @@
package org.tests.model.basic;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import java.math.BigDecimal;
@Entity
@Inheritance
@DiscriminatorValue("SHORT")
public class VehicleLeaseShort extends VehicleLease {
BigDecimal dayRate;
Integer maxDays;
public BigDecimal getDayRate() {
return dayRate;
}
public void setDayRate(BigDecimal dayRate) {
this.dayRate = dayRate;
}
public Integer getMaxDays() {
return maxDays;
}
public void setMaxDays(Integer maxDays) {
this.maxDays = maxDays;
}
}
@@ -0,0 +1,49 @@
package org.tests.model.compositekeys;
import javax.persistence.Embeddable;
import java.util.Date;
@Embeddable
public class AuditInfo {
private Date lastUpdated;
private Date created;
private String updatedBy;
private String createdBy;
public AuditInfo() {
created = new Date();
createdBy = "dummy";
}
public Date getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
}
@@ -0,0 +1,112 @@
package org.tests.model.compositekeys;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Version;
@Entity
public class Item {
@Id
private ItemKey key;
private String description;
private String units;
private int type;
private int region;
@Embedded
@AttributeOverride(name = "lastUpdated", column = @Column(name = "date_modified"))
@AttributeOverride(name = "created", column = @Column(name = "date_created"))
@AttributeOverride(name = "updatedBy", column = @Column(name = "modified_by"))
@AttributeOverride(name = "createdBy", column = @Column(name = "created_by"))
private AuditInfo auditInfo = new AuditInfo();
@Version
private Long version;
@ManyToOne
@JoinColumn(name = "customer", referencedColumnName = "customer", insertable = false, updatable = false)
@JoinColumn(name = "type", referencedColumnName = "type", insertable = false, updatable = false)
private Type eType;
@ManyToOne
@JoinColumn(name = "customer", referencedColumnName = "customer", insertable = false, updatable = false)
@JoinColumn(name = "region", referencedColumnName = "type", insertable = false, updatable = false)
private Region eRegion;
public ItemKey getKey() {
return key;
}
public void setKey(ItemKey key) {
this.key = key;
}
public String getUnits() {
return units;
}
public void setUnits(String units) {
this.units = units;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getRegion() {
return region;
}
public void setRegion(int region) {
this.region = region;
}
public Long getVersion() {
return version;
}
public Type getEType() {
return eType;
}
public Region getERegion() {
return eRegion;
}
public void setVersion(Long version) {
this.version = version;
}
public void setEType(Type eType) {
this.eType = eType;
}
public void setERegion(Region eRegion) {
this.eRegion = eRegion;
}
public AuditInfo getAuditInfo() {
return auditInfo;
}
}
@@ -0,0 +1,60 @@
package org.tests.model.compositekeys;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.validation.constraints.Size;
@Embeddable
public class ItemKey {
private int customer;
@Column(name = "itemnumber")
@Size(max = 127)
private String itemNumber;
public int getCustomer() {
return customer;
}
public void setCustomer(int customer) {
this.customer = customer;
}
public String getItemNumber() {
return itemNumber;
}
public void setItemNumber(String itemNumber) {
this.itemNumber = itemNumber;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ItemKey)) {
return false;
}
ItemKey itemKey = (ItemKey) o;
if (customer != itemKey.customer) {
return false;
}
if (!itemNumber.equals(itemKey.itemNumber)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = customer;
result = 31 * result + itemNumber.hashCode();
return result;
}
}
@@ -0,0 +1,30 @@
package org.tests.model.compositekeys;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Parcel {
@Id
@Column(name = "parcelid")
private Long parcelId;
private String description;
public Long getParcelId() {
return parcelId;
}
public void setParcelId(Long parcelId) {
this.parcelId = parcelId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
@@ -0,0 +1,45 @@
package org.tests.model.compositekeys;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
@Entity
public class ParcelLocation {
@Id
@Column(name = "parcellocid")
private Long parcelLocId;
private String location;
@OneToOne
@JoinColumn(name = "parcelid", referencedColumnName = "parcelid")
private Parcel parcel;
public Long getParcelLocId() {
return parcelLocId;
}
public void setParcelLocId(Long parcelLocId) {
this.parcelLocId = parcelLocId;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Parcel getParcel() {
return parcel;
}
public void setParcel(Parcel parcel) {
this.parcel = parcel;
}
}
@@ -0,0 +1,55 @@
package org.tests.model.compositekeys;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import java.util.List;
@Entity
public class Region {
@Id
private RegionKey key;
private String description;
@Version
private Long version;
@OneToMany
@JoinColumns({
@JoinColumn(name = "customer", referencedColumnName = "customer", insertable = false, updatable = false),
@JoinColumn(name = "region", referencedColumnName = "type", insertable = false, updatable = false)
})
private List<Item> items;
public RegionKey getKey() {
return key;
}
public void setKey(RegionKey key) {
this.key = key;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public List<Item> getItems() {
return items;
}
}
@@ -0,0 +1,45 @@
package org.tests.model.compositekeys;
import javax.persistence.Embeddable;
@Embeddable
public class RegionKey {
private int customer;
private int type;
public int getCustomer() {
return customer;
}
public void setCustomer(int customer) {
this.customer = customer;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public int hashCode() {
int hc = 31 * 7 + customer;
hc = 31 * hc + type;
return hc;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof RegionKey) {
RegionKey k = (RegionKey) o;
return k.customer == customer && k.type == type;
}
return false;
}
}
@@ -0,0 +1,45 @@
package org.tests.model.compositekeys;
import io.ebean.annotation.Identity;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Version;
import static io.ebean.annotation.IdentityGenerated.BY_DEFAULT;
@Identity(generated = BY_DEFAULT)
@Entity
public class SubType {
@EmbeddedId
private SubTypeKey key;
private String description;
@Version
private Long version;
public SubTypeKey getKey() {
return key;
}
public void setKey(SubTypeKey key) {
this.key = key;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
}
@@ -0,0 +1,33 @@
package org.tests.model.compositekeys;
import javax.persistence.Embeddable;
@Embeddable
public class SubTypeKey {
private int subTypeId;
public int getSubTypeId() {
return subTypeId;
}
public void setSubTypeId(int subTypeId) {
this.subTypeId = subTypeId;
}
@Override
public int hashCode() {
return 31 * 7 + subTypeId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof SubTypeKey)) {
return false;
}
return subTypeId == ((SubTypeKey) o).subTypeId;
}
}
@@ -0,0 +1,69 @@
package org.tests.model.compositekeys;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import java.util.List;
@Entity
@Table(name="`type`") // needs to be quoted because it's a keyword on HANA
public class Type {
@Id
private TypeKey key;
private String description;
@Version
private Long version;
@OneToMany
@JoinColumns({
@JoinColumn(name = "customer", referencedColumnName = "customer", insertable = false, updatable = false),
@JoinColumn(name = "type", referencedColumnName = "type", insertable = false, updatable = false)
})
private List<Item> items;
@ManyToOne
private SubType subType;
public TypeKey getKey() {
return key;
}
public void setKey(TypeKey key) {
this.key = key;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public List<Item> getItems() {
return items;
}
public SubType getSubType() {
return subType;
}
public void setSubType(SubType subType) {
this.subType = subType;
}
}
@@ -0,0 +1,45 @@
package org.tests.model.compositekeys;
import javax.persistence.Embeddable;
@Embeddable
public class TypeKey {
private int customer;
private int type;
public int getCustomer() {
return customer;
}
public void setCustomer(int customer) {
this.customer = customer;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public int hashCode() {
int hc = 31 + customer;
hc = hc * 31 + type;
return hc;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof TypeKey) {
TypeKey k = (TypeKey) o;
return k.customer == customer && k.type == type;
}
return false;
}
}
@@ -0,0 +1,66 @@
package org.tests.model.converstation;
import io.ebean.annotation.FetchPreference;
import org.tests.model.BaseModel;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;
@Entity
@Table(name = "c_conversation")
public class Conversation extends BaseModel {
String title;
@Column(name = "isopen")
boolean open;
@ManyToOne
Group group;
@FetchPreference(1)
@OneToMany(mappedBy = "conversation")
List<Participation> participants;
@FetchPreference(2)
@OneToMany(mappedBy = "conversation")
List<Message> messages;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public boolean isOpen() {
return open;
}
public void setOpen(boolean open) {
this.open = open;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public List<Message> getMessages() {
return messages;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
}
@@ -0,0 +1,45 @@
package org.tests.model.converstation;
import org.tests.model.BaseModel;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;
@Entity
@Table(name = "c_group")
public class Group extends BaseModel {
boolean inactive;
String name;
@OneToMany(mappedBy = "group")
List<User> users;
public boolean isInactive() {
return inactive;
}
public void setInactive(boolean inactive) {
this.inactive = inactive;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
}
@@ -0,0 +1,56 @@
package org.tests.model.converstation;
import org.tests.model.BaseModel;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "c_message")
public class Message extends BaseModel {
String title;
String body;
@ManyToOne
Conversation conversation;
@ManyToOne
User user;
public Conversation getConversation() {
return conversation;
}
public void setConversation(Conversation conversation) {
this.conversation = conversation;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
@@ -0,0 +1,60 @@
package org.tests.model.converstation;
import org.tests.model.BaseModel;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "c_participation")
public class Participation extends BaseModel {
public enum Type {
Moderator,
Member
}
Integer rating;
Type type;
@ManyToOne(optional = false)
Conversation conversation;
@ManyToOne(optional = false)
User user;
public Conversation getConversation() {
return conversation;
}
public void setConversation(Conversation conversation) {
this.conversation = conversation;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public Integer getRating() {
return rating;
}
public void setRating(Integer rating) {
this.rating = rating;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
@@ -0,0 +1,71 @@
package org.tests.model.converstation;
import io.ebean.annotation.History;
import io.ebean.annotation.HistoryExclude;
import org.tests.model.BaseModel;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@History
@Entity
@Table(name = "c_user")
public class User extends BaseModel {
boolean inactive;
String name;
String email;
@HistoryExclude
String passwordHash;
@ManyToOne
Group group;
public User() {
}
public boolean isInactive() {
return inactive;
}
public void setInactive(boolean inactive) {
this.inactive = inactive;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public String getPasswordHash() {
return passwordHash;
}
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
}
@@ -0,0 +1,20 @@
package org.tests.model.metaannotation;
import javax.validation.constraints.Size;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Meta-Annotation that defines &#64;Size(max=100)
*
* @author Roland Praml, FOCONIS AG
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Size(max = 100)
public @interface SizeMedium {
}