use of org.mybatis.generator.api.dom.xml.TextElement in project generator by mybatis.
the class UpdateByExampleWithoutBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("update");
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"id", introspectedTable.getUpdateByExampleStatementId()));
//$NON-NLS-1$ //$NON-NLS-2$
answer.addAttribute(new Attribute("parameterType", "map"));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("update ");
sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
// set up for first column
sb.setLength(0);
//$NON-NLS-1$
sb.append("set ");
Iterator<IntrospectedColumn> iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonBLOBColumns()).iterator();
while (iter.hasNext()) {
IntrospectedColumn introspectedColumn = iter.next();
sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, //$NON-NLS-1$
"record."));
if (iter.hasNext()) {
sb.append(',');
}
answer.addElement(new TextElement(sb.toString()));
// set up for the next column
if (iter.hasNext()) {
sb.setLength(0);
OutputUtilities.xmlIndent(sb, 1);
}
}
answer.addElement(getUpdateByExampleIncludeElement());
if (context.getPlugins().sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.TextElement in project generator by mybatis.
the class UpdateByPrimaryKeyWithBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("update");
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getUpdateByPrimaryKeyWithBLOBsStatementId()));
String parameterType;
if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
parameterType = introspectedTable.getRecordWithBLOBsType();
} else {
parameterType = introspectedTable.getBaseRecordType();
}
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"parameterType", parameterType));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("update ");
sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
// set up for first column
sb.setLength(0);
//$NON-NLS-1$
sb.append("set ");
Iterator<IntrospectedColumn> iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).iterator();
while (iter.hasNext()) {
IntrospectedColumn introspectedColumn = iter.next();
sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
if (iter.hasNext()) {
sb.append(',');
}
answer.addElement(new TextElement(sb.toString()));
// set up for the next column
if (iter.hasNext()) {
sb.setLength(0);
OutputUtilities.xmlIndent(sb, 1);
}
}
boolean and = false;
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
sb.setLength(0);
if (and) {
//$NON-NLS-1$
sb.append(" and ");
} else {
//$NON-NLS-1$
sb.append("where ");
and = true;
}
sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
answer.addElement(new TextElement(sb.toString()));
}
if (context.getPlugins().sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.TextElement in project generator by mybatis.
the class DefaultCommentGenerator method addComment.
/**
* Adds a suitable comment to warn users that the element was generated, and when it was generated.
*
* @param xmlElement
* the xml element
*/
public void addComment(XmlElement xmlElement) {
if (suppressAllComments) {
return;
}
//$NON-NLS-1$
xmlElement.addElement(new TextElement("<!--"));
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append(" WARNING - ");
sb.append(MergeConstants.NEW_ELEMENT_TAG);
xmlElement.addElement(new TextElement(sb.toString()));
xmlElement.addElement(new TextElement(//$NON-NLS-1$
" This element is automatically generated by MyBatis Generator, do not modify."));
String s = getDateString();
if (s != null) {
sb.setLength(0);
//$NON-NLS-1$
sb.append(" This element was generated on ");
sb.append(s);
sb.append('.');
xmlElement.addElement(new TextElement(sb.toString()));
}
//$NON-NLS-1$
xmlElement.addElement(new TextElement("-->"));
}
use of org.mybatis.generator.api.dom.xml.TextElement in project generator by mybatis.
the class UpdateByPrimaryKeyWithoutBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("update");
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getUpdateByPrimaryKeyStatementId()));
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"parameterClass", introspectedTable.getBaseRecordType()));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("update ");
sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
// set up for first column
sb.setLength(0);
//$NON-NLS-1$
sb.append("set ");
Iterator<IntrospectedColumn> iter = introspectedTable.getBaseColumns().iterator();
while (iter.hasNext()) {
IntrospectedColumn introspectedColumn = iter.next();
sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn));
if (iter.hasNext()) {
sb.append(',');
}
answer.addElement(new TextElement(sb.toString()));
// set up for the next column
if (iter.hasNext()) {
sb.setLength(0);
OutputUtilities.xmlIndent(sb, 1);
}
}
boolean and = false;
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
sb.setLength(0);
if (and) {
//$NON-NLS-1$
sb.append(" and ");
} else {
//$NON-NLS-1$
sb.append("where ");
and = true;
}
sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn));
answer.addElement(new TextElement(sb.toString()));
}
if (context.getPlugins().sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.TextElement in project generator by mybatis.
the class InsertSelectiveElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("insert");
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getInsertSelectiveStatementId()));
FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass();
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"parameterClass", parameterType.getFullyQualifiedName()));
context.getCommentGenerator().addComment(answer);
GeneratedKey gk = introspectedTable.getGeneratedKey();
if (gk != null && gk.isPlacedBeforeInsertInIbatis2()) {
IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
// warning has already been reported
if (introspectedColumn != null) {
// pre-generated key
answer.addElement(getSelectKey(introspectedColumn, gk));
}
}
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("insert into ");
sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
//$NON-NLS-1$
XmlElement insertElement = new XmlElement("dynamic");
//$NON-NLS-1$ //$NON-NLS-2$
insertElement.addAttribute(new Attribute("prepend", "("));
answer.addElement(insertElement);
//$NON-NLS-1$
answer.addElement(new TextElement("values"));
//$NON-NLS-1$
XmlElement valuesElement = new XmlElement("dynamic");
//$NON-NLS-1$ //$NON-NLS-2$
valuesElement.addAttribute(new Attribute("prepend", "("));
answer.addElement(valuesElement);
for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
if (introspectedColumn.isIdentity()) {
// cannot set values on identity fields
continue;
}
//$NON-NLS-1$
XmlElement insertNotNullElement = new XmlElement("isNotNull");
//$NON-NLS-1$ //$NON-NLS-2$
insertNotNullElement.addAttribute(new Attribute("prepend", ","));
insertNotNullElement.addAttribute(new Attribute("property", //$NON-NLS-1$
introspectedColumn.getJavaProperty()));
insertNotNullElement.addElement(new TextElement(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn)));
insertElement.addElement(insertNotNullElement);
//$NON-NLS-1$
XmlElement valuesNotNullElement = new XmlElement("isNotNull");
//$NON-NLS-1$ //$NON-NLS-2$
valuesNotNullElement.addAttribute(new Attribute("prepend", ","));
valuesNotNullElement.addAttribute(new Attribute("property", //$NON-NLS-1$
introspectedColumn.getJavaProperty()));
valuesNotNullElement.addElement(new TextElement(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn)));
valuesElement.addElement(valuesNotNullElement);
}
//$NON-NLS-1$
insertElement.addElement(new TextElement(")"));
//$NON-NLS-1$
valuesElement.addElement(new TextElement(")"));
if (gk != null && !gk.isPlacedBeforeInsertInIbatis2()) {
IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
// warning has already been reported
if (introspectedColumn != null) {
// pre-generated key
answer.addElement(getSelectKey(introspectedColumn, gk));
}
}
if (context.getPlugins().sqlMapInsertSelectiveElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
Aggregations