Index: entity-persistence/src/java/oracle/toplink/essentials/config/CascadePolicy.java =================================================================== RCS file: entity-persistence/src/java/oracle/toplink/essentials/config/CascadePolicy.java diff -N entity-persistence/src/java/oracle/toplink/essentials/config/CascadePolicy.java *** /dev/null 1 Jan 1970 00:00:00 -0000 --- entity-persistence/src/java/oracle/toplink/essentials/config/CascadePolicy.java 28 Jun 2007 17:49:01 -0000 *************** *** 0 **** --- 1,63 ---- + /* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * // Copyright (c) 1998, 2007, Oracle. All rights reserved. + * + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can obtain + * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html + * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. + * Sun designates this particular file as subject to the "Classpath" exception + * as provided by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the License + * Header, with the fields enclosed by brackets [] replaced by your own + * identifying information: "Portions Copyrighted [year] + * [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + package oracle.toplink.essentials.config; + + /** + * Cascade policy hint values. + * + * The class contains all the valid values for TopLinkQueryHints.REFRESH_CASCADE query hint. + * + * JPA Query Hint Usage: + * + * query.setHint(TopLinkQueryHints.REFRESH_CASCADE, CascadePolicy.CascadeAllParts); + * or + * @QueryHint(name=TopLinkQueryHints.REFRESH_CASCADE, value=CascadePolicy.CascadeAllParts) + * + * Hint values are case-insensitive. + * "" could be used instead of default value CascadePolicy.DEFAULT. + * + * @see TopLinkQueryHints + */ + public class CascadePolicy { + public static final String NoCascading = "NoCascading"; + public static final String CascadePrivateParts = "CascadePrivateParts"; + public static final String CascadeAllParts = "CascadeAllParts"; + public static final String CascadeByMapping = "CascadeByMapping"; + + public static final String DEFAULT = CascadeByMapping; + + } Index: entity-persistence/src/java/oracle/toplink/essentials/config/TopLinkQueryHints.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/config/TopLinkQueryHints.java,v retrieving revision 1.4 diff -c -w -r1.4 TopLinkQueryHints.java *** entity-persistence/src/java/oracle/toplink/essentials/config/TopLinkQueryHints.java 22 May 2007 23:54:15 -0000 1.4 --- entity-persistence/src/java/oracle/toplink/essentials/config/TopLinkQueryHints.java 28 Jun 2007 17:49:01 -0000 *************** *** 51,56 **** --- 51,57 ---- * @see HintValues * @see CacheUsage * @see PessimisticLock + * @see CascadePolicy */ public class TopLinkQueryHints { /** *************** *** 74,77 **** --- 75,83 ---- * "" could be used instead of default value HintValues.FALSE */ public static final String REFRESH = "toplink.refresh"; + + /** + * Valid values are all declared in CascadePolicy class. + */ + public static final String REFRESH_CASCADE = "toplink.refresh.cascade"; } Index: entity-persistence/src/java/oracle/toplink/essentials/internal/ejb/cmp3/base/QueryHintsHandler.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/internal/ejb/cmp3/base/QueryHintsHandler.java,v retrieving revision 1.4 diff -c -w -r1.4 QueryHintsHandler.java *** entity-persistence/src/java/oracle/toplink/essentials/internal/ejb/cmp3/base/QueryHintsHandler.java 22 May 2007 23:54:24 -0000 1.4 --- entity-persistence/src/java/oracle/toplink/essentials/internal/ejb/cmp3/base/QueryHintsHandler.java 28 Jun 2007 17:49:01 -0000 *************** *** 156,161 **** --- 156,162 ---- addHint(new CacheUsageHint()); addHint(new PessimisticLockHint()); addHint(new RefreshHint()); + addHint(new CascadePolicyHint()); } Hint(String name, String defaultValue) { *************** *** 305,310 **** --- 306,332 ---- } } + protected static class CascadePolicyHint extends Hint { + CascadePolicyHint() { + super(TopLinkQueryHints.REFRESH_CASCADE, CascadePolicy.DEFAULT); + valueArray = new Object[][] { + {CascadePolicy.NoCascading, DatabaseQuery.NoCascading}, + {CascadePolicy.CascadePrivateParts, DatabaseQuery.CascadePrivateParts}, + {CascadePolicy.CascadeAllParts, DatabaseQuery.CascadeAllParts}, + {CascadePolicy.CascadeByMapping, DatabaseQuery.CascadeByMapping} + }; + } + + void applyToDatabaseQuery(Object valueToApply, DatabaseQuery query) { + // this time cascade policy make sense only for read query with refresh option + // However cascade policy is generic property for DatabaseQuery, + // therefore can have a meaning for other types of query in the future. + if (query.isObjectLevelReadQuery()) { + query.setCascadePolicy((Integer)valueToApply); + } + } + } + protected static class PessimisticLockHint extends Hint { PessimisticLockHint() { super(TopLinkQueryHints.PESSIMISTIC_LOCK, PessimisticLock.DEFAULT); Index: entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java =================================================================== RCS file: /cvs/glassfish/entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java,v retrieving revision 1.55 diff -c -w -r1.55 EntityManagerJUnitTestSuite.java *** entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java 21 Jun 2007 23:40:27 -0000 1.55 --- entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/advanced/EntityManagerJUnitTestSuite.java 28 Jun 2007 17:49:03 -0000 *************** *** 53,58 **** --- 53,59 ---- import junit.framework.*; import oracle.toplink.essentials.config.CacheUsage; + import oracle.toplink.essentials.config.CascadePolicy; import oracle.toplink.essentials.config.PessimisticLock; import oracle.toplink.essentials.config.TopLinkProperties; import oracle.toplink.essentials.config.TopLinkQueryHints; *************** *** 60,65 **** --- 61,67 ---- import oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl; import oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer; import oracle.toplink.essentials.internal.helper.Helper; + import oracle.toplink.essentials.queryframework.DatabaseQuery; import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery; import oracle.toplink.essentials.tools.schemaframework.SchemaManager; import oracle.toplink.essentials.testing.framework.junit.JUnitTestCase; *************** *** 2209,2214 **** --- 2211,2229 ---- query.setHint(TopLinkQueryHints.REFRESH, ""); assertFalse(olrQuery.shouldRefreshIdentityMapResult()); + //cascade policy + query.setHint(TopLinkQueryHints.REFRESH_CASCADE, CascadePolicy.NoCascading); + assertTrue(olrQuery.getCascadePolicy()==DatabaseQuery.NoCascading); + query.setHint(TopLinkQueryHints.REFRESH_CASCADE, CascadePolicy.CascadeByMapping); + assertTrue(olrQuery.getCascadePolicy()==DatabaseQuery.CascadeByMapping); + query.setHint(TopLinkQueryHints.REFRESH_CASCADE, CascadePolicy.CascadeAllParts); + assertTrue(olrQuery.getCascadePolicy()==DatabaseQuery.CascadeAllParts); + query.setHint(TopLinkQueryHints.REFRESH_CASCADE, CascadePolicy.CascadePrivateParts); + assertTrue(olrQuery.getCascadePolicy()==DatabaseQuery.CascadePrivateParts); + // reset to the original state + query.setHint(TopLinkQueryHints.REFRESH_CASCADE, ""); + assertTrue(olrQuery.getCascadePolicy()==DatabaseQuery.CascadeByMapping); + em.close(); }