use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class ResultMapWithoutBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("resultMap");
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"id", introspectedTable.getBaseResultMapId()));
String returnType;
if (isSimple) {
returnType = introspectedTable.getBaseRecordType();
} else {
if (introspectedTable.getRules().generateBaseRecordClass()) {
returnType = introspectedTable.getBaseRecordType();
} else {
returnType = introspectedTable.getPrimaryKeyType();
}
}
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"type", returnType));
context.getCommentGenerator().addComment(answer);
if (introspectedTable.isConstructorBased()) {
addResultMapConstructorElements(answer);
} else {
addResultMapElements(answer);
}
if (context.getPlugins().sqlMapResultMapWithoutBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class SelectByPrimaryKeyElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("select");
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getSelectByPrimaryKeyStatementId()));
if (introspectedTable.getRules().generateResultMapWithBLOBs()) {
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"resultMap", introspectedTable.getResultMapWithBLOBsId()));
} else {
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"resultMap", introspectedTable.getBaseResultMapId()));
}
String parameterType;
if (introspectedTable.getRules().generatePrimaryKeyClass()) {
parameterType = introspectedTable.getPrimaryKeyType();
} else {
// field, then they are coming in a map.
if (introspectedTable.getPrimaryKeyColumns().size() > 1) {
//$NON-NLS-1$
parameterType = "map";
} else {
parameterType = introspectedTable.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType().toString();
}
}
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("select ");
if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
sb.append('\'');
sb.append(introspectedTable.getSelectByPrimaryKeyQueryId());
//$NON-NLS-1$
sb.append("' as QUERYID,");
}
answer.addElement(new TextElement(sb.toString()));
answer.addElement(getBaseColumnListElement());
if (introspectedTable.hasBLOBColumns()) {
//$NON-NLS-1$
answer.addElement(new TextElement(","));
answer.addElement(getBlobColumnListElement());
}
sb.setLength(0);
//$NON-NLS-1$
sb.append("from ");
sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
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.getAliasedEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
answer.addElement(new TextElement(sb.toString()));
}
if (context.getPlugins().sqlMapSelectByPrimaryKeyElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class SimpleSelectAllElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("select");
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getSelectAllStatementId()));
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"resultMap", introspectedTable.getBaseResultMapId()));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("select ");
Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns().iterator();
while (iter.hasNext()) {
sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter.next()));
if (iter.hasNext()) {
//$NON-NLS-1$
sb.append(", ");
}
if (sb.length() > 80) {
answer.addElement(new TextElement(sb.toString()));
sb.setLength(0);
}
}
if (sb.length() > 0) {
answer.addElement(new TextElement(sb.toString()));
}
sb.setLength(0);
//$NON-NLS-1$
sb.append("from ");
sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
String orderByClause = introspectedTable.getTableConfigurationProperty(PropertyRegistry.TABLE_SELECT_ALL_ORDER_BY_CLAUSE);
boolean hasOrderBy = StringUtility.stringHasValue(orderByClause);
if (hasOrderBy) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("order by ");
sb.append(orderByClause);
answer.addElement(new TextElement(sb.toString()));
}
if (context.getPlugins().sqlMapSelectAllElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.XmlElement 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()));
//$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()));
//$NON-NLS-1$
XmlElement dynamicElement = new XmlElement("set");
answer.addElement(dynamicElement);
for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
//$NON-NLS-1$
XmlElement isNotNullElement = new XmlElement("if");
sb.setLength(0);
//$NON-NLS-1$
sb.append(introspectedColumn.getJavaProperty("record."));
//$NON-NLS-1$
sb.append(" != null");
//$NON-NLS-1$
isNotNullElement.addAttribute(new Attribute("test", sb.toString()));
dynamicElement.addElement(isNotNullElement);
sb.setLength(0);
sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(" = ");
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, //$NON-NLS-1$
"record."));
sb.append(',');
isNotNullElement.addElement(new TextElement(sb.toString()));
}
answer.addElement(getUpdateByExampleIncludeElement());
if (context.getPlugins().sqlMapUpdateByExampleSelectiveElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class GeneratedKey method toXmlElement.
/**
* To xml element.
*
* @return the xml element
*/
public XmlElement toXmlElement() {
//$NON-NLS-1$
XmlElement xmlElement = new XmlElement("generatedKey");
//$NON-NLS-1$
xmlElement.addAttribute(new Attribute("column", column));
xmlElement.addAttribute(new Attribute("sqlStatement", //$NON-NLS-1$
configuredSqlStatement));
if (stringHasValue(type)) {
//$NON-NLS-1$
xmlElement.addAttribute(new Attribute("type", type));
}
xmlElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"identity", //$NON-NLS-1$ //$NON-NLS-2$
isIdentity ? "true" : "false"));
return xmlElement;
}
Aggregations