db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject svn commit: r366036 - in /db/jdo/trunk/tck20: ./ test/conf/ test/java/org/apache/jdo/tck/api/jdohelper/ test/java/org/apache/jdo/tck/api/persistencemanager/detach/ test/java/org/apache/jdo/tck/pc/shoppingcart/ test/jdo/applicationidentity/org/apache/jd...
Date Thu, 05 Jan 2006 00:38:45 GMT
Author: madams
Date: Wed Jan  4 16:38:21 2006
New Revision: 366036

URL: http://svn.apache.org/viewcvs?rev=366036&view=rev
Log:
JDO-272 Checking in some code so as not to lose it.  Some tests work, but IsDetached is currently
broken.

Added:
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/jdohelper/IsDetached.java
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Product.java
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Undetachable.java
    db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/shoppingcart/
    db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
    db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/shoppingcart/
    db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
    db/jdo/trunk/tck20/test/sql/derby/applicationidentity/schema8.sql
    db/jdo/trunk/tck20/test/sql/derby/datastoreidentity/schema8.sql
Modified:
    db/jdo/trunk/tck20/project.properties
    db/jdo/trunk/tck20/test/conf/alltests.conf
    db/jdo/trunk/tck20/test/conf/detach.conf
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java
    db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java

Modified: db/jdo/trunk/tck20/project.properties
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/project.properties?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- db/jdo/trunk/tck20/project.properties (original)
+++ db/jdo/trunk/tck20/project.properties Wed Jan  4 16:38:21 2006
@@ -191,7 +191,11 @@
     org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldPrimitiveshort.java \
     org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldShort.java \
     org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldString.java \
-    org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldDate.java
+    org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldDate.java \
+    org/apache/jdo/tck/pc/shoppingcart/Undetachable.java \
+    org/apache/jdo/tck/pc/shoppingcart/Cart.java \
+    org/apache/jdo/tck/pc/shoppingcart/Product.java \
+    org/apache/jdo/tck/pc/shoppingcart/CartEntry.java
 
 jdo.tck.pcclasses.files = \
     org/apache/jdo/tck/api/instancecallbacks/InstanceLifecycleListenerAttach$PC.class \
@@ -292,7 +296,11 @@
     org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldPrimitiveshort.class \
     org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldShort.class \
     org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldString.class \
-    org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldDate.class
+    org/apache/jdo/tck/pc/singlefieldidentity/PCPointSingleFieldDate.class\
+    org/apache/jdo/tck/pc/shoppingcart/Undetachable.class \
+    org/apache/jdo/tck/pc/shoppingcart/Cart.class \
+    org/apache/jdo/tck/pc/shoppingcart/Product.class \
+    org/apache/jdo/tck/pc/shoppingcart/CartEntry.class
 
 jdo.tck.paclasses.sources = \
     org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java \
@@ -383,4 +391,5 @@
     org/apache/jdo/tck/pc/mylib/PCClass.jdo \
     org/apache/jdo/tck/pc/query/package.jdo \
     org/apache/jdo/tck/pc/singlefieldidentity/package.jdo \
+    org/apache/jdo/tck/pc/shoppingcart/package.jdo \
     org/apache/jdo/tck/package.jdo

Modified: db/jdo/trunk/tck20/test/conf/alltests.conf
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/conf/alltests.conf?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/conf/alltests.conf (original)
+++ db/jdo/trunk/tck20/test/conf/alltests.conf Wed Jan  4 16:38:21 2006
@@ -154,6 +154,9 @@
 org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientFieldsPreservedUnchanged
\
 org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientHasNoEffectOnTransientInstances
\
 org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientNotSubjectToRollback \
+org.apache.jdo.tck.api.jdohelper.IsDetached \
+org.apache.jdo.tck.api.persistencemanager.detach.SetDetachAllOnCommit \
+org.apache.jdo.tck.api.persistencemanager.detach.GetDetachAllOnCommit \
 org.apache.jdo.tck.api.persistencemanagerfactory.AfterCloseGetPMThrowsException \
 org.apache.jdo.tck.api.persistencemanagerfactory.AfterCloseSetMethodsThrowException \
 org.apache.jdo.tck.api.persistencemanagerfactory.AfterGetPersistenceManagerNoSetMethodsSucceed
