Example usage for org.apache.commons.lang3 StringUtils uncapitalize

List of usage examples for org.apache.commons.lang3 StringUtils uncapitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils uncapitalize.

Prototype

public static String uncapitalize(final String str) 

Source Link

Document

Uncapitalizes a String, changing the first letter to lower case as per Character#toLowerCase(char) .

Usage

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Returns <code>findAll</code> method for render-a-view visualization mode. <br>
 * This method handles datatables AJAX request for data which are no related
 * to a Roo Dynamic finder./*from  w ww  .j  a  va  2s .c o m*/
 * 
 * @return
 */
private MethodMetadata getFindAllMethodRenderMode() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    parameterTypes.add(new AnnotatedJavaType(DATATABLES_CRITERIA_TYPE,
            new AnnotationMetadataBuilder(DATATABLES_PARAMS).build()));
    parameterTypes.add(new AnnotatedJavaType(entity, new AnnotationMetadataBuilder(MODEL_ATTRIBUTE).build()));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_RESPONSE));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(findAllMethodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

    // Define method annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder();
    methodAnnotation.setAnnotationType(REQUEST_MAPPING);
    methodAnnotation.addStringAttribute(HEADERS, ACCEPT_APPLICATION_JSON);
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_VAL_NAME, "/datatables/ajax");
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_PROD_NAME, APPLICATION_JSON);
    annotations.add(methodAnnotation);
    annotations.add(new AnnotationMetadataBuilder(RESPONSE_BODY));

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();
    throwsTypes.add(SERVLET_EXCEPTION);
    throwsTypes.add(IO_EXCEPTION);

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(CRITERIA_PARAM_NAME);
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entityName)));
    parameterNames.add(REQUEST_PARAM_NAME);
    parameterNames.add(RESPONSE_PARAM_NAME);

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildFindAllMethodBodyRenderMode(bodyBuilder);

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, findAllMethodName,
            FIND_ALL_RETURN, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Build method-code to call Datatables.findByCriteria method. <br>
 * Generated code will depend on entity has JPAQuery metadata and if there
 * is a base search./*from w  w  w  . ja  va 2  s . co  m*/
 * 
 * @param bodyBuilder
 * @param baseSearch
 * @return
 */
