本文整理匯總了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());
};
}
示例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());
};
}
示例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());
};
}
示例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());
};
}
示例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());
};
}
示例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);
};
}
示例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());
};
}
示例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());
};
}