in mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java [82:132]
private void addBatchInsertXml(Document document, IntrospectedTable introspectedTable) {
List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
String incrementField =
introspectedTable.getTableConfiguration().getProperties().getProperty("incrementField");
if (incrementField != null) {
incrementField = incrementField.toUpperCase();
}
XmlElement insertBatchElement = new XmlElement("insert");
insertBatchElement.addAttribute(new Attribute("id", "batchInsert"));
insertBatchElement.addAttribute(new Attribute("parameterType", "java.util.List"));
StringBuilder sqlElement = new StringBuilder();
StringBuilder javaPropertyAndDbType = new StringBuilder("(");
for (IntrospectedColumn introspectedColumn : columns) {
String columnName = introspectedColumn.getActualColumnName();
if (!columnName.toUpperCase().equals(incrementField)) {
sqlElement.append(columnName + ",\n ");
javaPropertyAndDbType.append(
"\n #{item."
+ introspectedColumn.getJavaProperty()
+ ",jdbcType="
+ introspectedColumn.getJdbcTypeName()
+ "},");
}
}
XmlElement foreachElement = new XmlElement("foreach");
foreachElement.addAttribute(new Attribute("collection", "records"));
foreachElement.addAttribute(new Attribute("index", "index"));
foreachElement.addAttribute(new Attribute("item", "item"));
foreachElement.addAttribute(new Attribute("separator", ","));
insertBatchElement.addElement(
new TextElement(
"insert into "
+ introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()
+ " ("));
insertBatchElement.addElement(
new TextElement(
" " + sqlElement.delete(sqlElement.lastIndexOf(","), sqlElement.length()).toString()));
insertBatchElement.addElement(new TextElement(") values "));
foreachElement.addElement(
new TextElement(
javaPropertyAndDbType
.delete(javaPropertyAndDbType.length() - 1, javaPropertyAndDbType.length())
.append("\n )")
.toString()));
insertBatchElement.addElement(foreachElement);
document.getRootElement().addElement(insertBatchElement);
}