use of org.mybatis.generator.api.IntrospectedColumn 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.IntrospectedColumn 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);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class UpdateByExampleWithBLOBsElementGenerator 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.getUpdateByExampleWithBLOBsStatementId()));
//$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.getAllColumns()).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().sqlMapUpdateByExampleWithBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class AnnotatedSelectAllMethodGenerator method addAnnotatedResults.
private void addAnnotatedResults(Interface interfaze, Method method) {
if (introspectedTable.isConstructorBased()) {
//$NON-NLS-1$
method.addAnnotation("@ConstructorArgs({");
} else {
//$NON-NLS-1$
method.addAnnotation("@Results({");
}
StringBuilder sb = new StringBuilder();
Iterator<IntrospectedColumn> iterPk = introspectedTable.getPrimaryKeyColumns().iterator();
Iterator<IntrospectedColumn> iterNonPk = introspectedTable.getNonPrimaryKeyColumns().iterator();
while (iterPk.hasNext()) {
IntrospectedColumn introspectedColumn = iterPk.next();
sb.setLength(0);
javaIndent(sb, 1);
sb.append(getResultAnnotation(interfaze, introspectedColumn, true, introspectedTable.isConstructorBased()));
if (iterPk.hasNext() || iterNonPk.hasNext()) {
sb.append(',');
}
method.addAnnotation(sb.toString());
}
while (iterNonPk.hasNext()) {
IntrospectedColumn introspectedColumn = iterNonPk.next();
sb.setLength(0);
javaIndent(sb, 1);
sb.append(getResultAnnotation(interfaze, introspectedColumn, false, introspectedTable.isConstructorBased()));
if (iterNonPk.hasNext()) {
sb.append(',');
}
method.addAnnotation(sb.toString());
}
//$NON-NLS-1$
method.addAnnotation("})");
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class AnnotatedSelectAllMethodGenerator method addMapperAnnotations.
@Override
public void addMapperAnnotations(Interface interfaze, Method method) {
//$NON-NLS-1$
interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Select"));
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
method.addAnnotation("@Select({");
javaIndent(sb, 1);
//$NON-NLS-1$
sb.append("\"select\",");
method.addAnnotation(sb.toString());
Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns().iterator();
sb.setLength(0);
javaIndent(sb, 1);
sb.append('"');
boolean hasColumns = false;
while (iter.hasNext()) {
sb.append(escapeStringForJava(getSelectListPhrase(iter.next())));
hasColumns = true;
if (iter.hasNext()) {
//$NON-NLS-1$
sb.append(", ");
}
if (sb.length() > 80) {
//$NON-NLS-1$
sb.append("\",");
method.addAnnotation(sb.toString());
sb.setLength(0);
javaIndent(sb, 1);
sb.append('"');
hasColumns = false;
}
}
if (hasColumns) {
//$NON-NLS-1$
sb.append("\",");
method.addAnnotation(sb.toString());
}
String orderByClause = introspectedTable.getTableConfigurationProperty(PropertyRegistry.TABLE_SELECT_ALL_ORDER_BY_CLAUSE);
boolean hasOrderBy = StringUtility.stringHasValue(orderByClause);
sb.setLength(0);
javaIndent(sb, 1);
//$NON-NLS-1$
sb.append("\"from ");
sb.append(escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
sb.append('\"');
if (hasOrderBy) {
sb.append(',');
}
method.addAnnotation(sb.toString());
if (hasOrderBy) {
sb.setLength(0);
javaIndent(sb, 1);
//$NON-NLS-1$
sb.append("\"order by ");
sb.append(orderByClause);
sb.append('\"');
method.addAnnotation(sb.toString());
}
//$NON-NLS-1$
method.addAnnotation("})");
addAnnotatedResults(interfaze, method);
}
Aggregations