From fb413b106c8d1fff3aba014d51308f367a33f674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Tue, 20 Oct 2009 17:57:25 +0000 Subject: [PATCH] added better support for generic signature of domain types --- .../com/mysema/query/apt/APTModelFactory.java | 25 ++-- .../mysema/query/apt/DTOElementVisitor.java | 5 +- .../query/apt/EntityElementVisitor.java | 4 +- .../com/mysema/query/domain/EntityTest.java | 15 ++- .../query/domain/JodaTimeSupportTest.java | 23 ++-- .../com/mysema/query/domain/RelationTest.java | 48 ++++++- .../mysema/query/domain/SimpleTypesTest.java | 3 + .../mysema/query/domain/p4/SSupertype.java | 2 +- .../com/mysema/query/codegen/BeanModel.java | 119 ++++++++++-------- .../query/codegen/BeanModelFactory.java | 7 +- .../mysema/query/codegen/ClassTypeModel.java | 27 ++-- .../query/codegen/EntitySerializer.java | 91 +++++++++----- .../mysema/query/codegen/PropertyModel.java | 53 ++++++-- .../mysema/query/codegen/SimpleTypeModel.java | 41 +++--- .../mysema/query/codegen/TypeCategory.java | 18 ++- .../com/mysema/query/codegen/TypeModel.java | 7 +- .../query/codegen/TypeModelFactory.java | 15 ++- .../com/mysema/query/types/expr/EBoolean.java | 10 +- .../com/mysema/query/types/expr/EString.java | 30 +++-- .../query/types/path/PComponentMap.java | 10 +- .../com/mysema/query/types/path/PEntity.java | 13 +- .../query/types/path/PEntityCollection.java | 8 +- .../mysema/query/types/path/PEntityList.java | 6 +- .../mysema/query/types/path/PEntityMap.java | 10 +- .../mysema/query/codegen/SerializerTest.java | 8 +- .../mysema/query/sql/MetaDataExporter.java | 4 +- 26 files changed, 379 insertions(+), 223 deletions(-) diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/APTModelFactory.java b/querydsl-apt/src/main/java/com/mysema/query/apt/APTModelFactory.java index 272e6bf28..50068b14c 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/APTModelFactory.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/APTModelFactory.java @@ -66,6 +66,7 @@ public class APTModelFactory implements TypeVisitor { if (cache.containsKey(key)){ return cache.get(key); }else{ + cache.put(key, null); TypeModel value = type.accept(this, el); cache.put(key, value); return value; @@ -92,9 +93,9 @@ public class APTModelFactory implements TypeVisitor { if (t.asElement() != null && t.asElement() instanceof TypeElement){ TypeElement typeElement = (TypeElement)t.asElement(); switch(typeElement.getKind()){ - case CLASS: return createClassType(typeElement, p); + case CLASS: return createClassType(t, typeElement, p); case INTERFACE: return createInterfaceType(t, typeElement, p); - case ENUM: return create(typeElement, TypeCategory.SIMPLE, p); + case ENUM: return create(typeElement, TypeCategory.SIMPLE, p, t.getTypeArguments()); } }else{ throw new IllegalArgumentException("Unsupported element type " + t.asElement()); @@ -106,7 +107,7 @@ public class APTModelFactory implements TypeVisitor { // entity type for (Class entityAnn : entityAnnotations){ if (typeElement.getAnnotation(entityAnn) != null){ - return create(typeElement, TypeCategory.ENTITY, p); + return create(typeElement, TypeCategory.ENTITY, p, t.getTypeArguments()); } } @@ -115,7 +116,7 @@ public class APTModelFactory implements TypeVisitor { Iterator i = t.getTypeArguments().iterator(); Class cl = TypeUtil.safeForName(name); if (cl == null) { // class not available - return create(typeElement, TypeCategory.get(name), p); + return create(typeElement, TypeCategory.get(name), p, t.getTypeArguments()); }else if (Map.class.isAssignableFrom(cl)){ if (!i.hasNext()){ @@ -136,15 +137,15 @@ public class APTModelFactory implements TypeVisitor { return factory.createCollectionType(create(i.next(), p)); }else{ - return create(typeElement, TypeCategory.get(name), p); + return create(typeElement, TypeCategory.get(name), p, t.getTypeArguments()); } } - private TypeModel createClassType(TypeElement typeElement, Elements p) { + private TypeModel createClassType(DeclaredType t, TypeElement typeElement, Elements p) { // entity type for (Class entityAnn : entityAnnotations){ if (typeElement.getAnnotation(entityAnn) != null){ - return create(typeElement, TypeCategory.ENTITY, p); + return create(typeElement, TypeCategory.ENTITY, p, t.getTypeArguments()); } } @@ -161,7 +162,7 @@ public class APTModelFactory implements TypeVisitor { && isAssignable(typeElement, comparableType)){ typeCategory = TypeCategory.COMPARABLE; } - return create(typeElement, typeCategory, p); + return create(typeElement, typeCategory, p, t.getTypeArguments()); } private boolean isSubType(TypeElement type1, TypeElement type2) { @@ -175,11 +176,15 @@ public class APTModelFactory implements TypeVisitor { } - private TypeModel create(TypeElement typeElement, TypeCategory category, Elements p) { + private TypeModel create(TypeElement typeElement, TypeCategory category, Elements p, List typeArgs) { String name = typeElement.getQualifiedName().toString(); String simpleName = typeElement.getSimpleName().toString(); String packageName = p.getPackageOf(typeElement).getQualifiedName().toString(); - return new SimpleTypeModel(category, name, packageName, simpleName, null, null); + TypeModel[] params = new TypeModel[typeArgs.size()]; + for (int i = 0; i < params.length; i++){ + params[i] = create(typeArgs.get(i), p); + } + return new SimpleTypeModel(category, name, packageName, simpleName, params); } @Override diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/DTOElementVisitor.java b/querydsl-apt/src/main/java/com/mysema/query/apt/DTOElementVisitor.java index e4d7f5b26..8c625f568 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/DTOElementVisitor.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/DTOElementVisitor.java @@ -6,7 +6,6 @@ package com.mysema.query.apt; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.processing.ProcessingEnvironment; @@ -48,9 +47,7 @@ public final class DTOElementVisitor extends SimpleElementVisitor6emptySet()); + BeanModel classModel = new BeanModel(configuration.getNamePrefix(), c); List elements = e.getEnclosedElements(); // CONSTRUCTOR diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/EntityElementVisitor.java b/querydsl-apt/src/main/java/com/mysema/query/apt/EntityElementVisitor.java index 2dd0f814a..172571aad 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/EntityElementVisitor.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/EntityElementVisitor.java @@ -72,9 +72,7 @@ public final class EntityElementVisitor extends SimpleElementVisitor6 elements = e.getEnclosedElements(); // CONSTRUCTORS diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/EntityTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/EntityTest.java index b5a192f7d..816859e75 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/EntityTest.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/EntityTest.java @@ -7,21 +7,21 @@ import org.junit.Test; import com.mysema.query.annotations.QueryEntity; import com.mysema.query.annotations.QuerySupertype; -public class EntityTest { +public class EntityTest extends AbstractTest{ @QueryEntity public static class Entity1 { - String entity1Field; + public String entity1Field; } @QueryEntity public static class Entity2 extends Supertype{ - String entity2Field; + public String entity2Field; } @QueryEntity public static class Entity3 extends Entity2{ - String entity3Field; + public String entity3Field; } @QueryEntity @@ -31,7 +31,7 @@ public class EntityTest { @QuerySupertype public static class Supertype { - String supertypeField; + public String supertypeField; } @QuerySupertype @@ -39,10 +39,9 @@ public class EntityTest { } - @SuppressWarnings("unchecked") @Test public void inheritance(){ - assertTrue(QEntity2.entity2 instanceof QSupertype); - assertTrue(QEntity3.entity3 instanceof QSupertype); + assertTrue(QSupertype.class.isAssignableFrom(QEntity2.class)); + assertTrue(QSupertype.class.isAssignableFrom(QEntity3.class)); } } diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/JodaTimeSupportTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/JodaTimeSupportTest.java index 8c87f132d..54277dc7b 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/JodaTimeSupportTest.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/JodaTimeSupportTest.java @@ -1,7 +1,5 @@ package com.mysema.query.domain; -import static org.junit.Assert.assertTrue; - import org.joda.time.DateMidnight; import org.joda.time.DateTime; import org.joda.time.Instant; @@ -17,7 +15,7 @@ import com.mysema.query.types.path.PDate; import com.mysema.query.types.path.PDateTime; import com.mysema.query.types.path.PTime; -public class JodaTimeSupportTest { +public class JodaTimeSupportTest extends AbstractTest{ @QueryEntity public static class JodaTimeSupport { @@ -38,16 +36,15 @@ public class JodaTimeSupportTest { } - @SuppressWarnings("unchecked") @Test - public void test() { - QJodaTimeSupport i = QJodaTimeSupport.jodaTimeSupport; - assertTrue(i.dateMidnight instanceof PDateTime); - assertTrue(i.dateTime instanceof PDateTime); - assertTrue(i.instant instanceof PDateTime); - assertTrue(i.localDate instanceof PDate); - assertTrue(i.localDateTime instanceof PDateTime); - assertTrue(i.localTime instanceof PTime); - assertTrue(i.partial instanceof PComparable); + public void test() throws SecurityException, NoSuchFieldException { + cl = QJodaTimeSupport.class; + match(PDateTime.class, "dateMidnight"); + match(PDateTime.class, "dateTime"); + match(PDateTime.class, "instant"); + match(PDate.class, "localDate"); + match(PDateTime.class, "localDateTime"); + match(PTime.class, "localTime"); + match(PComparable.class, "partial"); } } diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/RelationTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/RelationTest.java index 7aac04709..25115f8a9 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/RelationTest.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/RelationTest.java @@ -10,8 +10,15 @@ import org.junit.Test; import com.mysema.query.annotations.QueryEntity; import com.mysema.query.domain.rel.RelationType2; +import com.mysema.query.types.path.PComponentCollection; +import com.mysema.query.types.path.PComponentList; +import com.mysema.query.types.path.PComponentMap; +import com.mysema.query.types.path.PEntityCollection; +import com.mysema.query.types.path.PEntityList; +import com.mysema.query.types.path.PEntityMap; +import com.mysema.query.types.path.PSimple; -public class RelationTest { +public class RelationTest extends AbstractTest{ public enum MyEnum { VAR1, VAR2 @@ -70,8 +77,43 @@ public class RelationTest { } @Test - public void test(){ - // TODO + public void test() throws SecurityException, NoSuchFieldException{ + cl = QRelationType.class; + match(PSimple.class, "enumProperty"); + match(PComponentList.class, "enumList"); + match(PComponentMap.class, "enumMap1"); + match(PComponentMap.class, "enumMap"); + + match(PEntityList.class, "list"); + match(PEntityList.class, "list2"); + match(PComponentList.class, "list3"); + match(PEntityList.class, "list4"); + match(PEntityList.class, "list5"); + + match(PEntityCollection.class, "set"); + match(PEntityCollection.class, "sortedSet"); + match(PComponentCollection.class, "set2"); + match(PEntityCollection.class, "set3"); + match(PEntityCollection.class, "set4"); + + match(PComponentList.class, "listOfObjects"); + match(PComponentCollection.class, "setOfObjects"); + match(PEntityCollection.class, "setOfObjects2"); + + match(PEntityCollection.class, "collection"); + match(PEntityCollection.class, "collection2"); + match(PComponentCollection.class, "collection3"); + match(PEntityCollection.class, "collection4"); + + match(PEntityMap.class, "map"); + match(PEntityMap.class, "map2"); + match(PComponentMap.class, "map3"); + match(PEntityMap.class, "map4"); + match(PEntityMap.class, "map5"); + match(PComponentMap.class, "map6"); + match(PEntityMap.class, "map7"); + match(PEntityMap.class, "map8"); + match(PComponentMap.class, "map9"); } } diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java index 643cf7a0b..00828c054 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java @@ -2,6 +2,7 @@ package com.mysema.query.domain; import java.io.Serializable; import java.math.BigDecimal; +import java.util.Calendar; import java.util.Date; import java.util.Locale; @@ -69,6 +70,7 @@ public class SimpleTypesTest extends AbstractTest{ @QueryEntity public static class SimpleTypes { transient int test; + Calendar calendar; long id; BigDecimal bigDecimal; Byte bbyte; @@ -124,6 +126,7 @@ public class SimpleTypesTest extends AbstractTest{ match(PString.class, "sstring"); match(PDateTime.class, "date"); + match(PDateTime.class, "calendar"); match(PDateTime.class, "timestamp"); match(PTime.class, "time"); diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/p4/SSupertype.java b/querydsl-apt/src/test/java/com/mysema/query/domain/p4/SSupertype.java index 9f15c7180..4cccd1566 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/p4/SSupertype.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/p4/SSupertype.java @@ -5,6 +5,6 @@ import com.mysema.query.annotations.QuerySupertype; @QuerySupertype public class SSupertype { - String supertypeField; + public String supertypeField; } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModel.java index 4d93ec38b..9456d88af 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModel.java @@ -6,6 +6,7 @@ package com.mysema.query.codegen; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -28,19 +29,19 @@ public final class BeanModel implements Comparable { private final Collection constructors = new HashSet(); - private BeanModel superModel; + private boolean entityModel = true; // mutable private int escapeSuffix = 1; - private boolean entityModel = true; - - private final String simpleName, name, packageName, localName; - private final String prefix; + private BeanModel superModel; + private final Collection superTypes; + private final TypeModel typeModel; + private final Map> typeToProperties = MapUtils.lazyMap( new HashMap>(), new Factory>(){ @@ -52,13 +53,14 @@ public final class BeanModel implements Comparable { private String uncapSimpleName; - public BeanModel(String prefix, String packageName, String name, String simpleName, Collection superTypes) { + public BeanModel(String prefix, TypeModel typeModel) { + this(prefix, typeModel, Collections.emptyList()); + } + + public BeanModel(String prefix, TypeModel typeModel, Collection superTypes) { this.prefix = Assert.notNull(prefix); - this.packageName = Assert.notNull(packageName); - this.name = Assert.notNull(name); - this.simpleName = Assert.notNull(simpleName); - this.uncapSimpleName = StringUtils.uncapitalize(simpleName); - this.localName = name.substring(packageName.length()+1); + this.typeModel = typeModel; + this.uncapSimpleName = StringUtils.uncapitalize(typeModel.getSimpleName()); this.superTypes = superTypes; } @@ -74,11 +76,11 @@ public final class BeanModel implements Comparable { } public int compareTo(BeanModel o) { - return simpleName.compareTo(o.simpleName); + return typeModel.getSimpleName().compareTo(o.typeModel.getSimpleName()); } public boolean equals(Object o) { - return o instanceof BeanModel && simpleName.equals(((BeanModel) o).simpleName); + return o instanceof BeanModel && typeModel.getName().equals(((BeanModel) o).typeModel.getName()); } public Collection getBooleanProperties() { @@ -105,10 +107,6 @@ public final class BeanModel implements Comparable { return typeToProperties.get(TypeCategory.ENTITYCOLLECTION); } - public Collection getEntityProperties() { - return typeToProperties.get(TypeCategory.ENTITY); - } - public Collection getEntityLists() { return typeToProperties.get(TypeCategory.ENTITYLIST); } @@ -117,8 +115,29 @@ public final class BeanModel implements Comparable { return typeToProperties.get(TypeCategory.ENTITYMAP); } + public Collection getEntityProperties() { + return typeToProperties.get(TypeCategory.ENTITY); + } + + public String getLocalName() { + return typeModel.getLocalName(); + } + public String getName() { - return name; + return typeModel.getName(); + } + + public String getGenericName(){ + if (typeModel.getParameterCount() == 0){ + return typeModel.getLocalName(); + }else{ + StringBuilder builder = new StringBuilder(typeModel.getLocalName()).append("<"); + for (int i = 0; i < typeModel.getParameterCount(); i++){ + if (i > 0) builder.append(","); + builder.append("?"); + } + return builder.append(">").toString(); + } } public Collection getNumericProperties() { @@ -126,15 +145,15 @@ public final class BeanModel implements Comparable { } public String getPackageName() { - return packageName; - } - - public Collection getSimpleCollections() { - return typeToProperties.get(TypeCategory.SIMPLECOLLECTION); + return typeModel.getPackageName(); } - public Collection getSimpleProperties() { - return typeToProperties.get(TypeCategory.SIMPLE); + public String getPrefix(){ + return prefix; + } + + public Collection getSimpleCollections() { + return typeToProperties.get(TypeCategory.SIMPLECOLLECTION); } public Collection getSimpleLists() { @@ -145,18 +164,22 @@ public final class BeanModel implements Comparable { return typeToProperties.get(TypeCategory.SIMPLEMAP); } - public String getLocalName(){ - return localName; - } - public String getSimpleName() { - return simpleName; + return typeModel.getSimpleName(); + } + + public Collection getSimpleProperties() { + return typeToProperties.get(TypeCategory.SIMPLE); } public Collection getStringProperties() { return typeToProperties.get(TypeCategory.STRING); } - + + public BeanModel getSuperModel() { + return superModel; + } + public Collection getSuperTypes() { return superTypes; } @@ -170,7 +193,7 @@ public final class BeanModel implements Comparable { } public int hashCode() { - return name.hashCode(); + return typeModel.getName().hashCode(); } public void include(BeanModel clazz) { @@ -184,32 +207,28 @@ public final class BeanModel implements Comparable { } } } - - private PropertyModel validateField(PropertyModel field) { - if (field.getName().equals(this.uncapSimpleName)) { - uncapSimpleName = StringUtils.uncapitalize(simpleName)+ (escapeSuffix++); - } - return field; - } - - public String getPrefix(){ - return prefix; - } - public BeanModel getSuperModel() { - return superModel; - } - - public void setSuperModel(BeanModel superModel) { - this.superModel = superModel; - } public boolean isEntityModel() { return entityModel; } + public void setEntityModel(boolean entityModel) { this.entityModel = entityModel; } + + + public void setSuperModel(BeanModel superModel) { + this.superModel = superModel; + } + + + private PropertyModel validateField(PropertyModel field) { + if (field.getName().equals(this.uncapSimpleName)) { + uncapSimpleName = StringUtils.uncapitalize(typeModel.getSimpleName())+ (escapeSuffix++); + } + return field; + } } \ No newline at end of file diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModelFactory.java b/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModelFactory.java index 079f1d6fa..c2df676ac 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModelFactory.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/BeanModelFactory.java @@ -51,11 +51,8 @@ public class BeanModelFactory { }else{ superTypes = Collections.singleton(key.getSuperclass().getName()); } - BeanModel beanModel = new BeanModel( - prefix, - key.getPackage().getName(), - key.getName(), - key.getSimpleName(), + BeanModel beanModel = new BeanModel(prefix, + new ClassTypeModel(TypeCategory.ENTITY, key), superTypes); for (Field f : key.getDeclaredFields()) { if (isValidField(f)){ diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/ClassTypeModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/ClassTypeModel.java index 447ae4835..d0cb52ee3 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/ClassTypeModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/ClassTypeModel.java @@ -1,5 +1,8 @@ package com.mysema.query.codegen; +import java.util.Collections; +import java.util.List; + import org.apache.commons.lang.ClassUtils; import com.mysema.commons.lang.Assert; @@ -16,6 +19,8 @@ public class ClassTypeModel implements TypeModel{ private final Class primitiveClass; + private final List parameters; + public ClassTypeModel(TypeCategory typeCategory, Class clazz){ this(typeCategory, clazz, ClassUtils.wrapperToPrimitive(clazz)); } @@ -24,6 +29,8 @@ public class ClassTypeModel implements TypeModel{ this.typeCategory = Assert.notNull(typeCategory); this.clazz = Assert.notNull(clazz); this.primitiveClass = primitiveClass; + // TODO + this.parameters = Collections.emptyList(); } @Override @@ -35,11 +42,6 @@ public class ClassTypeModel implements TypeModel{ } } - @Override - public TypeModel getKeyType() { - return null; - } - @Override public String getLocalName() { return clazz.getName().substring(clazz.getPackage().getName().length()+1); @@ -70,14 +72,19 @@ public class ClassTypeModel implements TypeModel{ return typeCategory; } - @Override - public TypeModel getValueType() { - return null; - } - @Override public boolean isPrimitive() { return primitiveClass != null; } + @Override + public TypeModel getParameter(int i) { + return parameters.get(i); + } + + @Override + public int getParameterCount() { + return parameters.size(); + } + } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java b/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java index b0976c63d..9a3599abe 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java @@ -134,27 +134,28 @@ public class EntitySerializer implements Serializer{ } protected void collectionOfEntity(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PEntityCollection<" + field.getTypeName()+">", writer, "createEntityCollection", field.getTypeName()+".class", "\"" + field.getSimpleTypeName()+"\""); + serialize(field, "PEntityCollection<" + field.getGenericTypeName()+">", writer, "createEntityCollection", field.getTypeName()+".class", "\"" + field.getSimpleTypeName()+"\""); } protected void collectionOfSimple(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PComponentCollection<" + field.getTypeName()+">", writer, "createSimpleCollection", field.getTypeName()+".class"); + serialize(field, "PComponentCollection<" + field.getGenericTypeName()+">", writer, "createSimpleCollection", field.getTypeName()+".class"); } protected void comparableField(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PComparable<" + field.getTypeName() + ">", writer, "createComparable", field.getTypeName() + ".class"); + serialize(field, "PComparable<" + field.getGenericTypeName() + ">", writer, "createComparable", field.getTypeName() + ".class"); } protected void constructors(BeanModel model, Writer writer) throws IOException { final String simpleName = model.getSimpleName(); final String queryType = model.getPrefix() + simpleName; final String localName = model.getLocalName(); + final String genericName = model.getGenericName(); StringBuilder builder = new StringBuilder(); constructorsForVariables(builder, model); - builder.append(" public " + queryType + "(PEntity entity) {\n"); + builder.append(" public " + queryType + "(PEntity entity) {\n"); builder.append(" super(entity.getType(), entity.getEntityName(), entity.getMetadata());\n"); if (!model.getEntityProperties().isEmpty()){ builder.append(" if (entity.getMetadata().getParent() == null){\n"); @@ -166,8 +167,15 @@ public class EntitySerializer implements Serializer{ builder.append(" }\n\n"); + if (!localName.equals(genericName)){ + builder.append(" @SuppressWarnings(\"unchecked\")\n"); + } builder.append(" public " + queryType + "(PathMetadata metadata) {\n"); - builder.append(" super("+ localName + ".class, \"" + simpleName + "\", metadata);\n"); + builder.append(" super("); + if (!localName.equals(genericName)){ + builder.append("(Class)"); + } + builder.append(localName + ".class, \"" + simpleName + "\", metadata);\n"); if (!model.getEntityProperties().isEmpty()){ builder.append(" if (metadata.getParent() == null){\n"); for (PropertyModel entityField : model.getEntityProperties()){ @@ -183,8 +191,17 @@ public class EntitySerializer implements Serializer{ final String simpleName = model.getSimpleName(); final String queryType = model.getPrefix() + simpleName; final String localName = model.getLocalName(); + final String genericName = model.getGenericName(); + + if (!localName.equals(genericName)){ + builder.append(" @SuppressWarnings(\"unchecked\")\n"); + } builder.append(" public " + queryType + "(@NotEmpty String variable) {\n"); - builder.append(" super(" + localName + ".class, \""+simpleName+"\", PathMetadata.forVariable(variable));\n"); + builder.append(" super("); + if (!localName.equals(genericName)){ + builder.append("(Class)"); + } + builder.append(localName + ".class, \""+simpleName+"\", PathMetadata.forVariable(variable));\n"); for (PropertyModel entityField : model.getEntityProperties()){ builder.append(" _" + entityField.getName()+"();\n"); } @@ -192,11 +209,11 @@ public class EntitySerializer implements Serializer{ } protected void dateField(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PDate<" + field.getTypeName() + ">", writer, "createDate", field.getTypeName()+".class"); + serialize(field, "PDate<" + field.getGenericTypeName() + ">", writer, "createDate", field.getTypeName()+".class"); } protected void dateTimeField(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PDateTime<" + field.getTypeName() + ">", writer, "createDateTime", field.getTypeName()+".class"); + serialize(field, "PDateTime<" + field.getGenericTypeName() + ">", writer, "createDateTime", field.getTypeName()+".class"); } protected void entityField(PropertyModel field, Writer writer) throws IOException { @@ -246,7 +263,8 @@ public class EntitySerializer implements Serializer{ protected void introClassHeader(StringBuilder builder, BeanModel model) { final String queryType = model.getPrefix() + model.getSimpleName(); - final String localName = model.getLocalName(); + final String localName = model.getGenericName(); + builder.append("@SuppressWarnings(\"serial\")\n"); BeanModel superModel = model.getSuperModel(); while (superModel != null && superModel.isEntityModel()){ @@ -267,6 +285,7 @@ public class EntitySerializer implements Serializer{ final String simpleName = model.getSimpleName(); final String unscapSimpleName = model.getUncapSimpleName(); final String queryType = model.getPrefix() + simpleName; + builder.append(" public static final " + queryType + " " + unscapSimpleName + " = new " + queryType + "(\"" + unscapSimpleName + "\");\n\n"); } @@ -281,6 +300,7 @@ public class EntitySerializer implements Serializer{ protected void introJavadoc(StringBuilder builder, BeanModel model) { final String simpleName = model.getSimpleName(); final String queryType = model.getPrefix() + simpleName; + builder.append("/**\n"); builder.append(" * " + queryType + " is a Querydsl query type for " + simpleName + "\n"); builder.append(" * \n"); @@ -292,14 +312,14 @@ public class EntitySerializer implements Serializer{ } protected void listOfEntity(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PEntityList<" + field.getTypeName()+ ">", writer, "createEntityList", field.getTypeName()+".class", "\"" + field.getSimpleTypeName()+"\""); + serialize(field, "PEntityList<" + field.getGenericTypeName()+ ">", writer, "createEntityList", field.getTypeName()+".class", "\"" + field.getSimpleTypeName()+"\""); } protected void listOfEntityAccessor(PropertyModel field, Writer writer) throws IOException { final String escapedName = field.getEscapedName(); final String queryType = field.getQueryTypeName(); - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder(); builder.append(" public " + queryType + " " + escapedName + "(int index) {\n"); builder.append(" return new " + queryType + "(PathMetadata.forListAccess(" + escapedName+", index));\n"); builder.append(" }\n\n"); @@ -311,9 +331,9 @@ public class EntitySerializer implements Serializer{ protected void listOfSimpleAccessor(PropertyModel field, Writer writer) throws IOException { final String escapedName = field.getEscapedName(); - final String valueType = field.getValueTypeName(); - StringBuilder builder = new StringBuilder(); + final String valueType = field.getParameterName(0); + StringBuilder builder = new StringBuilder(); builder.append(" public PSimple<" + valueType + "> " + escapedName + "(int index) {\n"); builder.append(" return new PSimple<" + valueType + ">("+valueType+".class, PathMetadata.forListAccess(" + escapedName+", index));\n"); builder.append(" }\n\n"); @@ -329,10 +349,13 @@ public class EntitySerializer implements Serializer{ } protected void mapOfEntity(PropertyModel field, Writer writer) throws IOException{ - final String keyType = field.getKeyTypeName(); - final String valueType = field.getValueTypeName(); + final String keyType = field.getParameterName(0); + final String valueType = field.getParameterName(1); final String simpleName = field.getSimpleTypeName(); - serialize(field, "PEntityMap<"+keyType+","+valueType+">", + final String genericKey = field.getGenericParameterName(0); + final String genericValue = field.getGenericParameterName(1); + + serialize(field, "PEntityMap<"+genericKey+","+genericValue+">", writer, "createEntityMap", keyType+".class", valueType+".class", "\""+simpleName+"\""); } @@ -340,13 +363,14 @@ public class EntitySerializer implements Serializer{ protected void mapOfEntityAccessor(PropertyModel field, Writer writer) throws IOException { final String escapedName = field.getEscapedName(); final String queryType = field.getQueryTypeName(); - final String keyType = field.getKeyTypeName(); - StringBuilder builder = new StringBuilder(); + final String keyType = field.getGenericParameterName(0); + final String genericKey = field.getGenericParameterName(0); + StringBuilder builder = new StringBuilder(); builder.append(" public " + queryType + " " + escapedName + "(" + keyType+ " key) {\n"); builder.append(" return new " + queryType + "(PathMetadata.forMapAccess(" + escapedName+", key));\n"); builder.append(" }\n\n"); - builder.append(" public " + queryType + " " + escapedName + "(com.mysema.query.types.expr.Expr<"+keyType+"> key) {\n"); + builder.append(" public " + queryType + " " + escapedName + "(com.mysema.query.types.expr.Expr<"+genericKey+"> key) {\n"); builder.append(" return new " + queryType + "(PathMetadata.forMapAccess(" + escapedName+", key));\n"); builder.append(" }\n\n"); writer.append(builder.toString()); @@ -354,24 +378,29 @@ public class EntitySerializer implements Serializer{ } protected void mapOfSimple(PropertyModel field, Writer writer) throws IOException { - final String keyType = field.getKeyTypeName(); - final String valueType = field.getValueTypeName(); + final String keyType = field.getParameterName(0); + final String valueType = field.getParameterName(1); + final String genericKey = field.getGenericParameterName(0); + final String genericValue = field.getGenericParameterName(1); - serialize(field, "PComponentMap<"+keyType+","+valueType+">", writer, "createSimpleMap", keyType+".class", valueType+".class"); + serialize(field, "PComponentMap<"+genericKey+","+genericValue+">", + writer, "createSimpleMap", keyType+".class", valueType+".class"); } protected void mapOfSimpleAccessor(PropertyModel field, Writer writer) throws IOException { -// final String fieldName = field.getName(); final String escapedName = field.getEscapedName(); - final String keyType = field.getKeyTypeName(); - final String valueType = field.getValueTypeName(); +// final String keyType = field.getParameterName(0); + final String valueType = field.getParameterName(1); + final String genericKey = field.getGenericParameterName(0); + final String genericValue = field.getGenericParameterName(1); + StringBuilder builder = new StringBuilder(); - builder.append(" public PSimple<" + valueType + "> " + escapedName + "(" + keyType + " key) {\n"); - builder.append(" return new PSimple<" + valueType + ">("+valueType+".class, PathMetadata.forMapAccess(" + escapedName+", key));\n"); + builder.append(" public PSimple<" + genericValue + "> " + escapedName + "(" + genericKey + " key) {\n"); + builder.append(" return new PSimple<" + genericValue + ">("+valueType+".class, PathMetadata.forMapAccess(" + escapedName+", key));\n"); builder.append(" }\n\n"); - builder.append(" public PSimple<" + valueType + "> " + escapedName + "(com.mysema.query.types.expr.Expr<"+keyType+"> key) {\n"); + builder.append(" public PSimple<" + genericValue + "> " + escapedName + "(com.mysema.query.types.expr.Expr<"+genericKey+"> key) {\n"); builder.append(" return new PSimple<" + valueType + ">("+valueType+".class, PathMetadata.forMapAccess(" + escapedName+", key));\n"); builder.append(" }\n\n"); writer.append(builder.toString()); @@ -379,7 +408,7 @@ public class EntitySerializer implements Serializer{ } protected void numericField(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PNumber<" + field.getTypeName() + ">", writer, "createNumber", field.getTypeName() +".class"); + serialize(field, "PNumber<" + field.getGenericTypeName() + ">", writer, "createNumber", field.getTypeName() +".class"); } protected void outro(BeanModel model, Writer writer) throws IOException { @@ -414,7 +443,7 @@ public class EntitySerializer implements Serializer{ } protected void simpleField(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PSimple<" + field.getTypeName()+">", writer, "createSimple", field.getTypeName()+".class"); + serialize(field, "PSimple<" + field.getGenericTypeName()+">", writer, "createSimple", field.getTypeName()+".class"); } protected void stringField(PropertyModel field, Writer writer) throws IOException { @@ -422,7 +451,7 @@ public class EntitySerializer implements Serializer{ } protected void timeField(PropertyModel field, Writer writer) throws IOException { - serialize(field, "PTime<" + field.getTypeName() + ">", writer, "createTime", field.getTypeName()+".class"); + serialize(field, "PTime<" + field.getGenericTypeName() + ">", writer, "createTime", field.getTypeName()+".class"); } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/PropertyModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/PropertyModel.java index edda6c6e0..c105e2f9f 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/PropertyModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/PropertyModel.java @@ -26,7 +26,7 @@ public final class PropertyModel implements Comparable { private final String name, escapedName, typeName; @Nullable - private final String keyTypeName, valueTypeName, queryTypeName; + private final String queryTypeName; private final TypeModel type; @@ -35,9 +35,7 @@ public final class PropertyModel implements Comparable { this.name = Assert.notNull(name); this.escapedName = JavaSyntaxUtils.isReserved(name) ? (name + "_") : name; this.type = Assert.notNull(type); - this.typeName = getLocalName(type); - this.keyTypeName = type.getKeyType() != null ? getLocalName(type.getKeyType()) : null; - this.valueTypeName = type.getValueType() != null ? getLocalName(type.getValueType()) : null; + this.typeName = getLocalName(type); if (type.getTypeCategory().isSubCategoryOf(TypeCategory.SIMPLE)){ this.queryTypeName = null; }else if (isVisible(type)){ @@ -71,14 +69,28 @@ public final class PropertyModel implements Comparable { return type.getTypeCategory(); } - public String getKeyTypeName() { - return keyTypeName; + public String getGenericParameterName(int i){ + if (i < type.getParameterCount()){ + TypeModel typeModel = type.getParameter(i); + if (typeModel.getParameterCount() > 0){ + return getGenericName(typeModel); + }else{ + return getLocalName(typeModel); + } + + }else{ + return null; + } } - public String getValueTypeName() { - return valueTypeName; + public String getParameterName(int i){ + if (i < type.getParameterCount()){ + return getLocalName(type.getParameter(i)); + }else{ + return null; + } } - + public String getName() { return name; } @@ -99,6 +111,29 @@ public final class PropertyModel implements Comparable { return typeName; } + public String getGenericTypeName(){ + TypeModel base = type; + if (type.getTypeCategory().isSubCategoryOf(TypeCategory.COLLECTION)){ + base = type.getParameter(0); + }else if (type.getTypeCategory().isSubCategoryOf(TypeCategory.MAP)){ + base = type.getParameter(1); + } + if (base.getParameterCount() > 0){ + return getGenericName(base); + }else{ + return typeName; + } + } + + private String getGenericName(TypeModel typeModel){ + StringBuilder builder = new StringBuilder(getLocalName(typeModel)).append("<"); + for (int i = 0; i < typeModel.getParameterCount(); i++){ + if (i > 0) builder.append(","); + builder.append("?"); + } + return builder.append(">").toString(); + } + public String getTypePackage() { return type.getPackageName(); } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleTypeModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleTypeModel.java index f24140576..aeaaf619b 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleTypeModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleTypeModel.java @@ -5,8 +5,6 @@ */ package com.mysema.query.codegen; -import javax.annotation.Nullable; - import net.jcip.annotations.Immutable; import com.mysema.commons.lang.Assert; @@ -21,8 +19,7 @@ import com.mysema.commons.lang.Assert; @Immutable public final class SimpleTypeModel implements TypeModel { - @Nullable - private final TypeModel keyType, valueType; + private final TypeModel[] parameters; private final String name, packageName, simpleName, localName; @@ -33,64 +30,72 @@ public final class SimpleTypeModel implements TypeModel { String name, String packageName, String simpleName, - @Nullable TypeModel keyType, - @Nullable TypeModel valueType) { + TypeModel... parameters) { this.typeCategory = Assert.notNull(typeCategory,"typeCategory is null"); this.name = Assert.notNull(name,"name is null"); this.packageName = Assert.notNull(packageName,"packageName is null"); this.simpleName = Assert.notNull(simpleName,"simpleName is null"); this.localName = name.substring(packageName.length()+1); - this.keyType = keyType; - this.valueType = valueType; + this.parameters = Assert.notNull(parameters); } public SimpleTypeModel as(TypeCategory category) { if (typeCategory == category){ return this; }else{ - return new SimpleTypeModel(category, name, packageName, simpleName, keyType, valueType); + return new SimpleTypeModel(category, name, packageName, simpleName, parameters); } } - public TypeModel getKeyType() { - return keyType; - } - + @Override public String getLocalName(){ return localName; } - + + @Override public String getName() { return name; } + @Override public String getPackageName() { return packageName; } + @Override public String getPrimitiveName(){ return null; } + @Override public String getSimpleName() { return simpleName; } + @Override public TypeCategory getTypeCategory() { return typeCategory; } - public TypeModel getValueType() { - return valueType; - } - + @Override public boolean isPrimitive() { return false; } + @Override public String toString() { return name; } + @Override + public TypeModel getParameter(int i) { + return parameters[i]; + } + + @Override + public int getParameterCount() { + return parameters.length; + } + } \ No newline at end of file diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeCategory.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeCategory.java index 67eb9014f..d1cba0278 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeCategory.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeCategory.java @@ -23,6 +23,14 @@ import com.mysema.query.annotations.PropertyType; */ @Immutable public enum TypeCategory { + /** + * + */ + MAP(null), + /** + * + */ + COLLECTION(null), /** * Simple non-entity fields */ @@ -43,6 +51,7 @@ public enum TypeCategory { * Date/Time fields */ DATETIME(COMPARABLE, + java.util.Calendar.class.getName(), java.util.Date.class.getName(), java.sql.Timestamp.class.getName(), "org.joda.time.LocalDateTime", @@ -56,7 +65,7 @@ public enum TypeCategory { /** * Entity collection fields */ - ENTITYCOLLECTION(null), + ENTITYCOLLECTION(COLLECTION), /** * Entity list fields */ @@ -64,7 +73,8 @@ public enum TypeCategory { /** * Entity map fields */ - ENTITYMAP(null), + ENTITYMAP(MAP), + /** * Numeric fields (? extends Number & Comparable) */ @@ -72,7 +82,7 @@ public enum TypeCategory { /** * Simple collection fields */ - SIMPLECOLLECTION(null), + SIMPLECOLLECTION(COLLECTION), /** * Simple list fields */ @@ -80,7 +90,7 @@ public enum TypeCategory { /** * Simple map fields */ - SIMPLEMAP(null), + SIMPLEMAP(MAP), /** * String fields */ diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModel.java index 18cc3edc0..edfd027b5 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModel.java @@ -11,8 +11,10 @@ public interface TypeModel { TypeModel as(TypeCategory category); @Nullable - TypeModel getKeyType(); + TypeModel getParameter(int i); + int getParameterCount(); + String getLocalName(); String getName(); @@ -26,9 +28,6 @@ public interface TypeModel { TypeCategory getTypeCategory(); - @Nullable - TypeModel getValueType(); - boolean isPrimitive(); String toString(); diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelFactory.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelFactory.java index ed53b567f..ad7471484 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelFactory.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelFactory.java @@ -13,8 +13,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.annotation.Nullable; - import org.apache.commons.lang.ClassUtils; import com.mysema.query.util.TypeUtil; @@ -98,30 +96,31 @@ public class TypeModelFactory { } public TypeModel createArrayType(TypeModel valueType) { - return createComposite(null, valueType, TypeCategory.ENTITYCOLLECTION, TypeCategory.SIMPLECOLLECTION); + return createComposite(TypeCategory.ENTITYCOLLECTION, TypeCategory.SIMPLECOLLECTION, valueType); } public TypeModel createCollectionType(TypeModel valueType) { - return createComposite(null, valueType, TypeCategory.ENTITYCOLLECTION, TypeCategory.SIMPLECOLLECTION); + return createComposite(TypeCategory.ENTITYCOLLECTION, TypeCategory.SIMPLECOLLECTION, valueType); } - private TypeModel createComposite(@Nullable TypeModel key, TypeModel value, TypeCategory entity, TypeCategory simple) { + private TypeModel createComposite(TypeCategory entity, TypeCategory simple, TypeModel... parameters) { TypeCategory category; + TypeModel value = parameters[parameters.length -1]; if (value.getTypeCategory() == TypeCategory.ENTITY) { category = entity; } else { category = simple; } - return new SimpleTypeModel(category, value.getName(), value.getPackageName(), value.getSimpleName(), key, value); + return new SimpleTypeModel(category, value.getName(), value.getPackageName(), value.getSimpleName(), parameters); } public TypeModel createListType(TypeModel valueType) { - return createComposite(null, valueType, TypeCategory.ENTITYLIST, TypeCategory.SIMPLELIST); + return createComposite(TypeCategory.ENTITYLIST, TypeCategory.SIMPLELIST, valueType); } public TypeModel createMapType(TypeModel keyType, TypeModel valueType) { - return createComposite(keyType, valueType, TypeCategory.ENTITYMAP, TypeCategory.SIMPLEMAP); + return createComposite(TypeCategory.ENTITYMAP, TypeCategory.SIMPLEMAP, keyType, valueType); } } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/expr/EBoolean.java b/querydsl-core/src/main/java/com/mysema/query/types/expr/EBoolean.java index de9a7dafc..11ca69618 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/expr/EBoolean.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/expr/EBoolean.java @@ -23,6 +23,10 @@ public abstract class EBoolean extends EComparable { public static final EBoolean TRUE = new EBooleanConst(Boolean.TRUE); + public static final EBoolean create(Boolean b){ + return b.booleanValue() ? TRUE : FALSE; + } + private volatile EBoolean not; public EBoolean() { @@ -50,7 +54,7 @@ public abstract class EBoolean extends EComparable { } return not; } - + /** * Create a union of this and the given expression * @@ -60,8 +64,4 @@ public abstract class EBoolean extends EComparable { public final EBoolean or(EBoolean right) { return OBoolean.create(Ops.OR, this, right); } - - public static final EBoolean create(Boolean b){ - return b.booleanValue() ? TRUE : FALSE; - } } \ No newline at end of file diff --git a/querydsl-core/src/main/java/com/mysema/query/types/expr/EString.java b/querydsl-core/src/main/java/com/mysema/query/types/expr/EString.java index a706a8682..92be131b6 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/expr/EString.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/expr/EString.java @@ -5,6 +5,12 @@ */ package com.mysema.query.types.expr; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import com.mysema.commons.lang.Assert; import com.mysema.query.types.operation.OBoolean; import com.mysema.query.types.operation.OComparable; @@ -23,9 +29,21 @@ import com.mysema.query.types.operation.Ops; @SuppressWarnings("serial") public abstract class EString extends EComparable { - public static final EString emptyString = new EStringConst(""); + private static final Map cache; + + static{ + List strs = new ArrayList(); + strs.addAll(Arrays.asList("", ".", ".*", "%", "id", "name")); + for (int i = 0; i < 256; i++){ + strs.add(String.valueOf(i)); + } + + cache = new HashMap(strs.size()); + for (String str : strs){ + cache.put(str, new EStringConst(str)); + } + } - public static final EString percentString = new EStringConst("%"); /** * Factory method for constants @@ -34,12 +52,10 @@ public abstract class EString extends EComparable { * @return */ public static final EString create(String str){ - if (str.equals("")){ - return emptyString; - }else if (str.equals("%")){ - return percentString; + if (cache.containsKey(str)){ + return cache.get(str); }else{ - return new EStringConst(Assert.notNull(str)); + return new EStringConst(Assert.notNull(str)); } } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/PComponentMap.java b/querydsl-core/src/main/java/com/mysema/query/types/path/PComponentMap.java index 911eadc7a..59efcfd5c 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/PComponentMap.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/PComponentMap.java @@ -37,20 +37,20 @@ public class PComponentMap extends EMapBase implements PMap { private volatile EBoolean isnull, isnotnull; @SuppressWarnings("unchecked") - public PComponentMap(Class keyType, Class valueType, + public PComponentMap(Class keyType, Class valueType, PathMetadata metadata) { super((Class)Map.class); - this.keyType = keyType; - this.valueType = valueType; + this.keyType = (Class)keyType; + this.valueType = (Class)valueType; this.metadata = metadata; this.root = metadata.getRoot() != null ? metadata.getRoot() : this; } - public PComponentMap(Class keyType, Class valueType, @NotEmpty String var) { + public PComponentMap(Class keyType, Class valueType, @NotEmpty String var) { this(keyType, valueType, PathMetadata.forVariable(var)); } - public PComponentMap(Class keyType, Class valueType, Path parent, @NotEmpty String property) { + public PComponentMap(Class keyType, Class valueType, Path parent, @NotEmpty String property) { this(keyType, valueType, PathMetadata.forProperty(parent, property)); } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntity.java b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntity.java index 939a8a95e..8dd518eef 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntity.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntity.java @@ -58,15 +58,15 @@ public class PEntity extends EEntity implements Path { return new PEntity(type, entityName, PathMetadata.forProperty(this, property)); } - protected PEntityCollection createEntityCollection(@NotEmpty String property, Class type, @NotEmpty String entityName) { + protected PEntityCollection createEntityCollection(@NotEmpty String property, Class type, @NotEmpty String entityName) { return new PEntityCollection(type, entityName, this, property); } - protected PEntityList createEntityList(@NotEmpty String property, Class type, @NotEmpty String entityName) { + protected PEntityList createEntityList(@NotEmpty String property, Class type, @NotEmpty String entityName) { return new PEntityList(type, entityName, this, property); } - protected PEntityMap createEntityMap(@NotEmpty String property, Class key, Class value, @NotEmpty String entityName) { + protected PEntityMap createEntityMap(@NotEmpty String property, Class key, Class value, @NotEmpty String entityName) { return new PEntityMap(key, value, entityName, this, property); } @@ -74,8 +74,9 @@ public class PEntity extends EEntity implements Path { return new PNumber(type, this, property); } - protected PSimple createSimple(@NotEmpty String path, Class type) { - return new PSimple(type, this, path); + @SuppressWarnings("unchecked") + protected PSimple createSimple(@NotEmpty String path, Class type) { + return new PSimple((Class)type, this, path); } protected PComponentCollection createSimpleCollection(@NotEmpty String path, Class type) { @@ -86,7 +87,7 @@ public class PEntity extends EEntity implements Path { return new PComponentList(type, this, path); } - protected PComponentMap createSimpleMap(@NotEmpty String path, Class key, Class value) { + protected PComponentMap createSimpleMap(@NotEmpty String path, Class key, Class value) { return new PComponentMap(key, value, this, path); } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityCollection.java b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityCollection.java index 408172c67..09aa6eba9 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityCollection.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityCollection.java @@ -42,19 +42,19 @@ public class PEntityCollection extends EEntity> imple private final Path root; @SuppressWarnings("unchecked") - public PEntityCollection(Class type, @NotEmpty String entityName, PathMetadata metadata) { + public PEntityCollection(Class type, @NotEmpty String entityName, PathMetadata metadata) { super((Class)Collection.class); - this.elementType = Assert.notNull(type,"type is null"); + this.elementType = (Class) Assert.notNull(type,"type is null"); this.metadata = Assert.notNull(metadata,"metadata is null"); this.entityName = Assert.notNull(entityName,"entityName is null"); this.root = metadata.getRoot() != null ? metadata.getRoot() : this; } - public PEntityCollection(Class type, @NotEmpty String entityName, @NotEmpty String var) { + public PEntityCollection(Class type, @NotEmpty String entityName, @NotEmpty String var) { this(type, entityName, PathMetadata.forVariable(var)); } - public PEntityCollection(Class type, @NotEmpty String entityName, Path parent, @NotEmpty String property) { + public PEntityCollection(Class type, @NotEmpty String entityName, Path parent, @NotEmpty String property) { this(type, entityName, PathMetadata.forProperty(parent, property)); } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityList.java b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityList.java index bc380c349..496817990 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityList.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityList.java @@ -18,15 +18,15 @@ import com.mysema.query.util.NotEmpty; @SuppressWarnings("serial") public class PEntityList extends PEntityCollection implements PList { - public PEntityList(Class elementType, @NotEmpty String entityName, PathMetadata metadata) { + public PEntityList(Class elementType, @NotEmpty String entityName, PathMetadata metadata) { super(elementType, entityName, metadata); } - public PEntityList(Class elementType, @NotEmpty String entityName, @NotEmpty String var) { + public PEntityList(Class elementType, @NotEmpty String entityName, @NotEmpty String var) { super(elementType, entityName, PathMetadata.forVariable(var)); } - public PEntityList(Class elementType, @NotEmpty String entityName, Path parent, @NotEmpty String property) { + public PEntityList(Class elementType, @NotEmpty String entityName, Path parent, @NotEmpty String property) { super(elementType, entityName, PathMetadata.forProperty(parent, property)); } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityMap.java b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityMap.java index 96a6b01da..d56d86169 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityMap.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/PEntityMap.java @@ -40,21 +40,21 @@ public class PEntityMap extends EMapBase implements PMap { private final Path root; @SuppressWarnings("unchecked") - public PEntityMap(Class keyType, Class valueType, @NotEmpty String entityName, + public PEntityMap(Class keyType, Class valueType, @NotEmpty String entityName, PathMetadata metadata) { super((Class)Map.class); - this.keyType = keyType; - this.valueType = valueType; + this.keyType = (Class) keyType; + this.valueType = (Class) valueType; this.entityName = entityName; this.metadata = metadata; this.root = metadata.getRoot() != null ? metadata.getRoot() : this; } - public PEntityMap(Class keyType, Class valueType, @NotEmpty String entityName, @NotEmpty String var) { + public PEntityMap(Class keyType, Class valueType, @NotEmpty String entityName, @NotEmpty String var) { this(keyType, valueType, entityName, PathMetadata.forVariable(var)); } - public PEntityMap(Class keyType, Class valueType, @NotEmpty String entityName, Path parent, @NotEmpty String var) { + public PEntityMap(Class keyType, Class valueType, @NotEmpty String entityName, Path parent, @NotEmpty String var) { this(keyType, valueType, entityName, PathMetadata.forProperty(parent, var)); } diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java index e07c96b19..45499c3ac 100644 --- a/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java @@ -28,12 +28,8 @@ public class SerializerTest { */ public SerializerTest() { TypeModelFactory typeFactory = new TypeModelFactory(); - type = new BeanModel( - "Q", - "com.mysema.query", - "com.mysema.query.DomainClass", - "DomainClass", - Collections.singleton("com.mysema.query.DomainSuperClass")); + TypeModel typeModel = new SimpleTypeModel(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass"); + type = new BeanModel("Q", typeModel, Collections.singleton("com.mysema.query.DomainSuperClass")); PropertyModel field = new PropertyModel(type, "field", typeFactory.create(String.class)); type.addProperty(field); diff --git a/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java b/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java index 6fa3435b5..2c7ae874f 100644 --- a/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java +++ b/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java @@ -21,6 +21,7 @@ import com.mysema.query.codegen.ClassTypeModel; import com.mysema.query.codegen.PropertyModel; import com.mysema.query.codegen.Serializer; import com.mysema.query.codegen.Serializers; +import com.mysema.query.codegen.SimpleTypeModel; import com.mysema.query.codegen.TypeCategory; import com.mysema.query.codegen.TypeModel; import com.mysema.query.util.FileUtils; @@ -98,7 +99,8 @@ public class MetaDataExporter { // ClassModelFactory factory = new ClassModelFactory(new TypeModelFactory()); while (tables.next()) { String tableName = tables.getString(3); - BeanModel classModel = new BeanModel(namePrefix, "java.lang", "java.lang.Object", tableName, Collections.emptySet()); + TypeModel classTypeModel = new SimpleTypeModel(TypeCategory.ENTITY, "java.lang.Object", "java.lang", tableName); + BeanModel classModel = new BeanModel(namePrefix, classTypeModel); ResultSet columns = md.getColumns(null, schemaPattern, tables.getString(3), null); while (columns.next()) { String name = columns.getString(4);