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.ibatis2.sqlmap.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.ibatis2.Ibatis2FormattingUtilities;
25  
26  /**
27   * 
28   * @author Jeff Butler
29   * 
30   */
31  public class BlobColumnListElementGenerator extends AbstractXmlElementGenerator {
32  
33      public BlobColumnListElementGenerator() {
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.getBlobColumnListId()));
43  
44          context.getCommentGenerator().addComment(answer);
45  
46          StringBuilder sb = new StringBuilder();
47  
48          Iterator<IntrospectedColumn> iter = introspectedTable.getBLOBColumns()
49                  .iterator();
50          while (iter.hasNext()) {
51              sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter
52                      .next()));
53  
54              if (iter.hasNext()) {
55                  sb.append(", "); //$NON-NLS-1$
56              }
57  
58              if (sb.length() > 80) {
59                  answer.addElement(new TextElement(sb.toString()));
60                  sb.setLength(0);
61              }
62          }
63  
64          if (sb.length() > 0) {
65              answer.addElement(new TextElement(sb.toString()));
66          }
67  
68          if (context.getPlugins().sqlMapBlobColumnListElementGenerated(
69                  answer, introspectedTable)) {
70              parentElement.addElement(answer);
71          }
72      }
73  }