Hibernate SVN: r17271 - core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-08-11 23:05:57 -0400 (Tue, 11 Aug 2009)
New Revision: 17271
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
Log:
JBPAPP-1547 HHH-3686 : Sybase - QueryCacheTest.testQueryCacheInvalidation fails
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-12 02:27:18 UTC (rev 17270)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-12 03:05:57 UTC (rev 17271)
@@ -64,7 +64,13 @@
public boolean supportsCascadeDelete() {
return false;
}
-
+ /**
+ * By default, Sybase string comparisons are case-insensitive.<br>
+ * If the DB is configured to be case-sensitive, then the return value will be incorrect.
+ */
+ public boolean areStringComparisonsCaseInsensitive() {
+ return true;
+ }
public boolean supportsExpectedLobUsagePattern() {
return false;
}
14 years, 8 months
Hibernate SVN: r17270 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-08-11 22:27:18 -0400 (Tue, 11 Aug 2009)
New Revision: 17270
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
Log:
JBPAPP-1547 HHH-3686 : Sybase - QueryCacheTest.testQueryCacheInvalidation fails
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-11 20:54:53 UTC (rev 17269)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-12 02:27:18 UTC (rev 17270)
@@ -68,7 +68,13 @@
public boolean supportsCascadeDelete() {
return false;
}
-
+ /**
+ * By default, Sybase string comparisons are case-insensitive.<br>
+ * If the DB is configured to be case-sensitive, then the return value will be incorrect.
+ */
+ public boolean areStringComparisonsCaseInsensitive() {
+ return true;
+ }
public boolean supportsExpectedLobUsagePattern() {
return false;
}
14 years, 8 months
Hibernate SVN: r17269 - core/trunk/entitymanager/src/main/java/org/hibernate/engine.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-11 16:54:53 -0400 (Tue, 11 Aug 2009)
New Revision: 17269
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadeStyle.java
core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadingAction.java
Log:
copyright notice
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadeStyle.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadeStyle.java 2009-08-11 20:50:34 UTC (rev 17268)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadeStyle.java 2009-08-11 20:54:53 UTC (rev 17269)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.engine;
/**
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadingAction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadingAction.java 2009-08-11 20:50:34 UTC (rev 17268)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/engine/EJB3CascadingAction.java 2009-08-11 20:54:53 UTC (rev 17269)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.engine;
import java.util.Map;
14 years, 8 months
Hibernate SVN: r17268 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb: util and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-11 16:50:34 -0400 (Tue, 11 Aug 2009)
New Revision: 17268
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/NamingHelper.java
Log:
copyright notice
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2009-08-11 20:30:32 UTC (rev 17267)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2009-08-11 20:50:34 UTC (rev 17268)
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb.packaging;
import java.io.IOException;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java 2009-08-11 20:30:32 UTC (rev 17267)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java 2009-08-11 20:50:34 UTC (rev 17268)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb.util;
import java.util.Map;
@@ -42,7 +62,9 @@
}
private static FlushMode getFlushMode(String flushMode) {
- if (flushMode == null) return null;
+ if (flushMode == null) {
+ return null;
+ }
flushMode = flushMode.toUpperCase();
return FlushMode.parse( flushMode );
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java 2009-08-11 20:30:32 UTC (rev 17267)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java 2009-08-11 20:50:34 UTC (rev 17268)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb.util;
import java.net.URL;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/NamingHelper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/NamingHelper.java 2009-08-11 20:30:32 UTC (rev 17267)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/NamingHelper.java 2009-08-11 20:50:34 UTC (rev 17268)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb.util;
import javax.naming.Context;
14 years, 8 months
Hibernate SVN: r17267 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-11 16:30:32 -0400 (Tue, 11 Aug 2009)
New Revision: 17267
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/CurrentEntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3ConfigurationObjectFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EventListenerConfigurator.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManager.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateQuery.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/InjectionSettingsFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java
Log:
copyright notice
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,7 +1,23 @@
-// $Id$
/*
- * JBoss, the OpenSource EJB server Distributable under LGPL license. See terms of license at
- * gnu.org.
+ * Copyright (c) 2009, 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
*/
package org.hibernate.ejb;
@@ -11,7 +27,6 @@
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
-import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
@@ -395,7 +410,9 @@
public abstract Session getSession();
/**
- * Return a Session (even if the entity manager is closed
+ * Return a Session (even if the entity manager is closed).
+ *
+ * @return A session.
*/
protected abstract Session getRawSession();
@@ -465,15 +482,6 @@
else if ( mode == FlushMode.COMMIT ) {
this.flushModeType = FlushModeType.COMMIT;
}
-// else if ( mode == FlushMode.NEVER ) {
-// if ( PersistenceContextType.EXTENDED == persistenceContextType && !isTransactionInProgress() ) {
-// //we are in flushMode none for EXTENDED
-// return flushMode;
-// }
-// else {
-// return null; //TODO exception?
-// }
-// }
else {
return null; //TODO exception?
}
@@ -689,8 +697,6 @@
return getSession();
}
- ;
-
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/CurrentEntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/CurrentEntityManagerImpl.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/CurrentEntityManagerImpl.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb;
import java.util.Map;
@@ -6,7 +26,6 @@
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.Session;
-import org.hibernate.SessionFactory;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.util.JTAHelper;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3ConfigurationObjectFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3ConfigurationObjectFactory.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3ConfigurationObjectFactory.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb;
import java.io.ByteArrayInputStream;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb;
import java.util.Map;
@@ -19,8 +39,11 @@
import org.hibernate.ejb.metamodel.MetamodelImpl;
/**
+ * Actual Hiberate implementation of {@link javax.persistence.EntityManagerFactory}.
+ *
* @author Gavin King
* @author Emmanuel Bernard
+ * @author Steve Ebersole
*/
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
private final SessionFactory sessionFactory;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
@@ -17,6 +39,8 @@
import org.slf4j.LoggerFactory;
/**
+ * Hibernate implementation of {@link javax.persistence.EntityManager}.
+ *
* @author Gavin King
*/
public class EntityManagerImpl extends AbstractEntityManagerImpl {
@@ -33,13 +57,14 @@
PersistenceUnitTransactionType transactionType,
boolean discardOnClose,
Class sessionInterceptorClass,
- Map properties
- ) {
+ Map properties) {
super( entityManagerFactory, pcType, transactionType, properties );
this.open = true;
this.discardOnClose = discardOnClose;
Object localSessionInterceptor = null;
- if (properties != null) localSessionInterceptor = properties.get( HibernatePersistence.SESSION_INTERCEPTOR );
+ if (properties != null) {
+ localSessionInterceptor = properties.get( HibernatePersistence.SESSION_INTERCEPTOR );
+ }
if ( localSessionInterceptor != null ) {
if (localSessionInterceptor instanceof Class) {
sessionInterceptorClass = (Class) localSessionInterceptor;
@@ -62,7 +87,9 @@
}
public Session getSession() {
- if ( !open ) throw new IllegalStateException( "EntityManager is closed" );
+ if ( !open ) {
+ throw new IllegalStateException( "EntityManager is closed" );
+ }
return getRawSession();
}
@@ -92,8 +119,9 @@
}
public void close() {
-
- if ( !open ) throw new IllegalStateException( "EntityManager is closed" );
+ if ( !open ) {
+ throw new IllegalStateException( "EntityManager is closed" );
+ }
if ( !discardOnClose && isTransactionInProgress() ) {
//delay the closing till the end of the enlisted transaction
getSession().getTransaction().registerSynchronization(
@@ -120,7 +148,9 @@
}
else {
//close right now
- if ( session != null ) session.close();
+ if ( session != null ) {
+ session.close();
+ }
}
open = false;
}
@@ -128,7 +158,9 @@
public boolean isOpen() {
//adjustFlushMode(); //don't adjust, can't be done on closed EM
try {
- if ( open ) getSession().isOpen(); //to force enlistment in tx
+ if ( open ) {
+ getSession().isOpen(); //to force enlistment in tx
+ }
return open;
}
catch (HibernateException he) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EventListenerConfigurator.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EventListenerConfigurator.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EventListenerConfigurator.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManager.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManager.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManager.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,4 +1,24 @@
-//$Id$
+/*
+ * Copyright (c) 2009, 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
+ */
package org.hibernate.ejb;
import javax.persistence.EntityManager;
@@ -6,8 +26,15 @@
import org.hibernate.Session;
/**
+ * Additional contract for Hibernate implementations of {@link EntityManager} providing access to various Hibernate
+ * specific functionality.
+ *
* @author Gavin King
*/
public interface HibernateEntityManager extends EntityManager {
+ /**
+ * Retrieve a reference to the Hibernate {@link Session} used by this {@link EntityManager}.
+ * @return
+ */
public Session getSession();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
@@ -32,7 +54,7 @@
*/
public static final String PROVIDER = "javax.persistence.provider";
/**
- * �
+ * �
* transaction type
*/
public static final String TRANSACTION_TYPE = "javax.persistence.transactionType";
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateQuery.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateQuery.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateQuery.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/InjectionSettingsFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/InjectionSettingsFactory.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/InjectionSettingsFactory.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java 2009-08-11 19:33:12 UTC (rev 17266)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java 2009-08-11 20:30:32 UTC (rev 17267)
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 2009, 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
+ */
+
//$Id$
package org.hibernate.ejb;
14 years, 8 months
Hibernate SVN: r17266 - beanvalidation/trunk/validation-tck and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-11 15:33:12 -0400 (Tue, 11 Aug 2009)
New Revision: 17266
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
beanvalidation/trunk/validation-tck/pom.xml
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/inheritance/GroupInheritanceTest.java
validator/trunk/pom.xml
Log:
HV-171 implement security in Validation
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-08-11 19:31:41 UTC (rev 17265)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-08-11 19:33:12 UTC (rev 17266)
@@ -27,6 +27,8 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
+import java.security.PrivilegedAction;
+import java.security.AccessController;
import javax.validation.bootstrap.GenericBootstrap;
import javax.validation.bootstrap.ProviderSpecificBootstrap;
import javax.validation.spi.BootstrapState;
@@ -265,15 +267,16 @@
//cache per classloader for an appropriate discovery
//keep them in a weak hashmap to avoid memory leaks and allow proper hot redeployment
//TODO use a WeakConcurrentHashMap
+ //FIXME The List<VP> does keep a strong reference to the key ClassLoader, use the same model as JPA CachingPersistenceProviderResolver
private static final Map<ClassLoader, List<ValidationProvider<?>>> providersPerClassloader =
new WeakHashMap<ClassLoader, List<ValidationProvider<?>>>();
private static final String SERVICES_FILE = "META-INF/services/" + ValidationProvider.class.getName();
public List<ValidationProvider<?>> getValidationProviders() {
- ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classloader = GetClassLoader.fromContext();
if ( classloader == null ) {
- classloader = DefaultValidationProviderResolver.class.getClassLoader();
+ classloader = GetClassLoader.fromClass( DefaultValidationProviderResolver.class );
}
List<ValidationProvider<?>> providers;
@@ -334,10 +337,10 @@
return providers;
}
- private static Class<?> loadClass(String name, Class caller) throws ClassNotFoundException {
+ private static Class<?> loadClass(String name, Class<?> caller) throws ClassNotFoundException {
try {
//try context classloader, if fails try caller classloader
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader = GetClassLoader.fromContext();
if ( loader != null ) {
return loader.loadClass( name );
}
@@ -348,7 +351,45 @@
throw e;
}
}
- return Class.forName( name, true, caller.getClassLoader() );
+ return Class.forName( name, true, GetClassLoader.fromClass( caller ) );
}
}
+
+ private static class GetClassLoader implements PrivilegedAction<ClassLoader> {
+ private final Class<?> clazz;
+
+ public static ClassLoader fromContext() {
+ final GetClassLoader action = new GetClassLoader( null );
+ if (System.getSecurityManager() != null) {
+ return AccessController.doPrivileged( action );
+ }
+ else {
+ return action.run();
+ }
+ }
+
+ public static ClassLoader fromClass(Class<?> clazz) {
+ if ( clazz == null ) throw new IllegalArgumentException("Class is null");
+ final GetClassLoader action = new GetClassLoader( clazz );
+ if (System.getSecurityManager() != null) {
+ return AccessController.doPrivileged( action );
+ }
+ else {
+ return action.run();
+ }
+ }
+
+ private GetClassLoader(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public ClassLoader run() {
+ if (clazz != null) {
+ return clazz.getClassLoader();
+ }
+ else {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+ }
}
Modified: beanvalidation/trunk/validation-tck/pom.xml
===================================================================
--- beanvalidation/trunk/validation-tck/pom.xml 2009-08-11 19:31:41 UTC (rev 17265)
+++ beanvalidation/trunk/validation-tck/pom.xml 2009-08-11 19:33:12 UTC (rev 17266)
@@ -46,7 +46,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
- <version>1.0.CR3</version>
+ <version>1.0.CR4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.test-audit</groupId>
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/inheritance/GroupInheritanceTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/inheritance/GroupInheritanceTest.java 2009-08-11 19:31:41 UTC (rev 17265)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/inheritance/GroupInheritanceTest.java 2009-08-11 19:33:12 UTC (rev 17266)
@@ -71,7 +71,7 @@
// PreManufacturing belongs implicitly to All
PropertyDescriptor propertyDescriptor = descriptor.getConstraintsForProperty( "partNumber" );
- Set<ConstraintDescriptor<?>> descriptorsForGroup = propertyDescriptor.getUnorderdConstraintDescriptorsMatchingGroups(
+ Set<ConstraintDescriptor<?>> descriptorsForGroup = propertyDescriptor.getUnorderedConstraintDescriptorsMatchingGroups(
All.class
);
assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
@@ -79,12 +79,12 @@
// PostManufacturing belongs implicitly to All
propertyDescriptor = descriptor.getConstraintsForProperty( "qaChecked" );
- descriptorsForGroup = propertyDescriptor.getUnorderdConstraintDescriptorsMatchingGroups( All.class );
+ descriptorsForGroup = propertyDescriptor.getUnorderedConstraintDescriptorsMatchingGroups( All.class );
assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), AssertTrue.class );
propertyDescriptor = descriptor.getConstraintsForProperty( "size" );
- descriptorsForGroup = propertyDescriptor.getUnorderdConstraintDescriptorsMatchingGroups( All.class );
+ descriptorsForGroup = propertyDescriptor.getUnorderedConstraintDescriptorsMatchingGroups( All.class );
assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), Max.class );
}
Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml 2009-08-11 19:31:41 UTC (rev 17265)
+++ validator/trunk/pom.xml 2009-08-11 19:33:12 UTC (rev 17266)
@@ -47,7 +47,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
- <version>1.0.CR3</version>
+ <version>1.0.CR4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
14 years, 8 months
Hibernate SVN: r17265 - in validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation: engine/resolver and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-11 15:31:41 -0400 (Tue, 11 Aug 2009)
New Revision: 17265
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetClassLoader.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/LoadClass.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java
Log:
HV-171 finishing implementation adding due doPriviledge when needed
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java 2009-08-11 19:16:08 UTC (rev 17264)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -24,11 +24,13 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.security.AccessController;
import javax.validation.MessageInterpolator;
import org.slf4j.Logger;
import org.hibernate.validation.util.LoggerFactory;
+import org.hibernate.validation.util.GetClassLoader;
/**
* Resource bundle backed message interpolator.
@@ -155,13 +157,18 @@
*/
private ResourceBundle getFileBasedResourceBundle(Locale locale) {
ResourceBundle rb = null;
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ boolean isSecured = System.getSecurityManager() != null;
+ GetClassLoader action = GetClassLoader.fromContext();
+ ClassLoader classLoader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+
if ( classLoader != null ) {
rb = loadBundle( classLoader, locale, USER_VALIDATION_MESSAGES + " not found by thread local classloader" );
}
if ( rb == null ) {
+ action = GetClassLoader.fromClass(ResourceBundleMessageInterpolator.class);
+ classLoader = isSecured ? AccessController.doPrivileged( action ) : action.run();
rb = loadBundle(
- this.getClass().getClassLoader(),
+ classLoader,
locale,
USER_VALIDATION_MESSAGES + " not found by validator classloader"
);
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java 2009-08-11 19:16:08 UTC (rev 17264)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -11,6 +11,7 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
import org.hibernate.validation.util.NewInstance;
+import org.hibernate.validation.util.LoadClass;
/**
* A JPA 2 aware <code>TraversableResolver</code>.
@@ -47,10 +48,10 @@
*/
private void detectJPA() {
try {
- ReflectionHelper.classForName( PERSISTENCE_UTIL_CLASS_NAME, this.getClass() );
+ loadClass( PERSISTENCE_UTIL_CLASS_NAME, this.getClass() );
log.debug( "Found {} on classpath.", PERSISTENCE_UTIL_CLASS_NAME );
}
- catch ( ClassNotFoundException e ) {
+ catch ( ValidationException e ) {
log.debug(
"Cannot find {} on classpath. All properties will per default be traversable.",
PERSISTENCE_UTIL_CLASS_NAME
@@ -61,7 +62,7 @@
try {
@SuppressWarnings( "unchecked" )
Class<? extends TraversableResolver> jpaAwareResolverClass = (Class<? extends TraversableResolver>)
- ReflectionHelper.classForName(JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, this.getClass() );
+ loadClass(JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, this.getClass() );
NewInstance<? extends TraversableResolver> newInstance = NewInstance.action( jpaAwareResolverClass, "" );
if ( System.getSecurityManager() != null ) {
jpaTraversableResolver = AccessController.doPrivileged( newInstance );
@@ -73,20 +74,24 @@
"Instantiated an instance of {}.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
}
- catch ( ClassNotFoundException e ) {
- log.info(
- "Unable to load JPA aware resolver {}. All properties will per default be traversable.",
- JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
- );
- }
catch ( ValidationException e ) {
log.info(
- "Unable to instantiate JPA aware resolver {}. All properties will per default be traversable.",
+ "Unable to load or instanciate JPA aware resolver {}. All properties will per default be traversable.",
JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
}
}
+ private Class<?> loadClass(String className, Class<?> caller) {
+ LoadClass action = LoadClass.action( className, caller );
+ if (System.getSecurityManager() != null) {
+ return AccessController.doPrivileged( action );
+ }
+ else {
+ return action.run();
+ }
+ }
+
public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
return jpaTraversableResolver == null || jpaTraversableResolver.isReachable(
traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetClassLoader.java (from rev 17263, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsField.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetClassLoader.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetClassLoader.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -0,0 +1,32 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetClassLoader implements PrivilegedAction<ClassLoader> {
+ private final Class<?> clazz;
+
+ public static GetClassLoader fromContext() {
+ return new GetClassLoader( null );
+ }
+
+ public static GetClassLoader fromClass(Class<?> clazz) {
+ if ( clazz == null ) throw new IllegalArgumentException("Class is null");
+ return new GetClassLoader( clazz );
+ }
+
+ private GetClassLoader(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public ClassLoader run() {
+ if (clazz != null) {
+ return clazz.getClassLoader();
+ }
+ else {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/LoadClass.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/LoadClass.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/LoadClass.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -0,0 +1,39 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+import javax.validation.ValidationException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class LoadClass implements PrivilegedAction<Class<?>> {
+ private final String className;
+ private final Class<?> caller;
+
+ public static LoadClass action(String className, Class<?> caller) {
+ return new LoadClass( className, caller );
+ }
+
+ private LoadClass(String className, Class<?> caller) {
+ this.className = className;
+ this.caller = caller;
+ }
+
+ public Class<?> run() {
+ try {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if ( contextClassLoader != null ) {
+ return contextClassLoader.loadClass( className );
+ }
+ }
+ catch ( Throwable e ) {
+ // ignore
+ }
+ try {
+ return Class.forName( className, true, caller.getClassLoader() );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException("Unable to load class: " + className, e);
+ }
+ }
+}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-08-11 19:16:08 UTC (rev 17264)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -198,23 +198,6 @@
}
}
- public static Class<?> loadClass(String name, Class<?> caller) throws ClassNotFoundException {
- try {
- //try context classloader, if fails try caller classloader
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if ( loader != null ) {
- return loader.loadClass( name );
- }
- }
- catch ( ClassNotFoundException e ) {
- //trying caller classloader
- if ( caller == null ) {
- throw e;
- }
- }
- return Class.forName( name, true, caller.getClassLoader() );
- }
-
/**
* Determines the type of elements of an <code>Iterable</code>, array or the value of a <code>Map</code>.
*
@@ -382,19 +365,6 @@
}
}
- public static Class<?> classForName(String name, Class<?> caller) throws ClassNotFoundException {
- try {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- if ( contextClassLoader != null ) {
- return contextClassLoader.loadClass( name );
- }
- }
- catch ( Throwable e ) {
- // ignore
- }
- return Class.forName( name, true, caller.getClassLoader() );
- }
-
/**
* Returns the autoboxed type of a primitive type.
*
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java 2009-08-11 19:16:08 UTC (rev 17264)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -25,6 +25,7 @@
import java.security.AccessController;
import org.hibernate.validation.util.GetConstructor;
+import org.hibernate.validation.util.GetClassLoader;
/**
@@ -38,7 +39,9 @@
@SuppressWarnings("unchecked")
public static <T extends Annotation> T create(AnnotationDescriptor<T> descriptor) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ boolean isSecured = System.getSecurityManager() != null;
+ GetClassLoader action = GetClassLoader.fromContext();
+ ClassLoader classLoader = isSecured ? AccessController.doPrivileged( action ) : action.run();
//TODO round 34ms to generate the proxy, hug! is Javassist Faster?
Class<T> proxyClass = (Class<T>) Proxy.getProxyClass( classLoader, descriptor.type() );
InvocationHandler handler = new AnnotationProxy( descriptor );
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java 2009-08-11 19:16:08 UTC (rev 17264)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -39,6 +39,8 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
import org.hibernate.validation.util.NewInstance;
+import org.hibernate.validation.util.GetClassLoader;
+import org.hibernate.validation.util.LoadClass;
import org.hibernate.validation.xml.PropertyType;
import org.hibernate.validation.xml.ValidationConfigType;
@@ -79,7 +81,7 @@
if ( constraintFactoryClass != null ) {
try {
@SuppressWarnings("unchecked")
- Class<ConstraintValidatorFactory> clazz = ( Class<ConstraintValidatorFactory> ) ReflectionHelper.classForName(
+ Class<ConstraintValidatorFactory> clazz = ( Class<ConstraintValidatorFactory> ) loadClass(
constraintFactoryClass, this.getClass()
);
NewInstance<ConstraintValidatorFactory> newInstance = NewInstance.action( clazz, "constraint factory class" );
@@ -91,7 +93,7 @@
}
log.info( "Using {} as constraint factory.", constraintFactoryClass );
}
- catch ( ClassNotFoundException e ) {
+ catch ( ValidationException e ) {
throw new ValidationException(
"Unable to instantiate constraint factory class " + constraintFactoryClass + ".", e
);
@@ -99,6 +101,16 @@
}
}
+ private Class<?> loadClass(String className, Class<?> caller) {
+ LoadClass action = LoadClass.action( className, caller );
+ if (System.getSecurityManager() != null) {
+ return AccessController.doPrivileged( action );
+ }
+ else {
+ return action.run();
+ }
+ }
+
private void setPropertiesFromXml(ValidationConfigType config, ValidationBootstrapParameters xmlParameters) {
for ( PropertyType property : config.getProperty() ) {
if ( log.isDebugEnabled() ) {
@@ -132,13 +144,13 @@
if ( messageInterpolatorClass != null ) {
try {
@SuppressWarnings("unchecked")
- Class<MessageInterpolator> clazz = ( Class<MessageInterpolator> ) ReflectionHelper.classForName(
+ Class<MessageInterpolator> clazz = ( Class<MessageInterpolator> ) loadClass(
messageInterpolatorClass, this.getClass()
);
xmlParameters.messageInterpolator = clazz.newInstance();
log.info( "Using {} as message interpolator.", messageInterpolatorClass );
}
- catch ( ClassNotFoundException e ) {
+ catch ( ValidationException e ) {
throw new ValidationException(
"Unable to instantiate message interpolator class " + messageInterpolatorClass + ".", e
);
@@ -161,13 +173,13 @@
if ( traversableResolverClass != null ) {
try {
@SuppressWarnings("unchecked")
- Class<TraversableResolver> clazz = ( Class<TraversableResolver> ) ReflectionHelper.classForName(
+ Class<TraversableResolver> clazz = ( Class<TraversableResolver> ) loadClass(
traversableResolverClass, this.getClass()
);
xmlParameters.traversableResolver = clazz.newInstance();
log.info( "Using {} as traversable resolver.", traversableResolverClass );
}
- catch ( ClassNotFoundException e ) {
+ catch ( ValidationException e ) {
throw new ValidationException(
"Unable to instantiate traversable resolver class " + traversableResolverClass + ".", e
);
@@ -190,7 +202,7 @@
String providerClassName = config.getDefaultProvider();
if ( providerClassName != null ) {
try {
- xmlParamters.providerClass = ( Class<? extends ValidationProvider<?>> ) ReflectionHelper.classForName(
+ xmlParamters.providerClass = ( Class<? extends ValidationProvider<?>> ) loadClass(
providerClassName, this.getClass()
);
log.info( "Using {} as validation provider.", providerClassName );
@@ -233,25 +245,36 @@
if ( path.startsWith( "/" ) ) {
path = path.substring( 1 );
}
+
+
+ boolean isSecured = System.getSecurityManager() != null;
+ boolean isContextCL = true;
// try the context class loader first
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- boolean isContextCL = true;
+ GetClassLoader action = GetClassLoader.fromContext();
+ ClassLoader loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+
if (loader == null) {
log.debug( "No default context class loader, fallbacking to Bean Validation's loader" );
- loader = ValidationXmlParser.class.getClassLoader();
+ action = GetClassLoader.fromClass(ValidationXmlParser.class);
+ loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
isContextCL = false;
}
InputStream inputStream = loader.getResourceAsStream( path );
// try the current class loader
if ( isContextCL && inputStream == null ) {
- inputStream = ValidationXmlParser.class.getClassLoader().getResourceAsStream( path );
+ action = GetClassLoader.fromClass(ValidationXmlParser.class);
+ loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ inputStream = loader.getResourceAsStream( path );
}
return inputStream;
}
private Schema getValidationConfigurationSchema() {
- URL schemaUrl = this.getClass().getClassLoader().getResource( VALIDATION_CONFIGURATION_XSD );
+ boolean isSecured = System.getSecurityManager() != null;
+ GetClassLoader action = GetClassLoader.fromClass( ValidationXmlParser.class );
+ ClassLoader loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ URL schemaUrl = loader.getResource( VALIDATION_CONFIGURATION_XSD );
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
Schema schema = null;
try {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java 2009-08-11 19:16:08 UTC (rev 17264)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java 2009-08-11 19:31:41 UTC (rev 17265)
@@ -59,6 +59,8 @@
import org.hibernate.validation.util.ContainsMethod;
import org.hibernate.validation.util.GetMethod;
import org.hibernate.validation.util.GetDeclaredField;
+import org.hibernate.validation.util.GetClassLoader;
+import org.hibernate.validation.util.LoadClass;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
import org.hibernate.validation.xml.AnnotationType;
@@ -173,14 +175,9 @@
for ( ConstraintDefinitionType constraintDefinition : constraintDefinitionList ) {
String annotationClassName = constraintDefinition.getAnnotation();
Class<? extends Annotation> annotationClass;
- try {
- annotationClass = ( Class<? extends Annotation> ) ReflectionHelper.classForName(
- annotationClassName, this.getClass()
- );
- }
- catch ( ClassNotFoundException e ) {
- throw new ValidationException( "Unable to load class " + annotationClassName );
- }
+ annotationClass = ( Class<? extends Annotation> ) loadClass(
+ annotationClassName, this.getClass()
+ );
if ( !annotationClass.isAnnotation() ) {
throw new ValidationException( annotationClassName + " is not an annotation" );
@@ -193,16 +190,12 @@
}
for ( JAXBElement<String> validatorClassName : validatedByType.getValue() ) {
Class<? extends ConstraintValidator<?, ?>> validatorClass;
- try {
- validatorClass = ( Class<? extends ConstraintValidator<?, ?>> ) ReflectionHelper.classForName(
- validatorClassName.getValue(),
- this.getClass()
- );
- }
- catch ( ClassNotFoundException e ) {
- throw new ValidationException( "Unable to load class " + validatorClassName );
- }
+ validatorClass = ( Class<? extends ConstraintValidator<?, ?>> ) loadClass(
+ validatorClassName.getValue(),
+ this.getClass()
+ );
+
if ( !ConstraintValidator.class.isAssignableFrom( validatorClass ) ) {
throw new ValidationException( validatorClass + " is not a constraint validator class" );
}
@@ -215,6 +208,16 @@
}
}
+ private Class<?> loadClass(String className, Class<?> caller) {
+ LoadClass action = LoadClass.action( className, caller );
+ if (System.getSecurityManager() != null) {
+ return AccessController.doPrivileged( action );
+ }
+ else {
+ return action.run();
+ }
+ }
+
private List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> findConstraintValidatorClasses(Class<? extends Annotation> annotationType) {
List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraintValidatorDefinitonClasses = new ArrayList<Class<? extends ConstraintValidator<? extends Annotation, ?>>>();
if ( constraintHelper.isBuiltinConstraint( annotationType ) ) {
@@ -569,12 +572,7 @@
returnValue = value;
}
else if ( returnType.getName().equals( Class.class.getName() ) ) {
- try {
- returnValue = ReflectionHelper.classForName( value, this.getClass() );
- }
- catch ( ClassNotFoundException e ) {
- throw new ValidationException( "Unable to instantiate class: " + value );
- }
+ returnValue = loadClass( value, this.getClass() );
}
else {
try {
@@ -615,12 +613,7 @@
else {
fullyQualifiedClass = defaultPackage + PACKAGE_SEPERATOR + clazz;
}
- try {
- return ReflectionHelper.classForName( fullyQualifiedClass, this.getClass() );
- }
- catch ( Exception e ) {
- throw new ValidationException( "Unable to instantiate class " + fullyQualifiedClass );
- }
+ return loadClass( fullyQualifiedClass, this.getClass() );
}
private boolean isQualifiedClass(String clazz) {
@@ -647,7 +640,10 @@
}
private Schema getMappingSchema() {
- URL schemaUrl = this.getClass().getClassLoader().getResource( VALIDATION_MAPPING_XSD );
+ boolean isSecured = System.getSecurityManager() != null;
+ GetClassLoader action = GetClassLoader.fromClass( XmlMappingParser.class );
+ ClassLoader loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ URL schemaUrl = loader.getResource( VALIDATION_MAPPING_XSD );
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
Schema schema = null;
try {
14 years, 8 months
Hibernate SVN: r17264 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-11 15:16:08 -0400 (Tue, 11 Aug 2009)
New Revision: 17264
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
Log:
EJB-447 : Implement JPA 2.0 criteria apis
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-08-11 18:00:25 UTC (rev 17263)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-08-11 19:16:08 UTC (rev 17264)
@@ -38,7 +38,8 @@
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
/**
- * TODO : javadoc
+ * The Hibernate implementation of the JPA {@link Subquery} contract. Mostlty a set of delegation to its internal
+ * {@link QueryStructure}.
*
* @author Steve Ebersole
*/
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-11 18:00:25 UTC (rev 17263)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-11 19:16:08 UTC (rev 17264)
@@ -813,9 +813,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> sum(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression1.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.ADD,
expression1,
expression2
@@ -826,9 +828,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> prod(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression1.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.MULTIPLY,
expression1,
expression2
@@ -839,6 +843,8 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> diff(Expression<? extends N> expression1, Expression<? extends N> expression2) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression1 );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, (Expression)expression2 );
return new BinaryArithmeticOperation<N>(
this,
(Class<N>) expression1.getJavaType(),
@@ -852,9 +858,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> sum(Expression<? extends N> expression, N n) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.ADD,
expression,
n
@@ -865,9 +873,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> prod(Expression<? extends N> expression, N n) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.MULTIPLY,
expression,
n
@@ -878,9 +888,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> diff(Expression<? extends N> expression, N n) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.SUBTRACT,
expression,
n
@@ -891,9 +903,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> sum(N n, Expression<? extends N> expression) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.ADD,
n,
expression
@@ -904,9 +918,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> prod(N n, Expression<? extends N> expression) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.MULTIPLY,
n,
expression
@@ -917,9 +933,11 @@
* {@inheritDoc}
*/
public <N extends Number> Expression<N> diff(N n, Expression<? extends N> expression) {
+ Class<N> type = (Class<N>)BinaryArithmeticOperation.determineReturnType( (Class)Number.class, (Expression)expression );
+ type = (Class<N>)BinaryArithmeticOperation.determineReturnType( type, n );
return new BinaryArithmeticOperation<N>(
this,
- (Class<N>) expression.getJavaType(),
+ type,
BinaryArithmeticOperation.Operation.SUBTRACT,
n,
expression
@@ -930,24 +948,39 @@
* {@inheritDoc}
*/
public Expression<Number> quot(Expression<? extends Number> expression1, Expression<? extends Number> expression2) {
- // TODO : still open question whether this should be a quotient (integer division) or division
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ return new BinaryArithmeticOperation<Number>(
+ this,
+ Number.class,
+ BinaryArithmeticOperation.Operation.DIVIDE,
+ expression1,
+ expression2
+ );
}
/**
* {@inheritDoc}
*/
public Expression<Number> quot(Expression<? extends Number> expression, Number number) {
- // TODO : still open question whether this should be a quotient (integer division) or division
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ return new BinaryArithmeticOperation<Number>(
+ this,
+ Number.class,
+ BinaryArithmeticOperation.Operation.DIVIDE,
+ expression,
+ number
+ );
}
/**
* {@inheritDoc}
*/
public Expression<Number> quot(Number number, Expression<? extends Number> expression) {
- // TODO : still open question whether this should be a quotient (integer division) or division
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ return new BinaryArithmeticOperation<Number>(
+ this,
+ Number.class,
+ BinaryArithmeticOperation.Operation.DIVIDE,
+ number,
+ expression
+ );
}
/**
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-08-11 18:00:25 UTC (rev 17263)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-08-11 19:16:08 UTC (rev 17264)
@@ -23,7 +23,6 @@
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
@@ -44,18 +43,66 @@
private final Expression<? extends N> rhs;
private final Expression<? extends N> lhs;
+ /**
+ * Helper for determining the appropriate operation return type based on one of the operands as an expression.
+ *
+ * @param defaultType The default return type to use if we cannot determine the java type of 'expression' operand.
+ * @param expression The operand.
+ *
+ * @return The appropriate return type.
+ */
+ public static Class<? extends Number> determineReturnType(
+ Class<? extends Number> defaultType,
+ Expression<? extends Number> expression) {
+ return expression == null || expression.getJavaType() == null
+ ? defaultType
+ : expression.getJavaType();
+ }
+
+ /**
+ * Helper for determining the appropriate operation return type based on one of the operands as a literal.
+ *
+ * @param defaultType The default return type to use if we cannot determine the java type of 'numberLiteral' operand.
+ * @param numberLiteral The operand.
+ *
+ * @return The appropriate return type.
+ */
+ public static Class<? extends Number> determineReturnType(
+ Class<? extends Number> defaultType,
+ Number numberLiteral) {
+ return numberLiteral == null ? defaultType : numberLiteral.getClass();
+ }
+
+ /**
+ * Creates an arithmethic operation based on 2 expressions.
+ *
+ * @param queryBuilder The builder for query components.
+ * @param resultType The operation result type
+ * @param operator The operator (type of operation).
+ * @param rhs The right-hand operand
+ * @param lhs The left-hand operand.
+ */
public BinaryArithmeticOperation(
QueryBuilderImpl queryBuilder,
- Class<N> javaType,
+ Class<N> resultType,
Operation operator,
Expression<? extends N> rhs,
Expression<? extends N> lhs) {
- super( queryBuilder, javaType );
+ super( queryBuilder, resultType );
this.operator = operator;
this.rhs = rhs;
this.lhs = lhs;
}
+ /**
+ * Creates an arithmethic operation based on an expression and a literal.
+ *
+ * @param queryBuilder The builder for query components.
+ * @param resultType The operation result type
+ * @param operator The operator (type of operation).
+ * @param rhs The right-hand operand
+ * @param lhs The left-hand operand (the literal).
+ */
public BinaryArithmeticOperation(
QueryBuilderImpl queryBuilder,
Class<N> javaType,
@@ -68,6 +115,15 @@
this.lhs = new LiteralExpression<N>( queryBuilder, lhs );
}
+ /**
+ * Creates an arithmethic operation based on an expression and a literal.
+ *
+ * @param queryBuilder The builder for query components.
+ * @param resultType The operation result type
+ * @param operator The operator (type of operation).
+ * @param rhs The right-hand operand (the literal).
+ * @param lhs The left-hand operand
+ */
public BinaryArithmeticOperation(
QueryBuilderImpl queryBuilder,
Class<N> javaType,
@@ -79,19 +135,27 @@
this.rhs = new LiteralExpression<N>( queryBuilder, rhs );
this.lhs = lhs;
}
-
public Operation getOperator() {
return operator;
}
+ /**
+ * {@inheritDoc}
+ */
public Expression<? extends N> getRightHandOperand() {
return rhs;
}
+ /**
+ * {@inheritDoc}
+ */
public Expression<? extends N> getLeftHandOperand() {
return lhs;
}
+ /**
+ * {@inheritDoc}
+ */
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getRightHandOperand(), registry );
Helper.possibleParameter( getLeftHandOperand(), registry );
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-08-11 18:00:25 UTC (rev 17263)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-08-11 19:16:08 UTC (rev 17264)
@@ -1,12 +1,11 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
- * Models arithmetc operations with two operands.
+ * Models unary arithmetic operation (unary plus and unary minus).
*
* @author Steve Ebersole
*/
@@ -30,14 +29,20 @@
this.operand = operand;
}
+ public Operation getOperation() {
+ return operation;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Expression<T> getOperand() {
return operand;
}
- public Operation getOperation() {
- return operation;
- }
-
+ /**
+ * {@inheritDoc}
+ */
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getOperand(), registry );
}
14 years, 8 months
Hibernate SVN: r17263 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validation/engine/resolver and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-11 14:00:25 -0400 (Tue, 11 Aug 2009)
New Revision: 17263
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsField.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetAnnotationParameter.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetConstructor.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredField.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredFields.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethodFromPropertyName.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/NewInstance.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/SetAccessibility.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationProxy.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ConstraintHelperTest.java
Log:
HV-171 continuing implementation adding due doPriviledge when needed
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -20,9 +20,8 @@
import java.security.AccessController;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
-import javax.validation.ValidationException;
-import org.hibernate.validation.util.priviledgedactions.NewInstance;
+import org.hibernate.validation.util.NewInstance;
/**
* Default <code>ConstraintValidatorFactory</code> using a no-arg constructor.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -10,7 +10,7 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
-import org.hibernate.validation.util.priviledgedactions.NewInstance;
+import org.hibernate.validation.util.NewInstance;
/**
* A JPA 2 aware <code>TraversableResolver</code>.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -31,7 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
+import java.security.AccessController;
import javax.validation.GroupDefinitionException;
import javax.validation.GroupSequence;
import javax.validation.Valid;
@@ -44,6 +44,9 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
+import org.hibernate.validation.util.GetDeclaredFields;
+import org.hibernate.validation.util.GetDeclaredMethods;
+import org.hibernate.validation.util.SetAccessibility;
/**
@@ -258,7 +261,15 @@
}
private void initFieldConstraints(Class<?> clazz, AnnotationIgnores annotationIgnores) {
- for ( Field field : clazz.getDeclaredFields() ) {
+ GetDeclaredFields action = GetDeclaredFields.action( clazz );
+ final Field[] fields;
+ if ( System.getSecurityManager() != null ) {
+ fields = AccessController.doPrivileged( action );
+ }
+ else {
+ fields = action.run();
+ }
+ for ( Field field : fields ) {
// HV-172
if ( Modifier.isStatic( field.getModifiers() ) ) {
continue;
@@ -272,20 +283,39 @@
if ( annotationIgnores.isIgnoreAnnotations( field ) ) {
break;
}
- ReflectionHelper.setAccessibility( field );
+ setAccessibility( field );
MetaConstraint<T, ?> metaConstraint = createMetaConstraint( field, constraintDescription );
addMetaConstraint( clazz, metaConstraint );
}
if ( field.isAnnotationPresent( Valid.class ) ) {
- ReflectionHelper.setAccessibility( field );
+ setAccessibility( field );
cascadedMembers.add( field );
addPropertyDescriptorForMember( field );
}
}
}
+ private void setAccessibility(Member member) {
+ SetAccessibility action = SetAccessibility.action( member );
+ if (System.getSecurityManager() != null) {
+ AccessController.doPrivileged( action );
+ }
+ else {
+ action.run();
+ }
+ }
+
private void initMethodConstraints(Class<?> clazz, AnnotationIgnores annotationIgnores) {
- for ( Method method : clazz.getDeclaredMethods() ) {
+ GetDeclaredMethods action = GetDeclaredMethods.action( clazz );
+ final Method[] declaredMethods;
+ if ( System.getSecurityManager() != null ) {
+ declaredMethods = AccessController.doPrivileged( action );
+ }
+ else {
+ declaredMethods = action.run();
+ }
+
+ for ( Method method : declaredMethods ) {
// HV-172
if ( Modifier.isStatic( method.getModifiers() ) ) {
continue;
@@ -300,12 +330,12 @@
if ( annotationIgnores.isIgnoreAnnotations( method ) ) {
break;
}
- ReflectionHelper.setAccessibility( method );
+ setAccessibility( method );
MetaConstraint<T, ?> metaConstraint = createMetaConstraint( method, constraintDescription );
addMetaConstraint( clazz, metaConstraint );
}
if ( method.isAnnotationPresent( Valid.class ) ) {
- ReflectionHelper.setAccessibility( method );
+ setAccessibility( method );
cascadedMembers.add( method );
addPropertyDescriptorForMember( method );
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -29,7 +29,6 @@
import java.util.Map;
import java.util.Set;
import java.security.AccessController;
-import java.security.PrivilegedAction;
import javax.validation.Constraint;
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintPayload;
@@ -43,10 +42,10 @@
import org.slf4j.Logger;
import org.hibernate.validation.util.LoggerFactory;
-import org.hibernate.validation.util.ReflectionHelper;
-import org.hibernate.validation.util.priviledgedactions.GetMethods;
-import org.hibernate.validation.util.priviledgedactions.GetMethod;
-import org.hibernate.validation.util.priviledgedactions.GetAnnotationParameter;
+import org.hibernate.validation.util.GetAnnotationParameter;
+import org.hibernate.validation.util.GetMethods;
+import org.hibernate.validation.util.GetMethod;
+import org.hibernate.validation.util.GetDeclaredMethods;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -248,7 +247,14 @@
}
private Map<String, Object> buildAnnotationParameterMap(Annotation annotation) {
- Method[] declaredMethods = annotation.annotationType().getDeclaredMethods();
+ GetDeclaredMethods action = GetDeclaredMethods.action( annotation.annotationType() );
+ final Method[] declaredMethods;
+ if ( System.getSecurityManager() != null ) {
+ declaredMethods = AccessController.doPrivileged( action );
+ }
+ else {
+ declaredMethods = action.run();
+ }
Map<String, Object> parameters = new HashMap<String, Object>( declaredMethods.length );
for ( Method m : declaredMethods ) {
try {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -72,10 +72,9 @@
import org.hibernate.validation.constraints.impl.SizeValidatorForCollection;
import org.hibernate.validation.constraints.impl.SizeValidatorForMap;
import org.hibernate.validation.constraints.impl.SizeValidatorForString;
-import org.hibernate.validation.util.ReflectionHelper;
-import org.hibernate.validation.util.priviledgedactions.GetMethods;
-import org.hibernate.validation.util.priviledgedactions.GetMethod;
-import org.hibernate.validation.util.priviledgedactions.GetAnnotationParameter;
+import org.hibernate.validation.util.GetMethods;
+import org.hibernate.validation.util.GetMethod;
+import org.hibernate.validation.util.GetAnnotationParameter;
/**
* Keeps track of builtin constraints and their validator implementations, as well as already resolved validator definitions.
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsField.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsField.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsField.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,30 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ContainsField implements PrivilegedAction<Boolean> {
+ private final Class<?> clazz;
+ private final String property;
+
+ public static ContainsField action(Class<?> clazz, String property) {
+ return new ContainsField( clazz, property );
+ }
+
+ private ContainsField(Class<?> clazz, String property) {
+ this.clazz = clazz;
+ this.property = property;
+ }
+
+ public Boolean run() {
+ try {
+ clazz.getDeclaredField( property );
+ return true;
+ }
+ catch ( NoSuchFieldException e ) {
+ return false;
+ }
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsMethod.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsMethod.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ContainsMethod.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,26 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+
+import org.hibernate.validation.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.getMethod( clazz, property ) != null;
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetAnnotationParameter.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetAnnotationParameter.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetAnnotationParameter.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,30 @@
+package org.hibernate.validation.util;
+
+import java.lang.annotation.Annotation;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetAnnotationParameter<T> implements PrivilegedAction<T> {
+ private final Annotation annotation;
+ private final String parameterName;
+ private final Class<T> type;
+
+
+ public static <T> GetAnnotationParameter<T> action(Annotation annotation, String parameterName, Class<T> type) {
+ return new GetAnnotationParameter<T>( annotation, parameterName, type );
+ }
+
+ private GetAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
+ this.annotation = annotation;
+ this.parameterName = parameterName;
+ this.type = type;
+ }
+
+ public T run() {
+ return ReflectionHelper.getAnnotationParameter( annotation, parameterName, type );
+ }
+}
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetConstructor.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetConstructor.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetConstructor.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,30 @@
+package org.hibernate.validation.util;
+
+import java.lang.reflect.Constructor;
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetConstructor<T> implements PrivilegedAction<Constructor<T>> {
+ private final Class<T> clazz;
+ private final Class<?>[] params;
+
+ public static <T> GetConstructor<T> action(Class<T> clazz, Class<?>... params) {
+ return new GetConstructor<T>( clazz, params );
+ }
+
+ private GetConstructor(Class<T> clazz, Class<?>... params) {
+ this.clazz = clazz;
+ this.params = params;
+ }
+
+ public Constructor<T> run() {
+ try {
+ return clazz.getConstructor(params);
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredField.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredField.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredField.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,34 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Field;
+
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetDeclaredField implements PrivilegedAction<Field> {
+ private final Class<?> clazz;
+ private final String fieldName;
+
+ public static GetDeclaredField action(Class<?> clazz, String fieldName) {
+ return new GetDeclaredField( clazz, fieldName );
+ }
+
+ private GetDeclaredField(Class<?> clazz, String fieldName) {
+ this.clazz = clazz;
+ this.fieldName = fieldName;
+ }
+
+ public Field run() {
+ try {
+ final Field field = clazz.getDeclaredField( fieldName );
+ ReflectionHelper.setAccessibility( field );
+ return field;
+ }
+ catch ( NoSuchFieldException e ) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredFields.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredFields.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredFields.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,23 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Field;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetDeclaredFields implements PrivilegedAction<Field[]> {
+ private final Class<?> clazz;
+
+ public static GetDeclaredFields action(Class<?> clazz) {
+ return new GetDeclaredFields( clazz );
+ }
+
+ private GetDeclaredFields(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public Field[] run() {
+ return clazz.getDeclaredFields();
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredMethods.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredMethods.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetDeclaredMethods.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,23 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Method;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetDeclaredMethods implements PrivilegedAction<Method[]> {
+ private final Class<?> clazz;
+
+ public static GetDeclaredMethods action(Class<?> clazz) {
+ return new GetDeclaredMethods( clazz );
+ }
+
+ private GetDeclaredMethods(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public Method[] run() {
+ return clazz.getDeclaredMethods();
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethod.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethod.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethod.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,30 @@
+package org.hibernate.validation.util;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethod implements PrivilegedAction<Method> {
+ private final Class<?> clazz;
+ private final String methodName;
+
+ public static GetMethod action(Class<?> clazz, String methodName) {
+ return new GetMethod( clazz, methodName );
+ }
+
+ private GetMethod(Class<?> clazz, String methodName) {
+ this.clazz = clazz;
+ this.methodName = methodName;
+ }
+
+ public Method run() {
+ try {
+ return clazz.getMethod(methodName);
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
+ }
+}
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethodFromPropertyName.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethodFromPropertyName.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethodFromPropertyName.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,27 @@
+package org.hibernate.validation.util;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethodFromPropertyName implements PrivilegedAction<Method> {
+ private final Class<?> clazz;
+ private final String property;
+
+ public static GetMethodFromPropertyName action(Class<?> clazz, String property) {
+ return new GetMethodFromPropertyName( clazz, property );
+ }
+
+ private GetMethodFromPropertyName(Class<?> clazz, String property) {
+ this.clazz = clazz;
+ this.property = property;
+ }
+
+ public Method run() {
+ return ReflectionHelper.getMethod( clazz, property );
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethods.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethods.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/GetMethods.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,23 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Method;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethods implements PrivilegedAction<Method[]> {
+ private final Class<?> clazz;
+
+ public static GetMethods action(Class<?> clazz) {
+ return new GetMethods( clazz );
+ }
+
+ private GetMethods(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public Method[] run() {
+ return clazz.getMethods();
+ }
+}
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/NewInstance.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/NewInstance.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/NewInstance.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,36 @@
+package org.hibernate.validation.util;
+
+import java.security.PrivilegedAction;
+import javax.validation.ValidationException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class NewInstance<T> implements PrivilegedAction<T> {
+ private final Class<T> clazz;
+ private final String message;
+
+ public static <T> NewInstance<T> action(Class<T> clazz, String message) {
+ return new NewInstance<T>( clazz, message );
+ }
+
+ private NewInstance(Class<T> clazz, String message) {
+ this.clazz = clazz;
+ this.message = message;
+ }
+
+ public T run() {
+ try {
+ return clazz.newInstance();
+ }
+ catch ( InstantiationException e ) {
+ throw new ValidationException( "Unable to instanciate " + message + ": " + clazz, e );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException( "Unable to instanciate " + clazz, e );
+ }
+ catch ( RuntimeException e ) {
+ throw new ValidationException( "Unable to instanciate " + clazz, e );
+ }
+ }
+}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -52,7 +52,7 @@
//run client in priviledge block
@SuppressWarnings("unchecked")
- public static <T> T getAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
+ static <T> T getAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
try {
Method m = annotation.getClass().getMethod( parameterName );
Object o = m.invoke( annotation );
@@ -190,7 +190,8 @@
return value;
}
- public static void setAccessibility(Member member) {
+ //run client in priviledge block
+ static void setAccessibility(Member member) {
if ( !Modifier.isPublic( member.getModifiers() ) ) {
//Sun's ease of use, sigh...
( ( AccessibleObject ) member ).setAccessible( true );
@@ -356,57 +357,6 @@
}
/**
- * Checks whether the specified class contains a field matching the specified name.
- *
- * @param clazz The class to check.
- * @param fieldName The field name.
- *
- * @return Returns <code>true</code> if the cass contains a field for the specified name, <code>
- * false</code> otherwise.
- */
- public static boolean containsField(Class<?> clazz, String fieldName) {
- try {
- clazz.getDeclaredField( fieldName );
- return true;
- }
- catch ( NoSuchFieldException e ) {
- return false;
- }
- }
-
- /**
- * Returns the field with the specified name or <code>null</code> if it does not exist.
- *
- * @param clazz The class to check.
- * @param fieldName The field name.
- *
- * @return Returns the field with the specified name or <code>null</code> if it does not exist.
- */
- public static Field getField(Class<?> clazz, String fieldName) {
- try {
- Field field = clazz.getDeclaredField( fieldName );
- setAccessibility( field );
- return field;
- }
- catch ( NoSuchFieldException e ) {
- return null;
- }
- }
-
- /**
- * Checks whether the specified class contains a method matching the specified name.
- *
- * @param clazz The class to check.
- * @param methodName The method name.
- *
- * @return Returns <code>true</code> if the cass contains a property for the specified name, <code>
- * false</code> otherwise.
- */
- public static boolean containsMethod(Class<?> clazz, String methodName) {
- return getMethod( clazz, methodName ) != null;
- }
-
- /**
* Returns the method with the specified name or <code>null</code> if it does not exist.
*
* @param clazz The class to check.
@@ -414,7 +364,8 @@
*
* @return Returns the method with the specified name or <code>null</code> if it does not exist.
*/
- public static Method getMethod(Class<?> clazz, String methodName) {
+ //run client in priviledge block
+ static Method getMethod(Class<?> clazz, String methodName) {
try {
char string[] = methodName.toCharArray();
string[0] = Character.toUpperCase( string[0] );
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/SetAccessibility.java (from rev 17261, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/SetAccessibility.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/SetAccessibility.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -0,0 +1,26 @@
+package org.hibernate.validation.util;
+
+import java.lang.reflect.Member;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class SetAccessibility implements PrivilegedAction<Object> {
+ private final Member member;
+
+ public static SetAccessibility action(Member member) {
+ return new SetAccessibility( member );
+ }
+
+ private SetAccessibility(Member member) {
+ this.member = member;
+ }
+
+ public Object run() {
+ ReflectionHelper.setAccessibility( member );
+ return member;
+ }
+}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -24,7 +24,7 @@
import java.lang.reflect.Proxy;
import java.security.AccessController;
-import org.hibernate.validation.util.priviledgedactions.GetConstructor;
+import org.hibernate.validation.util.GetConstructor;
/**
@@ -64,6 +64,6 @@
else {
constructor = action.run();
}
- return constructor.newInstance( new Object[]{handler} );
+ return constructor.newInstance( handler );
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationProxy.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationProxy.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationProxy.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -25,7 +25,10 @@
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.security.AccessController;
+import org.hibernate.validation.util.GetDeclaredMethods;
+
/**
* A concrete implementation of <code>Annotation</code> that pretends it is a
* "real" source code annotation. It's also an <code>InvocationHandler</code>.
@@ -66,7 +69,15 @@
private Map<Method, Object> getAnnotationValues(AnnotationDescriptor descriptor) {
Map<Method, Object> result = new HashMap<Method, Object>();
int processedValuesFromDescriptor = 0;
- for ( Method m : annotationType.getDeclaredMethods() ) {
+ GetDeclaredMethods action = GetDeclaredMethods.action( annotationType );
+ final Method[] declaredMethods;
+ if ( System.getSecurityManager() != null ) {
+ declaredMethods = AccessController.doPrivileged( action );
+ }
+ else {
+ declaredMethods = action.run();
+ }
+ for ( Method m : declaredMethods ) {
if ( descriptor.containsElement( m.getName() ) ) {
result.put( m, descriptor.valueOf( m.getName() ) );
processedValuesFromDescriptor++;
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -1,27 +0,0 @@
-package org.hibernate.validation.util.priviledgedactions;
-
-import java.lang.reflect.Method;
-import java.security.PrivilegedAction;
-
-import org.hibernate.validation.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.containsMethod( clazz, property );
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -1,31 +0,0 @@
-package org.hibernate.validation.util.priviledgedactions;
-
-import java.lang.reflect.Method;
-import java.lang.annotation.Annotation;
-import java.security.PrivilegedAction;
-
-import org.hibernate.validation.util.ReflectionHelper;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetAnnotationParameter<T> implements PrivilegedAction<T> {
- private final Annotation annotation;
- private final String parameterName;
- private final Class<T> type;
-
-
- public static <T> GetAnnotationParameter<T> action(Annotation annotation, String parameterName, Class<T> type) {
- return new GetAnnotationParameter<T>( annotation, parameterName, type );
- }
-
- private GetAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
- this.annotation = annotation;
- this.parameterName = parameterName;
- this.type = type;
- }
-
- public T run() {
- return ReflectionHelper.getAnnotationParameter( annotation, parameterName, type );
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -1,31 +0,0 @@
-package org.hibernate.validation.util.priviledgedactions;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Constructor;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetConstructor<T> implements PrivilegedAction<Constructor<T>> {
- private final Class<T> clazz;
- private final Class<?>[] params;
-
- public static <T> GetConstructor<T> action(Class<T> clazz, Class<?>... params) {
- return new GetConstructor<T>( clazz, params );
- }
-
- private GetConstructor(Class<T> clazz, Class<?>... params) {
- this.clazz = clazz;
- this.params = params;
- }
-
- public Constructor<T> run() {
- try {
- return clazz.getConstructor(params);
- }
- catch ( NoSuchMethodException e ) {
- return null;
- }
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -1,30 +0,0 @@
-package org.hibernate.validation.util.priviledgedactions;
-
-import java.lang.reflect.Method;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetMethod implements PrivilegedAction<Method> {
- private final Class<?> clazz;
- private final String methodName;
-
- public static GetMethod action(Class<?> clazz, String methodName) {
- return new GetMethod( clazz, methodName );
- }
-
- private GetMethod(Class<?> clazz, String methodName) {
- this.clazz = clazz;
- this.methodName = methodName;
- }
-
- public Method run() {
- try {
- return clazz.getMethod(methodName);
- }
- catch ( NoSuchMethodException e ) {
- return null;
- }
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -1,27 +0,0 @@
-package org.hibernate.validation.util.priviledgedactions;
-
-import java.lang.reflect.Method;
-import java.security.PrivilegedAction;
-
-import org.hibernate.validation.util.ReflectionHelper;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetMethodFromPropertyName implements PrivilegedAction<Method> {
- private final Class<?> clazz;
- private final String property;
-
- public static GetMethodFromPropertyName action(Class<?> clazz, String property) {
- return new GetMethodFromPropertyName( clazz, property );
- }
-
- private GetMethodFromPropertyName(Class<?> clazz, String property) {
- this.clazz = clazz;
- this.property = property;
- }
-
- public Method run() {
- return ReflectionHelper.getMethod( clazz, property );
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -1,23 +0,0 @@
-package org.hibernate.validation.util.priviledgedactions;
-
-import java.security.PrivilegedAction;
-import java.lang.reflect.Method;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetMethods implements PrivilegedAction<Method[]> {
- private final Class<?> clazz;
-
- public static GetMethods action(Class<?> clazz) {
- return new GetMethods( clazz );
- }
-
- private GetMethods(Class<?> clazz) {
- this.clazz = clazz;
- }
-
- public Method[] run() {
- return clazz.getMethods();
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -1,37 +0,0 @@
-package org.hibernate.validation.util.priviledgedactions;
-
-import java.lang.reflect.Method;
-import java.security.PrivilegedAction;
-import javax.validation.ValidationException;
-
-/**
- * @author Emmanuel Bernard
- */
-public class NewInstance<T> implements PrivilegedAction<T> {
- private final Class<T> clazz;
- private final String message;
-
- public static <T> NewInstance<T> action(Class<T> clazz, String message) {
- return new NewInstance<T>( clazz, message );
- }
-
- private NewInstance(Class<T> clazz, String message) {
- this.clazz = clazz;
- this.message = message;
- }
-
- public T run() {
- try {
- return clazz.newInstance();
- }
- catch ( InstantiationException e ) {
- throw new ValidationException( "Unable to instanciate " + message + ": " + clazz, e );
- }
- catch ( IllegalAccessException e ) {
- throw new ValidationException( "Unable to instanciate " + clazz, e );
- }
- catch ( RuntimeException e ) {
- throw new ValidationException( "Unable to instanciate " + clazz, e );
- }
- }
-}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -38,7 +38,7 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
-import org.hibernate.validation.util.priviledgedactions.NewInstance;
+import org.hibernate.validation.util.NewInstance;
import org.hibernate.validation.xml.PropertyType;
import org.hibernate.validation.xml.ValidationConfigType;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -54,9 +54,11 @@
import org.hibernate.validation.metadata.AnnotationIgnores;
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
-import org.hibernate.validation.util.priviledgedactions.GetMethodFromPropertyName;
-import org.hibernate.validation.util.priviledgedactions.ContainsMethod;
-import org.hibernate.validation.util.priviledgedactions.GetMethod;
+import org.hibernate.validation.util.ContainsField;
+import org.hibernate.validation.util.GetMethodFromPropertyName;
+import org.hibernate.validation.util.ContainsMethod;
+import org.hibernate.validation.util.GetMethod;
+import org.hibernate.validation.util.GetDeclaredField;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
import org.hibernate.validation.xml.AnnotationType;
@@ -242,10 +244,25 @@
private void parseFieldLevelOverrides(List<FieldType> fields, Class<?> beanClass, String defaultPackage) {
for ( FieldType fieldType : fields ) {
String fieldName = fieldType.getName();
- if ( !ReflectionHelper.containsField( beanClass, fieldName ) ) {
+ final boolean containsField;
+ ContainsField containsAction = ContainsField.action( beanClass, fieldName );
+ if ( System.getSecurityManager() != null ) {
+ containsField = AccessController.doPrivileged( containsAction );
+ }
+ else {
+ containsField = containsAction.run();
+ }
+ if ( !containsField ) {
throw new ValidationException( beanClass.getName() + " does not contain the fieldType " + fieldName );
}
- Field field = ReflectionHelper.getField( beanClass, fieldName );
+ GetDeclaredField action = GetDeclaredField.action( beanClass, fieldName );
+ final Field field;
+ if ( System.getSecurityManager() != null ) {
+ field = AccessController.doPrivileged( action );
+ }
+ else {
+ field = action.run();
+ }
// ignore annotations
boolean ignoreFieldAnnotation = fieldType.isIgnoreAnnotations() == null ? false : fieldType.isIgnoreAnnotations();
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ConstraintHelperTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ConstraintHelperTest.java 2009-08-11 15:37:23 UTC (rev 17262)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ConstraintHelperTest.java 2009-08-11 18:00:25 UTC (rev 17263)
@@ -19,6 +19,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import java.lang.reflect.Member;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
@@ -29,6 +30,7 @@
import org.testng.annotations.Test;
import org.hibernate.validation.util.ReflectionHelper;
+import org.hibernate.validation.util.SetAccessibility;
/**
* @author Hardy Ferentschik
@@ -48,7 +50,7 @@
Field[] fields = engine.getClass().getDeclaredFields();
assertNotNull( fields );
assertTrue( fields.length == 1 );
- ReflectionHelper.setAccessibility( fields[0] );
+ setAccessibility( fields[0] );
Annotation annotation = fields[0].getAnnotation( Pattern.List.class );
assertNotNull( annotation );
@@ -62,11 +64,15 @@
fields = order.getClass().getDeclaredFields();
assertNotNull( fields );
assertTrue( fields.length == 1 );
- ReflectionHelper.setAccessibility( fields[0] );
+ setAccessibility( fields[0] );
annotation = fields[0].getAnnotation( NotNull.class );
assertNotNull( annotation );
multiValueConstraintAnnotations = constraintHelper.getMultiValueConstraints( annotation );
assertTrue( multiValueConstraintAnnotations.size() == 0, "There should be no constraint annotations" );
}
+
+ void setAccessibility(Member member) {
+ SetAccessibility.action( member ).run();
+ }
}
14 years, 8 months
Hibernate SVN: r17262 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-08-11 11:37:23 -0400 (Tue, 11 Aug 2009)
New Revision: 17262
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
Log:
EJB-447 : Implement JPA 2.0 criteria apis
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-08-11 01:01:18 UTC (rev 17261)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-08-11 15:37:23 UTC (rev 17262)
@@ -66,6 +66,7 @@
for ( ParameterExpression param : queryStructure.getParameters() ) {
registry.registerParameter( param );
}
+ // TODO : correlations. Can they contain parameters?
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-08-11 01:01:18 UTC (rev 17261)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-08-11 15:37:23 UTC (rev 17262)
@@ -21,7 +21,6 @@
*/
package org.hibernate.ejb.criteria;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.HashSet;
@@ -83,6 +82,12 @@
ParameterContainer.Helper.possibleParameter(subquery, registry);
}
+ // both group-by and having expressions can (though unlikely) contain parameters...
+ ParameterContainer.Helper.possibleParameter(having, registry);
+ for ( Expression<?> grouping : groupings ) {
+ ParameterContainer.Helper.possibleParameter(grouping, registry);
+ }
+
return parameters;
}
14 years, 8 months