private MethodSpec load1() { return MethodSpec.methodBuilder("load") .addModifiers(Modifier.PUBLIC) .returns(naming.superClassTypeName()) .addParameters(parameterSpecList) .addParameter(pojoInfo.rowParameterSpec()) .addCode("return new $T($L, ", naming.pojo(), inject.name()) .addCode(Joiner.on(", ") .addAll(parameterSpecList.stream().map(spec -> spec.name)) .add("row") .join()) .addStatement(")") .build(); }
private MethodSpec load0() { return MethodSpec.methodBuilder("load") .addModifiers(Modifier.PUBLIC) .returns(naming.superClassTypeName()) .addParameters(parameterSpecList) .addParameters(pojoInfo.foreignKeyParameterSpecList()) .addParameter(pojoInfo.rowParameterSpecColumns()) .addCode("return new $T($L, ", naming.pojo(), inject.name()) .addCode(Joiner.on(", ") .addAll(parameterSpecList.stream().map(spec -> spec.name)) .addAll(pojoInfo.foreignKeyPropertyList().stream().map(OrmProperty::name)) .add("row") .join()) .addStatement(")") .build(); }
private MethodSpec load() { CodeBlock.Builder body = CodeBlock.builder() .addStatement("$1T rs = new $1T($2S, resultSet)", ResultSetWrapper.class, tableSimpleName()) .add("return new $T(", naming.pojo()) .add("\n $L", inject.name()); pojoInfo.constructorContextList() .stream() .flatMap(ConstructorContext::parameterInfoStream) .map(ParameterInfo::name) .forEach(name -> body.add(",\n $L", name)); pojoInfo.propertyList() .stream() .sorted() .map(property -> property.adapt(IsRelationalLoaderLoadMethod.INSTANCE)) .forEach(body::add); body.add(");\n"); return MethodSpec.methodBuilder("load") .addAnnotation(Override.class) .addModifiers(Modifier.PUBLIC) .addParameter(ResultSet.class, "resultSet") .returns(naming.superClass()) .addCode(body.build()) .build(); }
private CodeBlock body() { CodeBlock.Builder body = CodeBlock.builder() .add("return new $T(", pojoInfo.naming().pojo()) .add("\n $L", pojoInfo.inject().name()); pojoInfo.propertyList().stream() .sorted() .forEach(property -> property.acceptSetterMethodBody(body, parameterMap)); return body .addStatement(")") .build(); }
@Override public CodeBlock get() { Naming naming = pojoInfo.naming(); OrmInject inject = pojoInfo.inject(); ClassName ownerClassName = ownerPojoInfo.naming().pojo(); CodeBlock.Builder collectCode = CodeBlock.builder() .add("row -> $T.get($L).load(", naming.superClassSuffix("Orm"), inject.name()); Iterator<ReturnType> retIterator = returnTypeList.iterator(); while (retIterator.hasNext()) { ReturnType retType = retIterator.next(); retType.acceptQueryCollectExpression(collectCode, ownerClassName); collectCode.add(", "); } return returnType.collect(collectCode .add("row)") .build()); }
private MethodSpec companionTypeInsertAll(CompanionType type) { Naming naming = type.naming(); OrmInject inject = type.inject(); return MethodSpec.methodBuilder("insertAll") .addModifiers(Modifier.PUBLIC) .addParameter(OrmNaming.iterableOf(naming.superClassTypeName()), "entities") .addStatement("$T iterator = entities.iterator()", OrmNaming.iteratorOf(naming.superClassTypeName())) .addCode(CodeBlock.builder() .beginControlFlow("if (!iterator.hasNext())") .addStatement("return") .endControlFlow() .build()) .addStatement("$1T pojo = ($1T) iterator.next()", naming.pojo()) .addCode(tableInfo().tableGetCode()) .addStatement("$T insert", insertableRowValuesTypeName()) .addCode("insert = pojo.bindInsertableRow(") .addCode(tableInfo().insertIntoCode()) .addCode(");\n") .addCode(CodeBlock.builder() .beginControlFlow("while(iterator.hasNext())") .addStatement("pojo = ($T) iterator.next()", naming.pojo()) .addStatement("insert = pojo.bindInsertableRow(insert)") .endControlFlow() .build()) .addStatement("$L.executeUnchecked(insert)", inject.name()) .build(); }