当前位置: 首页>>代码示例>>Java>>正文


Java Element.addComment方法代码示例

本文整理汇总了Java中org.dom4j.Element.addComment方法的典型用法代码示例。如果您正苦于以下问题:Java Element.addComment方法的具体用法?Java Element.addComment怎么用?Java Element.addComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.dom4j.Element的用法示例。


在下文中一共展示了Element.addComment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addRemove

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addRemove(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("delete");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);
        String left = key.replaceFirst(prefix, "");
        List<String> params = split(left, daoGen.separator());
        if (params.isEmpty()) throw new Error("Remove method needs at least  one param");
        StringBuilder select = new StringBuilder(50);
        select.append("delete from ")
                .append(method.getDaoEnv().getTableName());
        int len = params.size();
        if (!params.isEmpty()) select.append(" where ");
        int cur = 0;
        appendParams(params, select, len, cur);
        sql.addText(select.toString());
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:19,代码来源:DaoGenHelper.java

示例2: addCount

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addCount(DaoGen daoGen, String key, MapperMethod method, Element root,Consumer<List<String>> validator) {
    return (prefix) -> {
        Element sql = root.addElement("select");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);
        sql.addAttribute("resultType", "int");
        String left = key.replaceFirst(prefix, "");
        List<String> params = split(left, daoGen.separator());
        validator.accept(params);
        StringBuilder select = new StringBuilder(50);
        select.append("select count(1) from ")
                .append(method.getDaoEnv().getTableName());
        int len = params.size();
        if (!params.isEmpty()) select.append(" where ");
        int cur = 0;
        appendParams(params, select, len, cur);
        select.append(" order by ").append(daoGen.primaryKey());
        sql.addText(select.toString());
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:21,代码来源:DaoGenHelper.java

示例3: addCountIn

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addCountIn(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("select");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);
        sql.addAttribute("resultType", "int");
        String left = key.replaceFirst(prefix, "");
        List<String> params = split(left, daoGen.separator());
        StringBuilder select = new StringBuilder(50);
        select.append("select count(1) from  ")
                .append(method.getDaoEnv().getTableName());
        int len = params.size();
        if (len != 1)
            throw new Error("count in method only support one param");
        if (!params.isEmpty()) select.append(" where ");
        String param = params.get(0);

        sql.addText(select.toString());
        if (param.endsWith("s")) param = lowerFirst(param.substring(0,param.length()-1));

        Element choose = sql.addElement("choose");
        String collection = param+"s";
        Element when = choose.addElement("when");
        when.addAttribute("test", collection + " !=null and " + collection + ".size() > 0");
        when.addText("`" + param + "` in ");

        Element each = when.addElement("foreach");
        each.addAttribute("item", param);
        each.addAttribute("collection", param+"s");
        each.addAttribute("open", "(");
        each.addAttribute("separator", ",");
        each.addAttribute("close", ")");
        each.addText("#{" + param + "}");

        Element otherwise = choose.addElement("otherwise");
        otherwise.addText(" 1 = 2 ");

        sql.addText(" order by " + daoGen.primaryKey());
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:41,代码来源:DaoGenHelper.java

示例4: addUpdateFor

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addUpdateFor(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("update");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);

        StringBuilder updateSql = new StringBuilder(50);
        updateSql.append("update ")
                .append(method.getDaoEnv().getTableName())
                .append(" set \n");

        String left = key.replaceFirst(prefix, "");
        List<String> fields = split(left, daoGen.separator()).stream().map(this::lowerFirst).collect(Collectors.toList());
        fields.add(method.getDaoEnv().getUpdateTime());
        String pk = daoGen.primaryKey();
        updateSql.append(
                Joiner.on(", ").join(
                        fields.stream().filter((field -> !field.equals(pk) &&
                                !method.getDaoEnv().getCreateTime().equals(field)))
                                .map((field -> {
                                    if (method.getDaoEnv().getUpdateTime().equals(field))
                                        return "`" + field + "` = " + "now() ";
                                    else return "`" + field + "` = " + "#{" + field + "} ";
                                }))
                                .iterator()));

        updateSql.append("Where `")
                .append(pk)
                .append("` = ")
                .append("#{")
                .append(pk)
                .append("}");
        sql.addText(updateSql.toString());
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:36,代码来源:DaoGenHelper.java

示例5: addBatchInsert

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addBatchInsert(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("insert");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);

        StringBuilder insertSql = new StringBuilder(50);
        insertSql.append("insert into ")
                .append(method.getDaoEnv().getTableName())
                .append("\n");

        String pk = daoGen.primaryKey();
        List<String> fields = getFields(method.getFirstParamType());
        insertSql.append("(")
                .append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(f -> "`"+f + "`").iterator()))
                .append(")\n");

        insertSql.append("values ");
        sql.addText(insertSql.toString());
        Element foreach = sql.addElement("foreach");
        foreach.addAttribute("collection", "list");
        foreach.addAttribute("item", "item");
        foreach.addAttribute("separator", ",");
        StringBuilder eachSql = new StringBuilder(50);
        eachSql.append("(").append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(field -> {
            if (method.getDaoEnv().getCreateTime().contains(field)
                    || method.getDaoEnv().getUpdateTime().contains(field))
                return "now()";
            else return "#{item." + field + "}";
        }).iterator()));
        eachSql.append(")");
        foreach.addText(eachSql.toString());
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:35,代码来源:DaoGenHelper.java