\

Modified: db/jdo/trunk/tck20/test/conf/detach.conf
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/conf/detach.conf?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/conf/detach.conf (original)
+++ db/jdo/trunk/tck20/test/conf/detach.conf Wed Jan  4 16:38:21 2006
@@ -1,8 +1,9 @@
 jdo.tck.description = Detachment tests with standard mapping, no testdata. 
 jdo.tck.testdata = 
 jdo.tck.standarddata = 
-jdo.tck.mapping = 0
+jdo.tck.mapping = 8
 jdo.tck.classes = \
+    org.apache.jdo.tck.api.jdohelper.IsDetached \
     org.apache.jdo.tck.api.persistencemanager.detach.SetDetachAllOnCommit \
     org.apache.jdo.tck.api.persistencemanager.detach.GetDetachAllOnCommit
 jdo.tck.requiredOptions =

Added: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/jdohelper/IsDetached.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/jdohelper/IsDetached.java?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/jdohelper/IsDetached.java (added)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/jdohelper/IsDetached.java Wed Jan
 4 16:38:21 2006
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.api.jdohelper;
+
+import org.apache.jdo.tck.api.persistencemanager.detach.DetachTest;
+import org.apache.jdo.tck.pc.shoppingcart.Cart;
+import org.apache.jdo.tck.pc.shoppingcart.Undetachable;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+import javax.jdo.JDOHelper;
+
+/**
+ * <B>Title:</B> Test IsDetached
+ * <BR>
+ * <B>Keywords:</B>
+ * <BR>
+ * <B>Assertion IDs:</B> A8.5.6-1
+ * <BR>
+ * <B>Assertion Description: </B>
+ * Instances that have been detached return true.
+ * The method returns false if the instance is transient or null or if its class is not detachable.
+ */
+public class IsDetached extends DetachTest {
+
+    private static final String ASSERTION_FAILED = "Assertion A8.5.6-1 JDOHelper.isDetached(Object)
failed: ";
+
+    /**
+     * The <code>main</code> is called when the class
+     * is directly executed from the command line.
+     *
+     * @param args The arguments passed to the program.
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(IsDetached.class);
+    }
+
+    public void testNullTransientAndUndetachableIsDetachedFalse() {
+        pm = getPM();
+        pm.currentTransaction().begin();
+
+        assertFalse(ASSERTION_FAILED + "null object is detached", JDOHelper.isDetached(null));
+        assertFalse(ASSERTION_FAILED + "transient object is detached", JDOHelper.isDetached(new
Cart()));
+        assertFalse(ASSERTION_FAILED + "object of class marked not detachabled is detached",
JDOHelper.isDetached(new Undetachable()));
+
+        pm.currentTransaction().commit();
+    }
+
+    public void testDetachableIsDetachedTrue() {
+        pm = getPM();
+        pm.currentTransaction().begin();
+
+        Cart c = new Cart();
+        Object oid = pm.getObjectId(c);
+
+        pm.makePersistent(c);
+        pm.currentTransaction().commit();
+
+        pm.currentTransaction().begin();
+
+        c = (Cart) pm.getObjectById(oid);
+        Cart detached = (Cart) pm.detachCopy(c);
+
+        assertTrue(JDOHelper.isDetached(detached));
+
+        pm.currentTransaction().commit();
+    }
+}

Modified: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
(original)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
Wed Jan  4 16:38:21 2006
@@ -16,15 +16,27 @@
 
 package org.apache.jdo.tck.api.persistencemanager.detach;
 
-import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.shoppingcart.CartEntry;
+import org.apache.jdo.tck.pc.shoppingcart.Cart;
+import org.apache.jdo.tck.pc.shoppingcart.Product;
+import org.apache.jdo.tck.pc.shoppingcart.Undetachable;
+
+import javax.jdo.PersistenceManager;
 
 /**
  *
  */
-public class DetachTest extends PersistenceManagerTest {
-    
+public class DetachTest extends JDO_Test {
+
     /** Creates a new instance of DetachTest */
     public DetachTest() {
     }
-    
+
+    protected void localSetUp() {
+        addTearDownClass(CartEntry.class);
+        addTearDownClass(Cart.class);
+        addTearDownClass(Product.class);
+        addTearDownClass(Undetachable.class);
+    }
 }

Modified: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java
(original)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java
Wed Jan  4 16:38:21 2006
@@ -21,18 +21,20 @@
 import org.apache.jdo.tck.util.BatchTestRunner;
 
 /**
- * <B>Title:</B> Test SetDetachAllOnCommit
+ * <B>Title:</B> Test GetDetachAllOnCommit
  * <BR>
- * <B>Keywords:</B> KEYWORDS
+ * <B>Keywords:</B>
  * <BR>
- * <B>Assertion IDs:</B> A12.6.8-1
+ * <B>Assertion IDs:</B> A12.6.8-2
  * <BR>
  * <B>Assertion Description: </B>
- * We define a new property called DetachOnClose PersistenceManager.setDetachOnClose(boolean
detachOnClose) sets the DetachOnClose property
+ * We define a new property called DetachAllOnCommit
+ * PersistenceManager.getDetachAllOnCommit(boolean detachAllOnCommit)
+ * gets the DetachAllOnCommit property
  */
 public class GetDetachAllOnCommit extends DetachTest {
     
-    private static final String ASSERTION_FAILED = "Assertion A12.6.8-1 (SetDetachAllOnCommit)
failed: ";
+    private static final String ASSERTION_FAILED = "Assertion A12.6.8-2 (pm.getDetachAllOnCommit)
failed: ";
     
     /**
      * The <code>main</code> is called when the class
@@ -68,4 +70,3 @@
         }
     }
 }
-

Modified: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java
(original)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java
Wed Jan  4 16:38:21 2006
@@ -28,11 +28,13 @@
  * <B>Assertion IDs:</B> A12.6.8-1
  * <BR>
  * <B>Assertion Description: </B>
- * We define a new property called DetachAllOnCommit PersistenceManager.getDetachAllOnCommit(boolean
detachAllOnCommit) gets the DetachAllOnCommit property
+ * We define a new property called DetachAllOnCommit
+ * PersistenceManager.setDetachAllOnCommit(boolean detachAllOnCommit)
+ * sets the DetachAllOnCommit property
  */
 public class SetDetachAllOnCommit extends DetachTest {
     
-    private static final String ASSERTION_FAILED = "Assertion A12.6.8-1 (SetDetachAllOnCommit)
failed: ";
+    private static final String ASSERTION_FAILED = "Assertion A12.6.8-1 (pm.setDetachAllOnCommit)
failed: ";
     
     /**
      * The <code>main</code> is called when the class
@@ -68,4 +70,3 @@
         }
     }
 }
-

Added: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java (added)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java Wed Jan  4 16:38:21
2006
@@ -0,0 +1,236 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.shoppingcart;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/** This class represents an online shopping cart.  It has a list of entries of
+ * type CartEntry.
+ */
+public class Cart implements Serializable {
+
+    protected static long nextId = System.currentTimeMillis();
+
+    public synchronized static long nextId() {
+        return nextId++;
+    }
+
+    /** Identity field for use with application identity */
+    protected long id;
+
+    /** The identity of the customer whose shopping cart this is. */
+    protected String customerId;
+
+    /** The list of entries in this cart */
+    protected List entries = new ArrayList(); // element-type CartEntry
+
+    public Cart() {
+        this(nextId());
+    }
+
+    protected Cart(long id) {
+        setId(id);
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    protected void setId(long id) {
+        this.id = id;
+    }
+
+    public CartEntry newCartEntry(Product product, int quantity) {
+        CartEntry ce = new CartEntry(this, CartEntry.nextId(), product, quantity);
+        entries.add(ce);
+        return ce;
+    }
+
+    public void addCartEntry(CartEntry ce) {
+        if (ce == null) {
+            throw new IllegalArgumentException("no CartEntry given");
+        }
+        ce.setCart(this);
+        entries.add(ce);
+    }
+
+    public String getCustomerId() {
+        return customerId;
+    }
+
+    public void setCustomerId(String customerId) {
+        this.customerId = customerId;
+    }
+
+    public void add(int arg0, CartEntry arg1) {
+        entries.add(arg0, arg1);
+    }
+
+    public boolean add(CartEntry arg0) {
+        return entries.add(arg0);
+    }
+
+    public boolean addAll(int arg0, Collection arg1) {
+        Iterator i = arg1.iterator();
+        while (i.hasNext()) {
+            CartEntry entry = (CartEntry) i.next();
+        }
+        return entries.addAll(arg0, arg1);
+    }
+
+    public boolean addAll(Collection arg0) {
+        Iterator i = arg0.iterator();
+        while (i.hasNext()) {
+            CartEntry entry = (CartEntry) i.next();
+        }
+        return entries.addAll(arg0);
+    }
+
+    public void clear() {
+        entries.clear();
+    }
+
+    public boolean contains(CartEntry o) {
+        return entries.contains(o);
+    }
+
+    public boolean containsAll(Collection arg0) {
+        return entries.containsAll(arg0);
+    }
+
+    public CartEntry get(int index) {
+        return (CartEntry) entries.get(index);
+    }
+
+    public int indexOf(CartEntry o) {
+        return entries.indexOf(o);
+    }
+
+    public boolean isEmpty() {
+        return entries.isEmpty();
+    }
+
+    public Iterator iterator() {
+        return entries.iterator();
+    }
+
+    public int lastIndexOf(CartEntry o) {
+        return entries.lastIndexOf(o);
+    }
+
+    public ListIterator listIterator() {
+        return entries.listIterator();
+    }
+
+    public ListIterator listIterator(int index) {
+        return entries.listIterator(index);
+    }
+
+    public Object remove(int index) {
+        return entries.remove(index);
+    }
+
+    public boolean remove(CartEntry o) {
+        return entries.remove(o);
+    }
+
+    public boolean removeAll(Collection arg0) {
+        Iterator i = arg0.iterator();
+        while (i.hasNext()) {
+            CartEntry entry = (CartEntry) i.next();
+        }
+        return entries.removeAll(arg0);
+    }
+
+    public boolean retainAll(Collection arg0) {
+        return entries.retainAll(arg0);
+    }
+
+    public Object set(int arg0, CartEntry arg1) {
+        return entries.set(arg0, arg1);
+    }
+
+    public int entrySize() {
+        return entries.size();
+    }
+
+    public List subList(int fromIndex, int toIndex) {
+        return entries.subList(fromIndex, toIndex);
+    }
+    
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (!(that instanceof Cart)) {
+            return false;
+        }
+        return equals((Cart) that);
+    }
+    
+    public boolean equals(Cart that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        return this.id == that.id;
+    }
+    
+    public int hashCode() {
+        return (int) id;
+    }
+
+    public static class Oid implements Serializable {
+        public long id;
+
+        public Oid() {
+        }
+
+        public Oid(String s) {
+            id = Long.parseLong(justTheId(s));
+        }
+
+        public String toString() {
+            return this.getClass().getName() + ":" + id;
+        }
+
+        public int hashCode() {
+            return (int) id;
+        }
+
+        public boolean equals(Object other) {
+            if (other != null && (other instanceof Oid)) {
+                Oid that = (Oid) other;
+                return that.id == this.id;
+            }
+            return false;
+        }
+
+        protected static String justTheId(String str) {
+            return str.substring(str.indexOf(':') + 1);
+        }
+    }
+}

Added: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java (added)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java Wed Jan
 4 16:38:21 2006
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.shoppingcart;
+
+import java.io.Serializable;
+
+/** This class represents an entry in an online shopping cart that has a
+ * quantity of a product.
+ */ 
+public class CartEntry implements Serializable {
+
+    protected static long nextId = System.currentTimeMillis();
+
+    public synchronized static long nextId() {
+        return nextId++;
+    }
+
+    /** Identity field for use with application identity */
+    protected long id;
+    protected Cart cart;
+    protected Product product;
+    protected int quantity = 1;
+
+    /** No-arg constructor required by JDO; not for public consumption */
+    protected CartEntry() {}
+
+    public CartEntry(Cart cart, Product product) {
+        this(cart, nextId(), product);
+    }
+    public CartEntry(Cart cart, long id, Product product) {
+        this(cart, id, product, 1);
+    }
+    public CartEntry(Cart cart, long id, Product product, int quantity) {
+        setCart(cart);
+        setId(id);
+        setProduct(product);
+        setQuantity(quantity);
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    protected void setId(long id) {
+        this.id = id;
+    }
+
+    public Cart getCart() {
+        return cart;
+    }
+
+    protected void setCart(Cart cart) {
+        if (this.cart != null) {
+            throw new IllegalStateException("Cart already set");
+        }
+        this.cart = cart;
+    }
+
+    public Product getProduct() {
+        return product;
+    }
+
+    public void setProduct(Product product) {
+        this.product = product;
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(int quantity) {
+        if (quantity < 1) {
+            throw new IllegalArgumentException("quantity can't be less than one");
+        }
+        this.quantity = quantity;
+    }
+
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (!(that instanceof CartEntry)) {
+            return false;
+        }
+        return equals((CartEntry) that);
+    }
+    
+    public boolean equals(CartEntry that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        return this.id == that.id;
+    }
+    
+    public int hashCode() {
+        return (int) id;
+    }
+
+    public static class Oid implements Serializable {
+        public long id;
+
+        public Oid() {
+        }
+
+        public Oid(String s) {
+            id = Long.parseLong(justTheId(s));
+        }
+
+        public String toString() {
+            return this.getClass().getName() + ":" + id;
+        }
+
+        public int hashCode() {
+            return (int) id;
+        }
+
+        public boolean equals(Object other) {
+            if (other != null && (other instanceof Oid)) {
+                Oid that = (Oid) other;
+                return that.id == this.id;
+            }
+            return false;
+        }
+
+        protected static String justTheId(String str) {
+            return str.substring(str.indexOf(':') + 1);
+        }
+    }
+}

Added: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Product.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Product.java?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Product.java (added)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Product.java Wed Jan 
4 16:38:21 2006
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.shoppingcart;
+
+import java.io.Serializable;
+
+/** This class represents a product that you would buy from an online store.
+ */
+public class Product implements Serializable {
+
+    /** Identity field when used with application identity */
+    protected String sku;
+
+    protected String description;
+
+    /** No-arg constructor required by JDO; not for public consumption */
+    protected Product() {}
+
+    /** Domain model constructor */
+    public Product(String sku) {
+        setSku(sku);
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getSku() {
+        return sku;
+    }
+
+    public void setSku(String sku) {
+        if (sku == null || (sku = sku.trim()).length() == 0) {
+            throw new IllegalArgumentException("no sku given");
+        }
+        this.sku = sku.toUpperCase();
+    }
+
+    public static class Oid implements Serializable {
+        public String sku;
+
+        public Oid() {
+        }
+
+        public Oid(String s) {
+            sku = justTheSku(s);
+        }
+
+        public String toString() {
+            return this.getClass().getName() + ":" + sku;
+        }
+
+        public int hashCode() {
+            return sku.hashCode();
+        }
+
+        public boolean equals(Object other) {
+            if (other != null && (other instanceof Oid)) {
+                Oid that = (Oid) other;
+                return that.sku.equals(this.sku);
+            }
+            return false;
+        }
+
+        protected static String justTheSku(String str) {
+            return str.substring(str.indexOf(':') + 1);
+        }
+    }
+}

Added: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Undetachable.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Undetachable.java?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Undetachable.java (added)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/shoppingcart/Undetachable.java Wed
Jan  4 16:38:21 2006
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.shoppingcart;
+
+import java.io.Serializable;
+
+/**
+ * This class is a token undetachable class. It is only present to be
+ * persistence-capable but not detachable so as to test that a detachable class
+ * must be declared so.
+ */
+public class Undetachable implements Serializable {
+
+    protected static long nextId = System.currentTimeMillis();
+
+    public synchronized static long nextId() {
+        return nextId++;
+    }
+
+    /** Identity field for use with application identity */
+    protected long id;
+    protected int foo;
+    protected int bar;
+
+    public Undetachable() {
+        this(nextId());
+    }
+
+    public Undetachable(long id) {
+        this.id = id;
+    }
+
+    public static class Oid implements Serializable {
+        public long id;
+
+        public Oid() {
+        }
+
+        public Oid(String s) {
+            id = Long.parseLong(justTheId(s));
+        }
+
+        public String toString() {
+            return this.getClass().getName() + ":" + id;
+        }
+
+        public int hashCode() {
+            return (int) id;
+        }
+
+        public boolean equals(Object other) {
+            if (other != null && (other instanceof Oid)) {
+                Oid that = (Oid) other;
+                return that.id == this.id;
+            }
+            return false;
+        }
+
+        protected static String justTheId(String str) {
+            return str.substring(str.indexOf(':') + 1);
+        }
+    }
+
+    public int getFoo() {
+        return foo;
+    }
+
+    public void setFoo(int foo) {
+        this.foo = foo;
+    }
+
+    public int getBar() {
+        return bar;
+    }
+
+    public void setBar(int bar) {
+        this.bar = bar;
+    }
+}

Added: db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
(added)
+++ db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
Wed Jan  4 16:38:21 2006
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN"
"http://java.sun.com/dtd/jdo_2_0.dtd">
+<jdo>
+    <package name="org.apache.jdo.tck.pc.shoppingcart">
+
+        <class
+                name="Undetachable"
+                identity-type="application"
+                objectid-class="org.apache.jdo.tck.pc.shoppingcart.Undetachable$Oid"
+                detachable="false"
+                >
+            <field name="id" primary-key="true"/>
+        </class>
+
+        <class
+                name="Product"
+                identity-type="application"
+                objectid-class="org.apache.jdo.tck.pc.shoppingcart.Product$Oid"
+                detachable="true"
+                >
+            <field name="sku" primary-key="true"/>
+        </class>
+
+        <class
+                name="Cart"
+                identity-type="application"
+                objectid-class="org.apache.jdo.tck.pc.shoppingcart.Product$Oid"
+                detachable="true"
+                >
+            <field name="id" primary-key="true"/>
+            <field name="entries">
+                <collection element-type="CartEntry"/>
+            </field>
+        </class>
+
+        <class
+                name="CartEntry"
+                identity-type="application"
+                objectid-class="org.apache.jdo.tck.pc.shoppingcart.CartEntry$Oid"
+                detachable="true"
+                >
+            <field name="id" primary-key="true"/>
+        </class>
+    </package>
+</jdo>

Added: db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
(added)
+++ db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/shoppingcart/package.jdo
Wed Jan  4 16:38:21 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN"
"http://java.sun.com/dtd/jdo_2_0.dtd">
+<jdo>
+    <package name="org.apache.jdo.tck.pc.shoppingcart">
+
+        <class
+                name="Undetachable"
+                identity-type="datastore"
+                detachable="false"
+                />
+
+        <class
+                name="Product"
+                identity-type="datastore"
+                detachable="true"
+                />
+
+        <class
+                name="Cart"
+                identity-type="datastore"
+                detachable="true"
+                >
+            <field name="entries">
+                <collection element-type="CartEntry"/>
+            </field>
+        </class>
+
+        <class
+                name="CartEntry"
+                identity-type="datastore"
+                detachable="true"
+                />
+    </package>
+</jdo>

Added: db/jdo/trunk/tck20/test/sql/derby/applicationidentity/schema8.sql
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/sql/derby/applicationidentity/schema8.sql?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/sql/derby/applicationidentity/schema8.sql (added)
+++ db/jdo/trunk/tck20/test/sql/derby/applicationidentity/schema8.sql Wed Jan  4 16:38:21
2006
@@ -0,0 +1,43 @@
+-- SchemaType: application identity
+
+connect 'jdbc:derby:jdotckdb;create=true' user 'tckuser' password 'tckuser';
+
+CREATE SCHEMA applicationidentity8;
+SET SCHEMA applicationidentity8;
+
+DROP TABLE CART_ENTRIES;
+DROP TABLE CARTS;
+DROP TABLE PRODUCTS;
+DROP TABLE UNDETACHABLES;
+
+CREATE TABLE CARTS (
+    CART_ID BIGINT NOT NULL,
+    CUSTOMER_ID INTEGER NOT NULL,
+
+    CONSTRAINT CARTS_PK PRIMARY KEY (CART_ID)
+);
+
+CREATE TABLE PRODUCTS (
+    SKU VARCHAR(48) NOT NULL,
+    DESCRIPTION VARCHAR(128),
+
+    CONSTRAINT PRODUCTS_PK PRIMARY KEY (SKU)
+);
+
+CREATE TABLE CART_ENTRIES (
+    ID BIGINT NOT NULL,
+    CART_ID BIGINT NOT NULL,
+    SKU VARCHAR(48) NOT NULL,
+
+    CONSTRAINT CART_ENTRIES_PK  PRIMARY KEY (ID),
+    CONSTRAINT CARTS_FK         FOREIGN KEY (CART_ID)   REFERENCES CARTS,
+    CONSTRAINT PRODUCTS_FK      FOREIGN KEY (SKU)       REFERENCES PRODUCTS
+);
+
+CREATE TABLE UNDETACHABLES (
+    ID BIGINT NOT NULL,
+    FOO INTEGER,
+    BAR INTEGER,
+
+    CONSTRAINT UNDETACHABLES_PK PRIMARY KEY (ID)
+);

Added: db/jdo/trunk/tck20/test/sql/derby/datastoreidentity/schema8.sql
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/sql/derby/datastoreidentity/schema8.sql?rev=366036&view=auto
==============================================================================
--- db/jdo/trunk/tck20/test/sql/derby/datastoreidentity/schema8.sql (added)
+++ db/jdo/trunk/tck20/test/sql/derby/datastoreidentity/schema8.sql Wed Jan  4 16:38:21 2006
@@ -0,0 +1,43 @@
+-- SchemaType: datastore identity
+
+connect 'jdbc:derby:jdotckdb;create=true' user 'tckuser' password 'tckuser';
+
+CREATE SCHEMA datastoreidentity8;
+SET SCHEMA datastoreidentity8;
+
+DROP TABLE CART_ENTRIES;
+DROP TABLE CARTS;
+DROP TABLE PRODUCTS;
+DROP TABLE UNDETACHABLES;
+
+CREATE TABLE CARTS (
+    CART_ID BIGINT NOT NULL,
+    CUSTOMER_ID INTEGER NOT NULL,
+
+    CONSTRAINT CARTS_PK PRIMARY KEY (CART_ID)
+);
+
+CREATE TABLE PRODUCTS (
+    SKU VARCHAR(48) NOT NULL,
+    DESCRIPTION VARCHAR(128),
+
+    CONSTRAINT PRODUCTS_PK PRIMARY KEY (SKU)
+);
+
+CREATE TABLE CART_ENTRIES (
+    ID BIGINT NOT NULL,
+    CART_ID BIGINT NOT NULL,
+    SKU VARCHAR(48) NOT NULL,
+
+    CONSTRAINT CART_ENTRIES_PK  PRIMARY KEY (ID),
+    CONSTRAINT CARTS_FK         FOREIGN KEY (CART_ID)   REFERENCES CARTS,
+    CONSTRAINT PRODUCTS_FK      FOREIGN KEY (SKU)       REFERENCES PRODUCTS
+);
+
+CREATE TABLE UNDETACHABLES (
+    ID BIGINT NOT NULL,
+    FOO INTEGER,
+    BAR INTEGER,
+
+    CONSTRAINT UNDETACHABLES_PK PRIMARY KEY (ID)
+);



Mime
View raw message