use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class BlobColumnListElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("sql");
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"id", introspectedTable.getBlobColumnListId()));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
Iterator<IntrospectedColumn> iter = introspectedTable.getBLOBColumns().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()));
}
if (context.getPlugins().sqlMapBlobColumnListElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class ExampleWhereClauseElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("sql");
if (isForUpdateByExample) {
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getMyBatis3UpdateByExampleWhereClauseId()));
} else {
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
introspectedTable.getExampleWhereClauseId()));
}
context.getCommentGenerator().addComment(answer);
//$NON-NLS-1$
XmlElement whereElement = new XmlElement("where");
answer.addElement(whereElement);
//$NON-NLS-1$
XmlElement outerForEachElement = new XmlElement("foreach");
if (isForUpdateByExample) {
outerForEachElement.addAttribute(new Attribute("collection", //$NON-NLS-1$ //$NON-NLS-2$
"example.oredCriteria"));
} else {
outerForEachElement.addAttribute(new Attribute("collection", //$NON-NLS-1$ //$NON-NLS-2$
"oredCriteria"));
}
//$NON-NLS-1$ //$NON-NLS-2$
outerForEachElement.addAttribute(new Attribute("item", "criteria"));
//$NON-NLS-1$ //$NON-NLS-2$
outerForEachElement.addAttribute(new Attribute("separator", "or"));
whereElement.addElement(outerForEachElement);
//$NON-NLS-1$
XmlElement ifElement = new XmlElement("if");
//$NON-NLS-1$ //$NON-NLS-2$
ifElement.addAttribute(new Attribute("test", "criteria.valid"));
outerForEachElement.addElement(ifElement);
//$NON-NLS-1$
XmlElement trimElement = new XmlElement("trim");
//$NON-NLS-1$ //$NON-NLS-2$
trimElement.addAttribute(new Attribute("prefix", "("));
//$NON-NLS-1$ //$NON-NLS-2$
trimElement.addAttribute(new Attribute("suffix", ")"));
//$NON-NLS-1$ //$NON-NLS-2$
trimElement.addAttribute(new Attribute("prefixOverrides", "and"));
ifElement.addElement(trimElement);
trimElement.addElement(getMiddleForEachElement(null));
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
if (stringHasValue(introspectedColumn.getTypeHandler())) {
trimElement.addElement(getMiddleForEachElement(introspectedColumn));
}
}
if (context.getPlugins().sqlMapExampleWhereClauseElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class InsertElementGenerator 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.getInsertStatementId()));
FullyQualifiedJavaType parameterType;
if (isSimple) {
parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
} else {
parameterType = introspectedTable.getRules().calculateAllFieldsClass();
}
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"parameterType", parameterType.getFullyQualifiedName()));
context.getCommentGenerator().addComment(answer);
GeneratedKey gk = introspectedTable.getGeneratedKey();
if (gk != null) {
IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
// warning has already been reported
if (introspectedColumn != null) {
if (gk.isJdbcStandard()) {
answer.addAttribute(new Attribute("useGeneratedKeys", //$NON-NLS-1$ //$NON-NLS-2$
"true"));
answer.addAttribute(new Attribute("keyProperty", //$NON-NLS-1$
introspectedColumn.getJavaProperty()));
answer.addAttribute(new Attribute("keyColumn", //$NON-NLS-1$
introspectedColumn.getActualColumnName()));
} else {
answer.addElement(getSelectKey(introspectedColumn, gk));
}
}
}
StringBuilder insertClause = new StringBuilder();
StringBuilder valuesClause = new StringBuilder();
//$NON-NLS-1$
insertClause.append("insert into ");
insertClause.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
//$NON-NLS-1$
insertClause.append(" (");
//$NON-NLS-1$
valuesClause.append("values (");
List<String> valuesClauses = new ArrayList<String>();
List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
for (int i = 0; i < columns.size(); i++) {
IntrospectedColumn introspectedColumn = columns.get(i);
insertClause.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
valuesClause.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
if (i + 1 < columns.size()) {
//$NON-NLS-1$
insertClause.append(", ");
//$NON-NLS-1$
valuesClause.append(", ");
}
if (valuesClause.length() > 80) {
answer.addElement(new TextElement(insertClause.toString()));
insertClause.setLength(0);
OutputUtilities.xmlIndent(insertClause, 1);
valuesClauses.add(valuesClause.toString());
valuesClause.setLength(0);
OutputUtilities.xmlIndent(valuesClause, 1);
}
}
insertClause.append(')');
answer.addElement(new TextElement(insertClause.toString()));
valuesClause.append(')');
valuesClauses.add(valuesClause.toString());
for (String clause : valuesClauses) {
answer.addElement(new TextElement(clause));
}
if (context.getPlugins().sqlMapInsertElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class AnnotatedSelectByExampleWithoutBLOBsMethodGenerator method addMapperAnnotations.
@Override
public void addMapperAnnotations(Interface interfaze, Method method) {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType());
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("@SelectProvider(type=");
sb.append(fqjt.getShortName());
//$NON-NLS-1$
sb.append(".class, method=\"");
sb.append(introspectedTable.getSelectByExampleStatementId());
//$NON-NLS-1$
sb.append("\")");
method.addAnnotation(sb.toString());
if (introspectedTable.isConstructorBased()) {
//$NON-NLS-1$
method.addAnnotation("@ConstructorArgs({");
} else {
//$NON-NLS-1$
method.addAnnotation("@Results({");
}
Iterator<IntrospectedColumn> iterPk = introspectedTable.getPrimaryKeyColumns().iterator();
Iterator<IntrospectedColumn> iterNonPk = introspectedTable.getBaseColumns().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 AnnotatedSelectByPrimaryKeyMethodGenerator method addMapperAnnotations.
@Override
public void addMapperAnnotations(Interface interfaze, Method method) {
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());
}
sb.setLength(0);
javaIndent(sb, 1);
//$NON-NLS-1$
sb.append("\"from ");
sb.append(escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
//$NON-NLS-1$
sb.append("\",");
method.addAnnotation(sb.toString());
boolean and = false;
iter = introspectedTable.getPrimaryKeyColumns().iterator();
while (iter.hasNext()) {
IntrospectedColumn introspectedColumn = iter.next();
sb.setLength(0);
javaIndent(sb, 1);
if (and) {
//$NON-NLS-1$
sb.append(" \"and ");
} else {
//$NON-NLS-1$
sb.append("\"where ");
and = true;
}
sb.append(escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)));
//$NON-NLS-1$
sb.append(" = ");
sb.append(getParameterClause(introspectedColumn));
sb.append('\"');
if (iter.hasNext()) {
sb.append(',');
}
method.addAnnotation(sb.toString());
}
//$NON-NLS-1$
method.addAnnotation("})");
if (useResultMapIfAvailable) {
if (introspectedTable.getRules().generateBaseResultMap() || introspectedTable.getRules().generateResultMapWithBLOBs()) {
addResultMapAnnotation(method);
} else {
addAnnotatedResults(interfaze, method);
}
} else {
addAnnotatedResults(interfaze, method);
}
}
Aggregations