use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class ResultMapWithoutBLOBsElementGenerator method addResultMapConstructorElements.
private void addResultMapConstructorElements(XmlElement answer) {
//$NON-NLS-1$
XmlElement constructor = new XmlElement("constructor");
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
//$NON-NLS-1$
XmlElement resultElement = new XmlElement("idArg");
resultElement.addAttribute(new Attribute("column", //$NON-NLS-1$
MyBatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn)));
resultElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"jdbcType", introspectedColumn.getJdbcTypeName()));
resultElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"javaType", introspectedColumn.getFullyQualifiedJavaType().getFullyQualifiedName()));
if (stringHasValue(introspectedColumn.getTypeHandler())) {
resultElement.addAttribute(new Attribute("typeHandler", //$NON-NLS-1$
introspectedColumn.getTypeHandler()));
}
constructor.addElement(resultElement);
}
List<IntrospectedColumn> columns;
if (isSimple) {
columns = introspectedTable.getNonPrimaryKeyColumns();
} else {
columns = introspectedTable.getBaseColumns();
}
for (IntrospectedColumn introspectedColumn : columns) {
//$NON-NLS-1$
XmlElement resultElement = new XmlElement("arg");
resultElement.addAttribute(new Attribute("column", //$NON-NLS-1$
MyBatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn)));
resultElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"jdbcType", introspectedColumn.getJdbcTypeName()));
resultElement.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"javaType", introspectedColumn.getFullyQualifiedJavaType().getFullyQualifiedName()));
if (stringHasValue(introspectedColumn.getTypeHandler())) {
resultElement.addAttribute(new Attribute("typeHandler", //$NON-NLS-1$
introspectedColumn.getTypeHandler()));
}
constructor.addElement(resultElement);
}
answer.addElement(constructor);
}
use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class ResultMapWithoutBLOBsElementGenerator method addResultMapElements.
private void addResultMapElements(XmlElement answer) {
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
//$NON-NLS-1$
XmlElement resultElement = new XmlElement("id");
resultElement.addAttribute(new Attribute("column", //$NON-NLS-1$
MyBatis3FormattingUtilities.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);
}
List<IntrospectedColumn> columns;
if (isSimple) {
columns = introspectedTable.getNonPrimaryKeyColumns();
} else {
columns = introspectedTable.getBaseColumns();
}
for (IntrospectedColumn introspectedColumn : columns) {
//$NON-NLS-1$
XmlElement resultElement = new XmlElement("result");
resultElement.addAttribute(new Attribute("column", //$NON-NLS-1$
MyBatis3FormattingUtilities.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);
}
}
use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class SelectByExampleWithBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
String fqjt = introspectedTable.getExampleType();
//$NON-NLS-1$
XmlElement answer = new XmlElement("select");
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getSelectByExampleWithBLOBsStatementId()));
answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
introspectedTable.getResultMapWithBLOBsId()));
//$NON-NLS-1$
answer.addAttribute(new Attribute("parameterType", fqjt));
context.getCommentGenerator().addComment(answer);
//$NON-NLS-1$
answer.addElement(new TextElement("select"));
//$NON-NLS-1$
XmlElement ifElement = new XmlElement("if");
//$NON-NLS-1$ //$NON-NLS-2$
ifElement.addAttribute(new Attribute("test", "distinct"));
//$NON-NLS-1$
ifElement.addElement(new TextElement("distinct"));
answer.addElement(ifElement);
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());
//$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()));
answer.addElement(getExampleIncludeElement());
//$NON-NLS-1$
ifElement = new XmlElement("if");
//$NON-NLS-1$ //$NON-NLS-2$
ifElement.addAttribute(new Attribute("test", "orderByClause != null"));
//$NON-NLS-1$
ifElement.addElement(new TextElement("order by ${orderByClause}"));
answer.addElement(ifElement);
if (context.getPlugins().sqlMapSelectByExampleWithBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class SelectByExampleWithoutBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
String fqjt = introspectedTable.getExampleType();
//$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()));
//$NON-NLS-1$
answer.addAttribute(new Attribute("parameterType", fqjt));
context.getCommentGenerator().addComment(answer);
//$NON-NLS-1$
answer.addElement(new TextElement("select"));
//$NON-NLS-1$
XmlElement ifElement = new XmlElement("if");
//$NON-NLS-1$ //$NON-NLS-2$
ifElement.addAttribute(new Attribute("test", "distinct"));
//$NON-NLS-1$
ifElement.addElement(new TextElement("distinct"));
answer.addElement(ifElement);
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()));
answer.addElement(getExampleIncludeElement());
//$NON-NLS-1$
ifElement = new XmlElement("if");
//$NON-NLS-1$ //$NON-NLS-2$
ifElement.addAttribute(new Attribute("test", "orderByClause != null"));
//$NON-NLS-1$
ifElement.addElement(new TextElement("order by ${orderByClause}"));
answer.addElement(ifElement);
if (context.getPlugins().sqlMapSelectByExampleWithoutBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.
the class SimpleSelectByPrimaryKeyElementGenerator 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()));
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"resultMap", introspectedTable.getBaseResultMapId()));
String parameterType;
// 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,");
}
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()));
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);
}
}
Aggregations