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.dao.elements;
17  
18  import org.mybatis.generator.api.dom.java.Field;
19  import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
20  import org.mybatis.generator.api.dom.java.InnerClass;
21  import org.mybatis.generator.api.dom.java.Interface;
22  import org.mybatis.generator.api.dom.java.JavaVisibility;
23  import org.mybatis.generator.api.dom.java.Method;
24  import org.mybatis.generator.api.dom.java.Parameter;
25  import org.mybatis.generator.api.dom.java.TopLevelClass;
26  
27  /**
28   * 
29   * @author Jeff Butler
30   * 
31   */
32  public class UpdateByExampleParmsInnerclassGenerator extends
33          AbstractDAOElementGenerator {
34  
35      public UpdateByExampleParmsInnerclassGenerator() {
36          super();
37      }
38  
39      @Override
40      public void addImplementationElements(TopLevelClass topLevelClass) {
41          topLevelClass.addImportedType(new FullyQualifiedJavaType(
42                  introspectedTable.getExampleType()));
43  
44          InnerClass innerClass = new InnerClass(new FullyQualifiedJavaType(
45                  "UpdateByExampleParms")); //$NON-NLS-1$
46          innerClass.setVisibility(JavaVisibility.PROTECTED);
47          innerClass.setStatic(true);
48          innerClass.setSuperClass(introspectedTable.getExampleType());
49          context.getCommentGenerator().addClassComment(innerClass,
50                  introspectedTable);
51  
52          Method method = new Method();
53          method.setConstructor(true);
54          method.setVisibility(JavaVisibility.PUBLIC);
55          method.setName(innerClass.getType().getShortName());
56          method.addParameter(new Parameter(FullyQualifiedJavaType
57                  .getObjectInstance(), "record")); //$NON-NLS-1$
58          method.addParameter(new Parameter(new FullyQualifiedJavaType(
59                  introspectedTable.getExampleType()), "example")); //$NON-NLS-1$
60          method.addBodyLine("super(example);"); //$NON-NLS-1$
61          method.addBodyLine("this.record = record;"); //$NON-NLS-1$
62          innerClass.addMethod(method);
63  
64          Field field = new Field();
65          field.setVisibility(JavaVisibility.PRIVATE);
66          field.setType(FullyQualifiedJavaType.getObjectInstance());
67          field.setName("record"); //$NON-NLS-1$
68          innerClass.addField(field);
69  
70          method = new Method();
71          method.setVisibility(JavaVisibility.PUBLIC);
72          method.setReturnType(FullyQualifiedJavaType.getObjectInstance());
73          method.setName("getRecord"); //$NON-NLS-1$
74          method.addBodyLine("return record;"); //$NON-NLS-1$
75          innerClass.addMethod(method);
76  
77          topLevelClass.addInnerClass(innerClass);
78      }
79  
80      @Override
81      public void addInterfaceElements(Interface interfaze) {
82          // nothing to add to the interface
83      }
84  }