private MethodSpec findByPrimaryKey0() { String paramNames = primaryKeyParameterSpecList.stream() .map(param -> param.name) .collect(Collectors.joining(", ")); return MethodSpec.methodBuilder("find") .addModifiers(Modifier.PUBLIC) .addParameters(primaryKeyParameterSpecList) .returns(naming.superClassTypeName()) .addStatement("return maybe($L).orElseThrow($T::new)", paramNames, NoResultFoundException.class) .build(); }
private MethodSpec findByPrimaryKey1() { ClassName optionalClassName = ClassName.get(Optional.class); return MethodSpec.methodBuilder("maybe") .addModifiers(Modifier.PUBLIC) .addParameters(primaryKeyParameterSpecList) .returns(ParameterizedTypeName.get(optionalClassName, naming.superClassTypeName())) .addCode(QueryMethodBody.builder(pojoInfo, QueryReturnType.OPTIONAL) .whereExpression(new Where()) .build()) .build(); }
public static TestableContribution of(PojoInfo pojoInfo) { Naming naming = pojoInfo.naming(); TypeName superClassTypeName = naming.superClassTypeName(); ParameterizedTypeName testerTypeName = ParameterizedTypeName.get(TESTER, naming.superClass()); return superClassTypeName instanceof ParameterizedTypeName ? new Generic(pojoInfo, testerTypeName) : new TestableContribution(pojoInfo, testerTypeName); }
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(); }
public static PojoClass of(PojoInfo pojoInfo, TypeInfo typeInfo) { Naming naming = pojoInfo.naming(); TypeSpec.Builder type = TypeSpec .classBuilder(naming.pojoSimpleName()) .addModifiers(Modifier.FINAL) .superclass(naming.superClassTypeName()); naming.typeVariableNameListTo(type); List<InvalidateMethod> invalidateMethodList = InvalidateMethod.of(typeInfo); return new PojoClass(pojoInfo, type, invalidateMethodList); }
public static PojoClass of(PojoInfo pojoInfo, TypeInfo typeInfo) { Naming naming = pojoInfo.naming(); TypeSpec.Builder type = TypeSpec .classBuilder(naming.pojoSimpleName()) .addModifiers(Modifier.FINAL) .superclass(naming.superClassTypeName()); naming.typeVariableNameListTo(type); List<InvalidateMethod> invalidateMethodList = InvalidateMethod.of(typeInfo); return new PojoClass(pojoInfo, type, invalidateMethodList); }
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 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(); }