private static void registerTypes(TypeMappings typeMappings) { Map<Class<?>, Class<?>> mappings = Maps.newHashMap(); mappings.put(GeometryCollection.class, GeometryCollectionPath.class); mappings.put(Geometry.class, GeometryPath.class); mappings.put(LinearRing.class, LinearRingPath.class); mappings.put(LineString.class, LineStringPath.class); mappings.put(MultiLineString.class, MultiLineStringPath.class); mappings.put(MultiPoint.class, MultiPointPath.class); mappings.put(MultiPolygon.class, MultiPolygonPath.class); mappings.put(Point.class, PointPath.class); mappings.put(Polygon.class, PolygonPath.class); mappings.put(PolyHedralSurface.class, PolyhedralSurfacePath.class); for (Map.Entry<Class<?>, Class<?>> entry : mappings.entrySet()) { Type type = new ClassType(entry.getKey()); typeMappings.register(type, new ClassType(entry.getValue(), type)); } }
private EntityType createEntityType(Class<?> cl, Map<Class<?>, EntityType> types) { if (allTypes.containsKey(cl)) { return allTypes.get(cl); } else { EntityType type = typeFactory.getEntityType(cl); typeMappings.register(type, queryTypeFactory.create(type)); if (!cl.getSuperclass().equals(Object.class)) { type.addSupertype(new Supertype(typeFactory.get(cl.getSuperclass(), cl.getGenericSuperclass()))); } types.put(cl, type); allTypes.put(cl, type); return type; } }
private EntityType createEntityType(Class<?> cl, Map<String, EntityType> types) { if (types.containsKey(cl.getName())) { return types.get(cl.getName()); } else { EntityType type = new EntityType(new ClassType(TypeCategory.ENTITY, cl)); typeMappings.register(type, queryTypeFactory.create(type)); if (cl.getSuperclass() != null && !cl.getSuperclass().equals(Object.class)) { type.addSupertype(new Supertype(new ClassType(cl.getSuperclass()))); } types.put(cl.getName(), type); allTypes.put(cl.getName(), type); return type; } }
protected EntityType createEntityType(Type type, Map<Class<?>, EntityType> types) { Class<?> key = type.getJavaClass(); if (allTypes.containsKey(key)) { return allTypes.get(key); } else { EntityType entityType = new EntityType(type, variableNameFunction); typeMappings.register(entityType, queryTypeFactory.create(entityType)); Class<?> superClass = key.getSuperclass(); if (entityType.getSuperType() == null && superClass != null && !superClass.equals(Object.class)) { entityType.addSupertype(new Supertype(typeFactory.get(superClass, key.getGenericSuperclass()))); } types.put(key, entityType); allTypes.put(key, entityType); return entityType; } }
@Test public void OriginalCategory() throws IOException{ Map<TypeCategory, String> categoryToSuperClass = new EnumMap<TypeCategory, String>(TypeCategory.class); categoryToSuperClass.put(TypeCategory.COMPARABLE, "ComparablePath<Entity>"); categoryToSuperClass.put(TypeCategory.ENUM, "EnumPath<Entity>"); categoryToSuperClass.put(TypeCategory.DATE, "DatePath<Entity>"); categoryToSuperClass.put(TypeCategory.DATETIME, "DateTimePath<Entity>"); categoryToSuperClass.put(TypeCategory.TIME, "TimePath<Entity>"); categoryToSuperClass.put(TypeCategory.NUMERIC, "NumberPath<Entity>"); categoryToSuperClass.put(TypeCategory.STRING, "StringPath"); categoryToSuperClass.put(TypeCategory.BOOLEAN, "BooleanPath"); for (Map.Entry<TypeCategory, String> entry : categoryToSuperClass.entrySet()) { SimpleType type = new SimpleType(entry.getKey(), "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(entry.toString(), writer.toString().contains("public class QEntity extends "+entry.getValue()+" {")); } }
@Test public void OriginalCategory() throws IOException{ Map<TypeCategory, String> categoryToSuperClass = new EnumMap<TypeCategory, String>(TypeCategory.class); categoryToSuperClass.put(TypeCategory.COMPARABLE, "ComparablePath<Entity>"); categoryToSuperClass.put(TypeCategory.ENUM, "EnumPath<Entity>"); categoryToSuperClass.put(TypeCategory.DATE, "DatePath<Entity>"); categoryToSuperClass.put(TypeCategory.DATETIME, "DateTimePath<Entity>"); categoryToSuperClass.put(TypeCategory.TIME, "TimePath<Entity>"); categoryToSuperClass.put(TypeCategory.NUMERIC, "NumberPath<Entity>"); categoryToSuperClass.put(TypeCategory.STRING, "StringPath"); categoryToSuperClass.put(TypeCategory.BOOLEAN, "BooleanPath"); for (Map.Entry<TypeCategory, String> entry : categoryToSuperClass.entrySet()) { SimpleType type = new SimpleType(entry.getKey(), "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(entry.toString(), writer.toString().contains("public class QEntity extends "+entry.getValue()+" {")); } }
protected EntityType createEntityType(@Nullable String schemaName, String tableName, final String className) { EntityType classModel; if (beanSerializer == null) { String packageName = normalizePackage(module.getPackageName(), schemaName); String simpleName = module.getPrefix() + className + module.getSuffix(); Type classTypeModel = new SimpleType(TypeCategory.ENTITY, packageName + "." + simpleName, packageName, simpleName, false, false); classModel = new EntityType(classTypeModel, module.get(Function.class, CodegenModule.VARIABLE_NAME_FUNCTION_CLASS)); typeMappings.register(classModel, classModel); } else { String beanPackage = normalizePackage(beanPackageName, schemaName); String simpleName = module.getBeanPrefix() + className + module.getBeanSuffix(); Type classTypeModel = new SimpleType(TypeCategory.ENTITY, beanPackage + "." + simpleName, beanPackage, simpleName, false, false); classModel = new EntityType(classTypeModel, module.get(Function.class, CodegenModule.VARIABLE_NAME_FUNCTION_CLASS)); Type mappedType = queryTypeFactory.create(classModel); entityToWrapped.put(classModel, mappedType); typeMappings.register(classModel, mappedType); } classModel.getData().put("schema", schemaName); classModel.getData().put("table", tableName); return classModel; }
@Test public void Correct_Imports() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "test.Entity", "test", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("import test.Entity;")); assertTrue(writer.toString().contains("public class QEntity extends EntityPathBase<Entity> {")); }
@Test public void No_Package() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public class QEntity extends BeanPath<Entity> {")); }
@Test public void No_Package() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public class QEntity extends EntityPathBase<Entity> {")); }
@Test public void SuperType() throws IOException{ EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType))); typeMappings.register(superType, queryTypeFactory.create(superType)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);")); }
@Test public void Correct_Superclass() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "java.util.Locale", "java.util", "Locale",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); // System.out.println(writer); assertTrue(writer.toString().contains("public class QLocale extends EntityPathBase<Locale> {")); }
@Test public void Correct_Superclass() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "java.util.Locale", "java.util", "Locale",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); //System.out.println(writer); assertTrue(writer.toString().contains("public class QLocale extends BeanPath<Locale> {")); }
@Test public void SuperType() throws IOException{ EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType))); typeMappings.register(superType, queryTypeFactory.create(superType)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);")); }
@Test public void Javadocs_For_InnerClass() throws IOException{ EntityType entityType = new EntityType(new ClassType(Entity.class)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("QEntitySerializerTest_Entity is a Querydsl query type for Entity")); }
@Test public void Different_Package() throws IOException { queryTypeFactory = new QueryTypeFactoryImpl("Q", "", ".gen"); EntityType entityType = new EntityType(new ClassType(Entity.class)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); // System.err.println(writer.toString()); assertTrue(writer.toString().contains("public class QEntitySerializerTest_Entity " + "extends EntityPathBase<EntitySerializerTest.Entity>")); }
@Test public void CustomType() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); entityType.addProperty(new Property(entityType, "property", new ClassType(Double[].class))); typeMappings.register(new ClassType(Double[].class), new ClassType(Point.class)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); assertTrue(typeMappings.isRegistered(entityType.getProperties().iterator().next().getType())); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains( "public final com.mysema.query.codegen.Point property = " + "new com.mysema.query.codegen.Point(forProperty(\"property\"));")); }
@Test public void IsRegistered() { TypeMappings typeMappings = new JavaTypeMappings(); typeMappings.register(new ClassType(Double[].class), new ClassType(Point.class)); assertTrue(typeMappings.isRegistered(new ClassType(Double[].class))); }
@Test public void GetPathType_Of_InnerClass() { TypeMappings typeMappings = new JavaTypeMappings(); EntityType model = new EntityType(new ClassType(TypeMappingsTest.class)); EntityType type = new EntityType(new ClassType(Entity.class)); typeMappings.register(type, new QueryTypeFactoryImpl("Q","","").create(type)); Type pathType = typeMappings.getPathType(type, model, false); assertEquals("QTypeMappingsTest_Entity", pathType.getSimpleName()); }