├── .classpath ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── README.md ├── ant-1.8.1.jar ├── dtd └── mybatis-generator-config_1_0.dtd ├── generatorConfig.xml ├── log4j-1.2.16.jar ├── md_img └── 1.png ├── mybatis-3.2.7.jar ├── mybatisGenerator-example.xml ├── mybatisGenerator.md ├── mysql-connector-java-5.1.25-bin.jar ├── src └── org │ └── mybatis │ └── generator │ ├── ant │ ├── AntProgressCallback.java │ └── GeneratorAntTask.java │ ├── api │ ├── CommentGenerator.java │ ├── DAOMethodNameCalculator.java │ ├── FullyQualifiedTable.java │ ├── GeneratedFile.java │ ├── GeneratedJavaFile.java │ ├── GeneratedXmlFile.java │ ├── IntrospectedColumn.java │ ├── IntrospectedTable.java │ ├── JavaFormatter.java │ ├── JavaTypeResolver.java │ ├── MyBatisGenerator.java │ ├── Plugin.java │ ├── PluginAdapter.java │ ├── ProgressCallback.java │ ├── ShellCallback.java │ ├── ShellRunner.java │ ├── VerboseProgressCallback.java │ ├── XmlFormatter.java │ ├── dom │ │ ├── DefaultJavaFormatter.java │ │ ├── DefaultXmlFormatter.java │ │ ├── OutputUtilities.java │ │ ├── java │ │ │ ├── CompilationUnit.java │ │ │ ├── Field.java │ │ │ ├── FullyQualifiedJavaType.java │ │ │ ├── InitializationBlock.java │ │ │ ├── InnerClass.java │ │ │ ├── InnerEnum.java │ │ │ ├── Interface.java │ │ │ ├── JavaElement.java │ │ │ ├── JavaVisibility.java │ │ │ ├── Method.java │ │ │ ├── Parameter.java │ │ │ ├── PrimitiveTypeWrapper.java │ │ │ ├── TopLevelClass.java │ │ │ └── TopLevelEnumeration.java │ │ └── xml │ │ │ ├── Attribute.java │ │ │ ├── Document.java │ │ │ ├── Element.java │ │ │ ├── TextElement.java │ │ │ └── XmlElement.java │ └── package.html │ ├── codegen │ ├── AbstractGenerator.java │ ├── AbstractJavaClientGenerator.java │ ├── AbstractJavaGenerator.java │ ├── AbstractXmlGenerator.java │ ├── RootClassInfo.java │ ├── XmlConstants.java │ ├── ibatis2 │ │ ├── Ibatis2FormattingUtilities.java │ │ ├── IntrospectedTableIbatis2Java2Impl.java │ │ ├── IntrospectedTableIbatis2Java5Impl.java │ │ ├── dao │ │ │ ├── DAOGenerator.java │ │ │ ├── elements │ │ │ │ ├── AbstractDAOElementGenerator.java │ │ │ │ ├── CountByExampleMethodGenerator.java │ │ │ │ ├── DeleteByExampleMethodGenerator.java │ │ │ │ ├── DeleteByPrimaryKeyMethodGenerator.java │ │ │ │ ├── InsertMethodGenerator.java │ │ │ │ ├── InsertSelectiveMethodGenerator.java │ │ │ │ ├── SelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── SelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ ├── SelectByPrimaryKeyMethodGenerator.java │ │ │ │ ├── UpdateByExampleParmsInnerclassGenerator.java │ │ │ │ ├── UpdateByExampleSelectiveMethodGenerator.java │ │ │ │ ├── UpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── UpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ ├── UpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ └── templates │ │ │ │ ├── AbstractDAOTemplate.java │ │ │ │ ├── GenericCIDAOTemplate.java │ │ │ │ ├── GenericSIDAOTemplate.java │ │ │ │ ├── IbatisDAOTemplate.java │ │ │ │ └── SpringDAOTemplate.java │ │ ├── model │ │ │ ├── BaseRecordGenerator.java │ │ │ ├── ExampleGenerator.java │ │ │ ├── PrimaryKeyGenerator.java │ │ │ └── RecordWithBLOBsGenerator.java │ │ └── sqlmap │ │ │ ├── SqlMapGenerator.java │ │ │ └── elements │ │ │ ├── AbstractXmlElementGenerator.java │ │ │ ├── BaseColumnListElementGenerator.java │ │ │ ├── BlobColumnListElementGenerator.java │ │ │ ├── CountByExampleElementGenerator.java │ │ │ ├── DeleteByExampleElementGenerator.java │ │ │ ├── DeleteByPrimaryKeyElementGenerator.java │ │ │ ├── ExampleWhereClauseElementGenerator.java │ │ │ ├── InsertElementGenerator.java │ │ │ ├── InsertSelectiveElementGenerator.java │ │ │ ├── ResultMapWithBLOBsElementGenerator.java │ │ │ ├── ResultMapWithoutBLOBsElementGenerator.java │ │ │ ├── SelectByExampleWithBLOBsElementGenerator.java │ │ │ ├── SelectByExampleWithoutBLOBsElementGenerator.java │ │ │ ├── SelectByPrimaryKeyElementGenerator.java │ │ │ ├── UpdateByExampleSelectiveElementGenerator.java │ │ │ ├── UpdateByExampleWithBLOBsElementGenerator.java │ │ │ ├── UpdateByExampleWithoutBLOBsElementGenerator.java │ │ │ ├── UpdateByPrimaryKeySelectiveElementGenerator.java │ │ │ ├── UpdateByPrimaryKeyWithBLOBsElementGenerator.java │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java │ └── mybatis3 │ │ ├── IntrospectedTableMyBatis3Impl.java │ │ ├── IntrospectedTableMyBatis3SimpleImpl.java │ │ ├── MyBatis3FormattingUtilities.java │ │ ├── javamapper │ │ ├── AnnotatedClientGenerator.java │ │ ├── JavaMapperGenerator.java │ │ ├── MixedClientGenerator.java │ │ ├── SimpleAnnotatedClientGenerator.java │ │ ├── SimpleJavaClientGenerator.java │ │ ├── SqlProviderGenerator.java │ │ └── elements │ │ │ ├── AbstractJavaMapperMethodGenerator.java │ │ │ ├── CountByExampleMethodGenerator.java │ │ │ ├── DeleteByExampleMethodGenerator.java │ │ │ ├── DeleteByPrimaryKeyMethodGenerator.java │ │ │ ├── InsertMethodGenerator.java │ │ │ ├── InsertSelectiveMethodGenerator.java │ │ │ ├── SelectAllMethodGenerator.java │ │ │ ├── SelectByExampleWithBLOBsMethodGenerator.java │ │ │ ├── SelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ ├── SelectByPrimaryKeyMethodGenerator.java │ │ │ ├── UpdateByExampleSelectiveMethodGenerator.java │ │ │ ├── UpdateByExampleWithBLOBsMethodGenerator.java │ │ │ ├── UpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ ├── UpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ ├── UpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ ├── UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ ├── annotated │ │ │ ├── AnnotatedCountByExampleMethodGenerator.java │ │ │ ├── AnnotatedDeleteByExampleMethodGenerator.java │ │ │ ├── AnnotatedDeleteByPrimaryKeyMethodGenerator.java │ │ │ ├── AnnotatedInsertMethodGenerator.java │ │ │ ├── AnnotatedInsertSelectiveMethodGenerator.java │ │ │ ├── AnnotatedSelectAllMethodGenerator.java │ │ │ ├── AnnotatedSelectByExampleWithBLOBsMethodGenerator.java │ │ │ ├── AnnotatedSelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ ├── AnnotatedSelectByPrimaryKeyMethodGenerator.java │ │ │ ├── AnnotatedUpdateByExampleSelectiveMethodGenerator.java │ │ │ ├── AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ ├── AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ ├── AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ ├── AnnotatedUpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ └── AnnotatedUpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ └── sqlprovider │ │ │ ├── AbstractJavaProviderMethodGenerator.java │ │ │ ├── ProviderApplyWhereMethodGenerator.java │ │ │ ├── ProviderCountByExampleMethodGenerator.java │ │ │ ├── ProviderDeleteByExampleMethodGenerator.java │ │ │ ├── ProviderInsertSelectiveMethodGenerator.java │ │ │ ├── ProviderSelectByExampleWithBLOBsMethodGenerator.java │ │ │ ├── ProviderSelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ ├── ProviderUpdateByExampleSelectiveMethodGenerator.java │ │ │ ├── ProviderUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ ├── ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ └── ProviderUpdateByPrimaryKeySelectiveMethodGenerator.java │ │ ├── model │ │ ├── BaseRecordGenerator.java │ │ ├── ExampleGenerator.java │ │ ├── PrimaryKeyGenerator.java │ │ ├── RecordWithBLOBsGenerator.java │ │ └── SimpleModelGenerator.java │ │ └── xmlmapper │ │ ├── MixedMapperGenerator.java │ │ ├── SimpleXMLMapperGenerator.java │ │ ├── XMLMapperGenerator.java │ │ └── elements │ │ ├── AbstractXmlElementGenerator.java │ │ ├── BaseColumnListElementGenerator.java │ │ ├── BlobColumnListElementGenerator.java │ │ ├── CountByExampleElementGenerator.java │ │ ├── DeleteByExampleElementGenerator.java │ │ ├── DeleteByPrimaryKeyElementGenerator.java │ │ ├── ExampleWhereClauseElementGenerator.java │ │ ├── InsertElementGenerator.java │ │ ├── InsertSelectiveElementGenerator.java │ │ ├── ResultMapWithBLOBsElementGenerator.java │ │ ├── ResultMapWithoutBLOBsElementGenerator.java │ │ ├── SelectByExampleWithBLOBsElementGenerator.java │ │ ├── SelectByExampleWithoutBLOBsElementGenerator.java │ │ ├── SelectByPrimaryKeyElementGenerator.java │ │ ├── SimpleSelectAllElementGenerator.java │ │ ├── SimpleSelectByPrimaryKeyElementGenerator.java │ │ ├── UpdateByExampleSelectiveElementGenerator.java │ │ ├── UpdateByExampleWithBLOBsElementGenerator.java │ │ ├── UpdateByExampleWithoutBLOBsElementGenerator.java │ │ ├── UpdateByPrimaryKeySelectiveElementGenerator.java │ │ ├── UpdateByPrimaryKeyWithBLOBsElementGenerator.java │ │ └── UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java │ ├── config │ ├── ColumnOverride.java │ ├── ColumnRenamingRule.java │ ├── CommentGeneratorConfiguration.java │ ├── Configuration.java │ ├── Context.java │ ├── GeneratedKey.java │ ├── IgnoredColumn.java │ ├── JDBCConnectionConfiguration.java │ ├── JavaClientGeneratorConfiguration.java │ ├── JavaModelGeneratorConfiguration.java │ ├── JavaTypeResolverConfiguration.java │ ├── MergeConstants.java │ ├── ModelType.java │ ├── PluginConfiguration.java │ ├── PropertyHolder.java │ ├── PropertyRegistry.java │ ├── SqlMapGeneratorConfiguration.java │ ├── TableConfiguration.java │ ├── TypedPropertyHolder.java │ └── xml │ │ ├── ConfigurationParser.java │ │ ├── IbatorConfigurationParser.java │ │ ├── MyBatisGeneratorConfigurationParser.java │ │ ├── ParserEntityResolver.java │ │ ├── ParserErrorHandler.java │ │ ├── ibator-config_1_0.dtd │ │ └── mybatis-generator-config_1_0.dtd │ ├── exception │ ├── InvalidConfigurationException.java │ ├── ShellException.java │ └── XMLParserException.java │ ├── internal │ ├── DefaultCommentGenerator.java │ ├── DefaultDAOMethodNameCalculator.java │ ├── DefaultShellCallback.java │ ├── DomWriter.java │ ├── ExtendedDAOMethodNameCalculator.java │ ├── NullProgressCallback.java │ ├── ObjectFactory.java │ ├── PluginAggregator.java │ ├── XmlFileMergerJaxp.java │ ├── db │ │ ├── ActualTableName.java │ │ ├── ConnectionFactory.java │ │ ├── DatabaseDialects.java │ │ ├── DatabaseIntrospector.java │ │ └── SqlReservedWords.java │ ├── rules │ │ ├── BaseRules.java │ │ ├── ConditionalModelRules.java │ │ ├── FlatModelRules.java │ │ ├── HierarchicalModelRules.java │ │ ├── Rules.java │ │ └── RulesDelegate.java │ ├── types │ │ ├── JavaTypeResolverDefaultImpl.java │ │ ├── Jdbc4Types.java │ │ └── JdbcTypeNameTranslator.java │ └── util │ │ ├── ClassloaderUtility.java │ │ ├── EqualsUtil.java │ │ ├── HashCodeUtil.java │ │ ├── JavaBeansUtil.java │ │ ├── StringUtility.java │ │ └── messages │ │ ├── Messages.java │ │ └── messages.properties │ ├── logging │ ├── AbstractLogFactory.java │ ├── JdkLoggingImpl.java │ ├── Log.java │ ├── Log4jImpl.java │ └── LogFactory.java │ └── plugins │ ├── CachePlugin.java │ ├── CaseInsensitiveLikePlugin.java │ ├── EqualsHashCodePlugin.java │ ├── MapperConfigPlugin.java │ ├── RenameExampleClassPlugin.java │ ├── RowBoundsPlugin.java │ ├── SerializablePlugin.java │ ├── SqlMapConfigPlugin.java │ ├── ToStringPlugin.java │ └── VirtualPrimaryKeyPlugin.java └── update.txt /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | MybatisGenerator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.7 12 | -------------------------------------------------------------------------------- /ant-1.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wu6660563/MybatisGenerator/894d226267d4ca63caa8ec38b2f0b180818dbd66/ant-1.8.1.jar -------------------------------------------------------------------------------- /log4j-1.2.16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wu6660563/MybatisGenerator/894d226267d4ca63caa8ec38b2f0b180818dbd66/log4j-1.2.16.jar -------------------------------------------------------------------------------- /md_img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wu6660563/MybatisGenerator/894d226267d4ca63caa8ec38b2f0b180818dbd66/md_img/1.png -------------------------------------------------------------------------------- /mybatis-3.2.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wu6660563/MybatisGenerator/894d226267d4ca63caa8ec38b2f0b180818dbd66/mybatis-3.2.7.jar -------------------------------------------------------------------------------- /mybatisGenerator.md: -------------------------------------------------------------------------------- 1 | # MyBatis Generator 快速入门指南 2 | 3 | 详细见: 4 | mybatis配置说明:http://generator.sturgeon.mopaas.com/index.html 5 | 大象修改博客:http://www.blogjava.net/bolo/archive/2015/03/25/423826.html 6 | 7 | ## 启动说明 8 | 9 | java -jar mybatis-generator-core-x.x.x.jar -configfile \temp\generatorConfig.xml -overwrite 10 | 11 | 源码方式:运行ShellRunner文件 12 | 13 | ## 源码修改记录 14 | update.txt 15 | 16 | ## 源码修改之后,使用说明 17 | + 配置生成注释,默认注释已经修改 18 | + javaModelGenerator里面targetProject可以配置非src,以便于区分源码和业务代码,如:targetProject="target" 19 | + table里面配置集成的父类可用,该属性也可以再javaModelGenerator里面配置公用 20 | + table里面配置插入返回主键配置 21 | 22 | -------------------------------------------------------------------------------- /mysql-connector-java-5.1.25-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wu6660563/MybatisGenerator/894d226267d4ca63caa8ec38b2f0b180818dbd66/mysql-connector-java-5.1.25-bin.jar -------------------------------------------------------------------------------- /src/org/mybatis/generator/ant/AntProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.ant; 18 | 19 | import org.apache.tools.ant.Project; 20 | import org.apache.tools.ant.Task; 21 | import org.mybatis.generator.internal.NullProgressCallback; 22 | 23 | /** 24 | * This callback logs progress messages with the Ant logger 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class AntProgressCallback extends NullProgressCallback { 30 | 31 | private Task task; 32 | private boolean verbose; 33 | 34 | /** 35 | * 36 | */ 37 | public AntProgressCallback(Task task, boolean verbose) { 38 | super(); 39 | this.task = task; 40 | this.verbose = verbose; 41 | } 42 | 43 | @Override 44 | public void startTask(String subTaskName) { 45 | if (verbose) { 46 | task.log(subTaskName, Project.MSG_VERBOSE); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/GeneratedFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.api; 17 | 18 | 19 | /** 20 | * Abstract class that holds information common to all generated files. 21 | * 22 | * @author Jeff Butler 23 | */ 24 | public abstract class GeneratedFile { 25 | protected String targetProject; 26 | 27 | /** 28 | * 29 | */ 30 | public GeneratedFile(String targetProject) { 31 | super(); 32 | this.targetProject = targetProject; 33 | } 34 | 35 | /** 36 | * This method returns the entire contents of the generated file. Clients 37 | * can simply save the value returned from this method as the file contents. 38 | * Subclasses such as @see org.mybatis.generator.api.GeneratedJavaFile offer 39 | * more fine grained access to file parts, but still implement this method 40 | * in the event that the entire contents are desired. 41 | * 42 | * @return Returns the content. 43 | */ 44 | public abstract String getFormattedContent(); 45 | 46 | /** 47 | * Get the file name (without any path). Clients should use this method to 48 | * determine how to save the results. 49 | * 50 | * @return Returns the file name. 51 | */ 52 | public abstract String getFileName(); 53 | 54 | /** 55 | * Gets the target project. Clients can call this method to determine how to 56 | * save the results. 57 | * 58 | * @return the target project 59 | */ 60 | public String getTargetProject() { 61 | return targetProject; 62 | } 63 | 64 | /** 65 | * Get the target package for the file. Clients should use this method to 66 | * determine how to save the results. 67 | * 68 | * @return Returns the target project. 69 | */ 70 | public abstract String getTargetPackage(); 71 | 72 | @Override 73 | public String toString() { 74 | return getFormattedContent(); 75 | } 76 | 77 | public abstract boolean isMergeable(); 78 | } 79 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/GeneratedJavaFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.api; 17 | 18 | import org.mybatis.generator.api.dom.java.CompilationUnit; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class GeneratedJavaFile extends GeneratedFile { 24 | private CompilationUnit compilationUnit; 25 | private String fileEncoding; 26 | private JavaFormatter javaFormatter; 27 | 28 | /** 29 | * Default constructor 30 | */ 31 | public GeneratedJavaFile(CompilationUnit compilationUnit, 32 | String targetProject, 33 | String fileEncoding, 34 | JavaFormatter javaFormatter) { 35 | super(targetProject); 36 | this.compilationUnit = compilationUnit; 37 | this.fileEncoding = fileEncoding; 38 | this.javaFormatter = javaFormatter; 39 | } 40 | 41 | public GeneratedJavaFile(CompilationUnit compilationUnit, 42 | String targetProject, 43 | JavaFormatter javaFormatter) { 44 | this(compilationUnit, targetProject, null, javaFormatter); 45 | } 46 | 47 | @Override 48 | public String getFormattedContent() { 49 | return javaFormatter.getFormattedContent(compilationUnit); 50 | } 51 | 52 | @Override 53 | public String getFileName() { 54 | return compilationUnit.getType().getShortName() + ".java"; //$NON-NLS-1$ 55 | } 56 | 57 | public String getTargetPackage() { 58 | return compilationUnit.getType().getPackageName(); 59 | } 60 | 61 | /** 62 | * This method is required by the Eclipse Java merger. If you are not 63 | * running in Eclipse, or some other system that implements the Java merge 64 | * function, you may return null from this method. 65 | * 66 | * @return the CompilationUnit associated with this file, or null if the 67 | * file is not mergeable. 68 | */ 69 | public CompilationUnit getCompilationUnit() { 70 | return compilationUnit; 71 | } 72 | 73 | /** 74 | * A Java file is mergeable if the getCompilationUnit() method returns a 75 | * valid compilation unit. 76 | * 77 | */ 78 | @Override 79 | public boolean isMergeable() { 80 | return true; 81 | } 82 | 83 | public String getFileEncoding() { 84 | return fileEncoding; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/GeneratedXmlFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.api; 17 | 18 | import org.mybatis.generator.api.dom.xml.Document; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class GeneratedXmlFile extends GeneratedFile { 24 | private Document document; 25 | 26 | private String fileName; 27 | 28 | private String targetPackage; 29 | 30 | private boolean isMergeable; 31 | 32 | private XmlFormatter xmlFormatter; 33 | 34 | /** 35 | * 36 | * @param document 37 | * @param fileName 38 | * @param targetPackage 39 | * @param targetProject 40 | * @param isMergeable 41 | * true if the file can be merged by the built in XML file 42 | * merger. 43 | */ 44 | public GeneratedXmlFile(Document document, String fileName, 45 | String targetPackage, String targetProject, boolean isMergeable, 46 | XmlFormatter xmlFormatter) { 47 | super(targetProject); 48 | this.document = document; 49 | this.fileName = fileName; 50 | this.targetPackage = targetPackage; 51 | this.isMergeable = isMergeable; 52 | this.xmlFormatter = xmlFormatter; 53 | } 54 | 55 | @Override 56 | public String getFormattedContent() { 57 | return xmlFormatter.getFormattedContent(document); 58 | } 59 | 60 | /** 61 | * @return Returns the fileName. 62 | */ 63 | @Override 64 | public String getFileName() { 65 | return fileName; 66 | } 67 | 68 | /** 69 | * @return Returns the targetPackage. 70 | */ 71 | @Override 72 | public String getTargetPackage() { 73 | return targetPackage; 74 | } 75 | 76 | @Override 77 | public boolean isMergeable() { 78 | return isMergeable; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/JavaFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 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.api; 17 | 18 | import org.mybatis.generator.api.dom.java.CompilationUnit; 19 | import org.mybatis.generator.config.Context; 20 | 21 | /** 22 | * Objects implementing this interface are used to convert the internal 23 | * representation of the Java DOM classes into a string suitable for 24 | * saving to the file system. Note that the string generated by this 25 | * class will be saved directly to the file system with no additional modifications. 26 | * 27 | * Only one instance of the class will be created in each context. Configuration can 28 | * be passed into the class through the use of properties in the Context. 29 | * 30 | * @author Jeff Butler 31 | * 32 | */ 33 | public interface JavaFormatter { 34 | void setContext(Context context); 35 | String getFormattedContent(CompilationUnit compilationUnit); 36 | } 37 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/VerboseProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.api; 18 | 19 | import org.mybatis.generator.internal.NullProgressCallback; 20 | 21 | /** 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public class VerboseProgressCallback extends NullProgressCallback { 26 | 27 | /** 28 | * 29 | */ 30 | public VerboseProgressCallback() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void startTask(String taskName) { 36 | System.out.println(taskName); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/XmlFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 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.api; 17 | 18 | import org.mybatis.generator.api.dom.xml.Document; 19 | import org.mybatis.generator.config.Context; 20 | 21 | /** 22 | * Objects implementing this interface are used to convert the internal 23 | * representation of the XML DOM classes into a string suitable for 24 | * saving to the file system. Note that the string generated by this 25 | * class will be saved directly to the file system with no additional modifications. 26 | * 27 | * Only one instance of the class will be created in each context. Configuration can 28 | * be passed into the class through the use of properties in the Context. 29 | * 30 | * @author Jeff Butler 31 | * 32 | */ 33 | public interface XmlFormatter { 34 | void setContext(Context context); 35 | String getFormattedContent(Document document); 36 | } 37 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/DefaultJavaFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 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.api.dom; 17 | 18 | import org.mybatis.generator.api.JavaFormatter; 19 | import org.mybatis.generator.api.dom.java.CompilationUnit; 20 | import org.mybatis.generator.config.Context; 21 | 22 | /** 23 | * This class is the default formatter for generated Java. This class will use the 24 | * built in formatting of the DOM classes directly. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class DefaultJavaFormatter implements JavaFormatter { 30 | protected Context context; 31 | 32 | public String getFormattedContent(CompilationUnit compilationUnit) { 33 | return compilationUnit.getFormattedContent(); 34 | } 35 | 36 | public void setContext(Context context) { 37 | this.context = context; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/DefaultXmlFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 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.api.dom; 17 | 18 | import org.mybatis.generator.api.XmlFormatter; 19 | import org.mybatis.generator.api.dom.xml.Document; 20 | import org.mybatis.generator.config.Context; 21 | 22 | /** 23 | * This class is the default formatter for generated XML. This class will use the 24 | * built in formatting of the DOM classes directly. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class DefaultXmlFormatter implements XmlFormatter { 30 | protected Context context; 31 | 32 | public String getFormattedContent(Document document) { 33 | return document.getFormattedContent(); 34 | } 35 | 36 | public void setContext(Context context) { 37 | this.context = context; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/java/CompilationUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.api.dom.java; 17 | 18 | import java.util.List; 19 | import java.util.Set; 20 | 21 | /** 22 | * This interface describes methods common to all Java compilation units (Java 23 | * classes, interfaces, and enums). 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public interface CompilationUnit { 28 | String getFormattedContent(); 29 | 30 | Set getImportedTypes(); 31 | 32 | Set getStaticImports(); 33 | 34 | FullyQualifiedJavaType getSuperClass(); 35 | 36 | boolean isJavaInterface(); 37 | 38 | boolean isJavaEnumeration(); 39 | 40 | Set getSuperInterfaceTypes(); 41 | 42 | FullyQualifiedJavaType getType(); 43 | 44 | void addImportedType(FullyQualifiedJavaType importedType); 45 | 46 | void addImportedTypes(Set importedTypes); 47 | 48 | void addStaticImport(String staticImport); 49 | 50 | void addStaticImports(Set staticImports); 51 | 52 | /** 53 | * Comments will be written at the top of the file as is, we do not append 54 | * any start or end comment characters. 55 | * 56 | * Note that in the Eclipse plugin, file comments will not be merged. 57 | * 58 | * @param commentLine 59 | */ 60 | void addFileCommentLine(String commentLine); 61 | 62 | List getFileCommentLines(); 63 | } 64 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/java/JavaVisibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.api.dom.java; 17 | 18 | /** 19 | * Typesafe enum of possible Java visibility settings 20 | * 21 | * @author Jeff Butler 22 | */ 23 | public enum JavaVisibility { 24 | PUBLIC("public "), //$NON-NLS-1$ 25 | PRIVATE("private "), //$NON-NLS-1$ 26 | PROTECTED("protected "), //$NON-NLS-1$ 27 | DEFAULT(""); //$NON-NLS-1$ 28 | 29 | private String value; 30 | 31 | private JavaVisibility(String value) { 32 | this.value = value; 33 | } 34 | 35 | public String getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/java/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.api.dom.java; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * @author Jeff Butler 23 | */ 24 | public class Parameter { 25 | private String name; 26 | private FullyQualifiedJavaType type; 27 | private boolean isVarargs; 28 | 29 | private List annotations; 30 | 31 | public Parameter(FullyQualifiedJavaType type, String name, boolean isVarargs) { 32 | super(); 33 | this.name = name; 34 | this.type = type; 35 | this.isVarargs = isVarargs; 36 | annotations = new ArrayList(); 37 | } 38 | 39 | public Parameter(FullyQualifiedJavaType type, String name) { 40 | this(type, name, false); 41 | } 42 | 43 | public Parameter(FullyQualifiedJavaType type, String name, String annotation) { 44 | this(type, name, false); 45 | addAnnotation(annotation); 46 | } 47 | 48 | public Parameter(FullyQualifiedJavaType type, String name, String annotation, boolean isVarargs) { 49 | this(type, name, isVarargs); 50 | addAnnotation(annotation); 51 | } 52 | 53 | /** 54 | * @return Returns the name. 55 | */ 56 | public String getName() { 57 | return name; 58 | } 59 | 60 | /** 61 | * @return Returns the type. 62 | */ 63 | public FullyQualifiedJavaType getType() { 64 | return type; 65 | } 66 | 67 | public List getAnnotations() { 68 | return annotations; 69 | } 70 | 71 | public void addAnnotation(String annotation) { 72 | annotations.add(annotation); 73 | } 74 | 75 | public String getFormattedContent() { 76 | StringBuilder sb = new StringBuilder(); 77 | 78 | for (String annotation : annotations) { 79 | sb.append(annotation); 80 | sb.append(' '); 81 | } 82 | 83 | sb.append(type.getShortName()); 84 | sb.append(' '); 85 | if (isVarargs) { 86 | sb.append("... "); //$NON-NLS-1$ 87 | } 88 | sb.append(name); 89 | 90 | return sb.toString(); 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return getFormattedContent(); 96 | } 97 | 98 | public boolean isVarargs() { 99 | return isVarargs; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/xml/Attribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.api.dom.xml; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public class Attribute { 22 | private String name; 23 | private String value; 24 | 25 | /** 26 | * 27 | */ 28 | public Attribute(String name, String value) { 29 | super(); 30 | this.name = name; 31 | this.value = value; 32 | } 33 | 34 | /** 35 | * @return Returns the name. 36 | */ 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | /** 42 | * @return Returns the value. 43 | */ 44 | public String getValue() { 45 | return value; 46 | } 47 | 48 | public String getFormattedContent() { 49 | StringBuilder sb = new StringBuilder(); 50 | sb.append(name); 51 | sb.append("=\""); //$NON-NLS-1$ 52 | sb.append(value); 53 | sb.append('\"'); 54 | 55 | return sb.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/xml/Document.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.api.dom.xml; 17 | 18 | import org.mybatis.generator.api.dom.OutputUtilities; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class Document { 24 | private String publicId; 25 | 26 | private String systemId; 27 | 28 | private XmlElement rootElement; 29 | 30 | /** 31 | * 32 | */ 33 | public Document(String publicId, String systemId) { 34 | super(); 35 | this.publicId = publicId; 36 | this.systemId = systemId; 37 | } 38 | 39 | public Document() { 40 | super(); 41 | } 42 | 43 | /** 44 | * @return Returns the rootElement. 45 | */ 46 | public XmlElement getRootElement() { 47 | return rootElement; 48 | } 49 | 50 | /** 51 | * @param rootElement 52 | * The rootElement to set. 53 | */ 54 | public void setRootElement(XmlElement rootElement) { 55 | this.rootElement = rootElement; 56 | } 57 | 58 | /** 59 | * @return Returns the publicId. 60 | */ 61 | public String getPublicId() { 62 | return publicId; 63 | } 64 | 65 | /** 66 | * @return Returns the systemId. 67 | */ 68 | public String getSystemId() { 69 | return systemId; 70 | } 71 | 72 | public String getFormattedContent() { 73 | StringBuilder sb = new StringBuilder(); 74 | 75 | sb.append(""); //$NON-NLS-1$ 76 | 77 | if (publicId != null && systemId != null) { 78 | OutputUtilities.newLine(sb); 79 | sb.append(""); //$NON-NLS-1$ 86 | } 87 | 88 | OutputUtilities.newLine(sb); 89 | sb.append(rootElement.getFormattedContent(0)); 90 | 91 | return sb.toString(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/xml/Element.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.api.dom.xml; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public abstract class Element { 22 | 23 | /** 24 | * 25 | */ 26 | public Element() { 27 | super(); 28 | } 29 | 30 | public abstract String getFormattedContent(int indentLevel); 31 | } 32 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/dom/xml/TextElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.api.dom.xml; 17 | 18 | import org.mybatis.generator.api.dom.OutputUtilities; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class TextElement extends Element { 24 | private String content; 25 | 26 | /** 27 | * 28 | */ 29 | public TextElement(String content) { 30 | super(); 31 | this.content = content; 32 | } 33 | 34 | @Override 35 | public String getFormattedContent(int indentLevel) { 36 | StringBuilder sb = new StringBuilder(); 37 | OutputUtilities.xmlIndent(sb, indentLevel); 38 | sb.append(content); 39 | return sb.toString(); 40 | } 41 | 42 | public String getContent() { 43 | return content; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/api/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Package Description for Main MyBatis Generator API Classes 4 | 5 | 6 |

