Package org.springframework.roo.classpath.itd

Examples of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder


        final JavaSymbolName methodName = new JavaSymbolName("reset");
        if (governorHasMethod(methodName)) {
            return null;
        }

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine(entityName.getSymbolName() + " = null;");
        for (final FieldMetadata field : locatedFields) {
            final CustomData customData = field.getCustomData();
            if (!customData.keySet().contains(PARAMETER_TYPE_KEY)) {
                continue;
            }

            bodyBuilder.appendFormalLine(getSelectedFieldName(field
                    .getFieldName().getSymbolName()) + " = null;");
        }
        bodyBuilder.appendFormalLine(CREATE_DIALOG_VISIBLE + " = false;");
        return getMethod(PUBLIC, methodName, VOID_PRIMITIVE, null, null,
                bodyBuilder);
    }
View Full Code Here


            final AnnotationMetadata decimalMinAnnotation,
            final AnnotationMetadata decimalMaxAnnotation, final String suffix) {
        final String fieldName = field.getFieldName().getSymbolName();
        final JavaType fieldType = field.getFieldType();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

        if (decimalMinAnnotation != null && decimalMaxAnnotation == null) {
            final String minValue = (String) decimalMinAnnotation.getAttribute(
                    VALUE).getValue();

            if (fieldType.equals(BIG_DECIMAL)) {
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".compareTo(new " + BIG_DECIMAL.getSimpleTypeName()
                        + "(\"" + minValue + "\")) == -1) {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = new "
                        + BIG_DECIMAL.getSimpleTypeName() + "(\"" + minValue
                        + "\");");
            }
            else {
                bodyBuilder.appendFormalLine("if (" + fieldName + " < "
                        + minValue + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + minValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }
        else if (decimalMinAnnotation == null && decimalMaxAnnotation != null) {
            final String maxValue = (String) decimalMaxAnnotation.getAttribute(
                    VALUE).getValue();

            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 + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + maxValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }
        else if (decimalMinAnnotation != null && decimalMaxAnnotation != null) {
            final String minValue = (String) decimalMinAnnotation.getAttribute(
                    VALUE).getValue();
            final String maxValue = (String) decimalMaxAnnotation.getAttribute(
                    VALUE).getValue();
            Validate.isTrue(
                    Double.parseDouble(maxValue) >= Double
                            .parseDouble(minValue),
                    "The value of @DecimalMax must be greater or equal to the value of @DecimalMin for field %s",
                    fieldName);

            if (fieldType.equals(BIG_DECIMAL)) {
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".compareTo(new " + BIG_DECIMAL.getSimpleTypeName()
                        + "(\"" + minValue + "\")) == -1 || " + fieldName
                        + ".compareTo(new " + BIG_DECIMAL.getSimpleTypeName()
                        + "(\"" + maxValue + "\")) == 1) {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = new "
                        + BIG_DECIMAL.getSimpleTypeName() + "(\"" + maxValue
                        + "\");");
            }
            else {
                bodyBuilder.appendFormalLine("if (" + fieldName + " < "
                        + minValue + suffix + " || " + fieldName + " > "
                        + maxValue + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + maxValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }

        return bodyBuilder.getOutput();
    }
View Full Code Here

        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        if (isGaeEnabled) {
            addTransactionalAnnotation(annotations);
        }

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        if (isGaeEnabled) {
            bodyBuilder.appendFormalLine("return "
                    + getFindAllMethod().getMethodName() + "().size();");
        }
        else {
            bodyBuilder.appendFormalLine("return " + ENTITY_MANAGER_METHOD_NAME
                    + "().createQuery(\"SELECT COUNT(o) FROM " + entityName
                    + " o\", Long.class).getSingleResult();");
        }

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
View Full Code Here

        }

        // Create the method
        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

        // Address non-injected entity manager field
        final MethodMetadata entityManagerMethod = getEntityManagerMethod();
        Validate.notNull(entityManagerMethod,
                "Entity manager method should not have returned null");

        // Use the getEntityManager() method to acquire an entity manager (the
        // method will throw an exception if it cannot be acquired)
        final String entityManagerFieldName = getEntityManagerField()
                .getFieldName().getSymbolName();
        bodyBuilder.appendFormalLine("if (this." + entityManagerFieldName
                + " == null) this." + entityManagerFieldName + " = "
                + entityManagerMethod.getMethodName().getSymbolName() + "();");

        JavaType returnType = JavaType.VOID_PRIMITIVE;
        if ("flush".equals(methodDelegateName)) {
            addTransactionalAnnotation(annotations);
            bodyBuilder.appendFormalLine("this." + entityManagerFieldName
                    + ".flush();");
        }
        else if ("clear".equals(methodDelegateName)) {
            addTransactionalAnnotation(annotations);
            bodyBuilder.appendFormalLine("this." + entityManagerFieldName
                    + ".clear();");
        }
        else if ("merge".equals(methodDelegateName)) {
            addTransactionalAnnotation(annotations);
            returnType = new JavaType(destination.getSimpleTypeName());
            bodyBuilder.appendFormalLine(destination.getSimpleTypeName()
                    + " merged = this." + entityManagerFieldName
                    + ".merge(this);");
            bodyBuilder.appendFormalLine("this." + entityManagerFieldName
                    + ".flush();");
            bodyBuilder.appendFormalLine("return merged;");
        }
        else if ("remove".equals(methodDelegateName)) {
            addTransactionalAnnotation(annotations);
            bodyBuilder.appendFormalLine("if (this." + entityManagerFieldName
                    + ".contains(this)) {");
            bodyBuilder.indent();
            bodyBuilder.appendFormalLine("this." + entityManagerFieldName
                    + ".remove(this);");
            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("} else {");
            bodyBuilder.indent();
            bodyBuilder.appendFormalLine(destination.getSimpleTypeName()
                    + " attached = " + destination.getSimpleTypeName() + "."
                    + getFindMethod().getMethodName().getSymbolName()
                    + "(this." + identifierField.getFieldName().getSymbolName()
                    + ");");
            bodyBuilder.appendFormalLine("this." + entityManagerFieldName
                    + ".remove(attached);");
            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }
        else {
            // Persist
            addTransactionalAnnotation(annotations, true);
            bodyBuilder.appendFormalLine("this." + entityManagerFieldName + "."
                    + methodDelegateName + "(this);");
        }

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                getId(), Modifier.PUBLIC, methodName, returnType,
View Full Code Here

        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();
    }
