From 2adbd6cf27c2250ba24942ab0dbf0ba15f08b8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Mon, 10 Mar 2008 19:00:08 +0000 Subject: [PATCH] added support for entity maps and simple maps added min, max and size methods import HqlParserTest from hibernate code and replaced the String queries with statically typed ones --- .../java/com/mysema/query/apt/TypeDecl.java | 45 ++++++++++++++++--- .../src/main/resources/querydsl-hibernate.ftl | 6 +++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/TypeDecl.java b/querydsl-apt/src/main/java/com/mysema/query/apt/TypeDecl.java index d2f0d74fa..fc9245d44 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/TypeDecl.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/TypeDecl.java @@ -42,10 +42,14 @@ public class TypeDecl implements Comparable{ private final Set entityCollections = new TreeSet(); + private final Set entityMaps = new TreeSet(); + private final Set entityFields = new TreeSet(); private final Set simpleCollections = new TreeSet(); + private final Set simpleMaps = new TreeSet(); + private final Set simpleFields = new TreeSet(); private final String simpleName, name; @@ -73,6 +77,8 @@ public class TypeDecl implements Comparable{ case ENTITY : entityFields.add(fieldDecl); break; case ENTITYCOLLECTION : entityCollections.add(fieldDecl); break; case SIMPLECOLLECTION : simpleCollections.add(fieldDecl); break; + case ENTITYMAP : entityMaps.add(fieldDecl); break; + case SIMPLEMAP : simpleMaps.add(fieldDecl); break; } } @@ -93,6 +99,10 @@ public class TypeDecl implements Comparable{ public Collection getEntityCollections() { return entityCollections; } + + public Collection getEntityMaps() { + return entityMaps; + } public Collection getEntityFields() { return entityFields; @@ -105,6 +115,10 @@ public class TypeDecl implements Comparable{ public Collection getSimpleCollections() { return simpleCollections; } + + public Collection getSimpleMaps() { + return simpleMaps; + } public Collection getSimpleFields() { return simpleFields; @@ -130,6 +144,8 @@ public class TypeDecl implements Comparable{ booleanFields.addAll(decl.booleanFields); entityCollections.addAll(decl.entityCollections); simpleCollections.addAll(decl.simpleCollections); + entityMaps.addAll(decl.entityMaps); + simpleMaps.addAll(decl.simpleMaps); entityFields.addAll(decl.entityFields); simpleFields.addAll(decl.simpleFields); stringFields.addAll(decl.stringFields); @@ -152,7 +168,7 @@ public class TypeDecl implements Comparable{ public static class FieldDecl implements Comparable{ private final FieldType fieldType; - private String name, typeName, simpleTypeName; + private String name, keyTypeName, typeName, simpleTypeName; public FieldDecl(FieldDeclaration field) { name = field.getSimpleName(); String type = field.getType().toString(); @@ -160,11 +176,21 @@ public class TypeDecl implements Comparable{ typeName = field.getType().toString(); if (typeName.contains("<")){ typeName = typeName.substring(typeName.lastIndexOf('<')+1, typeName.length()-1); - if (forType(typeName) == FieldType.ENTITY){ - fieldType = FieldType.ENTITYCOLLECTION; + if (typeName.contains(",")){ + keyTypeName = typeName.substring(0, typeName.indexOf(',')); + typeName = typeName.substring(keyTypeName.length()+1); + if (forType(typeName) == FieldType.ENTITY){ + fieldType = FieldType.ENTITYMAP; + }else{ + fieldType = FieldType.SIMPLEMAP; + } }else{ - fieldType = FieldType.SIMPLECOLLECTION; - } + if (forType(typeName) == FieldType.ENTITY){ + fieldType = FieldType.ENTITYCOLLECTION; + }else{ + fieldType = FieldType.SIMPLECOLLECTION; + } + } }else{ fieldType = forType(typeName); } @@ -204,6 +230,10 @@ public class TypeDecl implements Comparable{ return simpleTypeName; } + public String getKeyTypeName(){ + return keyTypeName; + } + public String getTypeName(){ return typeName; } @@ -215,7 +245,10 @@ public class TypeDecl implements Comparable{ } public enum FieldType{ - BOOLEAN, ENTITY, ENTITYCOLLECTION, SIMPLE, SIMPLECOLLECTION, STRING + BOOLEAN, + ENTITY, ENTITYCOLLECTION, ENTITYMAP, + SIMPLE, SIMPLECOLLECTION, SIMPLEMAP, + STRING } public static class ParameterDecl implements Comparable{ diff --git a/querydsl-apt/src/main/resources/querydsl-hibernate.ftl b/querydsl-apt/src/main/resources/querydsl-hibernate.ftl index 0bac25842..70b91b87c 100644 --- a/querydsl-apt/src/main/resources/querydsl-hibernate.ftl +++ b/querydsl-apt/src/main/resources/querydsl-hibernate.ftl @@ -33,6 +33,12 @@ ${include} <#list decl.simpleFields as field> public final PathComparable<${field.typeName}> ${field.name} = _comparable("${field.name}",${field.typeName}.class); + <#list decl.entityMaps as field> + public final PathEntityMap<${field.keyTypeName},${field.typeName}> ${field.name} = _entitymap("${field.name}",${field.keyTypeName}.class,${field.typeName}.class); + + <#list decl.simpleMaps as field> + public final PathComponentMap<${field.keyTypeName},${field.typeName}> ${field.name} = _simplemap("${field.name}",${field.keyTypeName}.class,${field.typeName}.class); + <#list decl.entityCollections as field> public final PathEntityCollection<${field.typeName}> ${field.name} = _entitycol("${field.name}",${field.typeName}.class); public ${pre}${field.simpleTypeName} ${field.name}(int index) {