Skip to content

Commit

Permalink
HHH-7696 Support multiple @AttributeOverride annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
brmeyer committed Oct 17, 2012
1 parent 7f1dbc2 commit 9ed8ac1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
Expand Up @@ -72,6 +72,7 @@
* Base class for a configured entity, mapped super class or embeddable
*
* @author Hardy Ferentschik
* @author Brett Meyer
*/
public class ConfiguredClass {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, AssertionFailure.class.getName());
Expand Down Expand Up @@ -704,28 +705,36 @@ private void findTransientFieldAndMethodNames() {
}

private Map<String, AttributeOverride> findAttributeOverrides() {
Map<String, AttributeOverride> attributeOverrideList = new HashMap<String, AttributeOverride>();

AnnotationInstance attributeOverrideAnnotation = JandexHelper.getSingleAnnotation(
classInfo,
JPADotNames.ATTRIBUTE_OVERRIDE
);
if ( attributeOverrideAnnotation != null ) {
String prefix = createPathPrefix( attributeOverrideAnnotation.target() );
AttributeOverride override = new AttributeOverride( prefix, attributeOverrideAnnotation );
attributeOverrideList.put( override.getAttributePath(), override );
Map<String, AttributeOverride> attributeOverrideList
= new HashMap<String, AttributeOverride>();

// Add all instances of @AttributeOverride
List<AnnotationInstance> attributeOverrideAnnotations = JandexHelper
.getAnnotations(classInfo, JPADotNames.ATTRIBUTE_OVERRIDE );
if ( attributeOverrideAnnotations != null ) {
for ( AnnotationInstance annotation : attributeOverrideAnnotations ) {
AttributeOverride override = new AttributeOverride(
createPathPrefix( annotation.target() ), annotation );
attributeOverrideList.put(
override.getAttributePath(), override );
}
}

AnnotationInstance attributeOverridesAnnotation = JandexHelper.getSingleAnnotation(
classInfo,
JPADotNames.ATTRIBUTE_OVERRIDES
);
if ( attributeOverridesAnnotation != null ) {
AnnotationInstance[] annotationInstances = attributeOverridesAnnotation.value().asNestedArray();
for ( AnnotationInstance annotationInstance : annotationInstances ) {
String prefix = createPathPrefix( attributeOverridesAnnotation.target() );
AttributeOverride override = new AttributeOverride( prefix, annotationInstance );
attributeOverrideList.put( override.getAttributePath(), override );
// Add all instances of @AttributeOverrides children
List<AnnotationInstance> attributeOverridesAnnotations = JandexHelper
.getAnnotations(classInfo, JPADotNames.ATTRIBUTE_OVERRIDES);
if ( attributeOverridesAnnotations != null ) {
for ( AnnotationInstance attributeOverridesAnnotation : attributeOverridesAnnotations ) {
AnnotationInstance[] annotationInstances
= attributeOverridesAnnotation.value().asNestedArray();
for ( AnnotationInstance annotation : annotationInstances ) {
AttributeOverride override = new AttributeOverride(
createPathPrefix(
attributeOverridesAnnotation.target() ),
annotation );
attributeOverrideList.put(
override.getAttributePath(), override );
}
}
}
return attributeOverrideList;
Expand Down
Expand Up @@ -52,6 +52,7 @@
* Utility methods for working with the jandex annotation index.
*
* @author Hardy Ferentschik
* @author Brett Meyer
*/
public class JandexHelper {
private static final Map<String, Object> DEFAULT_VALUES_BY_ELEMENT = new HashMap<String, Object>();
Expand Down Expand Up @@ -176,6 +177,17 @@ else if ( methodName.startsWith( "get" ) ) {
return propertyName;
}
}

/**
* @param classInfo the class info from which to retrieve the annotation instance
* @param annotationName the annotation to retrieve from the class info
*
* @return the list of annotations specified in the class
*/
public static List<AnnotationInstance> getAnnotations(
ClassInfo classInfo, DotName annotationName ) {
return classInfo.annotations().get( annotationName );
}

/**
* @param classInfo the class info from which to retrieve the annotation instance
Expand Down
Expand Up @@ -23,13 +23,15 @@
*/
package org.hibernate.test.annotations.embedded;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
Expand All @@ -38,10 +40,7 @@
import org.hibernate.test.util.SchemaUtil;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
* @author Emmanuel Bernard
Expand Down Expand Up @@ -537,7 +536,8 @@ protected Class[] getAnnotatedClasses() {
Country.class,
InternetFavorites.class,
FixedLeg.class,
FloatLeg.class
FloatLeg.class,
Swap.class
};
}
}

0 comments on commit 9ed8ac1

Please sign in to comment.