From 31d0ca2f0f7d235b8d0069757ad47c6d03e5725a Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Wed, 11 May 2011 23:21:28 +0800 Subject: [PATCH] HHH-6133 Enhance annotation based Jandex index with configuration extracted from orm.xml --- .../xml/mocker/PropertyMocker.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/xml/mocker/PropertyMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/xml/mocker/PropertyMocker.java index bde8759320..be3f70657d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/xml/mocker/PropertyMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/xml/mocker/PropertyMocker.java @@ -32,6 +32,7 @@ import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; +import org.hibernate.HibernateException; import org.hibernate.metamodel.source.annotation.xml.XMLAccessType; import org.hibernate.metamodel.source.annotation.xml.XMLEnumType; import org.hibernate.metamodel.source.annotation.xml.XMLMapKey; @@ -77,20 +78,28 @@ abstract class PropertyMocker extends AnnotationMocker { @Override final void process() { - setTarget( - MockHelper.getTarget( - indexBuilder.getServiceRegistry(), classInfo, getFieldName(), MockHelper.TargetType.FIELD - ) - ); - parserAccessType( getAccessType(), getTarget() ); - processExtra(); - setTarget( - MockHelper.getTarget( - indexBuilder.getServiceRegistry(), classInfo, getFieldName(), MockHelper.TargetType.PROPERTY - ) - ); - processExtra(); - parserAccessType( getAccessType(), getTarget() ); + processByTarget( MockHelper.TargetType.FIELD ); + processByTarget( MockHelper.TargetType.PROPERTY ); + } + + private void processByTarget(MockHelper.TargetType type) { + boolean isTargetAvailable = false; + try { + setTarget( + MockHelper.getTarget( + indexBuilder.getServiceRegistry(), classInfo, getFieldName(), type + ) + ); + isTargetAvailable = true; + } + catch ( HibernateException e ) { + //ignore + e.printStackTrace(); + } + if ( isTargetAvailable ) { + parserAccessType( getAccessType(), getTarget() ); + processExtra(); + } } protected AnnotationInstance parserMapKeyColumn(XMLMapKeyColumn mapKeyColumn, AnnotationTarget target) { @@ -158,7 +167,9 @@ abstract class PropertyMocker extends AnnotationMocker { "", annotationInstance ); } - MockHelper.addToCollectionIfNotNull( annotationValueList, AnnotationValue.createArrayValue( name, values ) ); + MockHelper.addToCollectionIfNotNull( + annotationValueList, AnnotationValue.createArrayValue( name, values ) + ); return values; } return MockHelper.EMPTY_ANNOTATION_VALUE_ARRAY;