private String buildFindByCriteriaCallMethodBody(InvocableMemberBodyBuilder bodyBuilder, boolean baseSearch) {
    final String entityTypeName = helper.getFinalTypeName(entity);
    JavaType searchResult = new JavaType(SEARCH_RESULTS.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
            Arrays.asList(entity));

    if (jpaQueryMetadata != null) {
        String filterByInfo = String.format("%s.%s()", entityTypeName,
                jpaQueryMetadata.getFilterByMethodName().getSymbolName());
        String orderByInfo = String.format("%s.%s()", entityTypeName,
                jpaQueryMetadata.getOrderByMethodName().getSymbolName());

        // SearchResults<Pet> searchResult =
        // datatablesUtilsBean_dtt.findByCriteria(entity, criterias,
        // baseSearch);

        if (baseSearch) {
            bodyBuilder.appendFormalLine(
                    String.format("%s searchResult = %s.findByCriteria(entity, %s, baseSearch);",
                            helper.getFinalTypeName(searchResult), getDatatablesUtilsBeanName(),
                            CRITERIA_PARAM_NAME.getSymbolName()));

        } else {

            bodyBuilder.appendFormalLine(PARAMETERS_AS_BASE_SEARCH);
            // Map<String, Object> baseSearchValuesMap = getPropertyMap(pet,
            // request);
            bodyBuilder.appendFormalLine(String.format("%s baseSearchValuesMap = getPropertyMap(%s, request);",
                    helper.getFinalTypeName(MAP_STRING_OBJECT),
                    new JavaSymbolName(StringUtils.uncapitalize(entityName))));

            // setVisitFilters(baseSearchValuesMap);
            bodyBuilder.appendFormalLine("setDatatablesBaseFilter(baseSearchValuesMap);");

            // SearchResults<Pet> searchResult =
            // datatablesUtilsBean_dtt.findByCriteria(Pet.class,
            // Pet.getFilterByAssociations(),
            // Pet.getOrderByAssociations(), criteria, baseSearchValuesMap);
            bodyBuilder.appendFormalLine(String.format(
                    "%s searchResult = %s.findByCriteria(%s.class, %s, %s, %s, baseSearchValuesMap);",
                    helper.getFinalTypeName(searchResult), getDatatablesUtilsBeanName(), entityTypeName,
                    filterByInfo, orderByInfo, CRITERIA_PARAM_NAME.getSymbolName()));
        }
    } else {

        // SearchResults<Pet> searchResult =
        // datatablesUtilsBean_dtt.findByCriteria(entity, criterias,
        // baseSearch);
        if (baseSearch) {
            bodyBuilder.appendFormalLine(
                    String.format("%s searchResult = %s.findByCriteria(entity, %s, baseSearch);",
                            helper.getFinalTypeName(searchResult), getDatatablesUtilsBeanName(),
                            CRITERIA_PARAM_NAME.getSymbolName()));
        } else {

            bodyBuilder.appendFormalLine(PARAMETERS_AS_BASE_SEARCH);
            // Map<String, Object> baseSearchValuesMap = getPropertyMap(pet,
            // request);
            bodyBuilder.appendFormalLine(String.format("%s baseSearchValuesMap = getPropertyMap(%s, request);",
                    helper.getFinalTypeName(MAP_STRING_OBJECT), StringUtils.uncapitalize(entityName)));

            // setVisitFilters(baseSearchValuesMap);
            bodyBuilder.appendFormalLine("setDatatablesBaseFilter(baseSearchValuesMap);");

            // SearchResults<Pet> searchResult =
            // datatablesUtilsBean_dtt.findByCriteria(Pet.class,
            // criterias, baseSearch);

            bodyBuilder.appendFormalLine(
                    String.format("%s searchResult = %s.findByCriteria(%s.class, %s, baseSearchValuesMap);",
                            helper.getFinalTypeName(searchResult), getDatatablesUtilsBeanName(), entityTypeName,
                            CRITERIA_PARAM_NAME.getSymbolName()));
        }

    }

    bodyBuilder.appendFormalLine("");
    bodyBuilder.appendFormalLine("// Get datatables required counts");
    // long totalRecords = searchResult.getTotalCount();
    bodyBuilder.appendFormalLine("long totalRecords = searchResult.getTotalCount();");
    // long recordsFound = findResult.getResultsCount();
    bodyBuilder.appendFormalLine("long recordsFound = searchResult.getResultsCount();");
    return entityTypeName;
}

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Returns export method for a specific format for a render-a-view
 * visualization mode./*from   ww w  .jav  a2  s.c  o m*/
 * <p />
 * This method handles datatables AJAX request for export data to a format
 * specified in the @{code exportType} parameter.
 * 
 * @param exportType the export type: csv, xml, pdf, etc.
 * @param exportTypeJavaType the @{code JavaType} of the export type.
 * @return
 */
