Hibernate SVN: r19578 - entitymanager/tags.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-21 01:21:10 -0400 (Fri, 21 May 2010)
New Revision: 19578
Added:
entitymanager/tags/3.4.0.GA_CP02/
Log:
JBPAPP-4318 tag hibernate components for EAP 5.1
Copied: entitymanager/tags/3.4.0.GA_CP02 (from rev 19577, entitymanager/branches/v3_4_0_GA_CP)
14 years, 7 months
Hibernate SVN: r19577 - annotations/tags.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-21 01:16:55 -0400 (Fri, 21 May 2010)
New Revision: 19577
Added:
annotations/tags/3.4.0.GA_CP02/
Log:
JBPAPP-4318 tag hibernate components for EAP 5.1
Copied: annotations/tags/3.4.0.GA_CP02 (from rev 19576, annotations/branches/v3_4_0_GA_CP)
14 years, 7 months
Hibernate SVN: r19576 - core/tags.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-21 01:13:26 -0400 (Fri, 21 May 2010)
New Revision: 19576
Added:
core/tags/hibernate-3.3.2.GA_CP02/
Log:
JBPAPP-4318 tag hibernate components for EAP 5.1
Copied: core/tags/hibernate-3.3.2.GA_CP02 (from rev 19575, core/branches/Branch_3_3_2_GA_CP)
14 years, 7 months
Hibernate SVN: r19575 - core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-21 01:10:52 -0400 (Fri, 21 May 2010)
New Revision: 19575
Modified:
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LongInElementsTest.java
Log:
JBPAPP-3089 HHH-2166
Modified: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LongInElementsTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LongInElementsTest.java 2010-05-21 04:26:21 UTC (rev 19574)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/criteria/LongInElementsTest.java 2010-05-21 05:10:52 UTC (rev 19575)
@@ -47,7 +47,7 @@
*/
public class LongInElementsTest extends FunctionalTestCase {
- private static final int ELEMENTS_SIZE = 4000;
+ private static final int ELEMENTS_SIZE = 2000;
public LongInElementsTest( String string ) {
super( string );
14 years, 7 months
Hibernate SVN: r19574 - in core/trunk/testsuite/src/test/java/org/hibernate/test: hql and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-21 00:26:21 -0400 (Fri, 21 May 2010)
New Revision: 19574
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Child.java
core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Parent.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Log:
account for more failures on h2 (only 1 more!)
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Child.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Child.java 2010-05-20 22:13:26 UTC (rev 19573)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Child.java 2010-05-21 04:26:21 UTC (rev 19574)
@@ -9,7 +9,8 @@
private String bio;
private Parent parent;
private int bioLength;
- private double heightInches;
+ private int position;
+
Child() {}
public Child(String name) {
this.name = name;
@@ -44,12 +45,15 @@
public void setBio(String bio) {
this.bio = bio;
}
- public double getHeightInches() {
- return heightInches;
+
+ public int getPosition() {
+ return position;
}
- public void setHeightInches(double heightInches) {
- this.heightInches = heightInches;
- }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
+
public int hashCode() {
return name.hashCode();
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java 2010-05-20 22:13:26 UTC (rev 19573)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java 2010-05-21 04:26:21 UTC (rev 19574)
@@ -88,47 +88,37 @@
}
public void testCustomColumnReadAndWrite() {
- final double HEIGHT_INCHES = 49;
- final double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
-
Session s = openSession();
Transaction t = s.beginTransaction();
Child c = new Child( "Child One" );
- c.setHeightInches(HEIGHT_INCHES);
+ c.setPosition( 1 );
Parent p = new Parent( "Parent" );
p.getChildren().add( c );
c.setParent( p );
s.save( p );
s.flush();
- // Test value conversion during insert
- Double heightViaSql = (Double)s.createSQLQuery("select height_centimeters from parentchild c where c.name='Child One'")
- .uniqueResult();
- assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
-
- // Test projection
- Double heightViaHql = (Double)s.createQuery("select c.heightInches from Parent p join p.children c where p.name='Parent'")
- .uniqueResult();
- assertEquals(HEIGHT_INCHES, heightViaHql, 0.01d);
-
- // Test entity load via criteria
+ Integer sqlValue = (Integer) s.createSQLQuery("select child_position from parentchild c where c.name='Child One'")
+ .uniqueResult();
+ assertEquals( 0, sqlValue.intValue() );
+
+ Integer hqlValue = (Integer)s.createQuery("select c.position from Parent p join p.children c where p.name='Parent'")
+ .uniqueResult();
+ assertEquals( 1, hqlValue.intValue() );
+
p = (Parent)s.createCriteria(Parent.class).add(Restrictions.eq("name", "Parent")).uniqueResult();
c = (Child)p.getChildren().iterator().next();
- assertEquals(HEIGHT_INCHES, c.getHeightInches(), 0.01d);
-
- // Test predicate and entity load via HQL
- p = (Parent)s.createQuery("from Parent p join p.children c where c.heightInches between ? and ?")
- .setDouble(0, HEIGHT_INCHES - 0.01d)
- .setDouble(1, HEIGHT_INCHES + 0.01d)
- .uniqueResult();
+ assertEquals( 1, c.getPosition() );
+
+ p = (Parent)s.createQuery("from Parent p join p.children c where c.position = 1").uniqueResult();
c = (Child)p.getChildren().iterator().next();
- assertEquals(HEIGHT_INCHES, c.getHeightInches(), 0.01d);
-
- // Test update
- c.setHeightInches(1);
+ assertEquals( 1, c.getPosition() );
+
+ c.setPosition( 2 );
s.flush();
- heightViaSql = (Double)s.createSQLQuery("select height_centimeters from parentchild c where c.name='Child One'").uniqueResult();
- assertEquals(2.54d, heightViaSql, 0.01d);
+ sqlValue = (Integer) s.createSQLQuery("select child_position from parentchild c where c.name='Child One'")
+ .uniqueResult();
+ assertEquals( 1, sqlValue.intValue() );
s.delete( p );
t.commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Parent.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Parent.hbm.xml 2010-05-20 22:13:26 UTC (rev 19573)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/Parent.hbm.xml 2010-05-21 04:26:21 UTC (rev 19574)
@@ -28,11 +28,11 @@
<property name="name" not-null="true"/>
<property name="bio"/>
<property name="bioLength" formula="length(bio)"/>
- <property name="heightInches">
- <column name="height_centimeters"
- not-null="true"
- read="height_centimeters / 2.54"
- write="? * 2.54"/>
+ <property name="position">
+ <column name="child_position"
+ not-null="true"
+ read="child_position + 1"
+ write="? - 1"/>
</property>
</composite-element>
</set>
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-05-20 22:13:26 UTC (rev 19573)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-05-21 04:26:21 UTC (rev 19574)
@@ -26,6 +26,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect;
+import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.MySQLDialect;
@@ -1370,9 +1371,11 @@
Object bodyWeight = s.createQuery("select cast(bodyWeight as integer) from Animal").uniqueResult();
assertTrue( Integer.class.isInstance( bodyWeight ) );
assertEquals( 12, bodyWeight );
+
bodyWeight = s.createQuery("select cast(bodyWeight as big_decimal) from Animal").uniqueResult();
assertTrue( BigDecimal.class.isInstance( bodyWeight ) );
- assertEquals( BigDecimal.valueOf( a.getBodyWeight() ), bodyWeight );
+ assertEquals( a.getBodyWeight(), ( (BigDecimal) bodyWeight ).floatValue() );
+
Object literal = s.createQuery("select cast(10000000 as big_integer) from Animal").uniqueResult();
assertTrue( BigInteger.class.isInstance( literal ) );
assertEquals( BigInteger.valueOf( 10000000 ), literal );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2010-05-20 22:13:26 UTC (rev 19573)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2010-05-21 04:26:21 UTC (rev 19574)
@@ -15,6 +15,7 @@
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.dialect.H2Dialect;
import org.hibernate.util.ArrayHelper;
import org.hibernate.test.sql.hand.Organization;
import org.hibernate.test.sql.hand.Person;
@@ -112,6 +113,11 @@
// there is actually an exception thrown, but it is the database
// throwing a sql exception because the SQL gets passed
// "un-processed"...
+ //
+ // Oddly, H2 accepts this query.
+ if ( H2Dialect.class.isInstance( getDialect() ) ) {
+ return;
+ }
Session s = openSession();
s.beginTransaction();
try {
14 years, 7 months
Hibernate SVN: r19573 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validator/engine and 8 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-20 18:13:26 -0400 (Thu, 20 May 2010)
New Revision: 19573
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ConstructorInstance.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
Log:
HV-274 Centralized the PriviligedAction use into ReflectionHelper
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -19,12 +19,11 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
-import java.security.AccessController;
+import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import javax.validation.ValidationException;
-import org.hibernate.validator.util.privilegedactions.NewInstance;
import org.hibernate.validator.util.ReflectionHelper;
/**
@@ -78,7 +77,15 @@
}
public <A extends Annotation, T extends ConstraintDefinition<A>> T constraint(Class<T> definition) {
- T constraintDefinition = createConstraintDefinition( definition );
+
+ final Constructor<T> constructor = ReflectionHelper.getConstructor(
+ definition, Class.class, String.class, ElementType.class, ConstraintMapping.class
+ );
+
+ final T constraintDefinition = ReflectionHelper.newConstructorInstance(
+ constructor, beanType, property, elementType, mapping
+ );
+
mapping.addConstraintConfig( constraintDefinition );
return constraintDefinition;
}
@@ -115,19 +122,6 @@
return property;
}
- private <A extends Annotation, T extends ConstraintDefinition<A>> T createConstraintDefinition(Class<T> definition) {
- T constraintDefinition;
- NewInstance<T> newInstance = NewInstance.action( definition, "", beanType, property, elementType, mapping );
-
- if ( System.getSecurityManager() != null ) {
- constraintDefinition = AccessController.doPrivileged( newInstance );
- }
- else {
- constraintDefinition = newInstance.run();
- }
- return constraintDefinition;
- }
-
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -19,9 +19,9 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
-import java.security.AccessController;
+import java.lang.reflect.Constructor;
-import org.hibernate.validator.util.privilegedactions.NewInstance;
+import org.hibernate.validator.util.ReflectionHelper;
import static java.lang.annotation.ElementType.TYPE;
@@ -46,7 +46,13 @@
}
public <A extends Annotation, T extends ConstraintDefinition<A>> T constraint(Class<T> definition) {
- T constraintDefinition = createConstraintDefinition( definition );
+ final Constructor<T> constructor = ReflectionHelper.getConstructor(
+ definition, Class.class, String.class, ElementType.class, ConstraintMapping.class
+ );
+
+ final T constraintDefinition = ReflectionHelper.newConstructorInstance(
+ constructor, beanClass, property, elementType, mapping
+ );
mapping.addConstraintConfig( constraintDefinition );
return constraintDefinition;
}
@@ -58,19 +64,6 @@
public ConstraintsForType valid(String property, ElementType type) {
return null;
}
-
- private <A extends Annotation, T extends ConstraintDefinition<A>> T createConstraintDefinition(Class<T> definition) {
- T constraintDefinition;
- NewInstance<T> newInstance = NewInstance.action( definition, "", beanClass, property, elementType, mapping );
-
- if ( System.getSecurityManager() != null ) {
- constraintDefinition = AccessController.doPrivileged( newInstance );
- }
- else {
- constraintDefinition = newInstance.run();
- }
- return constraintDefinition;
- }
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -17,11 +17,10 @@
*/
package org.hibernate.validator.engine;
-import java.security.AccessController;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
-import org.hibernate.validator.util.privilegedactions.NewInstance;
+import org.hibernate.validator.util.ReflectionHelper;
/**
* Default <code>ConstraintValidatorFactory</code> using a no-arg constructor.
@@ -32,12 +31,6 @@
public class ConstraintValidatorFactoryImpl implements ConstraintValidatorFactory {
public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
- NewInstance<T> newInstance = NewInstance.action( key, "" );
- if ( System.getSecurityManager() != null ) {
- return AccessController.doPrivileged( newInstance );
- }
- else {
- return newInstance.run();
- }
+ return ReflectionHelper.newInstance( key, "" );
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -18,7 +18,6 @@
package org.hibernate.validator.engine.resolver;
import java.lang.annotation.ElementType;
-import java.security.AccessController;
import javax.validation.Path;
import javax.validation.TraversableResolver;
import javax.validation.ValidationException;
@@ -26,8 +25,7 @@
import org.slf4j.Logger;
import org.hibernate.validator.util.LoggerFactory;
-import org.hibernate.validator.util.privilegedactions.NewInstance;
-import org.hibernate.validator.util.privilegedactions.LoadClass;
+import org.hibernate.validator.util.ReflectionHelper;
/**
* A JPA 2 aware <code>TraversableResolver</code>.
@@ -64,7 +62,7 @@
*/
private void detectJPA() {
try {
- loadClass( PERSISTENCE_UTIL_CLASS_NAME, this.getClass() );
+ ReflectionHelper.loadClass( PERSISTENCE_UTIL_CLASS_NAME, this.getClass() );
log.debug( "Found {} on classpath.", PERSISTENCE_UTIL_CLASS_NAME );
}
catch ( ValidationException e ) {
@@ -76,16 +74,10 @@
}
try {
- @SuppressWarnings( "unchecked" )
- Class<? extends TraversableResolver> jpaAwareResolverClass = (Class<? extends TraversableResolver>)
- loadClass(JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, this.getClass() );
- NewInstance<? extends TraversableResolver> newInstance = NewInstance.action( jpaAwareResolverClass, "" );
- if ( System.getSecurityManager() != null ) {
- jpaTraversableResolver = AccessController.doPrivileged( newInstance );
- }
- else {
- jpaTraversableResolver = newInstance.run();
- }
+ @SuppressWarnings("unchecked")
+ Class<? extends TraversableResolver> jpaAwareResolverClass = ( Class<? extends TraversableResolver> )
+ ReflectionHelper.loadClass( JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, this.getClass() );
+ jpaTraversableResolver = ReflectionHelper.newInstance( jpaAwareResolverClass, "" );
log.info(
"Instantiated an instance of {}.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
@@ -98,16 +90,6 @@
}
}
- 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
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -24,7 +24,6 @@
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.security.AccessController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -42,11 +41,8 @@
import org.slf4j.Logger;
-import org.hibernate.validator.util.privilegedactions.GetDeclaredFields;
-import org.hibernate.validator.util.privilegedactions.GetDeclaredMethods;
import org.hibernate.validator.util.LoggerFactory;
import org.hibernate.validator.util.ReflectionHelper;
-import org.hibernate.validator.util.privilegedactions.SetAccessibility;
/**
@@ -128,7 +124,7 @@
}
for ( Map.Entry<Class<?>, List<MetaConstraint<T, ?>>> entry : xmlConfiguredConstraints.entrySet() ) {
Class<?> clazz = entry.getKey();
- for(MetaConstraint<T,?> constraint : entry.getValue()) {
+ for ( MetaConstraint<T, ?> constraint : entry.getValue() ) {
addMetaConstraint( clazz, constraint );
}
}
@@ -237,7 +233,7 @@
}
private void addCascadedMember(Member member) {
- setAccessibility( member );
+ ReflectionHelper.setAccessibility( member );
cascadedMembers.add( member );
addPropertyDescriptorForMember( member, true );
}
@@ -282,14 +278,7 @@
}
private void initFieldConstraints(Class<?> clazz, AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache) {
- GetDeclaredFields action = GetDeclaredFields.action( clazz );
- final Field[] fields;
- if ( System.getSecurityManager() != null ) {
- fields = AccessController.doPrivileged( action );
- }
- else {
- fields = action.run();
- }
+ final Field[] fields = ReflectionHelper.getFields( clazz );
for ( Field field : fields ) {
addToPropertyNameList( field );
@@ -322,7 +311,7 @@
}
for ( ConstraintDescriptorImpl<?> constraintDescription : fieldMetaData ) {
- setAccessibility( field );
+ ReflectionHelper.setAccessibility( field );
MetaConstraint<T, ?> metaConstraint = createMetaConstraint( field, constraintDescription );
addMetaConstraint( clazz, metaConstraint );
}
@@ -340,26 +329,8 @@
}
}
- 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, BeanMetaDataCache beanMetaDataCache) {
- GetDeclaredMethods action = GetDeclaredMethods.action( clazz );
- final Method[] declaredMethods;
- if ( System.getSecurityManager() != null ) {
- declaredMethods = AccessController.doPrivileged( action );
- }
- else {
- declaredMethods = action.run();
- }
-
+ final Method[] declaredMethods = ReflectionHelper.getMethods( clazz );
for ( Method method : declaredMethods ) {
addToPropertyNameList( method );
@@ -392,7 +363,7 @@
}
for ( ConstraintDescriptorImpl<?> constraintDescription : methodMetaData ) {
- setAccessibility( method );
+ ReflectionHelper.setAccessibility( method );
MetaConstraint<T, ?> metaConstraint = createMetaConstraint( method, constraintDescription );
addMetaConstraint( clazz, metaConstraint );
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -43,11 +43,8 @@
import org.slf4j.Logger;
-import org.hibernate.validator.util.privilegedactions.GetAnnotationParameter;
-import org.hibernate.validator.util.privilegedactions.GetDeclaredMethods;
-import org.hibernate.validator.util.privilegedactions.GetMethod;
-import org.hibernate.validator.util.privilegedactions.GetMethods;
import org.hibernate.validator.util.LoggerFactory;
+import org.hibernate.validator.util.ReflectionHelper;
import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
@@ -147,15 +144,7 @@
Class<Payload>[] payloadFromAnnotation;
try {
//TODO be extra safe and make sure this is an array of Payload
- GetAnnotationParameter<Class[]> action = GetAnnotationParameter.action(
- annotation, PAYLOAD, Class[].class
- );
- if ( System.getSecurityManager() != null ) {
- payloadFromAnnotation = AccessController.doPrivileged( action );
- }
- else {
- payloadFromAnnotation = action.run();
- }
+ payloadFromAnnotation = ReflectionHelper.getAnnotationParameter( annotation, PAYLOAD, Class[].class );
}
catch ( ValidationException e ) {
//ignore people not defining payloads
@@ -169,14 +158,9 @@
private Set<Class<?>> buildGroupSet(Class<?> implicitGroup) {
Set<Class<?>> groupSet = new HashSet<Class<?>>();
- final Class<?>[] groupsFromAnnotation;
- GetAnnotationParameter<Class[]> action = GetAnnotationParameter.action( annotation, GROUPS, Class[].class );
- if ( System.getSecurityManager() != null ) {
- groupsFromAnnotation = AccessController.doPrivileged( action );
- }
- else {
- groupsFromAnnotation = action.run();
- }
+ final Class<?>[] groupsFromAnnotation = ReflectionHelper.getAnnotationParameter(
+ annotation, GROUPS, Class[].class
+ );
if ( groupsFromAnnotation.length == 0 ) {
groupSet.add( Default.class );
}
@@ -277,20 +261,13 @@
sb.append( ", elementType=" ).append( elementType );
sb.append( ", definedOn=" ).append( definedOn );
sb.append( ", groups=" ).append( groups );
- sb.append( ", attributes=" ).append( attributes );
+ sb.append( ", attributes=" ).append( attributes );
sb.append( '}' );
return sb.toString();
}
private Map<String, Object> buildAnnotationParameterMap(Annotation annotation) {
- GetDeclaredMethods action = GetDeclaredMethods.action( annotation.annotationType() );
- final Method[] declaredMethods;
- if ( System.getSecurityManager() != null ) {
- declaredMethods = AccessController.doPrivileged( action );
- }
- else {
- declaredMethods = action.run();
- }
+ final Method[] declaredMethods = ReflectionHelper.getMethods( annotation.annotationType() );
Map<String, Object> parameters = new HashMap<String, Object>( declaredMethods.length );
for ( Method m : declaredMethods ) {
try {
@@ -323,15 +300,7 @@
private Map<ClassIndexWrapper, Map<String, Object>> parseOverrideParameters() {
Map<ClassIndexWrapper, Map<String, Object>> overrideParameters = new HashMap<ClassIndexWrapper, Map<String, Object>>();
- final Method[] methods;
- final GetMethods getMethods = GetMethods.action( annotation.annotationType() );
- if ( System.getSecurityManager() != null ) {
- methods = AccessController.doPrivileged( getMethods );
- }
- else {
- methods = getMethods.run();
- }
-
+ final Method[] methods = ReflectionHelper.getMethods( annotation.annotationType() );
for ( Method m : methods ) {
if ( m.getAnnotation( OverridesAttribute.class ) != null ) {
addOverrideAttributes(
@@ -368,14 +337,7 @@
}
private void ensureAttributeIsOverridable(Method m, OverridesAttribute overridesAttribute) {
- final GetMethod getMethod = GetMethod.action( overridesAttribute.constraint(), overridesAttribute.name() );
- final Method method;
- if ( System.getSecurityManager() != null ) {
- method = AccessController.doPrivileged( getMethod );
- }
- else {
- method = getMethod.run();
- }
+ final Method method = ReflectionHelper.getMethod( overridesAttribute.constraint(), overridesAttribute.name() );
if ( method == null ) {
throw new ConstraintDefinitionException(
"Overridden constraint does not define an attribute with name " + overridesAttribute.name()
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
-import java.security.AccessController;
import javax.validation.Constraint;
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintValidator;
@@ -72,9 +71,7 @@
import org.hibernate.validator.constraints.impl.SizeValidatorForCollection;
import org.hibernate.validator.constraints.impl.SizeValidatorForMap;
import org.hibernate.validator.constraints.impl.SizeValidatorForString;
-import org.hibernate.validator.util.privilegedactions.GetMethods;
-import org.hibernate.validator.util.privilegedactions.GetMethod;
-import org.hibernate.validator.util.privilegedactions.GetAnnotationParameter;
+import org.hibernate.validator.util.ReflectionHelper;
/**
* Keeps track of builtin constraints and their validator implementations, as well as already resolved validator definitions.
@@ -196,15 +193,8 @@
public boolean isMultiValueConstraint(Annotation annotation) {
boolean isMultiValueConstraint = false;
try {
- final GetMethod getMethod = GetMethod.action( annotation.getClass(), "value" );
- final Method method;
- if ( System.getSecurityManager() != null ) {
- method = AccessController.doPrivileged( getMethod );
- }
- else {
- method = getMethod.run();
- }
- if (method != null) {
+ final Method method = ReflectionHelper.getMethod( annotation.getClass(), "value" );
+ if ( method != null ) {
Class returnType = method.getReturnType();
if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
Annotation[] annotations = ( Annotation[] ) method.invoke( annotation );
@@ -241,15 +231,8 @@
public <A extends Annotation> List<Annotation> getMultiValueConstraints(A annotation) {
List<Annotation> annotationList = new ArrayList<Annotation>();
try {
- final GetMethod getMethod = GetMethod.action( annotation.getClass(), "value" );
- final Method method;
- if ( System.getSecurityManager() != null ) {
- method = AccessController.doPrivileged( getMethod );
- }
- else {
- method = getMethod.run();
- }
- if (method != null) {
+ final Method method = ReflectionHelper.getMethod( annotation.getClass(), "value" );
+ if ( method != null ) {
Class returnType = method.getReturnType();
if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
Annotation[] annotations = ( Annotation[] ) method.invoke( annotation );
@@ -302,14 +285,7 @@
}
private void assertNoParameterStartsWithValid(Annotation annotation) {
- final Method[] methods;
- final GetMethods getMethods = GetMethods.action( annotation.annotationType() );
- if ( System.getSecurityManager() != null ) {
- methods = AccessController.doPrivileged( getMethods );
- }
- else {
- methods = getMethods.run();
- }
+ final Method[] methods = ReflectionHelper.getMethods( annotation.annotationType() );
for ( Method m : methods ) {
if ( m.getName().startsWith( "valid" ) ) {
String msg = "Parameters starting with 'valid' are not allowed in a constraint.";
@@ -320,17 +296,10 @@
private void assertPayloadParameterExists(Annotation annotation) {
try {
- final GetMethod getMethod = GetMethod.action( annotation.annotationType(), "payload" );
- final Method method;
- if ( System.getSecurityManager() != null ) {
- method = AccessController.doPrivileged( getMethod );
- }
- else {
- method = getMethod.run();
- }
- if (method == null) {
+ final Method method = ReflectionHelper.getMethod( annotation.annotationType(), "payload" );
+ if ( method == null ) {
String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
- "not contain a payload parameter.";
+ "not contain a payload parameter.";
throw new ConstraintDefinitionException( msg );
}
Class<?>[] defaultPayload = ( Class<?>[] ) method.getDefaultValue();
@@ -350,17 +319,10 @@
private void assertGroupsParameterExists(Annotation annotation) {
try {
- final GetMethod getMethod = GetMethod.action( annotation.annotationType(), "groups" );
- final Method method;
- if ( System.getSecurityManager() != null ) {
- method = AccessController.doPrivileged( getMethod );
- }
- else {
- method = getMethod.run();
- }
- if (method == null) {
+ final Method method = ReflectionHelper.getMethod( annotation.annotationType(), "groups" );
+ if ( method == null ) {
String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
- "not contain a groups parameter.";
+ "not contain a groups parameter.";
throw new ConstraintDefinitionException( msg );
}
Class<?>[] defaultGroups = ( Class<?>[] ) method.getDefaultValue();
@@ -380,13 +342,7 @@
private void assertMessageParameterExists(Annotation annotation) {
try {
- GetAnnotationParameter<?> action = GetAnnotationParameter.action( annotation, "message", String.class );
- if (System.getSecurityManager() != null) {
- AccessController.doPrivileged( action );
- }
- else {
- action.run();
- }
+ ReflectionHelper.getAnnotationParameter( annotation, "message", String.class );
}
catch ( Exception e ) {
String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -17,15 +17,14 @@
*/
package org.hibernate.validator.resourceloading;
-import java.security.AccessController;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.slf4j.Logger;
-import org.hibernate.validator.util.privilegedactions.GetClassLoader;
import org.hibernate.validator.util.LoggerFactory;
+import org.hibernate.validator.util.ReflectionHelper;
/**
* A resource bundle locator, that loads resource bundles by simply
@@ -53,11 +52,7 @@
*/
public ResourceBundle getResourceBundle(Locale locale) {
ResourceBundle rb = null;
- boolean isSecured = System.getSecurityManager() != null;
- GetClassLoader action = GetClassLoader.fromContext();
- ClassLoader classLoader = isSecured ? AccessController
- .doPrivileged( action ) : action.run();
-
+ ClassLoader classLoader = ReflectionHelper.getClassLoaderFromContext();
if ( classLoader != null ) {
rb = loadBundle(
classLoader, locale, bundleName
@@ -65,10 +60,7 @@
);
}
if ( rb == null ) {
- action = GetClassLoader
- .fromClass( PlatformResourceBundleLocator.class );
- classLoader = isSecured ? AccessController.doPrivileged( action )
- : action.run();
+ classLoader = ReflectionHelper.getClassLoaderFromClass( PlatformResourceBundleLocator.class );
rb = loadBundle(
classLoader, locale, bundleName
+ " not found by validator classloader"
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -20,12 +20,11 @@
import java.beans.Introspector;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
-import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
@@ -40,11 +39,22 @@
import com.googlecode.jtype.TypeUtils;
+import org.hibernate.validator.util.privilegedactions.ConstructorInstance;
+import org.hibernate.validator.util.privilegedactions.GetAnnotationParameter;
+import org.hibernate.validator.util.privilegedactions.GetClassLoader;
+import org.hibernate.validator.util.privilegedactions.GetConstructor;
import org.hibernate.validator.util.privilegedactions.GetDeclaredField;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredFields;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredMethods;
import org.hibernate.validator.util.privilegedactions.GetMethod;
+import org.hibernate.validator.util.privilegedactions.GetMethodFromPropertyName;
+import org.hibernate.validator.util.privilegedactions.LoadClass;
+import org.hibernate.validator.util.privilegedactions.NewInstance;
+import org.hibernate.validator.util.privilegedactions.SetAccessibility;
/**
- * Some reflection utility methods.
+ * Some reflection utility methods. Where necessary calls will be performed as {@code PrivilegedAction} which is necessary
+ * for situations where a security manager is in place.
*
* @author Hardy Ferentschik
*/
@@ -56,34 +66,89 @@
private ReflectionHelper() {
}
- @SuppressWarnings("unchecked")
- public static <T> T getAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
- try {
- Method m = annotation.getClass().getMethod( parameterName );
- m.setAccessible( true );
- Object o = m.invoke( annotation );
- if ( o.getClass().getName().equals( type.getName() ) ) {
- return ( T ) o;
- }
- else {
- String msg = "Wrong parameter type. Expected: " + type.getName() + " Actual: " + o.getClass().getName();
- throw new ValidationException( msg );
- }
+ public static ClassLoader getClassLoaderFromContext() {
+ ClassLoader loader;
+ GetClassLoader action = GetClassLoader.fromContext();
+ if ( System.getSecurityManager() != null ) {
+ loader = AccessController.doPrivileged( action );
}
- catch ( NoSuchMethodException e ) {
- String msg = "The specified annotation defines no parameter '" + parameterName + "'.";
- throw new ValidationException( msg, e );
+ else {
+ loader = action.run();
}
- catch ( IllegalAccessException e ) {
- String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
- throw new ValidationException( msg, e );
+ return loader;
+ }
+
+ public static ClassLoader getClassLoaderFromClass(Class<?> clazz) {
+ ClassLoader loader;
+ GetClassLoader action = GetClassLoader.fromClass( clazz );
+ if ( System.getSecurityManager() != null ) {
+ loader = AccessController.doPrivileged( action );
}
- catch ( InvocationTargetException e ) {
- String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
- throw new ValidationException( msg, e );
+ else {
+ loader = action.run();
}
+ return loader;
}
+ public static 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 static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... params) {
+ Constructor<T> constructor;
+ GetConstructor<T> action = GetConstructor.action( clazz, params );
+ if ( System.getSecurityManager() != null ) {
+ constructor = AccessController.doPrivileged( action );
+ }
+ else {
+ constructor = action.run();
+ }
+ return constructor;
+ }
+
+ public static <T> T newInstance(Class<T> clazz, String message) {
+ T instance;
+ NewInstance<T> newInstance = NewInstance.action( clazz, message );
+ if ( System.getSecurityManager() != null ) {
+ instance = AccessController.doPrivileged( newInstance );
+ }
+ else {
+ instance = newInstance.run();
+ }
+ return instance;
+ }
+
+ public static <T> T newConstructorInstance(Constructor<T> constructor, Object... initArgs) {
+ T instance;
+ ConstructorInstance<T> newInstance = ConstructorInstance.action( constructor, initArgs );
+ if ( System.getSecurityManager() != null ) {
+ instance = AccessController.doPrivileged( newInstance );
+ }
+ else {
+ instance = newInstance.run();
+ }
+ return instance;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T getAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
+ T result;
+ GetAnnotationParameter<T> action = GetAnnotationParameter.action( annotation, parameterName, type );
+ if ( System.getSecurityManager() != null ) {
+ result = AccessController.doPrivileged( action );
+ }
+ else {
+ result = action.run();
+ }
+ return result;
+ }
+
/**
* Process bean properties getter by applying the JavaBean naming conventions.
*
@@ -187,7 +252,6 @@
* @return Returns the type of the field of return type of a method.
*/
public static Class<?> getType(Member member) {
-
Class<?> type = null;
if ( member instanceof Field ) {
type = ( ( Field ) member ).getType();
@@ -252,15 +316,13 @@
}
public static void setAccessibility(Member member) {
- // HV-257
- // Also set accessibility in case of public abstract members. If you proxy an interface using java.lang.reflect.Proxy
- // per default you will get a IllegalAccessException since you are not allowed to access public abstract methods.
- // Seems odd. One could argue that the proxy 'is' the implementation for the interface method and hence they
- // should be accessible. Maybe this is a JVM bug !?
- if ( !Modifier.isPublic( member.getModifiers() )
- || ( Modifier.isPublic( member.getModifiers() ) && Modifier.isAbstract( member.getModifiers() ) ) ) {
- ( ( AccessibleObject ) member ).setAccessible( true );
+ SetAccessibility action = SetAccessibility.action( member );
+ if ( System.getSecurityManager() != null ) {
+ AccessController.doPrivileged( action );
}
+ else {
+ action.run();
+ }
}
/**
@@ -404,33 +466,143 @@
return map.get( key );
}
+
/**
- * Returns the method with the specified name or <code>null</code> if it does not exist.
+ * Returns the field with the specified name or <code>null</code> if it does not exist.
*
* @param clazz The class to check.
- * @param methodName The method name.
+ * @param fieldName The field name.
*
- * @return Returns the method with the specified name or <code>null</code> if it does not exist.
+ * @return Returns the field with the specified name or <code>null</code> if it does not exist.
*/
- //run client in privileged block
+ public static Field getField(Class<?> clazz, String fieldName) {
+ GetDeclaredField action = GetDeclaredField.action( clazz, fieldName );
+ final Field field;
+ if ( System.getSecurityManager() != null ) {
+ field = AccessController.doPrivileged( action );
+ }
+ else {
+ field = action.run();
+ }
+ return field;
+ }
+
+ /**
+ * Checks whether the specified class contains a field with the given name.
+ *
+ * @param clazz The class to check.
+ * @param fieldName The field name.
+ *
+ * @return Returns {@code true} if the field exists, {@code false} otherwise.
+ */
+ public static boolean containsField(Class<?> clazz, String fieldName) {
+ return getField( clazz, fieldName ) != null;
+ }
+
+ /**
+ * Returns the fields of the specified class.
+ *
+ * @param clazz The class for which to retrieve the fields.
+ *
+ * @return Returns the fields for this class.
+ */
+ public static Field[] getFields(Class<?> clazz) {
+ GetDeclaredFields action = GetDeclaredFields.action( clazz );
+ final Field[] fields;
+ if ( System.getSecurityManager() != null ) {
+ fields = AccessController.doPrivileged( action );
+ }
+ else {
+ fields = action.run();
+ }
+ return fields;
+ }
+
+ /**
+ * Returns the method with the specified property name or {@code null} if it does not exist. This method will
+ * prepend 'is' and 'get' to the property name and capitalize the first letter.
+ *
+ * @param clazz The class to check.
+ * @param methodName The property name.
+ *
+ * @return Returns the method with the specified property or {@code null} if it does not exist.
+ */
+ public static Method getMethodFromPropertyName(Class<?> clazz, String methodName) {
+ Method method;
+ GetMethodFromPropertyName action = GetMethodFromPropertyName.action( clazz, methodName );
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( action );
+ }
+ else {
+ method = action.run();
+ }
+ return method;
+ }
+
+ /**
+ * Checks whether the specified class contains a method for the specified property.
+ *
+ * @param clazz The class to check.
+ * @param property The property name.
+ *
+ * @return Returns {@code true} if the method exists, {@code false} otherwise.
+ */
+ public static boolean containsMethodWithPropertyName(Class<?> clazz, String property) {
+ return getMethodFromPropertyName( clazz, property ) != null;
+ }
+
+ /**
+ * Returns the method with the specified name or {@code null} if it does not exist.
+ *
+ * @param clazz The class to check.
+ * @param methodName The property name.
+ *
+ * @return Returns the method with the specified property or {@code null}if it does not exist.
+ */
public static Method getMethod(Class<?> clazz, String methodName) {
- try {
- char string[] = methodName.toCharArray();
- string[0] = Character.toUpperCase( string[0] );
- methodName = new String( string );
- try {
- return clazz.getMethod( "get" + methodName );
- }
- catch ( NoSuchMethodException e ) {
- return clazz.getMethod( "is" + methodName );
- }
+ Method method;
+ GetMethod action = GetMethod.action( clazz, methodName );
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( action );
}
- catch ( NoSuchMethodException e ) {
- return null;
+ else {
+ method = action.run();
}
+ return method;
}
/**
+ * Returns the methods of the specified class.
+ *
+ * @param clazz The class for which to retrieve the methods.
+ *
+ * @return Returns the methods for this class.
+ */
+ public static Method[] getMethods(Class<?> clazz) {
+ GetDeclaredMethods action = GetDeclaredMethods.action( clazz );
+ final Method[] methods;
+ if ( System.getSecurityManager() != null ) {
+ methods = AccessController.doPrivileged( action );
+ }
+ else {
+ methods = action.run();
+ }
+ return methods;
+ }
+
+ /**
+ * Checks whether the specified class contains a method with the given name.
+ *
+ * @param clazz The class to check.
+ * @param methodName The method name.
+ *
+ * @return Returns {@code true} if the method exists, {@code false} otherwise.
+ */
+ public static boolean containsMethod(Class<?> clazz, String methodName) {
+ return getMethodFromPropertyName( clazz, methodName ) != null;
+ }
+
+ /**
* Returns the autoboxed type of a primitive type.
*
* @param primitiveType the primitive type
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -22,36 +22,31 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
-import java.security.AccessController;
-import org.hibernate.validator.util.privilegedactions.GetConstructor;
-import org.hibernate.validator.util.privilegedactions.GetClassLoader;
+import org.hibernate.validator.util.ReflectionHelper;
-
/**
* Creates live annotations (actually <code>AnnotationProxies</code>) from <code>AnnotationDescriptors</code>.
*
* @author Paolo Perrotta
* @author Davide Marchignoli
+ * @author Hardy Ferentschik
* @see AnnotationProxy
*/
public class AnnotationFactory {
@SuppressWarnings("unchecked")
public static <T extends Annotation> T create(AnnotationDescriptor<T> descriptor) {
- 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() );
+ ClassLoader classLoader = ReflectionHelper.getClassLoaderFromContext();
+ Class<T> proxyClass = ( Class<T> ) Proxy.getProxyClass( classLoader, descriptor.type() );
InvocationHandler handler = new AnnotationProxy( descriptor );
try {
return getProxyInstance( proxyClass, handler );
}
- catch (RuntimeException e) {
+ catch ( RuntimeException e ) {
throw e;
}
- catch (Exception e) {
+ catch ( Exception e ) {
throw new RuntimeException( e );
}
}
@@ -59,14 +54,7 @@
private static <T extends Annotation> T getProxyInstance(Class<T> proxyClass, InvocationHandler handler) throws
SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
IllegalAccessException, InvocationTargetException {
- GetConstructor<T> action = GetConstructor.action( proxyClass, InvocationHandler.class );
- final Constructor<T> constructor;
- if ( System.getSecurityManager() != null ) {
- constructor = AccessController.doPrivileged( action );
- }
- else {
- constructor = action.run();
- }
- return constructor.newInstance( handler );
+ final Constructor<T> constructor = ReflectionHelper.getConstructor( proxyClass, InvocationHandler.class );
+ return ReflectionHelper.newConstructorInstance( constructor, handler );
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -21,14 +21,14 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
-import java.security.AccessController;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
-import org.hibernate.validator.util.privilegedactions.GetDeclaredMethods;
+import org.hibernate.validator.util.ReflectionHelper;
+
/**
* A concrete implementation of <code>Annotation</code> that pretends it is a
* "real" source code annotation. It's also an <code>InvocationHandler</code>.
@@ -68,14 +68,7 @@
private Map<String, Object> getAnnotationValues(AnnotationDescriptor descriptor) {
Map<String, Object> result = new HashMap<String, Object>();
int processedValuesFromDescriptor = 0;
- GetDeclaredMethods action = GetDeclaredMethods.action( annotationType );
- final Method[] declaredMethods;
- if ( System.getSecurityManager() != null ) {
- declaredMethods = AccessController.doPrivileged( action );
- }
- else {
- declaredMethods = action.run();
- }
+ final Method[] declaredMethods = ReflectionHelper.getMethods( annotationType );
for ( Method m : declaredMethods ) {
if ( descriptor.containsElement( m.getName() ) ) {
result.put( m.getName(), descriptor.valueOf( m.getName() ) );
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ConstructorInstance.java (from rev 19566, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ConstructorInstance.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ConstructorInstance.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// $Id$
+
+package org.hibernate.validator.util.privilegedactions;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedAction;
+import javax.validation.ValidationException;
+
+/**
+ * Execute instance creation as privileged action.
+ *
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+public class ConstructorInstance<T> implements PrivilegedAction<T> {
+ private final Constructor<T> constructor;
+ private final Object[] initArgs;
+
+ public static <T> ConstructorInstance<T> action(Constructor<T> constructor, Object... initArgs) {
+ return new ConstructorInstance<T>( constructor, initArgs );
+ }
+
+ private ConstructorInstance(Constructor<T> constructor, Object... initArgs) {
+ this.constructor = constructor;
+ this.initArgs = initArgs;
+ }
+
+ public T run() {
+ try {
+ return constructor.newInstance( initArgs );
+ }
+ catch ( InstantiationException e ) {
+ throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
+ }
+ catch ( InvocationTargetException e ) {
+ throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
+ }
+ catch ( RuntimeException e ) {
+ throw new ValidationException( "Unable to instantiate" + constructor.getName(), e );
+ }
+ }
+}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -1,47 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validator.util.privilegedactions;
-
-import java.security.PrivilegedAction;
-
-/**
- * @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;
- }
- }
-}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -38,6 +38,6 @@
}
public Boolean run() {
- return ReflectionHelper.getMethod( clazz, property ) != null;
+ return ReflectionHelper.getMethodFromPropertyName( clazz, property ) != null;
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -18,12 +18,14 @@
package org.hibernate.validator.util.privilegedactions;
import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.security.PrivilegedAction;
+import javax.validation.ValidationException;
-import org.hibernate.validator.util.ReflectionHelper;
-
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class GetAnnotationParameter<T> implements PrivilegedAction<T> {
private final Annotation annotation;
@@ -42,6 +44,29 @@
}
public T run() {
- return ReflectionHelper.getAnnotationParameter( annotation, parameterName, type );
+ try {
+ Method m = annotation.getClass().getMethod( parameterName );
+ m.setAccessible( true );
+ Object o = m.invoke( annotation );
+ if ( o.getClass().getName().equals( type.getName() ) ) {
+ return ( T ) o;
+ }
+ else {
+ String msg = "Wrong parameter type. Expected: " + type.getName() + " Actual: " + o.getClass().getName();
+ throw new ValidationException( msg );
+ }
+ }
+ catch ( NoSuchMethodException e ) {
+ String msg = "The specified annotation defines no parameter '" + parameterName + "'.";
+ throw new ValidationException( msg, e );
+ }
+ catch ( IllegalAccessException e ) {
+ String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
+ throw new ValidationException( msg, e );
+ }
+ catch ( InvocationTargetException e ) {
+ String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
+ throw new ValidationException( msg, e );
+ }
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -20,10 +20,9 @@
import java.lang.reflect.Method;
import java.security.PrivilegedAction;
-import org.hibernate.validator.util.ReflectionHelper;
-
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class GetMethodFromPropertyName implements PrivilegedAction<Method> {
private final Class<?> clazz;
@@ -39,6 +38,19 @@
}
public Method run() {
- return ReflectionHelper.getMethod( clazz, property );
+ try {
+ char string[] = property.toCharArray();
+ string[0] = Character.toUpperCase( string[0] );
+ String fullMethodName = new String( string );
+ try {
+ return clazz.getMethod( "get" + fullMethodName );
+ }
+ catch ( NoSuchMethodException e ) {
+ return clazz.getMethod( "is" + fullMethodName );
+ }
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -17,8 +17,6 @@
*/
package org.hibernate.validator.util.privilegedactions;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.security.PrivilegedAction;
import javax.validation.ValidationException;
@@ -31,27 +29,19 @@
public class NewInstance<T> implements PrivilegedAction<T> {
private final Class<T> clazz;
private final String message;
- private final Class<?>[] parameterTypes;
- private final Object[] initArgs;
- public static <T> NewInstance<T> action(Class<T> clazz, String message, Object... initArgs) {
- return new NewInstance<T>( clazz, message, initArgs );
+ public static <T> NewInstance<T> action(Class<T> clazz, String message) {
+ return new NewInstance<T>( clazz, message );
}
- private NewInstance(Class<T> clazz, String message, Object... initArgs) {
+ private NewInstance(Class<T> clazz, String message) {
this.clazz = clazz;
this.message = message;
- this.initArgs = initArgs;
- this.parameterTypes = new Class<?>[initArgs.length];
- for ( int i = 0; i < initArgs.length; i++ ) {
- this.parameterTypes[i] = initArgs[i].getClass();
- }
}
public T run() {
try {
- Constructor<T> constructor = clazz.getConstructor( parameterTypes );
- return constructor.newInstance( initArgs );
+ return clazz.newInstance();
}
catch ( InstantiationException e ) {
throw new ValidationException( "Unable to instantiate " + message + ": " + clazz, e );
@@ -59,12 +49,6 @@
catch ( IllegalAccessException e ) {
throw new ValidationException( "Unable to instantiate " + clazz, e );
}
- catch ( NoSuchMethodException e ) {
- throw new ValidationException( "Unable to instantiate " + clazz, e );
- }
- catch ( InvocationTargetException e ) {
- throw new ValidationException( "Unable to instantiate " + clazz, e );
- }
catch ( RuntimeException e ) {
throw new ValidationException( "Unable to instantiate " + clazz, e );
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -17,13 +17,13 @@
*/
package org.hibernate.validator.util.privilegedactions;
+import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Member;
import java.security.PrivilegedAction;
-import org.hibernate.validator.util.ReflectionHelper;
-
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class SetAccessibility implements PrivilegedAction<Object> {
private final Member member;
@@ -37,7 +37,7 @@
}
public Object run() {
- ReflectionHelper.setAccessibility( member );
+ ( ( AccessibleObject ) member ).setAccessible( true );
return member;
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.security.AccessController;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
@@ -37,10 +36,8 @@
import org.slf4j.Logger;
import org.xml.sax.SAXException;
-import org.hibernate.validator.util.privilegedactions.GetClassLoader;
-import org.hibernate.validator.util.privilegedactions.LoadClass;
import org.hibernate.validator.util.LoggerFactory;
-import org.hibernate.validator.util.privilegedactions.NewInstance;
+import org.hibernate.validator.util.ReflectionHelper;
/**
* Parser for <i>validation.xml</i> using JAXB.
@@ -79,18 +76,12 @@
if ( constraintFactoryClass != null ) {
try {
@SuppressWarnings("unchecked")
- Class<ConstraintValidatorFactory> clazz = ( Class<ConstraintValidatorFactory> ) loadClass(
+ Class<ConstraintValidatorFactory> clazz = ( Class<ConstraintValidatorFactory> ) ReflectionHelper.loadClass(
constraintFactoryClass, this.getClass()
);
- NewInstance<ConstraintValidatorFactory> newInstance = NewInstance.action(
+ xmlParameters.constraintValidatorFactory = ReflectionHelper.newInstance(
clazz, "constraint factory class"
);
- if ( System.getSecurityManager() != null ) {
- xmlParameters.constraintValidatorFactory = AccessController.doPrivileged( newInstance );
- }
- else {
- xmlParameters.constraintValidatorFactory = newInstance.run();
- }
log.info( "Using {} as constraint factory.", constraintFactoryClass );
}
catch ( ValidationException e ) {
@@ -101,16 +92,6 @@
}
}
- 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() ) {
@@ -144,7 +125,7 @@
if ( messageInterpolatorClass != null ) {
try {
@SuppressWarnings("unchecked")
- Class<MessageInterpolator> clazz = ( Class<MessageInterpolator> ) loadClass(
+ Class<MessageInterpolator> clazz = ( Class<MessageInterpolator> ) ReflectionHelper.loadClass(
messageInterpolatorClass, this.getClass()
);
xmlParameters.messageInterpolator = clazz.newInstance();
@@ -173,7 +154,7 @@
if ( traversableResolverClass != null ) {
try {
@SuppressWarnings("unchecked")
- Class<TraversableResolver> clazz = ( Class<TraversableResolver> ) loadClass(
+ Class<TraversableResolver> clazz = ( Class<TraversableResolver> ) ReflectionHelper.loadClass(
traversableResolverClass, this.getClass()
);
xmlParameters.traversableResolver = clazz.newInstance();
@@ -202,7 +183,7 @@
String providerClassName = config.getDefaultProvider();
if ( providerClassName != null ) {
try {
- xmlParamters.providerClass = ( Class<? extends ValidationProvider<?>> ) loadClass(
+ xmlParamters.providerClass = ( Class<? extends ValidationProvider<?>> ) ReflectionHelper.loadClass(
providerClassName, this.getClass()
);
log.info( "Using {} as validation provider.", providerClassName );
@@ -239,9 +220,10 @@
finally {
try {
inputStream.close();
- } catch ( IOException io) {
- log.warn( "Unable to close input stream for " + VALIDATION_XML_FILE);
}
+ catch ( IOException io ) {
+ log.warn( "Unable to close input stream for " + VALIDATION_XML_FILE );
+ }
}
return validationConfig;
}
@@ -253,34 +235,27 @@
path = path.substring( 1 );
}
-
- boolean isSecured = System.getSecurityManager() != null;
boolean isContextCL = true;
// try the context class loader first
- GetClassLoader action = GetClassLoader.fromContext();
- ClassLoader loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ ClassLoader loader = ReflectionHelper.getClassLoaderFromContext();
if ( loader == null ) {
log.debug( "No default context class loader, fall back to Bean Validation's loader" );
- action = GetClassLoader.fromClass( ValidationXmlParser.class );
- loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ loader = ReflectionHelper.getClassLoaderFromClass( ValidationXmlParser.class );
isContextCL = false;
}
InputStream inputStream = loader.getResourceAsStream( path );
// try the current class loader
if ( isContextCL && inputStream == null ) {
- action = GetClassLoader.fromClass( ValidationXmlParser.class );
- loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ loader = ReflectionHelper.getClassLoaderFromClass( ValidationXmlParser.class );
inputStream = loader.getResourceAsStream( path );
}
return inputStream;
}
private Schema getValidationConfigurationSchema() {
- boolean isSecured = System.getSecurityManager() != null;
- GetClassLoader action = GetClassLoader.fromClass( ValidationXmlParser.class );
- ClassLoader loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ ClassLoader loader = ReflectionHelper.getClassLoaderFromClass( ValidationXmlParser.class );
URL schemaUrl = loader.getResource( VALIDATION_CONFIGURATION_XSD );
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
Schema schema = null;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -25,7 +25,6 @@
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.net.URL;
-import java.security.AccessController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -54,14 +53,8 @@
import org.hibernate.validator.metadata.ConstraintHelper;
import org.hibernate.validator.metadata.ConstraintOrigin;
import org.hibernate.validator.metadata.MetaConstraint;
-import org.hibernate.validator.util.privilegedactions.ContainsField;
-import org.hibernate.validator.util.privilegedactions.ContainsMethod;
-import org.hibernate.validator.util.privilegedactions.GetClassLoader;
-import org.hibernate.validator.util.privilegedactions.GetDeclaredField;
-import org.hibernate.validator.util.privilegedactions.GetMethod;
-import org.hibernate.validator.util.privilegedactions.GetMethodFromPropertyName;
-import org.hibernate.validator.util.privilegedactions.LoadClass;
import org.hibernate.validator.util.LoggerFactory;
+import org.hibernate.validator.util.ReflectionHelper;
import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
@@ -170,7 +163,7 @@
}
for ( String validatorClassName : validatedByType.getValue() ) {
Class<? extends ConstraintValidator<?, ?>> validatorClass;
- validatorClass = ( Class<? extends ConstraintValidator<?, ?>> ) loadClass(
+ validatorClass = ( Class<? extends ConstraintValidator<?, ?>> ) ReflectionHelper.loadClass(
validatorClassName,
this.getClass()
);
@@ -188,16 +181,6 @@
}
}
- 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, ?>>> constraintValidatorDefinitionClasses = new ArrayList<Class<? extends ConstraintValidator<? extends Annotation, ?>>>();
if ( constraintHelper.isBuiltinConstraint( annotationType ) ) {
@@ -228,25 +211,11 @@
else {
fieldNames.add( fieldName );
}
- final boolean containsField;
- ContainsField containsAction = ContainsField.action( beanClass, fieldName );
- if ( System.getSecurityManager() != null ) {
- containsField = AccessController.doPrivileged( containsAction );
- }
- else {
- containsField = containsAction.run();
- }
+ final boolean containsField = ReflectionHelper.containsField( beanClass, fieldName );
if ( !containsField ) {
throw new ValidationException( beanClass.getName() + " does not contain the fieldType " + fieldName );
}
- GetDeclaredField action = GetDeclaredField.action( beanClass, fieldName );
- final Field field;
- if ( System.getSecurityManager() != null ) {
- field = AccessController.doPrivileged( action );
- }
- else {
- field = action.run();
- }
+ final Field field = ReflectionHelper.getField( beanClass, fieldName );
// ignore annotations
boolean ignoreFieldAnnotation = fieldType.isIgnoreAnnotations() == null ? false : fieldType.isIgnoreAnnotations();
@@ -279,25 +248,11 @@
else {
getterNames.add( getterName );
}
- ContainsMethod cmAction = ContainsMethod.action( beanClass, getterName );
- boolean containsMethod;
- if ( System.getSecurityManager() != null ) {
- containsMethod = AccessController.doPrivileged( cmAction );
- }
- else {
- containsMethod = cmAction.run();
- }
+ boolean containsMethod = ReflectionHelper.containsMethod( beanClass, getterName );
if ( !containsMethod ) {
throw new ValidationException( beanClass.getName() + " does not contain the property " + getterName );
}
- final Method method;
- GetMethodFromPropertyName action = GetMethodFromPropertyName.action( beanClass, getterName );
- if ( System.getSecurityManager() != null ) {
- method = AccessController.doPrivileged( action );
- }
- else {
- method = action.run();
- }
+ final Method method = ReflectionHelper.getMethodFromPropertyName( beanClass, getterName );
// ignore annotations
boolean ignoreGetterAnnotation = getterType.isIgnoreAnnotations() == null ? false : getterType.isIgnoreAnnotations();
@@ -423,15 +378,7 @@
}
private <A extends Annotation> Class<?> getAnnotationParameterType(Class<A> annotationClass, String name) {
- Method m;
- GetMethod action = GetMethod.action( annotationClass, name );
- if ( System.getSecurityManager() != null ) {
- m = AccessController.doPrivileged( action );
- }
- else {
- m = action.run();
- }
-
+ Method m = ReflectionHelper.getMethod( annotationClass, name );
if ( m == null ) {
throw new ValidationException( "Annotation of type " + annotationClass.getName() + " does not contain a parameter " + name + "." );
}
@@ -574,7 +521,7 @@
returnValue = value;
}
else if ( returnType.getName().equals( Class.class.getName() ) ) {
- returnValue = loadClass( value, this.getClass() );
+ returnValue = ReflectionHelper.loadClass( value, this.getClass() );
}
else {
try {
@@ -634,7 +581,7 @@
else {
fullyQualifiedClass = defaultPackage + PACKAGE_SEPARATOR + clazz;
}
- return loadClass( fullyQualifiedClass, this.getClass() );
+ return ReflectionHelper.loadClass( fullyQualifiedClass, this.getClass() );
}
private boolean isQualifiedClass(String clazz) {
@@ -661,9 +608,7 @@
}
private Schema getMappingSchema() {
- boolean isSecured = System.getSecurityManager() != null;
- GetClassLoader action = GetClassLoader.fromClass( XmlMappingParser.class );
- ClassLoader loader = isSecured ? AccessController.doPrivileged( action ) : action.run();
+ ClassLoader loader = ReflectionHelper.getClassLoaderFromClass( XmlMappingParser.class );
URL schemaUrl = loader.getResource( VALIDATION_MAPPING_XSD );
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
Schema schema = null;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java 2010-05-20 21:55:28 UTC (rev 19572)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java 2010-05-20 22:13:26 UTC (rev 19573)
@@ -19,19 +19,19 @@
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;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.hibernate.validator.metadata.ConstraintHelper;
-import org.hibernate.validator.util.privilegedactions.SetAccessibility;
+import org.hibernate.validator.util.ReflectionHelper;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
/**
* @author Hardy Ferentschik
*/
@@ -50,7 +50,7 @@
Field[] fields = engine.getClass().getDeclaredFields();
assertNotNull( fields );
assertTrue( fields.length == 1 );
- setAccessibility( fields[0] );
+ ReflectionHelper.setAccessibility( fields[0] );
Annotation annotation = fields[0].getAnnotation( Pattern.List.class );
assertNotNull( annotation );
@@ -64,15 +64,11 @@
fields = order.getClass().getDeclaredFields();
assertNotNull( fields );
assertTrue( fields.length == 1 );
- setAccessibility( fields[0] );
+ ReflectionHelper.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, 7 months
Hibernate SVN: r19572 - in core/trunk: core/src/main/java/org/hibernate/criterion and 15 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-20 17:55:28 -0400 (Thu, 20 May 2010)
New Revision: 19572
Added:
core/trunk/core/src/main/java/org/hibernate/type/CompositeType.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/HibernateTraversableResolver.java
core/trunk/core/src/main/java/org/hibernate/criterion/Example.java
core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java
core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
core/trunk/core/src/main/java/org/hibernate/engine/ForeignKeys.java
core/trunk/core/src/main/java/org/hibernate/engine/Nullability.java
core/trunk/core/src/main/java/org/hibernate/event/def/AbstractVisitor.java
core/trunk/core/src/main/java/org/hibernate/event/def/DefaultRefreshEventListener.java
core/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java
core/trunk/core/src/main/java/org/hibernate/event/def/WrapVisitor.java
core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java
core/trunk/core/src/main/java/org/hibernate/mapping/Property.java
core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
core/trunk/core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java
core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java
core/trunk/core/src/main/java/org/hibernate/proxy/ProxyFactory.java
core/trunk/core/src/main/java/org/hibernate/proxy/dom4j/Dom4jProxyFactory.java
core/trunk/core/src/main/java/org/hibernate/proxy/map/MapProxyFactory.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/BasicLazyInitializer.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistProxyFactory.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/SerializableProxy.java
core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java
core/trunk/core/src/main/java/org/hibernate/tuple/entity/Dom4jEntityTuplizer.java
core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java
core/trunk/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java
core/trunk/core/src/main/java/org/hibernate/type/AnyType.java
core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java
core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java
core/trunk/core/src/main/java/org/hibernate/type/Type.java
core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java
Log:
HHH-5248 - Introduce CompositeType interface (to replace AbstractComponentType interface)
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/HibernateTraversableResolver.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/HibernateTraversableResolver.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/HibernateTraversableResolver.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.cfg.beanvalidation;
import java.lang.annotation.ElementType;
@@ -11,9 +34,9 @@
import org.hibernate.Hibernate;
import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
import org.hibernate.type.CollectionType;
-import org.hibernate.type.AbstractComponentType;
/**
* Use Hibernate metadata to ignore cascade on entities.
@@ -56,7 +79,7 @@
else if ( type.isEntityType() || type.isAnyType() ) {
associations.add( prefix + name );
} else if ( type.isComponentType() ) {
- AbstractComponentType componentType = (AbstractComponentType) type;
+ CompositeType componentType = (CompositeType) type;
addAssociationsToTheSetForAllProperties(
componentType.getPropertyNames(),
componentType.getSubtypes(),
Modified: core/trunk/core/src/main/java/org/hibernate/criterion/Example.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/criterion/Example.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/criterion/Example.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.criterion;
@@ -35,7 +34,7 @@
import org.hibernate.HibernateException;
import org.hibernate.engine.TypedValue;
import org.hibernate.persister.entity.EntityPersister;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
@@ -218,7 +217,7 @@
appendComponentCondition(
propertyName,
propertyValue,
- (AbstractComponentType) propertyTypes[i],
+ (CompositeType) propertyTypes[i],
criteria,
criteriaQuery,
buf
@@ -261,7 +260,7 @@
if (isPropertyIncluded) {
if ( propertyTypes[i].isComponentType() ) {
- addComponentTypedValues(name, value, (AbstractComponentType) type, list, criteria, criteriaQuery);
+ addComponentTypedValues(name, value, (CompositeType) type, list, criteria, criteriaQuery);
}
else {
addPropertyTypedValue(value, type, list);
@@ -296,7 +295,7 @@
protected void addComponentTypedValues(
String path,
Object component,
- AbstractComponentType type,
+ CompositeType type,
List list,
Criteria criteria,
CriteriaQuery criteriaQuery)
@@ -312,7 +311,7 @@
String subpath = StringHelper.qualify( path, propertyNames[i] );
if ( isPropertyIncluded(value, subpath, subtype) ) {
if ( subtype.isComponentType() ) {
- addComponentTypedValues(subpath, value, (AbstractComponentType) subtype, list, criteria, criteriaQuery);
+ addComponentTypedValues(subpath, value, (CompositeType) subtype, list, criteria, criteriaQuery);
}
else {
addPropertyTypedValue(value, subtype, list);
@@ -356,7 +355,7 @@
protected void appendComponentCondition(
String path,
Object component,
- AbstractComponentType type,
+ CompositeType type,
Criteria criteria,
CriteriaQuery criteriaQuery,
StringBuffer buf)
@@ -375,7 +374,7 @@
appendComponentCondition(
subpath,
value,
- (AbstractComponentType) subtype,
+ (CompositeType) subtype,
criteria,
criteriaQuery,
buf
Modified: core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.criterion;
@@ -29,10 +28,8 @@
import org.hibernate.Criteria;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
-
import org.hibernate.engine.TypedValue;
-
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
@@ -84,7 +81,7 @@
ArrayList list = new ArrayList();
Type type = criteriaQuery.getTypeUsingProjection(criteria, propertyName);
if ( type.isComponentType() ) {
- AbstractComponentType actype = (AbstractComponentType) type;
+ CompositeType actype = (CompositeType) type;
Type[] types = actype.getSubtypes();
for ( int j=0; j<values.length; j++ ) {
for ( int i=0; i<types.length; i++ ) {
Modified: core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -38,9 +38,9 @@
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.util.CollectionHelper;
@@ -212,7 +212,7 @@
}
}
else if ( type.isComponentType() ) {
- cascadeComponent( parent, child, (AbstractComponentType) type, propertyName, anything );
+ cascadeComponent( parent, child, (CompositeType) type, propertyName, anything );
}
}
else {
@@ -300,7 +300,7 @@
private void cascadeComponent(
final Object parent,
final Object child,
- final AbstractComponentType componentType,
+ final CompositeType componentType,
final String componentPropertyName,
final Object anything) {
componentPathStack.push( componentPropertyName );
Modified: core/trunk/core/src/main/java/org/hibernate/engine/ForeignKeys.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/ForeignKeys.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/engine/ForeignKeys.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.engine;
@@ -32,7 +31,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@@ -96,7 +95,7 @@
return isNullifiable(null, value) ? null : value;
}
else if ( type.isComponentType() ) {
- AbstractComponentType actype = (AbstractComponentType) type;
+ CompositeType actype = (CompositeType) type;
Object[] subvalues = actype.getPropertyValues(value, session);
Type[] subtypes = actype.getSubtypes();
boolean substitute = false;
Modified: core/trunk/core/src/main/java/org/hibernate/engine/Nullability.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/Nullability.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/engine/Nullability.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.engine;
@@ -30,8 +29,8 @@
import org.hibernate.PropertyValueException;
import org.hibernate.intercept.LazyPropertyInitializer;
import org.hibernate.persister.entity.EntityPersister;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.CollectionType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
/**
@@ -138,7 +137,7 @@
throws HibernateException {
//for non null args, check for components and elements containing components
if ( propertyType.isComponentType() ) {
- return checkComponentNullability( value, (AbstractComponentType) propertyType );
+ return checkComponentNullability( value, (CompositeType) propertyType );
}
else if ( propertyType.isCollectionType() ) {
@@ -148,7 +147,7 @@
if ( collectionElementType.isComponentType() ) {
//check for all components values in the collection
- AbstractComponentType componentType = (AbstractComponentType) collectionElementType;
+ CompositeType componentType = (CompositeType) collectionElementType;
Iterator iter = CascadingAction.getLoadedElementsIterator(session, collectionType, value);
while ( iter.hasNext() ) {
Object compValue = iter.next();
@@ -171,7 +170,7 @@
* @return property path
* @throws HibernateException error while getting subcomponent values
*/
- private String checkComponentNullability(final Object value, final AbstractComponentType compType)
+ private String checkComponentNullability(final Object value, final CompositeType compType)
throws HibernateException {
/* will check current level if some of them are not null
* or sublevels if they exist
Modified: core/trunk/core/src/main/java/org/hibernate/event/def/AbstractVisitor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/def/AbstractVisitor.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/event/def/AbstractVisitor.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.event.def;
@@ -28,8 +27,8 @@
import org.hibernate.event.EventSource;
import org.hibernate.intercept.LazyPropertyInitializer;
import org.hibernate.persister.entity.EntityPersister;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.CollectionType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@@ -99,8 +98,7 @@
* @param componentType
* @throws HibernateException
*/
- Object processComponent(Object component, AbstractComponentType componentType)
- throws HibernateException {
+ Object processComponent(Object component, CompositeType componentType) throws HibernateException {
if (component!=null) {
processValues(
componentType.getPropertyValues(component, session),
@@ -127,7 +125,7 @@
return processEntity( value, (EntityType) type );
}
else if ( type.isComponentType() ) {
- return processComponent( value, (AbstractComponentType) type );
+ return processComponent( value, (CompositeType) type );
}
else {
return null;
Modified: core/trunk/core/src/main/java/org/hibernate/event/def/DefaultRefreshEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/def/DefaultRefreshEventListener.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/event/def/DefaultRefreshEventListener.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.event.def;
@@ -29,6 +28,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.hibernate.HibernateException;
import org.hibernate.PersistentObjectException;
import org.hibernate.UnresolvableObjectException;
@@ -43,8 +43,8 @@
import org.hibernate.event.RefreshEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.CollectionType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
import org.hibernate.util.IdentityMap;
@@ -177,7 +177,7 @@
factory.evictCollection( ( (CollectionType) types[i] ).getRole(), id );
}
else if ( types[i].isComponentType() ) {
- AbstractComponentType actype = (AbstractComponentType) types[i];
+ CompositeType actype = (CompositeType) types[i];
evictCachedCollections( actype.getSubtypes(), id, factory );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.event.def;
@@ -33,7 +32,7 @@
import org.hibernate.event.EventSource;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
/**
@@ -75,7 +74,7 @@
/**
* {@inheritDoc}
*/
- Object processComponent(Object component, AbstractComponentType componentType) throws HibernateException {
+ Object processComponent(Object component, CompositeType componentType) throws HibernateException {
Type[] types = componentType.getSubtypes();
if ( component == null ) {
processValues( new Object[types.length], types );
Modified: core/trunk/core/src/main/java/org/hibernate/event/def/WrapVisitor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/def/WrapVisitor.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/event/def/WrapVisitor.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.event.def;
@@ -34,8 +33,8 @@
import org.hibernate.event.EventSource;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.CollectionType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
/**
@@ -125,7 +124,7 @@
}
}
- Object processComponent(Object component, AbstractComponentType componentType)
+ Object processComponent(Object component, CompositeType componentType)
throws HibernateException {
if (component!=null) {
Modified: core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.loader;
@@ -50,8 +49,8 @@
import org.hibernate.sql.DisjunctionFragment;
import org.hibernate.sql.InFragment;
import org.hibernate.sql.JoinFragment;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type;
@@ -348,7 +347,7 @@
}
else if ( type.isComponentType() ) {
walkCompositeElementTree(
- (AbstractComponentType) type,
+ (CompositeType) type,
persister.getElementColumnNames(),
persister,
alias,
@@ -525,7 +524,7 @@
}
else if ( type.isComponentType() ) {
walkComponentTree(
- ( AbstractComponentType ) type,
+ ( CompositeType ) type,
i,
0,
persister,
@@ -552,7 +551,7 @@
* @throws org.hibernate.MappingException ???
*/
private void walkComponentTree(
- final AbstractComponentType componentType,
+ final CompositeType componentType,
final int propertyNumber,
int begin,
final OuterJoinLoadable persister,
@@ -599,7 +598,7 @@
else if ( types[i].isComponentType() ) {
final PropertyPath subPath = path.append( propertyNames[i] );
walkComponentTree(
- ( AbstractComponentType ) types[i],
+ ( CompositeType ) types[i],
propertyNumber,
begin,
persister,
@@ -617,7 +616,7 @@
* For a composite element, add to a list of associations to be fetched by outerjoin
*/
private void walkCompositeElementTree(
- final AbstractComponentType compositeType,
+ final CompositeType compositeType,
final String[] cols,
final QueryableCollection persister,
final String alias,
@@ -662,7 +661,7 @@
else if ( types[i].isComponentType() ) {
final PropertyPath subPath = path.append( propertyNames[i] );
walkCompositeElementTree(
- (AbstractComponentType) types[i],
+ (CompositeType) types[i],
lhsColumns,
persister,
alias,
Modified: core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/loader/entity/EntityJoinWalker.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.loader.entity;
@@ -42,7 +41,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.type.AssociationType;
-import org.hibernate.type.ComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@@ -160,21 +159,19 @@
if ( entityPersister != null
&& entityPersister.getIdentifierType().isComponentType()
&& ! entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded()
- && hasAssociation( (ComponentType) entityPersister.getIdentifierType() ) ) {
+ && hasAssociation( (CompositeType) entityPersister.getIdentifierType() ) ) {
aliasesForAssociationsWithCompositesIds.add( oja.getRhsAlias() );
}
}
- private boolean hasAssociation(ComponentType componentType) {
- int i = 0;
+ private boolean hasAssociation(CompositeType componentType) {
for ( Type subType : componentType.getSubtypes() ) {
if ( subType.isEntityType() ) {
return true;
}
- else if ( subType.isComponentType() && hasAssociation( ( (ComponentType) subType ) ) ) {
+ else if ( subType.isComponentType() && hasAssociation( ( (CompositeType) subType ) ) ) {
return true;
}
- i++;
}
return false;
}
@@ -197,7 +194,7 @@
findKeyManyToOneTargetIndices(
keyManyToOneTargetIndices,
joinWithCompositeId,
- (ComponentType) entityPersister.getIdentifierType()
+ (CompositeType) entityPersister.getIdentifierType()
);
if ( ! keyManyToOneTargetIndices.isEmpty() ) {
@@ -219,7 +216,7 @@
private void findKeyManyToOneTargetIndices(
ArrayList<Integer> keyManyToOneTargetIndices,
OuterJoinableAssociation joinWithCompositeId,
- ComponentType componentType) {
+ CompositeType componentType) {
for ( Type subType : componentType.getSubtypes() ) {
if ( subType.isEntityType() ) {
Integer index = locateKeyManyToOneTargetIndex( joinWithCompositeId, (EntityType) subType );
@@ -231,7 +228,7 @@
findKeyManyToOneTargetIndices(
keyManyToOneTargetIndices,
joinWithCompositeId,
- (ComponentType) subType
+ (CompositeType) subType
);
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/Property.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/Property.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/Property.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -27,16 +27,16 @@
import java.util.Iterator;
import java.util.StringTokenizer;
+import org.hibernate.EntityMode;
import org.hibernate.MappingException;
import org.hibernate.PropertyNotFoundException;
-import org.hibernate.EntityMode;
import org.hibernate.engine.CascadeStyle;
import org.hibernate.engine.Mapping;
import org.hibernate.property.Getter;
import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory;
import org.hibernate.property.Setter;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
import org.hibernate.util.ArrayHelper;
@@ -109,7 +109,7 @@
public CascadeStyle getCascadeStyle() throws MappingException {
Type type = value.getType();
if ( type.isComponentType() && !type.isAnyType() ) {
- AbstractComponentType actype = (AbstractComponentType) type;
+ CompositeType actype = (CompositeType) type;
int length = actype.getSubtypes().length;
for ( int i=0; i<length; i++ ) {
if ( actype.getCascadeStyle(i)!=CascadeStyle.NONE ) return CascadeStyle.ALL;
Modified: core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.persister.collection;
@@ -79,8 +78,8 @@
import org.hibernate.sql.SimpleSelect;
import org.hibernate.sql.Template;
import org.hibernate.sql.ordering.antlr.ColumnMapper;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.CollectionType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.util.ArrayHelper;
@@ -525,7 +524,7 @@
elementColumnReaders,
elementColumnReaderTemplates,
elementFormulaTemplates,
- (AbstractComponentType) elementType,
+ (CompositeType) elementType,
factory
);
}
@@ -1729,7 +1728,7 @@
collectionPropertyColumnNames.put(aliasName, columnNames);
if( type.isComponentType() ) {
- AbstractComponentType ct = (AbstractComponentType) type;
+ CompositeType ct = (CompositeType) type;
String[] propertyNames = ct.getPropertyNames();
for (int i = 0; i < propertyNames.length; i++) {
String name = propertyNames[i];
Modified: core/trunk/core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/persister/collection/CompositeElementPropertyMapping.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,14 +20,13 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.persister.collection;
import org.hibernate.MappingException;
import org.hibernate.engine.Mapping;
import org.hibernate.persister.entity.AbstractPropertyMapping;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
/**
@@ -35,14 +34,14 @@
*/
public class CompositeElementPropertyMapping extends AbstractPropertyMapping {
- private final AbstractComponentType compositeType;
+ private final CompositeType compositeType;
public CompositeElementPropertyMapping(
String[] elementColumns,
String[] elementColumnReaders,
String[] elementColumnReaderTemplates,
String[] elementFormulaTemplates,
- AbstractComponentType compositeType,
+ CompositeType compositeType,
Mapping factory)
throws MappingException {
Modified: core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.persister.entity;
@@ -37,16 +36,19 @@
import java.util.Map;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
+import org.hibernate.LockOptions;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.StaleObjectStateException;
import org.hibernate.StaleStateException;
-import org.hibernate.LockOptions;
import org.hibernate.cache.CacheKey;
import org.hibernate.cache.access.EntityRegionAccessStrategy;
import org.hibernate.cache.entry.CacheEntry;
@@ -63,7 +65,6 @@
import org.hibernate.engine.Mapping;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.Status;
import org.hibernate.engine.ValueInclusion;
import org.hibernate.engine.Versioning;
import org.hibernate.exception.JDBCExceptionHelper;
@@ -88,7 +89,6 @@
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.persister.entity.DiscriminatorMetadata;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.sql.Alias;
@@ -103,8 +103,8 @@
import org.hibernate.tuple.Tuplizer;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper;
@@ -112,8 +112,6 @@
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.FilterHelper;
import org.hibernate.util.StringHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Basic functionality for persisting an entity via JDBC
@@ -1699,7 +1697,7 @@
// aliases for composite-id's
if ( getIdentifierType().isComponentType() ) {
// Fetch embedded identifiers propertynames from the "virtual" identifier component
- AbstractComponentType componentId = ( AbstractComponentType ) getIdentifierType();
+ CompositeType componentId = ( CompositeType ) getIdentifierType();
String[] idPropertyNames = componentId.getPropertyNames();
String[] idAliases = getIdentifierAliases();
String[] idColumnNames = getIdentifierColumnNames();
Modified: core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -34,8 +34,8 @@
import org.hibernate.QueryException;
import org.hibernate.engine.Mapping;
import org.hibernate.sql.Template;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.util.ArrayHelper;
@@ -206,7 +206,7 @@
if (path!=null) addPropertyPath(path, type, columns, columnReaders, columnReaderTemplates, formulaTemplates);
if ( type.isComponentType() ) {
- AbstractComponentType actype = (AbstractComponentType) type;
+ CompositeType actype = (CompositeType) type;
initComponentPropertyPaths( path, actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory );
if ( actype.isEmbedded() ) {
initComponentPropertyPaths(
@@ -266,12 +266,11 @@
protected void initComponentPropertyPaths(
final String path,
- final AbstractComponentType type,
+ final CompositeType type,
final String[] columns,
final String[] columnReaders,
final String[] columnReaderTemplates,
- String[] formulaTemplates, final Mapping factory)
- throws MappingException {
+ String[] formulaTemplates, final Mapping factory) throws MappingException {
Type[] types = type.getSubtypes();
String[] properties = type.getPropertyNames();
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/ProxyFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/ProxyFactory.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/ProxyFactory.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy;
@@ -30,7 +29,7 @@
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
/**
* Contract for run-time, proxy-based lazy initialization proxies.
@@ -42,7 +41,7 @@
/**
* Called immediately after instantiation of this factory.
* <p/>
- * Essentially equivalent to contructor injection, but contracted
+ * Essentially equivalent to constructor injection, but contracted
* here via interface.
*
* @param entityName The name of the entity for which this factory should
@@ -69,7 +68,7 @@
Set interfaces,
Method getIdentifierMethod,
Method setIdentifierMethod,
- AbstractComponentType componentIdType) throws HibernateException;
+ CompositeType componentIdType) throws HibernateException;
/**
* Create a new proxy instance
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/dom4j/Dom4jProxyFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/dom4j/Dom4jProxyFactory.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/dom4j/Dom4jProxyFactory.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,20 +20,19 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.dom4j;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.Set;
+
import org.hibernate.HibernateException;
-import org.hibernate.proxy.ProxyFactory;
-import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.proxy.ProxyFactory;
+import org.hibernate.type.CompositeType;
-import java.util.Set;
-import java.lang.reflect.Method;
-import java.io.Serializable;
-
/**
* Builds proxies for "dom4j" entity representations.
*
@@ -52,7 +51,7 @@
Set interfaces,
Method getIdentifierMethod,
Method setIdentifierMethod,
- AbstractComponentType componentIdType) throws HibernateException {
+ CompositeType componentIdType) throws HibernateException {
this.entityName = entityName;
}
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/map/MapProxyFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/map/MapProxyFactory.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/map/MapProxyFactory.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.map;
@@ -32,7 +31,7 @@
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
/**
* @author Gavin King
@@ -42,23 +41,19 @@
private String entityName;
public void postInstantiate(
- final String entityName,
- final Class persistentClass,
- final Set interfaces,
- final Method getIdentifierMethod,
- final Method setIdentifierMethod,
- AbstractComponentType componentIdType)
- throws HibernateException {
-
+ final String entityName,
+ final Class persistentClass,
+ final Set interfaces,
+ final Method getIdentifierMethod,
+ final Method setIdentifierMethod,
+ CompositeType componentIdType) throws HibernateException {
this.entityName = entityName;
}
- public HibernateProxy getProxy(
- final Serializable id,
- final SessionImplementor session)
- throws HibernateException {
- return new MapProxy( new MapLazyInitializer(entityName, id, session) );
+ public HibernateProxy getProxy(final Serializable id, final SessionImplementor session)
+ throws HibernateException {
+ return new MapProxy( new MapLazyInitializer( entityName, id, session ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/BasicLazyInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/BasicLazyInitializer.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/BasicLazyInitializer.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo;
@@ -29,7 +28,7 @@
import org.hibernate.engine.EntityKey;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.util.MarkerObject;
import org.hibernate.util.ReflectHelper;
import org.hibernate.proxy.AbstractLazyInitializer;
@@ -48,7 +47,7 @@
protected Method setIdentifierMethod;
protected boolean overridesEquals;
private Object replacement;
- protected AbstractComponentType componentIdType;
+ protected CompositeType componentIdType;
protected BasicLazyInitializer(
String entityName,
@@ -56,7 +55,7 @@
Serializable id,
Method getIdentifierMethod,
Method setIdentifierMethod,
- AbstractComponentType componentIdType,
+ CompositeType componentIdType,
SessionImplementor session) {
super(entityName, id, session);
this.persistentClass = persistentClass;
@@ -68,30 +67,26 @@
protected abstract Object serializableProxy();
+ @SuppressWarnings({ "UnnecessaryBoxing" })
protected final Object invoke(Method method, Object[] args, Object proxy) throws Throwable {
-
String methodName = method.getName();
int params = args.length;
if ( params==0 ) {
-
if ( "writeReplace".equals(methodName) ) {
return getReplacement();
}
else if ( !overridesEquals && "hashCode".equals(methodName) ) {
- return new Integer( System.identityHashCode(proxy) );
+ return Integer.valueOf( System.identityHashCode(proxy) );
}
else if ( isUninitialized() && method.equals(getIdentifierMethod) ) {
return getIdentifier();
}
-
else if ( "getHibernateLazyInitializer".equals(methodName) ) {
return this;
}
-
}
else if ( params==1 ) {
-
if ( !overridesEquals && "equals".equals(methodName) ) {
return args[0]==proxy ? Boolean.TRUE : Boolean.FALSE;
}
@@ -100,7 +95,6 @@
setIdentifier( (Serializable) args[0] );
return INVOKE_IMPLEMENTATION;
}
-
}
//if it is a property of an embedded component, invoke on the "identifier"
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -39,7 +39,7 @@
import org.hibernate.proxy.pojo.BasicLazyInitializer;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.util.ReflectHelper;
import org.slf4j.LoggerFactory;
@@ -63,10 +63,15 @@
private Class[] interfaces;
private boolean constructed = false;
- static HibernateProxy getProxy(final String entityName, final Class persistentClass,
- final Class[] interfaces, final Method getIdentifierMethod,
- final Method setIdentifierMethod, AbstractComponentType componentIdType,
- final Serializable id, final SessionImplementor session) throws HibernateException {
+ static HibernateProxy getProxy(
+ final String entityName,
+ final Class persistentClass,
+ final Class[] interfaces,
+ final Method getIdentifierMethod,
+ final Method setIdentifierMethod,
+ CompositeType componentIdType,
+ final Serializable id,
+ final SessionImplementor session) throws HibernateException {
// note: interfaces is assumed to already contain HibernateProxy.class
try {
@@ -94,12 +99,16 @@
}
}
- public static HibernateProxy getProxy(final Class factory, final String entityName,
- final Class persistentClass, final Class[] interfaces,
- final Method getIdentifierMethod, final Method setIdentifierMethod,
- final AbstractComponentType componentIdType, final Serializable id,
+ public static HibernateProxy getProxy(
+ final Class factory,
+ final String entityName,
+ final Class persistentClass,
+ final Class[] interfaces,
+ final Method getIdentifierMethod,
+ final Method setIdentifierMethod,
+ final CompositeType componentIdType,
+ final Serializable id,
final SessionImplementor session) throws HibernateException {
-
final CGLIBLazyInitializer instance = new CGLIBLazyInitializer(
entityName,
persistentClass,
@@ -150,9 +159,14 @@
return e.createClass();
}
- private CGLIBLazyInitializer(final String entityName, final Class persistentClass,
- final Class[] interfaces, final Serializable id, final Method getIdentifierMethod,
- final Method setIdentifierMethod, final AbstractComponentType componentIdType,
+ private CGLIBLazyInitializer(
+ final String entityName,
+ final Class persistentClass,
+ final Class[] interfaces,
+ final Serializable id,
+ final Method getIdentifierMethod,
+ final Method setIdentifierMethod,
+ final CompositeType componentIdType,
final SessionImplementor session) {
super(
entityName,
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.cglib;
@@ -32,7 +31,7 @@
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
/**
* @author Gavin King
@@ -46,7 +45,7 @@
private Class[] interfaces;
private Method getIdentifierMethod;
private Method setIdentifierMethod;
- private AbstractComponentType componentIdType;
+ private CompositeType componentIdType;
private Class factory;
public void postInstantiate(
@@ -55,7 +54,7 @@
final Set interfaces,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
- AbstractComponentType componentIdType)
+ CompositeType componentIdType)
throws HibernateException {
this.entityName = entityName;
this.persistentClass = persistentClass;
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.cglib;
@@ -30,7 +29,7 @@
import org.hibernate.HibernateException;
import org.hibernate.proxy.AbstractSerializableProxy;
import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
/**
* Serializable placeholder for <tt>CGLIB</tt> proxies
@@ -44,20 +43,20 @@
private String getIdentifierMethodName;
private String setIdentifierMethodName;
private Class[] setIdentifierMethodParams;
- private AbstractComponentType componentIdType;
+ private CompositeType componentIdType;
- public SerializableProxy() {}
+ public SerializableProxy() {
+ }
public SerializableProxy(
- final String entityName,
- final Class persistentClass,
- final Class[] interfaces,
- final Serializable id,
- final Boolean readOnly,
- final Method getIdentifierMethod,
- final Method setIdentifierMethod,
- AbstractComponentType componentIdType
- ) {
+ final String entityName,
+ final Class persistentClass,
+ final Class[] interfaces,
+ final Serializable id,
+ final Boolean readOnly,
+ final Method getIdentifierMethod,
+ final Method setIdentifierMethod,
+ CompositeType componentIdType) {
super( entityName, id, readOnly );
this.persistentClass = persistentClass;
this.interfaces = interfaces;
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.javassist;
@@ -39,7 +38,7 @@
import org.hibernate.engine.SessionImplementor;
import org.hibernate.proxy.pojo.BasicLazyInitializer;
import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.util.ReflectHelper;
/**
@@ -66,7 +65,7 @@
final Serializable id,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
- final AbstractComponentType componentIdType,
+ final CompositeType componentIdType,
final SessionImplementor session) {
super( entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session );
this.interfaces = interfaces;
@@ -78,7 +77,7 @@
final Class[] interfaces,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
- AbstractComponentType componentIdType,
+ CompositeType componentIdType,
final Serializable id,
final SessionImplementor session) throws HibernateException {
// note: interface is assumed to already contain HibernateProxy.class
@@ -121,7 +120,7 @@
final Class[] interfaces,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
- final AbstractComponentType componentIdType,
+ final CompositeType componentIdType,
final Serializable id,
final SessionImplementor session) throws HibernateException {
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistProxyFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistProxyFactory.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/JavassistProxyFactory.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.javassist;
@@ -32,7 +31,7 @@
import org.hibernate.engine.SessionImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
/**
* A {@link ProxyFactory} implementation for producing Javassist-based proxies.
@@ -47,7 +46,7 @@
private Class[] interfaces;
private Method getIdentifierMethod;
private Method setIdentifierMethod;
- private AbstractComponentType componentIdType;
+ private CompositeType componentIdType;
private Class factory;
public void postInstantiate(
@@ -56,7 +55,7 @@
final Set interfaces,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
- AbstractComponentType componentIdType) throws HibernateException {
+ CompositeType componentIdType) throws HibernateException {
this.entityName = entityName;
this.persistentClass = persistentClass;
this.interfaces = (Class[]) interfaces.toArray(NO_CLASSES);
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/SerializableProxy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/SerializableProxy.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/javassist/SerializableProxy.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.javassist;
@@ -30,7 +29,7 @@
import org.hibernate.HibernateException;
import org.hibernate.proxy.AbstractSerializableProxy;
import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.type.CompositeType;
/**
* Serializable placeholder for Javassist proxies
@@ -44,20 +43,20 @@
private String getIdentifierMethodName;
private String setIdentifierMethodName;
private Class[] setIdentifierMethodParams;
- private AbstractComponentType componentIdType;
+ private CompositeType componentIdType;
- public SerializableProxy() {}
+ public SerializableProxy() {
+ }
public SerializableProxy(
- final String entityName,
- final Class persistentClass,
- final Class[] interfaces,
- final Serializable id,
- final Boolean readOnly,
- final Method getIdentifierMethod,
- final Method setIdentifierMethod,
- AbstractComponentType componentIdType
- ) {
+ final String entityName,
+ final Class persistentClass,
+ final Class[] interfaces,
+ final Serializable id,
+ final Boolean readOnly,
+ final Method getIdentifierMethod,
+ final Method setIdentifierMethod,
+ CompositeType componentIdType) {
super( entityName, id, readOnly );
this.persistentClass = persistentClass;
this.interfaces = interfaces;
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -34,20 +34,17 @@
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
-import org.hibernate.engine.Cascade;
import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.EntityKey;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.EventSource;
import org.hibernate.event.PersistEvent;
-import org.hibernate.event.SaveOrUpdateEvent;
import org.hibernate.id.Assigned;
import org.hibernate.intercept.LazyPropertyInitializer;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
-import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.property.Getter;
import org.hibernate.property.Setter;
import org.hibernate.proxy.HibernateProxy;
@@ -55,8 +52,8 @@
import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.StandardProperty;
import org.hibernate.tuple.VersionProperty;
-import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.ComponentType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@@ -84,7 +81,7 @@
protected final boolean hasCustomAccessors;
private final Instantiator instantiator;
private final ProxyFactory proxyFactory;
- private final AbstractComponentType identifierMapperType;
+ private final CompositeType identifierMapperType;
public Type getIdentifierMapperType() {
return identifierMapperType;
@@ -182,7 +179,7 @@
mappedIdentifierValueMarshaller = null;
}
else {
- identifierMapperType = (AbstractComponentType) mapper.getType();
+ identifierMapperType = (CompositeType) mapper.getType();
mappedIdentifierValueMarshaller = buildMappedIdentifierValueMarshaller(
(ComponentType) entityMetamodel.getIdentifierProperty().getType(),
(ComponentType) identifierMapperType
@@ -262,7 +259,7 @@
public void setIdentifier(Object entity, Serializable id, SessionImplementor session) {
if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
if ( entity != id ) {
- AbstractComponentType copier = (AbstractComponentType) entityMetamodel.getIdentifierProperty().getType();
+ CompositeType copier = (CompositeType) entityMetamodel.getIdentifierProperty().getType();
copier.setPropertyValues( entity, copier.getPropertyValues( id, getEntityMode() ), getEntityMode() );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/entity/Dom4jEntityTuplizer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/entity/Dom4jEntityTuplizer.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/entity/Dom4jEntityTuplizer.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,37 +20,37 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tuple.entity;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.dom4j.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.EntityMode;
+import org.hibernate.EntityNameResolver;
+import org.hibernate.HibernateException;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
-import org.hibernate.proxy.ProxyFactory;
-import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.proxy.dom4j.Dom4jProxyFactory;
+import org.hibernate.property.Getter;
import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory;
-import org.hibernate.property.Getter;
import org.hibernate.property.Setter;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.EntityNameResolver;
-import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.proxy.ProxyFactory;
+import org.hibernate.proxy.dom4j.Dom4jProxyFactory;
+import org.hibernate.tuple.Dom4jInstantiator;
import org.hibernate.tuple.Instantiator;
-import org.hibernate.tuple.Dom4jInstantiator;
-import org.hibernate.type.AbstractComponentType;
-import org.dom4j.Element;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.hibernate.type.CompositeType;
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.HashMap;
-
/**
* An {@link EntityTuplizer} specific to the dom4j entity mode.
*
@@ -151,7 +151,7 @@
null,
null,
mappingInfo.hasEmbeddedIdentifier() ?
- (AbstractComponentType) mappingInfo.getIdentifier().getType() :
+ (CompositeType) mappingInfo.getIdentifier().getType() :
null
);
}
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tuple.entity;
@@ -35,27 +34,27 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
-import org.hibernate.tuple.IdentifierProperty;
-import org.hibernate.tuple.StandardProperty;
-import org.hibernate.tuple.PropertyFactory;
-import org.hibernate.tuple.VersionProperty;
-import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.engine.CascadeStyle;
import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.engine.Versioning;
import org.hibernate.engine.ValueInclusion;
+import org.hibernate.engine.Versioning;
+import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.PropertyGeneration;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.tuple.IdentifierProperty;
+import org.hibernate.tuple.PropertyFactory;
+import org.hibernate.tuple.StandardProperty;
+import org.hibernate.tuple.VersionProperty;
import org.hibernate.type.AssociationType;
+import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
-import org.hibernate.type.TypeFactory;
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.ReflectHelper;
@@ -430,7 +429,7 @@
return true;
}
else if ( type.isComponentType() ) {
- Type[] subtypes = ( ( AbstractComponentType ) type ).getSubtypes();
+ Type[] subtypes = ( (CompositeType) type ).getSubtypes();
for ( int i = 0; i < subtypes.length; i++ ) {
if ( indicatesCollection( subtypes[i] ) ) {
return true;
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tuple.entity;
@@ -33,20 +32,19 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.hibernate.EntityMode;
+import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
-import org.hibernate.EntityNameResolver;
-import org.hibernate.tuple.Instantiator;
-import org.hibernate.tuple.PojoInstantiator;
import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.cfg.Environment;
import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.intercept.FieldInterceptor;
-import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Subclass;
@@ -54,7 +52,9 @@
import org.hibernate.property.Setter;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
-import org.hibernate.type.AbstractComponentType;
+import org.hibernate.tuple.Instantiator;
+import org.hibernate.tuple.PojoInstantiator;
+import org.hibernate.type.CompositeType;
import org.hibernate.util.ReflectHelper;
/**
@@ -191,7 +191,7 @@
proxyGetIdentifierMethod,
proxySetIdentifierMethod,
persistentClass.hasEmbeddedIdentifier() ?
- (AbstractComponentType) persistentClass.getIdentifier().getType() :
+ (CompositeType) persistentClass.getIdentifier().getType() :
null
);
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -23,52 +23,14 @@
*/
package org.hibernate.type;
-import java.lang.reflect.Method;
-
-import org.hibernate.EntityMode;
-import org.hibernate.FetchMode;
-import org.hibernate.HibernateException;
-import org.hibernate.engine.CascadeStyle;
-import org.hibernate.engine.SessionImplementor;
-
/**
* Enables other Component-like types to hold collections and have cascades, etc.
*
* @see ComponentType
* @see AnyType
* @author Gavin King
+ *
+ * @deprecated in favor of {@link org.hibernate.type.CompositeType}
*/
-public interface AbstractComponentType extends Type {
- /**
- * Get the types of the component properties
- */
- public Type[] getSubtypes();
- /**
- * Get the names of the component properties
- */
- public String[] getPropertyNames();
- /**
- * Optional operation
- * @return nullability of component properties
- */
- public boolean[] getPropertyNullability();
- /**
- * Get the values of the component properties of
- * a component instance
- */
- public Object[] getPropertyValues(Object component, SessionImplementor session) throws HibernateException;
- /**
- * Optional operation
- */
- public Object[] getPropertyValues(Object component, EntityMode entityMode) throws HibernateException;
- /**
- * Optional operation
- */
- public void setPropertyValues(Object component, Object[] values, EntityMode entityMode) throws HibernateException;
- public Object getPropertyValue(Object component, int i, SessionImplementor session) throws HibernateException;
- //public Object instantiate(Object parent, SessionImplementor session) throws HibernateException;
- public CascadeStyle getCascadeStyle(int i);
- public FetchMode getFetchMode(int i);
- public boolean isMethodOf(Method method);
- public boolean isEmbedded();
+public interface AbstractComponentType extends CompositeType {
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/AnyType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AnyType.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/type/AnyType.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -52,7 +52,7 @@
*
* @author Gavin King
*/
-public class AnyType extends AbstractType implements AbstractComponentType, AssociationType {
+public class AnyType extends AbstractType implements CompositeType, AssociationType {
private final Type identifierType;
private final Type metaType;
Modified: core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -54,7 +54,7 @@
*
* @author Gavin King
*/
-public class ComponentType extends AbstractType implements AbstractComponentType {
+public class ComponentType extends AbstractType implements CompositeType {
private final TypeFactory.TypeScope typeScope;
private final String[] propertyNames;
Modified: core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -47,7 +47,7 @@
* Adapts <tt>CompositeUserType</tt> to <tt>Type</tt> interface
* @author Gavin King
*/
-public class CompositeCustomType extends AbstractType implements AbstractComponentType {
+public class CompositeCustomType extends AbstractType implements CompositeType {
private final CompositeUserType userType;
private final String name;
Added: core/trunk/core/src/main/java/org/hibernate/type/CompositeType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CompositeType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/CompositeType.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -0,0 +1,151 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type;
+
+import java.lang.reflect.Method;
+
+import org.hibernate.EntityMode;
+import org.hibernate.FetchMode;
+import org.hibernate.HibernateException;
+import org.hibernate.engine.CascadeStyle;
+import org.hibernate.engine.SessionImplementor;
+
+/**
+ * Contract for value types to hold collections and have cascades, etc. The notion is that of composition. JPA terms
+ * this an embeddable.
+ *
+ * @author Steve Ebersole
+ */
+public interface CompositeType extends Type {
+ /**
+ * Get the types of the component properties
+ *
+ * @return The component property types.
+ */
+ public Type[] getSubtypes();
+
+ /**
+ * Get the names of the component properties
+ *
+ * @return The component property names
+ */
+ public String[] getPropertyNames();
+
+ /**
+ * Retrieve the indicators regarding which component properties are nullable.
+ * <p/>
+ * An optional operation
+ *
+ * @return nullability of component properties
+ */
+ public boolean[] getPropertyNullability();
+
+ /**
+ * Extract the values of the component properties from the given component instance
+ *
+ * @param component The component instance
+ * @param session The session from which the request originates
+ *
+ * @return The property values
+ *
+ * @throws HibernateException Indicates a problem access the property values.
+ */
+ public Object[] getPropertyValues(Object component, SessionImplementor session) throws HibernateException;
+
+ /**
+ * Extract the values of the component properties from the given component instance without access to the
+ * session.
+ * <p/>
+ * An optional operation
+ *
+ * @param component The component instance
+ * @param entityMode The entity mode
+ *
+ * @return The property values
+ *
+ * @throws HibernateException Indicates a problem access the property values.
+ */
+ public Object[] getPropertyValues(Object component, EntityMode entityMode) throws HibernateException;
+
+ /**
+ * Extract a particular component property value indicated by index.
+ *
+ * @param component The component instance
+ * @param index The index of the property whose value is to be extracted
+ * @param session The session from which the request originates.
+ *
+ * @return The extracted component property value
+ *
+ * @throws HibernateException Indicates a problem access the property value.
+ */
+ public Object getPropertyValue(Object component, int index, SessionImplementor session) throws HibernateException;
+
+ /**
+ * Inject property values onto the given component instance
+ * <p/>
+ * An optional operation
+ *
+ * @param component The component instance
+ * @param values The values to inject
+ * @param entityMode The entity mode
+ *
+ * @throws HibernateException Indicates an issue performing the injection
+ */
+ public void setPropertyValues(Object component, Object[] values, EntityMode entityMode) throws HibernateException;
+
+ /**
+ * Retrieve the cascade style of the indicated component property.
+ *
+ * @param index The property index,
+ *
+ * @return The cascade style.
+ */
+ public CascadeStyle getCascadeStyle(int index);
+
+ /**
+ * Retrieve the fetch mode of the indicated component property.
+ *
+ * @param index The property index,
+ *
+ * @return The fetch mode
+ */
+ public FetchMode getFetchMode(int index);
+
+ /**
+ * Is the given method a member of this component's class?
+ *
+ * @param method The method to check
+ *
+ * @return True if the method is a member; false otherwise.
+ */
+ public boolean isMethodOf(Method method);
+
+ /**
+ * Is this component embedded? "embedded" indicates that the component is "virtual", that its properties are
+ * "flattened" onto its owner
+ *
+ * @return True if this component is embedded; false otherwise.
+ */
+ public boolean isEmbedded();
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/Type.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/Type.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/type/Type.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -96,11 +96,11 @@
public boolean isAnyType();
/**
- * Return true if the implementation is castable to {@link AbstractComponentType}. Essentially a polymorphic
- * version of {@code (type instanceof AbstractComponentType.class)}. A component type may own collections or
+ * Return true if the implementation is castable to {@link CompositeType}. Essentially a polymorphic
+ * version of {@code (type instanceof CompositeType.class)}. A component type may own collections or
* associations and hence must provide certain extra functionality.
*
- * @return True if this type is also an {@link CollectionType} implementor; false otherwise.
+ * @return True if this type is also an {@link CompositeType} implementor; false otherwise.
*/
public boolean isComponentType();
Modified: core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java 2010-05-20 20:37:56 UTC (rev 19571)
+++ core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java 2010-05-20 21:55:28 UTC (rev 19572)
@@ -248,7 +248,7 @@
}
else if ( types[i].isComponentType() ) {
// need to extract the component values and check for subtype replacements...
- AbstractComponentType componentType = ( AbstractComponentType ) types[i];
+ CompositeType componentType = ( CompositeType ) types[i];
Type[] subtypes = componentType.getSubtypes();
Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
14 years, 7 months
Hibernate SVN: r19571 - in core/trunk: testsuite/src/test/java/org/hibernate/test/dialect/functional/cache and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-20 16:37:56 -0400 (Thu, 20 May 2010)
New Revision: 19571
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java
core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/lob/BlobLocatorTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/lob/ClobLocatorTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java
Log:
HHH-5245 - Introduce LobHelper
Modified: core/trunk/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java 2010-05-20 20:19:34 UTC (rev 19570)
+++ core/trunk/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java 2010-05-20 20:37:56 UTC (rev 19571)
@@ -46,7 +46,7 @@
public LobCreator getLobCreator();
/**
- * Create an instance of a {@link LobCreator} appropriate for the current envionment, mainly meant to account for
+ * Create an instance of a {@link LobCreator} appropriate for the current environment, mainly meant to account for
* variance between JDBC 4 (<= JDK 1.6) and JDBC3 (>= JDK 1.5).
*
* @param lobCreationContext The context in which the LOB is being created
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java 2010-05-20 20:19:34 UTC (rev 19570)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java 2010-05-20 20:37:56 UTC (rev 19571)
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.dialect.functional.cache;
import java.sql.Statement;
@@ -510,8 +533,8 @@
Session s = openSession();
s.beginTransaction();
Blobber b = new Blobber();
- b.setBlob( Hibernate.createBlob( "foo/bar/baz".getBytes() ) );
- b.setClob( Hibernate.createClob("foo/bar/baz") );
+ b.setBlob( s.getLobHelper().createBlob( "foo/bar/baz".getBytes() ) );
+ b.setClob( s.getLobHelper().createClob("foo/bar/baz") );
s.save(b);
//s.refresh(b);
//assertTrue( b.getClob() instanceof ClobImpl );
@@ -542,7 +565,7 @@
s = openSession();
s.beginTransaction();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
- b.setClob( Hibernate.createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") );
+ b.setClob( s.getLobHelper().createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") );
s.flush();
s.getTransaction().commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2010-05-20 20:19:34 UTC (rev 19570)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2010-05-20 20:37:56 UTC (rev 19571)
@@ -3,7 +3,6 @@
import junit.framework.Test;
-import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.junit.functional.FunctionalTestCase;
@@ -41,11 +40,11 @@
Transaction t = s.beginTransaction();
Document d = new DocumentImpl();
d.setName("Hibernate in Action");
- d.setContent( Hibernate.createBlob( "blah blah blah".getBytes(), s ) );
+ d.setContent( s.getLobHelper().createBlob( "blah blah blah".getBytes() ) );
Long did = (Long) s.save(d);
SecureDocument d2 = new SecureDocumentImpl();
d2.setName("Secret");
- d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes(), s ) );
+ d2.setContent( s.getLobHelper().createBlob( "wxyz wxyz".getBytes() ) );
// SybaseASE15Dialect only allows 7-bits in a byte to be inserted into a tinyint
// column (0 <= val < 128)
d2.setPermissionBits( (byte) 127 );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2010-05-20 20:19:34 UTC (rev 19570)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2010-05-20 20:37:56 UTC (rev 19571)
@@ -1,4 +1,26 @@
-//$Id: SQLFunctionsTest.java 10977 2006-12-12 23:28:04Z steve.ebersole(a)jboss.com $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.legacy;
import java.util.ArrayList;
@@ -13,7 +35,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.ScrollableResults;
import org.hibernate.Transaction;
@@ -519,8 +540,8 @@
Session s = openSession();
Blobber b = new Blobber();
- b.setBlob( Hibernate.createBlob( "foo/bar/baz".getBytes() ) );
- b.setClob( Hibernate.createClob("foo/bar/baz") );
+ b.setBlob( s.getLobHelper().createBlob( "foo/bar/baz".getBytes() ) );
+ b.setClob( s.getLobHelper().createClob("foo/bar/baz") );
s.save(b);
//s.refresh(b);
//assertTrue( b.getClob() instanceof ClobImpl );
@@ -556,7 +577,7 @@
s = openSession();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
- b.setClob( Hibernate.createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") );
+ b.setClob( s.getLobHelper().createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") );
s.flush();
s.connection().commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/lob/BlobLocatorTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/lob/BlobLocatorTest.java 2010-05-20 20:19:34 UTC (rev 19570)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/lob/BlobLocatorTest.java 2010-05-20 20:37:56 UTC (rev 19571)
@@ -75,7 +75,7 @@
Session s = openSession();
s.beginTransaction();
LobHolder entity = new LobHolder();
- entity.setBlobLocator( Hibernate.createBlob( original ) );
+ entity.setBlobLocator( s.getLobHelper().createBlob( original ) );
s.save( entity );
s.getTransaction().commit();
s.close();
@@ -117,7 +117,7 @@
assertNotNull( entity.getBlobLocator() );
assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
assertEquals( original, extractData( entity.getBlobLocator() ) );
- entity.setBlobLocator( Hibernate.createBlob( changed ) );
+ entity.setBlobLocator( s.getLobHelper().createBlob( changed ) );
s.getTransaction().commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/lob/ClobLocatorTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/lob/ClobLocatorTest.java 2010-05-20 20:19:34 UTC (rev 19570)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/lob/ClobLocatorTest.java 2010-05-20 20:37:56 UTC (rev 19571)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -21,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.test.lob;
@@ -29,7 +27,6 @@
import junit.framework.Test;
-import org.hibernate.Hibernate;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.dialect.Dialect;
@@ -74,7 +71,7 @@
Session s = openSession();
s.beginTransaction();
LobHolder entity = new LobHolder();
- entity.setClobLocator( Hibernate.createClob( original ) );
+ entity.setClobLocator( s.getLobHelper().createClob( original ) );
s.save( entity );
s.getTransaction().commit();
s.close();
@@ -116,7 +113,7 @@
assertNotNull( entity.getClobLocator() );
assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
assertEquals( original, extractData( entity.getClobLocator() ) );
- entity.setClobLocator( Hibernate.createClob( changed ) );
+ entity.setClobLocator( s.getLobHelper().createClob( changed ) );
s.getTransaction().commit();
s.close();
@@ -145,7 +142,7 @@
Session s = openSession();
s.beginTransaction();
LobHolder entity = new LobHolder();
- entity.setClobLocator( Hibernate.createClob( original ) );
+ entity.setClobLocator( s.getLobHelper().createClob( original ) );
s.save( entity );
s.getTransaction().commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java 2010-05-20 20:19:34 UTC (rev 19570)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/mixed/MixedTest.java 2010-05-20 20:37:56 UTC (rev 19571)
@@ -1,9 +1,30 @@
-//$Id: MixedTest.java 15736 2008-12-27 00:49:42Z gbadner $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.mixed;
import junit.framework.Test;
-import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.junit.functional.FunctionalTestCase;
@@ -39,13 +60,13 @@
Document d = new Document();
d.setName( "Hibernate in Action" );
- d.setContent( Hibernate.createBlob( "blah blah blah".getBytes() ) );
+ d.setContent( s.getLobHelper().createBlob( "blah blah blah".getBytes() ) );
d.setParent( f );
Long did = (Long) s.save( d );
SecureDocument d2 = new SecureDocument();
d2.setName( "Secret" );
- d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes() ) );
+ d2.setContent( s.getLobHelper().createBlob( "wxyz wxyz".getBytes() ) );
// SybaseASE15Dialect only allows 7-bits in a byte to be inserted into a tinyint
// column (0 <= val < 128)
d2.setPermissionBits( (byte) 127 );
14 years, 7 months
Hibernate SVN: r19570 - in core/trunk/core/src/main/java/org/hibernate: engine/jdbc and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-20 16:19:34 -0400 (Thu, 20 May 2010)
New Revision: 19570
Added:
core/trunk/core/src/main/java/org/hibernate/LobHelper.java
Modified:
core/trunk/core/src/main/java/org/hibernate/Hibernate.java
core/trunk/core/src/main/java/org/hibernate/Session.java
core/trunk/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java
core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
Log:
HHH-5245 - Introduce LobHelper
Modified: core/trunk/core/src/main/java/org/hibernate/Hibernate.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/Hibernate.java 2010-05-20 17:57:24 UTC (rev 19569)
+++ core/trunk/core/src/main/java/org/hibernate/Hibernate.java 2010-05-20 20:19:34 UTC (rev 19570)
@@ -438,7 +438,7 @@
*
* @param bytes a byte array
* @return the Blob
- * @deprecated Use {@link #createBlob(byte[], Session)} instead
+ * @deprecated Use {@link LobHelper#createBlob(byte[])} instead.
*/
public static Blob createBlob(byte[] bytes) {
return NonContextualLobCreator.INSTANCE.wrap(
@@ -452,9 +452,9 @@
* @param bytes a byte array
* @param session The session in which the {@link Blob} will be used.
* @return the Blob
+ * @deprecated Use {@link LobHelper#createBlob(byte[])} instead.
*/
public static Blob createBlob(byte[] bytes, Session session) {
- // todo : wrap?
return getLobCreator( session ).createBlob( bytes );
}
@@ -475,8 +475,9 @@
* @param stream a binary stream
* @param length the number of bytes in the stream
* @return the Blob
- * @deprecated Use {@link #createBlob(InputStream, long, Session)} instead
+ * @deprecated Use {@link LobHelper#createBlob(InputStream, long)} instead.
*/
+ @Deprecated
public static Blob createBlob(InputStream stream, int length) {
return NonContextualLobCreator.INSTANCE.wrap(
NonContextualLobCreator.INSTANCE.createBlob( stream, length )
@@ -489,8 +490,9 @@
* @param stream a binary stream
* @param length the number of bytes in the stream
* @return the Blob
- * @deprecated Use {@link #createBlob(InputStream, long, Session)} instead
+ * @deprecated Use {@link LobHelper#createBlob(InputStream, long)} instead.
*/
+ @Deprecated
public static Blob createBlob(InputStream stream, long length) {
return NonContextualLobCreator.INSTANCE.wrap(
NonContextualLobCreator.INSTANCE.createBlob( stream, length )
@@ -504,9 +506,10 @@
* @param length the number of bytes in the stream
* @param session The session in which the {@link Blob} will be used.
* @return the Blob
+ * @deprecated Use {@link LobHelper#createBlob(InputStream, long)} instead.
*/
+ @Deprecated
public static Blob createBlob(InputStream stream, long length, Session session) {
- // todo : wrap?
return getLobCreator( session ).createBlob( stream, length );
}
@@ -520,8 +523,9 @@
* @param stream a binary stream
* @return the Blob
* @throws IOException Indicates an I/O problem accessing the stream
- * @deprecated Use {@link #createBlob(InputStream, long, Session)} instead
+ * @deprecated With no direct replacement. Use {@link #createBlob(InputStream,long)} instead, passing in the length
*/
+ @Deprecated
public static Blob createBlob(InputStream stream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream( stream.available() );
StreamUtils.copy( stream, buffer );
@@ -533,8 +537,9 @@
*
* @param string The string data
* @return The created {@link Clob}
- * @deprecated Use {@link #createClob(String, Session)} instead
+ * @deprecated Use {@link LobHelper#createClob(String)} instead
*/
+ @Deprecated
public static Clob createClob(String string) {
return NonContextualLobCreator.INSTANCE.wrap(
NonContextualLobCreator.INSTANCE.createClob( string )
@@ -547,9 +552,10 @@
* @param string The string data
* @param session The session in which the {@link Clob} will be used.
* @return The created {@link Clob}
+ * @deprecated Use {@link LobHelper#createClob(String)} instead
*/
+ @Deprecated
public static Clob createClob(String string, Session session) {
- // todo : wrap?
return getLobCreator( session ).createClob( string );
}
@@ -559,8 +565,9 @@
* @param reader a character stream
* @param length the number of characters in the stream
* @return The created {@link Clob}
- * @deprecated Use {@link #createClob(Reader,long,Session)} instead
+ * @deprecated Use {@link LobHelper#createClob(Reader, long)} instead
*/
+ @Deprecated
public static Clob createClob(Reader reader, int length) {
return NonContextualLobCreator.INSTANCE.wrap(
NonContextualLobCreator.INSTANCE.createClob( reader, length )
@@ -573,8 +580,9 @@
* @param reader a character stream
* @param length the number of characters in the stream
* @return The created {@link Clob}
- * @deprecated Use {@link #createClob(Reader,long,Session)} instead
+ * @deprecated Use {@link LobHelper#createClob(Reader, long)} instead
*/
+ @Deprecated
public static Clob createClob(Reader reader, long length) {
return NonContextualLobCreator.INSTANCE.wrap(
NonContextualLobCreator.INSTANCE.createClob( reader, length )
@@ -588,7 +596,9 @@
* @param length the number of characters in the stream
* @param session The session in which the {@link Clob} will be used.
* @return The created {@link Clob}
+ * @deprecated Use {@link LobHelper#createClob(Reader, long)} instead
*/
+ @Deprecated
public static Clob createClob(Reader reader, long length, Session session) {
return getLobCreator( session ).createClob( reader, length );
}
Added: core/trunk/core/src/main/java/org/hibernate/LobHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/LobHelper.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/LobHelper.java 2010-05-20 20:19:34 UTC (rev 19570)
@@ -0,0 +1,100 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.Blob;
+import java.sql.Clob;
+
+/**
+ * A {@link Session session's} helper for creating LOB data
+ *
+ * @author Steve Ebersole
+ */
+public interface LobHelper {
+
+ /**
+ * Create a new {@link Blob} from bytes.
+ *
+ * @param bytes a byte array
+ *
+ * @return the created Blob
+ */
+ public Blob createBlob(byte[] bytes);
+
+ /**
+ * Create a new {@link Blob} from stream data.
+ *
+ * @param stream a binary stream
+ * @param length the number of bytes in the stream
+
+ * @return the create Blob
+ */
+ public Blob createBlob(InputStream stream, long length);
+
+ /**
+ * Create a new {@link java.sql.Clob} from content
+ *
+ * @param string The string data
+ *
+ * @return The created {@link java.sql.Clob}
+ */
+ public Clob createClob(String string);
+
+ /**
+ * Create a new {@link Clob} from character reader.
+ *
+ * @param reader a character stream
+ * @param length the number of characters in the stream
+ *
+ * @return The created {@link Clob}
+ */
+ public Clob createClob(Reader reader, long length);
+
+ /**
+ * Create a new {@link java.sql.Clob} from content.
+ * <p/>
+ * Note, on JDK 1.6+ environments will
+ * create and return a NClob instead (NClob extends the Clob interface).
+ *
+ * @param string The string data
+ *
+ * @return The created {@link java.sql.Clob}/NClob
+ */
+ public Clob createNClob(String string);
+
+ /**
+ * Create a new {@link Clob} from character reader.
+ * <p/>
+ * Note, on JDK 1.6+ environments will
+ * create and return a NClob instead (NClob extends the Clob interface).
+ *
+ * @param reader a character stream
+ * @param length the number of characters in the stream
+ *
+ * @return The created {@link java.sql.Clob}/NClob
+ */
+ public Clob createNClob(Reader reader, long length);
+}
Modified: core/trunk/core/src/main/java/org/hibernate/Session.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/Session.java 2010-05-20 17:57:24 UTC (rev 19569)
+++ core/trunk/core/src/main/java/org/hibernate/Session.java 2010-05-20 20:19:34 UTC (rev 19570)
@@ -1004,6 +1004,12 @@
*/
public TypeHelper getTypeHelper();
+ /**
+ * Retrieve this session's helper/delegate for creating LOB instances.
+ *
+ * @return This session's LOB helper
+ */
+ public LobHelper getLobHelper();
/**
* Contains locking details (LockMode, Timeout and Scope).
Modified: core/trunk/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java 2010-05-20 17:57:24 UTC (rev 19569)
+++ core/trunk/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java 2010-05-20 20:19:34 UTC (rev 19570)
@@ -26,9 +26,6 @@
import java.sql.Connection;
import java.sql.SQLException;
-import org.hibernate.JDBCException;
-import org.hibernate.exception.SQLExceptionConverter;
-
/**
* Provides callback access into the context in which the LOB is to be created. Mainly this is useful
* for gaining access to the JDBC {@link Connection} for use in JDBC 4 environments.
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2010-05-20 17:57:24 UTC (rev 19569)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2010-05-20 20:19:34 UTC (rev 19570)
@@ -25,11 +25,15 @@
package org.hibernate.impl;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Reader;
import java.io.Serializable;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
@@ -52,6 +56,7 @@
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
+import org.hibernate.LobHelper;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.ObjectDeletedException;
@@ -83,6 +88,7 @@
import org.hibernate.engine.Status;
import org.hibernate.engine.LoadQueryInfluencers;
import org.hibernate.engine.jdbc.LobCreationContext;
+import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.query.FilterQueryPlan;
import org.hibernate.engine.query.HQLQueryPlan;
import org.hibernate.engine.query.NativeSQLQueryPlan;
@@ -2199,6 +2205,9 @@
oos.writeObject( childSessionsByEntityMode );
}
+ /**
+ * {@inheritDoc}
+ */
public Object execute(Callback callback) {
Connection connection = jdbcContext.getConnectionManager().getConnection();
try {
@@ -2223,6 +2232,72 @@
return getSessionFactory().getTypeHelper();
}
+ /**
+ * {@inheritDoc}
+ */
+ public LobHelper getLobHelper() {
+ if ( lobHelper == null ) {
+ lobHelper = new LobHelperImpl( this );
+ }
+ return lobHelper;
+ }
+
+ private transient LobHelperImpl lobHelper;
+
+ private static class LobHelperImpl implements LobHelper {
+ private final SessionImpl session;
+
+ private LobHelperImpl(SessionImpl session) {
+ this.session = session;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Blob createBlob(byte[] bytes) {
+ return lobCreator().createBlob( bytes );
+ }
+
+ private LobCreator lobCreator() {
+ return session.getFactory().getSettings().getJdbcSupport().getLobCreator( session );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Blob createBlob(InputStream stream, long length) {
+ return lobCreator().createBlob( stream, length );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Clob createClob(String string) {
+ return lobCreator().createClob( string );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Clob createClob(Reader reader, long length) {
+ return lobCreator().createClob( reader, length );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Clob createNClob(String string) {
+ return lobCreator().createNClob( string );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Clob createNClob(Reader reader, long length) {
+ return lobCreator().createNClob( reader, length );
+ }
+ }
+
private class CoordinatingEntityNameResolver implements EntityNameResolver {
public String resolveEntityName(Object entity) {
String entityName = interceptor.getEntityName( entity );
14 years, 7 months
Hibernate SVN: r19569 - in search/trunk/hibernate-search/src: main/java/org/hibernate/search/util and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-05-20 13:57:24 -0400 (Thu, 20 May 2010)
New Revision: 19569
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PassThroughAnalyzer.java
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/MyEntity.java
Log:
HSEARCH-530 Return a pass through analyzer on fields not TOKENIZED
For fields marked as UN_TOKENIZED, NO and NO_NORMS, scoped analyzers (returned by searchFactory.getAnalyzer(...); now return an analyzer that pass through the data unmodified. There is room for improvement on the PassThroughAnalyzer but that's a start.
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2010-05-20 17:56:27 UTC (rev 19568)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2010-05-20 17:57:24 UTC (rev 19569)
@@ -69,6 +69,7 @@
import org.hibernate.search.bridge.LuceneOptions;
import org.hibernate.search.impl.InitContext;
import org.hibernate.search.util.LoggerFactory;
+import org.hibernate.search.util.PassThroughAnalyzer;
import org.hibernate.search.util.ReflectionHelper;
import org.hibernate.search.util.ScopedAnalyzer;
import org.hibernate.util.StringHelper;
@@ -96,6 +97,7 @@
protected Similarity similarity; //there is only 1 similarity per class hierarchy, and only 1 per index
protected boolean isRoot;
protected EntityState entityState;
+ private Analyzer passThroughAnalyzer = new PassThroughAnalyzer();
/**
* Constructor used on contained entities not annotated with <code>@Indexed</code> themselves.
@@ -468,7 +470,7 @@
if ( analyzer == null ) {
throw new AssertionFailure( "Analyzer should not be undefined" );
}
- this.analyzer.addScopedAnalyzer( fieldName, analyzer );
+ addToScopedAnalyzer( fieldName, analyzer, ann.index() );
}
private void bindFieldAnnotation(XProperty member, PropertiesMetadata propertiesMetadata, String prefix, org.hibernate.search.annotations.Field fieldAnn, InitContext context) {
@@ -488,9 +490,19 @@
if ( analyzer == null ) {
analyzer = getAnalyzer( member, context );
}
- if ( analyzer != null ) {
- this.analyzer.addScopedAnalyzer( fieldName, analyzer );
+ addToScopedAnalyzer( fieldName, analyzer, fieldAnn.index() );
+ }
+
+ protected void addToScopedAnalyzer(String fieldName, Analyzer analyzer, Index index) {
+ if ( index == Index.TOKENIZED) {
+ if ( analyzer != null ) {
+ this.analyzer.addScopedAnalyzer( fieldName, analyzer );
+ }
}
+ else {
+ //no analyzer is used, add a fake one for queries
+ this.analyzer.addScopedAnalyzer( fieldName, passThroughAnalyzer );
+ }
}
protected Float getBoost(XProperty member, org.hibernate.search.annotations.Field fieldAnn) {
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2010-05-20 17:56:27 UTC (rev 19568)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2010-05-20 17:57:24 UTC (rev 19569)
@@ -221,7 +221,7 @@
if ( analyzer == null ) {
throw new AssertionFailure( "Analyzer should not be undefined" );
}
- this.analyzer.addScopedAnalyzer( fieldName, analyzer );
+ addToScopedAnalyzer( fieldName, analyzer, Index.UN_TOKENIZED );
}
}
}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PassThroughAnalyzer.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PassThroughAnalyzer.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PassThroughAnalyzer.java 2010-05-20 17:57:24 UTC (rev 19569)
@@ -0,0 +1,39 @@
+package org.hibernate.search.util;
+
+import java.io.Reader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.CharTokenizer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.util.AttributeSource;
+
+/**
+ * Analyzer that applies no operation whatsoever to the flux
+ * This is useful for queries operating on non tokenized fields.
+ *
+ * TODO there is probably a way to make that much more efficient by
+ * reimplementing TokenStream to take the Reader and pass through the flux as a single token
+ *
+ * @author Emmanuel Bernard
+ */
+public class PassThroughAnalyzer extends Analyzer {
+
+
+
+ @Override
+ public TokenStream tokenStream(String fieldName, Reader reader) {
+ return new PassThroughTokenizer(reader);
+ }
+
+ private static class PassThroughTokenizer extends CharTokenizer {
+ public PassThroughTokenizer(Reader input) {
+ super( input );
+ }
+
+ @Override
+ protected boolean isTokenChar(char c) {
+ return true;
+ }
+ }
+}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java 2010-05-20 17:56:27 UTC (rev 19568)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java 2010-05-20 17:57:24 UTC (rev 19569)
@@ -179,6 +179,20 @@
session.close();
}
+ public void testNotAnalyzedFieldAndScopedAnalyzer() throws Exception {
+ FullTextSession session = Search.getFullTextSession( openSession() );
+ SearchFactory searchFactory = session.getSearchFactory();
+ Analyzer analyzer = searchFactory.getAnalyzer( MyEntity.class );
+
+ // you can pass what so ever into the analysis since the used analyzers are
+ // returning the same tokens all the time. We just want to make sure that
+ // the right analyzers are used.
+ Token[] tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "notAnalyzed", "pass through" );
+ AnalyzerUtils.assertTokensEqual( tokens, new String[] { "pass through" } );
+
+ session.close();
+ }
+
protected Class<?>[] getMappings() {
return new Class[] { MyEntity.class, Article.class };
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/MyEntity.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/MyEntity.java 2010-05-20 17:56:27 UTC (rev 19568)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/MyEntity.java 2010-05-20 17:57:24 UTC (rev 19569)
@@ -59,6 +59,17 @@
@Analyzer(impl = Test2Analyzer.class)
private String field;
+ @Field(index = Index.UN_TOKENIZED)
+ private String notAnalyzed;
+
+ public String getNotAnalyzed() {
+ return notAnalyzed;
+ }
+
+ public void setNotAnalyzed(String notAnalyzed) {
+ this.notAnalyzed = notAnalyzed;
+ }
+
@IndexedEmbedded
@Embedded
private MyComponent component;
14 years, 7 months