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.javamapper.elements;
17  
18  import static org.mybatis.generator.internal.util.messages.Messages.getString;
19  
20  import java.util.Set;
21  import java.util.TreeSet;
22  
23  import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
24  import org.mybatis.generator.api.dom.java.Interface;
25  import org.mybatis.generator.api.dom.java.JavaVisibility;
26  import org.mybatis.generator.api.dom.java.Method;
27  import org.mybatis.generator.api.dom.java.Parameter;
28  
29  /**
30   * 
31   * @author Jeff Butler
32   * 
33   */
34  public class SelectByExampleWithoutBLOBsMethodGenerator extends
35          AbstractJavaMapperMethodGenerator {
36  
37      public SelectByExampleWithoutBLOBsMethodGenerator() {
38          super();
39      }
40  
41      @Override
42      public void addInterfaceElements(Interface interfaze) {
43          Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
44          FullyQualifiedJavaType type = new FullyQualifiedJavaType(
45                  introspectedTable.getExampleType());
46          importedTypes.add(type);
47          importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
48  
49          Method method = new Method();
50          method.setVisibility(JavaVisibility.PUBLIC);
51  
52          FullyQualifiedJavaType returnType = FullyQualifiedJavaType
53                  .getNewListInstance();
54          FullyQualifiedJavaType listType;
55          if (introspectedTable.getRules().generateBaseRecordClass()) {
56              listType = new FullyQualifiedJavaType(introspectedTable
57                      .getBaseRecordType());
58          } else if (introspectedTable.getRules().generatePrimaryKeyClass()) {
59              listType = new FullyQualifiedJavaType(introspectedTable
60                      .getPrimaryKeyType());
61          } else {
62              throw new RuntimeException(getString("RuntimeError.12")); //$NON-NLS-1$
63          }
64  
65          importedTypes.add(listType);
66          returnType.addTypeArgument(listType);
67          method.setReturnType(returnType);
68  
69          method.setName(introspectedTable.getSelectByExampleStatementId());
70          method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
71  
72          context.getCommentGenerator().addGeneralMethodComment(method,
73                  introspectedTable);
74  
75          addMapperAnnotations(interfaze, method);
76          
77          if (context.getPlugins()
78                  .clientSelectByExampleWithoutBLOBsMethodGenerated(method,
79                          interfaze, introspectedTable)) {
80              interfaze.addImportedTypes(importedTypes);
81              interfaze.addMethod(method);
82          }
83      }
84  
85      public void addMapperAnnotations(Interface interfaze, Method method) {
86      }
87  }