HHH-6171 Parsing o.h.a.Type and o.h.a.Parameter
This commit is contained in:
parent
2b694d7a86
commit
d6b36fca5a
|
@ -29,6 +29,7 @@ import java.util.Map;
|
||||||
import javax.persistence.DiscriminatorType;
|
import javax.persistence.DiscriminatorType;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
import org.jboss.jandex.AnnotationValue;
|
||||||
import org.jboss.jandex.DotName;
|
import org.jboss.jandex.DotName;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
|
@ -207,7 +208,24 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
* @return the final type for this mapped attribute
|
* @return the final type for this mapped attribute
|
||||||
*/
|
*/
|
||||||
private String determineType(String type, Map<String, String> typeParameters) {
|
private String determineType(String type, Map<String, String> typeParameters) {
|
||||||
return type;
|
AnnotationInstance typeAnnotation = getIfExists( HibernateDotNames.TYPE );
|
||||||
|
if ( typeAnnotation == null ) {
|
||||||
|
// return discovered type
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnnotationValue parameterAnnotationValue = typeAnnotation.value( "parameters" );
|
||||||
|
if ( parameterAnnotationValue != null ) {
|
||||||
|
AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray();
|
||||||
|
for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) {
|
||||||
|
typeParameters.put(
|
||||||
|
parameterAnnotationInstance.value( "name" ).asString(),
|
||||||
|
parameterAnnotationInstance.value( "value" ).asString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeAnnotation.value( "type" ).asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,16 +24,17 @@
|
||||||
package org.hibernate.metamodel.source.annotations.util;
|
package org.hibernate.metamodel.source.annotations.util;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
||||||
import org.jboss.jandex.ClassInfo;
|
|
||||||
import org.jboss.jandex.DotName;
|
|
||||||
import org.jboss.jandex.Index;
|
import org.jboss.jandex.Index;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Parameter;
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
|
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
|
||||||
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
|
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
|
||||||
import org.hibernate.metamodel.source.annotations.entity.MappedAttribute;
|
import org.hibernate.metamodel.source.annotations.entity.MappedAttribute;
|
||||||
|
@ -72,8 +73,6 @@ public class TypeDiscoveryTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
Iterator<ConfiguredClass> iter = hierarchies.iterator().next().iterator();
|
Iterator<ConfiguredClass> iter = hierarchies.iterator().next().iterator();
|
||||||
ConfiguredClass configuredClass = iter.next();
|
ConfiguredClass configuredClass = iter.next();
|
||||||
ClassInfo info = configuredClass.getClassInfo();
|
|
||||||
assertEquals( "wrong class", DotName.createSimple( Entity.class.getName() ), info.name() );
|
|
||||||
|
|
||||||
MappedAttribute property = configuredClass.getMappedProperty( "id" );
|
MappedAttribute property = configuredClass.getMappedProperty( "id" );
|
||||||
assertEquals( "Unexpected property type", "int", property.getType() );
|
assertEquals( "Unexpected property type", "int", property.getType() );
|
||||||
|
@ -82,8 +81,10 @@ public class TypeDiscoveryTest extends BaseUnitTestCase {
|
||||||
assertEquals( "Unexpected property type", String.class.getName(), property.getType() );
|
assertEquals( "Unexpected property type", String.class.getName(), property.getType() );
|
||||||
|
|
||||||
property = configuredClass.getMappedProperty( "customString" );
|
property = configuredClass.getMappedProperty( "customString" );
|
||||||
assertEquals( "Unexpected property type", String.class.getName(), property.getType() );
|
assertEquals( "Unexpected property type", "my.custom.Type", property.getType() );
|
||||||
|
|
||||||
|
Map<String, String> typeParameters = property.getTypeParameters();
|
||||||
|
assertEquals( "There should be a type parameter", "bar", typeParameters.get( "foo" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@javax.persistence.Entity
|
@javax.persistence.Entity
|
||||||
|
@ -91,6 +92,7 @@ public class TypeDiscoveryTest extends BaseUnitTestCase {
|
||||||
@Id
|
@Id
|
||||||
private int id;
|
private int id;
|
||||||
private String string;
|
private String string;
|
||||||
|
@Type(type = "my.custom.Type", parameters = { @Parameter(name = "foo", value = "bar") })
|
||||||
private String customString;
|
private String customString;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue