mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
initial add of EbeanORM server based on v2.8.1
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
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.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
@Table(name = "drel_booking")
|
||||
public class Booking {
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "agent_invoice")
|
||||
private Invoice agentInvoice;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "client_invoice")
|
||||
private Invoice clientInvoice;
|
||||
|
||||
@OneToMany(mappedBy = "booking")//, cascade = CascadeType.ALL)
|
||||
private List<Invoice> invoices;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Invoice getAgentInvoice() {
|
||||
return agentInvoice;
|
||||
}
|
||||
|
||||
public void setAgentInvoice(Invoice agentInvoice) {
|
||||
this.agentInvoice = agentInvoice;
|
||||
}
|
||||
|
||||
public Invoice getClientInvoice() {
|
||||
return clientInvoice;
|
||||
}
|
||||
|
||||
public void setClientInvoice(Invoice clientInvoice) {
|
||||
this.clientInvoice = clientInvoice;
|
||||
}
|
||||
|
||||
public List<Invoice> getInvoices() {
|
||||
return invoices;
|
||||
}
|
||||
|
||||
public void setInvoices(List<Invoice> invoices) {
|
||||
this.invoices= invoices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
@Table(name="drel_invoice")
|
||||
public class Invoice {
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "booking")
|
||||
private Booking booking;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Booking getBooking() {
|
||||
return booking;
|
||||
}
|
||||
|
||||
public void setBooking(Booking booking) {
|
||||
this.booking = booking;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestOne2OneBookingInvoice extends TestCase {
|
||||
|
||||
public void test() {
|
||||
Booking b = new Booking();
|
||||
|
||||
Invoice ai = new Invoice();
|
||||
Invoice ci = new Invoice();
|
||||
|
||||
ai.setBooking(b);
|
||||
ci.setBooking(b);
|
||||
|
||||
b.setAgentInvoice(ai);
|
||||
b.setClientInvoice(ci);
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
Booking b1 = Ebean.find(Booking.class, b.getId());
|
||||
|
||||
Invoice ai1 = b1.getAgentInvoice();
|
||||
Assert.assertNotNull(ai1);
|
||||
|
||||
Booking b2 = ai1.getBooking();
|
||||
Assert.assertNotNull(b2);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
|
||||
Invoice ci1 = b1.getClientInvoice();
|
||||
Booking b3 = ci1.getBooking();
|
||||
Assert.assertNotNull(b3);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
|
||||
public class TestOneToOneWheelTire extends TestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
Wheel w = new Wheel();
|
||||
Tire t = new Tire();
|
||||
t.setWheel(w);
|
||||
w.setTire(t);
|
||||
|
||||
Ebean.save(t);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tire")
|
||||
public class Tire {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
@Version
|
||||
private int version;
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "wheel")
|
||||
private Wheel wheel;
|
||||
|
||||
public Tire() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Wheel getWheel() {
|
||||
return wheel;
|
||||
}
|
||||
|
||||
public void setWheel(Wheel wheel) {
|
||||
this.wheel = wheel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
@Table(name = "wheel")
|
||||
public class Wheel {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
@Version
|
||||
private int version;
|
||||
@OneToOne(mappedBy = "wheel", cascade = CascadeType.ALL)
|
||||
private Tire tire;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Wheel() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Tire getTire() {
|
||||
return tire;
|
||||
}
|
||||
|
||||
public void setTire(Tire tire) {
|
||||
this.tire = tire;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user