Index: src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java =================================================================== --- src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java (revision 383167) +++ src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java (working copy) @@ -34,6 +34,13 @@ setSku(sku); } + /** Constructor with sku and description + */ + public Product(String sku, String description) { + this(sku); + setDescription(description); + } + public String getDescription() { return description; } Index: src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java =================================================================== --- src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java (revision 383167) +++ src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java (working copy) @@ -72,6 +72,9 @@ entries.add(ce); } + public Iterator getEntries() { + return entries.iterator(); + } public String getCustomerId() { return customerId; } Index: src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java =================================================================== --- src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java (revision 383167) +++ src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java (working copy) @@ -44,10 +44,10 @@ this(cart, id, product, 1); } public CartEntry(Cart cart, long id, Product product, int quantity) { - setCart(cart); setId(id); setProduct(product); setQuantity(quantity); + cart.addCartEntry(this); } public long getId() { Index: src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java (revision 383167) +++ src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java (working copy) @@ -23,14 +23,16 @@ /** * Title: Test SetDetachAllOnCommit *
- * Keywords: KEYWORDS + * Keywords: DetachAllOnCommit commit detach *
- * Assertion IDs: A12.6.8-1 + * Assertion IDs: A12.6.8-1, A12.6.8-2 *
* Assertion Description: * We define a new property called DetachAllOnCommit * PersistenceManager.setDetachAllOnCommit(boolean detachAllOnCommit) * sets the DetachAllOnCommit property + * PersistenceManager.getDetachAllOnCommit() + * The value of the DetachAllOnCommit flag is returned. */ public class SetDetachAllOnCommit extends DetachTest { Index: src/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java (revision 383167) +++ src/java/org/apache/jdo/tck/api/persistencemanager/detach/GetDetachAllOnCommit.java (working copy) @@ -1,72 +0,0 @@ -/* - * 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.persistencemanager.detach; - -import javax.jdo.PersistenceManager; -import javax.jdo.Transaction; -import org.apache.jdo.tck.pc.mylib.PCPoint; -import org.apache.jdo.tck.util.BatchTestRunner; - -/** - * Title: Test GetDetachAllOnCommit - *
- * Keywords: - *
- * Assertion IDs: A12.6.8-2 - *
- * Assertion Description: - * 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-2 (pm.getDetachAllOnCommit) failed: "; - - /** - * The main 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(SetDetachAllOnCommit.class); - } - - /** */ - public void test() { - pm = getPM(); - - runTestGetDetachAllOnCommit(pm); - - pm.close(); - pm = null; - } - - /** */ - protected void runTestGetDetachAllOnCommit(PersistenceManager pm) { - pm.setDetachAllOnCommit(false); - if (pm.getDetachAllOnCommit()) { - fail(ASSERTION_FAILED, - "pm.getDetachAllOnCommit() should return false after setting the flag to false."); - } - - pm.setDetachAllOnCommit(true); - if (!pm.getDetachAllOnCommit()) { - fail(ASSERTION_FAILED, - "pm.getDetachAllOnCommit() should return true after setting the flag to true."); - } - } -} Index: src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java (revision 383167) +++ src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java (working copy) @@ -16,6 +16,11 @@ package org.apache.jdo.tck.api.persistencemanager.detach; +import java.util.Iterator; + +import javax.jdo.FetchPlan; +import javax.jdo.JDOHelper; + import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.shoppingcart.CartEntry; import org.apache.jdo.tck.pc.shoppingcart.Cart; @@ -29,14 +34,144 @@ */ public class DetachTest extends JDO_Test { + protected Cart cart1; + protected CartEntry cartEntry1; + protected Product product1; + + protected Object cart1oid; + + protected Cart goldenCart; + protected CartEntry goldenCartEntry; + + protected Object[] cartClosure; + + protected final static String CART_ENTRIES = "Cart.entries"; + protected final static String CARTENTRY_CART = "CartEntry.cart"; + protected final static String CARTENTRY_PRODUCT = "CartEntry.product"; + protected final static String[] CART_FETCH_GROUPS = new String[] + {FetchPlan.DEFAULT, CART_ENTRIES, CARTENTRY_CART, CARTENTRY_PRODUCT}; + /** Creates a new instance of DetachTest */ public DetachTest() { } + /** */ protected void localSetUp() { addTearDownClass(CartEntry.class); addTearDownClass(Cart.class); addTearDownClass(Product.class); addTearDownClass(Undetachable.class); + + Product goldenProduct = new Product("PRODUCT1", "Product 1"); + goldenCart = new Cart("142857"); + goldenCartEntry = + goldenCart.newCartEntry(goldenProduct, 100); + + product1 = new Product("PRODUCT1", "Product 1"); + cart1 = new Cart("142857"); + cartEntry1 = new CartEntry( + cart1, goldenCartEntry.getId(), product1, 100); + cartClosure = new Object[] + {cart1, cartEntry1, product1}; + + getPM().currentTransaction().begin(); + pm.makePersistent(cart1); + cart1oid = pm.getObjectId(cart1); + pm.currentTransaction().commit(); } + + /** */ + protected void setCartFetchGroups() { + FetchPlan fp = getPM().getFetchPlan(); + fp.setGroups(CART_FETCH_GROUPS); + } + + /** */ + protected void checkState(String location, Object obj, + boolean persistent) { + if(persistent) { + if (JDOHelper.isPersistent(obj)) + return; + } else if (JDOHelper.isDetached(obj)) + return; + appendMessage(location + + " should be " + + (persistent?"persistent":"detached") + + " but is not. The object state is: " + + getStateOfInstance(obj)); + } + + /** */ + protected void reportDifference(String location, + long expected, long actual) { + appendMessage(location + NL + + "expected: " + expected + NL + + "actual: " + actual); + } + + /** */ + protected void reportDifference(String location, + Object expected, Object actual) { + appendMessage(location + NL + + "expected: " + expected + NL + + "actual: " + actual); + } + + /** */ + protected void checkCartValues(String location, Cart cart) { + checkCartValues(location, cart, false); + } + + /** */ + protected void checkCartValues(String location, Cart cart, + boolean persistent) { + checkState(location + "Cart instance", cart, persistent); + if (!goldenCart.getCustomerId().equals(cart.getCustomerId())) + reportDifference(location + + " differences in cart.customerId", + goldenCart.getCustomerId(), cart.getCustomerId()); + Iterator goldenCartEntries = goldenCart.getEntries(); + Iterator cartEntries = cart.getEntries(); + while (cartEntries.hasNext()) { + CartEntry goldenCartEntry = (CartEntry)goldenCartEntries.next(); + CartEntry cartEntry = (CartEntry)cartEntries.next(); + checkState(location + "CartEntry instance", cartEntry, + persistent); + if (cartEntry.getCart() != cart) { + reportDifference(location + + " incorrect value for cartEntry.cart", + cart, cartEntry.getCart()); + } + if (goldenCartEntry.getId() != cartEntry.getId()) + reportDifference(location + + " differences in cartEntry.id", + goldenCartEntry.getId(), cartEntry.getId()); + if (goldenCartEntry.getQuantity() != cartEntry.getQuantity()) + reportDifference(location + + " differences in cartEntry.quantity", + goldenCartEntry.getQuantity(), cartEntry.getQuantity()); + Product goldenProduct = goldenCartEntry.getProduct(); + Product product = cartEntry.getProduct(); + checkState(location + "Product instance", product, + persistent); + if (!goldenProduct.getDescription() + .equals(product.getDescription())) + reportDifference(location + + " differences in product.description", + goldenProduct.getDescription(), product.getDescription()); + } + } + + /** */ + protected Cart createDetachedInstance(String ASSERTION_FAILED) { + getPM().currentTransaction().begin(); + setCartFetchGroups(); + pm.retrieveAll(cartClosure); + pm.setDetachAllOnCommit(true); + pm.currentTransaction().commit(); + checkCartValues(ASSERTION_FAILED + + "after commit with DetachAllOnCommit,", cart1); + failOnError(); + return cart1; + } } Index: src/java/org/apache/jdo/tck/JDO_Test.java =================================================================== --- src/java/org/apache/jdo/tck/JDO_Test.java (revision 383417) +++ src/java/org/apache/jdo/tck/JDO_Test.java (working copy) @@ -83,7 +83,8 @@ private static final int IS_DIRTY = 2; private static final int IS_NEW = 3; private static final int IS_DELETED = 4; - private static final int NUM_STATUSES = 5; + private static final int IS_DETACHED = 5; + private static final int NUM_STATUSES = 6; /* * This table indicates the values returned by the status interrogation @@ -741,6 +742,10 @@ if( existingEntries ) buff.append(", "); buff.append("deleted"); } + if( JDOHelper.isDetached(o) ){ + if( existingEntries ) buff.append(", "); + buff.append("detached"); + } buff.append("}"); return buff.toString(); } @@ -750,12 +755,13 @@ */ public static int currentState(Object o) { - boolean[] status = new boolean[5]; + boolean[] status = new boolean[NUM_STATUSES]; status[IS_PERSISTENT] = JDOHelper.isPersistent(o); status[IS_TRANSACTIONAL] = JDOHelper.isTransactional(o); status[IS_DIRTY] = JDOHelper.isDirty(o); status[IS_NEW] = JDOHelper.isNew(o); status[IS_DELETED] = JDOHelper.isDeleted(o); + status[IS_DETACHED] = JDOHelper.isDetached(o); int i, j; outerloop: for( i = 0; i < NUM_STATES; ++i ){ Index: src/conf/detach.conf =================================================================== --- src/conf/detach.conf (revision 383167) +++ src/conf/detach.conf (working copy) @@ -5,5 +5,9 @@ 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 + org.apache.jdo.tck.api.persistencemanager.detach.DetachCopy \ + org.apache.jdo.tck.api.persistencemanager.detach.DetachAllOnCommit \ + org.apache.jdo.tck.api.persistencemanager.detach.DetachAttach \ + org.apache.jdo.tck.api.persistencemanager.detach.DetachAttachDirty \ + org.apache.jdo.tck.api.persistencemanager.detach.DetachSerialize jdo.tck.requiredOptions = Index: src/conf/jdori-pmf.properties =================================================================== --- src/conf/jdori-pmf.properties (revision 383167) +++ src/conf/jdori-pmf.properties (working copy) @@ -21,5 +21,6 @@ org.jpox.autoCreateColumns=false org.jpox.rdbms.CheckExistTablesOrViews=false org.jpox.autoStartMechanism=None +org.jpox.initializePrimaryKeyColumnInfo=true #org.jpox.connectionPoolingType=DBCP org.jpox.connectionPoolingType=C3P0