private void serialize(Map<Class<?>, EntityType> types, Serializer serializer) throws IOException { for (EntityType entityType : types.values()) { if (serialized.add(entityType)) { Type type = typeMappings.getPathType(entityType, entityType, true); String packageName = type.getPackageName(); String className = packageName.length() > 0 ? (packageName + "." + type.getSimpleName()) : type.getSimpleName(); write(serializer, className.replace('.', '/') + ".java", entityType); } } }
private void serialize(Map<String, EntityType> types, Serializer serializer) throws IOException { for (EntityType entityType : types.values()) { if (serialized.add(entityType)) { Type type = typeMappings.getPathType(entityType, entityType, true); String packageName = entityType.getPackageName(); String className = packageName.length() > 0 ? (packageName + "." + type.getSimpleName()) : type.getSimpleName(); write(serializer, className.replace('.', '/') + sourceSuffix, entityType); } } }
@Override protected void introDefaultInstance(CodeWriter writer, EntityType entityType, String defaultName) throws IOException { String variableName = !defaultName.isEmpty() ? defaultName : namingStrategy.getDefaultVariableName(entityType); String alias = namingStrategy.getDefaultAlias(entityType); Type queryType = typeMappings.getPathType(entityType, entityType, true); writer.publicStaticFinal(queryType, variableName, NEW + queryType.getSimpleName() + "(\"" + alias + "\")"); }
@Override protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException { Type queryType = typeMappings.getPathType(model, model, true); writer.line("@Generated(\"", getClass().getName(), "\")"); TypeCategory category = model.getOriginalCategory(); // serialize annotations only, if no bean types are used if (model.equals(queryType)) { for (Annotation annotation : model.getAnnotations()) { writer.annotation(annotation); } } writer.beginClass(queryType, new ClassType(category, entityPathType, model)); writer.privateStaticFinal(Types.LONG_P, "serialVersionUID", String.valueOf(model.hashCode())); }
@Override protected void customField(EntityType model, Property field, SerializerConfig config, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); String localRawName = writer.getRawName(field.getType()); serialize(model, field, queryType, writer, "create" + field.getType().getSimpleName(), writer.getClassConstant(localRawName)); }
@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()); }