You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(22) |
Nov
(308) |
Dec
(131) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(369) |
Feb
(171) |
Mar
(236) |
Apr
(187) |
May
(218) |
Jun
(217) |
Jul
(127) |
Aug
(448) |
Sep
(270) |
Oct
(231) |
Nov
(422) |
Dec
(255) |
2004 |
Jan
(111) |
Feb
(73) |
Mar
(338) |
Apr
(351) |
May
(349) |
Jun
(495) |
Jul
(394) |
Aug
(1048) |
Sep
(499) |
Oct
(142) |
Nov
(269) |
Dec
(638) |
2005 |
Jan
(825) |
Feb
(1272) |
Mar
(593) |
Apr
(690) |
May
(950) |
Jun
(958) |
Jul
(767) |
Aug
(839) |
Sep
(525) |
Oct
(449) |
Nov
(585) |
Dec
(455) |
2006 |
Jan
(603) |
Feb
(656) |
Mar
(195) |
Apr
(114) |
May
(136) |
Jun
(100) |
Jul
(128) |
Aug
(68) |
Sep
(7) |
Oct
(1) |
Nov
(1) |
Dec
(8) |
2007 |
Jan
(4) |
Feb
(3) |
Mar
(8) |
Apr
(16) |
May
(5) |
Jun
(4) |
Jul
(6) |
Aug
(23) |
Sep
(15) |
Oct
(5) |
Nov
(7) |
Dec
(5) |
2008 |
Jan
(5) |
Feb
(1) |
Mar
(1) |
Apr
(5) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(2) |
2013 |
Jan
(1) |
Feb
|
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(2) |
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <hib...@li...> - 2006-08-09 21:12:59
|
Author: epbernard Date: 2006-08-09 17:12:56 -0400 (Wed, 09 Aug 2006) New Revision: 10237 Modified: trunk/Hibernate3/src/org/hibernate/engine/Cascade.java trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java Log: HHH-1992 avoid cascading checking on lazy properties if it does not make sense Modified: trunk/Hibernate3/src/org/hibernate/engine/Cascade.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-08-09 21:12:00 UTC (rev 10236) +++ trunk/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-08-09 21:12:56 UTC (rev 10237) @@ -241,12 +241,17 @@ CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles(); for ( int i=0; i<types.length; i++) { CascadeStyle style = cascadeStyles[i]; - if ( style.doCascade(action) ) { - // associations cannot be field-level lazy="true", so don't - // need to check that the field is fetched (laziness for - // associations is always done by proxying currently) + EntityMode entityMode = eventSource.getEntityMode(); + if ( persister.getPropertyLaziness()[i] + && ! action.performOnLazyProperty() + && persister.hasUninitializedLazyProperties( parent, entityMode ) + //currently there is no way to lazy a property an not the others + ) { + //do nothing to avoid a lazy property initialization + } + else if ( style.doCascade(action) ) { cascadeProperty( - persister.getPropertyValue( parent, i, eventSource.getEntityMode() ), + persister.getPropertyValue( parent, i, entityMode ), types[i], style, anything, @@ -254,13 +259,16 @@ ); } else { - action.noCascade( - eventSource, - persister.getPropertyValue( parent, i, eventSource.getEntityMode() ), - parent, - persister, - i - ); + + if ( action.requiresNoCascadeChecking() ) { + action.noCascade( + eventSource, + persister.getPropertyValue( parent, i, entityMode ), + parent, + persister, + i + ); + } } } Modified: trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-08-09 21:12:00 UTC (rev 10236) +++ trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-08-09 21:12:56 UTC (rev 10237) @@ -130,6 +130,9 @@ public boolean deleteOrphans() { return false; } + public boolean performOnLazyProperty() { + return false; + } public String toString() { return "ACTION_EVICT"; } @@ -154,6 +157,9 @@ // orphans should be deleted during save/update return true; } + public boolean performOnLazyProperty() { + return false; + } public String toString() { return "ACTION_SAVE_UPDATE"; } @@ -227,6 +233,9 @@ public boolean deleteOrphans() { return false; } + public boolean performOnLazyProperty() { + return false; + } public String toString() { return "ACTION_PERSIST"; } @@ -280,6 +289,9 @@ } } } + public boolean performOnLazyProperty() { + return false; + } private boolean isInManagedState(Object child, EventSource session) { EntityEntry entry = session.getPersistenceContext().getEntry( child ); @@ -350,4 +362,7 @@ return !(collection instanceof PersistentCollection) || ( (PersistentCollection) collection ).wasInitialized(); } + public boolean performOnLazyProperty() { + return true; + } } \ No newline at end of file |
From: <hib...@li...> - 2006-08-09 21:12:03
|
Author: epbernard Date: 2006-08-09 17:12:00 -0400 (Wed, 09 Aug 2006) New Revision: 10236 Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java Log: HHH-1992 Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-08-08 23:08:58 UTC (rev 10235) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-08-09 21:12:00 UTC (rev 10236) @@ -241,12 +241,17 @@ CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles(); for ( int i=0; i<types.length; i++) { CascadeStyle style = cascadeStyles[i]; - if ( style.doCascade(action) ) { - // associations cannot be field-level lazy="true", so don't - // need to check that the field is fetched (laziness for - // associations is always done by proxying currently) + EntityMode entityMode = eventSource.getEntityMode(); + if ( persister.getPropertyLaziness()[i] + && ! action.performOnLazyProperty() + && persister.hasUninitializedLazyProperties( parent, entityMode ) + //currently there is no way to lazy a property an not the others + ) { + //do nothing to avoid a lazy property initialization + } + else if ( style.doCascade(action) ) { cascadeProperty( - persister.getPropertyValue( parent, i, eventSource.getEntityMode() ), + persister.getPropertyValue( parent, i, entityMode ), types[i], style, anything, @@ -254,13 +259,16 @@ ); } else { - action.noCascade( - eventSource, - persister.getPropertyValue( parent, i, eventSource.getEntityMode() ), - parent, - persister, - i - ); + + if ( action.requiresNoCascadeChecking() ) { + action.noCascade( + eventSource, + persister.getPropertyValue( parent, i, entityMode ), + parent, + persister, + i + ); + } } } Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-08-08 23:08:58 UTC (rev 10235) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-08-09 21:12:00 UTC (rev 10236) @@ -130,6 +130,9 @@ public boolean deleteOrphans() { return false; } + public boolean performOnLazyProperty() { + return false; + } public String toString() { return "ACTION_EVICT"; } @@ -154,6 +157,9 @@ // orphans should be deleted during save/update return true; } + public boolean performOnLazyProperty() { + return false; + } public String toString() { return "ACTION_SAVE_UPDATE"; } @@ -227,6 +233,9 @@ public boolean deleteOrphans() { return false; } + public boolean performOnLazyProperty() { + return false; + } public String toString() { return "ACTION_PERSIST"; } @@ -280,6 +289,9 @@ } } } + public boolean performOnLazyProperty() { + return false; + } private boolean isInManagedState(Object child, EventSource session) { EntityEntry entry = session.getPersistenceContext().getEntry( child ); @@ -350,4 +362,7 @@ return !(collection instanceof PersistentCollection) || ( (PersistentCollection) collection ).wasInitialized(); } + public boolean performOnLazyProperty() { + return true; + } } \ No newline at end of file |
From: <hib...@li...> - 2006-08-08 23:09:06
|
Author: epbernard Date: 2006-08-08 19:08:58 -0400 (Tue, 08 Aug 2006) New Revision: 10235 Removed: trunk/HibernateExt/ejb-api/src/javax/persistence/FlushMode.java Modified: trunk/HibernateExt/ejb-api/build.xml trunk/HibernateExt/ejb-api/etc/license.txt trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverrides.java trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverrides.java trunk/HibernateExt/ejb-api/src/javax/persistence/Basic.java trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java trunk/HibernateExt/ejb-api/src/javax/persistence/Column.java trunk/HibernateExt/ejb-api/src/javax/persistence/ColumnResult.java trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorColumn.java trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java trunk/HibernateExt/ejb-api/src/javax/persistence/EmbeddedId.java trunk/HibernateExt/ejb-api/src/javax/persistence/Entity.java trunk/HibernateExt/ejb-api/src/javax/persistence/EntityNotFoundException.java trunk/HibernateExt/ejb-api/src/javax/persistence/EntityResult.java trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java trunk/HibernateExt/ejb-api/src/javax/persistence/FieldResult.java trunk/HibernateExt/ejb-api/src/javax/persistence/GenerationType.java trunk/HibernateExt/ejb-api/src/javax/persistence/Id.java trunk/HibernateExt/ejb-api/src/javax/persistence/IdClass.java trunk/HibernateExt/ejb-api/src/javax/persistence/Inheritance.java trunk/HibernateExt/ejb-api/src/javax/persistence/InheritanceType.java trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumn.java trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumns.java trunk/HibernateExt/ejb-api/src/javax/persistence/JoinTable.java trunk/HibernateExt/ejb-api/src/javax/persistence/Lob.java trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToMany.java trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToOne.java trunk/HibernateExt/ejb-api/src/javax/persistence/MappedSuperclass.java trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQueries.java trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQuery.java trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQueries.java trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQuery.java trunk/HibernateExt/ejb-api/src/javax/persistence/NoResultException.java trunk/HibernateExt/ejb-api/src/javax/persistence/NonUniqueResultException.java trunk/HibernateExt/ejb-api/src/javax/persistence/OneToMany.java trunk/HibernateExt/ejb-api/src/javax/persistence/OneToOne.java trunk/HibernateExt/ejb-api/src/javax/persistence/OrderBy.java trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceContext.java trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumn.java trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumns.java trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTable.java trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTables.java trunk/HibernateExt/ejb-api/src/javax/persistence/SequenceGenerator.java trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMapping.java trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMappings.java trunk/HibernateExt/ejb-api/src/javax/persistence/Table.java trunk/HibernateExt/ejb-api/src/javax/persistence/TableGenerator.java trunk/HibernateExt/ejb-api/src/javax/persistence/Temporal.java trunk/HibernateExt/ejb-api/src/javax/persistence/TemporalType.java trunk/HibernateExt/ejb-api/src/javax/persistence/TransactionRequiredException.java trunk/HibernateExt/ejb-api/src/javax/persistence/Transient.java trunk/HibernateExt/ejb-api/src/javax/persistence/UniqueConstraint.java trunk/HibernateExt/ejb-api/src/javax/persistence/Version.java trunk/HibernateExt/ejb-api/src/javax/persistence/spi/ClassTransformer.java trunk/HibernateExt/ejb-api/src/javax/persistence/spi/PersistenceProvider.java trunk/HibernateExt/ejb-api/src/javax/persistence/spi/PersistenceUnitInfo.java trunk/HibernateExt/ejb-api/src/javax/persistence/spi/PersistenceUnitTransactionType.java Log: licensing fix Modified: trunk/HibernateExt/ejb-api/build.xml =================================================================== --- trunk/HibernateExt/ejb-api/build.xml 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/build.xml 2006-08-08 23:08:58 UTC (rev 10235) @@ -14,7 +14,7 @@ <!-- Name of project and version, used to create filenames --> <property name="name" value="ejb3-persistence"/> - <property name="version" value="public-draft"/> + <property name="version" value="3.0 Final Release"/> <!-- set global properties for this build --> <property name="src.dir" value="src"/> Modified: trunk/HibernateExt/ejb-api/etc/license.txt =================================================================== --- trunk/HibernateExt/ejb-api/etc/license.txt 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/etc/license.txt 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,84 +1,119 @@ -Copyright 2004-2005 Sun Microsystems, Inc. +Specification: JSR-000220 Enterprise JavaBeans v.3.0 ("Specification") +Version: 3.0 +Status: Final Release +Release: 8 May 2006 +Copyright 2006 SUN MICROSYSTEMS, INC. 4150 Network Circle, Santa Clara, California 95054, U.S.A All rights reserved. -NOTICE: The Specification is protected by copyright and the information described therein may be protected -by one or more U.S. patents, foreign patents, or pending applications. Except as provided under -the following license, no part of the Specification may be reproduced in any form by any means without -the prior written authorization of Sun Microsystems, Inc. ("Sun") and its licensors, if any. Any use of the -Specification and the information described therein will be governed by the terms and conditions of this -Agreement. -Subject to the terms and conditions of this license, Sun hereby grants you a fully-paid, non-exclusive, -non-transferable, limited license (without the right to sublicense) under Sun's intellectual property rights -to review the Specification only for the purposes of evaluation. This license includes the right to discuss -the Specification (including the right to provide limited excerpts of text to the extent relevant to the -point[s] under discussion) with other licensees (under this or a substantially similar version of this Agreement) -of the Specification. Other than this limited license, you acquire no right, title or interest in or to -the Specification or any other Sun intellectual property, and the Specification may only be used in accordance -with the license terms set forth herein. This license will expire on the earlier of: (i) two (2) years -from the date of Release listed above; (ii) the date on which the final version of the Specification is publicly -released; or (iii) the date on which the Java Specification Request (JSR) to which the Specification -corresponds is withdrawn. In addition, this license will terminate immediately without notice from Sun -if you fail to comply with any provision of this license. Upon termination, you must cease use of or destroy -the Specification. -TRADEMARKS: No right, title, or interest in or to any trademarks, service marks, or trade names of Sun, -Sun's licensors, Specification Lead or the Specification Lead's licensors is granted hereunder. Sun, Sun -Microsystems, the Sun logo, Java, J2SE, J2EE, J2ME, Java Compatible, the Java Compatible Logo, and -the Java Coffee Cup logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. -and other countries. -DISCLAIMER OF WARRANTIES: THE SPECIFICATION IS PROVIDED "AS IS" AND IS EXPERIMENTAL -AND MAY CONTAIN DEFECTS OR DEFICIENCIES WHICH CANNOT OR WILL -NOT BE CORRECTED BY SUN. SUN MAKES NO REPRESENTATIONS OR WARRANTIES, EITHER -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT THAT -THE CONTENTS OF THE SPECIFICATION ARE SUITABLE FOR ANY PURPOSE OR THAT -ANY PRACTICE OR IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY -THIRD PARTY PATENTS, COPYRIGHTS, TRADE SECRETS OR OTHER RIGHTS. This document -does not represent any commitment to release or implement any portion of the Specification in any product. -THE SPECIFICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL -ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION THEREIN; THESE -CHANGES WILL BE INCORPORATED INTO NEW VERSIONS OF THE SPECIFICATION, IF -ANY. SUN MAY MAKE IMPROVEMENTS AND/OR CHANGES TO THE PRODUCT(S) AND/OR -THE PROGRAM(S) DESCRIBED IN THE SPECIFICATION AT ANY TIME. Any use of such changEnterprise -JavaBeans 3.0, Early Draft Sun Microsystems, Inc. -3 6/24/04 -es in the Specification will be governed by the then-current license for the applicable version of the Specification. -LIMITATION OF LIABILITY: TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT -WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT -LIMITATION, LOST REVENUE, PROFITS OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, -INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS -OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO ANY -FURNISHING, PRACTICING, MODIFYING OR ANY USE OF THE SPECIFICATION, EVEN IF -SUN AND/OR ITS LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -You will hold Sun (and its licensors) harmless from any claims based on your use of the Specification -for any purposes other than the limited right of evaluation as described above, and from any claims that -later versions or releases of any Specification furnished to you are incompatible with the Specification -provided to you under this license. -RESTRICTED RIGHTS LEGEND: If this Software is being acquired by or on behalf of the U.S. Government -or by a U.S. Government prime contractor or subcontractor (at any tier), then the Government's -rights in the Specification and accompanying documentation shall be only as set forth in this license; this -is in accordance with 48 C.F.R. 227.7201 through 227.7202-4 (for Department of Defense (DoD) acquisitions) -and with 48 C.F.R. 2.101 and 12.212 (for non-DoD acquisitions). -REPORT: You may wish to report any ambiguities, inconsistencies or inaccuracies you may find in connection -with your evaluation of the Specification ("Feedback"). To the extent that you provide Sun with -any Feedback, you hereby: (i) agree that such Feedback is provided on a non-proprietary and non-confidential -basis, and (ii) grant Sun a perpetual, non-exclusive, worldwide, fully paid-up, irrevocable license, -with the right to sublicense through multiple levels of sublicensees, to incorporate, disclose, and use -without limitation the Feedback for any purpose related to the Specification and future versions, implementations, -and test suites thereof. -GENERAL TERMS: Any action related to this Agreement will be governed by California law and controlling -U.S. federal law. The U.N. Convention for the International Sale of Goods and the choice of law -rules of any jurisdiction will not apply. +LIMITED LICENSE GRANTS +1. _License for Evaluation Purposes_. Sun hereby grants you a fully-paid, non-exclusive, non-transferable, +worldwide, limited license (without the right to sublicense), under Suns applicable intellectual +property rights to view, download, use and reproduce the Specification only for the purpose of internal +evaluation. This includes (i) developing applications intended to run on an implementation of the Specification, +provided that such applications do not themselves implement any portion(s) of the Specification, +and (ii) discussing the Specification with any third party; and (iii) excerpting brief portions of the +Specification in oral or written communications which discuss the Specification provided that such excerpts +do not in the aggregate constitute a significant portion of the Specification. +2. _License for the Distribution of Compliant Implementations_. Sun also grants you a perpetual, nonexclusive, +non-transferable, worldwide, fully paid-up, royalty free, limited license (without the right to +sublicense) under any applicable copyrights or, subject to the provisions of subsection 4 below, patent +rights it may have covering the Specification to create and/or distribute an Independent Implementation +of the Specification that: (a) fully implements the Specification including all its required interfaces and +functionality; (b) does not modify, subset, superset or otherwise extend the Licensor Name Space, or include +any public or protected packages, classes, Java interfaces, fields or methods within the Licensor +Name Space other than those required/authorized by the Specification or Specifications being implemented; +and (c) passes the Technology Compatibility Kit (including satisfying the requirements of the +applicable TCK Users Guide) for such Specification ("Compliant Implementation"). In addition, the +foregoing license is expressly conditioned on your not acting outside its scope. No license is granted +hereunder for any other purpose (including, for example, modifying the Specification, other than to the +extent of your fair use rights, or distributing the Specification to third parties). Also, no right, title, or +interest in or to any trademarks, service marks, or trade names of Sun or Suns licensors is granted hereunder. +Java, and Java-related logos, marks and names are trademarks or registered trademarks of Sun Microsystems, +Inc. in the U.S. and other countries. +3. _Pass-through Conditions_. You need not include limitations (a)-(c) from the previous paragraph or +any other particular "pass through" requirements in any license You grant concerning the use of your Independent +Implementation or products derived from it. However, except with respect to Independent Implementations +(and products derived from them) that satisfy limitations (a)-(c) from the previous +paragraph, You may neither: (a) grant or otherwise pass through to your licensees any licenses under +Suns applicable intellectual property rights; nor (b) authorize your licensees to make any claims concerning +their implementations compliance with the Specification in question. +4. _Reciprocity Concerning Patent Licenses_. +a. With respect to any patent claims covered by the license granted under subparagraph 2 above that +would be infringed by all technically feasible implementations of the Specification, such license is conditioned +upon your offering on fair, reasonable and non-discriminatory terms, to any party seeking it +from You, a perpetual, non-exclusive, non-transferable, worldwide license under Your patent rights +which are or would be infringed by all technically feasible implementations of the Specification to develop, +distribute and use a Compliant Implementation. +b With respect to any patent claims owned by Sun and covered by the license granted under subparagraph +2, whether or not their infringement can be avoided in a technically feasible manner when implementing +the Specification, such license shall terminate with respect to such claims if You initiate a claim against +Sun that it has, in the course of performing its responsibilities as the Specification Lead, induced any other +entity to infringe Your patent rights. +c Also with respect to any patent claims owned by Sun and covered by the license granted under subparagraph +2 above, where the infringement of such claims can be avoided in a technically feasible manner +when implementing the Specification such license, with respect to such claims, shall terminate if You +initiate a claim against Sun that its making, having made, using, offering to sell, selling or importing a +Compliant Implementation infringes Your patent rights. +5. _Definitions_. For the purposes of this Agreement: "Independent Implementation" shall mean an implementation +of the Specification that neither derives from any of Suns source code or binary code materials +nor, except with an appropriate and separate license from Sun, includes any of Suns source code +or binary code materials; "Licensor Name Space" shall mean the public class or interface declarations +whose names begin with "java", "javax", "com.sun" or their equivalents in any subsequent naming convention +adopted by Sun through the Java Community Process, or any recognized successors or replacements +thereof; and "Technology Compatibility Kit" or "TCK" shall mean the test suite and +accompanying TCK Users Guide provided by Sun which corresponds to the Specification and that was +available either (i) from Sun 120 days before the first release of Your Independent Implementation that +allows its use for commercial purposes, or (ii) more recently than 120 days from such release but against +which You elect to test Your implementation of the Specification. +This Agreement will terminate immediately without notice from Sun if you breach the Agreement or act +outside the scope of the licenses granted above. +DISCLAIMER OF WARRANTIES +THE SPECIFICATION IS PROVIDED "AS IS". SUN MAKES NO REPRESENTATIONS OR WARRANTIES, +EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT +(INCLUDING AS A CONSEQUENCE OF ANY PRACTICE OR IMPLEMENTATION +OF THE SPECIFICATION), OR THAT THE CONTENTS OF THE SPECIFICATION ARE +SUITABLE FOR ANY PURPOSE. This document does not represent any commitment to release or implement +any portion of the Specification in any product. In addition, the Specification could include technical +inaccuracies or typographical errors. +LIMITATION OF LIABILITY +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS LICENSORS +BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION, LOST REVENUE, +PROFITS OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE +DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +ARISING OUT OF OR RELATED IN ANY WAY TO YOUR HAVING, IMPLEMENTING OR +OTHERWISE USING THE SPECIFICATION, EVEN IF SUN AND/OR ITS LICENSORS HAVE +BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +You will indemnify, hold harmless, and defend Sun and its licensors from any claims arising or resulting +from: (i) your use of the Specification; (ii) the use or distribution of your Java application, applet and/or +implementation; and/or (iii) any claims that later versions or releases of any Specification furnished to +you are incompatible with the Specification provided to you under this license. + +RESTRICTED RIGHTS LEGEND +U.S. Government: If this Specification is being acquired by or on behalf of the U.S. Government or by a +U.S. Government prime contractor or subcontractor (at any tier), then the Governments rights in the +Software and accompanying documentation shall be only as set forth in this license; this is in accordance +with 48 C.F.R. 227.7201 through 227.7202-4 (for Department of Defense (DoD) acquisitions) and with +48 C.F.R. 2.101 and 12.212 (for non-DoD acquisitions). +REPORT +If you provide Sun with any comments or suggestions concerning the Specification ("Feedback"), you +hereby: (i) agree that such Feedback is provided on a non-proprietary and non-confidential basis, and (ii) +grant Sun a perpetual, non-exclusive, worldwide, fully paid-up, irrevocable license, with the right to sublicense +through multiple levels of sublicensees, to incorporate, disclose, and use without limitation the +Feedback for any purpose. +GENERAL TERMS +Any action related to this Agreement will be governed by California law and controlling U.S. federal law. +The U.N. Convention for the International Sale of Goods and the choice of law rules of any jurisdiction +will not apply. The Specification is subject to U.S. export control laws and may be subject to export or import regulations in other countries. Licensee agrees to comply strictly with all such laws and regulations and acknowledges that it has the responsibility to obtain such licenses to export, re-export or import as may be required after delivery to Licensee. -Neither party may assign or otherwise transfer any of its rights or obligations under this Agreement, without -the prior written consent of the other party, except that Sun may assign this Agreement to an affiliated -company. -This Agreement is the parties' entire agreement relating to its subject matter. It supersedes all prior or +This Agreement is the parties entire agreement relating to its subject matter. It supersedes all prior or contemporaneous oral or written communications, proposals, conditions, representations and warranties and prevails over any conflicting or additional terms of any quote, order, acknowledgment, or other communication between the parties relating to its subject matter during the term of this Agreement. No modification to this Agreement will be binding, unless in writing and signed by an authorized representative of each party. -(Sun.pSpec.license.11.14.2003) \ No newline at end of file +Rev. April, 2006 +Sun/Final/Full \ No newline at end of file Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,4 +1,5 @@ -//$Id: $ +//$Id:$ +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Target; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverrides.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverrides.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverrides.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,4 +1,5 @@ -//$Id: $ +//$Id:$ +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Target; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverrides.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverrides.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/AttributeOverrides.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Basic.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Basic.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Basic.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import static java.lang.annotation.ElementType.FIELD; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; /** Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Column.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Column.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Column.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/ColumnResult.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/ColumnResult.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/ColumnResult.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Target; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorColumn.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorColumn.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorColumn.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; /** Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/EmbeddedId.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/EmbeddedId.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/EmbeddedId.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.ElementType; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Entity.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Entity.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Entity.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import static java.lang.annotation.ElementType.TYPE; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/EntityNotFoundException.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/EntityNotFoundException.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/EntityNotFoundException.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -10,16 +10,8 @@ super(); } - public EntityNotFoundException(String message, Throwable cause) { - super( message, cause ); - } - public EntityNotFoundException(String message) { super( message ); } - public EntityNotFoundException(Throwable cause) { - super( cause ); - } - } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/EntityResult.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/EntityResult.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/EntityResult.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Target; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; /** Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/FieldResult.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/FieldResult.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/FieldResult.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Deleted: trunk/HibernateExt/ejb-api/src/javax/persistence/FlushMode.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/FlushMode.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/FlushMode.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,24 +0,0 @@ -/* - * JBoss, the OpenSource EJB server - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package javax.persistence; - - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * @author <a href="mailto:bi...@jb...">Bill Burke</a> - * @version $Revision$ - */ -@Target({METHOD, FIELD}) @Retention(RUNTIME) -public @interface FlushMode { - FlushModeType value() default FlushModeType.AUTO; -} Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/GenerationType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/GenerationType.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/GenerationType.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; /** Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Id.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Id.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Id.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import static java.lang.annotation.ElementType.FIELD; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/IdClass.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/IdClass.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/IdClass.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Inheritance.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Inheritance.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Inheritance.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import static java.lang.annotation.ElementType.TYPE; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/InheritanceType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/InheritanceType.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/InheritanceType.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; /** Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumn.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumn.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumn.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; @@ -9,16 +9,59 @@ import static java.lang.annotation.RetentionPolicy.*; /** + * Is used to specify a mapped column for joining an entity association. + * * @author Emmanuel Bernard */ -@Target({METHOD, FIELD}) @Retention(RUNTIME) +@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface JoinColumn { + /** + * The name of the foreign key column. + * The table in which it is found depends upon the context. If the join is for a OneToOne + * or Many- ToOne mapping, the foreign key column is in the table of the source entity. + * If the join is for a ManyToMany, the foreign key is in a join table. Default (only applies + * if a single join column is used): The concatenation of the following: the name of the referencing + * relationship property or field of the referencing entity; "_"; the name of the referenced primary + * key column. If there is no such referencing relationship property or field in the entity, the join + * column name is formed as the concatenation of the following: the name of the entity; "_"; the name + * of the referenced primary key column. + */ String name() default ""; + /** + * The name of the column referenced by this foreign key column. When used with relationship mappings, + * the referenced column is in the table of the target entity. When used inside a JoinTable annotation, + * the referenced key column is in the entity table of the owning entity, or inverse entity if the join + * is part of the inverse join definition. Default (only applies if single join column is being used): + * The same name as the primary key column of the referenced table. + */ String referencedColumnName() default ""; + /** + * Whether the property is a unique key. This is a shortcut for the UniqueConstraint annotation at the + * table level and is useful for when the unique key constraint is only a single field. It is not + * necessary to explicitly specify this for a join column that corresponds to a primary key that is part + * of a foreign key. + */ boolean unique() default false; + /** + * Whether the foreign key column is nullable + */ boolean nullable() default true; + /** + * Whether the column is included in SQL INSERT statements generated by the persistence provider + */ boolean insertable() default true; + /** + * Whether the column is included in SQL UPDATE statements generated by the persistence provider + */ boolean updatable() default true; + /** + * The SQL fragment that is used when generating the DDL for the column. + * Defaults to the generated SQL for the column. + */ String columnDefinition() default ""; + /** + * The name of the table that contains the column. If a table is not specified, the column is + * assumed to be in the primary table of the applicable entity + */ String table() default ""; } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumns.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumns.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/JoinColumns.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; @@ -9,9 +9,15 @@ import static java.lang.annotation.RetentionPolicy.*; /** + * Defines mapping for the composite foreign keys. + * This annotation groups JoinColumn annotations for the same relationship. + * + * When the JoinColumns annotation is used, both the name and the referencedColumnName + * elements must be specified in each such JoinColumn annotation. + * @author Emmanuel Bernard */ -@Target({METHOD, FIELD}) @Retention(RUNTIME) +@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface JoinColumns { - JoinColumn[] value() default {}; + JoinColumn[] value(); } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/JoinTable.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/JoinTable.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/JoinTable.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Lob.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Lob.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Lob.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import static java.lang.annotation.ElementType.METHOD; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToMany.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToMany.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToMany.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToOne.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToOne.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/ManyToOne.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/MappedSuperclass.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/MappedSuperclass.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/MappedSuperclass.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQueries.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQueries.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQueries.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,17 +1,21 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; -import static java.lang.annotation.ElementType.PACKAGE; import static java.lang.annotation.ElementType.TYPE; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Target; /** + * Is used to specify an array of native SQL named queries. Query names are scoped to the persistence unit + * * @author Emmanuel Bernard */ -@Target({TYPE, PACKAGE}) @Retention(RUNTIME) +@Target({TYPE}) @Retention(RUNTIME) public @interface NamedNativeQueries { + /** + * Array of native SQL named queries + */ NamedNativeQuery [] value (); } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQuery.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQuery.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/NamedNativeQuery.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import static java.lang.annotation.ElementType.*; @@ -8,19 +8,32 @@ import java.lang.annotation.Target; /** + * Is used to specify a native SQL named query. Query names are scoped to the persistence unit. + * * @author Emmanuel Bernard */ -//TODO remove the package target -@Target({TYPE, PACKAGE}) +@Target({TYPE}) @Retention(RUNTIME) public @interface NamedNativeQuery { + /** + * Is used to refer to the query when using the EntityManager methods that create query objects + */ String name(); - + /** + * The SQL query string + */ String query(); + /** + * Vendor-specific query hints + */ QueryHint[] hints() default {}; - + /** + * The class of the result + */ Class resultClass() default void.class; - + /** + * The name of a SqlResultSetMapping, as defined in metadata + */ String resultSetMapping() default ""; // name of SQLResultSetMapping } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQueries.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQueries.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQueries.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,18 +1,21 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; -import static java.lang.annotation.ElementType.PACKAGE; import static java.lang.annotation.ElementType.TYPE; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Target; /** + * Specifies an array of named Java Persistence query language queries. Query names are scoped to the persistence unit. + * * @author Emmanuel Bernard */ -//TODO remove PACKAGE target -@Target({TYPE, PACKAGE}) @Retention(RUNTIME) +@Target({TYPE}) @Retention(RUNTIME) public @interface NamedQueries { + /** + * An array of named Java Persistence query language queries. + */ NamedQuery [] value (); } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQuery.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQuery.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/NamedQuery.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; @@ -8,12 +8,24 @@ import static java.lang.annotation.ElementType.*; /** + * Is used to specify a named query in the Java Persistence query language, which is a static + * query expressed in metadata. Query names are scoped to the persistence unit. + * * @author Emmanuel Bernard */ //TODO remove the mackage target -@Target({TYPE, PACKAGE}) @Retention(RUNTIME) +@Target({TYPE}) @Retention(RUNTIME) public @interface NamedQuery { + /** + * Refers to the query when using the EntityManager methods that create query objects. + */ String name(); + /** + * The query string in the Java Persistence query language + */ String query(); + /** + * Vendor-specific query hints + */ QueryHint[] hints() default {}; } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/NoResultException.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/NoResultException.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/NoResultException.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -2,25 +2,26 @@ package javax.persistence; /** - * Expected an entity result, but none found. + * Thrown by the persistence provider when getSingleResult() is executed on a query and there is no result to return. + * This exception will not cause the current transaction, if one is active, to be marked for roll back. * * @author Emmanuel Bernard */ public class NoResultException extends PersistenceException { + /** + * Constructs a new NoResultException exception with null as its detail message + */ public NoResultException() { super(); } - public NoResultException(String message, Throwable cause) { - super( message, cause ); - } - + /** + * Constructs a new NoResultException exception with the specified detail message. + * + * @param message + */ public NoResultException(String message) { super( message ); } - - public NoResultException(Throwable cause) { - super( cause ); - } } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/NonUniqueResultException.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/NonUniqueResultException.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/NonUniqueResultException.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -2,24 +2,28 @@ package javax.persistence; /** + * Thrown by the persistence provider when getSingleResult() is executed on a query and there is more than + * one result from the query. This exception will not cause the current transaction, if one is active, to be + * marked for roll back. + * * @author Gavin King */ public class NonUniqueResultException extends PersistenceException { + /** + * Constructs a new NonUniqueResultException exception with null as its detail message + */ public NonUniqueResultException() { super(); } + /** + * Constructs a new NonUniqueResultException exception with the specified detail message + * + * @param message + */ public NonUniqueResultException(String message) { super( message ); } - public NonUniqueResultException(String message, Throwable cause) { - super( message, cause ); - } - - public NonUniqueResultException(Throwable cause) { - super( cause ); - } - } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/OneToMany.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/OneToMany.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/OneToMany.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/OneToOne.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/OneToOne.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/OneToOne.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/OrderBy.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/OrderBy.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/OrderBy.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceContext.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceContext.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceContext.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -12,16 +12,30 @@ import java.lang.annotation.Target; /** - * Comment + * Expresses a dependency on an EntityManager persistence context. * * @author <a href="mailto:bi...@jb...">Bill Burke</a> - * @version $Revision$ */ @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) -public @interface PersistenceContext -{ - String name() default ""; - String unitName() default ""; - PersistenceContextType type() default PersistenceContextType.TRANSACTION; +public @interface PersistenceContext { + /** + * The name by which the entity manager is to be accessed in the environment referencing context, + * and is not needed when dependency injection is used. + */ + String name() default ""; + /** + * The name of the persistence unit. If the unitName element is specified, the persistence unit for the + * entity manager that is accessible in JNDI must have the same name. + */ + String unitName() default ""; + /** + * Used to specify properties for the container or persistence provider. Vendor specific properties may be included + * in this set of properties. Properties that are not recognized by a vendor are ignored. + */ + PersistenceProperty[] properties() default {}; + /** + * Specifies whether this is a transaction-scoped persistence context or an extended persistence context. + */ + PersistenceContextType type() default PersistenceContextType.TRANSACTION; } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumn.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumn.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumn.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumns.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumns.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/PrimaryKeyJoinColumns.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; @@ -9,9 +9,14 @@ import static java.lang.annotation.RetentionPolicy.*; /** + * This annotation groups PrimaryKeyJoinColumn annotations. It is used to map composite foreign keys. + * * @author Emmanuel Bernard */ @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface PrimaryKeyJoinColumns { - PrimaryKeyJoinColumn[] value() default {}; + /** + * One or more PrimaryKeyJoinColumn annotations + */ + PrimaryKeyJoinColumn[] value(); } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTable.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTable.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTable.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTables.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTables.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/SecondaryTables.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; @@ -8,9 +8,14 @@ import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; /** + * This annotation is used to specify multiple secondary tables for an entity. + * * @author Emmanuel Bernard */ @Target({TYPE}) @Retention(RUNTIME) public @interface SecondaryTables { - SecondaryTable[] value() default {}; + /** + * The secondary tables for an entity. + */ + SecondaryTable[] value(); } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/SequenceGenerator.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/SequenceGenerator.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/SequenceGenerator.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Retention; @@ -9,13 +9,30 @@ import static java.lang.annotation.RetentionPolicy.*; /** + * This annotation defines a primary key generator that may be referenced by name when a generator + * element is specified for the GeneratedValue annotation. A sequence generator may be specified on + * the entity class or on the primary key field or property. The scope of the generator name is global + * to the persistence unit (across all generator types). + * * @author Emmanuel Bernard */ -//TODO remove Package eventually -@Target({PACKAGE, TYPE, METHOD, FIELD}) @Retention(RUNTIME) +@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface SequenceGenerator { - String name(); - String sequenceName() default ""; - int initialValue() default 1; - int allocationSize() default 50; + /** + * A unique generator name that can be referenced by one or more classes to be the generator for primary key values + */ + String name(); + /** + * The name of the database sequence object from which to obtain primary key values + * Defaults to a provider-chosen value + */ + String sequenceName() default ""; + /** + * The value from which the sequence object is to start generating + */ + int initialValue() default 1; + /** + * The amount to increment by when allocating sequence numbers from the sequence + */ + int allocationSize() default 50; } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMapping.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMapping.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMapping.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -1,5 +1,5 @@ //$Id$ -//EJB3 Specification Copyright 2004, 2005 Sun Microsystems, Inc. +//EJB3 Specification Copyright 2004-2006 Sun Microsystems, Inc. package javax.persistence; import java.lang.annotation.Target; @@ -8,12 +8,22 @@ import java.lang.annotation.RetentionPolicy; /** + * This annotation is used to specify the mapping of the result of a native SQL query + * * @author Emmanuel Bernard */ -//TODO remove the package target -@Target({ElementType.PACKAGE, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface SqlResultSetMapping { + /** + * The name given to the result set mapping, and used to refer to it in the methods of the Query API + */ String name(); + /** + * Specifies the result set mapping to entities + */ EntityResult[] entities() default {}; + /** + * Specifies the result set mapping to scalar values + */ ColumnResult[] columns() default {}; } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMappings.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMappings.java 2006-08-08 23:08:29 UTC (rev 10234) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/SqlResultSetMappings.java 2006-08-08 23:08:58 UTC (rev 10235) @@ -9,10 +9,11 @@ import java.lang.annotation.RetentionPolicy; /** + * This annotation is used to define one or more SqlResultSetMapping + * * @author Emmanuel Bernard */ -//TODO remove Package target -@Target({ElementType.PACKAGE, ElementType.TYPE}) @Retention... [truncated message content] |
From: <hib...@li...> - 2006-08-08 23:08:33
|
Author: epbernard Date: 2006-08-08 19:08:29 -0400 (Tue, 08 Aug 2006) New Revision: 10234 Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/PersistenceMetadata.java Log: more logs Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-08-08 17:14:16 UTC (rev 10233) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-08-08 23:08:29 UTC (rev 10234) @@ -175,6 +175,7 @@ cfg.getEntityResolver() ); for ( PersistenceMetadata metadata : metadataFiles ) { + log.trace( metadata.toString() ); JarVisitor.Filter[] filters = getFilters( metadata.getProps(), integration, metadata.getMappingFiles() ); if ( metadata.getProvider() == null || IMPLEMENTATION_NAME.equalsIgnoreCase( Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/PersistenceMetadata.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2006-08-08 17:14:16 UTC (rev 10233) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2006-08-08 23:08:29 UTC (rev 10234) @@ -6,6 +6,7 @@ import java.util.List; import java.util.Properties; import java.util.Set; +import java.util.Map; import javax.persistence.spi.PersistenceUnitTransactionType; /** @@ -127,4 +128,55 @@ public void setExcludeUnlistedClasses(boolean excludeUnlistedClasses) { this.excludeUnlistedClasses = excludeUnlistedClasses; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append( "PersistenceMetadata [\n") + .append("\tname: ").append(name).append("\n") + .append("\tjtaDataSource: ").append(jtaDatasource).append("\n") + .append("\tnonJtaDataSource: ").append(nonJtaDatasource).append("\n") + .append("\ttransactionType: ").append(transactionType).append("\n") + .append("\tprovider: ").append(provider).append("\n") + .append("\tclasses[\n"); + if (classes != null) { + for (String elt : classes) { + sb.append("\t\t").append( elt ); + } + } + sb.append( "\t]\n") + .append("\tpackages[\n"); + if (packages != null) { + for (String elt : packages) { + sb.append("\t\t").append( elt ).append("\n"); + } + } + sb.append( "\t]\n") + .append("\tmappingFiles[\n"); + if (mappingFiles != null) { + for (String elt : mappingFiles) { + sb.append("\t\t").append( elt ).append("\n"); + } + } + sb.append( "\t]\n") + .append("\tjarFiles[\n"); + if (jarFiles != null) { + for (String elt : jarFiles) { + sb.append("\t\t").append( elt ).append("\n"); + } + } + sb.append( "\t]\n") + .append("\thbmfiles: ") + .append( hbmfiles != null ? hbmfiles.size() : 0 ).append("\n") + .append("\tproperties[\n"); + + if (props != null) { + for ( Map.Entry elt : props.entrySet()) { + sb.append("\t\t").append( elt.getKey() ).append(": ").append( elt.getValue() ).append("\n"); + } + } + sb.append( "\t]").append( "]"); + + return sb.toString(); + } } |
Author: epbernard Date: 2006-08-08 13:14:16 -0400 (Tue, 08 Aug 2006) New Revision: 10233 Added: trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceProperty.java Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManager.java trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManagerFactory.java trunk/HibernateExt/ejb-api/src/javax/persistence/EntityTransaction.java trunk/HibernateExt/ejb-api/src/javax/persistence/EnumType.java trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java trunk/HibernateExt/ejb-api/src/javax/persistence/FlushModeType.java trunk/HibernateExt/ejb-api/src/javax/persistence/OptimisticLockException.java trunk/HibernateExt/ejb-api/src/javax/persistence/Persistence.java trunk/HibernateExt/ejb-api/src/javax/persistence/Query.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java Log: EJB-210 OptimisticLockException get the entity object EJB-211 enhance EJB3 javadoc Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -44,6 +44,7 @@ import org.hibernate.TypeMismatchException; import org.hibernate.QueryException; import org.hibernate.TransientObjectException; +import org.hibernate.StaleObjectStateException; import org.hibernate.ejb.transaction.JoinableCMTTransaction; import org.hibernate.ejb.util.ConfigurationHelper; import org.hibernate.engine.SessionFactoryImplementor; @@ -577,7 +578,14 @@ public void throwPersistenceException(HibernateException e) { if ( e instanceof StaleStateException ) { - throwPersistenceException( new OptimisticLockException( e ) ); + if ( e instanceof StaleObjectStateException ) { + StaleObjectStateException sose = (StaleObjectStateException) e; + Object entity = getSession().load( sose.getEntityName(), sose.getIdentifier() ); + throwPersistenceException( new OptimisticLockException( null, e, entity ) ); + } + else { + throwPersistenceException( new OptimisticLockException( e ) ); + } } else if ( e instanceof ConstraintViolationException ) { //FIXME this is bad cause ConstraintViolationException happens in other circumstances Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -1,10 +1,12 @@ //$Id: $ package org.hibernate.ejb.test.exception; +import java.util.Map; import javax.persistence.EntityManager; +import javax.persistence.EntityNotFoundException; import javax.persistence.OptimisticLockException; -import javax.persistence.EntityNotFoundException; +import org.hibernate.cfg.Environment; import org.hibernate.ejb.test.TestCase; /** @@ -30,11 +32,13 @@ em.getTransaction().begin(); music.setName( "Rock" ); try { + em.flush(); fail("Should raise an optimistic lock exception"); } catch( OptimisticLockException e) { //success + assertEquals( music, e.getEntity() ); } catch( Exception e ) { fail("Should raise an optimistic lock exception"); @@ -60,6 +64,13 @@ } } + @Override + public Map getConfig() { + Map config = super.getConfig(); + config.put( Environment.BATCH_VERSIONED_DATA, "false"); + return config; + } + public Class[] getAnnotatedClasses() { return new Class[] { Music.class Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/AssociationOverride.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -8,9 +8,7 @@ import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.FIELD; -/** - * @author Emmanuel Bernard - */ + @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface AssociationOverride { String name(); Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/CascadeType.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -3,6 +3,30 @@ package javax.persistence; /** + * Defines the set of cascadable operations that are propagated to the associated entity. + * The value cascade=ALL is equivalent to cascade={PERSIST, MERGE, REMOVE, REFRESH}. + * * @author Emmanuel Bernard */ -public enum CascadeType { ALL, PERSIST, MERGE, REMOVE, REFRESH }; +public enum CascadeType { + /** + * Cascade all operations + */ + ALL, + /** + * Cascade persist operations + */ + PERSIST, + /** + * Cascade merge operations + */ + MERGE, + /** + * Cascade remove operations + */ + REMOVE, + /** + * Cascade refresh operations + */ + REFRESH +} Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/DiscriminatorType.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -3,6 +3,21 @@ package javax.persistence; /** + * Defines supported types of the discriminator column + * * @author Emmanuel Bernard */ -public enum DiscriminatorType { STRING, CHAR, INTEGER }; +public enum DiscriminatorType { + /** + * String as the discriminator type + */ + STRING, + /** + * Single character as the discriminator type + */ + CHAR, + /** + * Integer as the discriminator type + */ + INTEGER +}; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManager.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManager.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManager.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -3,10 +3,23 @@ /** * Interface used to interact with the persistence context. + * + * An EntityManager instance is associated with a persistence context. A persistence context is a set of + * entity instances in which for any persistent entity identity there is a unique entity instance. + * Within the persistence context, the entity instances and their lifecycle are managed. This interface + * defines the methods that are used to interact with the persistence context. The EntityManager API is + * used to create and remove persistent entity instances, to find entities by their primary key, and to + * query over entities. + * + * The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit. + * A persistence unit defines the set of all classes that are related or grouped by the application, and + * which must be colocated in their mapping to a single database. + * + * @author Emmanuel Bernard */ public interface EntityManager { /** - * Make an instance managed and persistent. + * Make an entity instance managed and persistent. * * @param entity * @throws EntityExistsException if the entity already exists. @@ -14,6 +27,7 @@ * operation is invoked, or the EntityExistsException or * another PersistenceException may be thrown at commit * time.) + * @throws IllegalStateException if this EntityManager has been closed. * @throws IllegalArgumentException if not an entity * @throws TransactionRequiredException if invoked on a * container-managed entity manager of type @@ -28,6 +42,7 @@ * * @param entity * @return the instance that the state was merged to + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if instance is not an * entity or is a removed entity * @throws TransactionRequiredException if invoked on a @@ -41,6 +56,7 @@ * Remove the entity instance. * * @param entity + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if not an entity * or if a detached entity * @throws TransactionRequiredException if invoked on a @@ -57,6 +73,7 @@ * @param primaryKey * @return the found entity instance or null * if the entity does not exist + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if the first argument does * not denote an entity type or the second * argument is not a valid type for that @@ -78,6 +95,7 @@ * @param entityClass * @param primaryKey * @return the found entity instance + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if the first argument does * not denote an entity type or the second * argument is not a valid type for that @@ -91,6 +109,7 @@ * Synchronize the persistence context to the * underlying database. * + * @throws IllegalStateException if this EntityManager has been closed * @throws TransactionRequiredException if there is * no transaction * @throws PersistenceException if the flush fails @@ -102,6 +121,7 @@ * in the persistence context. * * @param flushMode + * @throws IllegalStateException if this EntityManager has been closed */ public void setFlushMode(FlushModeType flushMode); @@ -110,6 +130,7 @@ * in the persistence context. * * @return flushMode + * @throws IllegalStateException if this EntityManager has been closed */ public FlushModeType getFlushMode(); @@ -119,6 +140,7 @@ * * @param entity * @param lockMode + * @throws IllegalStateException if this EntityManager has been closed * @throws PersistenceException if an unsupported lock call * is made * @throws IllegalArgumentException if the instance is not @@ -133,6 +155,7 @@ * overwriting changes made to the entity, if any. * * @param entity + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if not an entity * or entity is not managed * @throws TransactionRequiredException if invoked on a @@ -149,6 +172,8 @@ * entities to become detached. Changes made to entities that * have not been flushed to the database will not be * persisted. + * + * @throws IllegalStateException if this EntityManager has been closed */ public void clear(); @@ -157,7 +182,8 @@ * context. * * @param entity - * @return + * @return <code>true</code> if the instance belongs to the current persistence context. + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if not an entity */ public boolean contains(Object entity); @@ -168,6 +194,7 @@ * * @param ejbqlString an EJB QL query string * @return the new query instance + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if query string is not valid */ public Query createQuery(String ejbqlString); @@ -178,6 +205,7 @@ * * @param name the name of a query defined in metadata * @return the new query instance + * @throws IllegalStateException if this EntityManager has been closed * @throws IllegalArgumentException if a query has not been * defined with the given name */ @@ -189,6 +217,7 @@ * * @param sqlString a native SQL query string * @return the new query instance + * @throws IllegalStateException if this EntityManager has been closed */ public Query createNativeQuery(String sqlString); @@ -199,6 +228,7 @@ * @param sqlString a native SQL query string * @param resultClass the class of the resulting instance(s) * @return the new query instance + * @throws IllegalStateException if this EntityManager has been closed */ public Query createNativeQuery(String sqlString, Class resultClass); @@ -209,6 +239,7 @@ * @param sqlString a native SQL query string * @param resultSetMapping the name of the result set mapping * @return the new query instance + * @throws IllegalStateException if this EntityManager has been closed */ public Query createNativeQuery(String sqlString, String resultSetMapping); @@ -219,6 +250,7 @@ * of the active transaction to associate it with the current * JTA transaction. * + * @throws IllegalStateException if this EntityManager has been closed * @throws TransactionRequiredException if there is * no transaction. */ @@ -228,7 +260,7 @@ * Return the underlying provider object for the EntityManager, if available. * The result of this method is implementation specific * - * @return + * @throws IllegalStateException if this EntityManager has been closed */ public Object getDelegate(); @@ -242,8 +274,7 @@ * associated with an active transaction, the persistence * context remains managed until the transaction completes. * - * @throws IllegalStateException if the EntityManager - * is container-managed. + * @throws IllegalStateException if the EntityManager is container-managed or has been already closed */ public void close(); Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManagerFactory.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManagerFactory.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/EntityManagerFactory.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -3,6 +3,15 @@ import java.util.Map; +/** + * The EntityManagerFactory interface is used by the application to obtain an + * application-managed entity manager. When the application has finished using + * the entity manager factory, and/or at application shutdown, the application + * should close the entity manager factory. Once an EntityManagerFactory has been + * closed, all its entity managers are considered to be in the closed state. + * + * @author Emmanuel Bernard + */ public interface EntityManagerFactory { /** @@ -33,8 +42,8 @@ void close(); /** - * Indicates whether the factory is open. Returns true - * until the factory has been closed. + * Indicates whether or not this factory is open. Returns + * true until a call to close has been made. */ public boolean isOpen(); } \ No newline at end of file Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/EntityTransaction.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/EntityTransaction.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/EntityTransaction.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -1,6 +1,13 @@ //$Id$ package javax.persistence; +/** + * The EntityTransaction interface is used to control resource transactions + * on resource-local entity managers. The EntityManager.getTransaction() + * method returns the EntityTransaction interface. + * + * @author Emmanuel Bernard + */ public interface EntityTransaction { /** * Start a resource transaction. Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/EnumType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/EnumType.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/EnumType.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -2,9 +2,18 @@ package javax.persistence; /** + * Defines mapping for the enumerated types. The constants of this enumerated type specify how persistent + * property or field should be persisted as a enumerated type. + * * @author Emmanuel Bernard */ public enum EnumType { + /** + * Persist enumerated type property or field as an integer + */ ORDINAL, + /** + * Persist enumerated type property or field as a string + */ STRING } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/FetchType.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -3,6 +3,22 @@ package javax.persistence; /** + * Defines strategies for fetching data from the database. + * The EAGER strategy is a requirement on the persistence provider runtime that data must + * be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime that + * data should be fetched lazily when it is first accessed. The implementation is permitted to + * eagerly fetch data for which the LAZY strategy hint has been specified. In particular, lazy + * fetching might only be available for Basic mappings for which property-based access is used. + * * @author Emmanuel Bernard */ -public enum FetchType { LAZY, EAGER }; +public enum FetchType { + /** + * Defines that data must be lazily fetched + */ + LAZY, + /** + * Defines that data must be eagerly fetched + */ + EAGER +}; Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/FlushModeType.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/FlushModeType.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/FlushModeType.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -2,9 +2,28 @@ package javax.persistence; /** + * Flush mode setting. + * + * When queries are executed within a transaction, if FlushModeType.AUTO is set on the Query object, + * or if the flush mode setting for the persistence context is AUTO (the default) and a flush mode + * setting has not been specified for the Query object, the persistence provider is responsible for + * ensuring that all updates to the state of all entities in the persistence context which could + * potentially affect the result of the query are visible to the processing of the query. + * The persistence provider implementation may achieve this by flushing those entities to the database + * or by some other means. If FlushModeType.COMMIT is set, the effect of updates made to entities in the + * persistence context upon queries is unspecified. + * + * If there is no transaction active, the persistence provider must not flush to the database. + * * @author Gavin King */ -public enum FlushModeType { +public enum FlushModeType { + /** + * Flushing must occur only at transaction commit + */ COMMIT, + /** + * (Default) Flushing to occur at query execution + */ AUTO } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/OptimisticLockException.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/OptimisticLockException.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/OptimisticLockException.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -2,13 +2,23 @@ package javax.persistence; /** + * Thrown by the persistence provider when an optimistic locking conflict occurs. + * This exception may be thrown as part of an API call, a flush or at commit time. + * The current transaction, if one is active, will be marked for rollback. + * * @author Emmanuel Bernard */ public class OptimisticLockException extends PersistenceException { + private Object entity; + public OptimisticLockException() { super(); } + public OptimisticLockException(Object entity) { + this.entity = entity; + } + public OptimisticLockException(Throwable cause) { super( cause ); } @@ -20,4 +30,13 @@ public OptimisticLockException(String message, Throwable cause) { super( message, cause ); } + + public OptimisticLockException(String message, Throwable cause, Object entity) { + super( message, cause ); + this.entity = entity; + } + + public Object getEntity() { + return entity; + } } Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Persistence.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Persistence.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Persistence.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -21,12 +21,26 @@ public static String PERSISTENCE_PROVIDER = PersistenceProvider.class.getName(); - protected static Set<PersistenceProvider> providers = new HashSet<PersistenceProvider>(); + protected static final Set<PersistenceProvider> providers = new HashSet<PersistenceProvider>(); + /** + * Create and return an EntityManagerFactory for the named persistence unit. + * + * @param persistenceUnitName The name of the persistence unit + * @return The factory that creates EntityManagers configured according to the specified persistence unit + */ public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName) { return createEntityManagerFactory( persistenceUnitName, null ); } + /** + * Create and return an EntityManagerFactory for the named persistence unit using the given properties. + * + * @param persistenceUnitName The name of the persistence unit + * @param properties Additional properties to use when creating the factory. The values of these properties override + * any values that may have been configured elsewhere + * @return The factory that creates EntityManagers configured according to the specified persistence unit + */ public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) { EntityManagerFactory emf = null; Added: trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceProperty.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceProperty.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/PersistenceProperty.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -0,0 +1,22 @@ +//$Id: $ +package javax.persistence; + +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + * Describes a single container or persistence provider property. + * Vendor specific properties may be included in the set of properties, and are passed to the persistence + * provider by the container when the entity manager is created. + * Properties that are not recognized by a vendor will be ignored. + * + * @author Emmanuel Bernard + */ +@Target({}) +@Retention(RUNTIME) +public @interface PersistenceProperty { + String name(); + + String value(); +} \ No newline at end of file Modified: trunk/HibernateExt/ejb-api/src/javax/persistence/Query.java =================================================================== --- trunk/HibernateExt/ejb-api/src/javax/persistence/Query.java 2006-08-08 17:12:21 UTC (rev 10232) +++ trunk/HibernateExt/ejb-api/src/javax/persistence/Query.java 2006-08-08 17:14:16 UTC (rev 10233) @@ -14,6 +14,7 @@ * Execute the query and return the query results as a List. * * @return a list of the results + * @throws IllegalStateException f called for a Java Persistence query language UPDATE or DELETE statement */ public List getResultList(); @@ -22,7 +23,8 @@ * * @return the result * @throws EntityNotFoundException if there is no result - * @throws NonUniqueResultException if more than one result + * @throws NonUniqueResultException if more than one resul + * @throws IllegalStateException f called for a Java Persistence query language UPDATE or DELETE statement */ public Object getSingleResult(); @@ -30,6 +32,8 @@ * Execute an update or delete statement. * * @return the number of entities updated or deleted + * @throws IllegalStateException if called for a Java Persistence query language SELECT statement + * @throws TransactionRequiredException if there is no transaction */ public int executeUpdate(); @@ -68,7 +72,7 @@ * @param name the parameter name * @param value * @return the same query instance - * @throws IllegalArgumentException if parameter name does not* correspond to parameter in query + * @throws IllegalArgumentException if parameter name does not correspond to parameter in query * string or argument is of incorrect type */ public Query setParameter(String name, Object value); |
From: <hib...@li...> - 2006-08-08 17:12:28
|
Author: epbernard Date: 2006-08-08 13:12:21 -0400 (Tue, 08 Aug 2006) New Revision: 10232 Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/entity/Java5FeaturesTest.java Log: ANN-409 enumtype implements EntancedType Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java 2006-08-08 13:31:56 UTC (rev 10231) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java 2006-08-08 17:12:21 UTC (rev 10232) @@ -18,8 +18,8 @@ import org.apache.commons.logging.LogFactory; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; +import org.hibernate.usertype.EnhancedUserType; import org.hibernate.usertype.ParameterizedType; -import org.hibernate.usertype.UserType; import org.hibernate.util.ReflectHelper; import org.hibernate.util.StringHelper; @@ -30,7 +30,7 @@ * @author Emmanuel Bernard */ //TODO implements readobject/writeobject to recalculate the enumclasses -public class EnumType implements UserType, ParameterizedType, Serializable { +public class EnumType implements EnhancedUserType, ParameterizedType, Serializable { private static Log log = LogFactory.getLog( EnumType.class ); private static final boolean IS_TRACE_ENABLED; @@ -324,4 +324,46 @@ ois.defaultReadObject(); initEnumValue(); } + + public String objectToSQLString(Object value) { + boolean isOrdinal = isOrdinal( sqlType ); + if ( isOrdinal ) { + int ordinal = ( (Enum) value ).ordinal(); + return Integer.toString( ordinal ); + } + else { + return '\'' + ( (Enum) value ).name() + '\''; + } + } + + public String toXMLString(Object value) { + boolean isOrdinal = isOrdinal( sqlType ); + if ( isOrdinal ) { + int ordinal = ( (Enum) value ).ordinal(); + return Integer.toString( ordinal ); + } + else { + return ( (Enum) value ).name(); + } + } + + public Object fromXMLString(String xmlValue) { + try { + int ordinal = Integer.parseInt( xmlValue ); + Object[] values = enumValues.get( enumClass ); + if ( values == null ) throw new AssertionFailure( "enumValues not preprocessed: " + enumClass ); + if ( ordinal < 0 || ordinal >= values.length ) { + throw new IllegalArgumentException( "Unknown ordinal value for enum " + enumClass + ": " + ordinal ); + } + return values[ordinal]; + } + catch(NumberFormatException e) { + try { + return Enum.valueOf( enumClass, xmlValue ); + } + catch (IllegalArgumentException iae) { + throw new IllegalArgumentException( "Unknown name value for enum " + enumClass + ": " + xmlValue, iae ); + } + } + } } Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/entity/Java5FeaturesTest.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/entity/Java5FeaturesTest.java 2006-08-08 13:31:56 UTC (rev 10231) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/entity/Java5FeaturesTest.java 2006-08-08 17:12:21 UTC (rev 10232) @@ -50,7 +50,12 @@ s = openSession(); tx = s.beginTransaction(); - bid = (Bid) s.get( Bid.class, bid.getId() ); + //bid = (Bid) s.get( Bid.class, bid.getId() ); + bid = (Bid)s.createQuery( "select b from Bid b where b.note = " + + Starred.class.getName() + ".OK and b.editorsNote = " + + Starred.class.getName() + ".GOOD and b.id = :id") + .setParameter( "id", bid.getId() ).uniqueResult(); + //testing constant value assertEquals( Starred.OK, bid.getNote() ); assertEquals( Starred.GOOD, bid.getEditorsNote() ); bid.setNote( null ); |
From: <hib...@li...> - 2006-08-08 13:32:10
|
Author: max...@jb... Date: 2006-08-08 09:31:56 -0400 (Tue, 08 Aug 2006) New Revision: 10231 Modified: trunk/HibernateExt/tools/src/templates/dao/daohome.ftl trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2DaoTest.java Log: HBX-714 Double methods generated in dao layer for named queries with pojo names starting with the same name Modified: trunk/HibernateExt/tools/src/templates/dao/daohome.ftl =================================================================== --- trunk/HibernateExt/tools/src/templates/dao/daohome.ftl 2006-08-06 16:12:09 UTC (rev 10230) +++ trunk/HibernateExt/tools/src/templates/dao/daohome.ftl 2006-08-08 13:31:56 UTC (rev 10231) @@ -220,7 +220,7 @@ } } <#foreach queryName in cfg.namedQueries.keySet()> -<#if queryName.startsWith(clazz.entityName)> +<#if queryName.startsWith(clazz.entityName + ".")> <#assign methname = c2j.unqualify(queryName)> <#assign params = cfg.namedQueries.get(queryName).parameterTypes><#assign argList = c2j.asFinderArgumentList(params, clazz)> <#if jdk5 && methname.startsWith("find")> Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2DaoTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2DaoTest.java 2006-08-06 16:12:09 UTC (rev 10230) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2DaoTest.java 2006-08-08 13:31:56 UTC (rev 10231) @@ -56,6 +56,11 @@ } + public void testNamedQueries() { + + assertTrue(findFirstString("findByNameAndAddress",new File(getOutputDir(), "org/hibernate/tool/hbm2x/AuthorHome.java") ).trim().startsWith( "public List" ) ); + } + protected String getBaseForMappings() { return "org/hibernate/tool/hbm2x/"; } |
Author: ste...@jb... Date: 2006-08-06 12:12:09 -0400 (Sun, 06 Aug 2006) New Revision: 10230 Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml Log: HHH-1980 : disallow combination of <version/> and optimistic-lock Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-06 16:11:24 UTC (rev 10229) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-06 16:12:09 UTC (rev 10230) @@ -2603,7 +2603,7 @@ public void delete(Serializable id, Object version, Object object, SessionImplementor session) throws HibernateException { final int span = getTableSpan(); - boolean isImpliedOptimisticLocking = entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION; + boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned() && entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION; Object[] loadedState = null; if ( isImpliedOptimisticLocking ) { // need to treat this as if it where optimistic-lock="all" (dirty does *not* make sense); Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java 2006-08-06 16:11:24 UTC (rev 10229) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java 2006-08-06 16:12:09 UTC (rev 10230) @@ -253,6 +253,9 @@ if ( optimisticLockMode > Versioning.OPTIMISTIC_LOCK_VERSION && !dynamicUpdate ) { throw new MappingException( "optimistic-lock setting requires dynamic-update=\"true\": " + name ); } + if ( versionPropertyIndex != NO_VERSION_INDX && optimisticLockMode > Versioning.OPTIMISTIC_LOCK_VERSION ) { + throw new MappingException( "version and optimistic-lock are not a valid combination : " + name ); + } hasCollections = foundCollection; hasMutableProperties = foundMutable; Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml 2006-08-06 16:11:24 UTC (rev 10229) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml 2006-08-06 16:12:09 UTC (rev 10230) @@ -7,8 +7,7 @@ <class name="Glarch" table="`glarchez`" proxy="GlarchProxy" - dynamic-update="true" - optimistic-lock="dirty"> + dynamic-update="true"> <!--cache--> <id type="string" column="tha_key" length="32"> |
From: <hib...@li...> - 2006-08-06 16:11:29
|
Author: ste...@jb... Date: 2006-08-06 12:11:24 -0400 (Sun, 06 Aug 2006) New Revision: 10229 Modified: trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java trunk/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml Log: HHH-1980 : disallow combination of <version/> and optimistic-lock Modified: trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java 2006-08-06 09:17:53 UTC (rev 10228) +++ trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java 2006-08-06 16:11:24 UTC (rev 10229) @@ -253,6 +253,9 @@ if ( optimisticLockMode > Versioning.OPTIMISTIC_LOCK_VERSION && !dynamicUpdate ) { throw new MappingException( "optimistic-lock setting requires dynamic-update=\"true\": " + name ); } + if ( versionPropertyIndex != NO_VERSION_INDX && optimisticLockMode > Versioning.OPTIMISTIC_LOCK_VERSION ) { + throw new MappingException( "version and optimistic-lock are not a valid combination : " + name ); + } hasCollections = foundCollection; hasMutableProperties = foundMutable; Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml 2006-08-06 09:17:53 UTC (rev 10228) +++ trunk/Hibernate3/test/org/hibernate/test/legacy/Glarch.hbm.xml 2006-08-06 16:11:24 UTC (rev 10229) @@ -7,8 +7,7 @@ <class name="Glarch" table="`glarchez`" proxy="GlarchProxy" - dynamic-update="true" - optimistic-lock="dirty"> + dynamic-update="true"> <!--cache--> <id type="string" column="tha_key" length="32"> |
From: <hib...@li...> - 2006-08-06 09:18:12
|
Author: ste...@jb... Date: 2006-08-06 05:17:53 -0400 (Sun, 06 Aug 2006) New Revision: 10228 Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java Log: temporary fix for HHH-1980 Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-05 04:28:22 UTC (rev 10227) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-06 09:17:53 UTC (rev 10228) @@ -2603,7 +2603,7 @@ public void delete(Serializable id, Object version, Object object, SessionImplementor session) throws HibernateException { final int span = getTableSpan(); - boolean isImpliedOptimisticLocking = entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION; + boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned() && entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION; Object[] loadedState = null; if ( isImpliedOptimisticLocking ) { // need to treat this as if it where optimistic-lock="all" (dirty does *not* make sense); |
From: <hib...@li...> - 2006-08-05 04:28:26
|
Author: ste...@jb... Date: 2006-08-05 00:28:22 -0400 (Sat, 05 Aug 2006) New Revision: 10227 Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java branches/Branch_3_2/Hibernate3/src/org/hibernate/sql/Delete.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java Log: HHH-1677 : optimistic-lock and delete Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-05 04:27:55 UTC (rev 10226) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-05 04:28:22 UTC (rev 10227) @@ -43,6 +43,7 @@ import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.Versioning; import org.hibernate.engine.ExecuteUpdateResultCheckStyle; +import org.hibernate.engine.EntityKey; import org.hibernate.exception.JDBCExceptionHelper; import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.PostInsertIdentifierGenerator; @@ -1269,7 +1270,7 @@ lockers.put( LockMode.READ, generateLocker( LockMode.READ ) ); lockers.put( LockMode.UPGRADE, generateLocker( LockMode.UPGRADE ) ); lockers.put( LockMode.UPGRADE_NOWAIT, generateLocker( LockMode.UPGRADE_NOWAIT ) ); - lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) ); + //lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) ); } protected LockingStrategy generateLocker(LockMode lockMode) { @@ -1757,9 +1758,9 @@ getPropertyUpdateability() : //optimistic-lock="all", include all updatable properties includeProperty; //optimistic-lock="dirty", include all properties we are updating this time + boolean[] versionability = getPropertyVersionability(); + Type[] types = getPropertyTypes(); for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { - boolean[] versionability = getPropertyVersionability(); - Type[] types = getPropertyTypes(); boolean include = includeInWhere[i] && isPropertyOfTable( i, j ) && versionability[i]; @@ -2233,7 +2234,7 @@ else if ( isNullableTable( j ) && isAllNull( fields, j ) ) { //if all fields are null, we might need to delete existing row isRowToUpdate = true; - delete( id, oldVersion, j, object, getSQLDeleteStrings()[j], session ); + delete( id, oldVersion, j, object, getSQLDeleteStrings()[j], session, null ); } else { //there is probably a row there, so try to update @@ -2370,11 +2371,12 @@ */ protected void delete( final Serializable id, - final Object version, - final int j, - final Object object, - final String sql, - final SessionImplementor session) throws HibernateException { + final Object version, + final int j, + final Object object, + final String sql, + final SessionImplementor session, + final Object[] loadedState) throws HibernateException { if ( isInverseTable( j ) ) { return; @@ -2428,12 +2430,26 @@ // Do the key. The key is immutable so we can use the _current_ object state - not necessarily // the state at the time the delete was issued getIdentifierType().nullSafeSet( delete, id, index, session ); + index += getIdentifierColumnSpan(); // We should use the _current_ object state (ie. after any updates that occurred during flush) if ( useVersion ) { - getVersionType().nullSafeSet( delete, version, getIdentifierColumnSpan() + index, session ); + getVersionType().nullSafeSet( delete, version, index, session ); } + else if ( entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION && loadedState != null ) { + boolean[] versionability = getPropertyVersionability(); + Type[] types = getPropertyTypes(); + for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { + if ( isPropertyOfTable( i, j ) && versionability[i] ) { + // this property belongs to the table and it is not specifically + // excluded from optimistic locking by optimistic-lock="false" + boolean[] settable = types[i].toColumnNullness( loadedState[i], getFactory() ); + types[i].nullSafeSet( delete, loadedState[i], index, settable, session ); + index += ArrayHelper.countTrue( settable ); + } + } + } if ( useBatch ) { session.getBatcher().addToBatch( expectation ); @@ -2586,14 +2602,72 @@ */ public void delete(Serializable id, Object version, Object object, SessionImplementor session) throws HibernateException { + final int span = getTableSpan(); + boolean isImpliedOptimisticLocking = entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION; + Object[] loadedState = null; + if ( isImpliedOptimisticLocking ) { + // need to treat this as if it where optimistic-lock="all" (dirty does *not* make sense); + // first we need to locate the "loaded" state + // + // Note, it potentially could be a proxy, so perform the location the safe way... + EntityKey key = new EntityKey( id, this, session.getEntityMode() ); + Object entity = session.getPersistenceContext().getEntity( key ); + if ( entity != null ) { + EntityEntry entry = session.getPersistenceContext().getEntry( entity ); + loadedState = entry.getLoadedState(); + } + } - final int span = getTableSpan(); + final String[] deleteStrings; + if ( isImpliedOptimisticLocking && loadedState != null ) { + // we need to utilize dynamic delete statements + deleteStrings = generateSQLDeletStrings( loadedState ); + } + else { + // otherwise, utilize the static delete statements + deleteStrings = getSQLDeleteStrings(); + } + for ( int j = span - 1; j >= 0; j-- ) { - delete( id, version, j, object, getSQLDeleteStrings()[j], session ); + delete( id, version, j, object, deleteStrings[j], session, loadedState ); } } + private String[] generateSQLDeletStrings(Object[] loadedState) { + int span = getTableSpan(); + String[] deleteStrings = new String[span]; + for ( int j = span - 1; j >= 0; j-- ) { + Delete delete = new Delete() + .setTableName( getTableName( j ) ) + .setPrimaryKeyColumnNames( getKeyColumns( j ) ); + if ( getFactory().getSettings().isCommentsEnabled() ) { + delete.setComment( "delete " + getEntityName() + " [" + j + "]" ); + } + + boolean[] versionability = getPropertyVersionability(); + Type[] types = getPropertyTypes(); + for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { + if ( isPropertyOfTable( i, j ) && versionability[i] ) { + // this property belongs to the table and it is not specifically + // excluded from optimistic locking by optimistic-lock="false" + String[] propertyColumnNames = getPropertyColumnNames( i ); + boolean[] propertyNullness = types[i].toColumnNullness( loadedState[i], getFactory() ); + for ( int k = 0; k < propertyNullness.length; k++ ) { + if ( propertyNullness[k] ) { + delete.addWhereFragment( propertyColumnNames[k] + " = ?" ); + } + else { + delete.addWhereFragment( propertyColumnNames[k] + " is null" ); + } + } + } + } + deleteStrings[j] = delete.toStatementString(); + } + return deleteStrings; + } + protected void logStaticSQL() { if ( log.isDebugEnabled() ) { log.debug( "Static SQL for entity: " + getEntityName() ); @@ -3596,11 +3670,11 @@ public Type getIdentifierType() { return entityMetamodel.getIdentifierProperty().getType(); } - + public boolean hasSubselectLoadableCollections() { return hasSubselectLoadableCollections; } - + public int[] getNaturalIdentifierProperties() { return entityMetamodel.getNaturalIdentifierProperties(); } @@ -3691,7 +3765,7 @@ public boolean hasNaturalIdentifier() { return entityMetamodel.hasNaturalIdentifier(); } - + public void setPropertyValue(Object object, String propertyName, Object value, EntityMode entityMode) throws HibernateException { getTuplizer( entityMode ).setPropertyValue( object, propertyName, value ); Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/sql/Delete.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/sql/Delete.java 2006-08-05 04:27:55 UTC (rev 10226) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/sql/Delete.java 2006-08-05 04:28:22 UTC (rev 10227) @@ -61,6 +61,16 @@ return this; } + public Delete addWhereFragment(String fragment) { + if ( where == null ) { + where = fragment; + } + else { + where += ( " and " + fragment ); + } + return this; + } + public Delete setPrimaryKeyColumnNames(String[] primaryKeyColumnNames) { this.primaryKeyColumnNames = primaryKeyColumnNames; return this; Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-08-05 04:27:55 UTC (rev 10226) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-08-05 04:28:22 UTC (rev 10227) @@ -1,7 +1,7 @@ <?xml version="1.0"?> -<!DOCTYPE hibernate-mapping PUBLIC - "-//Hibernate/Hibernate Mapping DTD 3.0//EN" - "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> +<!DOCTYPE hibernate-mapping PUBLIC + "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- @@ -12,44 +12,44 @@ --> <hibernate-mapping package="org.hibernate.test.optlock"> - - <class name="Document" - entity-name="Dirty" - table="Document" - optimistic-lock="dirty" - dynamic-update="true"> - <id name="id"> - <generator class="native"/> - </id> - <property name="title"/> - <property name="author"/> - <component name="pubDate"> - <property name="year" not-null="true"/> - <property name="month"/> - </component> - <property name="summary"/> - <property name="totalSales" optimistic-lock="false"/> - <property name="text" column="`text`"/> - </class> - - <class name="Document" - entity-name="All" - table="Document" - optimistic-lock="all" - dynamic-update="true"> - <id name="id"> - <generator class="native"/> - </id> - <property name="title"/> - <property name="author"/> - <component name="pubDate"> - <property name="year" not-null="true"/> - <property name="month"/> - </component> - <property name="summary"/> - <property name="totalSales" optimistic-lock="false"/> - <property name="text" column="`text`"/> - </class> - + + <class name="Document" + entity-name="Dirty" + table="Document" + optimistic-lock="dirty" + dynamic-update="true"> + <id name="id"> + <generator class="native"/> + </id> + <property name="title"/> + <property name="author"/> + <component name="pubDate"> + <property name="year" not-null="true"/> + <property name="month"/> + </component> + <property name="summary"/> + <property name="totalSales" optimistic-lock="false"/> + <property name="text" column="`text`"/> + </class> + + <class name="Document" + entity-name="All" + table="Document" + optimistic-lock="all" + dynamic-update="true"> + <id name="id"> + <generator class="native"/> + </id> + <property name="title"/> + <property name="author"/> + <component name="pubDate"> + <property name="year" not-null="true"/> + <property name="month"/> + </component> + <property name="summary"/> + <property name="totalSales" optimistic-lock="false"/> + <property name="text" column="`text`"/> + </class> + </hibernate-mapping> Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-08-05 04:27:55 UTC (rev 10226) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-08-05 04:28:22 UTC (rev 10227) @@ -10,146 +10,134 @@ import org.hibernate.test.TestCase; /** + * Tests relating to the optimisitc-lock mapping option. + * * @author Gavin King + * @author Steve Ebersole */ public class OptimisticLockTest extends TestCase { - + public OptimisticLockTest(String str) { super(str); } - + + protected String[] getMappings() { + return new String[] { "optlock/Document.hbm.xml" }; + } + + public static Test suite() { + return new TestSuite(OptimisticLockTest.class); + } + public void testOptimisticLockDirty() { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("Dirty", doc); - s.flush(); - doc.setSummary("A modern classic"); - s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); - s.flush(); - s.delete(doc); - t.commit(); - s.close(); + testUpdateOptimisticLockFailure( "Dirty" ); } public void testOptimisticLockAll() { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("All", doc); - s.flush(); - doc.setSummary("A modern classic"); - s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); - s.flush(); - s.delete(doc); - t.commit(); - s.close(); + testUpdateOptimisticLockFailure( "All" ); } - //TODO: also test that non-overlapping changes behavior. - public void testOptimisticLockDirtyDeleteFailureExpected() { - //HHH-1677 + public void testOptimisticLockDirtyDelete() { + testDeleteOptimisticLockFailure( "Dirty" ); + } + public void testOptimisticLockAllDelete() { + testDeleteOptimisticLockFailure( "All" ); + } + + private void testUpdateOptimisticLockFailure(String entityName) { Session s = openSession(); Transaction t = s.beginTransaction(); Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("Dirty", doc); - s.flush(); - doc.setSummary("A modern classic"); - s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); - s.flush(); + doc.setTitle( "Hibernate in Action" ); + doc.setAuthor( "Bauer et al" ); + doc.setSummary( "Very boring book about persistence" ); + doc.setText( "blah blah yada yada yada" ); + doc.setPubDate( new PublicationDate( 2004 ) ); + s.save( entityName, doc ); t.commit(); s.close(); - + s = openSession(); t = s.beginTransaction(); - doc = (Document) s.get("Dirty", doc.getId()); - - Session other = openSession(); - Transaction othert = other.beginTransaction(); - Document otherDoc = (Document) other.get("Dirty", doc.getId()); - otherDoc.setSummary( "my other summary" ); - other.flush(); - othert.commit(); - other.close(); - + doc = ( Document ) s.get( entityName, doc.getId() ); + + Session otherSession = openSession(); + otherSession.beginTransaction(); + Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() ); + otherDoc.setSummary( "A modern classic" ); + otherSession.getTransaction().commit(); + otherSession.close(); + try { - s.delete(doc); - t.commit(); - fail("Should fail since other session have update the summary"); - } catch(StaleObjectStateException soe) { - // expected + doc.setSummary( "A machiavelian achievement of epic proportions" ); + s.flush(); + fail( "expecting opt lock failure" ); } + catch ( StaleObjectStateException expected ) { + // expected result... + } + s.clear(); + t.commit(); s.close(); + + s = openSession(); + t = s.beginTransaction(); + doc = ( Document ) s.load( entityName, doc.getId() ); + s.delete( entityName, doc ); + t.commit(); + s.close(); } - public void testOptimisticLockAllDeleteFailureExpected() { - //HHH-1677 + private void testDeleteOptimisticLockFailure(String entityName) { Session s = openSession(); Transaction t = s.beginTransaction(); Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("Dirty", doc); + doc.setTitle( "Hibernate in Action" ); + doc.setAuthor( "Bauer et al" ); + doc.setSummary( "Very boring book about persistence" ); + doc.setText( "blah blah yada yada yada" ); + doc.setPubDate( new PublicationDate( 2004 ) ); + s.save( entityName, doc ); s.flush(); - doc.setSummary("A modern classic"); + doc.setSummary( "A modern classic" ); s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); + doc.getPubDate().setMonth( new Integer( 3 ) ); s.flush(); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); - doc = (Document) s.get("All", doc.getId()); + doc = ( Document ) s.get( entityName, doc.getId() ); Session other = openSession(); Transaction othert = other.beginTransaction(); - Document otherDoc = (Document) other.get("All", doc.getId()); + Document otherDoc = ( Document ) other.get( entityName, doc.getId() ); otherDoc.setSummary( "my other summary" ); other.flush(); othert.commit(); other.close(); try { - s.delete(doc); - t.commit(); - fail("Should fail since other session have update the summary"); - } catch(StaleObjectStateException soe) { + s.delete( doc ); + s.flush(); + fail( "expecting opt lock failure" ); + } + catch ( StaleObjectStateException e ) { // expected } - s.close(); - } + s.clear(); + t.commit(); + s.close(); - - protected String[] getMappings() { - return new String[] { "optlock/Document.hbm.xml" }; + s = openSession(); + t = s.beginTransaction(); + doc = ( Document ) s.load( entityName, doc.getId() ); + s.delete( entityName, doc ); + t.commit(); + s.close(); } - public static Test suite() { - return new TestSuite(OptimisticLockTest.class); - } - } |
From: <hib...@li...> - 2006-08-05 04:28:00
|
Author: ste...@jb... Date: 2006-08-05 00:27:55 -0400 (Sat, 05 Aug 2006) New Revision: 10226 Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java trunk/Hibernate3/src/org/hibernate/sql/Delete.java trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java Log: HHH-1677 : optimistic-lock and delete Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-04 20:33:48 UTC (rev 10225) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-05 04:27:55 UTC (rev 10226) @@ -43,6 +43,7 @@ import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.Versioning; import org.hibernate.engine.ExecuteUpdateResultCheckStyle; +import org.hibernate.engine.EntityKey; import org.hibernate.exception.JDBCExceptionHelper; import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.PostInsertIdentifierGenerator; @@ -1757,9 +1758,9 @@ getPropertyUpdateability() : //optimistic-lock="all", include all updatable properties includeProperty; //optimistic-lock="dirty", include all properties we are updating this time + boolean[] versionability = getPropertyVersionability(); + Type[] types = getPropertyTypes(); for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { - boolean[] versionability = getPropertyVersionability(); - Type[] types = getPropertyTypes(); boolean include = includeInWhere[i] && isPropertyOfTable( i, j ) && versionability[i]; @@ -2233,7 +2234,7 @@ else if ( isNullableTable( j ) && isAllNull( fields, j ) ) { //if all fields are null, we might need to delete existing row isRowToUpdate = true; - delete( id, oldVersion, j, object, getSQLDeleteStrings()[j], session ); + delete( id, oldVersion, j, object, getSQLDeleteStrings()[j], session, null ); } else { //there is probably a row there, so try to update @@ -2374,7 +2375,8 @@ final int j, final Object object, final String sql, - final SessionImplementor session) throws HibernateException { + final SessionImplementor session, + final Object[] loadedState) throws HibernateException { if ( isInverseTable( j ) ) { return; @@ -2428,12 +2430,26 @@ // Do the key. The key is immutable so we can use the _current_ object state - not necessarily // the state at the time the delete was issued getIdentifierType().nullSafeSet( delete, id, index, session ); + index += getIdentifierColumnSpan(); // We should use the _current_ object state (ie. after any updates that occurred during flush) if ( useVersion ) { - getVersionType().nullSafeSet( delete, version, getIdentifierColumnSpan() + index, session ); + getVersionType().nullSafeSet( delete, version, index, session ); } + else if ( entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION && loadedState != null ) { + boolean[] versionability = getPropertyVersionability(); + Type[] types = getPropertyTypes(); + for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { + if ( isPropertyOfTable( i, j ) && versionability[i] ) { + // this property belongs to the table and it is not specifically + // excluded from optimistic locking by optimistic-lock="false" + boolean[] settable = types[i].toColumnNullness( loadedState[i], getFactory() ); + types[i].nullSafeSet( delete, loadedState[i], index, settable, session ); + index += ArrayHelper.countTrue( settable ); + } + } + } if ( useBatch ) { session.getBatcher().addToBatch( expectation ); @@ -2586,14 +2602,72 @@ */ public void delete(Serializable id, Object version, Object object, SessionImplementor session) throws HibernateException { + final int span = getTableSpan(); + boolean isImpliedOptimisticLocking = entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION; + Object[] loadedState = null; + if ( isImpliedOptimisticLocking ) { + // need to treat this as if it where optimistic-lock="all" (dirty does *not* make sense); + // first we need to locate the "loaded" state + // + // Note, it potentially could be a proxy, so perform the location the safe way... + EntityKey key = new EntityKey( id, this, session.getEntityMode() ); + Object entity = session.getPersistenceContext().getEntity( key ); + if ( entity != null ) { + EntityEntry entry = session.getPersistenceContext().getEntry( entity ); + loadedState = entry.getLoadedState(); + } + } - final int span = getTableSpan(); + final String[] deleteStrings; + if ( isImpliedOptimisticLocking && loadedState != null ) { + // we need to utilize dynamic delete statements + deleteStrings = generateSQLDeletStrings( loadedState ); + } + else { + // otherwise, utilize the static delete statements + deleteStrings = getSQLDeleteStrings(); + } + for ( int j = span - 1; j >= 0; j-- ) { - delete( id, version, j, object, getSQLDeleteStrings()[j], session ); + delete( id, version, j, object, deleteStrings[j], session, loadedState ); } } + private String[] generateSQLDeletStrings(Object[] loadedState) { + int span = getTableSpan(); + String[] deleteStrings = new String[span]; + for ( int j = span - 1; j >= 0; j-- ) { + Delete delete = new Delete() + .setTableName( getTableName( j ) ) + .setPrimaryKeyColumnNames( getKeyColumns( j ) ); + if ( getFactory().getSettings().isCommentsEnabled() ) { + delete.setComment( "delete " + getEntityName() + " [" + j + "]" ); + } + + boolean[] versionability = getPropertyVersionability(); + Type[] types = getPropertyTypes(); + for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { + if ( isPropertyOfTable( i, j ) && versionability[i] ) { + // this property belongs to the table and it is not specifically + // excluded from optimistic locking by optimistic-lock="false" + String[] propertyColumnNames = getPropertyColumnNames( i ); + boolean[] propertyNullness = types[i].toColumnNullness( loadedState[i], getFactory() ); + for ( int k = 0; k < propertyNullness.length; k++ ) { + if ( propertyNullness[k] ) { + delete.addWhereFragment( propertyColumnNames[k] + " = ?" ); + } + else { + delete.addWhereFragment( propertyColumnNames[k] + " is null" ); + } + } + } + } + deleteStrings[j] = delete.toStatementString(); + } + return deleteStrings; + } + protected void logStaticSQL() { if ( log.isDebugEnabled() ) { log.debug( "Static SQL for entity: " + getEntityName() ); Modified: trunk/Hibernate3/src/org/hibernate/sql/Delete.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/sql/Delete.java 2006-08-04 20:33:48 UTC (rev 10225) +++ trunk/Hibernate3/src/org/hibernate/sql/Delete.java 2006-08-05 04:27:55 UTC (rev 10226) @@ -61,6 +61,16 @@ return this; } + public Delete addWhereFragment(String fragment) { + if ( where == null ) { + where = fragment; + } + else { + where += ( " and " + fragment ); + } + return this; + } + public Delete setPrimaryKeyColumnNames(String[] primaryKeyColumnNames) { this.primaryKeyColumnNames = primaryKeyColumnNames; return this; Modified: trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-08-04 20:33:48 UTC (rev 10225) +++ trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-08-05 04:27:55 UTC (rev 10226) @@ -13,11 +13,11 @@ <hibernate-mapping package="org.hibernate.test.optlock"> - <class name="Document" - entity-name="Dirty" - table="Document" - optimistic-lock="dirty" - dynamic-update="true"> + <class name="Document" + entity-name="Dirty" + table="Document" + optimistic-lock="dirty" + dynamic-update="true"> <id name="id"> <generator class="native"/> </id> @@ -32,11 +32,11 @@ <property name="text" column="`text`"/> </class> - <class name="Document" - entity-name="All" - table="Document" - optimistic-lock="all" - dynamic-update="true"> + <class name="Document" + entity-name="All" + table="Document" + optimistic-lock="all" + dynamic-update="true"> <id name="id"> <generator class="native"/> </id> Modified: trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-08-04 20:33:48 UTC (rev 10225) +++ trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-08-05 04:27:55 UTC (rev 10226) @@ -10,146 +10,134 @@ import org.hibernate.test.TestCase; /** + * Tests relating to the optimisitc-lock mapping option. + * * @author Gavin King + * @author Steve Ebersole */ public class OptimisticLockTest extends TestCase { public OptimisticLockTest(String str) { super(str); } + + protected String[] getMappings() { + return new String[] { "optlock/Document.hbm.xml" }; + } + + public static Test suite() { + return new TestSuite(OptimisticLockTest.class); + } public void testOptimisticLockDirty() { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("Dirty", doc); - s.flush(); - doc.setSummary("A modern classic"); - s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); - s.flush(); - s.delete(doc); - t.commit(); - s.close(); + testUpdateOptimisticLockFailure( "Dirty" ); } public void testOptimisticLockAll() { - Session s = openSession(); - Transaction t = s.beginTransaction(); - Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("All", doc); - s.flush(); - doc.setSummary("A modern classic"); - s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); - s.flush(); - s.delete(doc); - t.commit(); - s.close(); + testUpdateOptimisticLockFailure( "All" ); } - //TODO: also test that non-overlapping changes behavior. - public void testOptimisticLockDirtyDeleteFailureExpected() { - //HHH-1677 + public void testOptimisticLockDirtyDelete() { + testDeleteOptimisticLockFailure( "Dirty" ); + } + public void testOptimisticLockAllDelete() { + testDeleteOptimisticLockFailure( "All" ); + } + + private void testUpdateOptimisticLockFailure(String entityName) { Session s = openSession(); Transaction t = s.beginTransaction(); Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("Dirty", doc); - s.flush(); - doc.setSummary("A modern classic"); - s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); - s.flush(); + doc.setTitle( "Hibernate in Action" ); + doc.setAuthor( "Bauer et al" ); + doc.setSummary( "Very boring book about persistence" ); + doc.setText( "blah blah yada yada yada" ); + doc.setPubDate( new PublicationDate( 2004 ) ); + s.save( entityName, doc ); t.commit(); s.close(); - + s = openSession(); t = s.beginTransaction(); - doc = (Document) s.get("Dirty", doc.getId()); - - Session other = openSession(); - Transaction othert = other.beginTransaction(); - Document otherDoc = (Document) other.get("Dirty", doc.getId()); - otherDoc.setSummary( "my other summary" ); - other.flush(); - othert.commit(); - other.close(); - + doc = ( Document ) s.get( entityName, doc.getId() ); + + Session otherSession = openSession(); + otherSession.beginTransaction(); + Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() ); + otherDoc.setSummary( "A modern classic" ); + otherSession.getTransaction().commit(); + otherSession.close(); + try { - s.delete(doc); - t.commit(); - fail("Should fail since other session have update the summary"); - } catch(StaleObjectStateException soe) { - // expected + doc.setSummary( "A machiavelian achievement of epic proportions" ); + s.flush(); + fail( "expecting opt lock failure" ); } + catch ( StaleObjectStateException expected ) { + // expected result... + } + s.clear(); + t.commit(); s.close(); + + s = openSession(); + t = s.beginTransaction(); + doc = ( Document ) s.load( entityName, doc.getId() ); + s.delete( entityName, doc ); + t.commit(); + s.close(); } - public void testOptimisticLockAllDeleteFailureExpected() { - //HHH-1677 + private void testDeleteOptimisticLockFailure(String entityName) { Session s = openSession(); Transaction t = s.beginTransaction(); Document doc = new Document(); - doc.setTitle("Hibernate in Action"); - doc.setAuthor("Bauer et al"); - doc.setSummary("Very boring book about persistence"); - doc.setText("blah blah yada yada yada"); - doc.setPubDate( new PublicationDate(2004) ); - s.save("Dirty", doc); + doc.setTitle( "Hibernate in Action" ); + doc.setAuthor( "Bauer et al" ); + doc.setSummary( "Very boring book about persistence" ); + doc.setText( "blah blah yada yada yada" ); + doc.setPubDate( new PublicationDate( 2004 ) ); + s.save( entityName, doc ); s.flush(); - doc.setSummary("A modern classic"); + doc.setSummary( "A modern classic" ); s.flush(); - doc.getPubDate().setMonth( new Integer(3) ); + doc.getPubDate().setMonth( new Integer( 3 ) ); s.flush(); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); - doc = (Document) s.get("All", doc.getId()); + doc = ( Document ) s.get( entityName, doc.getId() ); Session other = openSession(); Transaction othert = other.beginTransaction(); - Document otherDoc = (Document) other.get("All", doc.getId()); + Document otherDoc = ( Document ) other.get( entityName, doc.getId() ); otherDoc.setSummary( "my other summary" ); other.flush(); othert.commit(); other.close(); try { - s.delete(doc); - t.commit(); - fail("Should fail since other session have update the summary"); - } catch(StaleObjectStateException soe) { + s.delete( doc ); + s.flush(); + fail( "expecting opt lock failure" ); + } + catch ( StaleObjectStateException e ) { // expected } - s.close(); - } + s.clear(); + t.commit(); + s.close(); - - protected String[] getMappings() { - return new String[] { "optlock/Document.hbm.xml" }; + s = openSession(); + t = s.beginTransaction(); + doc = ( Document ) s.load( entityName, doc.getId() ); + s.delete( entityName, doc ); + t.commit(); + s.close(); } - public static Test suite() { - return new TestSuite(OptimisticLockTest.class); - } - } |
From: <hib...@li...> - 2006-08-04 20:33:54
|
Author: ste...@jb... Date: 2006-08-04 16:33:48 -0400 (Fri, 04 Aug 2006) New Revision: 10225 Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Info.java Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Container.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java Log: HHH-1954 : proxies and eviction Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java 2006-08-04 20:29:45 UTC (rev 10224) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java 2006-08-04 20:33:48 UTC (rev 10225) @@ -40,20 +40,17 @@ public void onEvict(EvictEvent event) throws HibernateException { EventSource source = event.getSession(); final Object object = event.getObject(); - final PersistenceContext persistenceContext = source.getPersistenceContext(); + if ( object instanceof HibernateProxy ) { - LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer(); Serializable id = li.getIdentifier(); EntityPersister persister = source.getFactory().getEntityPersister( li.getEntityName() ); - if (id==null) { + if ( id == null ) { throw new IllegalArgumentException("null identifier"); } - EntityKey key = new EntityKey( id, persister, source.getEntityMode() ); - persistenceContext.removeProxy(key); - + persistenceContext.removeProxy( key ); if ( !li.isUninitialized() ) { final Object entity = persistenceContext.removeEntity(key); if ( entity != null ) { @@ -61,14 +58,13 @@ doEvict( entity, key, e.getPersister(), event.getSession() ); } } - + li.setSession( null ); } else { - - EntityEntry e = persistenceContext.removeEntry(object); + EntityEntry e = persistenceContext.removeEntry( object ); if ( e != null ) { EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode() ); - persistenceContext.removeEntity(key); + persistenceContext.removeEntity( key ); doEvict( object, key, e.getPersister(), source ); } @@ -79,23 +75,18 @@ final Object object, final EntityKey key, final EntityPersister persister, - final EventSource session) - throws HibernateException { + final EventSource session) throws HibernateException { if ( log.isTraceEnabled() ) { log.trace( "evicting " + MessageHelper.infoString(persister) ); } // remove all collections for the entity from the session-level cache - if ( persister.hasCollections() ) new EvictVisitor( session ).process( object, persister ); - - // remove any snapshot, not really for memory management purposes, but - // rather because it might now be stale, and there is no longer any - // EntityEntry to take precedence - // This is now handled by removeEntity() - //session.getPersistenceContext().removeDatabaseSnapshot(key); + if ( persister.hasCollections() ) { + new EvictVisitor( session ).process( object, persister ); + } - new Cascade(CascadingAction.EVICT, Cascade.AFTER_EVICT, session) - .cascade(persister, object); + new Cascade( CascadingAction.EVICT, Cascade.AFTER_EVICT, session ) + .cascade( persister, object ); } } Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Container.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Container.java 2006-08-04 20:29:45 UTC (rev 10224) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Container.java 2006-08-04 20:33:48 UTC (rev 10225) @@ -11,6 +11,7 @@ private Long id; private String name; private Owner owner; + private Info info; private Set dataPoints = new HashSet(); public Container() { @@ -44,6 +45,14 @@ this.owner = owner; } + public Info getInfo() { + return info; + } + + public void setInfo(Info info) { + this.info = info; + } + public Set getDataPoints() { return dataPoints; } Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml 2006-08-04 20:29:45 UTC (rev 10224) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml 2006-08-04 20:33:48 UTC (rev 10225) @@ -26,12 +26,20 @@ <property name="name" unique="true"/> </class> + <class name="Info"> + <id name="id"> + <generator class="increment"/> + </id> + <property name="details"/> + </class> + <class name="Container"> <id name="id"> <generator class="increment"/> </id> <property name="name"/> <many-to-one name="owner" class="Owner" column="owner_name" property-ref="name" cascade="all"/> + <many-to-one name="info" class="Info" column="info_id" cascade="all"/> <set name="dataPoints" lazy="true" inverse="false" cascade="all"> <key column="c_id"/> <one-to-many class="DataPoint"/> Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java 2006-08-04 20:29:45 UTC (rev 10224) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java 2006-08-04 20:33:48 UTC (rev 10225) @@ -12,6 +12,16 @@ private BigDecimal x; private BigDecimal y; private String description; + + public DataPoint() { + } + + public DataPoint(BigDecimal x, BigDecimal y, String description) { + this.x = x; + this.y = y; + this.description = description; + } + /** * @return Returns the description. */ Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Info.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Info.java 2006-08-04 20:29:45 UTC (rev 10224) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/Info.java 2006-08-04 20:33:48 UTC (rev 10225) @@ -0,0 +1,34 @@ +package org.hibernate.test.proxy; + +/** + * todo: describe Info + * + * @author Steve Ebersole + */ +public class Info { + private Long id; + private String details; + + public Info() { + } + + public Info(String details) { + this.details = details; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } +} Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-08-04 20:29:45 UTC (rev 10224) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-08-04 20:33:48 UTC (rev 10225) @@ -13,6 +13,7 @@ import org.hibernate.Transaction; import org.hibernate.FlushMode; import org.hibernate.ObjectNotFoundException; +import org.hibernate.LazyInitializationException; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.impl.SessionImpl; @@ -237,6 +238,51 @@ s.close(); } + public void testProxyEviction() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Container container = new Container( "container" ); + container.setOwner( new Owner( "owner" ) ); + container.setInfo( new Info( "blah blah blah" ) ); + container.getDataPoints().add( new DataPoint( new BigDecimal( 1 ), new BigDecimal( 1 ), "first data point" ) ); + container.getDataPoints().add( new DataPoint( new BigDecimal( 2 ), new BigDecimal( 2 ), "second data point" ) ); + s.save( container ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + Container c = ( Container ) s.load( Container.class, container.getId() ); + assertFalse( Hibernate.isInitialized( c ) ); + s.evict( c ); + try { + c.getName(); + fail( "expecting LazyInitializationException" ); + } + catch( LazyInitializationException e ) { + // expected result + } + + c = ( Container ) s.load( Container.class, container.getId() ); + assertFalse( Hibernate.isInitialized( c ) ); + Info i = c.getInfo(); + assertTrue( Hibernate.isInitialized( c ) ); + assertFalse( Hibernate.isInitialized( i ) ); + s.evict( c ); + try { + i.getDetails(); + fail( "expecting LazyInitializationException" ); + } + catch( LazyInitializationException e ) { + // expected result + } + + s.delete( c ); + + t.commit(); + s.close(); + } + protected String[] getMappings() { return new String[] { "proxy/DataPoint.hbm.xml" }; } |
From: <hib...@li...> - 2006-08-04 20:29:48
|
Author: ste...@jb... Date: 2006-08-04 16:29:45 -0400 (Fri, 04 Aug 2006) New Revision: 10224 Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java Log: HHH-1954 : proxies and eviction Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java 2006-08-04 20:29:21 UTC (rev 10223) +++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultEvictEventListener.java 2006-08-04 20:29:45 UTC (rev 10224) @@ -40,38 +40,35 @@ public void onEvict(EvictEvent event) throws HibernateException { EventSource source = event.getSession(); final Object object = event.getObject(); - final PersistenceContext persistenceContext = source.getPersistenceContext(); + if ( object instanceof HibernateProxy ) { - LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer(); Serializable id = li.getIdentifier(); EntityPersister persister = source.getFactory().getEntityPersister( li.getEntityName() ); - if (id==null) { + if ( id == null ) { throw new IllegalArgumentException("null identifier"); } - + EntityKey key = new EntityKey( id, persister, source.getEntityMode() ); - persistenceContext.removeProxy(key); - + persistenceContext.removeProxy( key ); + if ( !li.isUninitialized() ) { - final Object entity = persistenceContext.removeEntity(key); + final Object entity = persistenceContext.removeEntity( key ); if ( entity != null ) { - EntityEntry e = event.getSession().getPersistenceContext().removeEntry(entity); + EntityEntry e = event.getSession().getPersistenceContext().removeEntry( entity ); doEvict( entity, key, e.getPersister(), event.getSession() ); } } - + li.setSession( null ); } else { - - EntityEntry e = persistenceContext.removeEntry(object); + EntityEntry e = persistenceContext.removeEntry( object ); if ( e != null ) { EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode() ); - persistenceContext.removeEntity(key); + persistenceContext.removeEntity( key ); doEvict( object, key, e.getPersister(), source ); } - } } @@ -87,15 +84,17 @@ } // remove all collections for the entity from the session-level cache - if ( persister.hasCollections() ) new EvictVisitor( session ).process( object, persister ); - + if ( persister.hasCollections() ) { + new EvictVisitor( session ).process( object, persister ); + } + // remove any snapshot, not really for memory management purposes, but // rather because it might now be stale, and there is no longer any // EntityEntry to take precedence // This is now handled by removeEntity() //session.getPersistenceContext().removeDatabaseSnapshot(key); - new Cascade(CascadingAction.EVICT, Cascade.AFTER_EVICT, session) - .cascade(persister, object); + new Cascade( CascadingAction.EVICT, Cascade.AFTER_EVICT, session ) + .cascade( persister, object ); } } |
From: <hib...@li...> - 2006-08-04 20:29:24
|
Author: ste...@jb... Date: 2006-08-04 16:29:21 -0400 (Fri, 04 Aug 2006) New Revision: 10223 Added: trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java Log: HHH-1954 : proxies and eviction Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java 2006-08-04 20:17:12 UTC (rev 10222) +++ trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java 2006-08-04 20:29:21 UTC (rev 10223) @@ -11,6 +11,7 @@ private Long id; private String name; private Owner owner; + private Info info; private Set dataPoints = new HashSet(); public Container() { @@ -44,6 +45,14 @@ this.owner = owner; } + public Info getInfo() { + return info; + } + + public void setInfo(Info info) { + this.info = info; + } + public Set getDataPoints() { return dataPoints; } Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml 2006-08-04 20:17:12 UTC (rev 10222) +++ trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml 2006-08-04 20:29:21 UTC (rev 10223) @@ -26,12 +26,20 @@ <property name="name" unique="true"/> </class> + <class name="Info"> + <id name="id"> + <generator class="increment"/> + </id> + <property name="details"/> + </class> + <class name="Container"> <id name="id"> <generator class="increment"/> </id> <property name="name"/> <many-to-one name="owner" class="Owner" column="owner_name" property-ref="name" cascade="all"/> + <many-to-one name="info" class="Info" column="info_id" cascade="all"/> <set name="dataPoints" lazy="true" inverse="false" cascade="all"> <key column="c_id"/> <one-to-many class="DataPoint"/> Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java 2006-08-04 20:17:12 UTC (rev 10222) +++ trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java 2006-08-04 20:29:21 UTC (rev 10223) @@ -12,6 +12,16 @@ private BigDecimal x; private BigDecimal y; private String description; + + public DataPoint() { + } + + public DataPoint(BigDecimal x, BigDecimal y, String description) { + this.x = x; + this.y = y; + this.description = description; + } + /** * @return Returns the description. */ Added: trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java 2006-08-04 20:17:12 UTC (rev 10222) +++ trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java 2006-08-04 20:29:21 UTC (rev 10223) @@ -0,0 +1,34 @@ +package org.hibernate.test.proxy; + +/** + * todo: describe Info + * + * @author Steve Ebersole + */ +public class Info { + private Long id; + private String details; + + public Info() { + } + + public Info(String details) { + this.details = details; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } +} Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-08-04 20:17:12 UTC (rev 10222) +++ trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-08-04 20:29:21 UTC (rev 10223) @@ -13,6 +13,7 @@ import org.hibernate.Transaction; import org.hibernate.FlushMode; import org.hibernate.ObjectNotFoundException; +import org.hibernate.LazyInitializationException; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.impl.SessionImpl; @@ -237,6 +238,51 @@ s.close(); } + public void testProxyEviction() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Container container = new Container( "container" ); + container.setOwner( new Owner( "owner" ) ); + container.setInfo( new Info( "blah blah blah" ) ); + container.getDataPoints().add( new DataPoint( new BigDecimal( 1 ), new BigDecimal( 1 ), "first data point" ) ); + container.getDataPoints().add( new DataPoint( new BigDecimal( 2 ), new BigDecimal( 2 ), "second data point" ) ); + s.save( container ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + Container c = ( Container ) s.load( Container.class, container.getId() ); + assertFalse( Hibernate.isInitialized( c ) ); + s.evict( c ); + try { + c.getName(); + fail( "expecting LazyInitializationException" ); + } + catch( LazyInitializationException e ) { + // expected result + } + + c = ( Container ) s.load( Container.class, container.getId() ); + assertFalse( Hibernate.isInitialized( c ) ); + Info i = c.getInfo(); + assertTrue( Hibernate.isInitialized( c ) ); + assertFalse( Hibernate.isInitialized( i ) ); + s.evict( c ); + try { + i.getDetails(); + fail( "expecting LazyInitializationException" ); + } + catch( LazyInitializationException e ) { + // expected result + } + + s.delete( c ); + + t.commit(); + s.close(); + } + protected String[] getMappings() { return new String[] { "proxy/DataPoint.hbm.xml" }; } |
From: <hib...@li...> - 2006-08-04 20:17:30
|
Author: ste...@jb... Date: 2006-08-04 16:17:12 -0400 (Fri, 04 Aug 2006) New Revision: 10222 Modified: trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java Log: missed import cleanup Modified: trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java 2006-08-04 18:37:47 UTC (rev 10221) +++ trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java 2006-08-04 20:17:12 UTC (rev 10222) @@ -8,7 +8,6 @@ import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.type.Type; import org.hibernate.dialect.function.VarArgsSQLFunction; -import org.hibernate.dialect.function.AnsiTrimEmulationFunction; import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.id.TableHiLoGenerator; |
From: <hib...@li...> - 2006-08-04 18:38:37
|
Author: ste...@jb... Date: 2006-08-04 14:37:47 -0400 (Fri, 04 Aug 2006) New Revision: 10221 Added: trunk/Hibernate3/src/org/hibernate/dialect/ResultColumnReferenceStrategy.java Removed: trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java Modified: trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java Log: added ResultColumnReferenceStrategy (not yet being utilized); Derby trim() function (w/o capability to specify replacement character) Modified: trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java 2006-08-04 18:25:19 UTC (rev 10220) +++ trunk/Hibernate3/src/org/hibernate/dialect/DerbyDialect.java 2006-08-04 18:37:47 UTC (rev 10221) @@ -2,12 +2,22 @@ package org.hibernate.dialect; import org.hibernate.Hibernate; +import org.hibernate.QueryException; +import org.hibernate.HibernateException; +import org.hibernate.engine.Mapping; +import org.hibernate.engine.SessionFactoryImplementor; +import org.hibernate.type.Type; import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.dialect.function.AnsiTrimEmulationFunction; +import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.id.TableHiLoGenerator; import org.hibernate.sql.CaseFragment; import org.hibernate.sql.DerbyCaseFragment; +import java.util.List; +import java.util.ArrayList; + /** * @author Simon Johnston * @@ -21,7 +31,7 @@ public DerbyDialect() { super(); registerFunction( "concat", new VarArgsSQLFunction( Hibernate.STRING, "(","||",")" ) ); - registerFunction( "trim", new AnsiTrimEmulationFunction() ); + registerFunction( "trim", new DerbyTrimFunctionEmulation() ); } /** @@ -38,18 +48,18 @@ return new DerbyCaseFragment(); } - public boolean dropConstraints() { - return true; + public boolean dropConstraints() { + return true; } - + public Class getNativeIdentifierGeneratorClass() { return TableHiLoGenerator.class; } - + public boolean supportsSequences() { return false; } - + public boolean supportsLimit() { return false; } @@ -60,5 +70,124 @@ public String getQuerySequencesString() { return null ; - } + } + + /** + * A specialized function template to emulate the ANSI trim function on Derby DB + * since it does not support the full trim specification. However, we cannot even + * fully emulate it because there is not standard 'replace' function either. :( + */ + public static class DerbyTrimFunctionEmulation implements SQLFunction { + private static final SQLFunction LEADING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( ?1 )"); + private static final SQLFunction TRAILING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "rtrim( ?1 )"); + private static final SQLFunction BOTH_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?1 ) )"); + private static final SQLFunction BOTH_SPACE_TRIM_FROM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?2 ) )"); + + public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { + return Hibernate.STRING; + } + + public boolean hasArguments() { + return true; + } + + public boolean hasParenthesesIfNoArguments() { + return false; + } + + public String render(List args, SessionFactoryImplementor factory) throws QueryException { + // according to both the ANSI-SQL and EJB3 specs, trim can either take + // exactly one parameter or a variable number of parameters between 1 and 4. + // from the SQL spec: + // + // <trim function> ::= + // TRIM <left paren> <trim operands> <right paren> + // + // <trim operands> ::= + // [ [ <trim specification> ] [ <trim character> ] FROM ] <trim source> + // + // <trim specification> ::= + // LEADING + // | TRAILING + // | BOTH + // + // If only <trim specification> is omitted, BOTH is assumed; + // if <trim character> is omitted, space is assumed + if ( args.size() == 1 ) { + // we have the form: trim(trimSource) + // so we trim leading and trailing spaces + return BOTH_SPACE_TRIM.render( args, factory ); + } + else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) { + // we have the form: trim(from trimSource). + // This is functionally equivalent to trim(trimSource) + return BOTH_SPACE_TRIM_FROM.render( args, factory ); + } + else { + // otherwise, a trim-specification and/or a trim-character + // have been specified; we need to decide which options + // are present and "do the right thing" + boolean leading = true; // should leading trim-characters be trimmed? + boolean trailing = true; // should trailing trim-characters be trimmed? + String trimCharacter = null; // the trim-character + String trimSource = null; // the trim-source + + // potentialTrimCharacterArgIndex = 1 assumes that a + // trim-specification has been specified. we handle the + // exception to that explicitly + int potentialTrimCharacterArgIndex = 1; + String firstArg = ( String ) args.get( 0 ); + if ( "leading".equalsIgnoreCase( firstArg ) ) { + trailing = false; + } + else if ( "trailing".equalsIgnoreCase( firstArg ) ) { + leading = false; + } + else if ( "both".equalsIgnoreCase( firstArg ) ) { + } + else { + potentialTrimCharacterArgIndex = 0; + } + + String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex ); + if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) { + trimCharacter = "' '"; + trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); + } + else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) { + trimCharacter = "' '"; + trimSource = potentialTrimCharacter; + } + else { + trimCharacter = potentialTrimCharacter; + if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) { + trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 ); + } + else { + trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); + } + } + + List argsToUse = null; + argsToUse = new ArrayList(); + argsToUse.add( trimSource ); + argsToUse.add( trimCharacter ); + + if ( trimCharacter.equals( "' '" ) ) { + if ( leading && trailing ) { + return BOTH_SPACE_TRIM.render( argsToUse, factory ); + } + else if ( leading ) { + return LEADING_SPACE_TRIM.render( argsToUse, factory ); + } + else { + return TRAILING_SPACE_TRIM.render( argsToUse, factory ); + } + } + else { + throw new HibernateException( "cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it" ); + } + } + } + } } Modified: trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-08-04 18:25:19 UTC (rev 10220) +++ trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-08-04 18:37:47 UTC (rev 10221) @@ -1079,4 +1079,49 @@ // return false here, as most databases do not properly support this construct... return false; } + + /** + * Which strategy should be used to reference columns in the "result" when + * performing sorting (i.e. when processing an order by). This is + * defined by ANSI SQL as the manner in which columns can be referred to in the + * group-by, having, and order-by clauses. + * <p/> + * The default is to use {@link ResultColumnReferenceStrategy#SOURCE} since that + * is the most performant. + * + * @return The strategy to use. + */ + public ResultColumnReferenceStrategy getOrderByColumnReferenceStrategy() { + return ResultColumnReferenceStrategy.SOURCE; + } + + /** + * Which strategy should be used to reference columns in the "result" when + * performing aggregation (i.e. when processing a group by). This is + * defined by ANSI SQL as the manner in which columns can be referred to in the + * group-by, having, and order-by clauses. + * <p/> + * The default is to use {@link ResultColumnReferenceStrategy#SOURCE} since that + * is the most performant. + * + * @return The strategy to use. + */ + public ResultColumnReferenceStrategy getGroupByColumnReferenceStrategy() { + return ResultColumnReferenceStrategy.SOURCE; + } + + /** + * Which strategy should be used to reference columns in the "result" when + * performing aggregated restirctiuon(i.e. when processing a having). This is + * defined by ANSI SQL as the manner in which columns can be referred to in the + * group-by, having, and order-by clauses. + * <p/> + * The default is to use {@link ResultColumnReferenceStrategy#SOURCE} since that + * is the most performant. + * + * @return The strategy to use. + */ + public ResultColumnReferenceStrategy getHavingColumnReferenceStrategy() { + return ResultColumnReferenceStrategy.SOURCE; + } } Added: trunk/Hibernate3/src/org/hibernate/dialect/ResultColumnReferenceStrategy.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/ResultColumnReferenceStrategy.java 2006-08-04 18:25:19 UTC (rev 10220) +++ trunk/Hibernate3/src/org/hibernate/dialect/ResultColumnReferenceStrategy.java 2006-08-04 18:37:47 UTC (rev 10221) @@ -0,0 +1,67 @@ +package org.hibernate.dialect; + +import java.io.Serializable; +import java.io.ObjectStreamException; +import java.util.Map; +import java.util.HashMap; + +/** + * Defines how we need to reference columns in the group-by, having, and order-by + * clauses. + * + * @author Steve Ebersole + */ +public class ResultColumnReferenceStrategy implements Serializable { + + private static final Map INSTANCES = new HashMap(); + + /** + * This strategy says to reference the result columns by the qualified column name + * found in the result source. This strategy is not strictly allowed by ANSI SQL + * but is Hibernate's legacy behavior and is also the fastest of the strategies; thus + * it should be used if supported by the underlying database. + */ + public static final ResultColumnReferenceStrategy SOURCE = new ResultColumnReferenceStrategy( "source"); + + /** + * For databases which do not support {@link #SOURCE}, ANSI SQL defines two allowable + * approaches. One is to reference the result column by the alias it is given in the + * result source (if it is given an alias). This strategy says to use this approach. + * <p/> + * The other QNSI SQL compliant approach is {@link #ORDINAL}. + */ + public static final ResultColumnReferenceStrategy ALIAS = new ResultColumnReferenceStrategy( "alias" ); + + /** + * For databases which do not support {@link #SOURCE}, ANSI SQL defines two allowable + * approaches. One is to reference the result column by the ordinal position at which + * it appears in the result source. This strategy says to use this approach. + * <p/> + * The other QNSI SQL compliant approach is {@link #ALIAS}. + */ + public static final ResultColumnReferenceStrategy ORDINAL = new ResultColumnReferenceStrategy( "ordinal" ); + + static { + ResultColumnReferenceStrategy.INSTANCES.put( ResultColumnReferenceStrategy.SOURCE.name, ResultColumnReferenceStrategy.SOURCE ); + ResultColumnReferenceStrategy.INSTANCES.put( ResultColumnReferenceStrategy.ALIAS.name, ResultColumnReferenceStrategy.ALIAS ); + ResultColumnReferenceStrategy.INSTANCES.put( ResultColumnReferenceStrategy.ORDINAL.name, ResultColumnReferenceStrategy.ORDINAL ); + } + + private final String name; + + public ResultColumnReferenceStrategy(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + private Object readResolve() throws ObjectStreamException { + return parse( name ); + } + + public static ResultColumnReferenceStrategy parse(String name) { + return ( ResultColumnReferenceStrategy ) ResultColumnReferenceStrategy.INSTANCES.get( name ); + } +} Deleted: trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java 2006-08-04 18:25:19 UTC (rev 10220) +++ trunk/Hibernate3/src/org/hibernate/dialect/function/AnsiTrimEmulationFunction.java 2006-08-04 18:37:47 UTC (rev 10221) @@ -1,146 +0,0 @@ -package org.hibernate.dialect.function; - -import org.hibernate.Hibernate; -import org.hibernate.QueryException; -import org.hibernate.engine.Mapping; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.type.Type; - -import java.util.List; -import java.util.ArrayList; - -/** - * A {@link SQLFunction} implementation that emulates the ANSI SQL trim function - * on dialects which do not support the full definition. However, this function - * definition does assume the availability of ltrim, rtrim, and replace functions - * which it uses in various combinations to emulate the desired ANSI trim() - * functionality. - * - * @author Steve Ebersole - */ -public class AnsiTrimEmulationFunction implements SQLFunction { - - private static final SQLFunction LEADING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( ?1 )"); - private static final SQLFunction TRAILING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "rtrim( ?1 )"); - private static final SQLFunction BOTH_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?1 ) )"); - private static final SQLFunction BOTH_SPACE_TRIM_FROM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?2 ) )"); - - private static final SQLFunction LEADING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" ); - private static final SQLFunction TRAILING_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )" ); - private static final SQLFunction BOTH_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "replace( replace( ltrim( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ) ), ' ', ?2 ), '${space}$', ' ' )" ); - - public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { - return Hibernate.STRING; - } - - public boolean hasArguments() { - return true; - } - - public boolean hasParenthesesIfNoArguments() { - return false; - } - - public String render(List args, SessionFactoryImplementor factory) throws QueryException { - // according to both the ANSI-SQL and EJB3 specs, trim can either take - // exactly one parameter or a variable number of parameters between 1 and 4. - // from the SQL spec: - // - // <trim function> ::= - // TRIM <left paren> <trim operands> <right paren> - // - // <trim operands> ::= - // [ [ <trim specification> ] [ <trim character> ] FROM ] <trim source> - // - // <trim specification> ::= - // LEADING - // | TRAILING - // | BOTH - // - // If only <trim specification> is omitted, BOTH is assumed; - // if <trim character> is omitted, space is assumed - if ( args.size() == 1 ) { - // we have the form: trim(trimSource) - // so we trim leading and trailing spaces - return BOTH_SPACE_TRIM.render( args, factory ); - } - else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) { - // we have the form: trim(from trimSource). - // This is functionally equivalent to trim(trimSource) - return BOTH_SPACE_TRIM_FROM.render( args, factory ); - } - else { - // otherwise, a trim-specification and/or a trim-character - // have been specified; we need to decide which options - // are present and "do the right thing" - boolean leading = true; // should leading trim-characters be trimmed? - boolean trailing = true; // should trailing trim-characters be trimmed? - String trimCharacter = null; // the trim-character - String trimSource = null; // the trim-source - - // potentialTrimCharacterArgIndex = 1 assumes that a - // trim-specification has been specified. we handle the - // exception to that explicitly - int potentialTrimCharacterArgIndex = 1; - String firstArg = ( String ) args.get( 0 ); - if ( "leading".equalsIgnoreCase( firstArg ) ) { - trailing = false; - } - else if ( "trailing".equalsIgnoreCase( firstArg ) ) { - leading = false; - } - else if ( "both".equalsIgnoreCase( firstArg ) ) { - } - else { - potentialTrimCharacterArgIndex = 0; - } - - String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex ); - if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) { - trimCharacter = "' '"; - trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); - } - else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) { - trimCharacter = "' '"; - trimSource = potentialTrimCharacter; - } - else { - trimCharacter = potentialTrimCharacter; - if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) { - trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 ); - } - else { - trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 ); - } - } - - List argsToUse = null; - argsToUse = new ArrayList(); - argsToUse.add( trimSource ); - argsToUse.add( trimCharacter ); - - if ( trimCharacter.equals( "' '" ) ) { - if ( leading && trailing ) { - return BOTH_SPACE_TRIM.render( argsToUse, factory ); - } - else if ( leading ) { - return LEADING_SPACE_TRIM.render( argsToUse, factory ); - } - else { - return TRAILING_SPACE_TRIM.render( argsToUse, factory ); - } - } - else { - if ( leading && trailing ) { - return BOTH_TRIM.render( argsToUse, factory ); - } - else if ( leading ) { - return LEADING_TRIM.render( argsToUse, factory ); - } - else { - return TRAILING_TRIM.render( argsToUse, factory ); - } - } - } - } -} |
From: <hib...@li...> - 2006-08-04 18:25:22
|
Author: ste...@jb... Date: 2006-08-04 14:25:19 -0400 (Fri, 04 Aug 2006) New Revision: 10220 Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java Log: HHH-1848 : locking on versioned joined subclasses Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2006-08-04 18:24:33 UTC (rev 10219) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2006-08-04 18:25:19 UTC (rev 10220) @@ -219,7 +219,9 @@ jk--; pc = pc.getSuperclass(); } - if (jk!=-1) throw new AssertionFailure("Tablespan does not match height of joined-subclass hiearchy."); + if ( jk != -1 ) { + throw new AssertionFailure( "Tablespan does not match height of joined-subclass hiearchy." ); + } // PROPERTIES @@ -452,7 +454,9 @@ private static int getTableId(String tableName, String[] tables) { for ( int j=0; j<tables.length; j++ ) { - if ( tableName.equals( tables[j] ) ) return j; + if ( tableName.equals( tables[j] ) ) { + return j; + } } throw new AssertionFailure("Table " + tableName + " not found"); } @@ -554,7 +558,9 @@ public String getPropertyTableName(String propertyName) { Integer index = getEntityMetamodel().getPropertyIndexOrNull(propertyName); - if (index==null) return null; + if ( index == null ) { + return null; + } return tableNames[ propertyTableNumbers[ index.intValue() ] ]; } @@ -565,4 +571,8 @@ public String[][] getContraintOrderedTableKeyColumnClosure() { return constraintOrderedKeyColumnNames; } + + public String getRootTableName() { + return naturalOrderTableNames[0]; + } } Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-08-04 18:24:33 UTC (rev 10219) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-08-04 18:25:19 UTC (rev 10220) @@ -11,6 +11,7 @@ import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.LockMode; import org.hibernate.criterion.Expression; import org.hibernate.criterion.Property; import org.hibernate.dialect.DB2Dialect; @@ -141,6 +142,33 @@ s.close(); } + public void testLockingJoinedSubclass() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Person p = new Person(); + p.setName("Emmanuel"); + p.setSex('M'); + s.persist(p); + Employee q = new Employee(); + q.setName("Steve"); + q.setSex('M'); + q.setTitle("Mr"); + q.setSalary( new BigDecimal(1000) ); + s.persist(q); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.lock( p, LockMode.UPGRADE ); + s.lock( q, LockMode.UPGRADE ); + s.delete( p ); + s.delete( q ); + t.commit(); + s.close(); + + } + protected String[] getMappings() { return new String[] { "joinedsubclass/Person.hbm.xml" }; Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml 2006-08-04 18:24:33 UTC (rev 10219) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml 2006-08-04 18:25:19 UTC (rev 10220) @@ -26,8 +26,10 @@ unsaved-value="0"> <generator class="native"/> </id> - - <property name="name" + + <version name="version" column="version" type="int"/> + + <property name="name" not-null="true" length="80"/> <property name="sex" Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java 2006-08-04 18:24:33 UTC (rev 10219) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java 2006-08-04 18:25:19 UTC (rev 10220) @@ -9,6 +9,7 @@ private long id; private String name; private char sex; + private int version; private Address address = new Address(); /** * @return Returns the address. @@ -67,4 +68,11 @@ this.name = identity; } + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } } |
From: <hib...@li...> - 2006-08-04 18:24:35
|
Author: ste...@jb... Date: 2006-08-04 14:24:33 -0400 (Fri, 04 Aug 2006) New Revision: 10219 Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java Log: HHH-1848 : locking on versioned joined subclasses Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2006-08-04 18:24:04 UTC (rev 10218) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java 2006-08-04 18:24:33 UTC (rev 10219) @@ -219,7 +219,9 @@ jk--; pc = pc.getSuperclass(); } - if (jk!=-1) throw new AssertionFailure("Tablespan does not match height of joined-subclass hiearchy."); + if ( jk != -1 ) { + throw new AssertionFailure( "Tablespan does not match height of joined-subclass hiearchy." ); + } // PROPERTIES @@ -375,7 +377,7 @@ protected String getTableName(int j) { return naturalOrderTableNames[j]; } - + protected String[] getKeyColumns(int j) { return naturalOrderTableKeyColumns[j]; } @@ -452,7 +454,9 @@ private static int getTableId(String tableName, String[] tables) { for ( int j=0; j<tables.length; j++ ) { - if ( tableName.equals( tables[j] ) ) return j; + if ( tableName.equals( tables[j] ) ) { + return j; + } } throw new AssertionFailure("Table " + tableName + " not found"); } @@ -554,7 +558,9 @@ public String getPropertyTableName(String propertyName) { Integer index = getEntityMetamodel().getPropertyIndexOrNull(propertyName); - if (index==null) return null; + if ( index == null ) { + return null; + } return tableNames[ propertyTableNumbers[ index.intValue() ] ]; } @@ -565,4 +571,8 @@ public String[][] getContraintOrderedTableKeyColumnClosure() { return constraintOrderedKeyColumnNames; } + + public String getRootTableName() { + return naturalOrderTableNames[0]; + } } |
From: <hib...@li...> - 2006-08-04 18:24:08
|
Author: ste...@jb... Date: 2006-08-04 14:24:04 -0400 (Fri, 04 Aug 2006) New Revision: 10218 Modified: trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java Log: HHH-1848 : locking on versioned joined subclasses Modified: trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-08-04 17:40:56 UTC (rev 10217) +++ trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-08-04 18:24:04 UTC (rev 10218) @@ -11,6 +11,7 @@ import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.LockMode; import org.hibernate.criterion.Expression; import org.hibernate.criterion.Property; import org.hibernate.dialect.DB2Dialect; @@ -141,6 +142,32 @@ s.close(); } + public void testLockingJoinedSubclass() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + Person p = new Person(); + p.setName("Emmanuel"); + p.setSex('M'); + s.persist(p); + Employee q = new Employee(); + q.setName("Steve"); + q.setSex('M'); + q.setTitle("Mr"); + q.setSalary( new BigDecimal(1000) ); + s.persist(q); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.lock( p, LockMode.UPGRADE ); + s.lock( q, LockMode.UPGRADE ); + s.delete( p ); + s.delete( q ); + t.commit(); + s.close(); + + } protected String[] getMappings() { return new String[] { "joinedsubclass/Person.hbm.xml" }; Modified: trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml 2006-08-04 17:40:56 UTC (rev 10217) +++ trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.hbm.xml 2006-08-04 18:24:04 UTC (rev 10218) @@ -26,8 +26,10 @@ unsaved-value="0"> <generator class="native"/> </id> - - <property name="name" + + <version name="version" column="version" type="int"/> + + <property name="name" not-null="true" length="80"/> <property name="sex" Modified: trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java 2006-08-04 17:40:56 UTC (rev 10217) +++ trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/Person.java 2006-08-04 18:24:04 UTC (rev 10218) @@ -9,6 +9,7 @@ private long id; private String name; private char sex; + private int version; private Address address = new Address(); /** * @return Returns the address. @@ -67,4 +68,11 @@ this.name = identity; } + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } } |
Author: ste...@jb... Date: 2006-08-04 13:40:56 -0400 (Fri, 04 Aug 2006) New Revision: 10217 Added: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/Expectations.java branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java Log: ported changes for HHH-1959 to 3.2 branch Added: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,18 @@ +package org.hibernate.jdbc; + +import org.hibernate.HibernateException; + +/** + * Indicates a failed batch entry (-3 return). + * + * @author Steve Ebersole + */ +public class BatchFailedException extends HibernateException { + public BatchFailedException(String s) { + super( s ); + } + + public BatchFailedException(String string, Throwable root) { + super( string, root ); + } +} Added: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,21 @@ +package org.hibernate.jdbc; + +/** + * Much like {@link TooManyRowsAffectedException}, indicates that more + * rows than what we were expcecting were affected. Additionally, this form + * occurs from a batch and carries along the batch positon that failed. + * + * @author Steve Ebersole + */ +public class BatchedTooManyRowsAffectedException extends TooManyRowsAffectedException { + private final int batchPosition; + + public BatchedTooManyRowsAffectedException(String message, int expectedRowCount, int actualRowCount, int batchPosition) { + super( message, expectedRowCount, actualRowCount ); + this.batchPosition = batchPosition; + } + + public int getBatchPosition() { + return batchPosition; + } +} Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/Expectations.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/Expectations.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/Expectations.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -54,7 +54,7 @@ } } else if ( rowCount == -3 ) { - throw new HibernateException( "Batch update failed: " + batchPosition ); + throw new BatchFailedException( "Batch update failed: " + batchPosition ); } else { if ( expectedRowCount > rowCount ) { @@ -65,11 +65,10 @@ ); } if ( expectedRowCount < rowCount ) { - throw new HibernateException( - "Batch update returned unexpected row count from update [" + batchPosition + - "]; actual row count: " + rowCount + - "; expected: " + expectedRowCount - ); + String msg = "Batch update returned unexpected row count from update [" + + batchPosition + "]; actual row count: " + rowCount + + "; expected: " + expectedRowCount; + throw new BatchedTooManyRowsAffectedException( msg, expectedRowCount, rowCount, batchPosition ); } } } @@ -81,9 +80,8 @@ ); } if ( expectedRowCount < rowCount ) { - throw new HibernateException( - "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount - ); + String msg = "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount; + throw new TooManyRowsAffectedException( msg, expectedRowCount, rowCount ); } } Added: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,29 @@ +package org.hibernate.jdbc; + +import org.hibernate.HibernateException; + +/** + * Indicates that more rows were affected then we were expecting to be. + * Typically indicates presence of duplicate "PK" values in the + * given table. + * + * @author Steve Ebersole + */ +public class TooManyRowsAffectedException extends HibernateException { + private final int expectedRowCount; + private final int actualRowCount; + + public TooManyRowsAffectedException(String message, int expectedRowCount, int actualRowCount) { + super( message ); + this.expectedRowCount = expectedRowCount; + this.actualRowCount = actualRowCount; + } + + public int getExpectedRowCount() { + return expectedRowCount; + } + + public int getActualRowCount() { + return actualRowCount; + } +} Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -24,8 +24,10 @@ import org.hibernate.MappingException; import org.hibernate.QueryException; import org.hibernate.StaleObjectStateException; +import org.hibernate.StaleStateException; import org.hibernate.jdbc.Expectation; import org.hibernate.jdbc.Expectations; +import org.hibernate.jdbc.TooManyRowsAffectedException; import org.hibernate.dialect.lock.LockingStrategy; import org.hibernate.cache.CacheConcurrencyStrategy; import org.hibernate.cache.CacheKey; @@ -1683,8 +1685,11 @@ return createEntityLoader( lockMode, CollectionHelper.EMPTY_MAP ); } - protected boolean check(int rows, Serializable id, int tableNumber) throws HibernateException { - if ( rows < 1 ) { + protected boolean check(int rows, Serializable id, int tableNumber, Expectation expectation, PreparedStatement statement) throws HibernateException { + try { + expectation.verifyOutcome( rows, statement, -1 ); + } + catch( StaleStateException e ) { if ( !isNullableTable( tableNumber ) ) { if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatisticsImplementor() @@ -1693,13 +1698,16 @@ throw new StaleObjectStateException( getEntityName(), id ); } } - else if ( rows > 1 ) { + catch( TooManyRowsAffectedException e ) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( this, id, getFactory() ) ); } - return rows > 0; //it could be zero if we have a "nullable" table + catch ( Throwable t ) { + return false; + } + return true; } protected String generateUpdateString(boolean[] includeProperty, int j, boolean useRowId) { @@ -2173,7 +2181,7 @@ session.getBatcher().addToBatch( expectation ); } else { - insert.executeUpdate(); + expectation.verifyOutcome( insert.executeUpdate(), insert, -1 ); } } @@ -2330,7 +2338,7 @@ return true; } else { - return check( update.executeUpdate(), id, j ); + return check( update.executeUpdate(), id, j, expectation, update ); } } @@ -2431,7 +2439,7 @@ session.getBatcher().addToBatch( expectation ); } else { - check( delete.executeUpdate(), id, j ); + check( delete.executeUpdate(), id, j, expectation, delete ); } } Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -5,6 +5,9 @@ import junit.framework.TestSuite; import junit.textui.TestRunner; +import org.hibernate.dialect.Dialect; +import org.hibernate.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest; +import org.hibernate.test.abstractembeddedcomponents.propertyref.AbstractComponentPropertyRefTest; import org.hibernate.test.array.ArrayTest; import org.hibernate.test.ast.ASTIteratorTest; import org.hibernate.test.ast.ASTUtilTest; @@ -54,6 +57,7 @@ import org.hibernate.test.join.JoinTest; import org.hibernate.test.joinedsubclass.JoinedSubclassTest; import org.hibernate.test.joinfetch.JoinFetchTest; +import org.hibernate.test.jpa.JPAComplianceSuite; import org.hibernate.test.lazycache.InstrumentCacheTest; import org.hibernate.test.lazycache.InstrumentCacheTest2; import org.hibernate.test.lazyonetoone.LazyOneToOneTest; @@ -104,12 +108,7 @@ import org.hibernate.test.readonly.ReadOnlyTest; import org.hibernate.test.rowid.RowIdTest; import org.hibernate.test.sorted.SortTest; -import org.hibernate.test.sql.DataDirectOracleSQLTest; -import org.hibernate.test.sql.Db2SQLTest; -import org.hibernate.test.sql.GeneralTest; -import org.hibernate.test.sql.MSSQLTest; -import org.hibernate.test.sql.MySQLTest; -import org.hibernate.test.sql.OracleSQLTest; +import org.hibernate.test.sql.NativeSqlSupportSuite; import org.hibernate.test.stats.SessionStatsTest; import org.hibernate.test.stats.StatsTest; import org.hibernate.test.subclassfilter.DiscrimSubclassFilterTest; @@ -131,10 +130,6 @@ import org.hibernate.test.version.db.DbVersionTest; import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest; import org.hibernate.test.where.WhereTest; -import org.hibernate.test.abstractembeddedcomponents.propertyref.AbstractComponentPropertyRefTest; -import org.hibernate.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest; -import org.hibernate.test.jpa.JPAComplianceSuite; -import org.hibernate.dialect.Dialect; /** * @author Gavin King @@ -224,12 +219,7 @@ suite.addTest( org.hibernate.test.joineduid.PropertyRefTest.suite() ); suite.addTest( org.hibernate.test.orphan.PropertyRefTest.suite() ); suite.addTest( SubclassPropertyRefTest.suite() ); - suite.addTest( Db2SQLTest.suite() ); - suite.addTest( DataDirectOracleSQLTest.suite() ); - suite.addTest( OracleSQLTest.suite() ); - suite.addTest( MSSQLTest.suite() ); - suite.addTest( MySQLTest.suite() ); - suite.addTest( GeneralTest.suite() ); + suite.addTest( NativeSqlSupportSuite.suite() ); suite.addTest( CriteriaQueryTest.suite() ); suite.addTest( SubselectTest.suite() ); suite.addTest( SubselectFetchTest.suite() ); Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,24 @@ +package org.hibernate.test.sql; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.hibernate.test.sql.check.OracleCheckStyleTest; + +/** + * todo: describe NativeSqlSupportSuite + * + * @author Steve Ebersole + */ +public class NativeSqlSupportSuite { + public static Test suite() { + TestSuite suite = new TestSuite( "Native SQL support tests" ); + suite.addTest( Db2SQLTest.suite() ); + suite.addTest( DataDirectOracleSQLTest.suite() ); + suite.addTest( OracleSQLTest.suite() ); + suite.addTest( MSSQLTest.suite() ); + suite.addTest( MySQLTest.suite() ); + suite.addTest( GeneralTest.suite() ); + suite.addTest( OracleCheckStyleTest.suite() ); + return suite; + } +} Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,30 @@ +package org.hibernate.test.sql.check; + +/** + * An entity which is expected to be mapped to each database using stored + * procedures which throw exceptions on their own; in other words, using + * {@link org.hibernate.engine.ExecuteUpdateResultCheckStyle#NONE}. + * + * @author Steve Ebersole + */ +public class ExceptionCheckingEntity { + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,29 @@ +package org.hibernate.test.sql.check; + +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.Oracle9Dialect; +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * todo: describe OracleCheckStyleTest + * + * @author Steve Ebersole + */ +public class OracleCheckStyleTest extends ResultCheckStyleTest { + public OracleCheckStyleTest(String name) { + super( name ); + } + + protected String[] getMappings() { + return new String[] { "sql/check/oracle-mappings.hbm.xml" }; + } + + public boolean appliesTo(Dialect dialect) { + return dialect instanceof Oracle9Dialect; + } + + public static Test suite() { + return new TestSuite( OracleCheckStyleTest.class ); + } +} Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,29 @@ +package org.hibernate.test.sql.check; + +/** + * An entity which is expected to be mapped to each database using stored + * procedures which return "affected row counts"; in other words, using + * {@link org.hibernate.engine.ExecuteUpdateResultCheckStyle#PARAM}. + * + * @author Steve Ebersole + */ +public class ParamCheckingEntity { + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,135 @@ +package org.hibernate.test.sql.check; + +import org.hibernate.test.DatabaseSpecificTestCase; +import org.hibernate.Session; +import org.hibernate.JDBCException; +import org.hibernate.HibernateException; +import org.hibernate.dialect.Dialect; + +/** + * todo: describe ResultCheckStyleTest + * + * @author Steve Ebersole + */ +public abstract class ResultCheckStyleTest extends DatabaseSpecificTestCase { + + public ResultCheckStyleTest(String name) { + super( name ); + } + + public String getCacheConcurrencyStrategy() { + return null; + } + + public void testInsertionFailureWithExceptionChecking() { + Session s = openSession(); + s.beginTransaction(); + ExceptionCheckingEntity e = new ExceptionCheckingEntity(); + e.setName( "dummy" ); + s.save( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( JDBCException ex ) { + // these should specifically be JDBCExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testInsertionFailureWithParamChecking() { + Session s = openSession(); + s.beginTransaction(); + ParamCheckingEntity e = new ParamCheckingEntity(); + e.setName( "dummy" ); + s.save( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( HibernateException ex ) { + // these should specifically be HibernateExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testUpdateFailureWithExceptionChecking() { + Session s = openSession(); + s.beginTransaction(); + ExceptionCheckingEntity e = new ExceptionCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.update( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( JDBCException ex ) { + // these should specifically be JDBCExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testUpdateFailureWithParamChecking() { + Session s = openSession(); + s.beginTransaction(); + ParamCheckingEntity e = new ParamCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.update( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( HibernateException ex ) { + // these should specifically be HibernateExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testDeleteWithExceptionChecking() { + Session s = openSession(); + s.beginTransaction(); + ExceptionCheckingEntity e = new ExceptionCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.delete( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( JDBCException ex ) { + // these should specifically be JDBCExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testDeleteWithParamChecking() { + Session s = openSession(); + s.beginTransaction(); + ParamCheckingEntity e = new ParamCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.delete( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( HibernateException ex ) { + // these should specifically be HibernateExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } +} Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml =================================================================== --- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml 2006-08-04 17:39:14 UTC (rev 10216) +++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml 2006-08-04 17:40:56 UTC (rev 10217) @@ -0,0 +1,103 @@ +<?xml version="1.0"?> +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> + +<hibernate-mapping package="org.hibernate.test.sql.check"> + + <class name="ExceptionCheckingEntity" table="ENTITY_E"> + <id name="id" unsaved-value="0" column="ID"> + <generator class="increment"/> + </id> + <property name="name" not-null="true"/> + <sql-insert callable="true" check="none">{call createEntityE(?,?)}</sql-insert> + <sql-update callable="true" check="none">{call updateEntityE(?,?)}</sql-update> + <sql-delete callable="true" check="none">{call deleteEntityE(?)}</sql-delete> + </class> + + <class name="ParamCheckingEntity" table="ENTITY_P"> + <id name="id" unsaved-value="0" column="ID"> + <generator class="increment"/> + </id> + <property name="name" not-null="true"/> + <sql-insert callable="true" check="param">{call createEntityP(?,?,?)}</sql-insert> + <sql-update callable="true" check="param">{? = call updateEntityP(?,?)}</sql-update> + <sql-delete callable="true" check="param">{? = call deleteEntityP(?)}</sql-delete> + </class> + + + <database-object> + <create> + CREATE OR REPLACE PROCEDURE createEntityE(p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + AS BEGIN + RAISE_APPLICATION_ERROR( -20001, 'Insert failure checking' ); + END; + </create> + <drop> + DROP PROCEDURE createEntityE; + </drop> + </database-object> + + <database-object> + <create> + CREATE OR REPLACE PROCEDURE updateEntityE(p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + AS BEGIN + RAISE_APPLICATION_ERROR( -20001, 'Update failure checking' ); + END; + </create> + <drop> + DROP PROCEDURE updateEntityE; + </drop> + </database-object> + + <database-object> + <create> + CREATE OR REPLACE PROCEDURE deleteEntityE(p_id ENTITY_E.ID%TYPE) + AS BEGIN + RAISE_APPLICATION_ERROR( -20001, 'Update failure checking' ); + END; + </create> + <drop> + DROP PROCEDURE deleteEntityE; + </drop> + </database-object> + + + <database-object> + <!-- Demonstrate using an Oracle procedure and a registered OUT paramater as part of hand supplied sql --> + <create> + CREATE OR REPLACE PROCEDURE createEntityP(result OUT INTEGER, p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + AS BEGIN + /* force a failure by returning a non-1 result */ + result := 2; + END; + </create> + <drop> + DROP PROCEDURE createEntityP; + </drop> + </database-object> + + <database-object> + <!-- Demonstrate using an Oracle function and it's return value as part of hand supplied sql --> + <create> + CREATE OR REPLACE FUNCTION updateEntityP(p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + RETURN INTEGER IS BEGIN + RETURN 2; + END; + </create> + <drop> + DROP PROCEDURE updateEntityP; + </drop> + </database-object> + + <database-object> + <create> + CREATE OR REPLACE FUNCTION deleteEntityP(p_id ENTITY_E.ID%TYPE) + RETURN INTEGER IS BEGIN + RETURN 2; + END; + </create> + <drop> + DROP PROCEDURE deleteEntityE; + </drop> + </database-object> + +</hibernate-mapping> \ No newline at end of file |
From: <hib...@li...> - 2006-08-04 17:39:17
|
Author: ste...@jb... Date: 2006-08-04 13:39:14 -0400 (Fri, 04 Aug 2006) New Revision: 10216 Added: trunk/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java trunk/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java trunk/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java Modified: trunk/Hibernate3/src/org/hibernate/jdbc/Expectations.java trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java Log: HHH-1959 : apply check attribute properly in non-batched scenarios Added: trunk/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java 2006-08-04 17:35:08 UTC (rev 10215) +++ trunk/Hibernate3/src/org/hibernate/jdbc/BatchFailedException.java 2006-08-04 17:39:14 UTC (rev 10216) @@ -0,0 +1,18 @@ +package org.hibernate.jdbc; + +import org.hibernate.HibernateException; + +/** + * Indicates a failed batch entry (-3 return). + * + * @author Steve Ebersole + */ +public class BatchFailedException extends HibernateException { + public BatchFailedException(String s) { + super( s ); + } + + public BatchFailedException(String string, Throwable root) { + super( string, root ); + } +} Added: trunk/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java 2006-08-04 17:35:08 UTC (rev 10215) +++ trunk/Hibernate3/src/org/hibernate/jdbc/BatchedTooManyRowsAffectedException.java 2006-08-04 17:39:14 UTC (rev 10216) @@ -0,0 +1,21 @@ +package org.hibernate.jdbc; + +/** + * Much like {@link TooManyRowsAffectedException}, indicates that more + * rows than what we were expcecting were affected. Additionally, this form + * occurs from a batch and carries along the batch positon that failed. + * + * @author Steve Ebersole + */ +public class BatchedTooManyRowsAffectedException extends TooManyRowsAffectedException { + private final int batchPosition; + + public BatchedTooManyRowsAffectedException(String message, int expectedRowCount, int actualRowCount, int batchPosition) { + super( message, expectedRowCount, actualRowCount ); + this.batchPosition = batchPosition; + } + + public int getBatchPosition() { + return batchPosition; + } +} Modified: trunk/Hibernate3/src/org/hibernate/jdbc/Expectations.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/jdbc/Expectations.java 2006-08-04 17:35:08 UTC (rev 10215) +++ trunk/Hibernate3/src/org/hibernate/jdbc/Expectations.java 2006-08-04 17:39:14 UTC (rev 10216) @@ -54,7 +54,7 @@ } } else if ( rowCount == -3 ) { - throw new HibernateException( "Batch update failed: " + batchPosition ); + throw new BatchFailedException( "Batch update failed: " + batchPosition ); } else { if ( expectedRowCount > rowCount ) { @@ -65,11 +65,10 @@ ); } if ( expectedRowCount < rowCount ) { - throw new HibernateException( - "Batch update returned unexpected row count from update [" + batchPosition + - "]; actual row count: " + rowCount + - "; expected: " + expectedRowCount - ); + String msg = "Batch update returned unexpected row count from update [" + + batchPosition + "]; actual row count: " + rowCount + + "; expected: " + expectedRowCount; + throw new BatchedTooManyRowsAffectedException( msg, expectedRowCount, rowCount, batchPosition ); } } } @@ -81,9 +80,8 @@ ); } if ( expectedRowCount < rowCount ) { - throw new HibernateException( - "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount - ); + String msg = "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount; + throw new TooManyRowsAffectedException( msg, expectedRowCount, rowCount ); } } Added: trunk/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java 2006-08-04 17:35:08 UTC (rev 10215) +++ trunk/Hibernate3/src/org/hibernate/jdbc/TooManyRowsAffectedException.java 2006-08-04 17:39:14 UTC (rev 10216) @@ -0,0 +1,29 @@ +package org.hibernate.jdbc; + +import org.hibernate.HibernateException; + +/** + * Indicates that more rows were affected then we were expecting to be. + * Typically indicates presence of duplicate "PK" values in the + * given table. + * + * @author Steve Ebersole + */ +public class TooManyRowsAffectedException extends HibernateException { + private final int expectedRowCount; + private final int actualRowCount; + + public TooManyRowsAffectedException(String message, int expectedRowCount, int actualRowCount) { + super( message ); + this.expectedRowCount = expectedRowCount; + this.actualRowCount = actualRowCount; + } + + public int getExpectedRowCount() { + return expectedRowCount; + } + + public int getActualRowCount() { + return actualRowCount; + } +} Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-04 17:35:08 UTC (rev 10215) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-08-04 17:39:14 UTC (rev 10216) @@ -24,8 +24,10 @@ import org.hibernate.MappingException; import org.hibernate.QueryException; import org.hibernate.StaleObjectStateException; +import org.hibernate.StaleStateException; import org.hibernate.jdbc.Expectation; import org.hibernate.jdbc.Expectations; +import org.hibernate.jdbc.TooManyRowsAffectedException; import org.hibernate.dialect.lock.LockingStrategy; import org.hibernate.cache.CacheConcurrencyStrategy; import org.hibernate.cache.CacheKey; @@ -1683,8 +1685,11 @@ return createEntityLoader( lockMode, CollectionHelper.EMPTY_MAP ); } - protected boolean check(int rows, Serializable id, int tableNumber) throws HibernateException { - if ( rows < 1 ) { + protected boolean check(int rows, Serializable id, int tableNumber, Expectation expectation, PreparedStatement statement) throws HibernateException { + try { + expectation.verifyOutcome( rows, statement, -1 ); + } + catch( StaleStateException e ) { if ( !isNullableTable( tableNumber ) ) { if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatisticsImplementor() @@ -1693,13 +1698,16 @@ throw new StaleObjectStateException( getEntityName(), id ); } } - else if ( rows > 1 ) { + catch( TooManyRowsAffectedException e ) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( this, id, getFactory() ) ); } - return rows > 0; //it could be zero if we have a "nullable" table + catch ( Throwable t ) { + return false; + } + return true; } protected String generateUpdateString(boolean[] includeProperty, int j, boolean useRowId) { @@ -2173,7 +2181,7 @@ session.getBatcher().addToBatch( expectation ); } else { - insert.executeUpdate(); + expectation.verifyOutcome( insert.executeUpdate(), insert, -1 ); } } @@ -2330,7 +2338,7 @@ return true; } else { - return check( update.executeUpdate(), id, j ); + return check( update.executeUpdate(), id, j, expectation, update ); } } @@ -2362,11 +2370,11 @@ */ protected void delete( final Serializable id, - final Object version, - final int j, - final Object object, - final String sql, - final SessionImplementor session) throws HibernateException { + final Object version, + final int j, + final Object object, + final String sql, + final SessionImplementor session) throws HibernateException { if ( isInverseTable( j ) ) { return; @@ -2431,7 +2439,7 @@ session.getBatcher().addToBatch( expectation ); } else { - check( delete.executeUpdate(), id, j ); + check( delete.executeUpdate(), id, j, expectation, delete ); } } |
From: <hib...@li...> - 2006-08-04 17:35:11
|
Author: ste...@jb... Date: 2006-08-04 13:35:08 -0400 (Fri, 04 Aug 2006) New Revision: 10215 Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java Log: HHH-1959 : tests for check attribute on hand-supplied sql Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-08-04 17:31:22 UTC (rev 10214) +++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-08-04 17:35:08 UTC (rev 10215) @@ -104,12 +104,6 @@ import org.hibernate.test.readonly.ReadOnlyTest; import org.hibernate.test.rowid.RowIdTest; import org.hibernate.test.sorted.SortTest; -import org.hibernate.test.sql.DataDirectOracleSQLTest; -import org.hibernate.test.sql.Db2SQLTest; -import org.hibernate.test.sql.GeneralTest; -import org.hibernate.test.sql.MSSQLTest; -import org.hibernate.test.sql.MySQLTest; -import org.hibernate.test.sql.OracleSQLTest; import org.hibernate.test.stats.SessionStatsTest; import org.hibernate.test.stats.StatsTest; import org.hibernate.test.subclassfilter.DiscrimSubclassFilterTest; @@ -135,6 +129,7 @@ import org.hibernate.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest; import org.hibernate.test.jpa.JPAComplianceSuite; import org.hibernate.test.util.UtilSuite; +import org.hibernate.test.sql.NativeSqlSupportSuite; import org.hibernate.dialect.Dialect; /** @@ -225,12 +220,7 @@ suite.addTest( org.hibernate.test.joineduid.PropertyRefTest.suite() ); suite.addTest( org.hibernate.test.orphan.PropertyRefTest.suite() ); suite.addTest( SubclassPropertyRefTest.suite() ); - suite.addTest( Db2SQLTest.suite() ); - suite.addTest( DataDirectOracleSQLTest.suite() ); - suite.addTest( OracleSQLTest.suite() ); - suite.addTest( MSSQLTest.suite() ); - suite.addTest( MySQLTest.suite() ); - suite.addTest( GeneralTest.suite() ); + suite.addTest( NativeSqlSupportSuite.suite() ); suite.addTest( CriteriaQueryTest.suite() ); suite.addTest( SubselectTest.suite() ); suite.addTest( SubselectFetchTest.suite() ); |
From: <hib...@li...> - 2006-08-04 17:31:26
|
Author: ste...@jb... Date: 2006-08-04 13:31:22 -0400 (Fri, 04 Aug 2006) New Revision: 10214 Added: trunk/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java trunk/Hibernate3/test/org/hibernate/test/sql/check/ trunk/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java trunk/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java trunk/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java trunk/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java trunk/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml Log: HHH-1959 : tests for check attribute on hand-supplied sql Added: trunk/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java 2006-08-04 13:29:24 UTC (rev 10213) +++ trunk/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java 2006-08-04 17:31:22 UTC (rev 10214) @@ -0,0 +1,24 @@ +package org.hibernate.test.sql; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.hibernate.test.sql.check.OracleCheckStyleTest; + +/** + * todo: describe NativeSqlSupportSuite + * + * @author Steve Ebersole + */ +public class NativeSqlSupportSuite { + public static Test suite() { + TestSuite suite = new TestSuite( "Native SQL support tests" ); + suite.addTest( Db2SQLTest.suite() ); + suite.addTest( DataDirectOracleSQLTest.suite() ); + suite.addTest( OracleSQLTest.suite() ); + suite.addTest( MSSQLTest.suite() ); + suite.addTest( MySQLTest.suite() ); + suite.addTest( GeneralTest.suite() ); + suite.addTest( OracleCheckStyleTest.suite() ); + return suite; + } +} Added: trunk/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java 2006-08-04 13:29:24 UTC (rev 10213) +++ trunk/Hibernate3/test/org/hibernate/test/sql/check/ExceptionCheckingEntity.java 2006-08-04 17:31:22 UTC (rev 10214) @@ -0,0 +1,30 @@ +package org.hibernate.test.sql.check; + +/** + * An entity which is expected to be mapped to each database using stored + * procedures which throw exceptions on their own; in other words, using + * {@link org.hibernate.engine.ExecuteUpdateResultCheckStyle#NONE}. + * + * @author Steve Ebersole + */ +public class ExceptionCheckingEntity { + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + Added: trunk/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java 2006-08-04 13:29:24 UTC (rev 10213) +++ trunk/Hibernate3/test/org/hibernate/test/sql/check/OracleCheckStyleTest.java 2006-08-04 17:31:22 UTC (rev 10214) @@ -0,0 +1,29 @@ +package org.hibernate.test.sql.check; + +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.Oracle9Dialect; +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * todo: describe OracleCheckStyleTest + * + * @author Steve Ebersole + */ +public class OracleCheckStyleTest extends ResultCheckStyleTest { + public OracleCheckStyleTest(String name) { + super( name ); + } + + protected String[] getMappings() { + return new String[] { "sql/check/oracle-mappings.hbm.xml" }; + } + + public boolean appliesTo(Dialect dialect) { + return dialect instanceof Oracle9Dialect; + } + + public static Test suite() { + return new TestSuite( OracleCheckStyleTest.class ); + } +} Added: trunk/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java 2006-08-04 13:29:24 UTC (rev 10213) +++ trunk/Hibernate3/test/org/hibernate/test/sql/check/ParamCheckingEntity.java 2006-08-04 17:31:22 UTC (rev 10214) @@ -0,0 +1,29 @@ +package org.hibernate.test.sql.check; + +/** + * An entity which is expected to be mapped to each database using stored + * procedures which return "affected row counts"; in other words, using + * {@link org.hibernate.engine.ExecuteUpdateResultCheckStyle#PARAM}. + * + * @author Steve Ebersole + */ +public class ParamCheckingEntity { + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} Added: trunk/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java 2006-08-04 13:29:24 UTC (rev 10213) +++ trunk/Hibernate3/test/org/hibernate/test/sql/check/ResultCheckStyleTest.java 2006-08-04 17:31:22 UTC (rev 10214) @@ -0,0 +1,135 @@ +package org.hibernate.test.sql.check; + +import org.hibernate.test.DatabaseSpecificTestCase; +import org.hibernate.Session; +import org.hibernate.JDBCException; +import org.hibernate.HibernateException; +import org.hibernate.dialect.Dialect; + +/** + * todo: describe ResultCheckStyleTest + * + * @author Steve Ebersole + */ +public abstract class ResultCheckStyleTest extends DatabaseSpecificTestCase { + + public ResultCheckStyleTest(String name) { + super( name ); + } + + public String getCacheConcurrencyStrategy() { + return null; + } + + public void testInsertionFailureWithExceptionChecking() { + Session s = openSession(); + s.beginTransaction(); + ExceptionCheckingEntity e = new ExceptionCheckingEntity(); + e.setName( "dummy" ); + s.save( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( JDBCException ex ) { + // these should specifically be JDBCExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testInsertionFailureWithParamChecking() { + Session s = openSession(); + s.beginTransaction(); + ParamCheckingEntity e = new ParamCheckingEntity(); + e.setName( "dummy" ); + s.save( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( HibernateException ex ) { + // these should specifically be HibernateExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testUpdateFailureWithExceptionChecking() { + Session s = openSession(); + s.beginTransaction(); + ExceptionCheckingEntity e = new ExceptionCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.update( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( JDBCException ex ) { + // these should specifically be JDBCExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testUpdateFailureWithParamChecking() { + Session s = openSession(); + s.beginTransaction(); + ParamCheckingEntity e = new ParamCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.update( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( HibernateException ex ) { + // these should specifically be HibernateExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testDeleteWithExceptionChecking() { + Session s = openSession(); + s.beginTransaction(); + ExceptionCheckingEntity e = new ExceptionCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.delete( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( JDBCException ex ) { + // these should specifically be JDBCExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } + + public void testDeleteWithParamChecking() { + Session s = openSession(); + s.beginTransaction(); + ParamCheckingEntity e = new ParamCheckingEntity(); + e.setId( new Long( 1 ) ); + e.setName( "dummy" ); + s.delete( e ); + try { + s.flush(); + fail( "expection flush failure!" ); + } + catch( HibernateException ex ) { + // these should specifically be HibernateExceptions... + } + s.clear(); + s.getTransaction().commit(); + s.close(); + } +} Added: trunk/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml 2006-08-04 13:29:24 UTC (rev 10213) +++ trunk/Hibernate3/test/org/hibernate/test/sql/check/oracle-mappings.hbm.xml 2006-08-04 17:31:22 UTC (rev 10214) @@ -0,0 +1,103 @@ +<?xml version="1.0"?> +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> + +<hibernate-mapping package="org.hibernate.test.sql.check"> + + <class name="ExceptionCheckingEntity" table="ENTITY_E"> + <id name="id" unsaved-value="0" column="ID"> + <generator class="increment"/> + </id> + <property name="name" not-null="true"/> + <sql-insert callable="true" check="none">{call createEntityE(?,?)}</sql-insert> + <sql-update callable="true" check="none">{call updateEntityE(?,?)}</sql-update> + <sql-delete callable="true" check="none">{call deleteEntityE(?)}</sql-delete> + </class> + + <class name="ParamCheckingEntity" table="ENTITY_P"> + <id name="id" unsaved-value="0" column="ID"> + <generator class="increment"/> + </id> + <property name="name" not-null="true"/> + <sql-insert callable="true" check="param">{call createEntityP(?,?,?)}</sql-insert> + <sql-update callable="true" check="param">{? = call updateEntityP(?,?)}</sql-update> + <sql-delete callable="true" check="param">{? = call deleteEntityP(?)}</sql-delete> + </class> + + + <database-object> + <create> + CREATE OR REPLACE PROCEDURE createEntityE(p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + AS BEGIN + RAISE_APPLICATION_ERROR( -20001, 'Insert failure checking' ); + END; + </create> + <drop> + DROP PROCEDURE createEntityE; + </drop> + </database-object> + + <database-object> + <create> + CREATE OR REPLACE PROCEDURE updateEntityE(p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + AS BEGIN + RAISE_APPLICATION_ERROR( -20001, 'Update failure checking' ); + END; + </create> + <drop> + DROP PROCEDURE updateEntityE; + </drop> + </database-object> + + <database-object> + <create> + CREATE OR REPLACE PROCEDURE deleteEntityE(p_id ENTITY_E.ID%TYPE) + AS BEGIN + RAISE_APPLICATION_ERROR( -20001, 'Update failure checking' ); + END; + </create> + <drop> + DROP PROCEDURE deleteEntityE; + </drop> + </database-object> + + + <database-object> + <!-- Demonstrate using an Oracle procedure and a registered OUT paramater as part of hand supplied sql --> + <create> + CREATE OR REPLACE PROCEDURE createEntityP(result OUT INTEGER, p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + AS BEGIN + /* force a failure by returning a non-1 result */ + result := 2; + END; + </create> + <drop> + DROP PROCEDURE createEntityP; + </drop> + </database-object> + + <database-object> + <!-- Demonstrate using an Oracle function and it's return value as part of hand supplied sql --> + <create> + CREATE OR REPLACE FUNCTION updateEntityP(p_name ENTITY_E.NAME%TYPE, p_id ENTITY_E.ID%TYPE) + RETURN INTEGER IS BEGIN + RETURN 2; + END; + </create> + <drop> + DROP PROCEDURE updateEntityP; + </drop> + </database-object> + + <database-object> + <create> + CREATE OR REPLACE FUNCTION deleteEntityP(p_id ENTITY_E.ID%TYPE) + RETURN INTEGER IS BEGIN + RETURN 2; + END; + </create> + <drop> + DROP PROCEDURE deleteEntityE; + </drop> + </database-object> + +</hibernate-mapping> \ No newline at end of file |
From: <hib...@li...> - 2006-08-04 13:29:41
|
Author: ste...@jb... Date: 2006-08-04 09:29:24 -0400 (Fri, 04 Aug 2006) New Revision: 10213 Modified: trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java Log: clear warnings after logging them Modified: trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-08-04 13:00:30 UTC (rev 10212) +++ trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-08-04 13:29:24 UTC (rev 10213) @@ -306,10 +306,16 @@ } if ( export ) { statement.executeUpdate( sql ); - SQLWarning warnings = statement.getWarnings(); - if ( warnings != null) { - JDBCExceptionReporter.logWarnings( warnings ); + try { + SQLWarning warnings = statement.getWarnings(); + if ( warnings != null) { + JDBCExceptionReporter.logWarnings( warnings ); + connectionHelper.getConnection().clearWarnings(); + } } + catch( SQLException sqle ) { + log.warn( "unable to log SQLWarnings : " + sqle ); + } } |