private MethodMetadata getExportFormatMethod(String exportType, JavaType exportTypeJavaType) {

    String exportTypeUpperCase = StringUtils.upperCase(exportType);
    String exportTypeCapitalized = StringUtils.capitalize(exportType);

    /*
     * @RequestMapping(value = "/exportcsv", produces = "text/csv") public
     * void PetController.exportCsv(
     *
     * @DatatablesParams DatatablesCriterias criterias,
     *
     * @ModelAttribute Pet pet, HttpServletRequest request,
     * HttpServletResponse response) throws ServletException, IOException,
     * ExportException { ... }
     */
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(DATATABLES_CRITERIA_TYPE,
            new AnnotationMetadataBuilder(DATATABLES_PARAMS).build()));
    parameterTypes.add(new AnnotatedJavaType(entity, new AnnotationMetadataBuilder(MODEL_ATTRIBUTE).build()));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_RESPONSE));

    // Building method name
    JavaSymbolName methodName = new JavaSymbolName("export".concat(exportTypeCapitalized));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(methodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

    // Define method annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder();
    methodAnnotation.setAnnotationType(REQUEST_MAPPING);
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_VAL_NAME,
            "/export".concat(exportType));
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_PROD_NAME, "text/".concat(exportType));
    annotations.add(methodAnnotation);

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();
    throwsTypes.add(SERVLET_EXCEPTION);
    throwsTypes.add(IO_EXCEPTION);
    throwsTypes.add(DATATABLES_EXPORT_EXCEPTION);

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(CRITERIA_PARAM_NAME);
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entityName)));
    parameterNames.add(REQUEST_PARAM_NAME);
    parameterNames.add(RESPONSE_PARAM_NAME);

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    /*
     * export(criterias, pet, ExportType.CSV, new CsvExport(), request,
     * response);
     */
    String format = "export(%s, %s, %s.".concat(exportTypeUpperCase).concat(", new %s(), %s, %s);");
    bodyBuilder.appendFormalLine(String.format(format, CRITERIA_PARAM_NAME.getSymbolName(),
            StringUtils.uncapitalize(entityName), helper.getFinalTypeName(DATATABLES_EXPORT_TYPE),
            helper.getFinalTypeName(exportTypeJavaType), REQUEST_PARAM_NAME.getSymbolName(),
            RESPONSE_PARAM_NAME.getSymbolName()));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
            JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Returns <code>export</code> method for a render-a-view visualization
 * mode.// ww  w .  java  2 s. c  o  m
 * <p />
 * This is a private method that handles datatables AJAX request for a
 * specific format.
 * 
 * @return
 */
private MethodMetadata getExportMethod() {

    /*
     * private void export(DatatablesCriterias criterias, Pet pet,
     * ExportType exportType, DatatablesExport datatablesExport,
     * HttpServletRequest request, HttpServletResponse response) throws
     * ExportException { ... }
     */
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(DATATABLES_CRITERIA_TYPE));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(entity));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(DATATABLES_EXPORT_TYPE));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(DATATABLES_EXPORT));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_RESPONSE));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(EXPORT_METHOD_NAME, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();
    throwsTypes.add(DATATABLES_EXPORT_EXCEPTION);

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(CRITERIA_PARAM_NAME);
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entityName)));
    parameterNames.add(DATATABLES_EXPORT_TYPE_NAME);
    parameterNames.add(DATATABLES_EXPORT_NAME);
    parameterNames.add(REQUEST_PARAM_NAME);
    parameterNames.add(RESPONSE_PARAM_NAME);

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    /*
     * // Does the export process as is explained in
     * http://dandelion.github.
     * io/datatables/tutorials/export/controller-based-exports.html // 1.
     * Retrieve the data List<Map<String, String>> data =
     * retrieveData(criterias, pet, request);
     */
    bodyBuilder.appendFormalLine(
            "// Does the export process as is explained in http://dandelion.github.io/datatables/tutorials/export/controller-based-exports.html");
    bodyBuilder.appendFormalLine("// 1. Retrieve the data");
    String format = "%s data = retrieveData(%s, %s, %s);";
    bodyBuilder.appendFormalLine(String.format(format, helper.getFinalTypeName(LIST_MAP_STRING_STRING),
            CRITERIA_PARAM_NAME.getSymbolName(), new JavaSymbolName(StringUtils.uncapitalize(entityName)),
            REQUEST_PARAM_NAME.getSymbolName()));

    /*
     * // 2. Build an instance of "ExportConf". ExportConf exportConf = new
     * ExportConf.Builder(exportType).header(true)
     * .exportClass(datatablesExport).autoSize(true)
     * .fileName(pet.getClass().getSimpleName()).build();
     */
    bodyBuilder.appendFormalLine("// 2. Build an instance of \"ExportConf\"");
    format = "%s exportConf = new %s.Builder(%s).header(true).exportClass(%s).autoSize(true).fileName(%s.getClass().getSimpleName()).build();";
    bodyBuilder.appendFormalLine(String.format(format, helper.getFinalTypeName(DATATABLES_EXPORT_CONF),
            helper.getFinalTypeName(DATATABLES_EXPORT_CONF), DATATABLES_EXPORT_TYPE_NAME.getSymbolName(),
            DATATABLES_EXPORT_NAME.getSymbolName(), StringUtils.uncapitalize(entityName)));

    /*
     * // 3. Build an instance of "HtmlTable" HtmlTable table =
     * datatablesUtilsBean_dtt.makeHtmlTable(data, criterias, exportConf, request);
     */
    bodyBuilder.appendFormalLine("// 3. Build an instance of \"HtmlTable\"");
    format = "%s table = %s.makeHtmlTable(data, %s, exportConf, %s);";
    bodyBuilder.appendFormalLine(
            String.format(format, helper.getFinalTypeName(DATATABLES_HTML_TABLE), getDatatablesUtilsBeanName(),
                    CRITERIA_PARAM_NAME.getSymbolName(), REQUEST_PARAM_NAME.getSymbolName()));

    /*
     * // 4. Render the generated export file
     * ExportUtils.renderExport(table, exportConf, response);
     */
    bodyBuilder.appendFormalLine("// 4. Render the generated export file");
    format = "%s.renderExport(table, exportConf, %s);";
    bodyBuilder.appendFormalLine(String.format(format, helper.getFinalTypeName(DATATABLES_EXPORT_UTILS),
            RESPONSE_PARAM_NAME.getSymbolName()));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
            EXPORT_METHOD_NAME, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditListenerMetadata.java

