use of org.ehrbase.client.aql.field.AqlField in project openEHR_SDK by ehrbase.
the class RecordGenerator method buildQuery.
private void buildQuery(HashMap<Integer, TypeSpec> typeSpecHashMap) throws IOException {
TypeSpec.Builder builder = TypeSpec.interfaceBuilder("Query");
builder.addTypeVariable(TypeVariableName.get("T", Record.class));
builder.addModifiers(Modifier.PUBLIC);
builder.addMethod(MethodSpec.methodBuilder("buildAql").addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).returns(String.class).build());
builder.addMethod(MethodSpec.methodBuilder("fields").addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).returns(ArrayTypeName.of(ParameterizedTypeName.get(ClassName.get(AqlField.class), TypeName.OBJECT))).build());
builder.addMethod(MethodSpec.methodBuilder("buildEntityQuery").addModifiers(Modifier.STATIC, Modifier.PUBLIC).addParameter(ContainmentExpression.class, "containment").addParameter(ArrayTypeName.of(ParameterizedTypeName.get(ClassName.get(SelectAqlField.class), WildcardTypeName.subtypeOf(Object.class))), "selectFields").addCode("return new EntityQuery<>(containment, selectFields);").varargs(true).returns(ParameterizedTypeName.get(EntityQuery.class, Record.class)).build());
builder.addMethod(MethodSpec.methodBuilder("buildNativeQuery").addModifiers(Modifier.STATIC, Modifier.PUBLIC).addParameter(String.class, "aql").addParameter(ArrayTypeName.of(ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Object.class))), "expected").addCode(CodeBlock.builder().addStatement("return new NativeQuery<>(aql, $T.stream(expected).map(AqlField::create).toArray($T<?>[]::new))", ClassName.get(Arrays.class), ClassName.get(AqlField.class)).build()).varargs(true).returns(ParameterizedTypeName.get(NativeQuery.class, Record.class)).build());
for (int n = 1; n <= MAX_RECORD_SIZE; n++) {
TypeSpec recordNTypeSpec = typeSpecHashMap.get(n);
builder.addMethod(buildEntityQueryMethod(recordNTypeSpec));
builder.addMethod(buildNativeQueryMethod(recordNTypeSpec));
}
TypeSpec typeSpec = builder.build();
JavaFile javaFile = JavaFile.builder(QUERY_PACKAGE_NAME, typeSpec).build();
javaFile.writeTo(DIRECTORY);
}
Aggregations