initial add of EbeanORM server based on v2.8.1

This commit is contained in:
rbygrave
2012-09-14 00:40:39 +12:00
parent 2b74d0f9d9
commit 96ce4c0ddf
1188 changed files with 135034 additions and 0 deletions
@@ -0,0 +1,146 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import com.avaje.ebean.validation.Length;
/**
* Address entity bean.
*/
@Entity
@Table(name="o_address")
public class Address {
@Id
Short id;
@Length(max=100)
@Column(name="line_1")
String line1;
@Length(max=100)
@Column(name="line_2")
String line2;
@Length(max=100)
String city;
Timestamp cretime;
@Version
Timestamp updtime;
@ManyToOne
Country country;
public String toString() {
return id+" "+line1+" "+line2+" "+city+" "+country;
}
/**
* Return id.
*/
public Short getId() {
return id;
}
/**
* Set id.
*/
public void setId(Short 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;
}
/**
* Return country.
*/
public Country getCountry() {
return country;
}
/**
* Set country.
*/
public void setCountry(Country country) {
this.country = country;
}
}
@@ -0,0 +1,66 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import com.avaje.ebean.annotation.CacheStrategy;
@CacheStrategy(useBeanCache=true, warmingQuery="find article join sections")
@Entity
public class Article extends BasicDomain {
private static final long serialVersionUID = 1L;
String name;
String author;
@OneToMany(cascade=CascadeType.ALL)
List<Section> sections;
public Article() {
}
public Article(String name, String author) {
this.name = name;
this.author = author;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public List<Section> getSections() {
return sections;
}
public void setSections(List<Section> sections) {
this.sections = sections;
}
public void addSection(Section s){
if (sections == null){
sections = new ArrayList<Section>();
}
sections.add(s);
}
}
@@ -0,0 +1,30 @@
package com.avaje.tests.model.basic;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.ManyToOne;
@Entity
@Inheritance()
@DiscriminatorColumn(name = "option_type", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
public class Attribute extends BasicDomain{
private static final long serialVersionUID = 1L;
@ManyToOne
private AttributeHolder attributeHolder;
public AttributeHolder getAttributeHolder() {
return attributeHolder;
}
public void setAttributeHolder(AttributeHolder attributeHolder) {
this.attributeHolder = attributeHolder;
}
}
@@ -0,0 +1,29 @@
package com.avaje.tests.model.basic;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
@Entity
public class AttributeHolder extends BasicDomain{
private static final long serialVersionUID = 1L;
@OneToMany(mappedBy="attributeHolder", cascade={CascadeType.PERSIST})
private Set<Attribute> attributes;// = new HashSet<Attribute>();
public Set<Attribute> getAttributes() {
return attributes;
}
public void setAttributes(Set<Attribute> attributes) {
this.attributes = attributes;
}
public void add(Attribute attribute){
getAttributes().add(attribute);
attribute.setAttributeHolder(this);
}
}
@@ -0,0 +1,74 @@
package com.avaje.tests.model.basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
/**
* A user may have multiple bookmarks
*
* @author Chris
*
*/
@Entity
public class BBookmark {
@Id
@GeneratedValue
private Integer id;
@Column
private String bookmarkReference;
@ManyToOne(cascade = CascadeType.PERSIST)
@Column
private BBookmarkUser user;
/**
* @return the id
*/
public Integer getId() {
return this.id;
}
/**
* @param id
* the id to set
*/
public void setId(final Integer id) {
this.id = id;
}
/**
* @return the bookmarkReference
*/
public String getBookmarkReference() {
return this.bookmarkReference;
}
/**
* @param bookmarkReference
* the bookmarkReference to set
*/
public void setBookmarkReference(final String bookmarkReference) {
this.bookmarkReference = bookmarkReference;
}
/**
* @return the user
*/
public BBookmarkUser getUser() {
return this.user;
}
/**
* @param user
* the user to set
*/
public void setUser(final BBookmarkUser user) {
this.user = user;
}
}
@@ -0,0 +1,119 @@
package com.avaje.tests.model.basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* represents a user entity. A user contains a username and password.
*
* @author Chris
*
*/
@Entity
public class BBookmarkUser {
@Id
@GeneratedValue
private Integer id;
@Column
private String name;
@Column
private String password;
@Column
private String emailAddress;
@Column
private String country;
// @Version
// private Timestamp lastUpdate;
/**
* @return the id
*/
public Integer getId() {
return this.id;
}
/**
* @param id
* the id to set
*/
public void setId(final Integer id) {
this.id = id;
}
/**
* @return the password
*/
public String getPassword() {
return this.password;
}
/**
* @param password
* the password to set
*/
public void setPassword(final String password) {
this.password = password;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @param name
* the name to set
*/
public void setName(final String name) {
this.name = name;
}
/**
* @return the emailAddress
*/
public String getEmailAddress() {
return this.emailAddress;
}
/**
* @param emailAddress
* the emailAddress to set
*/
public void setEmailAddress(final String emailAddress) {
this.emailAddress = emailAddress;
}
/**
* @return the country
*/
public String getCountry() {
return this.country;
}
/**
* @param country
* the country to set
*/
public void setCountry(final String country) {
this.country = country;
}
// public Timestamp getLastUpdate() {
// return lastUpdate;
// }
//
// public void setLastUpdate(Timestamp lastUpdate) {
// this.lastUpdate = lastUpdate;
// }
}
@@ -0,0 +1,46 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
@Entity
public class BWithQIdent {
@Id
Integer id;
@Column(name="`Name`", unique=true)
String name;
@Version
Timestamp lastUpdated;
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 Timestamp getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Timestamp lastUpdated) {
this.lastUpdated = lastUpdated;
}
}
@@ -0,0 +1,49 @@
package com.avaje.tests.model.basic;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import com.avaje.ebean.annotation.CreatedTimestamp;
@MappedSuperclass
public class BasicDomain implements Serializable {
private static final long serialVersionUID = 5569496199004449769L;
@Id
Integer id;
@CreatedTimestamp
Timestamp cretime;
@Version
Timestamp updtime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Timestamp getUpdtime() {
return updtime;
}
public void setUpdtime(Timestamp updtime) {
this.updtime = updtime;
}
public Timestamp getCretime() {
return cretime;
}
public void setCretime(Timestamp cretime) {
this.cretime = cretime;
}
}
@@ -0,0 +1,30 @@
package com.avaje.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,73 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.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,96 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Version;
@Entity
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<CKeyDetail>();
}
details.add(detail);
}
}
@@ -0,0 +1,71 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Embeddable;
@Embeddable
public class CKeyParentId {
Integer oneKey;
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,51 @@
package com.avaje.tests.model.basic;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@Entity
@Inheritance
@DiscriminatorValue("C")
public class Car extends Vehicle {
private static final long serialVersionUID = 4716705779684333446L;
private String driver;
@ManyToOne
TruckRef carRef;
@OneToMany(mappedBy="car")
private Set<CarAccessory> accessories = new HashSet<CarAccessory>();
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public TruckRef getCarRef() {
return carRef;
}
public void setCarRef(TruckRef carRef) {
this.carRef = carRef;
}
public Set<CarAccessory> getAccessories() {
return accessories;
}
public void setAccessories(Set<CarAccessory> accessories) {
this.accessories = accessories;
}
}
@@ -0,0 +1,31 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
@Entity
public class CarAccessory extends BasicDomain{
private static final long serialVersionUID = 1L;
private String name;
@ManyToOne
private Car car;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
}
@@ -0,0 +1,144 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import com.avaje.ebean.annotation.CacheStrategy;
import com.avaje.ebean.annotation.CreatedTimestamp;
@Entity
@CacheStrategy(useBeanCache=true,naturalKey="email")
public class Contact {
private static final long serialVersionUID = 1L;
@Id
int id;
String firstName;
String lastName;
String phone;
String mobile;
String email;
@ManyToOne
Customer customer;
@ManyToOne(optional=true)
ContactGroup group;
@OneToMany
List<ContactNote> notes;
@CreatedTimestamp
Timestamp cretime;
@Version
Timestamp updtime;
public Contact(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public Contact() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Timestamp getUpdtime() {
return updtime;
}
public void setUpdtime(Timestamp updtime) {
this.updtime = updtime;
}
public Timestamp getCretime() {
return cretime;
}
public void setCretime(Timestamp cretime) {
this.cretime = cretime;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public ContactGroup getGroup() {
return group;
}
public void setGroup(ContactGroup group) {
this.group = group;
}
public List<ContactNote> getNotes() {
return notes;
}
public void setNotes(List<ContactNote> notes) {
this.notes = notes;
}
}
@@ -0,0 +1,20 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
@Entity
public class ContactGroup extends BasicDomain {
private static final long serialVersionUID = -5447111032760796085L;
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,63 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
@Entity
public class ContactNote extends BasicDomain {
private static final long serialVersionUID = 7949702621226333278L;
@ManyToOne
Contact contact;
String title;
@Lob
String note;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
}
@@ -0,0 +1,60 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.avaje.ebean.annotation.CacheStrategy;
import com.avaje.ebean.annotation.CacheTuning;
import com.avaje.ebean.validation.Length;
/**
* Country entity bean.
*/
@CacheStrategy(readOnly=true,warmingQuery="order by name")
@CacheTuning(maxSize=500)
@Entity
@Table(name="o_country")
public class Country {
@Id
@Length(max=2)
String code;
@Length(max=60)
String name;
public String toString() {
return code;
}
/**
* Return code.
*/
public String getCode() {
return code;
}
/**
* Set code.
*/
public void setCode(String code) {
this.code = code;
}
/**
* Return name.
*/
public String getName() {
return name;
}
/**
* Set name.
*/
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,187 @@
package com.avaje.tests.model.basic;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.avaje.ebean.annotation.EnumMapping;
import com.avaje.ebean.annotation.Where;
import com.avaje.ebean.validation.Length;
import com.avaje.ebean.validation.NotNull;
/**
* Customer entity bean.
*/
@Entity
@Table(name="o_customer")
//@UpdateMode(updateChangesOnly=false)
public class Customer extends BasicDomain {
private static final long serialVersionUID = 1L;
/**
* EnumMapping is an Ebean specific mapping for enums.
*/
@EnumMapping(nameValuePairs="NEW=N,ACTIVE=A,INACTIVE=I")
public enum Status {
NEW,
ACTIVE,
INACTIVE
}
@Transient
Boolean selected;
@Transient
ReentrantLock lock = new ReentrantLock();
Status status;
@NotNull
@Length(max=40)
//@Column(length=39,nullable=false)
String name;
@Length(max=100)
String smallnote;
Date anniversary;
@ManyToOne(cascade=CascadeType.ALL)
Address billingAddress;
@ManyToOne(cascade=CascadeType.ALL)
Address shippingAddress;
@OneToMany(mappedBy="customer")
@Where(clause="${ta}.order_date is not null")
List<Order> orders;
@OneToMany(mappedBy="customer", cascade=CascadeType.ALL)
List<Contact> contacts;
public String toString() {
return id+" "+status+" "+name;
}
/**
* Return name.
*/
public String getName() {
return name;
}
/**
* Set name.
*/
public void setName(String name) {
this.name = name;
}
/**
* Return billing address.
*/
public Address getBillingAddress() {
return billingAddress;
}
/**
* Set billing address.
*/
public void setBillingAddress(Address billingAddress) {
this.billingAddress = billingAddress;
}
/**
* Return status.
*/
public Status getStatus() {
return status;
}
/**
* Set status.
*/
public void setStatus(Status status) {
this.status = status;
}
/**
* Return shipping address.
*/
public Address getShippingAddress() {
return shippingAddress;
}
/**
* Set shipping address.
*/
public void setShippingAddress(Address shippingAddress) {
this.shippingAddress = shippingAddress;
}
/**
* Return orders.
*/
public List<Order> getOrders() {
return orders;
}
/**
* Set orders.
*/
public void setOrders(List<Order> orders) {
this.orders = orders;
}
public Boolean getSelected() {
return selected;
}
public void setSelected(Boolean selected) {
this.selected = selected;
}
public ReentrantLock getLock() {
return lock;
}
public String getSmallnote() {
return smallnote;
}
public void setSmallnote(String smallnote) {
this.smallnote = smallnote;
}
public Date getAnniversary() {
return anniversary;
}
public void setAnniversary(Date anniversary) {
this.anniversary = anniversary;
}
public List<Contact> getContacts() {
return contacts;
}
public void setContacts(List<Contact> contacts) {
this.contacts = contacts;
}
public void addContact(Contact contact){
if (contacts == null){
contacts = new ArrayList<Contact>();
}
contacts.add(contact);
}
}
@@ -0,0 +1,48 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import com.avaje.ebean.annotation.Sql;
/**
* An example of an Aggregate object.
* <p>
* Note the &#064;Sql indicates to Ebean that this bean is not based on a table but
* instead uses RawSql.
* </p>
*/
@Entity
@Sql
public class CustomerAggregate {
@OneToOne
Customer customer;
int totalContacts;
public String toString() {
return customer.getId() + " totalContacts:" + totalContacts;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public int getTotalContacts() {
return totalContacts;
}
public void setTotalContacts(int totalContacts) {
this.totalContacts = totalContacts;
}
}
@@ -0,0 +1,60 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.avaje.ebean.Ebean;
public class DMLTest extends TestCase {
public DMLTest() {
}
public static void main(String[] args) {
DMLTest dmlTest = new DMLTest();
dmlTest.deleteAll();
dmlTest.insertData();
}
public void test() {
Assert.assertTrue(true);
}
public void deleteAll() {
Ebean.beginTransaction();
try {
Ebean.createUpdate(Phone.class, "delete from phone").execute();
Ebean.createUpdate(Person.class, "delete from person").execute();
Ebean.commitTransaction();
} finally {
Ebean.endTransaction();
}
}
private void insertData() {
Person person = new Person();
person.setSurname("Kosinov");
person.setName("Yaroslav");
Phone phone = new Phone();
phone.setPhoneNumber("5244011");
List<Phone> phones = new ArrayList<Phone>();
phones.add(phone);
person.setPhones(phones);
Ebean.save(person);
person = new Person();
person.setSurname("Kosinov");
person.setName("Gennady");
phone = new Phone();
phone.setPhoneNumber("5712658");
phone.setPerson(person);
Ebean.save(phone);
}
}
@@ -0,0 +1,65 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.avaje.ebean.annotation.EnumValue;
@Entity
@Table(name="e_basic")
public class EBasic {
public enum Status {
@EnumValue("N")
NEW,
@EnumValue("A")
ACTIVE,
@EnumValue("I")
INACTIVE,
}
@Id
Integer id;
Status status;
String name;
String description;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
@@ -0,0 +1,67 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Version;
@Entity
public class EBasicClob {
@Id
private Long id;
private String name;
private String title;
@Lob
private String description;
@Version
private Timestamp lastUpdate;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Timestamp getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
}
@@ -0,0 +1,41 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
@Entity
public class EBasicClobNoVer {
@Id
private Long id;
private String name;
@Lob
private String description;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
@@ -0,0 +1,71 @@
package com.avaje.tests.model.basic;
import java.sql.Date;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.avaje.ebean.annotation.Encrypted;
@Entity
@Table(name="e_basicenc")
public class EBasicEncrypt {
@Id
Integer id;
String name;
//@Lob
@Encrypted(dbLength=80)
String description;
@Encrypted(dbLength=20)
Date dob;
//@Version
Timestamp lastUpdate;
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 Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Timestamp getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
}
@@ -0,0 +1,81 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Version;
import com.avaje.ebean.annotation.Encrypted;
@Entity
@Table(name="e_basicenc_bin")
public class EBasicEncryptBinary {
@Id
Integer id;
String name;
String description;
@Encrypted
@Lob
byte[] data;
@Encrypted
Timestamp someTime;
@Version
Timestamp lastUpdate;
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
public Timestamp getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
public Timestamp getSomeTime() {
return someTime;
}
public void setSomeTime(Timestamp someTime) {
this.someTime = someTime;
}
}
@@ -0,0 +1,40 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "e_basic_ndc")
public class EBasicNoDefaultConstructor {
@Id
Integer id;
String name;
public EBasicNoDefaultConstructor() {
}
public EBasicNoDefaultConstructor(Integer id, String name) {
this.id = id;
this.name = name;
}
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;
}
}
@@ -0,0 +1,56 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name="e_basicver")
public class EBasicVer {
@Id
Integer id;
String name;
String description;
@Version
Timestamp lastUpdate;
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Timestamp getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
}
@@ -0,0 +1,78 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
@Entity
@Table(name="e_basicverucon")
@UniqueConstraint(columnNames={"other","other_one"})
public class EBasicWithUniqueCon {
@Id
Integer id;
@Column(unique=true)
String name;
String other;
String otherOne;
String description;
@Version
Timestamp lastUpdate;
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 String getOther() {
return other;
}
public void setOther(String other) {
this.other = other;
}
public String getOtherOne() {
return otherOne;
}
public void setOtherOne(String otherOne) {
this.otherOne = otherOne;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Timestamp getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Timestamp lastUpdate) {
this.lastUpdate = lastUpdate;
}
}
@@ -0,0 +1,37 @@
package com.avaje.tests.model.basic;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class ENullCollection {
@Id
Integer id;
@OneToMany(cascade=CascadeType.PERSIST)
List<ENullCollectionDetail> details;
public ENullCollection() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public List<ENullCollectionDetail> getDetails() {
return details;
}
public void setDetails(List<ENullCollectionDetail> details) {
this.details = details;
}
}
@@ -0,0 +1,33 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class ENullCollectionDetail {
@Id
Integer id;
String something;
public ENullCollectionDetail() {
}
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,33 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
@Entity
public class EOptOneA extends BasicDomain {
private static final long serialVersionUID = 1L;
String nameForA;
@ManyToOne(optional=true)
EOptOneB b;
public String getNameForA() {
return nameForA;
}
public void setNameForA(String nameForA) {
this.nameForA = nameForA;
}
public EOptOneB getB() {
return b;
}
public void setB(EOptOneB b) {
this.b = b;
}
}
@@ -0,0 +1,32 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
@Entity
public class EOptOneB extends BasicDomain {
private static final long serialVersionUID = 1L;
String nameForB;
@ManyToOne(optional=false)
EOptOneC c;
public String getNameForB() {
return nameForB;
}
public void setNameForB(String nameForA) {
this.nameForB = nameForA;
}
public EOptOneC getC() {
return c;
}
public void setC(EOptOneC c) {
this.c = c;
}
}
@@ -0,0 +1,20 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
@Entity
public class EOptOneC extends BasicDomain {
private static final long serialVersionUID = 1L;
String nameForC;
public String getNameForC() {
return nameForC;
}
public void setNameForC(String nameForA) {
this.nameForC = nameForA;
}
}
@@ -0,0 +1,36 @@
package com.avaje.tests.model.basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class ESimple {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "usertypeid", unique = true, nullable = false)
private Integer id;
private String name;
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;
}
}
@@ -0,0 +1,58 @@
package com.avaje.tests.model.basic;
import java.util.Currency;
import java.util.Locale;
import java.util.TimeZone;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class ESomeType {
@Id
Integer id;
Currency currency;
Locale locale;
TimeZone timeZone;
public String toString() {
return id+" "+locale+" "+currency+" "+timeZone;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Currency getCurrency() {
return currency;
}
public void setCurrency(Currency currency) {
this.currency = currency;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public TimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(TimeZone timeZone) {
this.timeZone = timeZone;
}
}
@@ -0,0 +1,44 @@
package com.avaje.tests.model.basic;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
@Entity
public class ETransMany {
@Id
Integer id;
String name;
@Transient
Map<String,String> transMap;
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 Map<String, String> getTransMap() {
return transMap;
}
public void setTransMap(Map<String, String> transMap) {
this.transMap = transMap;
}
}
@@ -0,0 +1,40 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class EVanillaCollection {
@Id
Integer id;
@OneToMany(cascade=CascadeType.PERSIST)
List<EVanillaCollectionDetail> details;
public EVanillaCollection() {
details = new ArrayList<EVanillaCollectionDetail>();
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public List<EVanillaCollectionDetail> getDetails() {
return details;
}
public void setDetails(List<EVanillaCollectionDetail> details) {
this.details = details;
}
}
@@ -0,0 +1,33 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EVanillaCollectionDetail {
@Id
Integer id;
String something;
public EVanillaCollectionDetail() {
}
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,34 @@
package com.avaje.tests.model.basic;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
@Entity
@DiscriminatorValue("1")
public class ListAttribute extends Attribute {
private static final long serialVersionUID = 1L;
@ManyToMany(mappedBy="listAttributes", cascade={CascadeType.PERSIST})
private Set<ListAttributeValue> values;// = new HashSet<ListAttributeValue>();
// Do not define this as a HashSet so that it is left up to Ebean
// to define it as a BeanSet ... and hence aware of M2M modify changes
// Put this back to HashSet and Duplicate Key Exception will return
public Set<ListAttributeValue> getValues() {
return values;
}
public void setValues(Set<ListAttributeValue> values) {
this.values = values;
}
public void add(ListAttributeValue value){
getValues().add(value);
value.getListAttributes().add(this);
}
}
@@ -0,0 +1,34 @@
package com.avaje.tests.model.basic;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
@Entity
@Table(name="la_attr_value")
public class ListAttributeValue extends BasicDomain{
private static final long serialVersionUID = 1L;
private String name;
@ManyToMany
private Set<ListAttribute> listAttributes;
public Set<ListAttribute> getListAttributes() {
return listAttributes;
}
public void setListAttribute(Set<ListAttribute> listAttributes) {
this.listAttributes = listAttributes;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,8 @@
package com.avaje.tests.model.basic;
public enum MNonEnum {
BEGIN,
END
}
@@ -0,0 +1,57 @@
package com.avaje.tests.model.basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="non_updateprop")
public class MNonUpdPropEntity {
@Id
Integer id;
@Enumerated(EnumType.STRING)
MNonEnum nonEnum;
@Column(updatable=false)
String name;
String note;
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 String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public MNonEnum getNonEnum() {
return nonEnum;
}
public void setNonEnum(MNonEnum nonEnum) {
this.nonEnum = nonEnum;
}
}
@@ -0,0 +1,95 @@
package com.avaje.tests.model.basic;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
@Entity
public class MRole {
@Id
Integer roleid;
String roleName;
@ManyToMany(cascade=CascadeType.ALL
// @JoinTable(name="myint_table"//,
// joinColumns={
// @JoinColumn(name="mroleid", referencedColumnName="roleid")
// }//,
// inverseJoinColumns={
// @JoinColumn(name = "muserid", referencedColumnName="userid")
// }
)
List<MUser> users;
public MRole() {
}
public MRole(String roleName) {
this.roleName = roleName;
}
public Integer getRoleid() {
return roleid;
}
public void setRoleid(Integer roleid) {
this.roleid = roleid;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public List<MUser> getUsers() {
return users;
}
public void setUsers(List<MUser> users) {
this.users = users;
}
@Override
public String toString() {
return "MRole [roleName=" + roleName + "]";
}
@Override
public boolean equals(Object other) {
if (this == other){
return true;
}
// Make sure other is not null and has the same class as this
if (other != null && getClass().equals(other.getClass())){
final MRole rhs = (MRole)other;
if ( roleid.equals(rhs.roleid)){
if (roleid == 0){
return false;
}else{
return true;
}
}
}
return false;
}
@Override
public int hashCode() {
if (roleid != null && roleid != 0){
int rid = roleid;
return (int)( rid ^ (rid >>> 32) );
}
return super.hashCode();
}
}
@@ -0,0 +1,63 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
@Entity
public class MUser {
@Id
Integer userid;
String userName;
// Cascade remove will delete from intersection table
// but will not delete the actual Roles
@ManyToMany(mappedBy="users",cascade=CascadeType.ALL)
List<MRole> roles;
public MUser() {
}
public MUser(String userName) {
this.userName = userName;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public List<MRole> getRoles() {
return roles;
}
public void setRoles(List<MRole> roles) {
this.roles = roles;
}
public void addRole(MRole role){
if (roles == null){
roles = new ArrayList<MRole>();
}
roles.add(role);
}
}
@@ -0,0 +1,50 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
@Entity
public class MnocRole {
@Id
Integer roleId;
String roleName;
@Version
Integer version;
public MnocRole() {
}
public MnocRole(String roleName) {
this.roleName = roleName;
}
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
@@ -0,0 +1,73 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Version;
@Entity
public class MnocUser {
@Id
Integer userId;
String userName;
@Version
Integer version;
// No cascade REMOVE
@ManyToMany(cascade=CascadeType.PERSIST)
List<MnocRole> validRoles;
public MnocUser() {
}
public MnocUser(String userName) {
this.userName = userName;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer roleId) {
this.userId = roleId;
}
public String getUserName() {
return userName;
}
public void setUserName(String roleName) {
this.userName = roleName;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public List<MnocRole> getValidRoles() {
return validRoles;
}
public void setValidRoles(List<MnocRole> validRoles) {
this.validRoles = validRoles;
}
public void addValidRole(MnocRole role) {
if (validRoles == null){
validRoles = new ArrayList<MnocRole>();
}
validRoles.add(role);
}
}
@@ -0,0 +1,33 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import com.avaje.ebean.annotation.Sql;
@Entity
@Sql
public class MyAdHoc {
@ManyToOne
Order order;
int detailCount;
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public int getDetailCount() {
return detailCount;
}
public void setDetailCount(int detailCount) {
this.detailCount = detailCount;
}
}
@@ -0,0 +1,66 @@
package com.avaje.tests.model.basic;
import java.util.HashSet;
import java.util.Set;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.event.BeanPersistListener;
import com.avaje.ebean.event.BulkTableEvent;
import com.avaje.ebean.event.BulkTableEventListener;
import com.avaje.ebean.event.ServerConfigStartup;
public class MyEBasicConfigStartup implements ServerConfigStartup {
public void onStart(ServerConfig serverConfig) {
serverConfig.add(new EbasicPersistList());
serverConfig.add(new EbasicBulkListener());
}
public static class EbasicBulkListener implements BulkTableEventListener {
final Set<String> s = new HashSet<String>();
EbasicBulkListener() {
s.add("e_basic");
}
public Set<String> registeredTables() {
return s;
}
public void process(BulkTableEvent bulkTableEvent) {
System.out.println("-- "+bulkTableEvent);
}
}
public static class EbasicPersistList implements BeanPersistListener<EBasic> {
public boolean inserted(EBasic bean) {
System.out.println("-- EBasic inserted "+bean.getId());
return false;
}
public boolean updated(EBasic bean, Set<String> updatedProperties) {
System.out.println("-- EBasic updated "+bean.getId());
return false;
}
public boolean deleted(EBasic bean) {
System.out.println("-- EBasic deleted "+bean.getId());
return false;
}
public void remoteInsert(Object id) {
}
public void remoteUpdate(Object id) {
}
public void remoteDelete(Object id) {
}
}
}
@@ -0,0 +1,64 @@
package com.avaje.tests.model.basic;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
@Entity
public class MyLobSize {
@Id
Integer id;
String name;
@Basic(fetch=FetchType.LAZY)
int myCount;
@Basic(fetch=FetchType.LAZY)
@Lob
//@Length(max=65535)
//@Length(max=65536)
String myLob;
@OneToMany(mappedBy="parent")
List<MyLobSizeJoinMany> details;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getMyLob() {
return myLob;
}
public void setMyLob(String myLob) {
this.myLob = myLob;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMyCount() {
return myCount;
}
public void setMyCount(int myCount) {
this.myCount = myCount;
}
}
@@ -0,0 +1,56 @@
package com.avaje.tests.model.basic;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class MyLobSizeJoinMany {
@Id
Integer id;
@Basic(fetch=FetchType.LAZY)
String something;
String other;
@ManyToOne
MyLobSize parent;
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 String getOther() {
return other;
}
public void setOther(String other) {
this.other = other;
}
public MyLobSize getParent() {
return parent;
}
public void setParent(MyLobSize parent) {
this.parent = parent;
}
}
@@ -0,0 +1,31 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Entity;
@Entity
public class NoIdEntityType {
String name;
Timestamp someDateTime;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Timestamp getSomeDateTime() {
return someDateTime;
}
public void setSomeDateTime(Timestamp someDateTime) {
this.someDateTime = someDateTime;
}
}
@@ -0,0 +1,64 @@
package com.avaje.tests.model.basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
@Entity
public class OCar extends BasicDomain {
private static final long serialVersionUID = 1L;
private String vin;
private String name;
@OneToOne(mappedBy="car",cascade=CascadeType.ALL)
private OGearBox gearBox;
@OneToOne(mappedBy="car",cascade=CascadeType.ALL)
private OEngine engine;
public OCar() {
}
public OCar(String vin, String name) {
super();
this.vin = vin;
this.name = name;
}
public String getVin() {
return vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public OGearBox getGearBox() {
return gearBox;
}
public void setGearBox(OGearBox gearBox) {
this.gearBox = gearBox;
gearBox.setCar(this);
}
public OEngine getEngine() {
return engine;
}
public void setEngine(OEngine engine) {
this.engine = engine;
engine.setCar(this);
}
}
@@ -0,0 +1,62 @@
package com.avaje.tests.model.basic;
import java.util.UUID;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Version;
@Entity
public class OEngine {
private static final long serialVersionUID = 1L;
@Id
private UUID engineId;
private String shortDesc;
@Version
private Integer version;
@OneToOne
private OCar car;
public OEngine() {
}
public UUID getEngineId() {
return engineId;
}
public void setEngineId(UUID engineId) {
this.engineId = engineId;
}
public String getShortDesc() {
return shortDesc;
}
public void setShortDesc(String shortDesc) {
this.shortDesc = shortDesc;
}
public OCar getCar() {
return car;
}
public void setCar(OCar car) {
this.car = car;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
@@ -0,0 +1,73 @@
package com.avaje.tests.model.basic;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Version;
@Entity
public class OGearBox {
private static final long serialVersionUID = 1L;
@Id
private UUID id;
private String boxDesc;
@Column(name="box_size")
private Integer size;
@Version
private Integer version;
@OneToOne
private OCar car;
public OGearBox() {
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getBoxDesc() {
return boxDesc;
}
public void setBoxDesc(String boxDesc) {
this.boxDesc = boxDesc;
}
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
this.size = size;
}
public OCar getCar() {
return car;
}
public void setCar(OCar car) {
this.car = car;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
@@ -0,0 +1,270 @@
package com.avaje.tests.model.basic;
import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlType;
import com.avaje.ebean.annotation.CreatedTimestamp;
import com.avaje.ebean.annotation.Formula;
import com.avaje.ebean.annotation.Where;
import com.avaje.ebean.validation.NotNull;
/**
* Order entity bean.
*/
@Entity
@Table(name="o_order")
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
@XmlType(name="status")
public enum Status {
NEW,
APPROVED,
SHIPPED,
COMPLETE
}
public Order(){
}
@Id
Integer id;
/**
* Derived total amount from the order details. Needs to be explicitly included in query as Transient.
* Removing the Transient would mean by default it would be included in a order query.
* <p>
* NOTE: The join clause for totalAmount and totalItems is the same. If your query includes both
* totalAmount and totalItems only the one join is added to the query.
* </p>
*/
@Transient
@Formula(
select="z_b${ta}.total_amount",
join="join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id")
Double totalAmount;
/**
* Derived total item count from the order details. Needs to be explicitly included in query as Transient.
*/
@Transient
@Formula(
select="z_b${ta}.total_items",
join="join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id")
Integer totalItems;
@Enumerated(value=EnumType.ORDINAL)
Status status = Status.NEW;
Date orderDate = new Date(System.currentTimeMillis());
Date shipDate;
@NotNull
@ManyToOne
@JoinColumn(name="kcustomer_id")
Customer customer;
//@Basic(fetch=FetchType.LAZY)
@Column(name="name",table="o_customer")
String customerName;
@CreatedTimestamp
Timestamp cretime;
@Version
Timestamp updtime;
@Where(clause="${ta}.id > 0")
@OneToMany(cascade=CascadeType.ALL, mappedBy="order")
@OrderBy("id asc, orderQty asc, cretime desc")
List<OrderDetail> details;
@OneToMany(cascade=CascadeType.ALL, mappedBy="order")
List<OrderShipment> shipments;
public String toString() {
return id+" totalAmount:"+totalAmount+" totalItems:"+totalItems;
}
/**
* Return id.
*/
public Integer getId() {
return id;
}
/**
* Set id.
*/
public void setId(Integer id) {
this.id = id;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public Double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(Double totalAmount) {
this.totalAmount = totalAmount;
}
public Integer getTotalItems() {
return totalItems;
}
public void setTotalItems(Integer totalItems) {
this.totalItems = totalItems;
}
/**
* Return order date.
*/
public Date getOrderDate() {
return orderDate;
}
/**
* Set order date.
*/
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
/**
* Return ship date.
*/
public Date getShipDate() {
return shipDate;
}
/**
* Set ship date.
*/
public void setShipDate(Date shipDate) {
this.shipDate = shipDate;
}
/**
* 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;
}
/**
* Return status.
*/
public Status getStatus() {
return status;
}
/**
* Set status.
*/
public void setStatus(Status status) {
this.status = status;
}
/**
* Return customer.
*/
public Customer getCustomer() {
return customer;
}
/**
* Set customer.
*/
public void setCustomer(Customer customer) {
this.customer = customer;
}
/**
* Return details.
*/
public List<OrderDetail> getDetails() {
return details;
}
/**
* Set details.
*/
public void setDetails(List<OrderDetail> details) {
this.details = details;
}
public void addDetail(OrderDetail detail){
if (details == null){
details = new ArrayList<OrderDetail>();
}
details.add(detail);
}
public List<OrderShipment> getShipments() {
return shipments;
}
public void setShipments(List<OrderShipment> shipments) {
this.shipments = shipments;
}
public void addShipment(OrderShipment shipment){
if (shipments == null){
shipments = new ArrayList<OrderShipment>();
}
shipments.add(shipment);
}
}
@@ -0,0 +1,53 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import com.avaje.ebean.annotation.Sql;
/**
* An example of an Aggregate object.
* <p>
* Note the &#064;Sql indicates to Ebean that this bean is not based on a table but
* instead uses RawSql.
* </p>
*/
@Entity
@Sql
public class OrderAggregate {
@OneToOne
Order order;
Double totalAmount;
Double totalItems;
public String toString() {
return order.getId() + " totalAmount:" + totalAmount + " totalItems:" + totalItems;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public Double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(Double totalAmount) {
this.totalAmount = totalAmount;
}
public Double getTotalItems() {
return totalItems;
}
public void setTotalItems(Double totalItems) {
this.totalItems = totalItems;
}
}
@@ -0,0 +1,156 @@
package com.avaje.tests.model.basic;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
/**
* Order Detail entity bean.
*/
@Entity
@Table(name = "o_order_detail")
public class OrderDetail implements Serializable {
private static final long serialVersionUID = 1L;
@Id
Integer id;
@ManyToOne
Order order;
Integer orderQty;
Integer shipQty;
Double unitPrice;
@ManyToOne
Product product;
Timestamp cretime;
@Version
Timestamp updtime;
public OrderDetail() {
}
public OrderDetail(Product product, Integer orderQty, Double unitPrice) {
this.product = product;
this.orderQty = orderQty;
this.unitPrice = unitPrice;
}
/**
* Return id.
*/
public Integer getId() {
return id;
}
/**
* Set id.
*/
public void setId(Integer id) {
this.id = id;
}
/**
* Return order qty.
*/
public Integer getOrderQty() {
return orderQty;
}
/**
* Set order qty.
*/
public void setOrderQty(Integer orderQty) {
this.orderQty = orderQty;
}
/**
* Return ship qty.
*/
public Integer getShipQty() {
return shipQty;
}
/**
* Set ship qty.
*/
public void setShipQty(Integer shipQty) {
this.shipQty = shipQty;
}
public Double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Double unitPrice) {
this.unitPrice = unitPrice;
}
/**
* 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;
}
/**
* Return order.
*/
public Order getOrder() {
return order;
}
/**
* Set order.
*/
public void setOrder(Order order) {
this.order = order;
}
/**
* Return product.
*/
public Product getProduct() {
return product;
}
/**
* Set product.
*/
public void setProduct(Product product) {
this.product = product;
}
}
@@ -0,0 +1,36 @@
package com.avaje.tests.model.basic;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="or_order_ship")
public class OrderShipment extends BasicDomain {
private static final long serialVersionUID = 1L;
@ManyToOne
private Order order;
private Timestamp shipTime = new Timestamp(System.currentTimeMillis());
public Timestamp getShipTime() {
return shipTime;
}
public void setShipTime(Timestamp shipTime) {
this.shipTime = shipTime;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
}
@@ -0,0 +1,55 @@
package com.avaje.tests.model.basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
@Entity
public class PFile extends BasicDomain {
private static final long serialVersionUID = 1L;
private String name;
@OneToOne(cascade=CascadeType.ALL)
private PFileContent fileContent;
/** Another persistent file. */
@OneToOne(cascade=CascadeType.ALL)
private PFileContent fileContent2;
public PFile() {
}
public PFile(String name,PFileContent fileContent) {
super();
this.name = name;
this.fileContent = fileContent;
//this.persistentFileContent.setPersistentFile(this);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public PFileContent getFileContent() {
return fileContent;
}
public void setFileContent(PFileContent fileContent) {
this.fileContent = fileContent;
}
public PFileContent getFileContent2() {
return fileContent2;
}
public void setFileContent2(PFileContent fileContent2) {
this.fileContent2 = fileContent2;
}
}
@@ -0,0 +1,30 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Lob;
@Entity
public class PFileContent extends BasicDomain {
private static final long serialVersionUID = 1L;
/** The content. */
@Lob
private byte[] content;
public PFileContent(){
}
public PFileContent(byte[] content) {
super();
this.content = content;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
@@ -0,0 +1,45 @@
package com.avaje.tests.model.basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
@Entity
public class PersistentFile extends BasicDomain {
private static final long serialVersionUID = 1L;
private String name;
@OneToOne(mappedBy="persistentFile", cascade=CascadeType.ALL)
private PersistentFileContent persistentFileContent;
public PersistentFile() {
}
public PersistentFile(String name,
PersistentFileContent persistentFileContent) {
super();
this.name = name;
this.persistentFileContent = persistentFileContent;
this.persistentFileContent.setPersistentFile(this);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public PersistentFileContent getPersistentFileContent() {
return persistentFileContent;
}
public void setPersistentFileContent(PersistentFileContent persistentFileContent) {
this.persistentFileContent = persistentFileContent;
}
}
@@ -0,0 +1,44 @@
package com.avaje.tests.model.basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
@Entity
public class PersistentFileContent extends BasicDomain {
private static final long serialVersionUID = 1L;
/** The persistent file. */
@OneToOne(cascade=CascadeType.ALL)
private PersistentFile persistentFile;
/** The content. */
@Lob
private byte[] content;
public PersistentFileContent(){
}
public PersistentFileContent(byte[] content) {
super();
this.content = content;
}
public PersistentFile getPersistentFile() {
return persistentFile;
}
public void setPersistentFile(PersistentFile persistentFile) {
this.persistentFile = persistentFile;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
@@ -0,0 +1,67 @@
package com.avaje.tests.model.basic;
import java.io.Serializable;
import java.util.List;
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.Table;
@Entity(name = "Person")
@Table(name = "PERSONS")
public class Person implements Serializable {
private static final long serialVersionUID = 495045977245770183L;
private Long id;
private String surname;
private String name;
private List<Phone> phones;
public Person() {
}
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
@Column(name = "ID", unique = true, nullable = false)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "SURNAME", nullable = false, unique = false, columnDefinition = "varchar(64)")
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
@Column(name = "NAME", nullable = false, unique = false, columnDefinition = "varchar(64)")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(targetEntity = Phone.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "person")
public List<Phone> getPhones() {
return phones;
}
public void setPhones(List<Phone> phones) {
this.phones = phones;
}
}
@@ -0,0 +1,61 @@
package com.avaje.tests.model.basic;
import java.io.Serializable;
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 com.avaje.ebean.validation.NotNull;
@Entity(name = "Phone")
@Table(name = "PHONES")
public class Phone implements Serializable {
private static final long serialVersionUID = -326610269092956952L;
private Long id;
private String phoneNumber;
private Person person;
public Phone() {
}
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
@Column(name = "ID", unique = true, nullable = false)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "PHONE_NUMBER", nullable = false, unique = true, columnDefinition = "varchar(7)")
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@NotNull
@ManyToOne(targetEntity = Person.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "PERSON_ID", nullable = false)
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
@@ -0,0 +1,109 @@
package com.avaje.tests.model.basic;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
import com.avaje.ebean.annotation.CacheStrategy;
import com.avaje.ebean.annotation.CreatedTimestamp;
import com.avaje.ebean.validation.Length;
/**
* Product entity bean.
*/
@CacheStrategy(warmingQuery="order by name")
@Entity
@Table(name="o_product")
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
@Id
Integer id;
@Length(max=20)
String sku;
String name;
@CreatedTimestamp
Timestamp cretime;
@Version
Timestamp updtime;
/**
* Return id.
*/
public Integer getId() {
return id;
}
/**
* Set id.
*/
public void setId(Integer id) {
this.id = id;
}
/**
* Return sku.
*/
public String getSku() {
return sku;
}
/**
* Set sku.
*/
public void setSku(String sku) {
this.sku = sku;
}
/**
* Return name.
*/
public String getName() {
return name;
}
/**
* Set name.
*/
public void setName(String name) {
this.name = name;
}
/**
* 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,312 @@
package com.avaje.tests.model.basic;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.TxRunnable;
public class ResetBasicData {
private static boolean runOnce;
public static synchronized void reset() {
if (runOnce){
return;
}
final ResetBasicData me = new ResetBasicData();
Ebean.execute(new TxRunnable() {
public void run() {
me.deleteAll();
me.insertCountries();
me.insertProducts();
me.insertTestCustAndOrders();
}
});
runOnce = true;
}
public void deleteAll() {
Ebean.execute(new TxRunnable() {
public void run() {
//Ebean.currentTransaction().setBatchMode(false);
// orm update use bean name and bean properties
Ebean.createUpdate(OrderShipment.class, "delete from orderShipment")
.execute();
Ebean.createUpdate(OrderDetail.class, "delete from orderDetail")
.execute();
Ebean.createUpdate(Order.class,"delete from order")
.execute();
Ebean.createUpdate(Contact.class,"delete from contact")
.execute();
Ebean.createUpdate(Customer.class,"delete from Customer")
.execute();
Ebean.createUpdate(Address.class,"delete from address")
.execute();
// sql update uses table and column names
Ebean.createSqlUpdate("delete from o_country")
.execute();
Ebean.createSqlUpdate("delete from o_product")
.execute();
}
});
}
public void insertCountries() {
Ebean.execute(new TxRunnable() {
public void run() {
Country c = new Country();
c.setCode("NZ");
c.setName("New Zealand");
Ebean.save(c);
Country au = new Country();
au.setCode("AU");
au.setName("Australia");
Ebean.save(au);
}
});
}
public void insertProducts() {
Ebean.execute(new TxRunnable() {
public void run() {
Product p = new Product();
p.setId(1);
p.setName("Chair");
p.setSku("C001");
Ebean.save(p);
p = new Product();
p.setId(2);
p.setName("Desk");
p.setSku("DSK1");
Ebean.save(p);
p = new Product();
p.setId(3);
p.setName("Computer");
p.setSku("C002");
Ebean.save(p);
p = new Product();
p.setId(4);
p.setName("Printer");
p.setSku("C003");
Ebean.save(p);
}
});
}
public void insertTestCustAndOrders() {
Ebean.execute(new TxRunnable() {
public void run() {
Customer cust1 = insertCustomer("Rob");
Customer cust2 = insertCustomerNoAddress();
insertCustomerFiona();
insertCustomerNoContacts("NocCust");
createOrder1(cust1);
createOrder2(cust2);
createOrder3(cust1);
createOrder4(cust1);
}
});
}
public static Customer createCustAndOrder(String custName) {
ResetBasicData me = new ResetBasicData();
Customer cust1 = insertCustomer(custName);
me.createOrder1(cust1);
return cust1;
}
public static Order createOrderCustAndOrder(String custName) {
ResetBasicData me = new ResetBasicData();
Customer cust1 = insertCustomer(custName);
Order o = me.createOrder1(cust1);
return o;
}
private static int contactEmailNum = 1;
private Customer insertCustomerFiona() {
Customer c = createCustomer("Fiona", "12 Apple St", "West Coast Rd", 1, "2009-08-31");
c.setStatus(Customer.Status.ACTIVE);
c.addContact(createContact("Fiona","Black"));
c.addContact(createContact("Tracy","Red"));
Ebean.save(c);
return c;
}
public static Contact createContact(String firstName, String lastName) {
Contact contact = new Contact(firstName,lastName);
String email = contact.getLastName()+(contactEmailNum++)+"@test.com";
contact.setEmail(email.toLowerCase());
return contact;
}
private Customer insertCustomerNoContacts(String name) {
Customer c = createCustomer("Roger", "15 Kumera Way", "Bos town", 1, "2010-04-10");
c.setName(name);
c.setStatus(Customer.Status.ACTIVE);
Ebean.save(c);
return c;
}
private Customer insertCustomerNoAddress() {
Customer c = new Customer();
c.setName("Cust NoAddress");
c.setStatus(Customer.Status.NEW);
c.addContact(createContact("Jack","Black"));
Ebean.save(c);
return c;
}
private static Customer insertCustomer(String name) {
Customer c = createCustomer(name, "1 Banana St", "P.O.Box 1234", 1, null);
Ebean.save(c);
return c;
}
public static Customer createCustomer(String name, String shippingStreet, String billingStreet, int contactSuffix) {
return createCustomer(name, shippingStreet, billingStreet, contactSuffix, null);
}
public static Customer createCustomer(String name, String shippingStreet, String billingStreet, int contactSuffix, String annDate) {
Customer c = new Customer();
c.setName(name);
c.setStatus(Customer.Status.NEW);
if (annDate == null){
annDate = "2010-04-14";
}
c.setAnniversary(Date.valueOf(annDate));
if (contactSuffix > 0){
c.addContact(new Contact("Jim"+contactSuffix,"Cricket"));
c.addContact(new Contact("Fred"+contactSuffix,"Blue"));
c.addContact(new Contact("Bugs"+contactSuffix,"Bunny"));
}
if (shippingStreet != null){
Address shippingAddr = new Address();
shippingAddr.setLine1(shippingStreet);
shippingAddr.setLine2("Sandringham");
shippingAddr.setCity("Auckland");
shippingAddr.setCountry(Ebean.getReference(Country.class, "NZ"));
c.setShippingAddress(shippingAddr);
}
if (billingStreet != null){
Address billingAddr = new Address();
billingAddr.setLine1(billingStreet);
billingAddr.setLine2("St Lukes");
billingAddr.setCity("Auckland");
billingAddr.setCountry(Ebean.getReference(Country.class, "NZ"));
c.setBillingAddress(billingAddr);
}
return c;
}
private Order createOrder1(Customer customer) {
Product product1 = Ebean.getReference(Product.class, 1);
Product product2 = Ebean.getReference(Product.class, 2);
Product product3 = Ebean.getReference(Product.class, 3);
Order order = new Order();
order.setCustomer(customer);
List<OrderDetail> details = new ArrayList<OrderDetail>();
details.add(new OrderDetail(product1, 5, 10.50));
details.add(new OrderDetail(product2, 3, 1.10));
details.add(new OrderDetail(product3, 1, 2.00));
order.setDetails(details);
order.addShipment(new OrderShipment());
Ebean.save(order);
return order;
}
private void createOrder2(Customer customer) {
Product product1 = Ebean.getReference(Product.class, 1);
Order order = new Order();
order.setCustomer(customer);
List<OrderDetail> details = new ArrayList<OrderDetail>();
details.add(new OrderDetail(product1, 4, 10.50));
order.setDetails(details);
order.addShipment(new OrderShipment());
Ebean.save(order);
}
private void createOrder3(Customer customer) {
Product product1 = Ebean.getReference(Product.class, 1);
Product product3 = Ebean.getReference(Product.class, 3);
Order order = new Order();
order.setCustomer(customer);
List<OrderDetail> details = new ArrayList<OrderDetail>();
details.add(new OrderDetail(product1, 3, 10.50));
details.add(new OrderDetail(product3, 40, 2.10));
order.setDetails(details);
order.addShipment(new OrderShipment());
Ebean.save(order);
}
private void createOrder4(Customer customer) {
Order order = new Order();
order.setCustomer(customer);
order.addShipment(new OrderShipment());
Ebean.save(order);
}
}
@@ -0,0 +1,59 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import com.avaje.ebean.annotation.CacheStrategy;
@CacheStrategy(useBeanCache=true)
@Entity
public class Section extends BasicDomain {
private static final long serialVersionUID = 1L;
public enum Type {
GENERAL,
NOTE
}
@ManyToOne
Article article;
Type type = Type.GENERAL;
@Lob
String content;
public Section() {
}
public Section(String content) {
this.content = content;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Article getArticle() {
return article;
}
public void setArticle(Article article) {
this.article = article;
}
}
@@ -0,0 +1,22 @@
package com.avaje.tests.model.basic;
public class SomeObject {
String nonScalar;
Integer value;
public String getNonScalar() {
return nonScalar;
}
public void setNonScalar(String nonScalar) {
this.nonScalar = nonScalar;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
@@ -0,0 +1,35 @@
package com.avaje.tests.model.basic;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Lob;
@Entity
public class TBytesOnly {
@Id
Integer id;
@Lob
@Basic(fetch=FetchType.EAGER)
byte[] content;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
@@ -0,0 +1,24 @@
package com.avaje.tests.model.basic;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
@Entity
@Inheritance
@DiscriminatorValue("2")
public class TIntChild extends TIntRoot {
private static final long serialVersionUID = 1L;
String childProperty;
public String getChildProperty() {
return childProperty;
}
public void setChildProperty(String childProperty) {
this.childProperty = childProperty;
}
}
@@ -0,0 +1,37 @@
package com.avaje.tests.model.basic;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
@Entity
@Inheritance
@DiscriminatorColumn(name="my_type",length=3,discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorValue("1")
public class TIntRoot {
@Id
Integer id;
String name;
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;
}
}
@@ -0,0 +1,51 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.joda.time.LocalTime;
@Entity
public class TJodaEntity {
@Id
Integer id;
LocalTime localTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public LocalTime getLocalTime() {
return localTime;
}
public void setLocalTime(LocalTime localTime) {
this.localTime = localTime;
}
}
@@ -0,0 +1,37 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.avaje.ebean.annotation.UpdateMode;
@Entity
@Table(name="t_mapsuper1")
@UpdateMode(updateChangesOnly=true)
public class TMapSuperEntity extends TMappedSuper2 {
private static final long serialVersionUID = 1L;
@Id
Integer id;
String name;
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;
}
}
@@ -0,0 +1,55 @@
package com.avaje.tests.model.basic;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;
@MappedSuperclass
public class TMappedSuper2 {
String something;
@Version
int version;
@Transient
SomeObject someObject;
@Transient
Integer myint;
public String getSomething() {
return something;
}
public void setSomething(String something) {
this.something = something;
}
public SomeObject getSomeObject() {
return someObject;
}
public void setSomeObject(SomeObject someObject) {
this.someObject = someObject;
}
public Integer getMyint() {
return myint;
}
public void setMyint(Integer myint) {
this.myint = myint;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}
@@ -0,0 +1,55 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* A basic entity to test simple things.
*/
@Entity
@Table(name = "t_oneb")
public class TOne {
@Id
Integer id;
String name;
String description;
boolean active;
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
@@ -0,0 +1,77 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* A basic entity to test simple things.
*/
@Entity
@Table(name = "t_detail_with_other_namexxxyy")
public class TSDetail {
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "t_atable_detail_seq")
@Id
Integer id;
String name;
String description;
boolean active;
@ManyToOne
TSMaster master;
public TSDetail(String name){
this.name = name;
}
public TSDetail() {
}
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public TSMaster getMaster() {
return master;
}
public void setMaster(TSMaster master) {
this.master = master;
}
}
@@ -0,0 +1,73 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* A basic entity to test simple things.
*/
@Entity
@Table(name = "ts_detail_two")
public class TSDetailTwo {
@Id
Integer id;
String name;
String description;
boolean active;
@ManyToOne
TSMasterTwo master;
public TSDetailTwo(String name){
this.name = name;
}
public TSDetailTwo() {
}
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public TSMasterTwo getMaster() {
return master;
}
public void setMaster(TSMasterTwo master) {
this.master = master;
}
}
@@ -0,0 +1,83 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.avaje.ebean.annotation.PrivateOwned;
/**
* A basic entity to test simple things.
*/
@Entity
@Table(name = "t_atable_thatisrelatively")
public class TSMaster {
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "t_atable_master_seq")
@Id
Integer id;
String name;
String description;
boolean active;
@OneToMany(cascade=CascadeType.ALL,mappedBy="master")
@PrivateOwned
List<TSDetail> details;
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public List<TSDetail> getDetails() {
return details;
}
public void setDetails(List<TSDetail> details) {
this.details = details;
}
public void addDetail(TSDetail detail) {
if (details == null){
details = new ArrayList<TSDetail>();
}
details.add(detail);
}
}
@@ -0,0 +1,80 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.avaje.ebean.annotation.PrivateOwned;
/**
* A basic entity to test simple things.
*/
@Entity
@Table(name = "ts_master_two")
public class TSMasterTwo {
@Id
Integer id;
String name;
String description;
boolean active;
@OneToMany(cascade=CascadeType.ALL,mappedBy="master")
@PrivateOwned(cascadeRemove=false)
List<TSDetailTwo> details;
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public List<TSDetailTwo> getDetails() {
return details;
}
public void setDetails(List<TSDetailTwo> details) {
this.details = details;
}
public void addDetail(TSDetailTwo detail) {
if (details == null){
details = new ArrayList<TSDetailTwo>();
}
details.add(detail);
}
}
@@ -0,0 +1,32 @@
package com.avaje.tests.model.basic;
import java.util.UUID;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class TUuidEntity {
@Id
private UUID id;
private String name;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,43 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import com.avaje.ebean.validation.NotEmpty;
@Entity
public class TWithPreInsert {
@Id
private Integer id;
@NotEmpty
private String name;
private String title;
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 String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
@@ -0,0 +1,56 @@
package com.avaje.tests.model.basic;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
@Entity
public class Trip extends BasicDomain {
private static final long serialVersionUID = 1L;
@ManyToOne
private VehicleDriver vehicleDriver;
private String destination;
@ManyToOne
private Address address;
private Date starDate;
public VehicleDriver getVehicleDriver() {
return vehicleDriver;
}
public void setVehicleDriver(VehicleDriver vehicleDriver) {
this.vehicleDriver = vehicleDriver;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Date getStarDate() {
return starDate;
}
public void setStarDate(Date starDate) {
this.starDate = starDate;
}
}
@@ -0,0 +1,36 @@
package com.avaje.tests.model.basic;
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 = 7433386912403859900L;
@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;
}
}
@@ -0,0 +1,49 @@
/**
* Copyright (C) 2009 Authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.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,77 @@
package com.avaje.tests.model.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name="ut_detail")
public class UTDetail {
@Id
Integer id;
String name;
Integer qty;
Double amount;
@Version
Integer version;
public UTDetail() {
}
public UTDetail(String name, Integer qty, Double amount) {
this.name = name;
this.qty = qty;
this.amount = amount;
}
public String toString() {
return id+" name:"+name+" qty:"+qty+" amt:"+amount;
}
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 Integer getQty() {
return qty;
}
public void setQty(Integer qty) {
this.qty = qty;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
@@ -0,0 +1,66 @@
package com.avaje.tests.model.basic;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name="ut_master")
public class UTMaster {
@Id
Integer id;
String name;
@Version
Integer version;
@OneToMany(cascade=CascadeType.ALL)
List<UTDetail> details;
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 Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public List<UTDetail> getDetails() {
return details;
}
public void setDetails(List<UTDetail> details) {
this.details = details;
}
public void addDetail(UTDetail detail) {
if (details == null){
details = new ArrayList<UTDetail>();
}
details.add(detail);
}
}
@@ -0,0 +1,47 @@
package com.avaje.tests.model.basic;
import java.util.List;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class UUOne {
@Id
UUID id;
String name;
@OneToMany(cascade=CascadeType.ALL, mappedBy="master")
List<UUTwo> comments;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<UUTwo> getComments() {
return comments;
}
public void setComments(List<UUTwo> comments) {
this.comments = comments;
}
}
@@ -0,0 +1,44 @@
package com.avaje.tests.model.basic;
import java.util.UUID;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class UUTwo {
@Id
UUID id;
String name;
@ManyToOne
UUOne master;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public UUOne getMaster() {
return master;
}
public void setMaster(UUOne master) {
this.master = master;
}
}
@@ -0,0 +1,46 @@
package com.avaje.tests.model.basic;
import java.util.Date;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
@Entity
@Inheritance
@DiscriminatorColumn(length = 3)
public abstract class Vehicle extends BasicDomain {
private static final long serialVersionUID = -3060920549470002030L;
private String licenseNumber;
private Date registrationDate;
// @Transient
private transient String testTransient;
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;
}
}
@@ -0,0 +1,55 @@
package com.avaje.tests.model.basic;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
@Entity
public class VehicleDriver extends BasicDomain {
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,23 @@
package com.avaje.tests.model.basic.event;
import com.avaje.ebean.event.BeanPersistAdapter;
import com.avaje.ebean.event.BeanPersistRequest;
import com.avaje.tests.model.basic.Customer;
public class CustomerPersistAdapter extends BeanPersistAdapter {
@Override
public boolean isRegisterFor(Class<?> cls) {
return Customer.class.equals(cls);
}
@Override
public boolean preInsert(BeanPersistRequest<?> request) {
// StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// request.getTransaction().log("+++++ "+Arrays.toString(stackTrace));
return true;
}
}
@@ -0,0 +1,30 @@
package com.avaje.tests.model.basic.event;
import com.avaje.ebean.Query;
import com.avaje.ebean.event.BeanQueryAdapter;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.tests.model.basic.TOne;
public class SimpleTOneQueryAdapter implements BeanQueryAdapter {
public int getExecutionOrder() {
// just return 0
return 0;
}
public boolean isRegisterFor(Class<?> cls) {
return TOne.class.equals(cls);
}
public void preQuery(BeanQueryRequest<?> request) {
Query<?> query = request.getQuery();
// can get the type of query Bean, List, RowCount, Id's etc
//Type queryType = query.getType();
query.where().raw("1=1");
}
}
@@ -0,0 +1,39 @@
package com.avaje.tests.model.basic.event;
import com.avaje.ebean.event.BeanPersistAdapter;
import com.avaje.ebean.event.BeanPersistRequest;
import com.avaje.tests.model.basic.TWithPreInsert;
public class TWithPreInsertPersistAdapter extends BeanPersistAdapter {
@Override
public boolean isRegisterFor(Class<?> cls) {
return TWithPreInsert.class.equals(cls);
}
@Override
public boolean preInsert(BeanPersistRequest<?> request) {
TWithPreInsert e = (TWithPreInsert)request.getBean();
e.setName("aname");
return true;
}
@Override
public boolean preUpdate(BeanPersistRequest<?> request) {
TWithPreInsert b = (TWithPreInsert)request.getBean();
System.out.println("title is Missus:"+b.getTitle());
//Ebean.refresh(b);
request.getEbeanServer().refresh(b);
System.out.println("title is Mister:"+b.getTitle());
return super.preUpdate(request);
}
}
@@ -0,0 +1,30 @@
package com.avaje.tests.model.basic.mapsuper;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class MapSuperActual extends MapSuperNoId {
@Id
Long id;
String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,35 @@
package com.avaje.tests.model.basic.mapsuper;
import java.sql.Timestamp;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import com.avaje.ebean.annotation.CreatedTimestamp;
@MappedSuperclass
public class MapSuperNoId {
@CreatedTimestamp
Timestamp whenCreated;
@Version
Timestamp whenUpdated;
public Timestamp getWhenCreated() {
return whenCreated;
}
public void setWhenCreated(Timestamp whenCreated) {
this.whenCreated = whenCreated;
}
public Timestamp getWhenUpdated() {
return whenUpdated;
}
public void setWhenUpdated(Timestamp whenUpdated) {
this.whenUpdated = whenUpdated;
}
}
@@ -0,0 +1,37 @@
package com.avaje.tests.model.basic.mapsuper;
import junit.framework.TestCase;
import org.junit.Assert;
import com.avaje.ebean.bean.EntityBean;
public class TestMapSuperEquals extends TestCase {
public void testEquals() {
MapSuperActual a = new MapSuperActual();
if (a instanceof EntityBean) {
// test on enhanced beans only
MapSuperActual b = new MapSuperActual();
b.setId(456l);
MapSuperActual c = new MapSuperActual();
c.setId(2l);
a.setId(456l);
Assert.assertTrue("equals By Id value on enhanced mapped super",a.equals(b));
Assert.assertTrue(b.equals(a));
Assert.assertTrue(!a.equals(c));
Assert.assertTrue(!b.equals(c));
} else {
System.out.println("--- ok, not running TestMapSuperEquals test");
}
}
}
@@ -0,0 +1,24 @@
package com.avaje.tests.model.basic.xtra;
import java.util.List;
import javax.persistence.EntityNotFoundException;
import com.avaje.ebean.TxType;
import com.avaje.ebean.annotation.Transactional;
public class DummyDao {
@Transactional(type = TxType.REQUIRES_NEW)
public void doSomething() {
System.out.println("Hello World");
}
@Transactional
// ebean transactional annotation, not spring transactional annotation
public void addToObject(Long id, Double anotherNumber, List<Long> ids) throws EntityNotFoundException {
// and more code
}
}
@@ -0,0 +1,47 @@
package com.avaje.tests.model.basic.xtra;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="td_child")
public class EdChild {
@Id
@Column(name="child_id")
private int id;
@Column(name="child_name")
private String name;
@ManyToOne
@JoinColumn(name="parent_id", nullable=false )
EdParent parent;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public EdParent getParent() {
return parent;
}
public void setParent(EdParent parent) {
this.parent = parent;
}
}
@@ -0,0 +1,21 @@
package com.avaje.tests.model.basic.xtra;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("EXTENDED")
public class EdExtendedParent extends EdParent {
private String extendedName;
public String getExtendedName() {
return extendedName;
}
public void setExtendedName(String extendedName) {
this.extendedName = extendedName;
}
}

Some files were not shown because too many files have changed in this diff Show More