OPENJPA-2025: Byte[] and Char[] should be treated as SingularAttributes, not lists by the metamodel generator - merged Mike Dick's trunk changes to 2.1.x

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1469097 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2013-04-17 23:18:05 +00:00
parent 59322050ed
commit 19f8697218
2 changed files with 21 additions and 7 deletions

View File

@ -48,6 +48,7 @@ import javax.tools.JavaFileObject;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.MetaDataFactory;
import org.apache.openjpa.persistence.PersistenceMetaDataFactory;
import org.apache.openjpa.persistence.PersistentCollection;
import org.apache.openjpa.persistence.util.SourceCode;
@ -164,9 +165,10 @@ public class AnnotationProcessor6 extends AbstractProcessor {
*
*/
private TypeCategory toMetaModelTypeCategory(TypeMirror mirror,
String name) {
if (mirror.getKind() == TypeKind.ARRAY)
String name, boolean persistentCollection) {
if (mirror.getKind() == TypeKind.ARRAY && persistentCollection ) {
return TypeCategory.LIST;
}
if (CLASSNAMES_COLLECTION.contains(name))
return TypeCategory.COLLECTION;
if (CLASSNAMES_LIST.contains(name))
@ -240,10 +242,13 @@ public class AnnotationProcessor6 extends AbstractProcessor {
Set<? extends Element> members = handler.getPersistentMembers(e);
for (Element m : members) {
boolean isPersistentCollection = m.getAnnotation(PersistentCollection.class) != null;
TypeMirror decl = handler.getDeclaredType(m);
String fieldName = handler.getPersistentMemberName(m);
String fieldType = handler.getDeclaredTypeName(decl);
TypeCategory typeCategory = toMetaModelTypeCategory(decl, fieldType);
String fieldType = handler.getDeclaredTypeName(decl, true, isPersistentCollection);
TypeCategory typeCategory =
toMetaModelTypeCategory(decl, fieldType, isPersistentCollection);
String metaModelType = typeCategory.getMetaModelType();
SourceCode.Field modelField = null;
switch (typeCategory) {

View File

@ -549,6 +549,10 @@ public class SourceAnnotationHandler
return getDeclaredTypeName(mirror, true);
}
String getDeclaredTypeName(TypeMirror mirror, boolean box) {
return getDeclaredTypeName(mirror, box, false);
}
/**
* Get the element name of the class the given mirror represents. If the
* mirror is primitive then returns the corresponding boxed class name.
@ -557,12 +561,17 @@ public class SourceAnnotationHandler
* <code>java.util.Set&lt;java.lang.String&gt;</code> this method will
* return <code>java.util.Set</code>.
*/
String getDeclaredTypeName(TypeMirror mirror, boolean box) {
String getDeclaredTypeName(TypeMirror mirror, boolean box, boolean persistentCollection) {
if (mirror == null || mirror.getKind() == TypeKind.NULL || mirror.getKind() == TypeKind.WILDCARD)
return "java.lang.Object";
if (mirror.getKind() == TypeKind.ARRAY) {
TypeMirror comp = ((ArrayType)mirror).getComponentType();
return getDeclaredTypeName(comp, false);
if(persistentCollection) {
TypeMirror comp = ((ArrayType)mirror).getComponentType();
return getDeclaredTypeName(comp, false);
}
else {
return mirror.toString();
}
}
mirror = box ? box(mirror) : mirror;
if (isPrimitive(mirror))