public JpaAuditListenerMetadata(String identifier, JavaType aspectName,
        PhysicalTypeMetadata governorPhysicalTypeMetadata, JpaAuditListenerAnnotationValues annotationValues,
        JavaType entity, JpaAuditMetadata auditMetadata, JavaType userType, JavaType userService) {
    super(identifier, aspectName, governorPhysicalTypeMetadata);
    Validate.isTrue(isValid(identifier),
            "Metadata identification string '" + identifier + "' does not appear to be a valid");

    // Helper itd generation
    this.helper = new ItdBuilderHelper(this, governorPhysicalTypeMetadata,
            builder.getImportRegistrationResolver());

    this.isEntityAbstract = auditMetadata.isAbstractEntity();

    this.annotationValues = annotationValues;
    this.entity = entity;
    this.entityParamName = new JavaSymbolName(StringUtils.uncapitalize(entity.getSimpleTypeName()));

    this.auditMetadata = auditMetadata;

    this.userType = userType;
    this.userService = userService;

    if (!isEntityAbstract) {
        // Add listener methods (only in non-abstract entities)
        builder.addMethod(getOnCreateMethod());
        builder.addMethod(getOnUpdateMethod());
    }//from   ww  w .  j  a v  a  2s.c  o m

    // Create a representation of the desired output ITD
    itdTypeDetails = builder.build();
}

From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java

/**
 * @return Creates constructor for XXRevsion class
 *///from w w  w  . ja  va  2 s.  c  o  m
private ConstructorMetadata createRevisionItemConstructor() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(2);
    parameterTypes.add(new AnnotatedJavaType(context.getEntity()));
    parameterTypes.add(new AnnotatedJavaType(revisionEntityMetadata.getType()));
    parameterTypes.add(new AnnotatedJavaType(REVISON_TYPE));

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(3);
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(context.getEntityName())));
    parameterNames.add(REV_ITEM_REVISON_ENTITY_FIELD);
    parameterNames.add(REV_ITEM_REVISON_TYPE_FIELD);

    // Create the method body
    InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder();

    helper.buildSetterMethodBody(body, parameterNames.get(0));
    helper.buildSetterMethodBody(body, parameterNames.get(1));
    helper.buildSetterMethodBody(body, parameterNames.get(2));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    ConstructorMetadataBuilder builder = new ConstructorMetadataBuilder(context.getMetadataId());

    builder.setParameterTypes(parameterTypes);
    builder.setParameterNames(parameterNames);
    builder.setModifier(Modifier.PUBLIC);
    builder.setAnnotations(annotations);
    builder.setThrowsTypes(throwsTypes);
    builder.setBodyBuilder(body);

    return builder.build(); // Build and return a MethodMetadata
}

From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java

/**
 * @param context/*from   w w  w.java  2s  .  c  o  m*/
 * @return XXXRevision.item field name
 */
private JavaSymbolName getRevisionItemFieldName() {
    if (revisionItemFielName == null) {
        revisionItemFielName = new JavaSymbolName(StringUtils.uncapitalize(context.getEntityName()));
    }
    return revisionItemFielName;
}

