use of core.framework.impl.asm.DynamicInstanceBuilder in project core-ng-project by neowu.
the class InsertQuery method paramBuilder.
private Function<T, Object[]> paramBuilder(Class<T> entityClass, List<Field> paramFields) {
CodeBuilder builder = new CodeBuilder();
String entityClassLiteral = type(entityClass);
builder.append("public Object apply(Object value) {\n").indent(1).append("{} entity = ({}) value;", entityClassLiteral, entityClassLiteral).indent(1).append("Object[] params = new Object[{}];\n", paramFields.size());
int index = 0;
for (Field paramField : paramFields) {
builder.indent(1).append("params[{}] = entity.{};\n", index, paramField.getName());
index++;
}
builder.append("return params;\n").append("}");
DynamicInstanceBuilder<Function<T, Object[]>> dynamicInstanceBuilder = new DynamicInstanceBuilder<>(Function.class, InsertQuery.class.getCanonicalName() + "$" + entityClass.getSimpleName() + "$InsertQueryParamBuilder");
dynamicInstanceBuilder.addMethod(builder.build());
return dynamicInstanceBuilder.build();
}
Aggregations