Hibernate SVN: r19588 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-22 08:31:15 -0400 (Sat, 22 May 2010)
New Revision: 19588
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java
Log:
HV-274 removed some unnecessary depednecies between util and privilegedaction package
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java 2010-05-22 12:09:58 UTC (rev 19587)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java 2010-05-22 12:31:15 UTC (rev 19588)
@@ -1,43 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validator.util.privilegedactions;
-
-import java.security.PrivilegedAction;
-
-import org.hibernate.validator.util.ReflectionHelper;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ContainsMethod implements PrivilegedAction<Boolean> {
- private final Class<?> clazz;
- private final String property;
-
- public static ContainsMethod action(Class<?> clazz, String property) {
- return new ContainsMethod( clazz, property );
- }
-
- private ContainsMethod(Class<?> clazz, String property) {
- this.clazz = clazz;
- this.property = property;
- }
-
- public Boolean run() {
- return ReflectionHelper.getMethodFromPropertyName( clazz, property ) != null;
- }
-}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java 2010-05-22 12:09:58 UTC (rev 19587)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java 2010-05-22 12:31:15 UTC (rev 19588)
@@ -20,8 +20,6 @@
import java.lang.reflect.Field;
import java.security.PrivilegedAction;
-import org.hibernate.validator.util.ReflectionHelper;
-
/**
* @author Emmanuel Bernard
*/
@@ -41,7 +39,7 @@
public Field run() {
try {
final Field field = clazz.getDeclaredField( fieldName );
- ReflectionHelper.setAccessibility( field );
+ field.setAccessible( true );
return field;
}
catch ( NoSuchFieldException e ) {
14 years, 7 months
Hibernate SVN: r19587 - in validator/trunk: hibernate-validator and 15 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-22 08:09:58 -0400 (Sat, 22 May 2010)
New Revision: 19587
Added:
validator/trunk/hibernate-validator/src/main/javadoc/
validator/trunk/hibernate-validator/src/main/javadoc/package.html
validator/trunk/hibernate-validator/src/main/javadoc/resources/
validator/trunk/hibernate-validator/src/main/javadoc/resources/bkg_blkheader.png
validator/trunk/hibernate-validator/src/main/javadoc/resources/bkg_gradient.gif
validator/trunk/hibernate-validator/src/main/javadoc/resources/bkgheader.png
validator/trunk/hibernate-validator/src/main/javadoc/resources/h1_hdr.png
validator/trunk/hibernate-validator/src/main/javadoc/stylesheet.css
Modified:
validator/trunk/hibernate-validator/pom.xml
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/scriptassert/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/groups/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html
validator/trunk/pom.xml
Log:
HV-325
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/pom.xml 2010-05-22 12:09:58 UTC (rev 19587)
@@ -204,6 +204,23 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <docfilessubdirs>true</docfilessubdirs>
+ <stylesheetfile>${basedir}/src/main/javadoc/stylesheet.css</stylesheetfile>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ <link>http://docs.jboss.org/hibernate/stable/beanvalidation/api/</link>
+ </links>
+ <packagesheader>Hibernate Validator Packages</packagesheader>
+ <doctitle>Hibernate Validator ${project.version}</doctitle>
+ <windowtitle>Hibernate Validator ${project.version}</windowtitle>
+ <bottom>
+ <![CDATA[Copyright © ${inceptionYear}-{currentYear} <a href="http://redhat.com">Red Hat Middleware, LLC.</a> All Rights Reserved]]></bottom>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jdocbook-plugin</artifactId>
<extensions>true</extensions>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,7 +21,7 @@
-->
</head>
<body>
-This package contains the implementations of the built-in as well as Hibernate Validator specific
+Implementations of the built-in as well as Hibernate Validator specific
constraints.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/scriptassert/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/scriptassert/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/scriptassert/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-This package contains classes related to the evaluation of the @ScriptAssert constraint.
+Classes related to the evaluation of the @ScriptAssert constraint.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,7 +21,7 @@
-->
</head>
<body>
-This package contains the Hibernate Validator specific constraints. Classes in this package are part of the public Hibernate
+Hibernate Validator specific constraints. Classes in this package are part of the public Hibernate
Validator API.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/groups/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/groups/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/groups/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-This package contains helper classes for the processing of groups.
+Helper classes for the processing of groups.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-This package contains the implementing classes for the core interfaces of JSR-303.
+Implementations for the core interfaces of JSR-303.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-This package contains different implementations of the TraversableResolver interface.
+Various implementations of the TraversableResolver interface.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -22,8 +22,7 @@
<head>
</head>
<body>
-Classes in this package are part of the public Hibernate Validator API. The package contains implementations of the
-MessageInterpolator interface in particular ResourceBundleMessageInterpolator which can be used by custom implementations
-of the interface for delegation.
+Implementations of the MessageInterpolator interface in particular ResourceBundleMessageInterpolator which can be used
+by custom implementations of the interface for delegation. Classes in this package are part of the public Hibernate Validator API.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -22,7 +22,7 @@
<head>
</head>
<body>
-This package contains the classes HibernateValidator and HibernateValidatorConfiguration. These classes are used to
+Contains the classes HibernateValidator and HibernateValidatorConfiguration. These classes are used to
bootstrap and configure Hibernate Validator and form part of the public Hibernate Validator API.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,7 +21,6 @@
-->
</head>
<body>
-This package contains the ResourceBundleLocator interface and different implementations. It is part of the Hibernate
-Validator public API.
+ResourceBundleLocator interface and its various implementations. Part of the Hibernate Validator public API.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-Classes in this package allow to generate annotation proxies.
+Annotation proxy helper.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-This package contains independend helper classes.
+Independent helper classes.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-Implementations of {@code PrivilegedAction} in order to execute reflection operations in a security manager.
+Implementations of PrivilegedAction in order to execute reflection operations in a security manager.
</body>
</html>
Added: validator/trunk/hibernate-validator/src/main/javadoc/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/javadoc/package.html (rev 0)
+++ validator/trunk/hibernate-validator/src/main/javadoc/package.html 2010-05-22 12:09:58 UTC (rev 19587)
@@ -0,0 +1,54 @@
+<body>
+
+<h2>Hibernate Core (native API) JavaDocs</h2>
+
+In addition to {@link org.hibernate.SessionFactory} and {@link org.hibernate.Session}, applications using the
+Hibernate native API will often need to utilize the following interfaces:<ul>
+ <li>{@link org.hibernate.cfg.Configuration}</li>
+ <li>{@link org.hibernate.Hibernate}</li>
+ <li>{@link org.hibernate.Transaction}</li>
+ <li>{@link org.hibernate.Query}</li>
+ <li>{@link org.hibernate.Criteria}</li>
+ <li>{@link org.hibernate.criterion.Projection}</li>
+ <li>{@link org.hibernate.criterion.Projections}</li>
+ <li>{@link org.hibernate.criterion.Criterion}</li>
+ <li>{@link org.hibernate.criterion.Restrictions}</li>
+ <li>{@link org.hibernate.criterion.Order}</li>
+ <li>{@link org.hibernate.criterion.Example}</li>
+</ul>
+These interfaces are fully intended to be exposed to application code.
+<hr/>
+
+<h3>Extensions</h3>
+Hibernate defines a number of interfaces that are completely intended to be extendable by application programmers and/or
+integrators. Listed below is a (not necessarily exhaustive) list of the most commonly utilized extension points:<ul>
+ <li>{@link org.hibernate.EntityNameResolver}</li>
+ <li>{@link org.hibernate.Interceptor} / {@link org.hibernate.EmptyInterceptor}</li>
+ <li>{@link org.hibernate.Transaction} / {@link org.hibernate.transaction.TransactionFactory}</li>
+ <li>{@link org.hibernate.context.CurrentSessionContext}</li>
+ <li>{@link org.hibernate.dialect.Dialect}</li>
+ <li>{@link org.hibernate.dialect.resolver.DialectResolver}</li>
+ <li>{@link org.hibernate.event event listener} interfaces</li>
+ <li>{@link org.hibernate.id.IdentifierGenerator}</li>
+ <li>{@link org.hibernate.tuple.entity.EntityTuplizer} / {@link org.hibernate.tuple.component.ComponentTuplizer}</li>
+ <li>{@link org.hibernate.type.Type} / {@link org.hibernate.usertype}</li>
+</ul>
+Note that there is a large degree of crossover between the notion of extension points and that of an integration SPI (below).
+<hr/>
+
+<h3>Integration SPI</h3>
+Hibernate provides a number of SPIs intended to integrate itself with various third party frameworks or application code to provide
+additional capabilities. The SPIs fall mainly into 2 categories:<ul>
+ <li>Caching - {@link org.hibernate.cache.RegionFactory}</li>
+ <li>JDBC Connection management - {@link org.hibernate.connection.ConnectionProvider}
+</ul>
+Certainly {@link org.hibernate.dialect.Dialect} could fit in here as well, though we chose to list it under extensions since application
+developers tend to provide extended dialects rather frequently for various reasons.
+<br/>
+Another SPI that is not yet exposed but is planned for such is the <em>bytecode provider</em> SPI. See {@link org.hibernate.bytecode}
+for details.
+<hr/>
+
+Complete Hibernate documentation may be found online at <a href="http://docs.jboss.org/hibernate/">http://docs.jboss.org/hibernate/</a>.
+
+</body>
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/javadoc/resources/bkg_blkheader.png
===================================================================
(Binary files differ)
Property changes on: validator/trunk/hibernate-validator/src/main/javadoc/resources/bkg_blkheader.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: validator/trunk/hibernate-validator/src/main/javadoc/resources/bkg_gradient.gif
===================================================================
(Binary files differ)
Property changes on: validator/trunk/hibernate-validator/src/main/javadoc/resources/bkg_gradient.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: validator/trunk/hibernate-validator/src/main/javadoc/resources/bkgheader.png
===================================================================
(Binary files differ)
Property changes on: validator/trunk/hibernate-validator/src/main/javadoc/resources/bkgheader.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: validator/trunk/hibernate-validator/src/main/javadoc/resources/h1_hdr.png
===================================================================
(Binary files differ)
Property changes on: validator/trunk/hibernate-validator/src/main/javadoc/resources/h1_hdr.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: validator/trunk/hibernate-validator/src/main/javadoc/stylesheet.css
===================================================================
--- validator/trunk/hibernate-validator/src/main/javadoc/stylesheet.css (rev 0)
+++ validator/trunk/hibernate-validator/src/main/javadoc/stylesheet.css 2010-05-22 12:09:58 UTC (rev 19587)
@@ -0,0 +1,174 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Custom Hibernate javadoc style sheet
+ */
+
+/* Page background color */
+body {
+ background: #FFFFFF url(resources/bkg_gradient.gif) repeat-x;
+ margin:0 auto;
+ font-family:'Lucida Grande', Geneva, Verdana, Arial, sans-serif;
+ font-size:12px;
+ padding:0 2em;
+ color:#333;
+
+ }
+
+/* Common elements */
+
+font {
+ font-family: inherit, sans-serif;
+ font-size: inherit;
+ color: inherit;
+ font-weight: inherit;
+}
+
+hr {
+ border-style: none;
+ border-bottom: 1px solid #CCCCCC;
+}
+
+/* Links */
+a:link {
+ color:#003399;
+}
+a:visited {
+ color:#888888;
+}
+a:hover {
+ color:#6699cc;
+}
+a:active {
+ color: #003399;
+}
+
+/* Headings */
+h1 {
+ background: url(resources/h1_hdr.png) no-repeat;
+ line-height:1.2em;
+ color:#586464;
+ font-size:2em;
+ padding:1.5em;
+ margin-top: 0;
+ text-align:left;
+}
+
+h2 {
+ color:#586464;
+}
+
+
+/* Default Table elements and colors */
+
+th, table {
+ border-collapse:collapse;
+ border-color: #E6E7E8;
+}
+
+
+.TableHeadingColor {
+ background:#000000 url(resources/bkg_blkheader.png) repeat-x scroll left top;
+ color:#FFFFFF;
+ font-size:12px;
+ font-weight:bold;
+ height:31px;
+ text-align:left;
+ padding:1.5em;
+}
+
+.TableHeadingColor th {
+ padding-left: 10px;
+}
+
+
+.TableSubHeadingColor {
+ background: #ebe7d7;
+}
+.TableRowColor {
+ background: #FFFFFF;
+ border-color: #E6E7E8;
+}
+.TableRowColor td {
+ line-height: 175%;
+ padding-left: 10px;
+}
+
+/* Font used in left-hand frame lists */
+.FrameTitleFont {
+ font-size: 125%;
+ font-family: Helvetica, Arial, sans-serif;
+ font-weight: bold;
+ margin-top: 1em;
+ display: block;
+}
+.FrameHeadingFont {
+ font-size: 125%;
+ font-family: 'Lucida Grande', Geneva, Verdana, Arial, sans-serif;
+ font-weight: bold;
+ margin-top: 1em;
+ display: block;
+ color:#586464;
+ border-bottom:1px dotted #CCCCCC;
+}
+.FrameItemFont {
+ font-size: 100%;
+ font-family: Helvetica, Arial, sans-serif
+}
+
+/* Navigation bar fonts and colors */
+
+.NavBarCell1 {
+ background: #ffffff url(resources/bkgheader.png) repeat-x;
+ line-height:3em;
+ padding-left:10px;
+ padding-right:10px;
+}
+
+.NavBarFont1 {
+ color: white;
+}
+.NavBarCell1 a {
+ color: white;
+}
+
+.NavBarCell1Rev {
+ background-color:#FFFFFF;
+ padding-left:6px;
+ padding-right:6px;
+}
+.NavBarFont1 {
+ color:#FFFFFF;
+}
+.NavBarFont1Rev {
+ color:#243446;
+}
+
+.NavBarCell2 {
+ background-color:#FFFFFF;
+}
+.NavBarCell3 {
+ background-color:#FFFFFF;
+}
Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml 2010-05-21 21:20:36 UTC (rev 19586)
+++ validator/trunk/pom.xml 2010-05-22 12:09:58 UTC (rev 19587)
@@ -35,7 +35,7 @@
<email>gunnar.morling(a)googlemail.com</email>
<organization>Individual</organization>
<url>http://musingsofaprogrammingaddict.blogspot.com/</url>
- </developer>
+ </developer>
</developers>
<mailingLists>
@@ -297,6 +297,11 @@
<artifactId>maven-archetype-plugin</artifactId>
<version>2.0-alpha-4</version>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.7</version>
+ </plugin>
</plugins>
</pluginManagement>
</build>
@@ -346,26 +351,6 @@
<version>2.0.1</version>
</plugin>
<plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <reportSets>
- <reportSet>
- <id>html</id>
- <configuration>
- <tags>
- <tag>
- <name>todo</name>
- <placement>a</placement>
- <head>ToDo:</head>
- </tag>
- </tags>
- </configuration>
- <reports>
- <report>javadoc</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jxr-maven-plugin</artifactId>
</plugin>
14 years, 7 months
Hibernate SVN: r19586 - in core/trunk/core/src: test/java/org/hibernate/id and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-21 17:20:36 -0400 (Fri, 21 May 2010)
New Revision: 19586
Added:
core/trunk/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java
Modified:
core/trunk/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java
Log:
HHH-5253 - TableHiLoGenerator does not increment hi-value any more when lo-range es exhausted
Modified: core/trunk/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java 2010-05-21 21:19:56 UTC (rev 19585)
+++ core/trunk/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java 2010-05-21 21:20:36 UTC (rev 19586)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,17 +20,16 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.id;
import java.io.Serializable;
import java.util.Properties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.id.enhanced.AccessCallback;
+import org.hibernate.id.enhanced.OptimizerFactory;
import org.hibernate.type.Type;
import org.hibernate.util.PropertiesHelper;
@@ -38,7 +37,7 @@
* <b>hilo</b><br>
* <br>
* An <tt>IdentifierGenerator</tt> that returns a <tt>Long</tt>, constructed using
- * a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction
+ * a hi/lo algorithm. The hi value MUST be fetched in a separate transaction
* to the <tt>Session</tt> transaction so the generator must be able to obtain
* a new connection and commit it. Hence this implementation may not
* be used when the user is supplying connections. In this
@@ -51,26 +50,25 @@
* @author Gavin King
*/
public class TableHiLoGenerator extends TableGenerator {
-
/**
* The max_lo parameter
*/
public static final String MAX_LO = "max_lo";
+ private OptimizerFactory.LegacyHiLoAlgorithmOptimizer hiloOptimizer;
+
private int maxLo;
- private int lo;
- private IntegralDataTypeHolder value;
-
- private static final Logger log = LoggerFactory.getLogger(TableHiLoGenerator.class);
-
public void configure(Type type, Properties params, Dialect d) {
super.configure(type, params, d);
maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
- lo = maxLo + 1; // so we "clock over" on the first invocation
+
+ if ( maxLo >= 1 ) {
+ hiloOptimizer = new OptimizerFactory.LegacyHiLoAlgorithmOptimizer( type.getReturnedClass(), maxLo );
+ }
}
- public synchronized Serializable generate(SessionImplementor session, Object obj) {
+ public synchronized Serializable generate(final SessionImplementor session, Object obj) {
// maxLo < 1 indicates a hilo generator with no hilo :?
if ( maxLo < 1 ) {
//keep the behavior consistent even for boundary usages
@@ -81,16 +79,13 @@
return value.makeValue();
}
- if ( lo > maxLo ) {
- IntegralDataTypeHolder hiVal = generateHolder( session );
- lo = ( hiVal.eq( 0 ) ) ? 1 : 0;
- value = hiVal.copy().multiplyBy( maxLo+1 ).add( lo );
- if ( log.isDebugEnabled() ) {
- log.debug("new hi value: " + hiVal);
- }
- }
-
- return value.makeValueThenIncrement();
+ return hiloOptimizer.generate(
+ new AccessCallback() {
+ public IntegralDataTypeHolder getNextValue() {
+ return generateHolder( session );
+ }
+ }
+ );
}
}
Copied: core/trunk/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java (from rev 19581, core/trunk/core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java)
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java 2010-05-21 21:20:36 UTC (rev 19586)
@@ -0,0 +1,170 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.TestingDatabaseInfo;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.cfg.ObjectNameNormalizer;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.H2Dialect;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.impl.SessionImpl;
+import org.hibernate.jdbc.Work;
+import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
+
+/**
+ * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
+ * unit test so that we can make sure the value keep being generated in the expected manner
+ *
+ * @author Steve Ebersole
+ */
+@SuppressWarnings({ "deprecation" })
+public class TableHiLoGeneratorTest extends TestCase {
+ private static final String GEN_TABLE = "generator_table";
+ private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME;
+
+ private Configuration cfg;
+ private SessionFactoryImplementor sessionFactory;
+ private TableHiLoGenerator generator;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Properties properties = new Properties();
+ properties.setProperty( TableHiLoGenerator.TABLE, GEN_TABLE );
+ properties.setProperty( TableHiLoGenerator.COLUMN, GEN_COLUMN );
+ properties.setProperty( TableHiLoGenerator.MAX_LO, "3" );
+ properties.put(
+ PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
+ new ObjectNameNormalizer() {
+ @Override
+ protected boolean isUseQuotedIdentifiersGlobally() {
+ return false;
+ }
+
+ @Override
+ protected NamingStrategy getNamingStrategy() {
+ return cfg.getNamingStrategy();
+ }
+ }
+ );
+
+ Dialect dialect = new H2Dialect();
+
+ generator = new TableHiLoGenerator();
+ generator.configure( Hibernate.LONG, properties, dialect );
+
+ cfg = TestingDatabaseInfo.buildBaseConfiguration()
+ .setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ cfg.addAuxiliaryDatabaseObject(
+ new SimpleAuxiliaryDatabaseObject(
+ generator.sqlCreateStrings( dialect )[0],
+ generator.sqlDropStrings( dialect )[0]
+ )
+ );
+
+ cfg.addAuxiliaryDatabaseObject(
+ new SimpleAuxiliaryDatabaseObject(
+ generator.sqlCreateStrings( dialect )[1],
+ null
+ )
+ );
+
+ sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if ( sessionFactory != null ) {
+ sessionFactory.close();
+ }
+
+ super.tearDown();
+ }
+
+ public void testHiLoAlgorithm() {
+ SessionImpl session = (SessionImpl) sessionFactory.openSession();
+ session.beginTransaction();
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // initially sequence should be uninitialized
+ assertEquals( 0L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ Long generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 1L, generatedValue.longValue() );
+ assertEquals( 1L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 2L, generatedValue.longValue() );
+ assertEquals( 1L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 3L, generatedValue.longValue() );
+ assertEquals( 1L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 4L, generatedValue.longValue() );
+ assertEquals( 2L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 5L, generatedValue.longValue() );
+ assertEquals( 2L, extractInDatabaseValue( session ) );
+
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ private long extractInDatabaseValue(Session session) {
+ class WorkImpl implements Work {
+ private long value;
+ public void execute(Connection connection) throws SQLException {
+ PreparedStatement query = connection.prepareStatement( "select " + GEN_COLUMN + " from " + GEN_TABLE );
+ ResultSet resultSet = query.executeQuery();
+ resultSet.next();
+ value = resultSet.getLong( 1 );
+ }
+ }
+ WorkImpl work = new WorkImpl();
+ session.doWork( work );
+ return work.value;
+ }
+}
\ No newline at end of file
14 years, 7 months
Hibernate SVN: r19585 - in core/branches/Branch_3_5/core/src: test/java/org/hibernate/id and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-21 17:19:56 -0400 (Fri, 21 May 2010)
New Revision: 19585
Added:
core/branches/Branch_3_5/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java
Log:
HHH-5253 - TableHiLoGenerator does not increment hi-value any more when lo-range es exhausted
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java 2010-05-21 19:38:04 UTC (rev 19584)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java 2010-05-21 21:19:56 UTC (rev 19585)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,17 +20,16 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.id;
import java.io.Serializable;
import java.util.Properties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.id.enhanced.AccessCallback;
+import org.hibernate.id.enhanced.OptimizerFactory;
import org.hibernate.type.Type;
import org.hibernate.util.PropertiesHelper;
@@ -38,7 +37,7 @@
* <b>hilo</b><br>
* <br>
* An <tt>IdentifierGenerator</tt> that returns a <tt>Long</tt>, constructed using
- * a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction
+ * a hi/lo algorithm. The hi value MUST be fetched in a separate transaction
* to the <tt>Session</tt> transaction so the generator must be able to obtain
* a new connection and commit it. Hence this implementation may not
* be used when the user is supplying connections. In this
@@ -51,26 +50,25 @@
* @author Gavin King
*/
public class TableHiLoGenerator extends TableGenerator {
-
/**
* The max_lo parameter
*/
public static final String MAX_LO = "max_lo";
+ private OptimizerFactory.LegacyHiLoAlgorithmOptimizer hiloOptimizer;
+
private int maxLo;
- private int lo;
- private IntegralDataTypeHolder value;
-
- private static final Logger log = LoggerFactory.getLogger(TableHiLoGenerator.class);
-
public void configure(Type type, Properties params, Dialect d) {
super.configure(type, params, d);
maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
- lo = maxLo + 1; // so we "clock over" on the first invocation
+
+ if ( maxLo >= 1 ) {
+ hiloOptimizer = new OptimizerFactory.LegacyHiLoAlgorithmOptimizer( type.getReturnedClass(), maxLo );
+ }
}
- public synchronized Serializable generate(SessionImplementor session, Object obj) {
+ public synchronized Serializable generate(final SessionImplementor session, Object obj) {
// maxLo < 1 indicates a hilo generator with no hilo :?
if ( maxLo < 1 ) {
//keep the behavior consistent even for boundary usages
@@ -81,16 +79,13 @@
return value.makeValue();
}
- if ( lo > maxLo ) {
- IntegralDataTypeHolder hiVal = generateHolder( session );
- lo = ( hiVal.eq( 0 ) ) ? 1 : 0;
- value = hiVal.copy().multiplyBy( maxLo+1 ).add( lo );
- if ( log.isDebugEnabled() ) {
- log.debug("new hi value: " + hiVal);
- }
- }
-
- return value.makeValueThenIncrement();
+ return hiloOptimizer.generate(
+ new AccessCallback() {
+ public IntegralDataTypeHolder getNextValue() {
+ return generateHolder( session );
+ }
+ }
+ );
}
}
Added: core/branches/Branch_3_5/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java
===================================================================
--- core/branches/Branch_3_5/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java (rev 0)
+++ core/branches/Branch_3_5/core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java 2010-05-21 21:19:56 UTC (rev 19585)
@@ -0,0 +1,167 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.TestingDatabaseInfo;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.cfg.ObjectNameNormalizer;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.impl.SessionImpl;
+import org.hibernate.jdbc.Work;
+import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
+
+/**
+ * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
+ * unit test so that we can make sure the value keep being generated in the expected manner
+ *
+ * @author Steve Ebersole
+ */
+public class TableHiLoGeneratorTest extends TestCase {
+ private static final String GEN_TABLE = "generator_table";
+ private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME;
+
+ private Configuration cfg;
+ private SessionFactoryImplementor sessionFactory;
+ private TableHiLoGenerator generator;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Properties properties = new Properties();
+ properties.setProperty( TableHiLoGenerator.TABLE, GEN_TABLE );
+ properties.setProperty( TableHiLoGenerator.COLUMN, GEN_COLUMN );
+ properties.setProperty( TableHiLoGenerator.MAX_LO, "3" );
+ properties.put(
+ PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
+ new ObjectNameNormalizer() {
+ protected boolean isUseQuotedIdentifiersGlobally() {
+ return false;
+ }
+
+ protected NamingStrategy getNamingStrategy() {
+ return cfg.getNamingStrategy();
+ }
+ }
+ );
+
+ Dialect dialect = new HSQLDialect();
+
+ generator = new TableHiLoGenerator();
+ generator.configure( Hibernate.LONG, properties, dialect );
+
+ cfg = TestingDatabaseInfo.buildBaseConfiguration()
+ .setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ cfg.addAuxiliaryDatabaseObject(
+ new SimpleAuxiliaryDatabaseObject(
+ generator.sqlCreateStrings( dialect )[0],
+ generator.sqlDropStrings( dialect )[0]
+ )
+ );
+
+ cfg.addAuxiliaryDatabaseObject(
+ new SimpleAuxiliaryDatabaseObject(
+ // the row insertion
+ generator.sqlCreateStrings( dialect )[1],
+ // hsqldb needs some drop string
+ "select count(1) from " + GEN_TABLE
+ )
+ );
+
+ sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory();
+ }
+
+ protected void tearDown() throws Exception {
+ if ( sessionFactory != null ) {
+ sessionFactory.close();
+ }
+
+ super.tearDown();
+ }
+
+ public void testHiLoAlgorithm() {
+ SessionImpl session = (SessionImpl) sessionFactory.openSession();
+ session.beginTransaction();
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // initially sequence should be uninitialized
+ assertEquals( 0L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ Long generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 1L, generatedValue.longValue() );
+ assertEquals( 1L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 2L, generatedValue.longValue() );
+ assertEquals( 1L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 3L, generatedValue.longValue() );
+ assertEquals( 1L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 4L, generatedValue.longValue() );
+ assertEquals( 2L, extractInDatabaseValue( session ) );
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generatedValue = (Long) generator.generate( session, null );
+ assertEquals( 5L, generatedValue.longValue() );
+ assertEquals( 2L, extractInDatabaseValue( session ) );
+
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ private long extractInDatabaseValue(Session session) {
+ class WorkImpl implements Work {
+ private long value;
+ public void execute(Connection connection) throws SQLException {
+ PreparedStatement query = connection.prepareStatement( "select " + GEN_COLUMN + " from " + GEN_TABLE );
+ ResultSet resultSet = query.executeQuery();
+ resultSet.next();
+ value = resultSet.getLong( 1 );
+ }
+ }
+ WorkImpl work = new WorkImpl();
+ session.doWork( work );
+ return work.value;
+ }
+}
\ No newline at end of file
14 years, 7 months
Hibernate SVN: r19584 - in core/trunk/core/src/main/java/org/hibernate: impl and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-21 15:38:04 -0400 (Fri, 21 May 2010)
New Revision: 19584
Removed:
core/trunk/core/src/main/java/org/hibernate/util/FastHashMap.java
Modified:
core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java
core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java
core/trunk/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java
core/trunk/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java
core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java
Log:
HHH-3050 - Convert usage of Hibernate's FastHashMap to ConcurrentHashMap (Java 1.5)
Modified: core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java 2010-05-21 17:57:21 UTC (rev 19583)
+++ core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java 2010-05-21 19:38:04 UTC (rev 19584)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,12 +20,12 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.id.factory;
import java.util.Properties;
import java.io.Serializable;
+import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,7 +46,6 @@
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.enhanced.TableGenerator;
import org.hibernate.type.Type;
-import org.hibernate.util.FastHashMap;
import org.hibernate.util.ReflectHelper;
import org.hibernate.dialect.Dialect;
import org.hibernate.MappingException;
@@ -60,7 +59,7 @@
private static final Logger log = LoggerFactory.getLogger( DefaultIdentifierGeneratorFactory.class );
private transient Dialect dialect;
- private FastHashMap generatorStrategyToClassNameMap = new FastHashMap();
+ private ConcurrentHashMap<String, Class> generatorStrategyToClassNameMap = new ConcurrentHashMap<String, Class>();
/**
* Constructs a new DefaultIdentifierGeneratorFactory.
@@ -126,7 +125,7 @@
return dialect.getNativeIdentifierGeneratorClass();
}
- Class generatorClass = ( Class ) generatorStrategyToClassNameMap.get( strategy );
+ Class generatorClass = generatorStrategyToClassNameMap.get( strategy );
try {
if ( generatorClass == null ) {
generatorClass = ReflectHelper.classForName( strategy );
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java 2010-05-21 17:57:21 UTC (rev 19583)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryObjectFactory.java 2010-05-21 19:38:04 UTC (rev 19584)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,14 +20,13 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.impl;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;
-
+import java.util.concurrent.ConcurrentHashMap;
import javax.naming.Context;
import javax.naming.InvalidNameException;
import javax.naming.Name;
@@ -40,18 +39,18 @@
import javax.naming.event.NamingListener;
import javax.naming.spi.ObjectFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.SessionFactory;
-import org.hibernate.util.FastHashMap;
import org.hibernate.util.NamingHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * Resolves <tt>SessionFactory</tt> JNDI lookups and deserialization
+ * Resolves {@link SessionFactory} instances during <tt>JNDI<tt> look-ups as well as during deserialization
*/
public class SessionFactoryObjectFactory implements ObjectFactory {
+ @SuppressWarnings({ "UnusedDeclaration" })
private static final SessionFactoryObjectFactory INSTANCE; //to stop the class from being unloaded
private static final Logger log;
@@ -62,8 +61,8 @@
log.debug("initializing class SessionFactoryObjectFactory");
}
- private static final FastHashMap INSTANCES = new FastHashMap();
- private static final FastHashMap NAMED_INSTANCES = new FastHashMap();
+ private static final ConcurrentHashMap<String, SessionFactory> INSTANCES = new ConcurrentHashMap<String, SessionFactory>();
+ private static final ConcurrentHashMap<String, SessionFactory> NAMED_INSTANCES = new ConcurrentHashMap<String, SessionFactory>();
private static final NamingListener LISTENER = new NamespaceChangeListener() {
public void objectAdded(NamingEvent evt) {
@@ -84,6 +83,7 @@
NAMED_INSTANCES.put( evt.getNewBinding().getName(), NAMED_INSTANCES.remove(name) );
}
public void namingExceptionThrown(NamingExceptionEvent evt) {
+ //noinspection ThrowableResultOfMethodCallIgnored
log.warn( "Naming exception occurred accessing factory: " + evt.getException() );
}
};
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java 2010-05-21 17:57:21 UTC (rev 19583)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/EntityModeToTuplizerMapping.java 2010-05-21 19:38:04 UTC (rev 19584)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,17 +20,16 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tuple;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
-import org.hibernate.util.FastHashMap;
/**
* Centralizes handling of {@link EntityMode} to {@link Tuplizer} mappings.
@@ -38,14 +37,13 @@
* @author Steve Ebersole
*/
public abstract class EntityModeToTuplizerMapping implements Serializable {
+ private final Map<EntityMode,Tuplizer> tuplizers;
- // map of EntityMode -> Tuplizer
- private final Map tuplizers;
-
public EntityModeToTuplizerMapping() {
- tuplizers = new FastHashMap();
+ tuplizers = new ConcurrentHashMap<EntityMode,Tuplizer>();
}
+ @SuppressWarnings({ "unchecked", "UnusedDeclaration" })
public EntityModeToTuplizerMapping(Map tuplizers) {
this.tuplizers = tuplizers;
}
@@ -70,12 +68,9 @@
* @return The guessed entity mode.
*/
public EntityMode guessEntityMode(Object object) {
- Iterator itr = tuplizers.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry entry = ( Map.Entry ) itr.next();
- Tuplizer tuplizer = ( Tuplizer ) entry.getValue();
- if ( tuplizer.isInstance( object ) ) {
- return ( EntityMode ) entry.getKey();
+ for ( Map.Entry<EntityMode, Tuplizer> entityModeTuplizerEntry : tuplizers.entrySet() ) {
+ if ( entityModeTuplizerEntry.getValue().isInstance( object ) ) {
+ return entityModeTuplizerEntry.getKey();
}
}
return null;
@@ -89,7 +84,7 @@
* @return The tuplizer, or null if not found.
*/
public Tuplizer getTuplizerOrNull(EntityMode entityMode) {
- return ( Tuplizer ) tuplizers.get( entityMode );
+ return tuplizers.get( entityMode );
}
/**
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java 2010-05-21 17:57:21 UTC (rev 19583)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java 2010-05-21 19:38:04 UTC (rev 19584)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,15 +20,14 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tuple.component;
import java.util.Map;
import java.lang.reflect.Constructor;
import java.io.Serializable;
+import java.util.concurrent.ConcurrentHashMap;
-import org.hibernate.util.FastHashMap;
import org.hibernate.util.ReflectHelper;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
@@ -40,10 +39,9 @@
* @author Steve Ebersole
*/
public class ComponentTuplizerFactory implements Serializable {
-
private static final Class[] COMPONENT_TUP_CTOR_SIG = new Class[] { Component.class };
- private Map defaultImplClassByMode = buildBaseMapping();
+ private Map<EntityMode,Class<? extends ComponentTuplizer>> defaultImplClassByMode = buildBaseMapping();
/**
* Method allowing registration of the tuplizer class to use as default for a particular entity-mode.
@@ -51,7 +49,8 @@
* @param entityMode The entity-mode for which to register the tuplizer class
* @param tuplizerClass The class to use as the default tuplizer for the given entity-mode.
*/
- public void registerDefaultTuplizerClass(EntityMode entityMode, Class tuplizerClass) {
+ @SuppressWarnings({ "UnusedDeclaration" })
+ public void registerDefaultTuplizerClass(EntityMode entityMode, Class<? extends ComponentTuplizer> tuplizerClass) {
assert isComponentTuplizerImplementor( tuplizerClass )
: "Specified tuplizer class [" + tuplizerClass.getName() + "] does not implement " + ComponentTuplizer.class.getName();
assert hasProperConstructor( tuplizerClass )
@@ -71,9 +70,10 @@
* @throws HibernateException If class name cannot be resolved to a class reference, or if the
* {@link Constructor#newInstance} call fails.
*/
+ @SuppressWarnings({ "unchecked" })
public ComponentTuplizer constructTuplizer(String tuplizerClassName, Component metadata) {
try {
- Class tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
+ Class<? extends ComponentTuplizer> tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
return constructTuplizer( tuplizerClass, metadata );
}
catch ( ClassNotFoundException e ) {
@@ -91,11 +91,11 @@
*
* @throws HibernateException if the {@link java.lang.reflect.Constructor#newInstance} call fails.
*/
- public ComponentTuplizer constructTuplizer(Class tuplizerClass, Component metadata) {
- Constructor ctor = getProperConstructor( tuplizerClass );
- assert ctor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
+ public ComponentTuplizer constructTuplizer(Class<? extends ComponentTuplizer> tuplizerClass, Component metadata) {
+ Constructor<? extends ComponentTuplizer> constructor = getProperConstructor( tuplizerClass );
+ assert constructor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
try {
- return ( ComponentTuplizer ) ctor.newInstance( new Object[] { metadata } );
+ return constructor.newInstance( metadata );
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to instantiate default tuplizer [" + tuplizerClass.getName() + "]", t );
@@ -114,7 +114,7 @@
* {@link #constructTuplizer} too.
*/
public ComponentTuplizer constructDefaultTuplizer(EntityMode entityMode, Component metadata) {
- Class tuplizerClass = ( Class ) defaultImplClassByMode.get( entityMode );
+ Class<? extends ComponentTuplizer> tuplizerClass = defaultImplClassByMode.get( entityMode );
if ( tuplizerClass == null ) {
throw new HibernateException( "could not determine default tuplizer class to use [" + entityMode + "]" );
}
@@ -126,32 +126,33 @@
return ReflectHelper.implementsInterface( tuplizerClass, ComponentTuplizer.class );
}
+ @SuppressWarnings({ "unchecked" })
private boolean hasProperConstructor(Class tuplizerClass) {
return getProperConstructor( tuplizerClass ) != null;
}
- private Constructor getProperConstructor(Class clazz) {
- Constructor ctor = null;
+ private Constructor<? extends ComponentTuplizer> getProperConstructor(Class<? extends ComponentTuplizer> clazz) {
+ Constructor<? extends ComponentTuplizer> constructor = null;
try {
- ctor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
- if ( ! ReflectHelper.isPublic( ctor ) ) {
+ constructor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
+ if ( ! ReflectHelper.isPublic( constructor ) ) {
try {
- // found a ctor, but it was not publicly accessible so try to request accessibility
- ctor.setAccessible( true );
+ // found a constructor, but it was not publicly accessible so try to request accessibility
+ constructor.setAccessible( true );
}
catch ( SecurityException e ) {
- ctor = null;
+ constructor = null;
}
}
}
catch ( NoSuchMethodException ignore ) {
}
- return ctor;
+ return constructor;
}
- private static Map buildBaseMapping() {
- Map map = new FastHashMap();
+ private static Map<EntityMode,Class<? extends ComponentTuplizer>> buildBaseMapping() {
+ Map<EntityMode,Class<? extends ComponentTuplizer>> map = new ConcurrentHashMap<EntityMode,Class<? extends ComponentTuplizer>>();
map.put( EntityMode.POJO, PojoComponentTuplizer.class );
map.put( EntityMode.DOM4J, Dom4jComponentTuplizer.class );
map.put( EntityMode.MAP, DynamicMapComponentTuplizer.class );
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java 2010-05-21 17:57:21 UTC (rev 19583)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizerFactory.java 2010-05-21 19:38:04 UTC (rev 19584)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,20 +20,18 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tuple.entity;
-import java.util.Map;
-import java.lang.reflect.Constructor;
import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
-
-import org.hibernate.util.FastHashMap;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.mapping.PersistentClass;
+import org.hibernate.util.ReflectHelper;
/**
* A registry allowing users to define the default {@link EntityTuplizer} class to use per {@link EntityMode}.
@@ -41,10 +39,9 @@
* @author Steve Ebersole
*/
public class EntityTuplizerFactory implements Serializable {
-
public static final Class[] ENTITY_TUP_CTOR_SIG = new Class[] { EntityMetamodel.class, PersistentClass.class };
- private Map defaultImplClassByMode = buildBaseMapping();
+ private Map<EntityMode,Class<? extends EntityTuplizer>> defaultImplClassByMode = buildBaseMapping();
/**
* Method allowing registration of the tuplizer class to use as default for a particular entity-mode.
@@ -52,7 +49,7 @@
* @param entityMode The entity-mode for which to register the tuplizer class
* @param tuplizerClass The class to use as the default tuplizer for the given entity-mode.
*/
- public void registerDefaultTuplizerClass(EntityMode entityMode, Class tuplizerClass) {
+ public void registerDefaultTuplizerClass(EntityMode entityMode, Class<? extends EntityTuplizer> tuplizerClass) {
assert isEntityTuplizerImplementor( tuplizerClass )
: "Specified tuplizer class [" + tuplizerClass.getName() + "] does not implement " + EntityTuplizer.class.getName();
assert hasProperConstructor( tuplizerClass )
@@ -73,12 +70,13 @@
* @throws HibernateException If class name cannot be resolved to a class reference, or if the
* {@link Constructor#newInstance} call fails.
*/
+ @SuppressWarnings({ "unchecked" })
public EntityTuplizer constructTuplizer(
String tuplizerClassName,
EntityMetamodel metamodel,
PersistentClass persistentClass) {
try {
- Class tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
+ Class<? extends EntityTuplizer> tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
return constructTuplizer( tuplizerClass, metamodel, persistentClass );
}
catch ( ClassNotFoundException e ) {
@@ -98,13 +96,13 @@
* @throws HibernateException if the {@link Constructor#newInstance} call fails.
*/
public EntityTuplizer constructTuplizer(
- Class tuplizerClass,
+ Class<? extends EntityTuplizer> tuplizerClass,
EntityMetamodel metamodel,
PersistentClass persistentClass) {
- Constructor ctor = getProperConstructor( tuplizerClass );
- assert ctor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
+ Constructor<? extends EntityTuplizer> constructor = getProperConstructor( tuplizerClass );
+ assert constructor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
try {
- return ( EntityTuplizer ) ctor.newInstance( new Object[] { metamodel, persistentClass } );
+ return constructor.newInstance( metamodel, persistentClass );
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to instantiate default tuplizer [" + tuplizerClass.getName() + "]", t );
@@ -127,7 +125,7 @@
EntityMode entityMode,
EntityMetamodel metamodel,
PersistentClass persistentClass) {
- Class tuplizerClass = ( Class ) defaultImplClassByMode.get( entityMode );
+ Class<? extends EntityTuplizer> tuplizerClass = defaultImplClassByMode.get( entityMode );
if ( tuplizerClass == null ) {
throw new HibernateException( "could not determine default tuplizer class to use [" + entityMode + "]" );
}
@@ -139,33 +137,33 @@
return ReflectHelper.implementsInterface( tuplizerClass, EntityTuplizer.class );
}
- private boolean hasProperConstructor(Class tuplizerClass) {
+ private boolean hasProperConstructor(Class<? extends EntityTuplizer> tuplizerClass) {
return getProperConstructor( tuplizerClass ) != null
&& ! ReflectHelper.isAbstractClass( tuplizerClass );
}
- private Constructor getProperConstructor(Class clazz) {
- Constructor ctor = null;
+ private Constructor<? extends EntityTuplizer> getProperConstructor(Class<? extends EntityTuplizer> clazz) {
+ Constructor<? extends EntityTuplizer> constructor = null;
try {
- ctor = clazz.getDeclaredConstructor( ENTITY_TUP_CTOR_SIG );
- if ( ! ReflectHelper.isPublic( ctor ) ) {
+ constructor = clazz.getDeclaredConstructor( ENTITY_TUP_CTOR_SIG );
+ if ( ! ReflectHelper.isPublic( constructor ) ) {
try {
- // found a ctor, but it was not publicly accessible so try to request accessibility
- ctor.setAccessible( true );
+ // found a constructor, but it was not publicly accessible so try to request accessibility
+ constructor.setAccessible( true );
}
catch ( SecurityException e ) {
- ctor = null;
+ constructor = null;
}
}
}
catch ( NoSuchMethodException ignore ) {
}
- return ctor;
+ return constructor;
}
- private static Map buildBaseMapping() {
- Map map = new FastHashMap();
+ private static Map<EntityMode,Class<? extends EntityTuplizer>> buildBaseMapping() {
+ Map<EntityMode,Class<? extends EntityTuplizer>> map = new ConcurrentHashMap<EntityMode,Class<? extends EntityTuplizer>>();
map.put( EntityMode.POJO, PojoEntityTuplizer.class );
map.put( EntityMode.DOM4J, Dom4jEntityTuplizer.class );
map.put( EntityMode.MAP, DynamicMapEntityTuplizer.class );
Deleted: core/trunk/core/src/main/java/org/hibernate/util/FastHashMap.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/FastHashMap.java 2010-05-21 17:57:21 UTC (rev 19583)
+++ core/trunk/core/src/main/java/org/hibernate/util/FastHashMap.java 2010-05-21 19:38:04 UTC (rev 19584)
@@ -1,335 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- *
- */
-
-// This class was taken from Apache commons-collections -
-// I made it final + removed the "slow" mode...
-
-package org.hibernate.util;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * <p>A customized implementation of <code>java.util.HashMap</code> designed
- * to operate in a multithreaded environment where the large majority of
- * method calls are read-only, instead of structural changes.
- * Read calls are non-synchronized and write calls perform the
- * following steps:</p>
- * <ul>
- * <li>Clone the existing collection
- * <li>Perform the modification on the clone
- * <li>Replace the existing collection with the (modified) clone
- * </ul>
- * <p><strong>NOTE</strong>: If you are creating and accessing a
- * <code>HashMap</code> only within a single thread, you should use
- * <code>java.util.HashMap</code> directly (with no synchronization), for
- * maximum performance.</p>
- *
- */
-
-public final class FastHashMap implements Map, Serializable {
-
- // ----------------------------------------------------------- Constructors
-
- /**
- * Construct a an empty map.
- */
- public FastHashMap() {
-
- super();
- this.map = new HashMap();
-
- }
-
- /**
- * Construct an empty map with the specified capacity.
- *
- * @param capacity The initial capacity of the empty map
- */
- public FastHashMap(int capacity) {
-
- super();
- this.map = new HashMap(capacity);
-
- }
-
- /**
- * Construct an empty map with the specified capacity and load factor.
- *
- * @param capacity The initial capacity of the empty map
- * @param factor The load factor of the new map
- */
- public FastHashMap(int capacity, float factor) {
-
- super();
- this.map = new HashMap(capacity, factor);
-
- }
-
- /**
- * Construct a new map with the same mappings as the specified map.
- *
- * @param map The map whose mappings are to be copied
- */
- public FastHashMap(Map map) {
-
- super();
- this.map = new HashMap(map);
-
- }
-
- // ----------------------------------------------------- Instance Variables
-
- /**
- * The underlying map we are managing.
- */
- private HashMap map = null;
-
- // --------------------------------------------------------- Public Methods
-
- /**
- * Remove all mappings from this map.
- */
- public void clear() {
-
- synchronized (this) {
- HashMap temp = (HashMap) map.clone();
- temp.clear();
- map = temp;
- }
-
- }
-
- /**
- * Return a shallow copy of this <code>FastHashMap</code> instance.
- * The keys and values themselves are not copied.
- */
- public Object clone() {
-
- return new FastHashMap(map);
-
- }
-
- /**
- * Return <code>true</code> if this map contains a mapping for the
- * specified key.
- *
- * @param key Key to be searched for
- */
- public boolean containsKey(Object key) {
-
- return map.containsKey(key);
-
- }
-
- /**
- * Return <code>true</code> if this map contains one or more keys mapping
- * to the specified value.
- *
- * @param value Value to be searched for
- */
- public boolean containsValue(Object value) {
-
- return map.containsValue(value);
-
- }
-
- /**
- * Return a collection view of the mappings contained in this map. Each
- * element in the returned collection is a <code>Map.Entry</code>.
- */
- public Set entrySet() {
-
- return map.entrySet();
-
- }
-
- /**
- * Compare the specified object with this list for equality. This
- * implementation uses exactly the code that is used to define the
- * list equals function in the documentation for the
- * <code>Map.equals</code> method.
- *
- * @param o Object to be compared to this list
- */
- public boolean equals(Object o) {
-
- // Simple tests that require no synchronization
- if (o == this)
- return true;
- else if ( !(o instanceof Map) )
- return false;
- Map mo = (Map) o;
-
- // Compare the two maps for equality
-
- if ( mo.size() != map.size() )
- return false;
- java.util.Iterator i = map.entrySet().iterator();
- while ( i.hasNext() ) {
- Map.Entry e = (Map.Entry) i.next();
- Object key = e.getKey();
- Object value = e.getValue();
- if (value == null) {
- if ( !( mo.get(key) == null && mo.containsKey(key) ) )
- return false;
- }
- else {
- if ( !value.equals( mo.get(key) ) )
- return false;
- }
- }
- return true;
-
- }
-
- /**
- * Return the value to which this map maps the specified key. Returns
- * <code>null</code> if the map contains no mapping for this key, or if
- * there is a mapping with a value of <code>null</code>. Use the
- * <code>containsKey()</code> method to disambiguate these cases.
- *
- * @param key Key whose value is to be returned
- */
- public Object get(Object key) {
-
- return map.get(key);
-
- }
-
- /**
- * Return the hash code value for this map. This implementation uses
- * exactly the code that is used to define the list hash function in the
- * documentation for the <code>Map.hashCode</code> method.
- */
- public int hashCode() {
-
- int h = 0;
- java.util.Iterator i = map.entrySet().iterator();
- while ( i.hasNext() )
- h += i.next().hashCode();
- return h;
-
- }
-
- /**
- * Return <code>true</code> if this map contains no mappings.
- */
- public boolean isEmpty() {
-
- return map.isEmpty();
-
- }
-
- /**
- * Return a set view of the keys contained in this map.
- */
- public Set keySet() {
-
- return map.keySet();
-
- }
-
- /**
- * Associate the specified value with the specified key in this map.
- * If the map previously contained a mapping for this key, the old
- * value is replaced and returned.
- *
- * @param key The key with which the value is to be associated
- * @param value The value to be associated with this key
- */
- public Object put(Object key, Object value) {
-
- synchronized (this) {
- HashMap temp = (HashMap) map.clone();
- Object result = temp.put(key, value);
- map = temp;
- return (result);
- }
-
- }
-
- /**
- * Copy all of the mappings from the specified map to this one, replacing
- * any mappings with the same keys.
- *
- * @param in Map whose mappings are to be copied
- */
- public void putAll(Map in) {
-
- synchronized (this) {
- HashMap temp = (HashMap) map.clone();
- temp.putAll(in);
- map = temp;
- }
-
- }
-
- /**
- * Remove any mapping for this key, and return any previously
- * mapped value.
- *
- * @param key Key whose mapping is to be removed
- */
- public Object remove(Object key) {
-
- synchronized (this) {
- HashMap temp = (HashMap) map.clone();
- Object result = temp.remove(key);
- map = temp;
- return (result);
- }
-
- }
-
- /**
- * Return the number of key-value mappings in this map.
- */
- public int size() {
-
- return map.size();
-
- }
-
- /**
- * Return a collection view of the values contained in this map.
- */
- public Collection values() {
-
- return map.values();
-
- }
-
- public String toString() { return map.toString(); }
-
-}
-
-
-
-
-
14 years, 7 months
Hibernate SVN: r19583 - in core/trunk: annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-21 13:57:21 -0400 (Fri, 21 May 2010)
New Revision: 19583
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/IntermediateMappedSuperclassTest.java
core/trunk/parent/pom.xml
Log:
HHH-5200 - Prepare to use H2 as the default testing datbase
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java 2010-05-21 15:48:20 UTC (rev 19582)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java 2010-05-21 17:57:21 UTC (rev 19583)
@@ -22,10 +22,21 @@
try {
s.persist( ch );
s.flush();
+ if ( getDialect().supportsColumnCheck() ) {
+ fail( "expecting SQL constraint violation" );
+ }
}
catch ( ConstraintViolationException e ) {
fail("invalid object should not be validated");
}
+ catch ( org.hibernate.exception.ConstraintViolationException e ) {
+ if ( getDialect().supportsColumnCheck() ) {
+ // expected
+ }
+ else {
+ fail( "Unexpected SQL constraint violation [" + e.getConstraintName() + "] : " + e.getSQLException() );
+ }
+ }
tx.rollback();
s.close();
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/IntermediateMappedSuperclassTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/IntermediateMappedSuperclassTest.java 2010-05-21 15:48:20 UTC (rev 19582)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/mappedsuperclass/intermediate/IntermediateMappedSuperclassTest.java 2010-05-21 17:57:21 UTC (rev 19583)
@@ -40,7 +40,7 @@
}
public void testGetOnIntermediateMappedSuperclass() {
- final BigDecimal withdrawalLimit = new BigDecimal( 1000 );
+ final BigDecimal withdrawalLimit = new BigDecimal( 1000.00 ).setScale( 2 );
Session session = openSession();
session.beginTransaction();
SavingsAccount savingsAccount = new SavingsAccount( "123", withdrawalLimit );
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2010-05-21 15:48:20 UTC (rev 19582)
+++ core/trunk/parent/pom.xml 2010-05-21 17:57:21 UTC (rev 19583)
@@ -568,7 +568,7 @@
<profile>
<id>hsqldb</id>
<activation>
- <activeByDefault>true</activeByDefault>
+ <activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
@@ -591,7 +591,7 @@
<profile>
<id>h2</id>
<activation>
- <activeByDefault>false</activeByDefault>
+ <activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
14 years, 7 months
Hibernate SVN: r19582 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validator/engine and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-21 11:48:20 -0400 (Fri, 21 May 2010)
New Revision: 19582
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertFalseDefinition.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertTrueDefinition.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/CascadeDefinition.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java
Log:
HV-274 added support for cascading
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertFalseDefinition.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertFalseDefinition.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertFalseDefinition.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -0,0 +1,47 @@
+// $Id: NotNullDefinition.java 19559 2010-05-19 16:20:53Z hardy.ferentschik $
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.cfg;
+
+import java.lang.annotation.ElementType;
+import javax.validation.Payload;
+import javax.validation.constraints.AssertFalse;
+import javax.validation.constraints.AssertTrue;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class AssertFalseDefinition extends ConstraintDefinition<AssertFalse> {
+ public AssertFalseDefinition(Class<?> beanType, String property, ElementType elementType, ConstraintMapping mapping) {
+ super( beanType, AssertFalse.class, property, elementType, mapping );
+ }
+
+ public AssertFalseDefinition message(String message) {
+ addParameter( "message", message );
+ return this;
+ }
+
+ public AssertFalseDefinition groups(Class<?>... groups) {
+ addParameter( "groups", groups );
+ return this;
+ }
+
+ public AssertFalseDefinition payload(Class<? extends Payload>... payload) {
+ addParameter( "payload", payload );
+ return this;
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertTrueDefinition.java (from rev 19559, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/NotNullDefinition.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertTrueDefinition.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/AssertTrueDefinition.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -0,0 +1,47 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.cfg;
+
+import java.lang.annotation.ElementType;
+import javax.validation.Payload;
+import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class AssertTrueDefinition extends ConstraintDefinition<AssertTrue> {
+ public AssertTrueDefinition(Class<?> beanType, String property, ElementType elementType, ConstraintMapping mapping) {
+ super( beanType, AssertTrue.class, property, elementType, mapping );
+ }
+
+ public AssertTrueDefinition message(String message) {
+ addParameter( "message", message );
+ return this;
+ }
+
+ public AssertTrueDefinition groups(Class<?>... groups) {
+ addParameter( "groups", groups );
+ return this;
+ }
+
+ public AssertTrueDefinition payload(Class<? extends Payload>... payload) {
+ addParameter( "payload", payload );
+ return this;
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/CascadeDefinition.java (from rev 19573, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/CascadeDefinition.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/CascadeDefinition.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -0,0 +1,78 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.cfg;
+
+import java.lang.annotation.ElementType;
+import javax.validation.ValidationException;
+
+import org.hibernate.validator.util.ReflectionHelper;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CascadeDefinition {
+ private final Class<?> beanType;
+ private final ElementType elementType;
+ private final String property;
+
+ public CascadeDefinition(Class<?> beanType, String property, ElementType elementType) {
+ if ( beanType == null ) {
+ throw new ValidationException( "Null is not a valid bean type" );
+ }
+
+ if ( ElementType.FIELD.equals( elementType ) || ElementType.METHOD.equals( elementType ) ) {
+ if ( property == null || property.length() == 0 ) {
+ throw new ValidationException( "A valid property name has to be specified" );
+ }
+
+ if ( !ReflectionHelper.propertyExists( beanType, property, elementType ) ) {
+ throw new ValidationException(
+ "The class " + beanType + " does not have a property '"
+ + property + "' with access " + elementType
+ );
+ }
+ }
+
+ this.beanType = beanType;
+ this.property = property;
+ this.elementType = elementType;
+ }
+
+ public ElementType getElementType() {
+ return elementType;
+ }
+
+ public Class<?> getBeanType() {
+ return beanType;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "CascadeDefinition" );
+ sb.append( "{beanType=" ).append( beanType );
+ sb.append( ", elementType=" ).append( elementType );
+ sb.append( ", property='" ).append( property ).append( '\'' );
+ sb.append( '}' );
+ return sb.toString();
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/CascadeDefinition.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -99,7 +99,8 @@
}
public ConstraintsForType valid(String property, ElementType type) {
- return null;
+ mapping.addCascadeConfig( new CascadeDefinition( beanType, property, type ) );
+ return new ConstraintsForType( beanType, mapping );
}
public Class<A> getConstraintType() {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -18,20 +18,25 @@
package org.hibernate.validator.cfg;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
-import org.hibernate.validator.util.ReflectionHelper;
-
/**
* @author Hardy Ferentschik
*/
public class ConstraintMapping {
- private final Map<Class<?>, List<ConstraintDefinition<?>>> configData;
+ private final Map<Class<?>, List<ConstraintDefinition<?>>> constraintConfig;
+ private final Map<Class<?>, List<CascadeDefinition>> cascadeConfig;
+ private final Set<Class<?>> configuredClasses;
public ConstraintMapping() {
- configData = new HashMap<Class<?>, List<ConstraintDefinition<?>>>();
+ constraintConfig = new HashMap<Class<?>, List<ConstraintDefinition<?>>>();
+ cascadeConfig = new HashMap<Class<?>, List<CascadeDefinition>>();
+ configuredClasses = new HashSet<Class<?>>();
}
public ConstraintsForType type(Class<?> beanClass) {
@@ -40,26 +45,48 @@
protected void addConstraintConfig(ConstraintDefinition<?> definition) {
Class<?> beanClass = definition.getBeanType();
-
- if ( configData.containsKey( beanClass ) ) {
- configData.get( beanClass ).add( definition );
+ configuredClasses.add( beanClass );
+ if ( constraintConfig.containsKey( beanClass ) ) {
+ constraintConfig.get( beanClass ).add( definition );
}
else {
List<ConstraintDefinition<?>> definitionList = new ArrayList<ConstraintDefinition<?>>();
definitionList.add( definition );
- configData.put( beanClass, definitionList );
+ constraintConfig.put( beanClass, definitionList );
}
}
- public Map<Class<?>, List<ConstraintDefinition<?>>> getConfigData() {
- return configData;
+ protected void addCascadeConfig(CascadeDefinition cascade) {
+ Class<?> beanClass = cascade.getBeanType();
+ configuredClasses.add( beanClass );
+ if ( cascadeConfig.containsKey( beanClass ) ) {
+ cascadeConfig.get( beanClass ).add( cascade );
+ }
+ else {
+ List<CascadeDefinition> cascadeList = new ArrayList<CascadeDefinition>();
+ cascadeList.add( cascade );
+ cascadeConfig.put( beanClass, cascadeList );
+ }
}
+ public Map<Class<?>, List<ConstraintDefinition<?>>> getConstraintConfig() {
+ return constraintConfig;
+ }
+
+ public Map<Class<?>, List<CascadeDefinition>> getCascadeConfig() {
+ return cascadeConfig;
+ }
+
+ public Collection<Class<?>> getConfiguredClasses() {
+ return configuredClasses;
+ }
+
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "ConstraintMapping" );
- sb.append( "{configData=" ).append( configData );
+ sb.append( "{cascadeConfig=" ).append( cascadeConfig );
+ sb.append( ", constraintConfig=" ).append( constraintConfig );
sb.append( '}' );
return sb.toString();
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -29,13 +29,15 @@
* @author Hardy Ferentschik
*/
public class ConstraintsForType {
+ private static final String EMPTY_PROPERTY = "";
+
private final ConstraintMapping mapping;
private final Class<?> beanClass;
private String property;
private ElementType elementType;
public ConstraintsForType(Class<?> beanClass, ConstraintMapping mapping) {
- this( beanClass, "", TYPE, mapping );
+ this( beanClass, EMPTY_PROPERTY, TYPE, mapping );
}
public ConstraintsForType(Class<?> beanClass, String property, ElementType type, ConstraintMapping mapping) {
@@ -62,8 +64,13 @@
}
public ConstraintsForType valid(String property, ElementType type) {
- return null;
+ mapping.addCascadeConfig(new CascadeDefinition( beanClass, property, type));
+ return this;
}
+
+ public ConstraintsForType type(Class<?> type) {
+ return new ConstraintsForType( type, mapping );
+ }
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -34,6 +34,7 @@
import javax.validation.ValidatorFactory;
import javax.validation.spi.ConfigurationState;
+import org.hibernate.validator.cfg.CascadeDefinition;
import org.hibernate.validator.cfg.ConstraintDefinition;
import org.hibernate.validator.cfg.ConstraintMapping;
import org.hibernate.validator.metadata.AnnotationIgnores;
@@ -123,10 +124,8 @@
*
* @param mapping The constraint configuration created via the programmatic API.
*/
- private <A extends Annotation, T> void initProgrammaticConfiguration(ConstraintMapping mapping) {
- Map<Class<?>, List<ConstraintDefinition<?>>> configData = mapping.getConfigData();
-
- for ( Class<?> clazz : mapping.getConfigData().keySet() ) {
+ private <T> void initProgrammaticConfiguration(ConstraintMapping mapping) {
+ for ( Class<?> clazz : mapping.getConfiguredClasses() ) {
@SuppressWarnings("unchecked")
Class<T> beanClass = ( Class<T> ) clazz;
@@ -139,19 +138,29 @@
for ( Class<?> classInHierarchy : classes ) {
// if the programmatic config contains constraints for the class in the hierarchy create a meta constraint
- if ( mapping.getConfigData().keySet().contains( classInHierarchy ) ) {
+ if ( mapping.getConstraintConfig().keySet().contains( classInHierarchy ) ) {
addProgrammaticConfiguredConstraints(
- mapping.getConfigData().get( classInHierarchy ), beanClass, classInHierarchy, constraints
+ mapping.getConstraintConfig().get( classInHierarchy ),
+ beanClass,
+ classInHierarchy,
+ constraints
);
}
+
+ if ( mapping.getCascadeConfig().keySet().contains( classInHierarchy ) ) {
+ addProgrammaticConfiguredCascade(
+ mapping.getCascadeConfig().get( classInHierarchy ), cascadedMembers
+ );
+ }
}
+ // TODO handle redefinition of default group
BeanMetaDataImpl<T> metaData = new BeanMetaDataImpl<T>(
beanClass,
constraintHelper,
new ArrayList<Class<?>>(),
constraints,
- new ArrayList<Member>(),
+ cascadedMembers,
new AnnotationIgnores(),
beanMetaDataCache
);
@@ -224,7 +233,7 @@
Class<T> rootClass, Class<?> hierarchyClass,
Map<Class<?>, List<MetaConstraint<T, ?>>> constraints) {
for ( ConstraintDefinition<?> config : definitions ) {
- A annotation = (A) createAnnotationProxy( config );
+ A annotation = ( A ) createAnnotationProxy( config );
ConstraintOrigin definedIn = definedIn( rootClass, hierarchyClass );
ConstraintDescriptorImpl<A> constraintDescriptor = new ConstraintDescriptorImpl<A>(
annotation, constraintHelper, config.getElementType(), definedIn
@@ -261,6 +270,19 @@
}
}
+ private void addProgrammaticConfiguredCascade(List<CascadeDefinition> cascades,
+ List<Member> cascadedMembers) {
+ if ( cascades == null ) {
+ return;
+ }
+ for ( CascadeDefinition cascade : cascades ) {
+ Member m = ReflectionHelper.getMember(
+ cascade.getBeanType(), cascade.getProperty(), cascade.getElementType()
+ );
+ cascadedMembers.add( m );
+ }
+ }
+
/**
* @param rootClass The root class. That is the class for which we currently create a {@code BeanMetaData}
* @param hierarchyClass The class on which the current constraint is defined on
@@ -279,7 +301,7 @@
@SuppressWarnings("unchecked")
private <A extends Annotation> Annotation createAnnotationProxy(ConstraintDefinition<?> config) {
- Class<A> constraintType = (Class<A>) config.getConstraintType();
+ Class<A> constraintType = ( Class<A> ) config.getConstraintType();
AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>( constraintType );
for ( Map.Entry<String, Object> parameter : config.getParameters().entrySet() ) {
annotationDescriptor.setValue( parameter.getKey(), parameter.getValue() );
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -112,8 +112,8 @@
public BeanMetaDataImpl(Class<T> beanClass,
ConstraintHelper constraintHelper,
List<Class<?>> defaultGroupSequence,
- Map<Class<?>, List<MetaConstraint<T, ?>>> xmlConfiguredConstraints,
- List<Member> xmlConfiguredMember,
+ Map<Class<?>, List<MetaConstraint<T, ?>>> constraints,
+ List<Member> cascadedMembers,
AnnotationIgnores annotationIgnores,
BeanMetaDataCache beanMetaDataCache) {
this.beanClass = beanClass;
@@ -122,13 +122,13 @@
if ( !defaultGroupSequence.isEmpty() ) {
setDefaultGroupSequence( defaultGroupSequence );
}
- for ( Map.Entry<Class<?>, List<MetaConstraint<T, ?>>> entry : xmlConfiguredConstraints.entrySet() ) {
+ for ( Map.Entry<Class<?>, List<MetaConstraint<T, ?>>> entry : constraints.entrySet() ) {
Class<?> clazz = entry.getKey();
for ( MetaConstraint<T, ?> constraint : entry.getValue() ) {
addMetaConstraint( clazz, constraint );
}
}
- for ( Member member : xmlConfiguredMember ) {
+ for ( Member member : cascadedMembers ) {
addCascadedMember( member );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -30,6 +30,7 @@
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.HibernateValidatorConfiguration;
+import org.hibernate.validator.cfg.AssertTrueDefinition;
import org.hibernate.validator.cfg.ConstraintMapping;
import org.hibernate.validator.cfg.FutureDefinition;
import org.hibernate.validator.cfg.MinDefinition;
@@ -59,8 +60,8 @@
.property( "numberOfRunners", FIELD )
.constraint( MinDefinition.class ).value( 1 );
- assertTrue( mapping.getConfigData().containsKey( Marathon.class ) );
- assertTrue( mapping.getConfigData().get( Marathon.class ).size() == 2 );
+ assertTrue( mapping.getConstraintConfig().containsKey( Marathon.class ) );
+ assertTrue( mapping.getConstraintConfig().get( Marathon.class ).size() == 2 );
}
@Test
@@ -121,6 +122,34 @@
}
@Test
+ public void testValid() {
+ HibernateValidatorConfiguration config = TestUtil.getConfiguration( HibernateValidator.class );
+
+ ConstraintMapping mapping = new ConstraintMapping();
+ mapping.type( Marathon.class )
+ .valid( "runners", METHOD )
+ .type( Runner.class )
+ .property( "paidEntryFee", FIELD )
+ .constraint( AssertTrueDefinition.class );
+
+ config.addMapping( mapping );
+
+ ValidatorFactory factory = config.buildValidatorFactory();
+ Validator validator = factory.getValidator();
+
+ Marathon marathon = new Marathon();
+ marathon.setName( "New York Marathon" );
+
+ Set<ConstraintViolation<Marathon>> violations = validator.validate( marathon );
+ assertNumberOfViolations( violations, 0 );
+
+ marathon.addRunner( new Runner() );
+ violations = validator.validate( marathon );
+ assertNumberOfViolations( violations, 1 );
+ assertConstraintViolation( violations.iterator().next(), "must be true" );
+ }
+
+ @Test
public void testSingleConstraintWrongAccessType() {
ConstraintMapping mapping = new ConstraintMapping();
try {
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -17,7 +17,9 @@
*/
package org.hibernate.validator.test.cfg;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
/**
* @author Hardy Ferentschik
@@ -29,6 +31,12 @@
private Date tournamentDate;
+ private List<Runner> runners;
+
+ public Marathon() {
+ runners = new ArrayList<Runner>();
+ }
+
public String getName() {
return name;
}
@@ -44,6 +52,14 @@
public void setTournamentDate(Date tournamentDate) {
this.tournamentDate = tournamentDate;
}
+
+ public List<Runner> getRunners() {
+ return runners;
+ }
+
+ public void addRunner(Runner runner) {
+ runners.add( runner );
+ }
}
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -0,0 +1,46 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.test.cfg;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Runner {
+ private String name;
+
+ private boolean paidEntryFee;
+
+ public boolean isPaidEntryFee() {
+ return paidEntryFee;
+ }
+
+ public void setPaidEntryFee(boolean paidEntryFee) {
+ this.paidEntryFee = paidEntryFee;
+ }
+
+ public String getName() {
+
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
+
+
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -57,8 +57,7 @@
*/
@Test
public void testEmailAndRangeMessageEnglishLocale() {
- Locale.setDefault( Locale.ENGLISH );
- Configuration<?> config = TestUtil.getConfiguration();
+ Configuration<?> config = TestUtil.getConfiguration( Locale.ENGLISH );
config.messageInterpolator( new ResourceBundleMessageInterpolator() );
Validator validator = config.buildValidatorFactory().getValidator();
User user = new User();
@@ -76,8 +75,7 @@
*/
@Test
public void testEmailAndRangeMessageGermanLocale() {
- Locale.setDefault( Locale.GERMAN );
- Configuration<?> config = TestUtil.getConfiguration();
+ Configuration<?> config = TestUtil.getConfiguration( Locale.GERMAN );
config.messageInterpolator( new ResourceBundleMessageInterpolator() );
Validator validator = config.buildValidatorFactory().getValidator();
User user = new User();
@@ -95,8 +93,7 @@
*/
@Test
public void testEmailAndRangeMessageFrenchLocale() {
- Locale.setDefault( Locale.FRENCH );
- Configuration<?> config = TestUtil.getConfiguration();
+ Configuration<?> config = TestUtil.getConfiguration( Locale.FRENCH );
config.messageInterpolator( new ResourceBundleMessageInterpolator() );
Validator validator = config.buildValidatorFactory().getValidator();
User user = new User();
@@ -115,9 +112,7 @@
*/
@Test
public void testThatExplicitlySetEnglishLocaleHasPrecedenceOverDefaultLocale() {
-
- Locale.setDefault( Locale.FRENCH );
- Configuration<?> config = TestUtil.getConfiguration();
+ Configuration<?> config = TestUtil.getConfiguration( Locale.FRENCH );
config.messageInterpolator( new LocalizedMessageInterpolator( Locale.ENGLISH ) );
Validator validator = config.buildValidatorFactory().getValidator();
User user = new User();
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java 2010-05-21 10:31:30 UTC (rev 19581)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java 2010-05-21 15:48:20 UTC (rev 19582)
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import javax.validation.Configuration;
import javax.validation.ConstraintViolation;
@@ -59,7 +60,7 @@
public static Validator getValidator() {
if ( hibernateValidator == null ) {
- Configuration configuration = getConfiguration();
+ Configuration configuration = getConfiguration( Locale.ENGLISH );
configuration.traversableResolver( new DummyTraversableResolver() );
hibernateValidator = configuration.buildValidatorFactory().getValidator();
}
@@ -67,10 +68,19 @@
}
public static Configuration<HibernateValidatorConfiguration> getConfiguration() {
- return Validation.byProvider( HibernateValidator.class ).configure();
+ return getConfiguration( HibernateValidator.class, Locale.ENGLISH );
}
+ public static Configuration<HibernateValidatorConfiguration> getConfiguration(Locale locale) {
+ return getConfiguration( HibernateValidator.class, locale );
+ }
+
public static <T extends Configuration<T>, U extends ValidationProvider<T>> T getConfiguration(Class<U> type) {
+ return getConfiguration( type, Locale.ENGLISH );
+ }
+
+ public static <T extends Configuration<T>, U extends ValidationProvider<T>> T getConfiguration(Class<U> type, Locale locale) {
+ Locale.setDefault( locale );
return Validation.byProvider( type ).configure();
}
@@ -83,43 +93,14 @@
*/
public static Validator getValidatorWithCustomConfiguration(String path) {
Thread.currentThread().setContextClassLoader( new CustomValidationXmlClassLoader( path ) );
-
- HibernateValidatorConfiguration configuration = Validation
- .byProvider( HibernateValidator.class )
- .configure();
- return configuration.buildValidatorFactory().getValidator();
+ return getConfiguration().buildValidatorFactory().getValidator();
}
- /**
- * @return A <code>Validator</code> instance which ignores <i>validation.xml</code>.
- */
- public static Validator getValidatorIgnoringValidationXml() {
- Thread.currentThread().setContextClassLoader( new IgnoringValidationXmlClassLoader() );
-
- HibernateValidatorConfiguration configuration = Validation
- .byProvider( HibernateValidator.class )
- .configure();
- return configuration.buildValidatorFactory().getValidator();
- }
-
- public static ConstraintDescriptor<?> getSingleConstraintDescriptorFor(Class<?> clazz, String property) {
- Set<ConstraintDescriptor<?>> constraintDescriptors = getConstraintDescriptorsFor( clazz, property );
- assertTrue(
- constraintDescriptors.size() == 1, "This method should only be used when there is a single constraint"
- );
- return constraintDescriptors.iterator().next();
- }
-
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String property) {
Validator validator = getValidator();
return validator.getConstraintsForClass( clazz ).getConstraintsForProperty( property );
}
- public static Set<ConstraintDescriptor<?>> getConstraintDescriptorsFor(Class<?> clazz, String property) {
- ElementDescriptor elementDescriptor = getPropertyDescriptor( clazz, property );
- return elementDescriptor.getConstraintDescriptors();
- }
-
public static <T> void assertCorrectConstraintViolationMessages(Set<ConstraintViolation<T>> violations, String... messages) {
List<String> actualMessages = new ArrayList<String>();
for ( ConstraintViolation<?> violation : violations ) {
14 years, 7 months
Hibernate SVN: r19581 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validator/util and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-21 06:31:30 -0400 (Fri, 21 May 2010)
New Revision: 19581
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
Log:
HV-274 made sure inherited constraints configured via api get picked up
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-21 06:56:48 UTC (rev 19580)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-21 10:31:30 UTC (rev 19581)
@@ -49,7 +49,7 @@
import org.hibernate.validator.xml.XmlMappingParser;
/**
- * Factory returning initialized <code>Validator</code> instances. This is Hibernate Validator's default
+ * Factory returning initialized {@code Validator} instances. This is Hibernate Validator's default
* implementation of the {@code ValidatorFactory} interface.
*
* @author Emmanuel Bernard
@@ -125,54 +125,38 @@
*/
private <A extends Annotation, T> void initProgrammaticConfiguration(ConstraintMapping mapping) {
Map<Class<?>, List<ConstraintDefinition<?>>> configData = mapping.getConfigData();
- for ( Map.Entry<Class<?>, List<ConstraintDefinition<?>>> entry : configData.entrySet() ) {
- Map<Class<?>, List<MetaConstraint<T, ?>>> constraints = new HashMap<Class<?>, List<MetaConstraint<T, ?>>>();
- for ( ConstraintDefinition<?> config : entry.getValue() ) {
- AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>(
- ( Class<A> ) config.getConstraintType()
- );
- for ( Map.Entry<String, Object> parameter : config.getParameters().entrySet() ) {
- annotationDescriptor.setValue( parameter.getKey(), parameter.getValue() );
- }
- A annotation;
- try {
- annotation = AnnotationFactory.create( annotationDescriptor );
- }
- catch ( RuntimeException e ) {
- throw new ValidationException(
- "Unable to create annotation for configured constraint: " + e.getMessage(), e
- );
- }
+ for ( Class<?> clazz : mapping.getConfigData().keySet() ) {
+ @SuppressWarnings("unchecked")
+ Class<T> beanClass = ( Class<T> ) clazz;
- ConstraintDescriptorImpl<A> constraintDescriptor = new ConstraintDescriptorImpl<A>(
- annotation, constraintHelper, config.getElementType(), ConstraintOrigin.DEFINED_LOCALLY
- );
+ // for each configured entity we have to check whether any of the interfaces or super classes is configured
+ // vua the programmatic api as well
+ List<Class<?>> classes = ReflectionHelper.computeClassHierarchy( beanClass );
- final Member member = ReflectionHelper.getMember(
- config.getBeanType(), config.getProperty(), config.getElementType()
- );
+ Map<Class<?>, List<MetaConstraint<T, ?>>> constraints = createEmptyConstraintMap();
+ List<Member> cascadedMembers = new ArrayList<Member>();
- MetaConstraint<T, ?> metaConstraint = new MetaConstraint(
- config.getBeanType(), member, constraintDescriptor
- );
- List<MetaConstraint<T, ?>> constraintList = new ArrayList<MetaConstraint<T, ?>>();
- constraintList.add( metaConstraint );
- constraints.put( config.getBeanType(), constraintList );
+ for ( Class<?> classInHierarchy : classes ) {
+ // if the programmatic config contains constraints for the class in the hierarchy create a meta constraint
+ if ( mapping.getConfigData().keySet().contains( classInHierarchy ) ) {
+ addProgrammaticConfiguredConstraints(
+ mapping.getConfigData().get( classInHierarchy ), beanClass, classInHierarchy, constraints
+ );
+ }
+ }
+ BeanMetaDataImpl<T> metaData = new BeanMetaDataImpl<T>(
+ beanClass,
+ constraintHelper,
+ new ArrayList<Class<?>>(),
+ constraints,
+ new ArrayList<Member>(),
+ new AnnotationIgnores(),
+ beanMetaDataCache
+ );
- BeanMetaDataImpl<T> metaData = new BeanMetaDataImpl<T>(
- ( Class<T> ) config.getBeanType(),
- constraintHelper,
- new ArrayList<Class<?>>(),
- constraints,
- new ArrayList<Member>(),
- new AnnotationIgnores(),
- beanMetaDataCache
- );
-
- beanMetaDataCache.addBeanMetaData( ( Class<T> ) config.getBeanType(), metaData );
- }
+ beanMetaDataCache.addBeanMetaData( beanClass, metaData );
}
}
@@ -188,7 +172,7 @@
Class<T> beanClass = ( Class<T> ) clazz;
List<Class<?>> classes = ReflectionHelper.computeClassHierarchy( beanClass );
- Map<Class<?>, List<MetaConstraint<T, ?>>> constraints = new HashMap<Class<?>, List<MetaConstraint<T, ?>>>();
+ Map<Class<?>, List<MetaConstraint<T, ?>>> constraints = createEmptyConstraintMap();
List<Member> cascadedMembers = new ArrayList<Member>();
// we need to collect all constraints which apply for a single class. Due to constraint inheritance
// some constraints might be configured in super classes or interfaces. The xml configuration does not
@@ -216,7 +200,9 @@
}
@SuppressWarnings("unchecked")
- private <T, A extends Annotation> void addXmlConfiguredConstraints(XmlMappingParser mappingParser, Class<T> rootClass, Class<?> hierarchyClass, Map<Class<?>, List<MetaConstraint<T, ?>>> constraints) {
+ private <T, A extends Annotation> void addXmlConfiguredConstraints(XmlMappingParser mappingParser,
+ Class<T> rootClass,
+ Class<?> hierarchyClass, Map<Class<?>, List<MetaConstraint<T, ?>>> constraints) {
for ( MetaConstraint<?, ? extends Annotation> constraint : mappingParser.getConstraintsForClass( hierarchyClass ) ) {
ConstraintOrigin definedIn = definedIn( rootClass, hierarchyClass );
ConstraintDescriptorImpl<A> descriptor = new ConstraintDescriptorImpl<A>(
@@ -228,21 +214,60 @@
MetaConstraint<T, A> newMetaConstraint = new MetaConstraint<T, A>(
rootClass, constraint.getMember(), descriptor
);
- List<MetaConstraint<T, ?>> constraintList = constraints.get( hierarchyClass );
- if ( constraintList == null ) {
- constraintList = new ArrayList<MetaConstraint<T, ?>>();
- constraints.put( hierarchyClass, constraintList );
- }
- constraintList.add( newMetaConstraint );
+
+ addConstraintToMap( hierarchyClass, newMetaConstraint, constraints );
}
}
- private void addXmlCascadedMember(XmlMappingParser mappingParser, Class<?> hierarchyClass, List<Member> cascadedMembers) {
+ @SuppressWarnings("unchecked")
+ private <T, A extends Annotation> void addProgrammaticConfiguredConstraints(List<ConstraintDefinition<?>> definitions,
+ Class<T> rootClass, Class<?> hierarchyClass,
+ Map<Class<?>, List<MetaConstraint<T, ?>>> constraints) {
+ for ( ConstraintDefinition<?> config : definitions ) {
+ A annotation = (A) createAnnotationProxy( config );
+ ConstraintOrigin definedIn = definedIn( rootClass, hierarchyClass );
+ ConstraintDescriptorImpl<A> constraintDescriptor = new ConstraintDescriptorImpl<A>(
+ annotation, constraintHelper, config.getElementType(), definedIn
+ );
+
+ Member member = ReflectionHelper.getMember(
+ config.getBeanType(), config.getProperty(), config.getElementType()
+ );
+
+ MetaConstraint<T, ?> metaConstraint = new MetaConstraint(
+ config.getBeanType(), member, constraintDescriptor
+ );
+ addConstraintToMap( hierarchyClass, metaConstraint, constraints );
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T, A extends Annotation> void addConstraintToMap(Class<?> hierarchyClass,
+ MetaConstraint<T, A> constraint,
+ Map<Class<?>, List<MetaConstraint<T, ?>>> constraints) {
+ List<MetaConstraint<T, ?>> constraintList = constraints.get( hierarchyClass );
+ if ( constraintList == null ) {
+ constraintList = new ArrayList<MetaConstraint<T, ?>>();
+ constraints.put( hierarchyClass, constraintList );
+ }
+ constraintList.add( constraint );
+ }
+
+ private void addXmlCascadedMember(XmlMappingParser mappingParser,
+ Class<?> hierarchyClass,
+ List<Member> cascadedMembers) {
for ( Member m : mappingParser.getCascadedMembersForClass( hierarchyClass ) ) {
cascadedMembers.add( m );
}
}
+ /**
+ * @param rootClass The root class. That is the class for which we currently create a {@code BeanMetaData}
+ * @param hierarchyClass The class on which the current constraint is defined on
+ *
+ * @return Returns {@code ConstraintOrigin.DEFINED_LOCALLY} if the constraint was defined on the root bean,
+ * {@code ConstraintOrigin.DEFINED_IN_HIERARCHY} otherwise.
+ */
private ConstraintOrigin definedIn(Class<?> rootClass, Class<?> hierarchyClass) {
if ( hierarchyClass.equals( rootClass ) ) {
return ConstraintOrigin.DEFINED_LOCALLY;
@@ -251,4 +276,28 @@
return ConstraintOrigin.DEFINED_IN_HIERARCHY;
}
}
+
+ @SuppressWarnings("unchecked")
+ private <A extends Annotation> Annotation createAnnotationProxy(ConstraintDefinition<?> config) {
+ Class<A> constraintType = (Class<A>) config.getConstraintType();
+ AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>( constraintType );
+ for ( Map.Entry<String, Object> parameter : config.getParameters().entrySet() ) {
+ annotationDescriptor.setValue( parameter.getKey(), parameter.getValue() );
+ }
+
+ A annotation;
+ try {
+ annotation = AnnotationFactory.create( annotationDescriptor );
+ }
+ catch ( RuntimeException e ) {
+ throw new ValidationException(
+ "Unable to create annotation for configured constraint: " + e.getMessage(), e
+ );
+ }
+ return annotation;
+ }
+
+ private <T> Map<Class<?>, List<MetaConstraint<T, ?>>> createEmptyConstraintMap() {
+ return new HashMap<Class<?>, List<MetaConstraint<T, ?>>>();
+ }
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java 2010-05-21 06:56:48 UTC (rev 19580)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java 2010-05-21 10:31:30 UTC (rev 19581)
@@ -650,7 +650,8 @@
*
* @param clazz The class to start the search with.
*
- * @return List of all super classes and interfaces of {@code clazz}.
+ * @return List of all super classes and interfaces of {@code clazz}. The list contains the class itself! The empty
+ * list is returned if {@code clazz} is {@code null}.
*/
public static List<Class<?>> computeClassHierarchy(Class<?> clazz) {
List<Class<?>> classes = new ArrayList<Class<?>>();
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html (from rev 19558, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/package.html)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/package.html 2010-05-21 10:31:30 UTC (rev 19581)
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+ <!--
+
+ JBoss, Home of Professional Open Source
+ Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ by the @authors tag. See the copyright.txt in the distribution for a
+ full listing of individual contributors.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+</head>
+<body>
+Implementations of {@code PrivilegedAction} in order to execute reflection operations in a security manager.
+</body>
+</html>
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-05-21 06:56:48 UTC (rev 19580)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-05-21 10:31:30 UTC (rev 19581)
@@ -92,7 +92,7 @@
assertConstraintViolation( violations.iterator().next(), "may not be null" );
}
- @Test(enabled = false)
+ @Test
public void testInheritedConstraint() {
HibernateValidatorConfiguration config = TestUtil.getConfiguration( HibernateValidator.class );
@@ -117,7 +117,7 @@
Set<ConstraintViolation<Marathon>> violations = validator.validate( marathon );
assertNumberOfViolations( violations, 1 );
- assertConstraintViolation( violations.iterator().next(), "may not be null" );
+ assertConstraintViolation( violations.iterator().next(), "must be in the future" );
}
@Test
14 years, 7 months
Hibernate SVN: r19580 - core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-21 02:56:48 -0400 (Fri, 21 May 2010)
New Revision: 19580
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Log:
account for last H2 failure on core.
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2010-05-21 05:34:58 UTC (rev 19579)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2010-05-21 06:56:48 UTC (rev 19580)
@@ -365,16 +365,26 @@
s = openSession();
t = s.beginTransaction();
- sqlQuery = s.getNamedQuery("organizationreturnproperty");
- sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
+ sqlQuery = s.getNamedQuery( "organizationreturnproperty" );
+ sqlQuery.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
list = sqlQuery.list();
- assertEquals(2,list.size() );
+ assertEquals( 2,list.size() );
m = (Map) list.get(0);
- assertTrue(m.containsKey("org"));
- assertClassAssignability(m.get("org").getClass(), Organization.class);
- assertTrue(m.containsKey("emp"));
- assertClassAssignability(m.get("emp").getClass(), Employment.class);
- assertEquals(2, m.size());
+ assertEquals( 2, m.size() );
+ assertTrue( m.containsKey("org") );
+ assertTrue( m.containsKey("emp") );
+ assertClassAssignability( m.get("org").getClass(), Organization.class );
+ if ( jboss.getId() == ( (Organization) m.get("org") ).getId() ) {
+ assertClassAssignability( m.get("emp").getClass(), Employment.class );
+ }
+ Map m2 = (Map) list.get(1);
+ assertEquals( 2, m.size() );
+ assertTrue( m2.containsKey("org") );
+ assertTrue( m2.containsKey("emp") );
+ assertClassAssignability( m2.get("org").getClass(), Organization.class );
+ if ( jboss.getId() == ( (Organization) m2.get("org") ).getId() ) {
+ assertClassAssignability( m2.get("emp").getClass(), Employment.class );
+ }
t.commit();
s.close();
14 years, 7 months
Hibernate SVN: r19579 - search/tags.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-21 01:34:58 -0400 (Fri, 21 May 2010)
New Revision: 19579
Added:
search/tags/v3_1_1_GA_CP02/
Log:
JBPAPP-4318 tag hibernate components for EAP 5.1
Copied: search/tags/v3_1_1_GA_CP02 (from rev 19578, search/branches/v3_1_1_GA_CP)
14 years, 7 months