protected void serialize(EntityType model, Property field, Type type, CodeWriter writer, String factoryMethod, String... args) throws IOException { Supertype superType = model.getSuperType(); // construct value StringBuilder value = new StringBuilder(); if (field.isInherited() && superType != null) { if (!superType.getEntityType().hasEntityFields()) { value.append("_super." + field.getEscapedName()); } } else { value.append(factoryMethod + "(\"" + field.getName() + QUOTE); for (String arg : args) { value.append(COMMA + arg); } value.append(")"); } // serialize it if (field.isInherited()) { writer.line("//inherited"); } if (value.length() > 0) { writer.publicFinal(type, field.getEscapedName(), value.toString()); } else { writer.publicFinal(type, field.getEscapedName()); } }
protected boolean hasOwnEntityProperties(EntityType model) { if (model.hasEntityFields()) { for (Property property : model.getProperties()) { if (!property.isInherited() && property.getType().getCategory() == TypeCategory.ENTITY) { return true; } } } return false; }
Set<TypeCategory> collections = Sets.newHashSet(TypeCategory.COLLECTION, TypeCategory.LIST, TypeCategory.SET); for (Property property : model.getProperties()) { if (!property.isInherited() && collections.contains(property.getType().getCategory())) { inits = true; break;
protected void entityField(EntityType model, Property field, SerializerConfig config, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); if (field.isInherited()) { writer.line("// inherited"); } if (config.useEntityAccessors()) { writer.protectedField(queryType, field.getEscapedName()); } else { writer.publicFinal(queryType, field.getEscapedName()); } }
protected void initEntityField(CodeWriter writer, SerializerConfig config, EntityType model, Property field) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); if (!field.isInherited()) { boolean hasEntityFields = field.getType() instanceof EntityType && ((EntityType) field.getType()).hasEntityFields(); writer.line("this." + field.getEscapedName() + ASSIGN, "inits.isInitialized(\"" + field.getName() + "\") ? ", NEW + writer.getRawName(queryType) + "(forProperty(\"" + field.getName() + "\")", hasEntityFields ? (", inits.get(\"" + field.getName() + "\")") : EMPTY, ") : null;"); } else if (!config.useEntityAccessors()) { writer.line("this.", field.getEscapedName(), ASSIGN, "_super.", field.getEscapedName(), SEMICOLON); } }
protected void initEntityFields(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { Supertype superType = model.getSuperType(); if (superType != null) { EntityType entityType = superType.getEntityType(); if (entityType != null && entityType.hasEntityFields()) { Type superQueryType = typeMappings.getPathType(entityType, model, false); writer.line("this._super = new " + writer.getRawName(superQueryType) + "(type, metadata, inits);"); } } for (Property field : model.getProperties()) { if (field.getType().getCategory() == TypeCategory.ENTITY) { initEntityField(writer, config, model, field); } else if (field.isInherited() && superType != null && superType.getEntityType().hasEntityFields()) { writer.line("this.", field.getEscapedName(), " = _super.", field.getEscapedName(), SEMICOLON); } } }
protected void customField(EntityType model, Property field, SerializerConfig config, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); writer.line("// custom"); if (field.isInherited()) { writer.line("// inherited"); Supertype superType = model.getSuperType(); if (!superType.getEntityType().hasEntityFields()) { String value = NEW + writer.getRawName(queryType) + "(_super." + field.getEscapedName() + ")"; writer.publicFinal(queryType, field.getEscapedName(), value); } else { writer.publicFinal(queryType, field.getEscapedName()); } } else { String value = NEW + writer.getRawName(queryType) + "(forProperty(\"" + field.getName() + "\"))"; writer.publicFinal(queryType, field.getEscapedName(), value); } }