示例6: addInsert

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addInsert(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("insert");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);

        StringBuilder insertSql = new StringBuilder(50);
        insertSql.append("insert into ")
                .append(method.getDaoEnv().getTableName())
                .append("\n");

        String pk = daoGen.primaryKey();
        List<String> fields = getFields(method.getFirstParamType());
        insertSql.append("(")
                .append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(f -> "`"+f + "`").iterator()))
                .append(")\n");

        insertSql.append("values (");
        insertSql.append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(field -> {
            if (method.getDaoEnv().getCreateTime().contains(field)
                    || method.getDaoEnv().getUpdateTime().contains(field))
                return "now()";
            else return "#{" + field + "}";
        }).iterator()));
        insertSql.append(")");
        sql.addText(insertSql.toString());

        Element selectKey = sql.addElement("selectKey");
        selectKey.addAttribute("resultType", "int");
        selectKey.addAttribute("keyProperty", pk);
        selectKey.addText("SELECT @@IDENTITY AS " + pk);
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:34,代码来源:DaoGenHelper.java

示例7: addQueryIn

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addQueryIn(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("select");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);
        sql.addAttribute("resultType", method.getReturnType().toString());
        String left = key.replaceFirst(prefix, "");
        List<String> params = split(left, daoGen.separator());
        StringBuilder select = new StringBuilder(50);
        List<String> fields = getFields(method.getReturnType());
        select.append("select ")
                .append(Joiner.on(", ").join(fields.stream().map(f-> "`" + f + "`").iterator()))
                .append(" from ")
                .append(method.getDaoEnv().getTableName());
        int len = params.size();
        if (len != 1)
            throw new Error("query in method only support one param");
        if (!params.isEmpty()) select.append(" where ");
        String param = params.get(0);

        sql.addText(select.toString());
        if (param.endsWith("s")) param = lowerFirst(param.substring(0,param.length()-1));

        Element choose = sql.addElement("choose");
        String collection = param+"s";
        Element when = choose.addElement("when");
        when.addAttribute("test", collection + " !=null and " + collection + ".size() > 0");
        when.addText("`" + param + "` in ");

        Element each = when.addElement("foreach");
        each.addAttribute("item", param);
        each.addAttribute("collection", param+"s");
        each.addAttribute("open", "(");
        each.addAttribute("separator", ",");
        each.addAttribute("close", ")");
        each.addText("#{" + param + "}");

        Element otherwise = choose.addElement("otherwise");
        otherwise.addText(" 1 = 2 ");

        sql.addText(" order by " + daoGen.primaryKey());
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:44,代码来源:DaoGenHelper.java

示例8: addUpdate

import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addUpdate(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("update");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);

        StringBuilder updateSql = new StringBuilder(50);
        updateSql.append("update ")
                .append(method.getDaoEnv().getTableName())
                .append(" set \n");

        List<String> fields = getFields(method.getFirstParamType());
        String pk = daoGen.primaryKey();
        String updateByField;
        String entity;
        if (key.startsWith("updateBy")){
            updateByField = lowerFirst(key.substring(8));
            entity = "entity";
        }else{
            updateByField = pk;
            entity = null;
        }
        updateSql.append(
                Joiner.on(", ").join(
                        fields.stream().filter((field -> !field.equals(pk)
                                && !field.equals(updateByField)
                                && !method.getDaoEnv().getCreateTime().equals(field)))
                                .map((field -> {
                                    if (method.getDaoEnv().getUpdateTime().equals(field))
                                        return "`" + field + "` = " + "now() ";
                                    else
                                        return "`" + field + "` = " + "#{" + (entity != null ?
                                                entity + "." :
                                                "") + field + "} ";
                                }))
                                .iterator()));

        updateSql.append("Where `")
                .append(updateByField)
                .append("` = ")
                .append("#{")
                .append(updateByField)
                .append("}");
        sql.addText(updateSql.toString());
    };
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:47,代码来源:DaoGenHelper.java


注:本文中的org.dom4j.Element.addComment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。