View Full Code Here

        if (governorHasMethod(methodName, parameterTypes)) {
            // Method found in governor so do not create method in ITD
            return null;
        }

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

        // Create constructor for embedded class
        final JavaType embeddedFieldType = embeddedHolder.getEmbeddedField()
                .getFieldType();
        builder.getImportRegistrationResolver().addImport(embeddedFieldType);
        bodyBuilder.appendFormalLine(embeddedFieldType.getSimpleTypeName()
                + " embeddedClass = new "
                + embeddedFieldType.getSimpleTypeName() + "();");
        for (final FieldMetadata field : embeddedHolder.getFields()) {
            bodyBuilder.appendFormalLine(getEmbeddedFieldMutatorMethodName(
                    embeddedHolder.getEmbeddedField().getFieldName(),
                    field.getFieldName()).getSymbolName()
                    + "(embeddedClass, " + INDEX_VAR + ");");
        }
        bodyBuilder.appendFormalLine(OBJ_VAR + "."
                + embeddedHolder.getEmbeddedMutatorMethodName()
                + "(embeddedClass);");

        final List<JavaSymbolName> parameterNames = Arrays.asList(OBJ_SYMBOL,
                INDEX_SYMBOL);
View Full Code Here

        if (governorHasMethod(methodName, parameterTypes)) {
            // Method found in governor so do not create method in ITD
            return null;
        }

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

        // Create constructor for embedded id class
        final JavaType embeddedIdFieldType = embeddedIdHolder
                .getEmbeddedIdField().getFieldType();
        builder.getImportRegistrationResolver().addImport(embeddedIdFieldType);

        final StringBuilder sb = new StringBuilder();
        final List<FieldMetadata> identifierFields = embeddedIdHolder
                .getIdFields();
        for (int i = 0, n = identifierFields.size(); i < n; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            final FieldMetadata field = identifierFields.get(i);
            final String fieldName = field.getFieldName().getSymbolName();
            final JavaType fieldType = field.getFieldType();
            builder.getImportRegistrationResolver().addImport(fieldType);
            final String initializer = getFieldInitializer(field, null);
            bodyBuilder.append(getFieldValidationBody(field, initializer, null,
                    true));
            sb.append(fieldName);
        }
        bodyBuilder.appendFormalLine("");
        bodyBuilder.appendFormalLine(embeddedIdFieldType.getSimpleTypeName()
                + " embeddedIdClass = new "
                + embeddedIdFieldType.getSimpleTypeName() + "(" + sb.toString()
                + ");");
        bodyBuilder.appendFormalLine(OBJ_VAR + "." + embeddedIdMutator
                + "(embeddedIdClass);");

        final List<JavaSymbolName> parameterNames = Arrays.asList(OBJ_SYMBOL,
                INDEX_SYMBOL);
View Full Code Here

        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        if (isGaeEnabled) {
            addTransactionalAnnotation(annotations);
        }
       
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine("return " + ENTITY_MANAGER_METHOD_NAME
                + "().createQuery(\"SELECT o FROM " + entityName + " o\", "
                + destination.getSimpleTypeName() + ".class).getResultList();");

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                getId(), Modifier.PUBLIC | Modifier.STATIC, methodName,
View Full Code Here

        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        if (isGaeEnabled) {
            addTransactionalAnnotation(annotations);
        }
       
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine("String jpaQuery = \"SELECT o FROM " + entityName + " o\";");
        bodyBuilder.appendFormalLine("if (fieldNames4OrderClauseFilter.contains(sortFieldName)) {");
        bodyBuilder.indent();
        bodyBuilder.appendFormalLine("jpaQuery = jpaQuery + \" ORDER BY \" + sortFieldName;");
        bodyBuilder.appendFormalLine("if (\"ASC\".equalsIgnoreCase(sortOrder) || \"DESC\".equalsIgnoreCase(sortOrder)) {");
        bodyBuilder.indent();
        bodyBuilder.appendFormalLine("jpaQuery = jpaQuery + \" \" + sortOrder;");
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");
        bodyBuilder.appendFormalLine("return " + ENTITY_MANAGER_METHOD_NAME
            + "().createQuery(jpaQuery, " + destination.getSimpleTypeName() + ".class" + ").getResultList();");

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                getId(), Modifier.PUBLIC | Modifier.STATIC, methodName,
                returnType,
View Full Code Here

            }

            // Method not on governor so need to create it
            final String initializer = entry.getValue();
            if (!StringUtils.isBlank(initializer)) {
                final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
                bodyBuilder.append(getFieldValidationBody(field, initializer,
                        mutatorName, false));

                fieldMutatorMethods.add(new MethodMetadataBuilder(getId(),
                        Modifier.PUBLIC, mutatorName, JavaType.VOID_PRIMITIVE,
                        AnnotatedJavaType.convertFromJavaTypes(parameterTypes),
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.