use of org.mybatis.generator.api.dom.xml.Attribute 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.Attribute 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);
}
}
use of org.mybatis.generator.api.dom.xml.Attribute in project generator by mybatis.
the class ResultMapWithoutBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
boolean useColumnIndex = isTrue(introspectedTable.getTableConfigurationProperty(PropertyRegistry.TABLE_USE_COLUMN_INDEXES));
//$NON-NLS-1$
XmlElement answer = new XmlElement("resultMap");
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"id", introspectedTable.getBaseResultMapId()));
String returnType;
if (introspectedTable.getRules().generateBaseRecordClass()) {
returnType = introspectedTable.getBaseRecordType();
} else {
returnType = introspectedTable.getPrimaryKeyType();
}
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"class", returnType));
context.getCommentGenerator().addComment(answer);
int i = 1;
if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId()) || stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
i++;
}
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
//$NON-NLS-1$
XmlElement resultElement = new XmlElement("result");
if (useColumnIndex) {
resultElement.addAttribute(new Attribute("columnIndex", //$NON-NLS-1$
Integer.toString(i++)));
} else {
resultElement.addAttribute(new Attribute("column", //$NON-NLS-1$
Ibatis2FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn)));
}
resultElement.addAttribute(new Attribute("property", //$NON-NLS-1$
introspectedColumn.getJavaProperty()));
resultElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"jdbcType", introspectedColumn.getJdbcTypeName()));
if (stringHasValue(introspectedColumn.getTypeHandler())) {
resultElement.addAttribute(new Attribute("typeHandler", //$NON-NLS-1$
introspectedColumn.getTypeHandler()));
}
answer.addElement(resultElement);
}
if (context.getPlugins().sqlMapResultMapWithoutBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.Attribute in project generator by mybatis.
the class SelectByExampleWithoutBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("select");
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"id", introspectedTable.getSelectByExampleStatementId()));
answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
introspectedTable.getBaseResultMapId()));
answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$
introspectedTable.getExampleType()));
context.getCommentGenerator().addComment(answer);
//$NON-NLS-1$
answer.addElement(new TextElement("select"));
//$NON-NLS-1$
XmlElement isParameterPresent = new XmlElement("isParameterPresent");
//$NON-NLS-1$
XmlElement isEqualElement = new XmlElement("isEqual");
//$NON-NLS-1$ //$NON-NLS-2$
isEqualElement.addAttribute(new Attribute("property", "distinct"));
//$NON-NLS-1$ //$NON-NLS-2$
isEqualElement.addAttribute(new Attribute("compareValue", "true"));
//$NON-NLS-1$
isEqualElement.addElement(new TextElement("distinct"));
isParameterPresent.addElement(isEqualElement);
answer.addElement(isParameterPresent);
StringBuilder sb = new StringBuilder();
if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
sb.append('\'');
sb.append(introspectedTable.getSelectByExampleQueryId());
//$NON-NLS-1$
sb.append("' as QUERYID,");
answer.addElement(new TextElement(sb.toString()));
}
answer.addElement(getBaseColumnListElement());
sb.setLength(0);
//$NON-NLS-1$
sb.append("from ");
sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
XmlElement isParameterPresenteElement = new XmlElement(//$NON-NLS-1$
"isParameterPresent");
answer.addElement(isParameterPresenteElement);
//$NON-NLS-1$
XmlElement includeElement = new XmlElement("include");
includeElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"refid", introspectedTable.getIbatis2SqlMapNamespace() + "." + //$NON-NLS-1$
introspectedTable.getExampleWhereClauseId()));
isParameterPresenteElement.addElement(includeElement);
//$NON-NLS-1$
XmlElement isNotNullElement = new XmlElement("isNotNull");
isNotNullElement.addAttribute(//$NON-NLS-1$ //$NON-NLS-2$
new Attribute("property", "orderByClause"));
isNotNullElement.addElement(//$NON-NLS-1$
new TextElement("order by $orderByClause$"));
isParameterPresenteElement.addElement(isNotNullElement);
if (context.getPlugins().sqlMapSelectByExampleWithoutBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.Attribute in project generator by mybatis.
the class UpdateByExampleSelectiveElementGenerator 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.getUpdateByExampleSelectiveStatementId()));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("update ");
sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
//$NON-NLS-1$
XmlElement dynamicElement = new XmlElement("dynamic");
//$NON-NLS-1$ //$NON-NLS-2$
dynamicElement.addAttribute(new Attribute("prepend", "set"));
answer.addElement(dynamicElement);
for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
//$NON-NLS-1$
XmlElement isNotNullElement = new XmlElement("isNotNull");
//$NON-NLS-1$ //$NON-NLS-2$
isNotNullElement.addAttribute(new Attribute("prepend", ","));
isNotNullElement.addAttribute(new Attribute("property", //$NON-NLS-1$ //$NON-NLS-2$
introspectedColumn.getJavaProperty("record.")));
dynamicElement.addElement(isNotNullElement);
sb.setLength(0);
sb.append(Ibatis2FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn, //$NON-NLS-1$
"record."));
isNotNullElement.addElement(new TextElement(sb.toString()));
}
XmlElement isParameterPresentElement = new XmlElement(//$NON-NLS-1$
"isParameterPresent");
answer.addElement(isParameterPresentElement);
//$NON-NLS-1$
XmlElement includeElement = new XmlElement("include");
includeElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"refid", introspectedTable.getIbatis2SqlMapNamespace() + "." + //$NON-NLS-1$
introspectedTable.getExampleWhereClauseId()));
isParameterPresentElement.addElement(includeElement);
if (context.getPlugins().sqlMapUpdateByExampleSelectiveElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
Aggregations