From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchMetadata.java

/**
 * Builds body method for <code>deleteByValues</code> method. <br>
 * This method performs a delete base on property values condition (value
 * equal and concatenates conditions using "and" operator)
 * // w w  w .  j av  a  2s  . com
 * @param bodyBuilder
 */
private void buildDeleteByValuesMethodBody(InvocableMemberBodyBuilder bodyBuilder) {
    if (useBulkStatements) {
        //
        bodyBuilder.appendFormalLine("");
        //
        // // if there no is a filter
        bodyBuilder.appendFormalLine("// if there no is a filter");
        // if (propertyValues == null || propertyValues.isEmpty()) {
        bodyBuilder.appendFormalLine("if (propertyValues == null || propertyValues.isEmpty()) {");
        bodyBuilder.indent();

        // throw new IllegalArgumentException("Missing property values");
        bodyBuilder.appendFormalLine("throw new IllegalArgumentException(\"Missing property values\");");

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

        // // Prepare a predicate
        bodyBuilder.appendFormalLine("// Prepare a predicate");
        // BooleanBuilder baseFilterPredicate = new BooleanBuilder();
        bodyBuilder.appendFormalLine(String.format("%s baseFilterPredicate = new %s();",
                helper.getFinalTypeName(QDSL_BOOLEAN_BUILDER), helper.getFinalTypeName(QDSL_BOOLEAN_BUILDER)));
        bodyBuilder.appendFormalLine("");
        // // Base filter. Using BooleanBuilder, a cascading builder for
        bodyBuilder.appendFormalLine("// Base filter. Using BooleanBuilder, a cascading builder for");
        // // Predicate expressions
        bodyBuilder.appendFormalLine("// Predicate expressions");
        // PathBuilder<Visit> entity = new PathBuilder<Visit>(Visit.class,
        // "entity");
        bodyBuilder.appendFormalLine(String.format("%s<%s> entity = new %s<%s>(%s.class, \"entity\");",
                helper.getFinalTypeName(QDSL_PATH_BUILDER), helper.getFinalTypeName(entity),
                helper.getFinalTypeName(QDSL_PATH_BUILDER), helper.getFinalTypeName(entity),
                helper.getFinalTypeName(entity)));

        bodyBuilder.appendFormalLine("");
        //
        // // Build base filter
        bodyBuilder.appendFormalLine("// Build base filter");
        // for (String key : propertyMap.keySet()) {
        bodyBuilder.appendFormalLine("for (String key : propertyValues.keySet()) {");
        bodyBuilder.indent();
        // baseFilterPredicate.and(entity.get(key).eq(propertyMap.get(key)));
        bodyBuilder.appendFormalLine("baseFilterPredicate.and(entity.get(key).eq(propertyValues.get(key)));");
        // }
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");

        bodyBuilder.appendFormalLine("");
        //

        // // Create a query with filter
        bodyBuilder.appendFormalLine("// Create a query with filter");
        // JPADeleteClause delete = new
        // JPADeleteClause(Visit.entityManager(),entity);
        bodyBuilder.appendFormalLine(String.format("%s delete = new %s(%s.entityManager(),entity);",
                helper.getFinalTypeName(QDSL_JPA_DELETE_CLAUSE),
                helper.getFinalTypeName(QDSL_JPA_DELETE_CLAUSE), helper.getFinalTypeName(entity)));
        //
        bodyBuilder.appendFormalLine("");
        // // execute delete
        bodyBuilder.appendFormalLine("// execute delete");
        // return delete.where(baseFilterPredicate).execute();
        bodyBuilder.appendFormalLine("return delete.where(baseFilterPredicate).execute();");
    } else {

        // List<Visit> visits = findByValues(propertyValues);
        bodyBuilder.appendFormalLine(
                String.format("%s %s = %s(propertyValues);", helper.getFinalTypeName(listOfEntitiesType),
                        StringUtils.uncapitalize(entityPlural), FIND_BY_VALUES_METHOD));

        // delete(visits);
        bodyBuilder.appendFormalLine(
                String.format("%s(%s);", DELETE_METHOD, StringUtils.uncapitalize(entityPlural)));

        // return (long)visits.size();
        bodyBuilder.appendFormalLine(
                String.format("return (long)%s.size();", StringUtils.uncapitalize(entityPlural)));

    }

}

