View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements;
17  
18  import java.util.Iterator;
19  
20  import org.mybatis.generator.api.IntrospectedColumn;
21  import org.mybatis.generator.api.dom.xml.Attribute;
22  import org.mybatis.generator.api.dom.xml.TextElement;
23  import org.mybatis.generator.api.dom.xml.XmlElement;
24  import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
25  
26  /**
27   * 
28   * @author Jeff Butler
29   * 
30   */
31  public class BaseColumnListElementGenerator extends AbstractXmlElementGenerator {
32  
33      public BaseColumnListElementGenerator() {
34          super();
35      }
36  
37      @Override
38      public void addElements(XmlElement parentElement) {
39          XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$
40  
41          answer.addAttribute(new Attribute("id", //$NON-NLS-1$
42                  introspectedTable.getBaseColumnListId()));
43  
44          context.getCommentGenerator().addComment(answer);
45  
46          StringBuilder sb = new StringBuilder();
47          Iterator<IntrospectedColumn> iter = introspectedTable
48                  .getNonBLOBColumns().iterator();
49          while (iter.hasNext()) {
50              sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter
51                      .next()));
52  
53              if (iter.hasNext()) {
54                  sb.append(", "); //$NON-NLS-1$
55              }
56  
57              if (sb.length() > 80) {
58                  answer.addElement(new TextElement(sb.toString()));
59                  sb.setLength(0);
60              }
61          }
62  
63          if (sb.length() > 0) {
64              answer.addElement(new TextElement(sb.toString()));
65          }
66  
67          if (context.getPlugins().sqlMapBaseColumnListElementGenerated(
68                  answer, introspectedTable)) {
69              parentElement.addElement(answer);
70          }
71      }
72  }