Index: polymorphism/AllTests.java
===================================================================
RCS file: polymorphism/AllTests.java
diff -N polymorphism/AllTests.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/AllTests.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,30 @@
+/**
+ * Created on 15.03.2005 at 15:39:49
+ *
+ * TODO Insert class description here
+ *
+ * @author werner.guttmann
+ *
+ * Copyright (c) Vector SW DV GmbH, 2005
+ */
+package polymorphism;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for polymorphism");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(PolymorphismTest.class);
+ suite.addTestSuite(Test1197.class);
+ //$JUnit-END$
+ return suite;
+ }
+}
Index: polymorphism/Base.java
===================================================================
RCS file: polymorphism/Base.java
diff -N polymorphism/Base.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Base.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,16 @@
+package polymorphism;
+
+public class Base {
+ private String id;
+ private String color;
+
+ public String getId() { return this.id; }
+ public void setId(String id) { this.id = id; }
+
+ public String getColor() { return this.color; }
+ public void setColor(String color) { this.color = color; }
+
+ public String toString(){
+ return super.toString() + " Base: id=" + this.id + ",color=" + this.color;
+ }
+}
Index: polymorphism/Car.java
===================================================================
RCS file: polymorphism/Car.java
diff -N polymorphism/Car.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Car.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,36 @@
+package polymorphism;
+
+/**
+ * @author Administrator
+ */
+public class Car extends Product {
+
+ private int kw;
+ private String make;
+
+
+ /**
+ * @return Returns the kw.
+ */
+ public int getKw() {
+ return kw;
+ }
+ /**
+ * @param kw The kw to set.
+ */
+ public void setKw(int kw) {
+ this.kw = kw;
+ }
+ /**
+ * @return Returns the make.
+ */
+ public String getMake() {
+ return make;
+ }
+ /**
+ * @param make The make to set.
+ */
+ public void setMake(String make) {
+ this.make = make;
+ }
+}
Index: polymorphism/Computer.java
===================================================================
RCS file: polymorphism/Computer.java
diff -N polymorphism/Computer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Computer.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+package polymorphism;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class Computer extends Product {
+
+ private String cpu;
+
+ /**
+ * @return Returns the cpu.
+ */
+ public String getCpu() {
+ return this.cpu;
+ }
+ /**
+ * @param cpu The cpu to set.
+ */
+ public void setCpu(String cpu) {
+ this.cpu = cpu;
+ }
+}
Index: polymorphism/ComputerMulti.java
===================================================================
RCS file: polymorphism/ComputerMulti.java
diff -N polymorphism/ComputerMulti.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/ComputerMulti.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+package polymorphism;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class ComputerMulti extends ProductMulti {
+
+ private String cpu;
+
+ /**
+ * @return Returns the cpu.
+ */
+ public String getCpu() {
+ return this.cpu;
+ }
+ /**
+ * @param cpu The cpu to set.
+ */
+ public void setCpu(String cpu) {
+ this.cpu = cpu;
+ }
+}
Index: polymorphism/Container.java
===================================================================
RCS file: polymorphism/Container.java
diff -N polymorphism/Container.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Container.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,16 @@
+package polymorphism;
+
+public class Container {
+ private String id;
+ private Base reference;
+
+ public String getId() { return this.id; }
+ public void setId(String id) { this.id = id; }
+
+ public Base getReference() { return this.reference; }
+ public void setReference(Base reference) { this.reference = reference; }
+
+ public String toString(){
+ return super.toString() + "Container: id =" + this.id + ",reference=[" + this.reference + "]";
+ }
+}
Index: polymorphism/Derived.java
===================================================================
RCS file: polymorphism/Derived.java
diff -N polymorphism/Derived.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Derived.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,12 @@
+package polymorphism;
+
+public class Derived extends Base {
+ private String scent;
+
+ public String getScent() { return this.scent; }
+ public void setScent(String scent) { this.scent = scent; }
+
+ public String toString(){
+ return super.toString() + ", Derived: scent=" + this.scent;
+ }
+}
Index: polymorphism/Laptop.java
===================================================================
RCS file: polymorphism/Laptop.java
diff -N polymorphism/Laptop.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Laptop.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,36 @@
+package polymorphism;
+
+
+/**
+ * @author werner.guttmann
+ */
+public class Laptop extends Computer {
+
+ private int weight;
+ private String resolution;
+
+ /**
+ * @return Returns the resolution.
+ */
+ public String getResolution() {
+ return this.resolution;
+ }
+ /**
+ * @param resolution The resolution to set.
+ */
+ public void setResolution(String resolution) {
+ this.resolution = resolution;
+ }
+ /**
+ * @return Returns the weight.
+ */
+ public int getWeight() {
+ return this.weight;
+ }
+ /**
+ * @param weight The weight to set.
+ */
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+}
Index: polymorphism/LaptopMulti.java
===================================================================
RCS file: polymorphism/LaptopMulti.java
diff -N polymorphism/LaptopMulti.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/LaptopMulti.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,36 @@
+package polymorphism;
+
+
+/**
+ * @author werner.guttmann
+ */
+public class LaptopMulti extends ComputerMulti {
+
+ private int weight;
+ private String resolution;
+
+ /**
+ * @return Returns the resolution.
+ */
+ public String getResolution() {
+ return this.resolution;
+ }
+ /**
+ * @param resolution The resolution to set.
+ */
+ public void setResolution(String resolution) {
+ this.resolution = resolution;
+ }
+ /**
+ * @return Returns the weight.
+ */
+ public int getWeight() {
+ return this.weight;
+ }
+ /**
+ * @param weight The weight to set.
+ */
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+}
Index: polymorphism/M.java
===================================================================
RCS file: polymorphism/M.java
diff -N polymorphism/M.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/M.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,34 @@
+package polymorphism;
+
+import java.util.Collection;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class M {
+
+ private int id;
+ private String name;
+ private Collection ns;
+
+ public int getId() {
+ return this.id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getName() {
+ return this.name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Collection getNs() {
+ return this.ns;
+ }
+ public void setNs(Collection ns) {
+ this.ns = ns;
+ }
+}
Index: polymorphism/N.java
===================================================================
RCS file: polymorphism/N.java
diff -N polymorphism/N.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/N.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,34 @@
+package polymorphism;
+
+import java.util.Collection;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class N {
+
+ private int id;
+ private String name;
+ private Collection ms;
+
+ public Collection getMs() {
+ return this.ms;
+ }
+ public void setMs(Collection ms) {
+ this.ms = ms;
+ }
+ public int getId() {
+ return this.id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getName() {
+ return this.name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Index: polymorphism/Order.java
===================================================================
RCS file: polymorphism/Order.java
diff -N polymorphism/Order.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Order.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,34 @@
+package polymorphism;
+
+import java.util.Collection;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class Order {
+
+ private int id;
+ private String name;
+ private Collection products;
+
+ public int getId() {
+ return this.id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getName() {
+ return this.name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Collection getProducts() {
+ return this.products;
+ }
+ public void setProducts(Collection products) {
+ this.products = products;
+ }
+}
Index: polymorphism/Owner.java
===================================================================
RCS file: polymorphism/Owner.java
diff -N polymorphism/Owner.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Owner.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,31 @@
+package polymorphism;
+
+/**
+ * @author werner.guttmann
+ */
+public class Owner {
+
+ private int id;
+ private String name;
+ private Product product;
+
+ public int getId() {
+ return this.id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getName() {
+ return this.name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Product getProduct() {
+ return this.product;
+ }
+ public void setProduct(Product product) {
+ this.product = product;
+ }
+}
Index: polymorphism/PolymorphismTest.java
===================================================================
RCS file: polymorphism/PolymorphismTest.java
diff -N polymorphism/PolymorphismTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/PolymorphismTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,648 @@
+package polymorphism;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.exolab.castor.jdo.Database;
+import org.exolab.castor.jdo.JDO2;
+import org.exolab.castor.jdo.OQLQuery;
+import org.exolab.castor.jdo.ObjectNotFoundException;
+import org.exolab.castor.jdo.QueryResults;
+import org.exolab.castor.persist.spi.Complex;
+
+import junit.framework.TestCase;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class PolymorphismTest extends TestCase {
+
+ /**
+ * Castor JDO manager
+ */
+ private JDO2 jdo = null;
+
+ private static final Log log = LogFactory.getLog (PolymorphismTest.class);
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ JDO2.loadConfiguration (getClass().getResource("jdo-conf.xml").toString());
+ this.jdo = JDO2.createInstance("poly");
+
+ }
+
+ public void testLoadLaptop() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Laptop laptop = (Laptop) database.load (Laptop.class, new Integer (1));
+ database.commit();
+
+ assertNotNull (laptop);
+ assertEquals ("polymorphism.Laptop", laptop.getClass().getName());
+ assertEquals (1, laptop.getId());
+ assertEquals ("laptop 1", laptop.getName());
+
+ database.close();
+
+ }
+
+ public void testLoadLaptopAndRollback() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Laptop laptop = (Laptop) database.load (Laptop.class, new Integer (1));
+
+ assertNotNull (laptop);
+ assertEquals ("polymorphism.Laptop", laptop.getClass().getName());
+ assertEquals (1, laptop.getId());
+ assertEquals ("laptop 1", laptop.getName());
+
+ database.rollback();
+
+ database.close();
+
+ }
+
+ public void testLoadLaptopReadOnly() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Laptop laptop = (Laptop) database.load (Laptop.class, new Integer (1), Database.ReadOnly);
+ database.commit();
+
+ assertNotNull (laptop);
+ assertEquals ("polymorphism.Laptop", laptop.getClass().getName());
+ assertEquals (1, laptop.getId());
+ assertEquals ("laptop 1", laptop.getName());
+
+ database.close();
+
+ }
+
+ public void testCreateAndLoadLaptop() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ ProductDetail detail = new ProductDetail();
+ detail.setId(10);
+ detail.setCategory("category 10");
+ detail.setLocation("location 10");
+ database.create(detail);
+ database.commit();
+
+ database.begin();
+ Laptop laptop = new Laptop();
+ laptop.setId(10);
+ laptop.setName("laptop 10");
+ laptop.setCpu("centrino");
+ laptop.setResolution("1600");
+ laptop.setWeight(2750);
+ laptop.setDetail((ProductDetail) database.load(ProductDetail.class, new Integer (10)));
+ database.create(laptop);
+ database.commit();
+
+ database.begin();
+ laptop = (Laptop) database.load (Laptop.class, new Integer (10));
+ database.commit();
+
+ assertNotNull (laptop);
+ assertEquals ("polymorphism.Laptop", laptop.getClass().getName());
+ assertEquals (10, laptop.getId());
+ assertEquals ("laptop 10", laptop.getName());
+
+ database.begin();
+ database.remove (database.load(Laptop.class, new Integer (10)));
+ database.remove (database.load (ProductDetail.class, new Integer (10)));
+ database.commit();
+
+ database.begin();
+ try {
+ laptop = (Laptop) database.load(Laptop.class, new Integer (10));
+ fail ("Laptop with id 10 still exists.");
+ }
+ catch (ObjectNotFoundException e) {
+ assertEquals ("The object of type polymorphism.Laptop with identity 10 was not found in persistent storage", e.getMessage());
+ }
+
+ database.commit();
+
+ database.close();
+
+ }
+
+ public void testLoadLaptopMulti() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ LaptopMulti laptop = (LaptopMulti) database.load (LaptopMulti.class, new Complex (new Integer (1), new Integer(1)));
+ database.commit();
+
+ assertNotNull (laptop);
+ assertEquals ("polymorphism.LaptopMulti", laptop.getClass().getName());
+ assertEquals ("laptop 1", laptop.getName());
+ assertEquals (1, laptop.getId1());
+ assertEquals (1, laptop.getId2());
+
+ database.close();
+
+ }
+
+ public void testLoadServer() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Server server = (Server) database.load (Server.class, new Integer (3));
+ database.commit();
+
+ assertNotNull (server);
+ assertEquals ("polymorphism.Server", server.getClass().getName());
+ assertEquals (3, server.getId());
+ assertEquals ("server 3", server.getName());
+
+ database.close();
+
+ }
+
+ public void testLoadServerMulti() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ ServerMulti server = (ServerMulti) database.load (ServerMulti.class, new Complex (new Integer (3), new Integer(3)));
+ database.commit();
+
+ assertNotNull (server);
+ assertEquals ("polymorphism.ServerMulti", server.getClass().getName());
+ assertEquals (3, server.getId1());
+ assertEquals (3, server.getId2());
+ assertEquals ("server 3", server.getName());
+
+ database.close();
+
+ }
+
+ public void testLoadComputer() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Computer computer = (Computer) database.load (Computer.class, new Integer (2));
+ database.commit();
+
+ assertNotNull (computer);
+ assertEquals ("polymorphism.Laptop", computer.getClass().getName());
+ assertEquals (2, computer.getId());
+ assertEquals ("laptop 2", computer.getName());
+
+ database.close();
+
+ }
+
+ public void testLoadComputerAndRollback() throws Exception {
+
+ log.debug ("testLoadComputerAndRollback()");
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Computer computer = (Computer) database.load (Computer.class, new Integer (2));
+
+ assertNotNull (computer);
+ assertEquals ("polymorphism.Laptop", computer.getClass().getName());
+ assertEquals (2, computer.getId());
+ assertEquals ("laptop 2", computer.getName());
+
+ database.rollback();
+
+ database.close();
+
+ }
+
+ public void testLoadComputerAndCommitAndRollback() throws Exception {
+
+ Computer computer = null;
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ computer = (Computer) database.load (Computer.class, new Integer (2));
+ assertNotNull (computer);
+ assertEquals ("polymorphism.Laptop", computer.getClass().getName());
+ assertEquals (2, computer.getId());
+ assertEquals ("laptop 2", computer.getName());
+ database.commit();
+
+ database.begin();
+ computer = (Computer) database.load (Computer.class, new Integer (2));
+
+ assertNotNull (computer);
+ assertEquals ("polymorphism.Laptop", computer.getClass().getName());
+ assertEquals (2, computer.getId());
+ assertEquals ("laptop 2", computer.getName());
+
+ database.rollback();
+
+ database.close();
+
+ }
+
+ public void testCreateAndLoadComputer() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Order order = new Order();
+ order.setId(12);
+ order.setName("order 12");
+ database.create(order);
+ database.commit();
+
+ database.begin();
+ ProductDetail detail = new ProductDetail();
+ detail.setId(12);
+ detail.setCategory("category 12");
+ detail.setLocation("location 12");
+ database.create(detail);
+ database.commit();
+
+ database.begin();
+ Laptop laptop = new Laptop();
+ laptop.setId(12);
+ laptop.setName("laptop 12");
+ laptop.setCpu("centrino");
+ laptop.setResolution("1600");
+ laptop.setWeight(2450);
+ laptop.setDetail((ProductDetail) database.load(ProductDetail.class, new Integer (12)));
+ database.create(laptop);
+ Collection orders = new LinkedList();
+ orders.add(database.load (Order.class, new Integer (12)));;
+ laptop.setOrders(orders);
+ database.commit();
+
+ database.begin();
+ Computer computer = (Computer) database.load (Computer.class, new Integer (12));
+ database.commit();
+
+ assertNotNull (computer);
+ assertEquals ("polymorphism.Laptop", computer.getClass().getName());
+ assertEquals (12, computer.getId());
+ assertEquals ("laptop 12", computer.getName());
+
+ database.begin();
+ database.remove (database.load(Computer.class, new Integer (12)));
+ database.remove (database.load (ProductDetail.class, new Integer (12)));
+ database.remove (database.load(Order.class, new Integer (12)));
+ database.commit();
+
+
+ database.close();
+
+ }
+
+
+ public void testLoadComputerMulti() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ ComputerMulti computer = (LaptopMulti) database.load (ComputerMulti.class, new Complex (new Integer (1), new Integer (1)));
+ database.commit();
+
+ assertNotNull (computer);
+ assertEquals (1, computer.getId1());
+ assertEquals (1, computer.getId2());
+ assertEquals ("laptop 1", computer.getName());
+
+ database.close();
+
+ }
+
+ public void testLoadTruck() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Truck truck = (Truck) database.load (Truck.class, new Integer (5));
+ database.commit();
+
+ assertNotNull (truck);
+ assertEquals (5, truck.getId());
+
+ database.close();
+
+ }
+
+ public void testLoadCar() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Object object = database.load (Car.class, new Integer (5));
+ assertNotNull (object);
+ assertEquals ("polymorphism.Truck", object.getClass().getName());
+ Truck truck = (Truck) object;
+ database.commit();
+
+ assertNotNull (truck);
+ assertEquals (5, truck.getId());
+
+ database.close();
+
+ }
+
+ public void testCreateAndLoadCar() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Order order = new Order();
+ order.setId(11);
+ order.setName("order 11");
+ database.create(order);
+ database.commit();
+
+ database.begin();
+ ProductDetail detail = new ProductDetail();
+ detail.setId(11);
+ detail.setCategory("category 11");
+ detail.setLocation("location 11");
+ database.create(detail);
+ database.commit();
+
+ database.begin();
+ Truck truck = new Truck();
+ truck.setId(11);
+ truck.setName("truck 11");
+ truck.setKw(112);
+ truck.setMake("Fiat");
+ truck.setMaxWeight(3750);
+ truck.setDetail((ProductDetail) database.load(ProductDetail.class, new Integer (11)));
+ database.create(truck);
+ Collection orders = new LinkedList();
+ orders.add(database.load (Order.class, new Integer (11)));;
+ truck.setOrders(orders);
+ database.commit();
+
+ database.begin();
+ Object object = database.load (Car.class, new Integer (11));
+ assertNotNull (object);
+ assertEquals ("polymorphism.Truck", object.getClass().getName());
+ Truck loadedTruck = (Truck) object;
+ database.commit();
+
+ assertNotNull (loadedTruck);
+ assertEquals (11, loadedTruck.getId());
+
+ database.begin();
+ database.remove (database.load (Car.class, new Integer (11)));
+ database.remove (database.load (ProductDetail.class, new Integer (11)));
+ database.remove(database.load(Order.class, new Integer (11)));
+ database.commit();
+
+ database.close();
+
+ }
+
+
+ public void testLoadOwner() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ Owner owner = (Owner) database.load (Owner.class, new Integer (1));
+ database.commit();
+
+ assertNotNull (owner);
+ assertEquals (1, owner.getId());
+ assertEquals ("owner 1", owner.getName());
+
+ Product product = owner.getProduct();
+ assertNotNull (product);
+ assertEquals (1, product.getId());
+ assertEquals ("polymorphism.Laptop", product.getClass().getName());
+
+ database.close();
+
+ }
+
+ public void testLoadM() throws Exception {
+
+ Database database = null;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ M m = (M) database.load (M.class, new Integer (1));
+ database.commit();
+
+ assertNotNull (m);
+ assertEquals (1, m.getId());
+ assertEquals ("m1", m.getName());
+
+ Collection ns = m.getNs();
+ assertNotNull (ns);
+ assertEquals (2, ns.size());
+
+ database.close();
+
+ }
+
+ public void testQueryOwner () throws Exception {
+
+ Database database = this.jdo.getDatabase();
+
+ database.begin();
+ OQLQuery query = database.getOQLQuery("select owner from polymorphism.Owner as owner");
+ QueryResults results = query.execute();
+
+ if (results.hasMore()) {
+ int counter = 1;
+ while (results.hasMore()) {
+ Owner owner = (Owner) results.next();
+ assertNotNull (owner);
+ assertEquals (counter, owner.getId());
+
+ counter += 1;
+ }
+ } else {
+ fail ("Query does not return any Computer instances.");
+ }
+ database.commit();
+
+ database.close();
+ }
+
+ public void testQueryComputers () throws Exception {
+
+ Database database;
+
+ String[] classNames =
+ {
+ "polymorphism.Laptop",
+ "polymorphism.Laptop",
+ "polymorphism.Server",
+ "polymorphism.Server"
+ };
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ OQLQuery query = database.getOQLQuery("select computer from polymorphism.Computer as computer");
+ QueryResults results = query.execute();
+
+ if (results.hasMore()) {
+ int counter = 1;
+ while (results.hasMore()) {
+ Computer computer = (Computer) results.next();
+ assertNotNull (computer);
+ assertEquals (counter, computer.getId());
+ assertEquals (classNames[counter - 1], computer.getClass().getName());
+
+ counter += 1;
+ }
+ } else {
+ fail ("Query does not return any Computer instances.");
+ }
+ database.commit();
+
+ database.close();
+ }
+
+ public void testQueryLaptops () throws Exception {
+
+ Database database;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ OQLQuery query = database.getOQLQuery("select l from polymorphism.Laptop as l");
+ QueryResults results = query.execute();
+
+ if (results.hasMore()) {
+ int counter = 1;
+ Laptop laptop = null;
+ while (results.hasMore()) {
+ laptop = (Laptop) results.next();
+ assertNotNull (laptop);
+ assertEquals (counter, laptop.getId());
+
+ counter += 1;
+ }
+ } else {
+ fail ("Query does not return any Laptop instances.");
+ }
+ database.commit();
+
+ database.close();
+ }
+
+ public void testQueryServers () throws Exception {
+
+ Database database;
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ OQLQuery query = database.getOQLQuery("select l from polymorphism.Server as l");
+ QueryResults results = query.execute();
+
+ if (results.hasMore()) {
+ int counter = 3;
+ while (results.hasMore()) {
+ Server server = (Server) results.next();
+ assertNotNull (server);
+ assertEquals (counter, server.getId());
+
+ counter += 1;
+ }
+ } else {
+ fail ("Query does not return any Laptop instances.");
+ }
+ database.commit();
+
+ database.close();
+ }
+
+ public void testQueryProducts () throws Exception {
+
+ Database database;
+
+ String[] classNames =
+ {
+ "polymorphism.Laptop",
+ "polymorphism.Laptop",
+ "polymorphism.Server",
+ "polymorphism.Server",
+ "polymorphism.Truck"
+ };
+
+ database = this.jdo.getDatabase();
+
+ database.begin();
+ OQLQuery query = database.getOQLQuery("select product from polymorphism.Product as product");
+ QueryResults results = query.execute();
+
+ if (results.hasMore()) {
+ int counter = 1;
+ while (results.hasMore()) {
+ Product product = (Product) results.next();
+ assertNotNull (product);
+ assertEquals (counter, product.getId());
+ assertEquals (classNames[counter - 1], product.getClass().getName());
+
+ counter += 1;
+ }
+ } else {
+ fail ("Query does not return any Product instances.");
+ }
+ database.commit();
+
+ database.close();
+ }
+
+}
Index: polymorphism/Product.java
===================================================================
RCS file: polymorphism/Product.java
diff -N polymorphism/Product.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Product.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,51 @@
+package polymorphism;
+
+import java.util.Collection;
+
+/**
+ * @author werner.guttmann
+ */
+public class Product {
+
+ private int id;
+ private String name;
+ private ProductDetail detail;
+ private Collection orders;
+
+ public ProductDetail getDetail() {
+ return this.detail;
+ }
+ public void setDetail(ProductDetail detail) {
+ this.detail = detail;
+ }
+ /**
+ * @return Returns the id.
+ */
+ public int getId() {
+ return this.id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return this.name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Collection getOrders() {
+ return this.orders;
+ }
+ public void setOrders(Collection orders) {
+ this.orders = orders;
+ }
+}
Index: polymorphism/ProductDetail.java
===================================================================
RCS file: polymorphism/ProductDetail.java
diff -N polymorphism/ProductDetail.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/ProductDetail.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,33 @@
+package polymorphism;
+
+/**
+ * @author werner.guttmann
+ *
+ * This is a type.
+ */
+public class ProductDetail {
+
+ private int id;
+ private String category;
+ private String location;
+
+
+ public String getCategory() {
+ return this.category;
+ }
+ public void setCategory(String category) {
+ this.category = category;
+ }
+ public int getId() {
+ return this.id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getLocation() {
+ return this.location;
+ }
+ public void setLocation(String location) {
+ this.location = location;
+ }
+}
Index: polymorphism/ProductMulti.java
===================================================================
RCS file: polymorphism/ProductMulti.java
diff -N polymorphism/ProductMulti.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/ProductMulti.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,49 @@
+package polymorphism;
+
+/**
+ * @author werner.guttmann
+ */
+public class ProductMulti {
+
+ private int id1;
+ private int id2;
+ private String name;
+ private ProductDetail detail;
+
+ public ProductDetail getDetail() {
+ return this.detail;
+ }
+ public void setDetail(ProductDetail detail) {
+ this.detail = detail;
+ }
+ /**
+ * @return Returns the id.
+ */
+ public int getId1() {
+ return this.id1;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId1(int id1) {
+ this.id1 = id1;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return this.name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ public int getId2() {
+ return this.id2;
+ }
+ public void setId2(int id2) {
+ this.id2 = id2;
+ }
+}
Index: polymorphism/Server.java
===================================================================
RCS file: polymorphism/Server.java
diff -N polymorphism/Server.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Server.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,35 @@
+package polymorphism;
+
+/**
+ * @author werner.guttmann
+ */
+public class Server extends Computer {
+
+ private int numberOfCPUs;
+ private int supportInYears;
+
+ /**
+ * @return Returns the numberOfCPUs.
+ */
+ public int getNumberOfCPUs() {
+ return this.numberOfCPUs;
+ }
+ /**
+ * @param numberOfCPUs The numberOfCPUs to set.
+ */
+ public void setNumberOfCPUs(int numberOfCPUs) {
+ this.numberOfCPUs = numberOfCPUs;
+ }
+ /**
+ * @return Returns the supportInYears.
+ */
+ public int getSupportInYears() {
+ return this.supportInYears;
+ }
+ /**
+ * @param supportInYears The supportInYears to set.
+ */
+ public void setSupportInYears(int supportInYears) {
+ this.supportInYears = supportInYears;
+ }
+}
Index: polymorphism/ServerMulti.java
===================================================================
RCS file: polymorphism/ServerMulti.java
diff -N polymorphism/ServerMulti.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/ServerMulti.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,35 @@
+package polymorphism;
+
+/**
+ * @author werner.guttmann
+ */
+public class ServerMulti extends ComputerMulti{
+
+ private int numberOfCPUs;
+ private int supportInYears;
+
+ /**
+ * @return Returns the numberOfCPUs.
+ */
+ public int getNumberOfCPUs() {
+ return this.numberOfCPUs;
+ }
+ /**
+ * @param numberOfCPUs The numberOfCPUs to set.
+ */
+ public void setNumberOfCPUs(int numberOfCPUs) {
+ this.numberOfCPUs = numberOfCPUs;
+ }
+ /**
+ * @return Returns the supportInYears.
+ */
+ public int getSupportInYears() {
+ return this.supportInYears;
+ }
+ /**
+ * @param supportInYears The supportInYears to set.
+ */
+ public void setSupportInYears(int supportInYears) {
+ this.supportInYears = supportInYears;
+ }
+}
Index: polymorphism/Test1197.java
===================================================================
RCS file: polymorphism/Test1197.java
diff -N polymorphism/Test1197.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Test1197.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,193 @@
+package polymorphism;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.exolab.castor.jdo.Database;
+import org.exolab.castor.jdo.JDO2;
+import org.exolab.castor.jdo.OQLQuery;
+import org.exolab.castor.jdo.QueryResults;
+import org.exolab.castor.mapping.Mapping;
+
+public class Test1197 extends TestCase {
+ private static final String JdoConfFile = "jdo-conf.xml";
+ private static final String MappingFile = "mapping.xml";
+ private static final int REPS = 100;
+
+ private static final Log log = LogFactory.getLog (Test1197.class);
+
+ private Mapping mapping;
+ private JDO2 jdo;
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run( Test1197.class );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.mapping = new Mapping( getClass().getClassLoader() );
+ this.mapping.loadMapping( getClass().getResource( MappingFile ) );
+
+ JDO2.loadConfiguration( getClass().getResource( JdoConfFile ).toString() );
+ this.jdo = JDO2.createInstance( "poly" );
+
+ Database db = this.jdo.getDatabase();
+
+ db.begin();
+ OQLQuery query = db.getOQLQuery( "select c from " + Container.class.getName() + " c" );
+ QueryResults results = query.execute();
+ while (results.hasMore()) { db.remove(results.next()); }
+ db.commit();
+
+ db.begin();
+ query = db.getOQLQuery( "select d from " + Derived.class.getName() + " d" );
+ results = query.execute();
+ while (results.hasMore()) { db.remove(results.next()); }
+ db.commit();
+
+ db.begin();
+ query = db.getOQLQuery( "select d from " + Base.class.getName() + " d" );
+ results = query.execute();
+ while (results.hasMore()) { db.remove(results.next()); }
+ db.commit();
+
+ db.begin();
+ try{
+ Derived d = new Derived();
+ d.setId( "100" );
+ d.setColor( "blue" );
+ d.setScent( "parsimmon" );
+ db.create( d );
+
+ Container c = new Container();
+ c.setId( "200" );
+ c.setReference( d );
+ db.create( c );
+
+ db.commit();
+ } catch ( Exception ex ){
+ ex.printStackTrace();
+ db.rollback();
+ throw ex;
+ }
+
+ db.close();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ protected Container loadContainer() throws Exception{
+ Database db = this.jdo.getDatabase();
+ db.begin();
+ Container container;
+ try {
+ container = (Container) db.load( Container.class, "200" );
+ db.commit();
+ } catch ( Exception ex ) {
+ db.rollback();
+ throw ex;
+ } finally {
+ db.close();
+ }
+ return container;
+ }
+
+ private Derived loadDerived() throws Exception{
+ Database db = this.jdo.getDatabase();
+ db.begin();
+ Derived derived;
+ try {
+ derived = (Derived) db.load( Derived.class, "100" );
+ db.commit();
+ } catch ( Exception ex ) {
+ db.rollback();
+ throw ex;
+ } finally {
+ db.close();
+ }
+ return derived;
+ }
+
+ private Container loadContainerThenDerived() throws Exception {
+ Database db = this.jdo.getDatabase();
+ db.begin();
+ Container container = null;
+ Derived derived = null;
+ try {
+ container = (Container) db.load( Container.class, "200" );
+ derived = (Derived) db.load( Derived.class, "100" );
+ db.commit();
+ } catch ( Exception ex ) {
+ db.rollback();
+ throw ex;
+ } finally {
+ db.close();
+ }
+ return container;
+ }
+
+ public void testLoadContainer() throws Exception {
+ log.debug( "First we load a Container in its own transaction" );
+ System.out.flush();
+ Object o = loadContainer();
+ log.debug( "loadContainer: " + o );
+ }
+
+ public void testLoadDerived() throws Exception {
+ log.debug( "Second we load a Derived in its own transaction" );
+ System.out.flush();
+ Object o = loadDerived();
+ log.debug( "loadDerived: " + o );
+ }
+
+ public void testLoadContainerThenDerived() throws Exception {
+ log.debug( "Third we load a Container and a Derived in one transaction" );
+ System.out.flush();
+ Object o = loadContainerThenDerived();
+ log.debug( "loadContainerThenDerived: " + o);
+ }
+
+ public void testLoadContainerAndDerivedThreaded() throws Exception {
+ int count = 0;
+ try {
+ log.debug( "Forth we load Container and Derived in seperate "
+ + "threads in their own transactions" );
+ System.out.flush();
+
+ Thread thread = new Thread ( new TreadedContainerLoader() );
+ thread.start();
+
+ for ( int i = 0; i < REPS; i++ ) {
+ count = i;
+ loadDerived();
+ }
+ log.debug( "First thread successfully loaded " + (count + 1) + " Derived" );
+
+ thread.join();
+ } catch ( Exception ex ) {
+ System.err.println( "Exception on first thread loading Derived on " + (count + 1) + "th try" );
+ System.out.flush();
+ throw ex;
+ }
+ }
+
+ class TreadedContainerLoader implements Runnable {
+ public void run() {
+ int count = 0;
+ try {
+ for ( int i = 0; i < REPS; i++ ) {
+ count = i;
+ loadContainer();
+ }
+ log.debug( "Second thread successfully loaded " + (count + 1) + " Containers" );
+ } catch ( Exception ex ) {
+ log.error( "Exception on second thread loading Container on " + (count + 1) + "th try" );
+
+ }
+ }
+ }
+}
Index: polymorphism/Truck.java
===================================================================
RCS file: polymorphism/Truck.java
diff -N polymorphism/Truck.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/Truck.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,22 @@
+package polymorphism;
+
+/**
+ * @author Administrator
+ */
+public class Truck extends Car {
+
+ private int maxWeight;
+
+ /**
+ * @return Returns the maxWeight.
+ */
+ public int getMaxWeight() {
+ return maxWeight;
+ }
+ /**
+ * @param maxWeight The maxWeight to set.
+ */
+ public void setMaxWeight(int maxWeight) {
+ this.maxWeight = maxWeight;
+ }
+}
Index: polymorphism/ddl.sql
===================================================================
RCS file: polymorphism/ddl.sql
diff -N polymorphism/ddl.sql
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/ddl.sql 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,212 @@
+-- tests for bug 1881
+
+drop table if exists ordr;
+create table ordr (
+ id int not null,
+ name varchar (20) not null
+);
+
+drop table if exists detail;
+create table detail (
+ id int not null,
+ category varchar (20) not null,
+ location varchar (20) not null
+);
+
+drop table if exists owner;
+create table owner (
+ id int not null,
+ name varchar (20) not null,
+ product int not null
+);
+
+drop table if exists prod;
+create table prod (
+ id int not null,
+ name varchar(200) not null,
+ detail int not null
+);
+
+drop table if exists computer;
+create table computer (
+ id int not null,
+ cpu varchar(200) not null
+);
+
+drop table if exists laptop;
+create table laptop (
+ id int not null,
+ weight int not null,
+ resolution varchar(19) not null
+);
+
+drop table if exists server;
+create table server (
+ id int not null,
+ numberOfCPUs int not null,
+ support int not null
+);
+
+drop table if exists car;
+create table car (
+ id int not null,
+ kw int not null,
+ make varchar(200) not null
+);
+
+drop table if exists truck;
+create table truck (
+ id int not null,
+ max_weight int not null
+);
+
+drop table if exists prod_multi;
+create table prod_multi (
+ id1 int not null,
+ id2 int not null,
+ name varchar(200) not null,
+ detail int not null
+);
+
+drop table if exists computer_multi;
+create table computer_multi (
+ id1 int not null,
+ id2 int not null,
+ cpu varchar(200) not null
+);
+
+drop table if exists laptop_multi;
+create table laptop_multi (
+ id1 int not null,
+ id2 int not null,
+ weight int not null,
+ resolution varchar(19) not null
+);
+
+drop table if exists server_multi;
+create table server_multi (
+ id1 int not null,
+ id2 int not null,
+ numberOfCPUs int not null,
+ support int not null
+);
+
+drop table if exists order_product;
+create table order_product (
+ order_id int not null,
+ product_id int not null
+);
+
+drop table if exists table_m;
+create table table_m (
+ id int not null,
+ name varchar(20) not null
+);
+
+drop table if exists table_n;
+create table table_n (
+ id int not null,
+ name varchar(20) not null
+);
+
+drop table if exists m_n;
+create table m_n (
+ m_id int not null,
+ n_id int not null
+);
+
+
+insert into detail (id, category, location) values (1, 'category 1', 'location 1');
+insert into detail (id, category, location) values (2, 'category 2', 'location 2');
+insert into detail (id, category, location) values (3, 'category 3', 'location 3');
+insert into detail (id, category, location) values (4, 'category 4', 'location 4');
+insert into detail (id, category, location) values (5, 'category 5', 'location 5');
+
+insert into prod (id, name, detail) values (1, 'laptop 1', 1);
+insert into computer (id, cpu) values (1, 'centrino');
+insert into laptop (id, weight, resolution) values (1, 2800, '1280');
+
+insert into prod (id, name, detail) values (2, 'laptop 2', 2);
+insert into computer (id, cpu) values (2, 'centrino');
+insert into laptop (id, weight, resolution) values (2, 2700, '1024');
+
+insert into prod (id, name, detail) values (3, 'server 3', 3);
+insert into computer (id, cpu) values (3, 'pentium 4');
+insert into server (id, numberOfCPUs, support) values (3, 4, 3);
+
+insert into prod (id, name, detail) values (4, 'server 4', 4);
+insert into computer (id, cpu) values (4, 'pentium 4');
+insert into server (id, numberOfCPUs, support) values (4, 16,5);
+
+insert into prod (id, name, detail) values (5, 'truck 5', 5);
+insert into car (id, kw, make) values (5, 60, 'make 5');
+insert into truck (id, max_weight) values (5, 4);
+
+insert into prod_multi (id1, id2, name, detail) values (1, 1, 'laptop 1', 1);
+insert into computer_multi (id1, id2, cpu) values (1, 1, 'centrino');
+insert into laptop_multi (id1, id2, weight, resolution) values (1, 1, 2800, '1280');
+
+insert into prod_multi (id1, id2, name, detail) values (2, 2, 'laptop 2', 2);
+insert into computer_multi (id1, id2, cpu) values (2, 2, 'centrino');
+insert into laptop_multi (id1, id2, weight, resolution) values (2, 2, 2700, '1024');
+
+insert into prod_multi (id1, id2, name, detail) values (3, 3, 'server 3', 3);
+insert into computer_multi (id1, id2, cpu) values (3, 3, 'pentium 4');
+insert into server_multi (id1, id2, numberOfCPUs, support) values (3, 3, 4, 3);
+
+insert into prod_multi (id1, id2, name, detail) values (4, 4, 'server 4', 4);
+insert into computer_multi (id1, id2, cpu) values (4, 4, 'pentium 4');
+insert into server_multi (id1, id2, numberOfCPUs, support) values (4, 4, 16,5);
+
+insert into owner (id, name, product) values (1, 'owner 1', 1);
+
+insert into ordr (id, name) values (1, 'order 1');
+
+insert into order_product (order_id, product_id) values (1, 1);
+insert into order_product (order_id, product_id) values (1, 2);
+
+insert into m_n (m_id, n_id) values (1, 1);
+insert into m_n (m_id, n_id) values (1, 2);
+
+insert into table_m (id, name) values (1, "m1");
+insert into table_m (id, name) values (2, "m2");
+
+insert into table_n (id, name) values (1, "n1");
+insert into table_n (id, name) values (2, "n2");
+
+-- tests for bug 1197
+
+/*
+* Two objects, a Derived and a Container.
+* Since Derived derives from Base there is a row in Base too.
+* The Container id = 200
+* The Derived id = 100
+*/
+DROP TABLE IF EXISTS base;
+CREATE TABLE base (
+ id varchar(64) NOT NULL default '',
+ color varchar(64) default NULL,
+ PRIMARY KEY (ID)
+) ;
+
+INSERT INTO base VALUES ('100','red');
+
+DROP TABLE IF EXISTS derived;
+CREATE TABLE derived (
+ id varchar(64) NOT NULL default '',
+ scent varchar(64) default NULL,
+ PRIMARY KEY (ID)
+) ;
+INSERT INTO derived VALUES ('100','vanilla');
+
+
+DROP TABLE IF EXISTS container;
+CREATE TABLE container (
+ id varchar(64) NOT NULL default '',
+ reference varchar(64) default NULL,
+ PRIMARY KEY (ID)
+) ;
+INSERT INTO container VALUES ('200','100');
+
+
+
Index: polymorphism/jdo-conf.xml
===================================================================
RCS file: polymorphism/jdo-conf.xml
diff -N polymorphism/jdo-conf.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/jdo-conf.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: polymorphism/mapping.xml
===================================================================
RCS file: polymorphism/mapping.xml
diff -N polymorphism/mapping.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ polymorphism/mapping.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,290 @@
+
+
+
+
+
+
+
+ Product definition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Computer definition, extends generic product
+
+
+
+
+
+
+
+
+
+
+
+ Laptop definition, extends generic computer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Server definition, extends generic computer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Car definition, extends generic product
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Truck definition, extends generic car
+
+
+
+
+
+
+
+
+
+
+
+ ProductMulti definition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ComputerMulti definition, extends generic
+ product
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LaptopMulti definition, extends generic
+ computer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ServerMulti definition, extends generic
+ computer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Owner definition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Product detail definition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Order definition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ M definition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N definition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: test1197/Base.java
===================================================================
RCS file: test1197/Base.java
diff -N test1197/Base.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1197/Base.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,16 @@
+package test1197;
+
+public class Base {
+ private String id;
+ private String color;
+
+ public String getId() { return this.id; }
+ public void setId(String id) { this.id = id; }
+
+ public String getColor() { return this.color; }
+ public void setColor(String color) { this.color = color; }
+
+ public String toString(){
+ return super.toString() + " Base: id=" + this.id + ",color=" + this.color;
+ }
+}
Index: test1197/Container.java
===================================================================
RCS file: test1197/Container.java
diff -N test1197/Container.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1197/Container.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,16 @@
+package test1197;
+
+public class Container {
+ private String id;
+ private Base reference;
+
+ public String getId() { return this.id; }
+ public void setId(String id) { this.id = id; }
+
+ public Base getReference() { return this.reference; }
+ public void setReference(Base reference) { this.reference = reference; }
+
+ public String toString(){
+ return super.toString() + "Container: id =" + this.id + ",reference=[" + this.reference + "]";
+ }
+}
Index: test1197/Derived.java
===================================================================
RCS file: test1197/Derived.java
diff -N test1197/Derived.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1197/Derived.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,12 @@
+package test1197;
+
+public class Derived extends Base {
+ private String scent;
+
+ public String getScent() { return this.scent; }
+ public void setScent(String scent) { this.scent = scent; }
+
+ public String toString(){
+ return super.toString() + ", Derived: scent=" + this.scent;
+ }
+}
Index: test1197/Test1197.java
===================================================================
RCS file: test1197/Test1197.java
diff -N test1197/Test1197.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1197/Test1197.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,202 @@
+package test1197;
+
+import junit.framework.TestCase;
+
+import org.exolab.castor.jdo.Database;
+import org.exolab.castor.jdo.JDO2;
+import org.exolab.castor.jdo.OQLQuery;
+import org.exolab.castor.jdo.QueryResults;
+import org.exolab.castor.mapping.Mapping;
+
+public class Test1197 extends TestCase {
+ private static final String JdoConfFile = "jdo-conf.xml";
+ private static final String MappingFile = "mapping.xml";
+ private static final int REPS = 100;
+
+ private Mapping mapping;
+ private JDO2 jdo;
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run( Test1197.class );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.mapping = new Mapping( getClass().getClassLoader() );
+ this.mapping.loadMapping( getClass().getResource( MappingFile ) );
+
+ JDO2.loadConfiguration( getClass().getResource( JdoConfFile ).toString() );
+ this.jdo = JDO2.createInstance( "test" );
+
+ Database db = this.jdo.getDatabase();
+
+ db.begin();
+ OQLQuery query = db.getOQLQuery( "select c from " + Container.class.getName() + " c" );
+ QueryResults results = query.execute();
+ while (results.hasMore()) { db.remove(results.next()); }
+ db.commit();
+
+ db.begin();
+ query = db.getOQLQuery( "select d from " + Derived.class.getName() + " d" );
+ results = query.execute();
+ while (results.hasMore()) { db.remove(results.next()); }
+ db.commit();
+
+ db.begin();
+ query = db.getOQLQuery( "select d from " + Base.class.getName() + " d" );
+ results = query.execute();
+ while (results.hasMore()) { db.remove(results.next()); }
+ db.commit();
+
+ db.begin();
+ try{
+ Derived d = new Derived();
+ d.setId( "100" );
+ d.setColor( "blue" );
+ d.setScent( "parsimmon" );
+ db.create( d );
+
+ Container c = new Container();
+ c.setId( "200" );
+ c.setReference( d );
+ db.create( c );
+
+ db.commit();
+ } catch ( Exception ex ){
+ ex.printStackTrace();
+ db.rollback();
+ throw ex;
+ }
+
+ db.close();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ protected Container loadContainer() throws Exception{
+ Database db = this.jdo.getDatabase();
+ db.begin();
+ Container container;
+ try {
+ container = (Container) db.load( Container.class, "200" );
+ db.commit();
+ } catch ( Exception ex ) {
+ db.rollback();
+ throw ex;
+ } finally {
+ db.close();
+ }
+ return container;
+ }
+
+ private Derived loadDerived() throws Exception{
+ Database db = this.jdo.getDatabase();
+ db.begin();
+ Derived derived;
+ try {
+ derived = (Derived) db.load( Derived.class, "100" );
+ db.commit();
+ } catch ( Exception ex ) {
+ db.rollback();
+ throw ex;
+ } finally {
+ db.close();
+ }
+ return derived;
+ }
+
+ private Container loadContainerThenDerived() throws Exception {
+ Database db = this.jdo.getDatabase();
+ db.begin();
+ Container container = null;
+ Derived derived = null;
+ try {
+ container = (Container) db.load( Container.class, "200" );
+ derived = (Derived) db.load( Derived.class, "100" );
+ db.commit();
+ } catch ( Exception ex ) {
+ db.rollback();
+ throw ex;
+ } finally {
+ db.close();
+ }
+ return container;
+ }
+
+ public void testLoadContainer() {
+ try {
+ System.out.println( "First we load a Container in its own transaction" );
+ System.out.flush();
+ Object o = loadContainer();
+ System.out.println( "loadContainer: " + o );
+ } catch ( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void testLoadDerived() {
+ try {
+ System.out.println( "Second we load a Derived in its own transaction" );
+ System.out.flush();
+ Object o = loadDerived();
+ System.out.println( "loadDerived: " + o );
+ } catch ( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void testLoadContainerThenDerived() {
+ try {
+ System.out.println( "Third we load a Container and a Derived in one transaction" );
+ System.out.flush();
+ Object o = loadContainerThenDerived();
+ System.out.println( "loadContainerThenDerived: " + o);
+ } catch ( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void testLoadContainerAndDerivedThreaded() {
+ int count = 0;
+ try {
+ System.out.println( "Forth we load Container and Derived in seperate "
+ + "threads in their own transactions" );
+ System.out.flush();
+
+ Thread thread = new Thread ( new TreadedContainerLoader() );
+ thread.start();
+
+ for ( int i = 0; i < REPS; i++ ) {
+ count = i;
+ loadDerived();
+ }
+ System.out.println( "First thread successfully loaded " + (count + 1) + " Derived" );
+
+ thread.join();
+ } catch ( Exception ex ) {
+ System.err.println( "Exception on first thread loading Derived on " + (count + 1) + "th try" );
+ System.out.flush();
+ ex.printStackTrace();
+ }
+ }
+
+ class TreadedContainerLoader implements Runnable {
+ public void run() {
+ int count = 0;
+ try {
+ for ( int i = 0; i < REPS; i++ ) {
+ count = i;
+ loadContainer();
+ }
+ System.out.println( "Second thread successfully loaded " + (count + 1) + " Containers" );
+ } catch ( Exception ex ) {
+ System.err.println( "Exception on second thread loading Container on " + (count + 1) + "th try" );
+ System.out.flush();
+ ex.printStackTrace();
+ }
+ }
+ }
+}
Index: test1197/ddl.sql
===================================================================
RCS file: test1197/ddl.sql
diff -N test1197/ddl.sql
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1197/ddl.sql 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,34 @@
+/*
+* Two objects, a Derived and a Container.
+* Since Derived derives from Base there is a row in Base too.
+* The Container id = 200
+* The Derived id = 100
+*/
+DROP TABLE IF EXISTS base;
+CREATE TABLE base (
+ id varchar(64) NOT NULL default '',
+ color varchar(64) default NULL,
+ PRIMARY KEY (ID)
+) ;
+
+INSERT INTO base VALUES ('100','red');
+
+DROP TABLE IF EXISTS derived;
+CREATE TABLE derived (
+ id varchar(64) NOT NULL default '',
+ scent varchar(64) default NULL,
+ PRIMARY KEY (ID)
+) ;
+INSERT INTO derived VALUES ('100','vanilla');
+
+
+DROP TABLE IF EXISTS container;
+CREATE TABLE container (
+ id varchar(64) NOT NULL default '',
+ reference varchar(64) default NULL,
+ PRIMARY KEY (ID)
+) ;
+INSERT INTO container VALUES ('200','100');
+
+
+
Index: test1197/jdo-conf.xml
===================================================================
RCS file: test1197/jdo-conf.xml
diff -N test1197/jdo-conf.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1197/jdo-conf.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: test1197/mapping.xml
===================================================================
RCS file: test1197/mapping.xml
diff -N test1197/mapping.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1197/mapping.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: test1893/Accommodation.java
===================================================================
RCS file: test1893/Accommodation.java
diff -N test1893/Accommodation.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/Accommodation.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,10 @@
+package test1893;
+
+import org.exolab.castor.jdo.TimeStampable;
+
+public class Accommodation extends Product implements TimeStampable {
+ private String _best_season;
+
+ public String getBestSeason() { return _best_season; }
+ public void setBestSeason(String best_season) { _best_season = best_season; }
+}
Index: test1893/ComposedProduct.java
===================================================================
RCS file: test1893/ComposedProduct.java
diff -N test1893/ComposedProduct.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/ComposedProduct.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,49 @@
+package test1893;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.exolab.castor.jdo.TimeStampable;
+
+public class ComposedProduct extends Product implements TimeStampable {
+ private int _id;
+ private String _name;
+ private String _desc;
+ private Vector _sub_products = new Vector();
+
+ private long _timeStamp;
+
+ public int getId() { return _id; }
+ public void setId( int id ) { _id = id; }
+
+ public String getExtraName() { return _name; }
+ public void setExtraName( String name ) { _name = name; }
+
+ public String getExtraDescription() { return _name; }
+ public void setExtraDescription( String name ) { _name = name; }
+
+ public Vector getSubProducts() { return _sub_products; }
+ public void setSubProducts( Vector products ) {
+ Iterator i = products.iterator();
+ while( i.hasNext() ) {
+ ComposedProduct cp = (ComposedProduct)i.next();
+ if ( ! _sub_products.contains( cp ) ) {
+ _sub_products.add( cp );
+ cp.addComposition( this );
+ }
+ }
+ }
+ public void addSubProduct( Product product ) {
+ if ( ! _sub_products.contains( product ) ) {
+ _sub_products.addElement( product );
+ product.addComposition( this );
+ }
+ }
+
+ public void jdoSetTimeStamp(long timeStamp) { _timeStamp = timeStamp; }
+ public long jdoGetTimeStamp() { return _timeStamp; }
+
+ public String toString() {
+ return "";
+ }
+}
Index: test1893/Craft.java
===================================================================
RCS file: test1893/Craft.java
diff -N test1893/Craft.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/Craft.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+package test1893;
+
+import org.exolab.castor.jdo.TimeStampable;
+
+public class Craft extends Product implements TimeStampable { }
Index: test1893/Culture.java
===================================================================
RCS file: test1893/Culture.java
diff -N test1893/Culture.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/Culture.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+package test1893;
+
+import org.exolab.castor.jdo.TimeStampable;
+
+public class Culture extends Product implements TimeStampable { }
Index: test1893/Product.java
===================================================================
RCS file: test1893/Product.java
diff -N test1893/Product.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/Product.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,49 @@
+package test1893;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.exolab.castor.jdo.TimeStampable;
+
+public class Product implements TimeStampable {
+ private int _id;
+ private String _name;
+ private String _desc;
+ private Vector _composition = new Vector();
+
+ private long _timeStamp;
+
+ public int getId() { return _id; }
+ public void setId( int id ) { _id = id; }
+
+ public String getName() { return _name; }
+ public void setName( String name ) { _name = name; }
+
+ public String getDescription() { return _desc; }
+ public void setDescription( String desc ) { _desc = desc; }
+
+ public Vector getCompositions() { return _composition; }
+ public void setCompositions( Vector products ) {
+ Iterator iter = products.iterator();
+ while( iter.hasNext() ) {
+ ComposedProduct cp = (ComposedProduct)iter.next();
+ if ( ! _composition.contains( cp ) ) {
+ _composition.add( cp );
+ cp.addSubProduct( this );
+ }
+ }
+ }
+ public void addComposition( ComposedProduct product ) {
+ if ( ! _composition.contains( product ) ) {
+ _composition.addElement( product );
+ product.addSubProduct( this );
+ }
+ }
+
+ public void jdoSetTimeStamp( long timeStamp ) { _timeStamp = timeStamp; }
+ public long jdoGetTimeStamp() { return _timeStamp; }
+
+ public String toString() {
+ return "";
+ }
+}
Index: test1893/Test1893.java
===================================================================
RCS file: test1893/Test1893.java
diff -N test1893/Test1893.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/Test1893.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,167 @@
+package test1893;
+
+import junit.framework.TestCase;
+
+import org.exolab.castor.jdo.Database;
+import org.exolab.castor.jdo.DatabaseNotFoundException;
+import org.exolab.castor.jdo.JDO2;
+import org.exolab.castor.jdo.PersistenceException;
+import org.exolab.castor.mapping.Mapping;
+
+public class Test1893 extends TestCase {
+
+ public static final String JdoConfFile = "jdo-conf.xml";
+ public static final String MappingFile = "mapping.xml";
+
+ private Mapping mapping;
+ private JDO2 jdo;
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run( Test1893.class );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.mapping = new Mapping( getClass().getClassLoader() );
+ this.mapping.loadMapping( getClass().getResource( MappingFile ) );
+
+ JDO2.loadConfiguration( getClass().getResource( JdoConfFile ).toString() );
+ this.jdo = JDO2.createInstance( "1893" );
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCreateProd() throws Exception
+ {
+ Database db = this.jdo.getDatabase();
+ db.setAutoStore( true );
+ db.begin();
+
+ Product pd1 = new Product();
+ pd1.setName( "Product-1" );
+ pd1.setDescription( "Product-1: <30" );
+ db.create( pd1 );
+
+ Product pd2 = new Product();
+ pd2.setName( "Product-2" );
+ pd2.setDescription( "Product-2: <30" );
+ db.create( pd2 );
+
+ db.commit();
+ db.close();
+ }
+
+ public void testCreateCrafts() throws Exception
+ {
+ Database db = this.jdo.getDatabase();
+ db.setAutoStore( true );
+ db.begin();
+
+ Craft crf1 = new Craft();
+ crf1.setName( "Craft-1" );
+ crf1.setDescription( "Craft-1: <30" );
+ db.create( crf1 );
+
+ Craft crf2 = new Craft();
+ crf2.setName( "Craft-2" );
+ crf2.setDescription( "Craft-2: <30" );
+ db.create( crf2 );
+
+ db.commit();
+ db.close();
+ }
+
+ public void testCreateCulture() throws Exception {
+ Database db = this.jdo.getDatabase();
+ db.setAutoStore( true );
+ db.begin();
+
+ Culture cult1 = new Culture();
+ cult1.setName( "Culture-1" );
+ cult1.setDescription( "Culture-1: <30" );
+ db.create( cult1 );
+
+ Culture cult2 = new Culture();
+ cult2.setName( "Culture-2" );
+ cult2.setDescription( "Culture-2: <30" );
+ db.create( cult2 );
+
+ db.commit();
+ db.close();
+ }
+
+ public void testCreateAccomodation() throws Exception {
+ Database db = this.jdo.getDatabase();
+ db.setAutoStore( true );
+ db.begin();
+
+ Accommodation acc1 = new Accommodation();
+ acc1.setName( "Accommodation-1" );
+ acc1.setDescription( "Accommodation-1: <30" );
+ acc1.setBestSeason( "Season-1" );
+ db.create( acc1 );
+
+ Accommodation acc2 = new Accommodation();
+ acc2.setName( "Accommodation-2" );
+ acc2.setDescription( "Accommodation-2: <30" );
+ acc2.setBestSeason( "Season-2" );
+ db.create( acc2 );
+
+ db.commit();
+ db.close();
+ }
+
+ public void testCreateComposed() throws Exception {
+ Database db = this.jdo.getDatabase();
+ db.setAutoStore( true );
+ db.begin();
+
+ ComposedProduct compp1 = new ComposedProduct();
+ compp1.setName( "Composition-1" );
+ compp1.setExtraName( "Xtra-Composition-1" );
+ compp1.setDescription( "Composition-1: <30" );
+ compp1.setExtraDescription( "Xtra-Composition-1: <30" );
+ db.create( compp1 );
+
+ ComposedProduct compp2 = new ComposedProduct();
+ compp2.setName( "Composition-2" );
+ compp2.setExtraName( "Xtra-Composition-2" );
+ compp2.setDescription( "Composition-2: <30" );
+ compp2.setExtraDescription( "Xtra-Composition-2: <30" );
+ db.create( compp2 );
+
+ db.commit();
+ db.close();
+ }
+
+ public void testComposeOffer() throws Exception {
+ Database db = this.jdo.getDatabase();
+ db.setAutoStore( true );
+ db.begin();
+
+ Product pd1 = new Product();
+ pd1.setName( "Just product" );
+ db.create( pd1 );
+
+ Accommodation acc1 = new Accommodation();
+ acc1.setName( "Comp-Accommodation-2" );
+ acc1.setDescription( "Comp-Accommodation-2: <30" );
+ acc1.setBestSeason( "Comp-Season-2" );
+ db.create( acc1 );
+
+ ComposedProduct compp1 = new ComposedProduct();
+ compp1.setName( "Composition-3" );
+ compp1.setExtraName( "Xtra-Composition-3" );
+ compp1.setDescription( "Composition-3: <30" );
+ compp1.setExtraDescription( "Xtra-Composition-3: <30" );
+ compp1.addSubProduct( pd1 );
+ compp1.addSubProduct( acc1 );
+ db.create( compp1 );
+
+ db.commit();
+ db.close();
+ }
+}
Index: test1893/ddl.sql
===================================================================
RCS file: test1893/ddl.sql
diff -N test1893/ddl.sql
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/ddl.sql 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,18 @@
+CREATE TABLE Product(
+ IdProd NUMERIC(10) PRIMARY KEY,
+ NameProd VARCHAR(30) NULL,
+ DescProd VARCHAR(30) NULL);
+
+CREATE TABLE ActProduct(
+ IdAct NUMERIC(10) PRIMARY KEY REFERENCES Product (IdProd),
+ BestSeason VARCHAR(30) NULL);
+
+CREATE TABLE ComposedOffer(
+ IdCOffer NUMERIC(10) PRIMARY KEY REFERENCES Product (IdProd),
+ NameCO VARCHAR(30) NULL,
+ DescCO VARCHAR(30) NULL);
+
+CREATE TABLE OfferComposition(
+ Offer NUMERIC(10),
+ Product NUMERIC(10),
+ CONSTRAINT unique_rel UNIQUE (Offer, Product) );
Index: test1893/jdo-conf.xml
===================================================================
RCS file: test1893/jdo-conf.xml
diff -N test1893/jdo-conf.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/jdo-conf.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: test1893/mapping.xml
===================================================================
RCS file: test1893/mapping.xml
diff -N test1893/mapping.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test1893/mapping.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+