/** * Build remove method body for OneToOne relation * * @param field * @param mappedBy * @param builder */ private void buildRemoveOneToOneBody(final FieldMetadata field, final String mappedBy, final InvocableMemberBodyBuilder builder) { final String fieldName = field.getFieldName().getSymbolName(); // Build toString method body /* * if (this.{prop} != null) { * {prop}.set{mappedBy}(null); * } * this.{prop} = null; */ // if (this.{prop} != null) { builder.appendFormalLine(String.format("if (this.%s != null) {", fieldName)); // {prop}.set{mappedBy}(null); builder.indent(); builder.appendFormalLine(String.format("%s.set%s(null);", fieldName, StringUtils.capitalize(mappedBy))); // } builder.indentRemove(); builder.appendFormalLine("}"); // this.{prop} = null; builder.appendFormalLine(String.format("this.%s = null;", fieldName)); }
builder.indentRemove(); builder.appendFormalLine("} else {"); builder.indentRemove(); builder.appendFormalLine("}");
bodyBuilder.indent(); bodyBuilder.appendFormalLine("return false;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine("if (this == " + OBJECT_NAME + ") {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine("return true;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(typeName + " rhs = (" + typeName + ") " + OBJECT_NAME + ";");
builder.indentRemove(); builder.appendFormalLine("}");
builder.indentRemove(); builder.appendFormalLine("}");
builder.indentRemove(); builder.appendFormalLine("}");
builder.indentRemove(); builder.appendFormalLine("}");
bodyBuilder.indentRemove(); bodyBuilder.indentRemove(); bodyBuilder.indentRemove();
getNameOfJavaType(SpringJavaType.MVC_URI_COMPONENTS_BUILDER), getNameOfJavaType(getDestination()), this.showMethod.getMethodName(), entityItemName); body.indentRemove(); body.appendFormalLine(".buildAndExpand(%s.get%s()).encode();", entityItemName, StringUtils.capitalize(entityIdentifier)); body.indentRemove();
private InvocableMemberBodyBuilder getSingularEntityMutator(final FieldMetadata field, final JavaSymbolName hiddenIdFieldName) { final String entityName = field.getFieldName().getSymbolName(); final String entityIdName = hiddenIdFieldName.getSymbolName(); final String identifierMethodName = getIdentifierMethodName(field).getSymbolName(); final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("if (" + entityName + " != null) {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine("if (" + entityName + "." + identifierMethodName + " () == null) {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(entityName + ".persist();"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(THIS_DOT + entityIdName + " = " + entityName + "." + identifierMethodName + "();"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("} else {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(THIS_DOT + entityIdName + " = null;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(THIS_DOT + entityName + " = " + entityName + ";"); return bodyBuilder; }
bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}");
private InvocableMemberBodyBuilder getSingularEntityAccessor(final FieldMetadata field, final JavaSymbolName hiddenIdFieldName) { final String entityName = field.getFieldName().getSymbolName(); final String entityIdName = hiddenIdFieldName.getSymbolName(); final String simpleFieldTypeName = field.getFieldType().getSimpleTypeName(); final String identifierMethodName = getIdentifierMethodName(field).getSymbolName(); final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("if (this." + entityIdName + " != null) {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine("if (this." + entityName + " == null || this." + entityName + "." + identifierMethodName + "() != this." + entityIdName + ") {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(THIS_DOT + entityName + " = " + simpleFieldTypeName + ".find" + simpleFieldTypeName + "(this." + entityIdName + ");"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("} else {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(THIS_DOT + entityName + " = null;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine("return this." + entityName + ";"); return bodyBuilder; }
bodyBuilder.indent(); bodyBuilder.appendFormalLine("return true;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.indent(); bodyBuilder.appendFormalLine("return false;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}");
private String getDigitsBody(final FieldMetadata field, final AnnotationMetadata digitsAnnotation, final String suffix) { final String fieldName = field.getFieldName().getSymbolName(); final JavaType fieldType = field.getFieldType(); final Integer integerValue = (Integer) digitsAnnotation.getAttribute(new JavaSymbolName("integer")).getValue(); final Integer fractionValue = (Integer) digitsAnnotation.getAttribute(new JavaSymbolName("fraction")).getValue(); final BigDecimal maxValue = new BigDecimal(StringUtils.rightPad("9", integerValue, '9') + "." + StringUtils.rightPad("9", fractionValue, '9')); final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); if (fieldType.equals(BIG_DECIMAL)) { bodyBuilder.appendFormalLine("if (" + fieldName + ".compareTo(new " + BIG_DECIMAL.getSimpleTypeName() + "(\"" + maxValue + "\")) == 1) {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(fieldName + " = new " + BIG_DECIMAL.getSimpleTypeName() + "(\"" + maxValue + "\");"); } else { bodyBuilder.appendFormalLine("if (" + fieldName + " > " + maxValue.doubleValue() + suffix + ") {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(fieldName + " = " + maxValue.doubleValue() + suffix + ";"); } bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); return bodyBuilder.getOutput(); }
bodyBuilder.indent(); bodyBuilder.appendFormalLine(INDEX_VAR + " = 0;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine("if (" + INDEX_VAR + " > (" bodyBuilder.appendFormalLine(INDEX_VAR + " = " + getAccessorMethod(getDataField().build()).getMethodName() + "().size() - 1;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine("return %s().get(%s);", getAccessorMethod(getDataField().build())
getNameOfJavaType(SpringJavaType.MVC_URI_COMPONENTS_BUILDER), getNameOfJavaType(getDestination()), this.listMethod.getMethodName()); body.indentRemove(); body.appendFormalLine(".build().encode();"); body.reset();
bodyBuilder.indent(); bodyBuilder.appendFormalLine(localEnitiesName + ".add(entity);"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(THIS_DOT + entityCollectionName + " = " + localEnitiesName + ";");
bodyBuilder.appendFormalLine("query.where(searchCondition);"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}");
bodyBuilder .appendFormalLine(".as(\"Check result number is not greater than the page size\").isLessThanOrEqualTo(3);"); bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine(".concat(%s() + \"/*\").concat(\"' URL.\"));", getAccessorMethod(getServletField()).getMethodName()); bodyBuilder.indentRemove(); bodyBuilder.indentRemove();