From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchMetadata.java

/**
 * Build delete all method body//w  w  w.  j  a  va2s.  c om
 * 
 * @param bodyBuilder
 */
private void buildDeleteAllMethodBody(InvocableMemberBodyBuilder bodyBuilder) {
    if (useBulkStatements) {
        bodyBuilder.appendFormalLine(String
                .format("return entityManager().createQuery(\"DELETE FROM %s\").executeUpdate();", entityName));
    } else {
        // TypedQuery<Owner> query =
        // entityManager().createQuery("Select o FROM Owner o",
        // Owner.class);
        bodyBuilder.appendFormalLine(
                String.format("%s<%s> query = entityManager().createQuery(\"Select o FROM %s o\", %s.class);",
                        helper.getFinalTypeName(JpaJavaType.TYPED_QUERY), entityName, entityName, entityName));
        // List<Owner> owners = query.getResultList();
        bodyBuilder.appendFormalLine(String.format("%s %s = query.getResultList();",
                helper.getFinalTypeName(listOfEntitiesType), StringUtils.uncapitalize(entityPlural)));

        // delete(owners);
        bodyBuilder.appendFormalLine(
                String.format("%s(%s);", DELETE_METHOD, StringUtils.uncapitalize(entityPlural)));

        // return owners.size();
        bodyBuilder
                .appendFormalLine(String.format("return %s.size();", StringUtils.uncapitalize(entityPlural)));

    }

}

From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchMetadata.java

/**
 * Build method body for delete method filter by element's id list
 * /*ww  w.ja v a  2  s .  c  o  m*/
 * @param condition
 * @param parameterName
 * @param bodyBuilder
 */
private void buildDeleteByIdListMethod(String condition, JavaSymbolName parameterName,
        InvocableMemberBodyBuilder bodyBuilder) {

    if (useBulkStatements) {
        String aliasName = entity.getSimpleTypeName().toLowerCase().substring(0, 1);
        // Query query =
        // entityManager().createQuery("DELETE FROM Pet AS p WHERE p.id IN (:idList)");
        bodyBuilder.appendFormalLine(String.format(
                "%s query = entityManager().createQuery(\"DELETE FROM %s as %s WHERE %s.%s %s (:idList)\");",
                getFinalTypeName(JpaJavaType.QUERY), entityName, aliasName, aliasName,
                entityIdentifier.getFieldName().getSymbolName(), condition));

        // query.setParameter("list", ids);
        bodyBuilder.appendFormalLine(
                String.format("query.setParameter(\"idList\", %s);", parameterName.getSymbolName()));

        // return query.executeUpdate();
        bodyBuilder.appendFormalLine("return query.executeUpdate();");
    } else {
        // TypedQuery<Owner> query =
        // entityManager().createQuery("Select o FROM Owner o WHERE o.id IN (:idList)",
        // Owner.class);
        bodyBuilder.appendFormalLine(String.format(
                "%s<%s> query = entityManager().createQuery(\"SELECT o FROM %s o WHERE o.%s %s (:idList)\", %s.class);",
                getFinalTypeName(JpaJavaType.TYPED_QUERY), entityName, entityName,
                entityIdentifier.getFieldName().getSymbolName(), condition, entityName));

        // query.setParameter("list", ids);
        bodyBuilder.appendFormalLine(
                String.format("query.setParameter(\"idList\", %s);", parameterName.getSymbolName()));

        // List<Owner> owners = query.getResultList();
        bodyBuilder.appendFormalLine(String.format("%s %s = query.getResultList();",
                helper.getFinalTypeName(listOfEntitiesType), StringUtils.uncapitalize(entityPlural)));

        // delete(owners);
        bodyBuilder.appendFormalLine(String.format("delete(%s);", StringUtils.uncapitalize(entityPlural)));
        // return owners.size();
        bodyBuilder
                .appendFormalLine(String.format("return %s.size();", StringUtils.uncapitalize(entityPlural)));
    }
}