Provides the main classes and interfaces used by clients of MyBatis Generator.

7 | 8 | 9 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/AbstractGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.generator.api.IntrospectedTable; 21 | import org.mybatis.generator.api.ProgressCallback; 22 | import org.mybatis.generator.config.Context; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public abstract class AbstractGenerator { 30 | protected Context context; 31 | protected IntrospectedTable introspectedTable; 32 | protected List warnings; 33 | protected ProgressCallback progressCallback; 34 | 35 | public AbstractGenerator() { 36 | super(); 37 | } 38 | 39 | public Context getContext() { 40 | return context; 41 | } 42 | 43 | public void setContext(Context context) { 44 | this.context = context; 45 | } 46 | 47 | public IntrospectedTable getIntrospectedTable() { 48 | return introspectedTable; 49 | } 50 | 51 | public void setIntrospectedTable(IntrospectedTable introspectedTable) { 52 | this.introspectedTable = introspectedTable; 53 | } 54 | 55 | public List getWarnings() { 56 | return warnings; 57 | } 58 | 59 | public void setWarnings(List warnings) { 60 | this.warnings = warnings; 61 | } 62 | 63 | public ProgressCallback getProgressCallback() { 64 | return progressCallback; 65 | } 66 | 67 | public void setProgressCallback(ProgressCallback progressCallback) { 68 | this.progressCallback = progressCallback; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/AbstractJavaClientGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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; 17 | 18 | /** 19 | * This class exists to that Java client generators can specify whether 20 | * an XML generator is required to match the methods in the 21 | * Java client. For example, a Java client built entirely with 22 | * annotations does not need matching XML. 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public abstract class AbstractJavaClientGenerator extends AbstractJavaGenerator { 28 | 29 | private boolean requiresXMLGenerator; 30 | 31 | public AbstractJavaClientGenerator(boolean requiresXMLGenerator) { 32 | super(); 33 | this.requiresXMLGenerator = requiresXMLGenerator; 34 | } 35 | 36 | /** 37 | * @return true if matching XML is required 38 | */ 39 | public boolean requiresXMLGenerator() { 40 | return requiresXMLGenerator; 41 | } 42 | 43 | /** 44 | * This method returns an instance of the XML generator associated 45 | * with this client generator. 46 | * 47 | * @return the matched XML generator. May return null if no 48 | * XML is required by this generator 49 | */ 50 | public abstract AbstractXmlGenerator getMatchedXMLGenerator(); 51 | } 52 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/AbstractXmlGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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; 17 | 18 | import org.mybatis.generator.api.dom.xml.Document; 19 | 20 | /** 21 | * 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public abstract class AbstractXmlGenerator extends AbstractGenerator { 26 | public abstract Document getDocument(); 27 | } 28 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/XmlConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public class XmlConstants { 22 | 23 | /** 24 | * Utility Class, no instances 25 | */ 26 | private XmlConstants() { 27 | super(); 28 | } 29 | 30 | public static final String IBATIS2_SQL_MAP_SYSTEM_ID = "http://ibatis.apache.org/dtd/sql-map-2.dtd"; //$NON-NLS-1$ 31 | 32 | public static final String IBATIS2_SQL_MAP_PUBLIC_ID = "-//ibatis.apache.org//DTD SQL Map 2.0//EN"; //$NON-NLS-1$ 33 | 34 | public static final String IBATIS2_SQL_MAP_CONFIG_SYSTEM_ID = "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"; //$NON-NLS-1$ 35 | 36 | public static final String IBATIS2_SQL_MAP_CONFIG_PUBLIC_ID = "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"; //$NON-NLS-1$ 37 | 38 | public static final String MYBATIS3_MAPPER_SYSTEM_ID = "http://mybatis.org/dtd/mybatis-3-mapper.dtd"; //$NON-NLS-1$ 39 | 40 | public static final String MYBATIS3_MAPPER_PUBLIC_ID = "-//mybatis.org//DTD Mapper 3.0//EN"; //$NON-NLS-1$ 41 | 42 | public static final String MYBATIS3_MAPPER_CONFIG_SYSTEM_ID = "http://mybatis.org/dtd/mybatis-3-config.dtd"; //$NON-NLS-1$ 43 | 44 | public static final String MYBATIS3_MAPPER_CONFIG_PUBLIC_ID = "-//mybatis.org//DTD Config 3.0//EN"; //$NON-NLS-1$ 45 | 46 | public static final String IBATOR_CONFIG_SYSTEM_ID = "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd"; //$NON-NLS-1$ 47 | 48 | public static final String IBATOR_CONFIG_PUBLIC_ID = "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN"; //$NON-NLS-1$ 49 | 50 | public static final String MYBATIS_GENERATOR_CONFIG_SYSTEM_ID = "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"; //$NON-NLS-1$ 51 | 52 | public static final String MYBATIS_GENERATOR_CONFIG_PUBLIC_ID = "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"; //$NON-NLS-1$ 53 | } 54 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/IntrospectedTableIbatis2Java5Impl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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; 17 | 18 | /** 19 | * 20 | * @author Jeff Butler 21 | * 22 | */ 23 | public class IntrospectedTableIbatis2Java5Impl extends 24 | IntrospectedTableIbatis2Java2Impl { 25 | @Override 26 | public boolean isJava5Targeted() { 27 | return true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/dao/templates/IbatisDAOTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.templates; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.JavaVisibility; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.api.dom.java.Parameter; 22 | 23 | /** 24 | * @author Jeff Butler 25 | */ 26 | public class IbatisDAOTemplate extends AbstractDAOTemplate { 27 | 28 | private FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType( 29 | "com.ibatis.dao.client.DaoManager"); //$NON-NLS-1$ 30 | 31 | /** 32 | * 33 | */ 34 | public IbatisDAOTemplate() { 35 | super(); 36 | } 37 | 38 | @Override 39 | protected void configureConstructorTemplate() { 40 | Method method = new Method(); 41 | method.setConstructor(true); 42 | method.setVisibility(JavaVisibility.PUBLIC); 43 | method.addParameter(new Parameter(fqjt, "daoManager")); //$NON-NLS-1$ 44 | method.addBodyLine("super(daoManager);"); //$NON-NLS-1$ 45 | setConstructorTemplate(method); 46 | } 47 | 48 | @Override 49 | protected void configureDeleteMethodTemplate() { 50 | setDeleteMethodTemplate("delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 51 | } 52 | 53 | @Override 54 | protected void configureImplementationImports() { 55 | addImplementationImport(fqjt); 56 | } 57 | 58 | @Override 59 | protected void configureInsertMethodTemplate() { 60 | setInsertMethodTemplate("insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 61 | } 62 | 63 | @Override 64 | protected void configureQueryForListMethodTemplate() { 65 | setQueryForListMethodTemplate("queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 66 | } 67 | 68 | @Override 69 | protected void configureQueryForObjectMethodTemplate() { 70 | setQueryForObjectMethodTemplate("queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 71 | } 72 | 73 | @Override 74 | protected void configureSuperClass() { 75 | setSuperClass(new FullyQualifiedJavaType( 76 | "com.ibatis.dao.client.template.SqlMapDaoTemplate")); //$NON-NLS-1$ 77 | } 78 | 79 | @Override 80 | protected void configureUpdateMethodTemplate() { 81 | setUpdateMethodTemplate("update(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/dao/templates/SpringDAOTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.templates; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.JavaVisibility; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | 22 | /** 23 | * @author Jeff Butler 24 | */ 25 | public class SpringDAOTemplate extends AbstractDAOTemplate { 26 | 27 | /** 28 | * 29 | */ 30 | public SpringDAOTemplate() { 31 | super(); 32 | } 33 | 34 | @Override 35 | protected void configureConstructorTemplate() { 36 | Method method = new Method(); 37 | method.setConstructor(true); 38 | method.setVisibility(JavaVisibility.PUBLIC); 39 | method.addBodyLine("super();"); //$NON-NLS-1$ 40 | setConstructorTemplate(method); 41 | } 42 | 43 | @Override 44 | protected void configureDeleteMethodTemplate() { 45 | setDeleteMethodTemplate("getSqlMapClientTemplate().delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 46 | } 47 | 48 | @Override 49 | protected void configureInsertMethodTemplate() { 50 | setInsertMethodTemplate("getSqlMapClientTemplate().insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 51 | } 52 | 53 | @Override 54 | protected void configureQueryForListMethodTemplate() { 55 | setQueryForListMethodTemplate("getSqlMapClientTemplate().queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 56 | } 57 | 58 | @Override 59 | protected void configureQueryForObjectMethodTemplate() { 60 | setQueryForObjectMethodTemplate("getSqlMapClientTemplate().queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 61 | } 62 | 63 | @Override 64 | protected void configureSuperClass() { 65 | setSuperClass(new FullyQualifiedJavaType( 66 | "org.springframework.orm.ibatis.support.SqlMapClientDaoSupport")); //$NON-NLS-1$ 67 | } 68 | 69 | @Override 70 | protected void configureUpdateMethodTemplate() { 71 | setUpdateMethodTemplate("getSqlMapClientTemplate().update(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 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 iter = introspectedTable 48 | .getNonBLOBColumns().iterator(); 49 | while (iter.hasNext()) { 50 | sb.append(Ibatis2FormattingUtilities.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 | } 73 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 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 | } 74 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/CountByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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 org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class CountByExampleElementGenerator extends AbstractXmlElementGenerator { 28 | 29 | public CountByExampleElementGenerator() { 30 | super(); 31 | } 32 | 33 | @Override 34 | public void addElements(XmlElement parentElement) { 35 | XmlElement answer = new XmlElement("select"); //$NON-NLS-1$ 36 | 37 | answer.addAttribute(new Attribute( 38 | "id", introspectedTable.getCountByExampleStatementId())); //$NON-NLS-1$ 39 | answer.addAttribute(new Attribute( 40 | "parameterClass", introspectedTable.getExampleType())); //$NON-NLS-1$ 41 | answer.addAttribute(new Attribute("resultClass", "java.lang.Integer")); //$NON-NLS-1$ //$NON-NLS-2$ 42 | 43 | context.getCommentGenerator().addComment(answer); 44 | 45 | StringBuilder sb = new StringBuilder(); 46 | sb.append("select count(*) from "); //$NON-NLS-1$ 47 | sb.append(introspectedTable 48 | .getAliasedFullyQualifiedTableNameAtRuntime()); 49 | answer.addElement(new TextElement(sb.toString())); 50 | 51 | XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$ 52 | sb.setLength(0); 53 | sb.append(introspectedTable.getIbatis2SqlMapNamespace()); 54 | sb.append('.'); 55 | sb.append(introspectedTable.getExampleWhereClauseId()); 56 | includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$ 57 | sb.toString())); 58 | 59 | answer.addElement(includeElement); 60 | 61 | if (context.getPlugins().sqlMapCountByExampleElementGenerated( 62 | answer, introspectedTable)) { 63 | parentElement.addElement(answer); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/DeleteByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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 org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class DeleteByExampleElementGenerator extends 28 | AbstractXmlElementGenerator { 29 | 30 | public DeleteByExampleElementGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addElements(XmlElement parentElement) { 36 | XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$ 37 | 38 | answer.addAttribute(new Attribute( 39 | "id", introspectedTable.getDeleteByExampleStatementId())); //$NON-NLS-1$ 40 | answer.addAttribute(new Attribute( 41 | "parameterClass", introspectedTable.getExampleType())); //$NON-NLS-1$ 42 | 43 | context.getCommentGenerator().addComment(answer); 44 | 45 | StringBuilder sb = new StringBuilder(); 46 | sb.append("delete from "); //$NON-NLS-1$ 47 | sb.append(introspectedTable 48 | .getAliasedFullyQualifiedTableNameAtRuntime()); 49 | answer.addElement(new TextElement(sb.toString())); 50 | 51 | XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$ 52 | sb.setLength(0); 53 | sb.append(introspectedTable.getIbatis2SqlMapNamespace()); 54 | sb.append('.'); 55 | sb.append(introspectedTable.getExampleWhereClauseId()); 56 | includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$ 57 | sb.toString())); 58 | 59 | answer.addElement(includeElement); 60 | 61 | if (context.getPlugins().sqlMapDeleteByExampleElementGenerated( 62 | answer, introspectedTable)) { 63 | parentElement.addElement(answer); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/DeleteByPrimaryKeyElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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 org.mybatis.generator.api.IntrospectedColumn; 19 | import org.mybatis.generator.api.dom.xml.Attribute; 20 | import org.mybatis.generator.api.dom.xml.TextElement; 21 | import org.mybatis.generator.api.dom.xml.XmlElement; 22 | import org.mybatis.generator.codegen.ibatis2.Ibatis2FormattingUtilities; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class DeleteByPrimaryKeyElementGenerator extends 30 | AbstractXmlElementGenerator { 31 | 32 | public DeleteByPrimaryKeyElementGenerator() { 33 | super(); 34 | } 35 | 36 | @Override 37 | public void addElements(XmlElement parentElement) { 38 | XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$ 39 | 40 | answer.addAttribute(new Attribute( 41 | "id", introspectedTable.getDeleteByPrimaryKeyStatementId())); //$NON-NLS-1$ 42 | String parameterClass; 43 | if (introspectedTable.getRules().generatePrimaryKeyClass()) { 44 | parameterClass = introspectedTable.getPrimaryKeyType(); 45 | } else { 46 | parameterClass = introspectedTable.getBaseRecordType(); 47 | } 48 | answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$ 49 | parameterClass)); 50 | 51 | context.getCommentGenerator().addComment(answer); 52 | 53 | StringBuilder sb = new StringBuilder(); 54 | sb.append("delete from "); //$NON-NLS-1$ 55 | sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime()); 56 | answer.addElement(new TextElement(sb.toString())); 57 | 58 | boolean and = false; 59 | for (IntrospectedColumn introspectedColumn : introspectedTable 60 | .getPrimaryKeyColumns()) { 61 | sb.setLength(0); 62 | if (and) { 63 | sb.append(" and "); //$NON-NLS-1$ 64 | } else { 65 | sb.append("where "); //$NON-NLS-1$ 66 | and = true; 67 | } 68 | 69 | sb.append(Ibatis2FormattingUtilities 70 | .getEscapedColumnName(introspectedColumn)); 71 | sb.append(" = "); //$NON-NLS-1$ 72 | sb.append(Ibatis2FormattingUtilities 73 | .getParameterClause(introspectedColumn)); 74 | answer.addElement(new TextElement(sb.toString())); 75 | } 76 | 77 | if (context.getPlugins() 78 | .sqlMapDeleteByPrimaryKeyElementGenerated(answer, 79 | introspectedTable)) { 80 | parentElement.addElement(answer); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/CountByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class CountByExampleMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public CountByExampleMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType( 42 | introspectedTable.getExampleType()); 43 | 44 | Set importedTypes = new TreeSet(); 45 | importedTypes.add(fqjt); 46 | 47 | Method method = new Method(); 48 | method.setVisibility(JavaVisibility.PUBLIC); 49 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 50 | method.setName(introspectedTable.getCountByExampleStatementId()); 51 | method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ 52 | context.getCommentGenerator().addGeneralMethodComment(method, 53 | introspectedTable); 54 | 55 | addMapperAnnotations(interfaze, method); 56 | 57 | if (context.getPlugins().clientCountByExampleMethodGenerated(method, 58 | interfaze, introspectedTable)) { 59 | interfaze.addImportedTypes(importedTypes); 60 | interfaze.addMethod(method); 61 | } 62 | } 63 | 64 | public void addMapperAnnotations(Interface interfaze, Method method) { 65 | return; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/DeleteByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class DeleteByExampleMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public DeleteByExampleMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType type = new FullyQualifiedJavaType( 43 | introspectedTable.getExampleType()); 44 | importedTypes.add(type); 45 | 46 | Method method = new Method(); 47 | method.setVisibility(JavaVisibility.PUBLIC); 48 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 49 | method.setName(introspectedTable.getDeleteByExampleStatementId()); 50 | method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$ 51 | 52 | context.getCommentGenerator().addGeneralMethodComment(method, 53 | introspectedTable); 54 | 55 | addMapperAnnotations(interfaze, method); 56 | 57 | if (context.getPlugins().clientDeleteByExampleMethodGenerated( 58 | method, interfaze, introspectedTable)) { 59 | interfaze.addImportedTypes(importedTypes); 60 | interfaze.addMethod(method); 61 | } 62 | } 63 | 64 | public void addMapperAnnotations(Interface interfaze, Method method) { 65 | return; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/InsertMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class InsertMethodGenerator extends AbstractJavaMapperMethodGenerator { 33 | 34 | boolean isSimple; 35 | 36 | public InsertMethodGenerator(boolean isSimple) { 37 | super(); 38 | this.isSimple = isSimple; 39 | } 40 | 41 | @Override 42 | public void addInterfaceElements(Interface interfaze) { 43 | Set importedTypes = new TreeSet(); 44 | Method method = new Method(); 45 | 46 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 47 | method.setVisibility(JavaVisibility.PUBLIC); 48 | method.setName(introspectedTable.getInsertStatementId()); 49 | 50 | FullyQualifiedJavaType parameterType; 51 | if (isSimple) { 52 | parameterType = new FullyQualifiedJavaType( 53 | introspectedTable.getBaseRecordType()); 54 | } else { 55 | parameterType = introspectedTable.getRules() 56 | .calculateAllFieldsClass(); 57 | } 58 | 59 | importedTypes.add(parameterType); 60 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 61 | 62 | context.getCommentGenerator().addGeneralMethodComment(method, 63 | introspectedTable); 64 | 65 | addMapperAnnotations(interfaze, method); 66 | 67 | if (context.getPlugins().clientInsertMethodGenerated(method, interfaze, 68 | introspectedTable)) { 69 | interfaze.addImportedTypes(importedTypes); 70 | interfaze.addMethod(method); 71 | } 72 | } 73 | 74 | public void addMapperAnnotations(Interface interfaze, Method method) { 75 | return; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/InsertSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class InsertSelectiveMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public InsertSelectiveMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | Method method = new Method(); 43 | 44 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 45 | method.setVisibility(JavaVisibility.PUBLIC); 46 | method.setName(introspectedTable.getInsertSelectiveStatementId()); 47 | 48 | FullyQualifiedJavaType parameterType = introspectedTable.getRules() 49 | .calculateAllFieldsClass(); 50 | 51 | importedTypes.add(parameterType); 52 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 53 | 54 | context.getCommentGenerator().addGeneralMethodComment(method, 55 | introspectedTable); 56 | 57 | addMapperAnnotations(interfaze, method); 58 | 59 | if (context.getPlugins().clientInsertSelectiveMethodGenerated( 60 | method, interfaze, introspectedTable)) { 61 | interfaze.addImportedTypes(importedTypes); 62 | interfaze.addMethod(method); 63 | } 64 | } 65 | 66 | public void addMapperAnnotations(Interface interfaze, Method method) { 67 | return; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/SelectAllMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The MyBatis Team 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | 26 | /** 27 | * The selectAll method is only generated by the Mybatis3Simple runtime. 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class SelectAllMethodGenerator extends AbstractJavaMapperMethodGenerator { 33 | 34 | public SelectAllMethodGenerator() { 35 | super(); 36 | } 37 | 38 | @Override 39 | public void addInterfaceElements(Interface interfaze) { 40 | Set importedTypes = new TreeSet(); 41 | importedTypes.add(FullyQualifiedJavaType.getNewListInstance()); 42 | 43 | Method method = new Method(); 44 | method.setVisibility(JavaVisibility.PUBLIC); 45 | 46 | FullyQualifiedJavaType returnType = FullyQualifiedJavaType 47 | .getNewListInstance(); 48 | FullyQualifiedJavaType listType; 49 | listType = new FullyQualifiedJavaType( 50 | introspectedTable.getBaseRecordType()); 51 | 52 | importedTypes.add(listType); 53 | returnType.addTypeArgument(listType); 54 | method.setReturnType(returnType); 55 | method.setName(introspectedTable.getSelectAllStatementId()); 56 | 57 | context.getCommentGenerator().addGeneralMethodComment(method, 58 | introspectedTable); 59 | 60 | addMapperAnnotations(interfaze, method); 61 | 62 | if (context.getPlugins().clientSelectAllMethodGenerated(method, 63 | interfaze, introspectedTable)) { 64 | interfaze.addImportedTypes(importedTypes); 65 | interfaze.addMethod(method); 66 | } 67 | } 68 | 69 | public void addMapperAnnotations(Interface interfaze, Method method) { 70 | return; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/SelectByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class SelectByExampleWithBLOBsMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public SelectByExampleWithBLOBsMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType type = new FullyQualifiedJavaType( 43 | introspectedTable.getExampleType()); 44 | importedTypes.add(type); 45 | importedTypes.add(FullyQualifiedJavaType.getNewListInstance()); 46 | 47 | Method method = new Method(); 48 | method.setVisibility(JavaVisibility.PUBLIC); 49 | 50 | FullyQualifiedJavaType returnType = FullyQualifiedJavaType 51 | .getNewListInstance(); 52 | FullyQualifiedJavaType listType; 53 | if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { 54 | listType = new FullyQualifiedJavaType(introspectedTable 55 | .getRecordWithBLOBsType()); 56 | } else { 57 | // the blob fields must be rolled up into the base class 58 | listType = new FullyQualifiedJavaType(introspectedTable 59 | .getBaseRecordType()); 60 | } 61 | 62 | importedTypes.add(listType); 63 | returnType.addTypeArgument(listType); 64 | method.setReturnType(returnType); 65 | method.setName(introspectedTable 66 | .getSelectByExampleWithBLOBsStatementId()); 67 | method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$ 68 | 69 | context.getCommentGenerator().addGeneralMethodComment(method, 70 | introspectedTable); 71 | 72 | addMapperAnnotations(interfaze, method); 73 | 74 | if (context.getPlugins() 75 | .clientSelectByExampleWithBLOBsMethodGenerated(method, interfaze, 76 | introspectedTable)) { 77 | interfaze.addImportedTypes(importedTypes); 78 | interfaze.addMethod(method); 79 | } 80 | } 81 | 82 | public void addMapperAnnotations(Interface interfaze, Method method) { 83 | return; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByExampleSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByExampleSelectiveMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | @Override 36 | public void addInterfaceElements(Interface interfaze) { 37 | Set importedTypes = new TreeSet(); 38 | Method method = new Method(); 39 | method.setVisibility(JavaVisibility.PUBLIC); 40 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 41 | method.setName(introspectedTable 42 | .getUpdateByExampleSelectiveStatementId()); 43 | 44 | FullyQualifiedJavaType parameterType = 45 | introspectedTable.getRules().calculateAllFieldsClass(); 46 | method.addParameter(new Parameter(parameterType, 47 | "record", "@Param(\"record\")")); //$NON-NLS-1$ //$NON-NLS-2$ 48 | importedTypes.add(parameterType); 49 | 50 | FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType( 51 | introspectedTable.getExampleType()); 52 | method.addParameter(new Parameter(exampleType, 53 | "example", "@Param(\"example\")")); //$NON-NLS-1$ //$NON-NLS-2$ 54 | importedTypes.add(exampleType); 55 | 56 | importedTypes.add(new FullyQualifiedJavaType( 57 | "org.apache.ibatis.annotations.Param")); //$NON-NLS-1$ 58 | 59 | context.getCommentGenerator().addGeneralMethodComment(method, 60 | introspectedTable); 61 | 62 | addMapperAnnotations(interfaze, method); 63 | 64 | if (context.getPlugins() 65 | .clientUpdateByExampleSelectiveMethodGenerated(method, interfaze, 66 | introspectedTable)) { 67 | interfaze.addImportedTypes(importedTypes); 68 | interfaze.addMethod(method); 69 | } 70 | } 71 | 72 | public void addMapperAnnotations(Interface interfaze, Method method) { 73 | return; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByExampleWithoutBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByExampleWithoutBLOBsMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public UpdateByExampleWithoutBLOBsMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | Method method = new Method(); 43 | method.setVisibility(JavaVisibility.PUBLIC); 44 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 45 | method.setName(introspectedTable.getUpdateByExampleStatementId()); 46 | 47 | FullyQualifiedJavaType parameterType; 48 | if (introspectedTable.getRules().generateBaseRecordClass()) { 49 | parameterType = new FullyQualifiedJavaType(introspectedTable 50 | .getBaseRecordType()); 51 | } else { 52 | parameterType = new FullyQualifiedJavaType(introspectedTable 53 | .getPrimaryKeyType()); 54 | } 55 | method.addParameter(new Parameter(parameterType, 56 | "record", "@Param(\"record\")")); //$NON-NLS-1$ //$NON-NLS-2$ 57 | importedTypes.add(parameterType); 58 | 59 | FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType( 60 | introspectedTable.getExampleType()); 61 | method.addParameter(new Parameter(exampleType, 62 | "example", "@Param(\"example\")")); //$NON-NLS-1$ //$NON-NLS-2$ 63 | importedTypes.add(exampleType); 64 | 65 | importedTypes.add(new FullyQualifiedJavaType( 66 | "org.apache.ibatis.annotations.Param")); //$NON-NLS-1$ 67 | 68 | context.getCommentGenerator().addGeneralMethodComment(method, 69 | introspectedTable); 70 | 71 | addMapperAnnotations(interfaze, method); 72 | 73 | if (context.getPlugins() 74 | .clientUpdateByExampleWithoutBLOBsMethodGenerated(method, 75 | interfaze, introspectedTable)) { 76 | interfaze.addImportedTypes(importedTypes); 77 | interfaze.addMethod(method); 78 | } 79 | } 80 | 81 | public void addMapperAnnotations(Interface interfaze, Method method) { 82 | return; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByPrimaryKeySelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByPrimaryKeySelectiveMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public UpdateByPrimaryKeySelectiveMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType parameterType; 43 | 44 | if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { 45 | parameterType = new FullyQualifiedJavaType(introspectedTable 46 | .getRecordWithBLOBsType()); 47 | } else { 48 | parameterType = new FullyQualifiedJavaType(introspectedTable 49 | .getBaseRecordType()); 50 | } 51 | 52 | importedTypes.add(parameterType); 53 | 54 | Method method = new Method(); 55 | method.setVisibility(JavaVisibility.PUBLIC); 56 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 57 | method.setName(introspectedTable 58 | .getUpdateByPrimaryKeySelectiveStatementId()); 59 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 60 | 61 | context.getCommentGenerator().addGeneralMethodComment(method, 62 | introspectedTable); 63 | 64 | addMapperAnnotations(interfaze, method); 65 | 66 | if (context.getPlugins() 67 | .clientUpdateByPrimaryKeySelectiveMethodGenerated(method, 68 | interfaze, introspectedTable)) { 69 | interfaze.addImportedTypes(importedTypes); 70 | interfaze.addMethod(method); 71 | } 72 | } 73 | 74 | public void addMapperAnnotations(Interface interfaze, Method method) { 75 | return; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByPrimaryKeyWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByPrimaryKeyWithBLOBsMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public UpdateByPrimaryKeyWithBLOBsMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType parameterType; 43 | 44 | if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { 45 | parameterType = new FullyQualifiedJavaType(introspectedTable 46 | .getRecordWithBLOBsType()); 47 | } else { 48 | parameterType = new FullyQualifiedJavaType(introspectedTable 49 | .getBaseRecordType()); 50 | } 51 | 52 | importedTypes.add(parameterType); 53 | 54 | Method method = new Method(); 55 | method.setVisibility(JavaVisibility.PUBLIC); 56 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 57 | 58 | method.setName(introspectedTable 59 | .getUpdateByPrimaryKeyWithBLOBsStatementId()); 60 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 61 | 62 | context.getCommentGenerator().addGeneralMethodComment(method, 63 | introspectedTable); 64 | 65 | addMapperAnnotations(interfaze, method); 66 | 67 | if (context.getPlugins() 68 | .clientUpdateByPrimaryKeyWithBLOBsMethodGenerated(method, 69 | interfaze, introspectedTable)) { 70 | interfaze.addImportedTypes(importedTypes); 71 | interfaze.addMethod(method); 72 | } 73 | } 74 | 75 | public void addMapperAnnotations(Interface interfaze, Method method) { 76 | return; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByPrimaryKeyWithoutBLOBsMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public UpdateByPrimaryKeyWithoutBLOBsMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType( 43 | introspectedTable.getBaseRecordType()); 44 | importedTypes.add(parameterType); 45 | 46 | Method method = new Method(); 47 | method.setVisibility(JavaVisibility.PUBLIC); 48 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 49 | method.setName(introspectedTable.getUpdateByPrimaryKeyStatementId()); 50 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 51 | 52 | context.getCommentGenerator().addGeneralMethodComment(method, 53 | introspectedTable); 54 | 55 | addMapperAnnotations(interfaze, method); 56 | 57 | if (context.getPlugins() 58 | .clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method, 59 | interfaze, introspectedTable)) { 60 | interfaze.addImportedTypes(importedTypes); 61 | interfaze.addMethod(method); 62 | } 63 | } 64 | 65 | public void addMapperAnnotations(Interface interfaze, Method method) { 66 | return; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedCountByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.CountByExampleMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedCountByExampleMethodGenerator extends 28 | CountByExampleMethodGenerator { 29 | 30 | public AnnotatedCountByExampleMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.SelectProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@SelectProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getCountByExampleStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedDeleteByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.DeleteByExampleMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedDeleteByExampleMethodGenerator extends 28 | DeleteByExampleMethodGenerator { 29 | 30 | public AnnotatedDeleteByExampleMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.DeleteProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@DeleteProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getDeleteByExampleStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedInsertSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.InsertSelectiveMethodGenerator; 22 | import org.mybatis.generator.config.GeneratedKey; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | */ 28 | public class AnnotatedInsertSelectiveMethodGenerator extends 29 | InsertSelectiveMethodGenerator { 30 | 31 | public AnnotatedInsertSelectiveMethodGenerator() { 32 | super(); 33 | } 34 | 35 | @Override 36 | public void addMapperAnnotations(Interface interfaze, Method method) { 37 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 38 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.InsertProvider")); //$NON-NLS-1$ 39 | StringBuilder sb = new StringBuilder(); 40 | sb.append("@InsertProvider(type="); //$NON-NLS-1$ 41 | sb.append(fqjt.getShortName()); 42 | sb.append(".class, method=\""); //$NON-NLS-1$ 43 | sb.append(introspectedTable.getInsertSelectiveStatementId()); 44 | sb.append("\")"); //$NON-NLS-1$ 45 | 46 | method.addAnnotation(sb.toString()); 47 | 48 | GeneratedKey gk = introspectedTable.getGeneratedKey(); 49 | if (gk != null) { 50 | addGeneratedKeyAnnotation(interfaze, method, gk); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByExampleSelectiveMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByExampleSelectiveMethodGenerator extends 28 | UpdateByExampleSelectiveMethodGenerator { 29 | 30 | public AnnotatedUpdateByExampleSelectiveMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByExampleSelectiveStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByExampleWithBLOBsMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByExampleWithBLOBsMethodGenerator extends 28 | UpdateByExampleWithBLOBsMethodGenerator { 29 | 30 | public AnnotatedUpdateByExampleWithBLOBsMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByExampleWithBLOBsStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByExampleWithoutBLOBsMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator extends 28 | UpdateByExampleWithoutBLOBsMethodGenerator { 29 | 30 | public AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByExampleStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByPrimaryKeySelectiveMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator extends 28 | UpdateByPrimaryKeySelectiveMethodGenerator { 29 | 30 | public AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByPrimaryKeySelectiveStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/AbstractJavaProviderMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.sqlprovider; 17 | 18 | import org.mybatis.generator.api.dom.java.TopLevelClass; 19 | import org.mybatis.generator.codegen.AbstractGenerator; 20 | 21 | /** 22 | * 23 | * @author Jeff Butler 24 | */ 25 | public abstract class AbstractJavaProviderMethodGenerator extends 26 | AbstractGenerator { 27 | 28 | public AbstractJavaProviderMethodGenerator() { 29 | super(); 30 | } 31 | 32 | public abstract void addClassElements(TopLevelClass topLevelClass); 33 | } 34 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderDeleteByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.sqlprovider; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.escapeStringForJava; 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.JavaVisibility; 25 | import org.mybatis.generator.api.dom.java.Method; 26 | import org.mybatis.generator.api.dom.java.Parameter; 27 | import org.mybatis.generator.api.dom.java.TopLevelClass; 28 | 29 | /** 30 | * 31 | * @author Jeff Butler 32 | * 33 | */ 34 | public class ProviderDeleteByExampleMethodGenerator extends 35 | AbstractJavaProviderMethodGenerator { 36 | 37 | public ProviderDeleteByExampleMethodGenerator() { 38 | super(); 39 | } 40 | 41 | @Override 42 | public void addClassElements(TopLevelClass topLevelClass) { 43 | Set staticImports = new TreeSet(); 44 | Set importedTypes = new TreeSet(); 45 | 46 | staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ 47 | staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.DELETE_FROM"); //$NON-NLS-1$ 48 | staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ 49 | 50 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); 51 | importedTypes.add(fqjt); 52 | 53 | Method method = new Method( 54 | introspectedTable.getDeleteByExampleStatementId()); 55 | method.setVisibility(JavaVisibility.PUBLIC); 56 | method.setReturnType(FullyQualifiedJavaType.getStringInstance()); 57 | method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ 58 | 59 | context.getCommentGenerator().addGeneralMethodComment(method, 60 | introspectedTable); 61 | 62 | method.addBodyLine("BEGIN();"); //$NON-NLS-1$ 63 | method.addBodyLine(String.format("DELETE_FROM(\"%s\");", //$NON-NLS-1$ 64 | escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); 65 | method.addBodyLine("applyWhere(example, false);"); //$NON-NLS-1$ 66 | method.addBodyLine("return SQL();"); //$NON-NLS-1$ 67 | 68 | 69 | if (context.getPlugins().providerDeleteByExampleMethodGenerated(method, topLevelClass, 70 | introspectedTable)) { 71 | topLevelClass.addStaticImports(staticImports); 72 | topLevelClass.addImportedTypes(importedTypes); 73 | topLevelClass.addMethod(method); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderSelectByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.sqlprovider; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.java.Method; 22 | import org.mybatis.generator.api.dom.java.TopLevelClass; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class ProviderSelectByExampleWithBLOBsMethodGenerator extends 30 | ProviderSelectByExampleWithoutBLOBsMethodGenerator { 31 | 32 | public ProviderSelectByExampleWithBLOBsMethodGenerator() { 33 | super(); 34 | } 35 | 36 | @Override 37 | public List getColumns() { 38 | return introspectedTable.getAllColumns(); 39 | } 40 | 41 | @Override 42 | public String getMethodName() { 43 | return introspectedTable.getSelectByExampleWithBLOBsStatementId(); 44 | } 45 | 46 | @Override 47 | public boolean callPlugins(Method method, TopLevelClass topLevelClass) { 48 | return context.getPlugins().providerSelectByExampleWithBLOBsMethodGenerated(method, topLevelClass, 49 | introspectedTable); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderUpdateByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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.sqlprovider; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.java.Method; 22 | import org.mybatis.generator.api.dom.java.TopLevelClass; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class ProviderUpdateByExampleWithBLOBsMethodGenerator extends 30 | ProviderUpdateByExampleWithoutBLOBsMethodGenerator { 31 | 32 | public ProviderUpdateByExampleWithBLOBsMethodGenerator() { 33 | super(); 34 | } 35 | 36 | @Override 37 | public String getMethodName() { 38 | return introspectedTable.getUpdateByExampleWithBLOBsStatementId(); 39 | } 40 | 41 | @Override 42 | public List getColumns() { 43 | return introspectedTable.getAllColumns(); 44 | } 45 | 46 | @Override 47 | public boolean callPlugins(Method method, TopLevelClass topLevelClass) { 48 | return context.getPlugins().providerUpdateByExampleWithBLOBsMethodGenerated(method, topLevelClass, 49 | introspectedTable); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/xmlmapper/MixedMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 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; 17 | 18 | import org.mybatis.generator.api.dom.xml.XmlElement; 19 | 20 | /** 21 | * 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public class MixedMapperGenerator extends XMLMapperGenerator { 26 | 27 | @Override 28 | protected void addSelectByPrimaryKeyElement(XmlElement parentElement) { 29 | return; 30 | } 31 | 32 | @Override 33 | protected void addDeleteByPrimaryKeyElement(XmlElement parentElement) { 34 | return; 35 | } 36 | 37 | @Override 38 | protected void addInsertElement(XmlElement parentElement) { 39 | return; 40 | } 41 | 42 | @Override 43 | protected void addUpdateByPrimaryKeyWithBLOBsElement( 44 | XmlElement parentElement) { 45 | return; 46 | } 47 | 48 | @Override 49 | protected void addUpdateByPrimaryKeyWithoutBLOBsElement( 50 | XmlElement parentElement) { 51 | return; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/BaseColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 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 | } 73 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/BlobColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 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 iter = introspectedTable.getBLOBColumns() 49 | .iterator(); 50 | while (iter.hasNext()) { 51 | sb.append(MyBatis3FormattingUtilities.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 | } 74 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/CountByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class CountByExampleElementGenerator extends AbstractXmlElementGenerator { 28 | 29 | public CountByExampleElementGenerator() { 30 | super(); 31 | } 32 | 33 | @Override 34 | public void addElements(XmlElement parentElement) { 35 | XmlElement answer = new XmlElement("select"); //$NON-NLS-1$ 36 | 37 | String fqjt = introspectedTable.getExampleType(); 38 | 39 | answer.addAttribute(new Attribute( 40 | "id", introspectedTable.getCountByExampleStatementId())); //$NON-NLS-1$ 41 | answer.addAttribute(new Attribute("parameterType", fqjt)); //$NON-NLS-1$ 42 | answer.addAttribute(new Attribute("resultType", "java.lang.Integer")); //$NON-NLS-1$ //$NON-NLS-2$ 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | sb.append("select count(*) from "); //$NON-NLS-1$ 48 | sb.append(introspectedTable 49 | .getAliasedFullyQualifiedTableNameAtRuntime()); 50 | answer.addElement(new TextElement(sb.toString())); 51 | answer.addElement(getExampleIncludeElement()); 52 | 53 | if (context.getPlugins().sqlMapCountByExampleElementGenerated( 54 | answer, introspectedTable)) { 55 | parentElement.addElement(answer); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/DeleteByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class DeleteByExampleElementGenerator extends 28 | AbstractXmlElementGenerator { 29 | 30 | public DeleteByExampleElementGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addElements(XmlElement parentElement) { 36 | XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$ 37 | 38 | String fqjt = introspectedTable.getExampleType(); 39 | 40 | answer.addAttribute(new Attribute( 41 | "id", introspectedTable.getDeleteByExampleStatementId())); //$NON-NLS-1$ 42 | answer.addAttribute(new Attribute("parameterType", fqjt)); //$NON-NLS-1$ 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | sb.append("delete from "); //$NON-NLS-1$ 48 | sb.append(introspectedTable 49 | .getAliasedFullyQualifiedTableNameAtRuntime()); 50 | answer.addElement(new TextElement(sb.toString())); 51 | answer.addElement(getExampleIncludeElement()); 52 | 53 | if (context.getPlugins().sqlMapDeleteByExampleElementGenerated( 54 | answer, introspectedTable)) { 55 | parentElement.addElement(answer); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/ColumnRenamingRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The Apache Software Foundation 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.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * This class is used to specify a renaming rule for columns in a table. This 28 | * renaming rule will be run against all column names before calculating the 29 | * corresponding property name. The most common use case is when columns in a 30 | * table are all prefixed by a certain value. 31 | * 32 | * For example, if columns in a table are named: 33 | * 34 | *
    35 | *
  • CUST_NAME
  • 36 | *
  • CUST_ADDRESS
  • 37 | *
  • CUST_CITY
  • 38 | *
  • CUST_STATE
  • 39 | *
40 | * 41 | * it might be annoying to have the generated properties all containing the CUST 42 | * prefix. This class can be used to remove the prefix by specifying 43 | * 44 | *
    45 | *
  • searchString = "^CUST"
  • 46 | *
  • replaceString=""
  • 47 | *
48 | * 49 | * Note that internally, the generator uses the 50 | * java.util.regex.Matcher.replaceAll method for this function. See 51 | * the documentation of that method for example of the regular expression 52 | * language used in Java. 53 | * 54 | * @author Jeff Butler 55 | * 56 | */ 57 | public class ColumnRenamingRule { 58 | private String searchString; 59 | private String replaceString; 60 | 61 | public String getReplaceString() { 62 | return replaceString; 63 | } 64 | 65 | public void setReplaceString(String replaceString) { 66 | this.replaceString = replaceString; 67 | } 68 | 69 | public String getSearchString() { 70 | return searchString; 71 | } 72 | 73 | public void setSearchString(String searchString) { 74 | this.searchString = searchString; 75 | } 76 | 77 | public void validate(List errors, String tableName) { 78 | if (!stringHasValue(searchString)) { 79 | errors.add(getString("ValidationError.14", tableName)); //$NON-NLS-1$ 80 | } 81 | } 82 | 83 | public XmlElement toXmlElement() { 84 | XmlElement xmlElement = new XmlElement("columnRenamingRule"); //$NON-NLS-1$ 85 | xmlElement.addAttribute(new Attribute("searchString", searchString)); //$NON-NLS-1$ 86 | 87 | if (replaceString != null) { 88 | xmlElement.addAttribute(new Attribute( 89 | "replaceString", replaceString)); //$NON-NLS-1$ 90 | } 91 | 92 | return xmlElement; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/CommentGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.config; 18 | 19 | import org.mybatis.generator.api.dom.xml.Attribute; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * @author Jeff Butler 24 | * 25 | */ 26 | public class CommentGeneratorConfiguration extends TypedPropertyHolder { 27 | 28 | /** 29 | * 30 | */ 31 | public CommentGeneratorConfiguration() { 32 | } 33 | 34 | public XmlElement toXmlElement() { 35 | XmlElement answer = new XmlElement("commentGenerator"); //$NON-NLS-1$ 36 | if (getConfigurationType() != null) { 37 | answer.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$ 38 | } 39 | 40 | addPropertyXmlElements(answer); 41 | 42 | return answer; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/IgnoredColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.config; 18 | 19 | import static org.mybatis.generator.internal.util.StringUtility.stringContainsSpace; 20 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 21 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 22 | 23 | import java.util.List; 24 | 25 | import org.mybatis.generator.api.dom.xml.Attribute; 26 | import org.mybatis.generator.api.dom.xml.XmlElement; 27 | 28 | /** 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class IgnoredColumn { 33 | 34 | private String columnName; 35 | 36 | private boolean isColumnNameDelimited; 37 | 38 | private String configuredDelimitedColumnName; 39 | 40 | /** 41 | * 42 | */ 43 | public IgnoredColumn(String columnName) { 44 | super(); 45 | this.columnName = columnName; 46 | isColumnNameDelimited = stringContainsSpace(columnName); 47 | } 48 | 49 | public String getColumnName() { 50 | return columnName; 51 | } 52 | 53 | public boolean isColumnNameDelimited() { 54 | return isColumnNameDelimited; 55 | } 56 | 57 | public void setColumnNameDelimited(boolean isColumnNameDelimited) { 58 | this.isColumnNameDelimited = isColumnNameDelimited; 59 | configuredDelimitedColumnName = isColumnNameDelimited ? "true" : "false"; //$NON-NLS-1$ //$NON-NLS-2$ 60 | } 61 | 62 | public boolean equals(Object obj) { 63 | if (obj == null || !(obj instanceof IgnoredColumn)) { 64 | return false; 65 | } 66 | 67 | return columnName.equals(((IgnoredColumn) obj).getColumnName()); 68 | } 69 | 70 | public int hashCode() { 71 | return columnName.hashCode(); 72 | } 73 | 74 | public XmlElement toXmlElement() { 75 | XmlElement xmlElement = new XmlElement("ignoreColumn"); //$NON-NLS-1$ 76 | xmlElement.addAttribute(new Attribute("column", columnName)); //$NON-NLS-1$ 77 | 78 | if (stringHasValue(configuredDelimitedColumnName)) { 79 | xmlElement.addAttribute(new Attribute( 80 | "delimitedColumnName", configuredDelimitedColumnName)); //$NON-NLS-1$ 81 | } 82 | 83 | return xmlElement; 84 | } 85 | 86 | public void validate(List errors, String tableName) { 87 | if (!stringHasValue(columnName)) { 88 | errors.add(getString("ValidationError.21", //$NON-NLS-1$ 89 | tableName)); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/JDBCConnectionConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | */ 30 | public class JDBCConnectionConfiguration extends PropertyHolder { 31 | 32 | private String driverClass; 33 | 34 | private String connectionURL; 35 | 36 | private String userId; 37 | 38 | private String password; 39 | 40 | public JDBCConnectionConfiguration() { 41 | super(); 42 | } 43 | 44 | public String getConnectionURL() { 45 | return connectionURL; 46 | } 47 | 48 | public void setConnectionURL(String connectionURL) { 49 | this.connectionURL = connectionURL; 50 | } 51 | 52 | public String getPassword() { 53 | return password; 54 | } 55 | 56 | public void setPassword(String password) { 57 | this.password = password; 58 | } 59 | 60 | public String getUserId() { 61 | return userId; 62 | } 63 | 64 | public void setUserId(String userId) { 65 | this.userId = userId; 66 | } 67 | 68 | public String getDriverClass() { 69 | return driverClass; 70 | } 71 | 72 | public void setDriverClass(String driverClass) { 73 | this.driverClass = driverClass; 74 | } 75 | 76 | public XmlElement toXmlElement() { 77 | XmlElement xmlElement = new XmlElement("jdbcConnection"); //$NON-NLS-1$ 78 | xmlElement.addAttribute(new Attribute("driverClass", driverClass)); //$NON-NLS-1$ 79 | xmlElement.addAttribute(new Attribute("connectionURL", connectionURL)); //$NON-NLS-1$ 80 | 81 | if (stringHasValue(userId)) { 82 | xmlElement.addAttribute(new Attribute("userId", userId)); //$NON-NLS-1$ 83 | } 84 | 85 | if (stringHasValue(password)) { 86 | xmlElement.addAttribute(new Attribute("password", password)); //$NON-NLS-1$ 87 | } 88 | 89 | addPropertyXmlElements(xmlElement); 90 | 91 | return xmlElement; 92 | } 93 | 94 | public void validate(List errors) { 95 | if (!stringHasValue(driverClass)) { 96 | errors.add(getString("ValidationError.4")); //$NON-NLS-1$ 97 | } 98 | 99 | if (!stringHasValue(connectionURL)) { 100 | errors.add(getString("ValidationError.5")); //$NON-NLS-1$ 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/JavaModelGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class JavaModelGeneratorConfiguration extends PropertyHolder { 30 | 31 | private String targetPackage; 32 | 33 | private String targetProject; 34 | 35 | /** 36 | * 37 | */ 38 | public JavaModelGeneratorConfiguration() { 39 | super(); 40 | } 41 | 42 | public String getTargetProject() { 43 | return targetProject; 44 | } 45 | 46 | public void setTargetProject(String targetProject) { 47 | this.targetProject = targetProject; 48 | } 49 | 50 | public String getTargetPackage() { 51 | return targetPackage; 52 | } 53 | 54 | public void setTargetPackage(String targetPackage) { 55 | this.targetPackage = targetPackage; 56 | } 57 | 58 | public XmlElement toXmlElement() { 59 | XmlElement answer = new XmlElement("javaModelGenerator"); //$NON-NLS-1$ 60 | 61 | if (targetPackage != null) { 62 | answer.addAttribute(new Attribute("targetPackage", targetPackage)); //$NON-NLS-1$ 63 | } 64 | 65 | if (targetProject != null) { 66 | answer.addAttribute(new Attribute("targetProject", targetProject)); //$NON-NLS-1$ 67 | } 68 | 69 | addPropertyXmlElements(answer); 70 | 71 | return answer; 72 | } 73 | 74 | public void validate(List errors, String contextId) { 75 | if (!stringHasValue(targetProject)) { 76 | errors.add(getString("ValidationError.0", contextId)); //$NON-NLS-1$ 77 | } 78 | 79 | if (!stringHasValue(targetPackage)) { 80 | errors.add(getString("ValidationError.12", //$NON-NLS-1$ 81 | "JavaModelGenerator", contextId)); //$NON-NLS-1$ 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/JavaTypeResolverConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.config; 17 | 18 | import org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.XmlElement; 20 | 21 | /** 22 | * @author Jeff Butler 23 | */ 24 | public class JavaTypeResolverConfiguration extends TypedPropertyHolder { 25 | 26 | /** 27 | * 28 | */ 29 | public JavaTypeResolverConfiguration() { 30 | super(); 31 | } 32 | 33 | public XmlElement toXmlElement() { 34 | XmlElement answer = new XmlElement("javaTypeResolver"); //$NON-NLS-1$ 35 | if (getConfigurationType() != null) { 36 | answer.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$ 37 | } 38 | 39 | addPropertyXmlElements(answer); 40 | 41 | return answer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/MergeConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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.config; 17 | 18 | /** 19 | * This class holds constants useful in the XML and Java merging operations. 20 | * 21 | * @author Jeff Butler 22 | * 23 | */ 24 | public class MergeConstants { 25 | 26 | /** 27 | * Utility class - no instances 28 | * 29 | */ 30 | private MergeConstants() { 31 | } 32 | 33 | public static final String[] OLD_XML_ELEMENT_PREFIXES = { 34 | "ibatorgenerated_", "abatorgenerated_" }; //$NON-NLS-1$ //$NON-NLS-2$ 35 | 36 | public static final String NEW_ELEMENT_TAG = "@mbggenerated"; //$NON-NLS-1$ 37 | public static final String[] OLD_ELEMENT_TAGS = { 38 | "@ibatorgenerated", "@abatorgenerated", "@mbggenerated" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/ModelType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.config; 18 | 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | /** 22 | * Typesafe enum of different model types 23 | * 24 | * @author Jeff Butler 25 | */ 26 | public enum ModelType { 27 | HIERARCHICAL("hierarchical"), //$NON-NLS-1$ 28 | FLAT("flat"), //$NON-NLS-1$ 29 | CONDITIONAL("conditional"); //$NON-NLS-1$ 30 | 31 | private final String modelType; 32 | 33 | /** 34 | * 35 | */ 36 | private ModelType(String modelType) { 37 | this.modelType = modelType; 38 | } 39 | 40 | public String getModelType() { 41 | return modelType; 42 | } 43 | 44 | public static ModelType getModelType(String type) { 45 | if (HIERARCHICAL.getModelType().equalsIgnoreCase(type)) { 46 | return HIERARCHICAL; 47 | } else if (FLAT.getModelType().equalsIgnoreCase(type)) { 48 | return FLAT; 49 | } else if (CONDITIONAL.getModelType().equalsIgnoreCase(type)) { 50 | return CONDITIONAL; 51 | } else { 52 | throw new RuntimeException(getString( 53 | "RuntimeError.13", type)); //$NON-NLS-1$ 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/PluginConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class PluginConfiguration extends TypedPropertyHolder { 32 | public PluginConfiguration() { 33 | } 34 | 35 | public XmlElement toXmlElement() { 36 | XmlElement answer = new XmlElement("plugin"); //$NON-NLS-1$ 37 | if (getConfigurationType() != null) { 38 | answer.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$ 39 | } 40 | 41 | addPropertyXmlElements(answer); 42 | 43 | return answer; 44 | } 45 | 46 | public void validate(List errors, String contextId) { 47 | if (!stringHasValue(getConfigurationType())) { 48 | errors.add(getString("ValidationError.17", //$NON-NLS-1$ 49 | contextId)); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/PropertyHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.config; 17 | 18 | import java.util.Enumeration; 19 | import java.util.Properties; 20 | 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.XmlElement; 23 | 24 | /** 25 | * @author Jeff Butler 26 | */ 27 | public abstract class PropertyHolder { 28 | private Properties properties; 29 | 30 | /** 31 | * 32 | */ 33 | public PropertyHolder() { 34 | super(); 35 | properties = new Properties(); 36 | } 37 | 38 | public void addProperty(String name, String value) { 39 | properties.setProperty(name, value); 40 | } 41 | 42 | public String getProperty(String name) { 43 | return properties.getProperty(name); 44 | } 45 | 46 | public Properties getProperties() { 47 | return properties; 48 | } 49 | 50 | protected void addPropertyXmlElements(XmlElement xmlElement) { 51 | Enumeration enumeration = properties.propertyNames(); 52 | while (enumeration.hasMoreElements()) { 53 | String propertyName = (String) enumeration.nextElement(); 54 | 55 | XmlElement propertyElement = new XmlElement("property"); //$NON-NLS-1$ 56 | propertyElement.addAttribute(new Attribute("name", propertyName)); //$NON-NLS-1$ 57 | propertyElement.addAttribute(new Attribute( 58 | "value", properties.getProperty(propertyName))); //$NON-NLS-1$ 59 | xmlElement.addElement(propertyElement); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/SqlMapGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class SqlMapGeneratorConfiguration extends PropertyHolder { 30 | private String targetPackage; 31 | 32 | private String targetProject; 33 | 34 | /** 35 | * 36 | */ 37 | public SqlMapGeneratorConfiguration() { 38 | super(); 39 | } 40 | 41 | public String getTargetProject() { 42 | return targetProject; 43 | } 44 | 45 | public void setTargetProject(String targetProject) { 46 | this.targetProject = targetProject; 47 | } 48 | 49 | public String getTargetPackage() { 50 | return targetPackage; 51 | } 52 | 53 | public void setTargetPackage(String targetPackage) { 54 | this.targetPackage = targetPackage; 55 | } 56 | 57 | public XmlElement toXmlElement() { 58 | XmlElement answer = new XmlElement("sqlMapGenerator"); //$NON-NLS-1$ 59 | 60 | if (targetPackage != null) { 61 | answer.addAttribute(new Attribute("targetPackage", targetPackage)); //$NON-NLS-1$ 62 | } 63 | 64 | if (targetProject != null) { 65 | answer.addAttribute(new Attribute("targetProject", targetProject)); //$NON-NLS-1$ 66 | } 67 | 68 | addPropertyXmlElements(answer); 69 | 70 | return answer; 71 | } 72 | 73 | public void validate(List errors, String contextId) { 74 | if (!stringHasValue(targetProject)) { 75 | errors.add(getString("ValidationError.1", contextId)); //$NON-NLS-1$ 76 | } 77 | 78 | if (!stringHasValue(targetPackage)) { 79 | errors.add(getString("ValidationError.12", //$NON-NLS-1$ 80 | "SQLMapGenerator", contextId)); //$NON-NLS-1$ 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/TypedPropertyHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005, 2006 The Apache Software Foundation 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.config; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public abstract class TypedPropertyHolder extends PropertyHolder { 22 | 23 | private String configurationType; 24 | 25 | /** 26 | * 27 | */ 28 | public TypedPropertyHolder() { 29 | super(); 30 | } 31 | 32 | public String getConfigurationType() { 33 | return configurationType; 34 | } 35 | 36 | /** 37 | * Sets the value of the type specified in the configuration. If the special 38 | * value DEFAULT is specified, then the value will be ignored. 39 | * 40 | * @param configurationType 41 | * the type specified in the configuration 42 | */ 43 | public void setConfigurationType(String configurationType) { 44 | if (!"DEFAULT".equalsIgnoreCase(configurationType)) { //$NON-NLS-1$ 45 | this.configurationType = configurationType; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/xml/ParserEntityResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.config.xml; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | 21 | import org.mybatis.generator.codegen.XmlConstants; 22 | import org.xml.sax.EntityResolver; 23 | import org.xml.sax.InputSource; 24 | import org.xml.sax.SAXException; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class ParserEntityResolver implements EntityResolver { 30 | 31 | /** 32 | * 33 | */ 34 | public ParserEntityResolver() { 35 | super(); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, 42 | * java.lang.String) 43 | */ 44 | public InputSource resolveEntity(String publicId, String systemId) 45 | throws SAXException, IOException { 46 | if (XmlConstants.IBATOR_CONFIG_PUBLIC_ID.equalsIgnoreCase(publicId)) { 47 | InputStream is = getClass().getClassLoader().getResourceAsStream( 48 | "org/mybatis/generator/config/xml/ibator-config_1_0.dtd"); //$NON-NLS-1$ 49 | InputSource ins = new InputSource(is); 50 | 51 | return ins; 52 | } else if (XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID 53 | .equalsIgnoreCase(publicId)) { 54 | InputStream is = getClass() 55 | .getClassLoader() 56 | .getResourceAsStream( 57 | "org/mybatis/generator/config/xml/mybatis-generator-config_1_0.dtd"); //$NON-NLS-1$ 58 | InputSource ins = new InputSource(is); 59 | 60 | return ins; 61 | } else { 62 | return null; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/config/xml/ParserErrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.config.xml; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | import java.util.List; 21 | 22 | import org.xml.sax.ErrorHandler; 23 | import org.xml.sax.SAXException; 24 | import org.xml.sax.SAXParseException; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class ParserErrorHandler implements ErrorHandler { 30 | private List warnings; 31 | 32 | private List errors; 33 | 34 | /** 35 | * 36 | */ 37 | public ParserErrorHandler(List warnings, List errors) { 38 | super(); 39 | this.warnings = warnings; 40 | this.errors = errors; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * 46 | * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) 47 | */ 48 | public void warning(SAXParseException exception) throws SAXException { 49 | warnings.add(getString("Warning.7", //$NON-NLS-1$ 50 | Integer.toString(exception.getLineNumber()), exception 51 | .getMessage())); 52 | } 53 | 54 | /* 55 | * (non-Javadoc) 56 | * 57 | * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) 58 | */ 59 | public void error(SAXParseException exception) throws SAXException { 60 | errors.add(getString("RuntimeError.4", //$NON-NLS-1$ 61 | Integer.toString(exception.getLineNumber()), exception 62 | .getMessage())); 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) 69 | */ 70 | public void fatalError(SAXParseException exception) throws SAXException { 71 | errors.add(getString("RuntimeError.4", //$NON-NLS-1$ 72 | Integer.toString(exception.getLineNumber()), exception 73 | .getMessage())); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/exception/InvalidConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.exception; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class InvalidConfigurationException extends Exception { 24 | static final long serialVersionUID = 4902307610148543411L; 25 | 26 | private List errors; 27 | 28 | /** 29 | * 30 | */ 31 | public InvalidConfigurationException(List errors) { 32 | super(); 33 | this.errors = errors; 34 | } 35 | 36 | public List getErrors() { 37 | return errors; 38 | } 39 | 40 | @Override 41 | public String getMessage() { 42 | if (errors != null && errors.size() > 0) { 43 | return errors.get(0); 44 | } 45 | 46 | return super.getMessage(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/exception/ShellException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.exception; 17 | 18 | /** 19 | * This class is used by the ShellCallback methods to denote unrecoverable 20 | * errors. 21 | * 22 | * @author Jeff Butler 23 | */ 24 | public class ShellException extends Exception { 25 | static final long serialVersionUID = -2026841561754434544L; 26 | 27 | /** 28 | * 29 | */ 30 | public ShellException() { 31 | super(); 32 | } 33 | 34 | /** 35 | * @param arg0 36 | */ 37 | public ShellException(String arg0) { 38 | super(arg0); 39 | } 40 | 41 | /** 42 | * @param arg0 43 | * @param arg1 44 | */ 45 | public ShellException(String arg0, Throwable arg1) { 46 | super(arg0, arg1); 47 | } 48 | 49 | /** 50 | * @param arg0 51 | */ 52 | public ShellException(Throwable arg0) { 53 | super(arg0); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/exception/XMLParserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.exception; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * @author Jeff Butler 23 | */ 24 | public class XMLParserException extends Exception { 25 | 26 | private static final long serialVersionUID = 5172525430401340573L; 27 | 28 | private List errors; 29 | 30 | /** 31 | * 32 | */ 33 | public XMLParserException(List errors) { 34 | super(); 35 | this.errors = errors; 36 | } 37 | 38 | public XMLParserException(String error) { 39 | super(error); 40 | this.errors = new ArrayList(); 41 | errors.add(error); 42 | } 43 | 44 | public List getErrors() { 45 | return errors; 46 | } 47 | 48 | @Override 49 | public String getMessage() { 50 | if (errors != null && errors.size() > 0) { 51 | return errors.get(0); 52 | } 53 | 54 | return super.getMessage(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/DefaultShellCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.internal; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | import java.io.File; 21 | import java.util.StringTokenizer; 22 | 23 | import org.mybatis.generator.api.ShellCallback; 24 | import org.mybatis.generator.exception.ShellException; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class DefaultShellCallback implements ShellCallback { 30 | private boolean overwrite; 31 | 32 | /** 33 | * 34 | */ 35 | public DefaultShellCallback(boolean overwrite) { 36 | super(); 37 | this.overwrite = overwrite; 38 | } 39 | 40 | public File getDirectory(String targetProject, String targetPackage) 41 | throws ShellException { 42 | // targetProject is interpreted as a directory that must exist 43 | // 44 | // targetPackage is interpreted as a sub directory, but in package 45 | // format (with dots instead of slashes). The sub directory will be 46 | // created 47 | // if it does not already exist 48 | 49 | File project = new File(targetProject); 50 | if (!project.isDirectory()) { 51 | throw new ShellException(getString("Warning.9", //$NON-NLS-1$ 52 | targetProject)); 53 | } 54 | 55 | StringBuilder sb = new StringBuilder(); 56 | StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ 57 | while (st.hasMoreTokens()) { 58 | sb.append(st.nextToken()); 59 | sb.append(File.separatorChar); 60 | } 61 | 62 | File directory = new File(project, sb.toString()); 63 | if (!directory.isDirectory()) { 64 | boolean rc = directory.mkdirs(); 65 | if (!rc) { 66 | throw new ShellException(getString("Warning.10", //$NON-NLS-1$ 67 | directory.getAbsolutePath())); 68 | } 69 | } 70 | 71 | return directory; 72 | } 73 | 74 | public void refreshProject(String project) { 75 | // nothing to do in the default shell callback 76 | } 77 | 78 | public boolean isMergeSupported() { 79 | return false; 80 | } 81 | 82 | public boolean isOverwriteEnabled() { 83 | return overwrite; 84 | } 85 | 86 | public String mergeJavaFile(String newFileSource, 87 | String existingFileFullPath, String[] javadocTags, String fileEncoding) 88 | throws ShellException { 89 | throw new UnsupportedOperationException(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/NullProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.internal; 17 | 18 | import org.mybatis.generator.api.ProgressCallback; 19 | 20 | /** 21 | * This class implements a progress callback that does nothing. It is used when 22 | * the client passes in a null for the ProgressCallback. 23 | * 24 | * @author Jeff Butler 25 | */ 26 | public class NullProgressCallback implements ProgressCallback { 27 | 28 | /** 29 | * 30 | */ 31 | public NullProgressCallback() { 32 | super(); 33 | } 34 | 35 | public void generationStarted(int totalTasks) { 36 | } 37 | 38 | public void introspectionStarted(int totalTasks) { 39 | } 40 | 41 | public void saveStarted(int totalTasks) { 42 | } 43 | 44 | public void startTask(String taskName) { 45 | } 46 | 47 | public void checkCancel() throws InterruptedException { 48 | } 49 | 50 | public void done() { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/db/ActualTableName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.internal.db; 18 | 19 | import static org.mybatis.generator.internal.util.StringUtility.composeFullyQualifiedTableName; 20 | 21 | /** 22 | * This class holds the actual catalog, schema, and table name returned from the 23 | * database introspection. 24 | * 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class ActualTableName { 29 | 30 | private String tableName; 31 | private String catalog; 32 | private String schema; 33 | private String fullName; 34 | 35 | public ActualTableName(String catalog, String schema, String tableName) { 36 | this.catalog = catalog; 37 | this.schema = schema; 38 | this.tableName = tableName; 39 | fullName = composeFullyQualifiedTableName(catalog, 40 | schema, tableName, '.'); 41 | } 42 | 43 | public String getCatalog() { 44 | return catalog; 45 | } 46 | 47 | public String getSchema() { 48 | return schema; 49 | } 50 | 51 | public String getTableName() { 52 | return tableName; 53 | } 54 | 55 | @Override 56 | public boolean equals(Object obj) { 57 | if (obj == null || !(obj instanceof ActualTableName)) { 58 | return false; 59 | } 60 | 61 | return obj.toString().equals(this.toString()); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | return fullName.hashCode(); 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return fullName; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/db/ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.internal.db; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.sql.Connection; 22 | import java.sql.Driver; 23 | import java.sql.SQLException; 24 | import java.util.Properties; 25 | 26 | import org.mybatis.generator.config.JDBCConnectionConfiguration; 27 | import org.mybatis.generator.internal.ObjectFactory; 28 | 29 | /** 30 | * This class assumes that classes are cached elsewhere for performance reasons, 31 | * but also to make sure that any native libraries are only loaded one time 32 | * (avoids the dreaded UnsatisfiedLinkError library loaded in another 33 | * classloader) 34 | * 35 | * @author Jeff Butler 36 | */ 37 | public class ConnectionFactory { 38 | 39 | private static ConnectionFactory instance = new ConnectionFactory(); 40 | 41 | public static ConnectionFactory getInstance() { 42 | return instance; 43 | } 44 | 45 | /** 46 | * 47 | */ 48 | private ConnectionFactory() { 49 | super(); 50 | } 51 | 52 | public Connection getConnection(JDBCConnectionConfiguration config) 53 | throws SQLException { 54 | Driver driver = getDriver(config); 55 | 56 | Properties props = new Properties(); 57 | 58 | if (stringHasValue(config.getUserId())) { 59 | props.setProperty("user", config.getUserId()); //$NON-NLS-1$ 60 | } 61 | 62 | if (stringHasValue(config.getPassword())) { 63 | props.setProperty("password", config.getPassword()); //$NON-NLS-1$ 64 | } 65 | 66 | props.putAll(config.getProperties()); 67 | 68 | Connection conn = driver.connect(config.getConnectionURL(), props); 69 | 70 | if (conn == null) { 71 | throw new SQLException(getString("RuntimeError.7")); //$NON-NLS-1$ 72 | } 73 | 74 | return conn; 75 | } 76 | 77 | private Driver getDriver(JDBCConnectionConfiguration connectionInformation) { 78 | String driverClass = connectionInformation.getDriverClass(); 79 | Driver driver; 80 | 81 | try { 82 | Class clazz = ObjectFactory.externalClassForName(driverClass); 83 | driver = (Driver) clazz.newInstance(); 84 | } catch (Exception e) { 85 | throw new RuntimeException(getString("RuntimeError.8"), e); //$NON-NLS-1$ 86 | } 87 | 88 | return driver; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/db/DatabaseDialects.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.internal.db; 17 | 18 | /** 19 | * Typesafe enum of known database dialects 20 | * 21 | * @author Jeff Butler 22 | */ 23 | public enum DatabaseDialects { 24 | 25 | DB2("VALUES IDENTITY_VAL_LOCAL()"), //$NON-NLS-1$ 26 | MYSQL("SELECT LAST_INSERT_ID()"), //$NON-NLS-1$ 27 | SQLSERVER("SELECT SCOPE_IDENTITY()"), //$NON-NLS-1$ 28 | CLOUDSCAPE("VALUES IDENTITY_VAL_LOCAL()"), //$NON-NLS-1$ 29 | DERBY("VALUES IDENTITY_VAL_LOCAL()"), //$NON-NLS-1$ 30 | HSQLDB("CALL IDENTITY()"), //$NON-NLS-1$ 31 | SYBASE("SELECT @@IDENTITY"), //$NON-NLS-1$ 32 | DB2_MF("SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"), //$NON-NLS-1$ 33 | INFORMIX("select dbinfo('sqlca.sqlerrd1') from systables where tabid=1"); //$NON-NLS-1$ 34 | 35 | private String identityRetrievalStatement; 36 | 37 | /** 38 | * 39 | */ 40 | private DatabaseDialects(String identityRetrievalStatement) { 41 | this.identityRetrievalStatement = identityRetrievalStatement; 42 | } 43 | 44 | public String getIdentityRetrievalStatement() { 45 | return identityRetrievalStatement; 46 | } 47 | 48 | /** 49 | * 50 | * @param database 51 | * @return the database dialect for the selected database. May return null 52 | * if there is no known dialect for the selected db 53 | */ 54 | public static DatabaseDialects getDatabaseDialect(String database) { 55 | DatabaseDialects returnValue = null; 56 | 57 | if ("DB2".equalsIgnoreCase(database)) { //$NON-NLS-1$ 58 | returnValue = DB2; 59 | } else if ("MySQL".equalsIgnoreCase(database)) { //$NON-NLS-1$ 60 | returnValue = MYSQL; 61 | } else if ("SqlServer".equalsIgnoreCase(database)) { //$NON-NLS-1$ 62 | returnValue = SQLSERVER; 63 | } else if ("Cloudscape".equalsIgnoreCase(database)) { //$NON-NLS-1$ 64 | returnValue = CLOUDSCAPE; 65 | } else if ("Derby".equalsIgnoreCase(database)) { //$NON-NLS-1$ 66 | returnValue = DERBY; 67 | } else if ("HSQLDB".equalsIgnoreCase(database)) { //$NON-NLS-1$ 68 | returnValue = HSQLDB; 69 | } else if ("SYBASE".equalsIgnoreCase(database)) { //$NON-NLS-1$ 70 | returnValue = SYBASE; 71 | } else if ("DB2_MF".equalsIgnoreCase(database)) { //$NON-NLS-1$ 72 | returnValue = DB2_MF; 73 | } else if ("Informix".equalsIgnoreCase(database)) { //$NON-NLS-1$ 74 | returnValue = INFORMIX; 75 | } 76 | 77 | return returnValue; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/rules/ConditionalModelRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.internal.rules; 18 | 19 | import org.mybatis.generator.api.IntrospectedTable; 20 | 21 | /** 22 | * This class encapsulates all the code generation rules for a table using the 23 | * conditional model. In this model we do not generate primary key or record 24 | * with BLOBs classes if the class would only hold one field. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class ConditionalModelRules extends BaseRules { 30 | 31 | /** 32 | * 33 | */ 34 | public ConditionalModelRules(IntrospectedTable introspectedTable) { 35 | super(introspectedTable); 36 | } 37 | 38 | /** 39 | * We generate a primary key if there is more than one primary key field. 40 | * 41 | * @return true if the primary key should be generated 42 | */ 43 | public boolean generatePrimaryKeyClass() { 44 | return introspectedTable.getPrimaryKeyColumns().size() > 1; 45 | } 46 | 47 | /** 48 | * Generate a base record if there are any base columns, or if there is only 49 | * one primary key coulmn (in which case we will not generate a primary key 50 | * class), or if there is only one BLOB column (in which case we will not 51 | * generate a record with BLOBs class). 52 | * 53 | * @return true if the class should be generated 54 | */ 55 | public boolean generateBaseRecordClass() { 56 | return introspectedTable.getBaseColumns().size() > 0 57 | || introspectedTable.getPrimaryKeyColumns().size() == 1 58 | || (introspectedTable.getBLOBColumns().size() > 0 && !generateRecordWithBLOBsClass()); 59 | 60 | } 61 | 62 | /** 63 | * We generate a record with BLOBs class if there is more than one BLOB 64 | * column. Do not generate a BLOBs class if any other super class would only 65 | * contain one field 66 | * 67 | * @return true if the record with BLOBs class should be generated 68 | */ 69 | public boolean generateRecordWithBLOBsClass() { 70 | int otherColumnCount = introspectedTable.getPrimaryKeyColumns().size() 71 | + introspectedTable.getBaseColumns().size(); 72 | 73 | return otherColumnCount > 1 74 | && introspectedTable.getBLOBColumns().size() > 1; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/rules/FlatModelRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.internal.rules; 18 | 19 | import org.mybatis.generator.api.IntrospectedTable; 20 | 21 | /** 22 | * This class encapsulates all the code generation rules for a table using the 23 | * flat model. 24 | * 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class FlatModelRules extends BaseRules { 29 | 30 | /** 31 | * 32 | */ 33 | public FlatModelRules(IntrospectedTable introspectedTable) { 34 | super(introspectedTable); 35 | } 36 | 37 | /** 38 | * We never generate a primary key in the flat model. 39 | * 40 | * @return true if the primary key should be generated 41 | */ 42 | public boolean generatePrimaryKeyClass() { 43 | return false; 44 | } 45 | 46 | /** 47 | * We always generate a base record in the flat model. 48 | * 49 | * @return true if the class should be generated 50 | */ 51 | public boolean generateBaseRecordClass() { 52 | return true; 53 | } 54 | 55 | /** 56 | * We never generate a record with BLOBs class in the flat model. 57 | * 58 | * @return true if the record with BLOBs class should be generated 59 | */ 60 | public boolean generateRecordWithBLOBsClass() { 61 | return false; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/rules/HierarchicalModelRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.internal.rules; 18 | 19 | import org.mybatis.generator.api.IntrospectedTable; 20 | 21 | /** 22 | * This class encapsulates all the code generation rules for a table using the 23 | * hierarchical model. 24 | * 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class HierarchicalModelRules extends BaseRules { 29 | 30 | /** 31 | * 32 | */ 33 | public HierarchicalModelRules(IntrospectedTable introspectedTable) { 34 | super(introspectedTable); 35 | } 36 | 37 | /** 38 | * Implements the rule for determining whether to generate a primary key 39 | * class. If the physical table has a primary key, then we generate the 40 | * class. 41 | * 42 | * @return true if the primary key should be generated 43 | */ 44 | public boolean generatePrimaryKeyClass() { 45 | return introspectedTable.hasPrimaryKeyColumns(); 46 | } 47 | 48 | /** 49 | * Implements the rule for generating a base record. If the table has fields 50 | * that are not in the primary key, and non-BLOB fields, then generate the 51 | * class. 52 | * 53 | * @return true if the class should be generated 54 | */ 55 | public boolean generateBaseRecordClass() { 56 | return introspectedTable.hasBaseColumns(); 57 | } 58 | 59 | /** 60 | * Implements the rule for generating a record with BLOBs. A record with 61 | * BLOBs is generated if the table contains any BLOB fields. 62 | * 63 | * @return true if the record with BLOBs class should be generated 64 | */ 65 | public boolean generateRecordWithBLOBsClass() { 66 | return introspectedTable.hasBLOBColumns(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/types/Jdbc4Types.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.internal.types; 2 | 3 | public class Jdbc4Types { 4 | // these are added manually until we move to JDK 6 5 | // TODO - remove after JDK 6 and use the java.sql.Types constants instead 6 | public static final int LONGNVARCHAR = -16; 7 | public static final int NVARCHAR = -9; 8 | public static final int NCHAR = -15; 9 | public static final int NCLOB = 2011; 10 | } 11 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/util/ClassloaderUtility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.internal.util; 18 | 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.io.File; 22 | import java.net.MalformedURLException; 23 | import java.net.URL; 24 | import java.net.URLClassLoader; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * This class holds methods useful for constructing custom classloaders. 30 | * 31 | * @author Jeff Butler 32 | * 33 | */ 34 | public class ClassloaderUtility { 35 | 36 | /** 37 | * Utility Class - No Instances 38 | */ 39 | private ClassloaderUtility() { 40 | } 41 | 42 | public static ClassLoader getCustomClassloader(List entries) { 43 | List urls = new ArrayList(); 44 | File file; 45 | 46 | if (entries != null) { 47 | for (String classPathEntry : entries) { 48 | file = new File(classPathEntry); 49 | if (!file.exists()) { 50 | throw new RuntimeException(getString( 51 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 52 | } 53 | 54 | try { 55 | urls.add(file.toURI().toURL()); 56 | } catch (MalformedURLException e) { 57 | // this shouldn't happen, but just in case... 58 | throw new RuntimeException(getString( 59 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 60 | } 61 | } 62 | } 63 | 64 | ClassLoader parent = Thread.currentThread().getContextClassLoader(); 65 | 66 | URLClassLoader ucl = new URLClassLoader(urls.toArray(new URL[urls 67 | .size()]), parent); 68 | 69 | return ucl; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/util/EqualsUtil.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.internal.util; 2 | 3 | /** 4 | * This class is from javapractices.com: 5 | * 6 | * http://www.javapractices.com/Topic17.cjp 7 | * 8 | * Collected methods which allow easy implementation of equals. 9 | * 10 | * Example use case in a class called Car: 11 | * 12 | *
13 |  * public boolean equals(Object that) {
14 |  *     if (this == that)
15 |  *         return true;
16 |  *     if (!(that instanceof Car))
17 |  *         return false;
18 |  *     Car thatCar = (Car) that;
19 |  *     return EqualsUtil.areEqual(this.fName, that.fName)
20 |  *             && EqualsUtil.areEqual(this.fNumDoors, that.fNumDoors)
21 |  *             && EqualsUtil.areEqual(this.fGasMileage, that.fGasMileage)
22 |  *             && EqualsUtil.areEqual(this.fColor, that.fColor)
23 |  *             && Arrays.equals(this.fMaintenanceChecks, that.fMaintenanceChecks); //array!
24 |  * }
25 |  * 
26 | * 27 | * Arrays are not handled by this class. This is because the 28 | * Arrays.equals methods should be used for array fields. 29 | */ 30 | public final class EqualsUtil { 31 | 32 | static public boolean areEqual(boolean aThis, boolean aThat) { 33 | return aThis == aThat; 34 | } 35 | 36 | static public boolean areEqual(char aThis, char aThat) { 37 | return aThis == aThat; 38 | } 39 | 40 | static public boolean areEqual(long aThis, long aThat) { 41 | /* 42 | * Implementation Note Note that byte, short, and int are handled by 43 | * this method, through implicit conversion. 44 | */ 45 | return aThis == aThat; 46 | } 47 | 48 | static public boolean areEqual(float aThis, float aThat) { 49 | return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat); 50 | } 51 | 52 | static public boolean areEqual(double aThis, double aThat) { 53 | return Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat); 54 | } 55 | 56 | /** 57 | * Possibly-null object field. 58 | * 59 | * Includes type-safe enumerations and collections, but does not include 60 | * arrays. See class comment. 61 | */ 62 | static public boolean areEqual(Object aThis, Object aThat) { 63 | return aThis == null ? aThat == null : aThis.equals(aThat); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/util/StringUtility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 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.internal.util; 17 | 18 | import java.util.StringTokenizer; 19 | 20 | /** 21 | * 22 | * @author Jeff Butler 23 | */ 24 | public class StringUtility { 25 | 26 | /** 27 | * Utility class. No instances allowed 28 | */ 29 | private StringUtility() { 30 | super(); 31 | } 32 | 33 | public static boolean stringHasValue(String s) { 34 | return s != null && s.length() > 0; 35 | } 36 | 37 | public static String composeFullyQualifiedTableName(String catalog, 38 | String schema, String tableName, char separator) { 39 | StringBuilder sb = new StringBuilder(); 40 | 41 | if (stringHasValue(catalog)) { 42 | sb.append(catalog); 43 | sb.append(separator); 44 | } 45 | 46 | if (stringHasValue(schema)) { 47 | sb.append(schema); 48 | sb.append(separator); 49 | } else { 50 | if (sb.length() > 0) { 51 | sb.append(separator); 52 | } 53 | } 54 | 55 | sb.append(tableName); 56 | 57 | return sb.toString(); 58 | } 59 | 60 | public static boolean stringContainsSpace(String s) { 61 | return s != null && s.indexOf(' ') != -1; 62 | } 63 | 64 | public static String escapeStringForJava(String s) { 65 | StringTokenizer st = new StringTokenizer(s, "\"", true); //$NON-NLS-1$ 66 | StringBuilder sb = new StringBuilder(); 67 | while (st.hasMoreTokens()) { 68 | String token = st.nextToken(); 69 | if ("\"".equals(token)) { //$NON-NLS-1$ 70 | sb.append("\\\""); //$NON-NLS-1$ 71 | } else { 72 | sb.append(token); 73 | } 74 | } 75 | 76 | return sb.toString(); 77 | } 78 | 79 | public static String escapeStringForXml(String s) { 80 | StringTokenizer st = new StringTokenizer(s, "\"", true); //$NON-NLS-1$ 81 | StringBuilder sb = new StringBuilder(); 82 | while (st.hasMoreTokens()) { 83 | String token = st.nextToken(); 84 | if ("\"".equals(token)) { //$NON-NLS-1$ 85 | sb.append("""); //$NON-NLS-1$ 86 | } else { 87 | sb.append(token); 88 | } 89 | } 90 | 91 | return sb.toString(); 92 | } 93 | 94 | public static boolean isTrue(String s) { 95 | return "true".equalsIgnoreCase(s); //$NON-NLS-1$ 96 | } 97 | 98 | public static boolean stringContainsSQLWildcard(String s) { 99 | if (s == null) { 100 | return false; 101 | } 102 | 103 | return s.indexOf('%') != -1 || s.indexOf('_') != -1; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/internal/util/messages/Messages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 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.internal.util.messages; 17 | 18 | import java.text.MessageFormat; 19 | import java.util.MissingResourceException; 20 | import java.util.ResourceBundle; 21 | 22 | /** 23 | * @author Jeff Butler 24 | */ 25 | public class Messages { 26 | private static final String BUNDLE_NAME = "org.mybatis.generator.internal.util.messages.messages"; //$NON-NLS-1$ 27 | 28 | private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle 29 | .getBundle(BUNDLE_NAME); 30 | 31 | private Messages() { 32 | } 33 | 34 | public static String getString(String key) { 35 | try { 36 | return RESOURCE_BUNDLE.getString(key); 37 | } catch (MissingResourceException e) { 38 | return '!' + key + '!'; 39 | } 40 | } 41 | 42 | public static String getString(String key, String parm1) { 43 | try { 44 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), 45 | new Object[] { parm1 }); 46 | } catch (MissingResourceException e) { 47 | return '!' + key + '!'; 48 | } 49 | } 50 | 51 | public static String getString(String key, String parm1, String parm2) { 52 | try { 53 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), 54 | new Object[] { parm1, parm2 }); 55 | } catch (MissingResourceException e) { 56 | return '!' + key + '!'; 57 | } 58 | } 59 | 60 | public static String getString(String key, String parm1, String parm2, 61 | String parm3) { 62 | try { 63 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), 64 | new Object[] { parm1, parm2, parm3 }); 65 | } catch (MissingResourceException e) { 66 | return '!' + key + '!'; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/logging/AbstractLogFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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 | 17 | package org.mybatis.generator.logging; 18 | 19 | /** 20 | * Defines the interface for creating Log implementations. 21 | * 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public interface AbstractLogFactory { 26 | Log getLog(Class aClass); 27 | } 28 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/logging/JdkLoggingImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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.logging; 17 | 18 | import java.util.logging.Level; 19 | import java.util.logging.LogRecord; 20 | import java.util.logging.Logger; 21 | 22 | /** 23 | * 24 | * @author Clinton Begin 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class JdkLoggingImpl implements Log { 29 | 30 | private Logger log; 31 | 32 | public JdkLoggingImpl(Class clazz) { 33 | log = Logger.getLogger(clazz.getName()); 34 | } 35 | 36 | public boolean isDebugEnabled() { 37 | return log.isLoggable(Level.FINE); 38 | } 39 | 40 | public void error(String s, Throwable e) { 41 | LogRecord lr = new LogRecord(Level.SEVERE, s); 42 | lr.setSourceClassName(log.getName()); 43 | lr.setThrown(e); 44 | 45 | log.log(lr); 46 | } 47 | 48 | public void error(String s) { 49 | LogRecord lr = new LogRecord(Level.SEVERE, s); 50 | lr.setSourceClassName(log.getName()); 51 | 52 | log.log(lr); 53 | } 54 | 55 | public void debug(String s) { 56 | LogRecord lr = new LogRecord(Level.FINE, s); 57 | lr.setSourceClassName(log.getName()); 58 | 59 | log.log(lr); 60 | } 61 | 62 | public void warn(String s) { 63 | LogRecord lr = new LogRecord(Level.WARNING, s); 64 | lr.setSourceClassName(log.getName()); 65 | 66 | log.log(lr); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/logging/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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.logging; 17 | 18 | /** 19 | * 20 | * @author Clinton Begin 21 | */ 22 | public interface Log { 23 | 24 | boolean isDebugEnabled(); 25 | 26 | void error(String s, Throwable e); 27 | 28 | void error(String s); 29 | 30 | public void debug(String s); 31 | 32 | public void warn(String s); 33 | } 34 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/logging/Log4jImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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.logging; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | /** 21 | * 22 | * @author Clinton Begin 23 | * 24 | */ 25 | public class Log4jImpl implements Log { 26 | 27 | private Logger log; 28 | 29 | public Log4jImpl(Class clazz) { 30 | log = Logger.getLogger(clazz); 31 | } 32 | 33 | public boolean isDebugEnabled() { 34 | return log.isDebugEnabled(); 35 | } 36 | 37 | public void error(String s, Throwable e) { 38 | log.error(s, e); 39 | } 40 | 41 | public void error(String s) { 42 | log.error(s); 43 | } 44 | 45 | public void debug(String s) { 46 | log.debug(s); 47 | } 48 | 49 | public void warn(String s) { 50 | log.warn(s); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/logging/LogFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 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.logging; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | import org.mybatis.generator.internal.ObjectFactory; 21 | 22 | /** 23 | * Factory for creating loggers. Uses runtime introspection to determine the 24 | * AbstractLogFactory implementation. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class LogFactory { 30 | private static AbstractLogFactory logFactory; 31 | 32 | static { 33 | try { 34 | ObjectFactory.internalClassForName("org.apache.log4j.Logger"); //$NON-NLS-1$ 35 | logFactory = new Log4jLoggingLogFactory(); 36 | } catch (Exception e) { 37 | logFactory = new JdkLoggingLogFactory(); 38 | } 39 | } 40 | 41 | public static Log getLog(Class clazz) { 42 | try { 43 | return logFactory.getLog(clazz); 44 | } catch (Throwable t) { 45 | throw new RuntimeException(getString("RuntimeError.21", //$NON-NLS-1$ 46 | clazz.getName(), t.getMessage()), t); 47 | } 48 | } 49 | 50 | /** 51 | * This method will switch the logging implementation to Java native 52 | * logging. This is useful in situations where you want to use Java native 53 | * logging to log activity but Log4J is on the classpath. Note that 54 | * this method is only effective for log classes obtained after calling this 55 | * method. If you intend to use this method you should call it before 56 | * calling any other method. 57 | */ 58 | public static synchronized void forceJavaLogging() { 59 | logFactory = new JdkLoggingLogFactory(); 60 | } 61 | 62 | private static class JdkLoggingLogFactory implements AbstractLogFactory { 63 | public Log getLog(Class clazz) { 64 | return new JdkLoggingImpl(clazz); 65 | } 66 | } 67 | 68 | private static class Log4jLoggingLogFactory implements AbstractLogFactory { 69 | public Log getLog(Class clazz) { 70 | return new Log4jImpl(clazz); 71 | } 72 | } 73 | 74 | public static void setLogFactory(AbstractLogFactory logFactory) { 75 | LogFactory.logFactory = logFactory; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/plugins/CachePlugin.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.plugins; 2 | 3 | import java.util.List; 4 | 5 | import org.mybatis.generator.api.IntrospectedTable; 6 | import org.mybatis.generator.api.PluginAdapter; 7 | import org.mybatis.generator.api.dom.xml.Attribute; 8 | import org.mybatis.generator.api.dom.xml.Document; 9 | import org.mybatis.generator.api.dom.xml.XmlElement; 10 | import org.mybatis.generator.internal.util.StringUtility; 11 | 12 | /** 13 | * This plugin adds a cache element to generated sqlMaps. This plugin 14 | * is for MyBatis3 targeted runtimes only. The plugin accepts the 15 | * following properties (all are optional): 16 | * 17 | * cache_eviction 18 | * cache_flushInterval 19 | * cache_size 20 | * cache_readOnly 21 | * cache_type 22 | * 23 | * All properties correspond to properties of the MyBatis cache element and 24 | * are passed "as is" to the corresponding properties of the generated cache 25 | * element. All properties can be specified at the table level, or on the 26 | * plugin element. The property on the table element will override any 27 | * property on the plugin element. 28 | * 29 | * @author Jason Bennett 30 | * @author Jeff Butler 31 | */ 32 | public class CachePlugin extends PluginAdapter { 33 | public enum CacheProperty { 34 | EVICTION("cache_eviction", "eviction"), //$NON-NLS-1$ //$NON-NLS-2$ 35 | FLUSH_INTERVAL("cache_flushInterval", "flushInterval"), //$NON-NLS-1$ //$NON-NLS-2$ 36 | READ_ONLY("cache_readOnly", "readOnly"), //$NON-NLS-1$ //$NON-NLS-2$ 37 | SIZE("cache_size", "size"), //$NON-NLS-1$ //$NON-NLS-2$ 38 | TYPE("cache_type", "type"); //$NON-NLS-1$ //$NON-NLS-2$ 39 | 40 | private String propertyName; 41 | private String attributeName; 42 | 43 | CacheProperty(String propertyName, String attributeName) { 44 | this.propertyName = propertyName; 45 | this.attributeName = attributeName; 46 | } 47 | 48 | public String getPropertyName() { 49 | return propertyName; 50 | } 51 | 52 | public String getAttributeName() { 53 | return attributeName; 54 | } 55 | } 56 | 57 | public CachePlugin() { 58 | super(); 59 | } 60 | 61 | public boolean validate(List warnings) { 62 | return true; 63 | } 64 | 65 | @Override 66 | public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) { 67 | 68 | XmlElement element = new XmlElement("cache"); //$NON-NLS-1$ 69 | context.getCommentGenerator().addComment(element); 70 | 71 | for (CacheProperty cacheProperty : CacheProperty.values()) { 72 | addAttributeIfExists(element, introspectedTable, cacheProperty); 73 | } 74 | 75 | document.getRootElement().addElement(element); 76 | 77 | return true; 78 | } 79 | 80 | private void addAttributeIfExists(XmlElement element, IntrospectedTable introspectedTable, 81 | CacheProperty cacheProperty) { 82 | String property = introspectedTable.getTableConfigurationProperty(cacheProperty.getPropertyName()); 83 | if (property == null) { 84 | property = properties.getProperty(cacheProperty.getPropertyName()); 85 | } 86 | 87 | if (StringUtility.stringHasValue(property)) { 88 | element.addAttribute(new Attribute(cacheProperty.getAttributeName(), property)); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/org/mybatis/generator/plugins/VirtualPrimaryKeyPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The MyBatis Team 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.plugins; 17 | 18 | import java.util.List; 19 | import java.util.StringTokenizer; 20 | 21 | import org.mybatis.generator.api.IntrospectedTable; 22 | import org.mybatis.generator.api.PluginAdapter; 23 | 24 | /** 25 | * This plugin can be used to specify columns that act as a primary key, even if 26 | * they are not strictly defined as primary keys in the database. 27 | * 28 | * To use the plugin, add a property to the table configuration specifying a 29 | * comma delimited list of column names to use as a primary key: 30 | * 31 | * 32 | * 33 | * 34 | * 35 | * @author Jeff Butler 36 | * 37 | */ 38 | public class VirtualPrimaryKeyPlugin extends PluginAdapter { 39 | 40 | public boolean validate(List warnings) { 41 | return true; 42 | } 43 | 44 | @Override 45 | public void initialized(IntrospectedTable introspectedTable) { 46 | String virtualKey = introspectedTable.getTableConfiguration() 47 | .getProperty("virtualKeyColumns"); //$NON-NLS-1$ 48 | 49 | if (virtualKey != null) { 50 | StringTokenizer st = new StringTokenizer(virtualKey, ", ", false); //$NON-NLS-1$ 51 | while (st.hasMoreTokens()) { 52 | String column = st.nextToken(); 53 | introspectedTable.addPrimaryKeyColumn(column); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /update.txt: -------------------------------------------------------------------------------- 1 | 修改记录: 2 | 3 | 1、Mapper.xml空格改成四个空格 4 | 修改详情: 5 | 6 | org.mybatis.generator.api.dom.OutputUtilities 7 | 8 | mybatis-generator 里面我觉得首先最应该改的就是 OutputUtilities 这个类,它里面有个 xmlIndent 方法是用来控制生成的 xml 文件中空格的缩进,默认是两个空格 9 | 但四个空格对于我们来说已经深入骨髓了,所以必须改。 在 sb.append( " " ) 里面增加两个空格就可以了。 10 | 11 | 2、修改dao包下的名称,由原来的XXXMapper改成XXXDao 12 | 修改详情: 13 | org.mybatis.generator.api.IntrospectedTable 14 | 15 | calculateJavaClientAttributes方法(大概820行) 16 | sb.append("Mapper");注释掉改成 sb.append("Dao"); 17 | 18 | 3、修改Mybatis的Model生成JavaDoc注释内容: 19 | 1)generatorConfig.xml配置里面设置成: 20 | 代码修改详情: 21 | org.mybatis.generator.internal.DefaultCommentGenerator里面的添加注释代码去掉,改成 22 | 23 | ------------------------------ code start ---------------------------------------- 24 | field.addJavaDocLine("/**"); 25 | field.addJavaDocLine(" * @Fields "+field.getName()+" "+introspectedColumn.getRemarks()); 26 | field.addJavaDocLine(" */"); 27 | 28 | ------------------------------ code end --------------------------------------------- 29 | 30 | 4、org.mybatis.generator.internal.DefaultCommentGenerator修改XXXDao.java(XXXMapper.java)的接口方法的Javadoc注释 31 | 搜索org.mybatis.generator.internal.DefaultCommentGenerator如下方法,并注释方法里面内容, 32 | public void addGeneralMethodComment(Method method, 33 | IntrospectedTable introspectedTable) 34 | 35 | 改成: 36 | 37 | method.addJavaDocLine("/**"); 38 | method.addJavaDocLine(" * @Title " + method.getName()); 39 | for (Parameter parameter : method.getParameters()) { 40 | method.addJavaDocLine(" * @param " + parameter.getName()); 41 | } 42 | String returnType = method.getReturnType().toString(); 43 | returnType = returnType.lastIndexOf(".") != -1 ? returnType.substring(returnType.lastIndexOf(".") + 1) : returnType; 44 | method.addJavaDocLine(" * @return " + returnType); 45 | method.addJavaDocLine(" */"); 46 | 47 | 5、注释掉Model里面Getter和Setter方法的注释,根据需要自己加上配置 48 | 搜索org.mybatis.generator.internal.DefaultCommentGenerator如下方法: 49 | public void addGetterComment(Method method, 50 | IntrospectedTable introspectedTable, 51 | IntrospectedColumn introspectedColumn) 52 | 53 | public void addSetterComment(Method method, 54 | IntrospectedTable introspectedTable, 55 | IntrospectedColumn introspectedColumn) 56 | 57 | 6、注释掉Mapper.xml里面的,实际使用未用到 58 | 搜索org.mybatis.generator.internal.DefaultCommentGenerator如下方法: 59 | public void addComment(XmlElement xmlElement) 60 | 61 | 7、XML里面每个SQL增加一个换行 62 | org.mybatis.generator.api.dom.xml.XmlElement里面getFormattedContent里面加上: 63 | if(indentLevel == 1) { 64 | //每个insert/update/select之间插入一个空行 65 | OutputUtilities.newLine(sb); 66 | } 67 | 68 | 8、修改mybatis的mapper.xml文件里面insert和update不根据字段判断的非动态SQL 69 | org.mybatis.generator.codegen.mybatis3.xmlmapper.XMLMapperGenerator 70 | 里面的getSqlMapElement方法 71 | 72 | 注释掉: 73 | addInsertElement(answer); 74 | addUpdateByPrimaryKeyWithoutBLOBsElement(answer); 75 | 76 | 对应的是mapper.xml里面的 77 | 78 | 79 | --------------------------------------------------------------------------------