├── .gitignore ├── Jenkinsfile ├── README.md ├── generatorConfig配置详解.md ├── java-generator-core ├── pom.xml └── src │ ├── main │ ├── assembly │ │ └── src.xml │ ├── java │ │ └── org │ │ │ └── mybatis │ │ │ ├── MyTest.java │ │ │ └── generator │ │ │ ├── ant │ │ │ ├── AntProgressCallback.java │ │ │ └── GeneratorAntTask.java │ │ │ ├── api │ │ │ ├── CommentGenerator.java │ │ │ ├── ConnectionFactory.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 │ │ │ │ │ ├── JavaDomUtils.java │ │ │ │ │ ├── JavaElement.java │ │ │ │ │ ├── JavaReservedWords.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 │ │ │ ├── freemarker │ │ │ │ ├── FreemarkerUtil.java │ │ │ │ ├── JavaDomainGenerator.java │ │ │ │ ├── JavaServiceGenerator.java │ │ │ │ └── TemplateEntity │ │ │ │ │ ├── DomainTemplateEntity.java │ │ │ │ │ ├── ServiceTemplateEntity.java │ │ │ │ │ └── TemplateEntity.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 │ │ │ │ ├── ListUtilities.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 │ │ │ │ │ ├── SelectNotDeleteAllMethodGenerator.java │ │ │ │ │ ├── SelectNotDeleteByPrimaryKeyMethodGenerator.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 │ │ │ │ ├── BoGenerator.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 │ │ │ │ ├── SelectNotDeleteAllElementGenerator.java │ │ │ │ ├── SelectNotDeleteByPrimaryKeyElementGenerator.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 │ │ │ ├── ConnectionFactoryConfiguration.java │ │ │ ├── Context.java │ │ │ ├── GeneratedKey.java │ │ │ ├── IgnoredColumn.java │ │ │ ├── IgnoredColumnException.java │ │ │ ├── IgnoredColumnPattern.java │ │ │ ├── JDBCConnectionConfiguration.java │ │ │ ├── JavaBoGeneratorConfiguration.java │ │ │ ├── JavaClientGeneratorConfiguration.java │ │ │ ├── JavaDomainGeneratorConfiguration.java │ │ │ ├── JavaModelGeneratorConfiguration.java │ │ │ ├── JavaServiceGeneratorConfiguration.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 │ │ │ ├── exception │ │ │ ├── InvalidConfigurationException.java │ │ │ ├── ShellException.java │ │ │ └── XMLParserException.java │ │ │ ├── internal │ │ │ ├── DefaultCommentGenerator.java │ │ │ ├── DefaultDAOMethodNameCalculator.java │ │ │ ├── DefaultShellCallback.java │ │ │ ├── DomWriter.java │ │ │ ├── ExtendedDAOMethodNameCalculator.java │ │ │ ├── JDBCConnectionFactory.java │ │ │ ├── JavaFileMergerJaxp.java │ │ │ ├── NullProgressCallback.java │ │ │ ├── ObjectFactory.java │ │ │ ├── PluginAggregator.java │ │ │ ├── XmlFileMergerJaxp.java │ │ │ ├── db │ │ │ │ ├── ActualTableName.java │ │ │ │ ├── DatabaseDialects.java │ │ │ │ ├── DatabaseIntrospector.java │ │ │ │ └── SqlReservedWords.java │ │ │ ├── rules │ │ │ │ ├── BaseRules.java │ │ │ │ ├── ConditionalModelRules.java │ │ │ │ ├── FlatModelRules.java │ │ │ │ ├── HierarchicalModelRules.java │ │ │ │ ├── Rules.java │ │ │ │ └── RulesDelegate.java │ │ │ ├── types │ │ │ │ ├── JavaTypeResolverDefaultImpl.java │ │ │ │ └── JdbcTypeNameTranslator.java │ │ │ └── util │ │ │ │ ├── ClassloaderUtility.java │ │ │ │ ├── EqualsUtil.java │ │ │ │ ├── HashCodeUtil.java │ │ │ │ ├── JavaBeansUtil.java │ │ │ │ ├── StringUtility.java │ │ │ │ └── messages │ │ │ │ └── Messages.java │ │ │ ├── logging │ │ │ ├── AbstractLogFactory.java │ │ │ ├── JdkLoggingImpl.java │ │ │ ├── Log.java │ │ │ ├── Log4jImpl.java │ │ │ └── LogFactory.java │ │ │ └── plugins │ │ │ ├── CachePlugin.java │ │ │ ├── CaseInsensitiveLikePlugin.java │ │ │ ├── EqualsHashCodePlugin.java │ │ │ ├── FluentBuilderMethodsPlugin.java │ │ │ ├── MapperConfigPlugin.java │ │ │ ├── RenameExampleClassPlugin.java │ │ │ ├── RowBoundsPlugin.java │ │ │ ├── SerializablePlugin.java │ │ │ ├── SqlMapConfigPlugin.java │ │ │ ├── ToStringPlugin.java │ │ │ └── VirtualPrimaryKeyPlugin.java │ └── resources │ │ ├── generatorConfig.xml │ │ ├── org │ │ └── mybatis │ │ │ └── generator │ │ │ ├── config │ │ │ └── xml │ │ │ │ ├── ibator-config_1_0.dtd │ │ │ │ └── mybatis-generator-config_1_0.dtd │ │ │ └── internal │ │ │ └── util │ │ │ └── messages │ │ │ └── messages.properties │ │ └── template │ │ ├── DomainTemplate │ │ ├── NativeDomainTemplate │ │ └── ServiceTemplate │ ├── site │ ├── resources │ │ └── mbgstyle.css │ ├── site.xml │ └── xhtml │ │ ├── afterRunning.xhtml │ │ ├── configreference │ │ ├── classPathEntry.xhtml │ │ ├── columnOverride.xhtml │ │ ├── columnRenamingRule.xhtml │ │ ├── commentGenerator.xhtml │ │ ├── connectionFactory.xhtml │ │ ├── context.xhtml │ │ ├── except.xhtml │ │ ├── generatedKey.xhtml │ │ ├── generatorConfiguration.xhtml │ │ ├── ignoreColumn.xhtml │ │ ├── ignoreColumnsByRegex.xhtml │ │ ├── javaBoGenerator.xhtml │ │ ├── javaClientGenerator.xhtml │ │ ├── javaModelGenerator.xhtml │ │ ├── javaTypeResolver.xhtml │ │ ├── jdbcConnection.xhtml │ │ ├── plugin.xhtml │ │ ├── properties.xhtml │ │ ├── property.xhtml │ │ ├── sqlMapGenerator.xhtml │ │ ├── table.xhtml │ │ └── xmlconfig.xhtml │ │ ├── generatedobjects │ │ ├── exampleClassUsage.xhtml │ │ ├── extendingExampleClass.xhtml │ │ ├── javabo.xhtml │ │ ├── javaclient.xhtml │ │ ├── javamodel.xhtml │ │ ├── results.xhtml │ │ └── sqlmap.xhtml │ │ ├── index.xhtml │ │ ├── license.xhtml │ │ ├── migratingFromAbator.xhtml │ │ ├── migratingFromIbator.xhtml │ │ ├── philosophy.xhtml │ │ ├── quickstart.xhtml │ │ ├── reference │ │ ├── building.xhtml │ │ ├── extending.xhtml │ │ ├── intro.xhtml │ │ ├── logging.xhtml │ │ ├── pluggingIn.xhtml │ │ └── plugins.xhtml │ │ ├── running │ │ ├── running.xhtml │ │ ├── runningFromCmdLine.xhtml │ │ ├── runningWithAnt.xhtml │ │ ├── runningWithEclipse.xhtml │ │ ├── runningWithJava.xhtml │ │ └── runningWithMaven.xhtml │ │ ├── usage │ │ ├── db2.xhtml │ │ ├── intro.xhtml │ │ ├── mysql.xhtml │ │ ├── oracle.xhtml │ │ └── postgresql.xhtml │ │ └── whatsNew.xhtml │ └── test │ ├── java │ └── org │ │ └── mybatis │ │ └── generator │ │ ├── JavaCodeGenerationTest.java │ │ ├── MyBatisGeneratorTest.java │ │ ├── SqlScriptRunner.java │ │ ├── XmlCodeGenerationTest.java │ │ ├── api │ │ ├── GeneratedJavaFileTest.java │ │ └── dom │ │ │ └── java │ │ │ ├── FullyQualifiedJavaTypeTest.java │ │ │ └── JavaDomUtilsTest.java │ │ └── internal │ │ ├── XmlFileMergerTest.java │ │ └── util │ │ ├── JavaBeansUtilTest.java │ │ └── StringUtilityTest.java │ └── resources │ ├── generatorConfigIbatis2_badConfig.xml │ ├── generatorConfigMyBatis3_badConfig.xml │ ├── log4j.properties │ └── scripts │ ├── CreateDB.sql │ ├── database.properties │ ├── generatorConfig.xml │ └── ibatorConfig.xml ├── java-generator-maven-plugin ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── mybatis │ └── generator │ └── maven │ ├── MavenLogFactory.java │ ├── MavenLogImpl.java │ ├── MavenProgressCallback.java │ ├── MavenShellCallback.java │ ├── MyBatisGeneratorMojo.java │ └── SqlScriptRunner.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | ### Java template 2 | *.class 3 | 4 | # Mobile Tools for Java (J2ME) 5 | .mtj.tmp/ 6 | 7 | # Package Files # 8 | *.jar 9 | *.war 10 | *.ear 11 | 12 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 13 | hs_err_pid* 14 | ### Example user template template 15 | ### Example user template 16 | 17 | # IntelliJ project files 18 | .idea 19 | *.iml 20 | out 21 | gen 22 | 23 | /target/ 24 | .classpath 25 | /.settings/ 26 | .project 27 | .DS_Store 28 | target 29 | ree.txt 30 | tree.txt 31 | *.log -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | node { 2 | try { 3 | stage('Stage Checkout') { 4 | checkout scm 5 | echo "My branch is: ${env.BRANCH_NAME}" 6 | } 7 | stage('Stage Build') { 8 | sh "mvn clean deploy -Dmaven.test.skip=true -U" 9 | } 10 | stage('Stage Archive') { 11 | archiveArtifacts artifacts: 'target/*.jar', fingerprint: true 12 | } 13 | } 14 | catch (err) { 15 | currentBuild.result = "FAILED" 16 | notifyFailed(err) 17 | throw err 18 | } 19 | // def sonProject = 'Multibranch-business-logic-core' 20 | // def branchName = getBranchName("${env.BRANCH_NAME}") 21 | // try { 22 | // stage('Build other project') { 23 | // 24 | // build "${sonProject}/${branchName}" 25 | // } 26 | // } 27 | // catch (err) { 28 | // flag = true 29 | // echo "触发下级工程有问题:${sonProject}/${branchName}" 30 | // mail body: "触发下级工程有问题:${sonProject}/${branchName} \n ${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - : \n Check console output at ${env.BUILD_URL} to view the results.\nERROR:\n ${err}", 31 | //// from: 'jenkins@cheok.com', 32 | // replyTo: 'jenkins@cheok.com', 33 | // subject: "触发下级工程有问题:${sonProject}/${branchName}", 34 | // to: 'scm@cheok.com' 35 | // echo "${err}" 36 | // } 37 | } 38 | 39 | def notifyFailed(def err) { 40 | emailext( 41 | subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}] [${env.BRANCH_NAME}]'", 42 | body: """FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}] [${env.BRANCH_NAME}]': 43 | Check console output at ${env.BUILD_URL} 44 | ERROR: 45 | ${err} 46 | """, 47 | recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']], 48 | to: 'scm@cheok.com' 49 | ) 50 | } 51 | 52 | //分支中带/符号,需要urlencode 53 | def static getBranchName(String branch) { 54 | return branch.replace('/', '%2F') 55 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 1、增加获取sqlServer数据库字段注释功能 2 | 2、Mapper生成接口修改: 3 | (1)deleteByExample接口修改为FIsDelete标志删除; 4 | (2)deleteByPrimaryKey接口修改为FIsDelete标志删除; 5 | (3)insert接口默认不生成; 6 | (4)updateByExample接口默认不生成; 7 | (5)updateByPrimaryKey接口默认不生成; 8 | (6)新增默认生成selectAll接口; 9 | (7)新增默认生成selectNotDeleteAll接口; 10 | (8)新增默认生成selectNotDeleteByPrimaryKey接口; 11 | 3、扩展生成Bo,可选; 12 | 4、扩展生成简单的Service和domain,可选,成对出现: 13 | (1)Service默认方法:save,deleteByPrimaryKey,getByPrimaryKey,getNotDeleteByPrimaryKey,findAll,findNotDeleteAll; 14 | (2)Domain默认方法:get; 15 | 16 | 17 | TODO: 18 | 1、需要优化重复生成覆盖java代码的问题; 19 | -------------------------------------------------------------------------------- /java-generator-core/src/main/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 18 | 21 | bundle 22 | 23 | zip 24 | 25 | 26 | 27 | 28 | ${project.basedir}/README* 29 | ${project.basedir}/LICENSE* 30 | ${project.basedir}/NOTICE* 31 | 32 | 33 | 34 | ${project.build.directory} 35 | lib 36 | 37 | *.jar 38 | 39 | 40 | 41 | ${project.build.directory}/site 42 | docs 43 | 44 | **/*.* 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/MyTest.java: -------------------------------------------------------------------------------- 1 | package org.mybatis; 2 | 3 | import org.mybatis.generator.api.MyBatisGenerator; 4 | import org.mybatis.generator.api.ShellRunner; 5 | import org.mybatis.generator.config.Configuration; 6 | import org.mybatis.generator.config.xml.ConfigurationParser; 7 | import org.mybatis.generator.exception.InvalidConfigurationException; 8 | import org.mybatis.generator.exception.XMLParserException; 9 | import org.mybatis.generator.internal.DefaultShellCallback; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.net.URL; 14 | import java.sql.SQLException; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * Created by whm on 2017/7/18. 20 | */ 21 | public class MyTest { 22 | public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException { 23 | List warnings = new ArrayList(); 24 | boolean overwrite = true; 25 | URL url = ShellRunner.class.getClassLoader().getResource("generatorConfig.xml"); 26 | File configFile = new File(url.getFile()); 27 | ConfigurationParser cp = new ConfigurationParser(warnings); 28 | Configuration config = cp.parseConfiguration(configFile); 29 | DefaultShellCallback callback = new DefaultShellCallback(overwrite); 30 | MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); 31 | myBatisGenerator.generate(null); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/ant/AntProgressCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.ant; 17 | 18 | import org.apache.tools.ant.Project; 19 | import org.apache.tools.ant.Task; 20 | import org.mybatis.generator.internal.NullProgressCallback; 21 | 22 | /** 23 | * This callback logs progress messages with the Ant logger. 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AntProgressCallback extends NullProgressCallback { 28 | 29 | /** The task. */ 30 | private Task task; 31 | 32 | /** The verbose. */ 33 | private boolean verbose; 34 | 35 | /** 36 | * Instantiates a new ant progress callback. 37 | * 38 | * @param task 39 | * the task 40 | * @param verbose 41 | * the verbose 42 | */ 43 | public AntProgressCallback(Task task, boolean verbose) { 44 | super(); 45 | this.task = task; 46 | this.verbose = verbose; 47 | } 48 | 49 | /* (non-Javadoc) 50 | * @see org.mybatis.generator.internal.NullProgressCallback#startTask(java.lang.String) 51 | */ 52 | @Override 53 | public void startTask(String subTaskName) { 54 | if (verbose) { 55 | task.log(subTaskName, Project.MSG_VERBOSE); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | import java.sql.Connection; 19 | import java.sql.SQLException; 20 | import java.util.Properties; 21 | 22 | public interface ConnectionFactory { 23 | /** 24 | * Should return a connection to the database in use for this context. 25 | * The generator will call this method only one time for each context. 26 | * The generator will close the connection. 27 | * 28 | * @return 29 | * @throws SQLException 30 | */ 31 | Connection getConnection() throws SQLException; 32 | 33 | /** 34 | * Adds properties for this instance from any properties configured in the 35 | * ConnectionFactory. 36 | * 37 | * This method will be called before any of the get methods. 38 | * 39 | * @param properties 40 | * All properties from the configuration 41 | */ 42 | void addConfigurationProperties(Properties properties); 43 | } 44 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/JavaFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/VerboseProgressCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | import org.mybatis.generator.internal.NullProgressCallback; 19 | 20 | /** 21 | * @author Jeff Butler 22 | * 23 | */ 24 | public class VerboseProgressCallback extends NullProgressCallback { 25 | 26 | /** 27 | * 28 | */ 29 | public VerboseProgressCallback() { 30 | super(); 31 | } 32 | 33 | @Override 34 | public void startTask(String taskName) { 35 | System.out.println(taskName); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/XmlFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/dom/DefaultJavaFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/dom/DefaultXmlFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/dom/java/JavaVisibility.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/Attribute.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.xml; 17 | 18 | /** 19 | * The Class Attribute. 20 | * 21 | * @author Jeff Butler 22 | */ 23 | public class Attribute implements Comparable{ 24 | 25 | /** The name. */ 26 | private String name; 27 | 28 | /** The value. */ 29 | private String value; 30 | 31 | /** 32 | * Instantiates a new attribute. 33 | * 34 | * @param name 35 | * the name 36 | * @param value 37 | * the value 38 | */ 39 | public Attribute(String name, String value) { 40 | super(); 41 | this.name = name; 42 | this.value = value; 43 | } 44 | 45 | /** 46 | * Gets the name. 47 | * 48 | * @return Returns the name. 49 | */ 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | /** 55 | * Gets the value. 56 | * 57 | * @return Returns the value. 58 | */ 59 | public String getValue() { 60 | return value; 61 | } 62 | 63 | /** 64 | * Gets the formatted content. 65 | * 66 | * @return the formatted content 67 | */ 68 | public String getFormattedContent() { 69 | StringBuilder sb = new StringBuilder(); 70 | sb.append(name); 71 | sb.append("=\""); //$NON-NLS-1$ 72 | sb.append(value); 73 | sb.append('\"'); 74 | 75 | return sb.toString(); 76 | } 77 | 78 | @Override 79 | public int compareTo(Attribute o) { 80 | if (this.name == null) { 81 | return o.name == null ? 0: -1; 82 | } else { 83 | if (o.name == null) { 84 | return 0; 85 | } else { 86 | return this.name.compareTo(o.name); 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/Element.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/TextElement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.xml; 17 | 18 | import org.mybatis.generator.api.dom.OutputUtilities; 19 | 20 | /** 21 | * The Class TextElement. 22 | * 23 | * @author Jeff Butler 24 | */ 25 | public class TextElement extends Element { 26 | 27 | /** The content. */ 28 | private String content; 29 | 30 | /** 31 | * Instantiates a new text element. 32 | * 33 | * @param content 34 | * the content 35 | */ 36 | public TextElement(String content) { 37 | super(); 38 | this.content = content; 39 | } 40 | 41 | /* (non-Javadoc) 42 | * @see org.mybatis.generator.api.dom.xml.Element#getFormattedContent(int) 43 | */ 44 | @Override 45 | public String getFormattedContent(int indentLevel) { 46 | StringBuilder sb = new StringBuilder(); 47 | OutputUtilities.xmlIndent(sb, indentLevel); 48 | sb.append(content); 49 | return sb.toString(); 50 | } 51 | 52 | /** 53 | * Gets the content. 54 | * 55 | * @return the content 56 | */ 57 | public String getContent() { 58 | return content; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/api/package.html: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | Package Description for Main MyBatis Generator API Classes 21 | 22 | 23 |

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

24 | 25 | 26 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/AbstractGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/AbstractJavaClientGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/AbstractXmlGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/XmlConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/freemarker/FreemarkerUtil.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.codegen.freemarker; 2 | 3 | import freemarker.template.Template; 4 | import freemarker.template.TemplateException; 5 | import org.mybatis.generator.codegen.freemarker.TemplateEntity.TemplateEntity; 6 | import org.mybatis.generator.internal.JavaFileMergerJaxp; 7 | 8 | import java.io.*; 9 | 10 | import static org.springframework.util.FileCopyUtils.copy; 11 | 12 | /** 13 | * Created by whm on 2017/8/8. 14 | */ 15 | public class FreemarkerUtil { 16 | public static void generateFreemarkerFile(File file ,Template t,TemplateEntity s){ 17 | try { 18 | Reader in; 19 | boolean isFirst = false; 20 | String oldFileSource = ""; 21 | if (file != null && file.canRead()){ 22 | in = new FileReader(file); 23 | StringWriter out = new StringWriter(); 24 | copy(in,out); 25 | oldFileSource = out.toString(); 26 | isFirst = true; 27 | } 28 | FileOutputStream fos = new FileOutputStream(file); //java文件的生成目录 29 | t.process(s, new OutputStreamWriter(fos, "utf-8")); // 30 | fos.flush(); 31 | fos.close(); 32 | 33 | //读取新生成的文件内容 34 | String newFileSource = ""; 35 | if (file != null && file.canRead()){ 36 | in = new FileReader(file); 37 | StringWriter out = new StringWriter(); 38 | copy(in,out); 39 | newFileSource = out.toString(); 40 | in.close(); 41 | } 42 | if (isFirst) { 43 | String newJavaFileContent = new JavaFileMergerJaxp().getNewFreemarkerJavaFile(newFileSource, oldFileSource); 44 | Writer writer = new FileWriter(file); 45 | writer.write(newJavaFileContent); 46 | writer.close(); 47 | } 48 | 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } catch (TemplateException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/freemarker/JavaDomainGenerator.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.codegen.freemarker; 2 | 3 | import freemarker.template.Configuration; 4 | import freemarker.template.Template; 5 | import freemarker.template.TemplateException; 6 | import org.mybatis.generator.codegen.freemarker.TemplateEntity.DomainTemplateEntity; 7 | import org.mybatis.generator.codegen.freemarker.TemplateEntity.ServiceTemplateEntity; 8 | 9 | import java.io.*; 10 | import java.util.List; 11 | 12 | import static org.mybatis.generator.codegen.freemarker.FreemarkerUtil.generateFreemarkerFile; 13 | 14 | /** 15 | * Created by whm on 2017/7/26. 16 | */ 17 | public class JavaDomainGenerator { 18 | public static void addJavaDomainGenerator(List domainTemplateEntities) { 19 | try { 20 | for (DomainTemplateEntity d:domainTemplateEntities) { 21 | Configuration cfg = new Configuration(); 22 | DomainTemplateEntity.DomainTemplate domainTemplate = d.getDomainTemplate(); 23 | DomainTemplateEntity.NativeDomainTemplate nativeDomainTemplate = d.getNativeDomainTemplate(); 24 | cfg.setClassForTemplateLoading(JavaDomainGenerator.class, "/template"); //指定模板所在的classpath目录 25 | Template t = cfg.getTemplate("DomainTemplate"); //指定模板 26 | File f = new File(System.getProperty("user.dir") +"/"+ domainTemplate.getProjectTargetPackage()); 27 | f.mkdirs(); 28 | File domainFile = new File(System.getProperty("user.dir") +"/"+ domainTemplate.getProjectTargetPackage() + domainTemplate.getDomainInterface()+".java"); 29 | generateFreemarkerFile(domainFile,t,domainTemplate); 30 | Configuration cfg1 = new Configuration(); 31 | cfg1.setClassForTemplateLoading(JavaDomainGenerator.class, "/template"); //指定模板所在的classpath目录 32 | Template t1 = cfg1.getTemplate("NativeDomainTemplate"); //指定模板 33 | File nativeDomainFile = new File(System.getProperty("user.dir") +"/"+ nativeDomainTemplate.getProjectTargetPackage() + nativeDomainTemplate.getNativeDomainClazz()+".java"); 34 | 35 | generateFreemarkerFile(nativeDomainFile,t1,nativeDomainTemplate); 36 | 37 | } 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/freemarker/JavaServiceGenerator.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.codegen.freemarker; 2 | 3 | import freemarker.template.Configuration; 4 | import freemarker.template.Template; 5 | import freemarker.template.TemplateException; 6 | import org.mybatis.generator.codegen.freemarker.TemplateEntity.ServiceTemplateEntity; 7 | import org.mybatis.generator.internal.JavaFileMergerJaxp; 8 | 9 | import java.io.*; 10 | 11 | import java.util.List; 12 | 13 | import static org.mybatis.generator.codegen.freemarker.FreemarkerUtil.generateFreemarkerFile; 14 | import static org.springframework.util.FileCopyUtils.copy; 15 | 16 | 17 | /** 18 | * 通过解析serviceTemplate生成对应的service 19 | * Created by whm on 2017/7/26. 20 | */ 21 | public class JavaServiceGenerator { 22 | 23 | public static void addJavaServiceGenerator(List serviceTemplateEntityList) { 24 | Configuration cfg = new Configuration(); 25 | try { 26 | for (ServiceTemplateEntity s : serviceTemplateEntityList) { 27 | cfg.setClassForTemplateLoading(JavaServiceGenerator.class, "/template"); //指定模板所在的classpath目录 28 | Template t = cfg.getTemplate("ServiceTemplate"); //指定模板 29 | File f = new File(System.getProperty("user.dir") + "/" + s.getProjectTargetPackage()); 30 | f.mkdirs(); 31 | String filePath = System.getProperty("user.dir") + "/" + s.getProjectTargetPackage() + s.getClassName() + ".java"; 32 | File file = new File(filePath); 33 | generateFreemarkerFile(file ,t,s); 34 | } 35 | } catch (IOException e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/freemarker/TemplateEntity/TemplateEntity.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.codegen.freemarker.TemplateEntity; 2 | 3 | /** 4 | * Created by whm on 2017/8/8. 5 | */ 6 | public interface TemplateEntity { 7 | } 8 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/IntrospectedTableIbatis2Java5Impl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2; 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/dao/templates/SpringDAOTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.dao.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.ibatis2.Ibatis2FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.ibatis2.Ibatis2FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class BlobColumnListElementGenerator extends AbstractXmlElementGenerator { 32 | 33 | public BlobColumnListElementGenerator() { 34 | super(); 35 | } 36 | 37 | @Override 38 | public void addElements(XmlElement parentElement) { 39 | XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$ 40 | 41 | answer.addAttribute(new Attribute("id", //$NON-NLS-1$ 42 | introspectedTable.getBlobColumnListId())); 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | 48 | Iterator 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/CountByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import 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.Long")); //$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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/DeleteByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/ListUtilities.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import org.mybatis.generator.api.IntrospectedColumn; 22 | 23 | /** 24 | * Couple of little utility methods to make dealing with generated always 25 | * columns easier. If a column is GENERATED ALWAYS, it should not 26 | * be references on an insert or update method. 27 | * 28 | * If a column is identity, it should not be referenced on an insert method. 29 | * 30 | * TODO - Replace this with Lambdas when we get to Java 8 31 | * @author Jeff Butler 32 | * 33 | */ 34 | public class ListUtilities { 35 | 36 | public static List removeGeneratedAlwaysColumns(List columns) { 37 | List filteredList = new ArrayList(); 38 | for (IntrospectedColumn ic : columns) { 39 | if (!ic.isGeneratedAlways()) { 40 | filteredList.add(ic); 41 | } 42 | } 43 | return filteredList; 44 | } 45 | 46 | public static List removeIdentityAndGeneratedAlwaysColumns(List columns) { 47 | List filteredList = new ArrayList(); 48 | for (IntrospectedColumn ic : columns) { 49 | if (!ic.isGeneratedAlways() && !ic.isIdentity()) { 50 | filteredList.add(ic); 51 | } 52 | } 53 | return filteredList; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/CountByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import 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(new FullyQualifiedJavaType("long")); //$NON-NLS-1$ 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 | } 66 | } 67 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/DeleteByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import 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 | } 66 | } 67 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/InsertSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import 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 | } 68 | } 69 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/SelectAllMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import 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 | } 71 | } 72 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/SelectNotDeleteAllMethodGenerator.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 2 | 3 | 4 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 5 | import org.mybatis.generator.api.dom.java.Interface; 6 | import org.mybatis.generator.api.dom.java.JavaVisibility; 7 | import org.mybatis.generator.api.dom.java.Method; 8 | 9 | import java.util.Set; 10 | import java.util.TreeSet; 11 | 12 | 13 | /** 14 | * Created by whm on 2017/7/25. 15 | */ 16 | public class SelectNotDeleteAllMethodGenerator extends AbstractJavaMapperMethodGenerator{ 17 | public SelectNotDeleteAllMethodGenerator() { 18 | super(); 19 | } 20 | @Override 21 | public void addInterfaceElements(Interface interfaze) { 22 | Set importedTypes = new TreeSet(); 23 | importedTypes.add(FullyQualifiedJavaType.getNewListInstance()); 24 | 25 | Method method = new Method(); 26 | method.setVisibility(JavaVisibility.PUBLIC); 27 | 28 | FullyQualifiedJavaType returnType = FullyQualifiedJavaType 29 | .getNewListInstance(); 30 | FullyQualifiedJavaType listType; 31 | listType = new FullyQualifiedJavaType( 32 | introspectedTable.getBaseRecordType()); 33 | 34 | importedTypes.add(listType); 35 | returnType.addTypeArgument(listType); 36 | method.setReturnType(returnType); 37 | method.setName(introspectedTable.getSelectNotDeleteAllStatementId()); 38 | 39 | context.getCommentGenerator().addGeneralMethodComment(method, 40 | introspectedTable); 41 | 42 | addMapperAnnotations(interfaze, method); 43 | 44 | if (context.getPlugins().clientSelectAllMethodGenerated(method, 45 | interfaze, introspectedTable)) { 46 | interfaze.addImportedTypes(importedTypes); 47 | interfaze.addMethod(method); 48 | } 49 | 50 | } 51 | 52 | 53 | public void addMapperAnnotations(Interface interfaze, Method method) { 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import 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 | } 67 | } 68 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedCountByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedDeleteByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedInsertSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/AbstractJavaProviderMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.sqlprovider; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.TopLevelClass; 20 | import org.mybatis.generator.codegen.AbstractGenerator; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | */ 26 | public abstract class AbstractJavaProviderMethodGenerator extends 27 | AbstractGenerator { 28 | 29 | protected static final FullyQualifiedJavaType NEW_BUILDER_IMPORT = new FullyQualifiedJavaType("org.apache.ibatis.jdbc.SQL"); //$NON-NLS-1$ 30 | protected boolean useLegacyBuilder; 31 | protected final String builderPrefix; 32 | 33 | public AbstractJavaProviderMethodGenerator(boolean useLegacyBuilder) { 34 | super(); 35 | this.useLegacyBuilder = useLegacyBuilder; 36 | if (useLegacyBuilder) { 37 | builderPrefix = ""; //$NON-NLS-1$ 38 | } else { 39 | builderPrefix = "sql."; //$NON-NLS-1$ 40 | } 41 | } 42 | 43 | public abstract void addClassElements(TopLevelClass topLevelClass); 44 | } 45 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderSelectByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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(boolean useLegacyBuilder) { 33 | super(useLegacyBuilder); 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderUpdateByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.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(boolean useLegacyBuilder) { 33 | super(useLegacyBuilder); 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/MixedMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper; 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 | } 30 | 31 | @Override 32 | protected void addDeleteByPrimaryKeyElement(XmlElement parentElement) { 33 | } 34 | 35 | @Override 36 | protected void addInsertElement(XmlElement parentElement) { 37 | } 38 | 39 | @Override 40 | protected void addUpdateByPrimaryKeyWithBLOBsElement( 41 | XmlElement parentElement) { 42 | } 43 | 44 | @Override 45 | protected void addUpdateByPrimaryKeyWithoutBLOBsElement( 46 | XmlElement parentElement) { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/BaseColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class BaseColumnListElementGenerator extends AbstractXmlElementGenerator { 32 | 33 | public BaseColumnListElementGenerator() { 34 | super(); 35 | } 36 | 37 | @Override 38 | public void addElements(XmlElement parentElement) { 39 | XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$ 40 | 41 | answer.addAttribute(new Attribute("id", //$NON-NLS-1$ 42 | introspectedTable.getBaseColumnListId())); 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | Iterator 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/BlobColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class 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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/CountByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import 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.Long")); //$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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/DeleteByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import 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("update "); //$NON-NLS-1$ 48 | sb.append(introspectedTable 49 | .getAliasedFullyQualifiedTableNameAtRuntime()); 50 | sb.append(" set FIsDelete = 1"); 51 | answer.addElement(new TextElement(sb.toString())); 52 | answer.addElement(getExampleIncludeElement()); 53 | 54 | if (context.getPlugins().sqlMapDeleteByExampleElementGenerated( 55 | answer, introspectedTable)) { 56 | parentElement.addElement(answer); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/CommentGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | */ 25 | public class CommentGeneratorConfiguration extends TypedPropertyHolder { 26 | 27 | /** 28 | * 29 | */ 30 | public CommentGeneratorConfiguration() { 31 | } 32 | 33 | public XmlElement toXmlElement() { 34 | XmlElement answer = new XmlElement("commentGenerator"); //$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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/ConnectionFactoryConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | import org.mybatis.generator.internal.util.StringUtility; 26 | 27 | public class ConnectionFactoryConfiguration extends TypedPropertyHolder { 28 | 29 | public ConnectionFactoryConfiguration() { 30 | super(); 31 | } 32 | 33 | public void validate(List errors) { 34 | if (getConfigurationType() == null || "DEFAULT".equals(getConfigurationType())) { //$NON-NLS-1$ 35 | if (!StringUtility.stringHasValue(getProperty("driverClass"))) { //$NON-NLS-1$ 36 | errors.add(getString("ValidationError.18", "connectionFactory", "driverClass")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 37 | } 38 | 39 | if (!StringUtility.stringHasValue(getProperty("connectionURL"))) { //$NON-NLS-1$ 40 | errors.add(getString("ValidationError.18", "connectionFactory", "connectionURL")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 41 | } 42 | } 43 | } 44 | 45 | public XmlElement toXmlElement() { 46 | XmlElement xmlElement = new XmlElement("connectionFactory"); //$NON-NLS-1$ 47 | 48 | if (stringHasValue(getConfigurationType())) { 49 | xmlElement.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$ 50 | } 51 | 52 | addPropertyXmlElements(xmlElement); 53 | 54 | return xmlElement; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/IgnoredColumnException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | public class IgnoredColumnException extends IgnoredColumn { 27 | 28 | public IgnoredColumnException(String columnName) { 29 | super(columnName); 30 | } 31 | 32 | @Override 33 | public XmlElement toXmlElement() { 34 | XmlElement xmlElement = new XmlElement("except"); //$NON-NLS-1$ 35 | xmlElement.addAttribute(new Attribute("column", columnName)); //$NON-NLS-1$ 36 | 37 | if (stringHasValue(configuredDelimitedColumnName)) { 38 | xmlElement.addAttribute(new Attribute( 39 | "delimitedColumnName", configuredDelimitedColumnName)); //$NON-NLS-1$ 40 | } 41 | 42 | return xmlElement; 43 | } 44 | 45 | public void validate(List errors, String tableName) { 46 | if (!stringHasValue(columnName)) { 47 | errors.add(getString("ValidationError.26", //$NON-NLS-1$ 48 | tableName)); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/IgnoredColumnPattern.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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.ArrayList; 22 | import java.util.List; 23 | import java.util.regex.Pattern; 24 | 25 | import org.mybatis.generator.api.dom.xml.Attribute; 26 | import org.mybatis.generator.api.dom.xml.XmlElement; 27 | 28 | public class IgnoredColumnPattern { 29 | 30 | private String patternRegex; 31 | private Pattern pattern; 32 | private List exceptions = new ArrayList(); 33 | 34 | public IgnoredColumnPattern(String patternRegex) { 35 | this.patternRegex = patternRegex; 36 | pattern = Pattern.compile(patternRegex); 37 | } 38 | 39 | public void addException(IgnoredColumnException exception) { 40 | exceptions.add(exception); 41 | } 42 | 43 | public boolean matches(String columnName) { 44 | boolean matches = pattern.matcher(columnName).matches(); 45 | 46 | if (matches) { 47 | for (IgnoredColumnException exception : exceptions) { 48 | if (exception.matches(columnName)) { 49 | matches = false; 50 | break; 51 | } 52 | } 53 | } 54 | 55 | return matches; 56 | } 57 | 58 | public XmlElement toXmlElement() { 59 | XmlElement xmlElement = new XmlElement("ignoreColumnsByRegex"); //$NON-NLS-1$ 60 | xmlElement.addAttribute(new Attribute("pattern", patternRegex)); //$NON-NLS-1$ 61 | 62 | for (IgnoredColumnException exception : exceptions) { 63 | xmlElement.addElement(exception.toXmlElement()); 64 | } 65 | 66 | return xmlElement; 67 | } 68 | 69 | public void validate(List errors, String tableName) { 70 | if (!stringHasValue(patternRegex)) { 71 | errors.add(getString("ValidationError.27", //$NON-NLS-1$ 72 | tableName)); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/JavaBoGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright ${license.git.copyrightYears} the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.XmlElement; 20 | 21 | import java.util.List; 22 | 23 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 24 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 25 | 26 | /** 27 | * Created by whm on 2017/7/20. 28 | */ 29 | public class JavaBoGeneratorConfiguration extends PropertyHolder { 30 | private String targetPackage; 31 | 32 | private String targetProject; 33 | 34 | /** 35 | * 36 | */ 37 | public JavaBoGeneratorConfiguration() { 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("javaBoGenerator"); //$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.0", contextId)); //$NON-NLS-1$ 76 | // } 77 | // 78 | // if (!stringHasValue(targetPackage)) { 79 | // errors.add(getString("ValidationError.12", //$NON-NLS-1$ 80 | // "JavaBoGenerator", contextId)); //$NON-NLS-1$ 81 | // } 82 | // } 83 | } 84 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/JavaDomainGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.config; 2 | 3 | import org.mybatis.generator.api.dom.xml.Attribute; 4 | import org.mybatis.generator.api.dom.xml.XmlElement; 5 | 6 | /** 7 | * Created by whm on 2017/7/26. 8 | */ 9 | public class JavaDomainGeneratorConfiguration extends PropertyHolder { 10 | private String targetPackage; 11 | 12 | private String targetProject; 13 | 14 | 15 | /** 16 | * 17 | */ 18 | public JavaDomainGeneratorConfiguration() { 19 | super(); 20 | } 21 | 22 | public XmlElement toXmlElement() { 23 | XmlElement answer = new XmlElement("javaDomainGenerator"); //$NON-NLS-1$ 24 | 25 | if (targetPackage != null) { 26 | answer.addAttribute(new Attribute("targetPackage", targetPackage)); //$NON-NLS-1$ 27 | } 28 | 29 | if (targetProject != null) { 30 | answer.addAttribute(new Attribute("targetProject", targetProject)); //$NON-NLS-1$ 31 | } 32 | 33 | addPropertyXmlElements(answer); 34 | 35 | return answer; 36 | } 37 | 38 | public String getTargetPackage() { 39 | return targetPackage; 40 | } 41 | 42 | public void setTargetPackage(String targetPackage) { 43 | this.targetPackage = targetPackage; 44 | } 45 | 46 | public String getTargetProject() { 47 | return targetProject; 48 | } 49 | 50 | public void setTargetProject(String targetProject) { 51 | this.targetProject = targetProject; 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/JavaModelGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/JavaServiceGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.config; 2 | 3 | import org.mybatis.generator.api.dom.xml.Attribute; 4 | import org.mybatis.generator.api.dom.xml.XmlElement; 5 | 6 | import java.util.List; 7 | 8 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 9 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 10 | 11 | /** 12 | * Created by whm on 2017/7/26. 13 | */ 14 | public class JavaServiceGeneratorConfiguration extends PropertyHolder{ 15 | private String targetPackage; 16 | 17 | private String targetProject; 18 | 19 | /** 20 | * 21 | */ 22 | public JavaServiceGeneratorConfiguration() { 23 | super(); 24 | } 25 | 26 | public String getTargetProject() { 27 | return targetProject; 28 | } 29 | 30 | public void setTargetProject(String targetProject) { 31 | this.targetProject = targetProject; 32 | } 33 | 34 | public String getTargetPackage() { 35 | return targetPackage; 36 | } 37 | 38 | public void setTargetPackage(String targetPackage) { 39 | this.targetPackage = targetPackage; 40 | } 41 | 42 | public XmlElement toXmlElement() { 43 | XmlElement answer = new XmlElement("javaServiceGenerator"); //$NON-NLS-1$ 44 | 45 | if (targetPackage != null) { 46 | answer.addAttribute(new Attribute("targetPackage", targetPackage)); //$NON-NLS-1$ 47 | } 48 | 49 | if (targetProject != null) { 50 | answer.addAttribute(new Attribute("targetProject", targetProject)); //$NON-NLS-1$ 51 | } 52 | 53 | addPropertyXmlElements(answer); 54 | 55 | return answer; 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/JavaTypeResolverConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/MergeConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 = "@mbg.generated"; //$NON-NLS-1$ 37 | public static final String[] OLD_ELEMENT_TAGS = { 38 | "@ibatorgenerated", //$NON-NLS-1$ 39 | "@abatorgenerated", //$NON-NLS-1$ 40 | "@mbggenerated", //$NON-NLS-1$ 41 | "@mbg.generated" }; //$NON-NLS-1$ 42 | 43 | } 44 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/ModelType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | /** 21 | * Typesafe enum of different model types 22 | * 23 | * @author Jeff Butler 24 | */ 25 | public enum ModelType { 26 | HIERARCHICAL("hierarchical"), //$NON-NLS-1$ 27 | FLAT("flat"), //$NON-NLS-1$ 28 | CONDITIONAL("conditional"); //$NON-NLS-1$ 29 | 30 | private final String modelType; 31 | 32 | /** 33 | * 34 | */ 35 | private ModelType(String modelType) { 36 | this.modelType = modelType; 37 | } 38 | 39 | public String getModelType() { 40 | return modelType; 41 | } 42 | 43 | public static ModelType getModelType(String type) { 44 | if (HIERARCHICAL.getModelType().equalsIgnoreCase(type)) { 45 | return HIERARCHICAL; 46 | } else if (FLAT.getModelType().equalsIgnoreCase(type)) { 47 | return FLAT; 48 | } else if (CONDITIONAL.getModelType().equalsIgnoreCase(type)) { 49 | return CONDITIONAL; 50 | } else { 51 | throw new RuntimeException(getString( 52 | "RuntimeError.13", type)); //$NON-NLS-1$ 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/PluginConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/PropertyHolder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/SqlMapGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/TypedPropertyHolder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/config/xml/ParserEntityResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/exception/InvalidConfigurationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.exception; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * The Class InvalidConfigurationException. 22 | * 23 | * @author Jeff Butler 24 | */ 25 | public class InvalidConfigurationException extends Exception { 26 | 27 | /** The Constant serialVersionUID. */ 28 | static final long serialVersionUID = 4902307610148543411L; 29 | 30 | /** The errors. */ 31 | private List errors; 32 | 33 | /** 34 | * Instantiates a new invalid configuration exception. 35 | * 36 | * @param errors 37 | * the errors 38 | */ 39 | public InvalidConfigurationException(List errors) { 40 | super(); 41 | this.errors = errors; 42 | } 43 | 44 | /** 45 | * Gets the errors. 46 | * 47 | * @return the errors 48 | */ 49 | public List getErrors() { 50 | return errors; 51 | } 52 | 53 | /* (non-Javadoc) 54 | * @see java.lang.Throwable#getMessage() 55 | */ 56 | @Override 57 | public String getMessage() { 58 | if (errors != null && errors.size() > 0) { 59 | return errors.get(0); 60 | } 61 | 62 | return super.getMessage(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/exception/ShellException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | 26 | /** The Constant serialVersionUID. */ 27 | static final long serialVersionUID = -2026841561754434544L; 28 | 29 | /** 30 | * Instantiates a new shell exception. 31 | */ 32 | public ShellException() { 33 | super(); 34 | } 35 | 36 | /** 37 | * Instantiates a new shell exception. 38 | * 39 | * @param arg0 40 | * the arg0 41 | */ 42 | public ShellException(String arg0) { 43 | super(arg0); 44 | } 45 | 46 | /** 47 | * Instantiates a new shell exception. 48 | * 49 | * @param arg0 50 | * the arg0 51 | * @param arg1 52 | * the arg1 53 | */ 54 | public ShellException(String arg0, Throwable arg1) { 55 | super(arg0, arg1); 56 | } 57 | 58 | /** 59 | * Instantiates a new shell exception. 60 | * 61 | * @param arg0 62 | * the arg0 63 | */ 64 | public ShellException(Throwable arg0) { 65 | super(arg0); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/exception/XMLParserException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.exception; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * The Class XMLParserException. 23 | * 24 | * @author Jeff Butler 25 | */ 26 | public class XMLParserException extends Exception { 27 | 28 | /** The Constant serialVersionUID. */ 29 | private static final long serialVersionUID = 5172525430401340573L; 30 | 31 | /** The errors. */ 32 | private List errors; 33 | 34 | /** 35 | * Instantiates a new XML parser exception. 36 | * 37 | * @param errors 38 | * the errors 39 | */ 40 | public XMLParserException(List errors) { 41 | super(); 42 | this.errors = errors; 43 | } 44 | 45 | /** 46 | * Instantiates a new XML parser exception. 47 | * 48 | * @param error 49 | * the error 50 | */ 51 | public XMLParserException(String error) { 52 | super(error); 53 | this.errors = new ArrayList(); 54 | errors.add(error); 55 | } 56 | 57 | /** 58 | * Gets the errors. 59 | * 60 | * @return the errors 61 | */ 62 | public List getErrors() { 63 | return errors; 64 | } 65 | 66 | /* (non-Javadoc) 67 | * @see java.lang.Throwable#getMessage() 68 | */ 69 | @Override 70 | public String getMessage() { 71 | if (errors != null && errors.size() > 0) { 72 | return errors.get(0); 73 | } 74 | 75 | return super.getMessage(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/internal/NullProgressCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/internal/db/ActualTableName.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.db; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.composeFullyQualifiedTableName; 19 | 20 | /** 21 | * This class holds the actual catalog, schema, and table name returned from the 22 | * database introspection. 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class ActualTableName { 28 | 29 | private String tableName; 30 | private String catalog; 31 | private String schema; 32 | private String fullName; 33 | 34 | public ActualTableName(String catalog, String schema, String tableName) { 35 | this.catalog = catalog; 36 | this.schema = schema; 37 | this.tableName = tableName; 38 | fullName = composeFullyQualifiedTableName(catalog, 39 | schema, tableName, '.'); 40 | } 41 | 42 | public String getCatalog() { 43 | return catalog; 44 | } 45 | 46 | public String getSchema() { 47 | return schema; 48 | } 49 | 50 | public String getTableName() { 51 | return tableName; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object obj) { 56 | if (obj == null || !(obj instanceof ActualTableName)) { 57 | return false; 58 | } 59 | 60 | return obj.toString().equals(this.toString()); 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return fullName.hashCode(); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return fullName; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/internal/rules/FlatModelRules.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.rules; 17 | 18 | import org.mybatis.generator.api.IntrospectedTable; 19 | 20 | /** 21 | * This class encapsulates all the code generation rules for a table using the 22 | * flat model. 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class FlatModelRules extends BaseRules { 28 | 29 | /** 30 | * Instantiates a new flat model rules. 31 | * 32 | * @param introspectedTable 33 | * the introspected table 34 | */ 35 | public FlatModelRules(IntrospectedTable introspectedTable) { 36 | super(introspectedTable); 37 | } 38 | 39 | /** 40 | * We never generate a primary key in the flat model. 41 | * 42 | * @return true if the primary key should be generated 43 | */ 44 | public boolean generatePrimaryKeyClass() { 45 | return false; 46 | } 47 | 48 | /** 49 | * We always generate a base record in the flat model. 50 | * 51 | * @return true if the class should be generated 52 | */ 53 | public boolean generateBaseRecordClass() { 54 | return true; 55 | } 56 | 57 | /** 58 | * We never generate a record with BLOBs class in the flat model. 59 | * 60 | * @return true if the record with BLOBs class should be generated 61 | */ 62 | public boolean generateRecordWithBLOBsClass() { 63 | return false; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/internal/rules/HierarchicalModelRules.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.rules; 17 | 18 | import org.mybatis.generator.api.IntrospectedTable; 19 | 20 | /** 21 | * This class encapsulates all the code generation rules for a table using the 22 | * hierarchical model. 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class HierarchicalModelRules extends BaseRules { 28 | 29 | /** 30 | * Instantiates a new hierarchical model rules. 31 | * 32 | * @param introspectedTable 33 | * the introspected table 34 | */ 35 | public HierarchicalModelRules(IntrospectedTable introspectedTable) { 36 | super(introspectedTable); 37 | } 38 | 39 | /** 40 | * Implements the rule for determining whether to generate a primary key 41 | * class. If the physical table has a primary key, then we generate the 42 | * class. 43 | * 44 | * @return true if the primary key should be generated 45 | */ 46 | public boolean generatePrimaryKeyClass() { 47 | return introspectedTable.hasPrimaryKeyColumns(); 48 | } 49 | 50 | /** 51 | * Implements the rule for generating a base record. If the table has fields 52 | * that are not in the primary key, and non-BLOB fields, then generate the 53 | * class. 54 | * 55 | * @return true if the class should be generated 56 | */ 57 | public boolean generateBaseRecordClass() { 58 | return introspectedTable.hasBaseColumns(); 59 | } 60 | 61 | /** 62 | * Implements the rule for generating a record with BLOBs. A record with 63 | * BLOBs is generated if the table contains any BLOB fields. 64 | * 65 | * @return true if the record with BLOBs class should be generated 66 | */ 67 | public boolean generateRecordWithBLOBsClass() { 68 | return introspectedTable.hasBLOBColumns(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/internal/util/ClassloaderUtility.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.util; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | import java.io.File; 21 | import java.net.MalformedURLException; 22 | import java.net.URL; 23 | import java.net.URLClassLoader; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * This class holds methods useful for constructing custom classloaders. 29 | * 30 | * @author Jeff Butler 31 | * 32 | */ 33 | public class ClassloaderUtility { 34 | 35 | /** 36 | * Utility Class - No Instances 37 | */ 38 | private ClassloaderUtility() { 39 | } 40 | 41 | public static ClassLoader getCustomClassloader(List entries) { 42 | List urls = new ArrayList(); 43 | File file; 44 | 45 | if (entries != null) { 46 | for (String classPathEntry : entries) { 47 | file = new File(classPathEntry); 48 | if (!file.exists()) { 49 | throw new RuntimeException(getString( 50 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 51 | } 52 | 53 | try { 54 | urls.add(file.toURI().toURL()); 55 | } catch (MalformedURLException e) { 56 | // this shouldn't happen, but just in case... 57 | throw new RuntimeException(getString( 58 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 59 | } 60 | } 61 | } 62 | 63 | ClassLoader parent = Thread.currentThread().getContextClassLoader(); 64 | 65 | URLClassLoader ucl = new URLClassLoader(urls.toArray(new URL[urls 66 | .size()]), parent); 67 | 68 | return ucl; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/internal/util/messages/Messages.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/logging/AbstractLogFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.logging; 17 | 18 | /** 19 | * Defines the interface for creating Log implementations. 20 | * 21 | * @author Jeff Butler 22 | * 23 | */ 24 | public interface AbstractLogFactory { 25 | Log getLog(Class aClass); 26 | } 27 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/logging/JdkLoggingImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/logging/Log.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | void debug(String s); 31 | 32 | void warn(String s); 33 | } 34 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/logging/Log4jImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | -------------------------------------------------------------------------------- /java-generator-core/src/main/java/org/mybatis/generator/plugins/VirtualPrimaryKeyPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.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 | * <property name="virtualKeyColumns" value="ID1,ID2"> 33 | * 34 | * @author Jeff Butler 35 | * 36 | */ 37 | public class VirtualPrimaryKeyPlugin extends PluginAdapter { 38 | 39 | /* (non-Javadoc) 40 | * @see org.mybatis.generator.api.Plugin#validate(java.util.List) 41 | */ 42 | public boolean validate(List warnings) { 43 | return true; 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see org.mybatis.generator.api.PluginAdapter#initialized(org.mybatis.generator.api.IntrospectedTable) 48 | */ 49 | @Override 50 | public void initialized(IntrospectedTable introspectedTable) { 51 | String virtualKey = introspectedTable.getTableConfiguration() 52 | .getProperty("virtualKeyColumns"); //$NON-NLS-1$ 53 | 54 | if (virtualKey != null) { 55 | StringTokenizer st = new StringTokenizer(virtualKey, ", ", false); //$NON-NLS-1$ 56 | while (st.hasMoreTokens()) { 57 | String column = st.nextToken(); 58 | introspectedTable.addPrimaryKeyColumn(column); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /java-generator-core/src/main/resources/template/DomainTemplate: -------------------------------------------------------------------------------- 1 | package ${domainPackage}; 2 | 3 | import ${boPackage}; 4 | 5 | /** 6 | * @author 7 | * @version 0.0.1 8 | * @date ${generatedDate} 9 | * @time ${generatedTime} 10 | * @function 功能: 11 | * @describe 版本描述: 12 | * @modifyLog 修改日志: 13 | * 14 | * @mbg.generated do_not_delete_during_merge 15 | */ 16 | public interface ${domainInterface} { 17 | /** 18 | * 通过ID获取对象 19 | * @param id 账号ID 20 | * @return ${boType} 21 | * 22 | * @mbg.generated 23 | */ 24 | ${boType} get(Integer id); 25 | } 26 | -------------------------------------------------------------------------------- /java-generator-core/src/main/resources/template/NativeDomainTemplate: -------------------------------------------------------------------------------- 1 | package ${nativeDomainPackage}; 2 | 3 | import ${boPackage}; 4 | import ${modelPackage}; 5 | import ${modelServicePackage}; 6 | import com.btjf.common.utils.BeanUtil; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | import javax.annotation.Resource; 10 | 11 | 12 | /** 13 | * @author 14 | * @version 0.0.1 15 | * @date ${generatedDate} 16 | * @time ${generatedTime} 17 | * @function 功能: 18 | * @describe 版本描述: 19 | * @modifyLog 修改日志: 20 | * 21 | * @mbg.generated do_not_delete_during_merge 22 | */ 23 | @Service("${domainName}") 24 | @Transactional(rollbackFor = Exception.class) 25 | public class ${nativeDomainClazz} implements ${domainInterface}{ 26 | @Resource 27 | private ${modelServiceClazz} ${modelServiceName}; 28 | 29 | /** 30 | * 通过ID获取对象 31 | * @param id 账号ID 32 | * @return ${boType} 33 | * 34 | * @mbg.generated 35 | */ 36 | @Override 37 | public ${boType} get(Integer id){ 38 | if (id == null) return null; 39 | ${modelClazz} modelName = this.${modelServiceName}.getNotDeleteByPrimaryKey(id); 40 | return BeanUtil.convert(modelName, ${boType}.class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /java-generator-core/src/main/resources/template/ServiceTemplate: -------------------------------------------------------------------------------- 1 | package ${templatePackage}; 2 | 3 | import java.util.List; 4 | import javax.annotation.Resource; 5 | import org.springframework.stereotype.Service; 6 | import ${modelPackage}; 7 | import ${mapperPackage}; 8 | <#if columnsHasBLOB == true> 9 | import ${modelPackage}WithBLOBs; 10 | 11 | 12 | 13 | /** 14 | * @author 15 | * @version 0.0.1 16 | * @date ${generatedDate} 17 | * @time ${generatedTime} 18 | * @function 功能: 19 | * @describe 版本描述: 20 | * @modifyLog 修改日志: 21 | * 22 | * @mbg.generated do_not_delete_during_merge 23 | */ 24 | @Service 25 | public class ${className} { 26 | @Resource 27 | private ${mapperType} ${mapperName}; 28 | 29 | /** 30 | * 保存 ${modelClazz} 31 | * @param modelName 对象 32 | * 33 | * @mbg.generated 34 | */ 35 | <#if columnsHasBLOB == true> 36 | public void save(${modelClazz}WithBLOBs modelName){ 37 | <#else> 38 | public void save(${modelClazz} modelName){ 39 | 40 | this.${mapperName}.insertSelective(modelName); 41 | } 42 | 43 | /** 44 | * 根据主键删除 45 | * @param primaryKey 主键 46 | * 47 | * @mbg.generated 48 | */ 49 | public void deleteByPrimaryKey(Integer primaryKey){ 50 | this.${mapperName}.deleteByPrimaryKey(primaryKey); 51 | } 52 | 53 | /** 54 | * 通过主键获取对象 55 | * @param primaryKey 主键 56 | * @return ${modelClazz} 57 | * 58 | * @mbg.generated 59 | */ 60 | public ${modelClazz} getByPrimaryKey(Integer primaryKey){ 61 | return this.${mapperName}.selectByPrimaryKey(primaryKey); 62 | } 63 | 64 | /** 65 | * 通过主键获取没有被删除的对象 66 | * @param primaryKey 主键 67 | * @return ${modelClazz} 68 | * 69 | * @mbg.generated 70 | */ 71 | public ${modelClazz} getNotDeleteByPrimaryKey(Integer primaryKey){ 72 | return this.${mapperName}.selectNotDeleteByPrimaryKey(primaryKey); 73 | } 74 | 75 | /** 76 | * 查询所有 77 | * @return List<${modelClazz}> 78 | * 79 | * @mbg.generated 80 | */ 81 | public List<${modelClazz}> findAll(){ 82 | return this.${mapperName}.selectAll(); 83 | } 84 | 85 | /** 86 | * 查询所有没有被删除的对象 87 | * @return List<${modelClazz}> 88 | * 89 | * @mbg.generated 90 | */ 91 | public List<${modelClazz}> findNotDeleteAll(){ 92 | return this.${mapperName}.selectNotDeleteAll(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /java-generator-core/src/site/resources/mbgstyle.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* custom stylesheet - used to override any maven style, and as a placeholder 17 | * for the eclipse help stylesheet 18 | */ 19 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/configreference/except.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | The <except> Element 24 | 25 | 26 | 27 |

The <except> Element

28 |

The <except> element is used to specify an exception to a set of columns 29 | that are ignored by a regular expression in a 30 | <ignoreColumnsByRegex> element. 31 | This allows you to specify a very general 32 | regular expression to ignore a large set of columns, then add columns back into 33 | the set of columns used for code generation.

34 |

For example, if you specify a regular 35 | expression like ".*" then MBG will ignore every column in a table. 36 | But if you add exceptions, you can add a few columns back. 37 | This element is an optional child 38 | element of the <ignoreColumnsByRegex> element.

39 | 40 |

Required Attributes

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
AttributeDescription
columnThe column name of the exception column.
51 | 52 |

Optional Attributes

53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 63 | 64 |
AttributeDescription
delimitedColumnNameIf true then MBG will perform a case-sensitive exact 61 | match when matching against returned columns from the database. If 62 | false (default) then the name is considered case-insensitive.
65 | 66 |

Child Elements

67 |

None

68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/configreference/generatorConfiguration.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | The <generatorConfiguration> Element 24 | 25 | 26 | 27 |

The <generatorConfiguration> Element

28 |

The <generatorConfiguration> element is the root element of a 29 | MyBatis Generator configuration file. The file should contain the following DOCTYPE: 30 |

31 |
32 | <!DOCTYPE generatorConfiguration PUBLIC
33 |   "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
34 |   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
35 | 
36 | 37 |

Required Attributes

38 |

None

39 | 40 |

Optional Attributes

41 |

None

42 | 43 |

Child Elements

44 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/configreference/ignoreColumn.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | The <ignoreColumn> Element 24 | 25 | 26 | 27 |

The <ignoreColumn> Element

28 |

The <ignoreColumn> element is used to tell MyBatis Generator (MBG) to ignore a column 29 | in an introspected table. No generated SQL will refer to the column, and no 30 | property will be generated for the column in the model objects. 31 | This element is an optional child 32 | element of the <table> element.

33 | 34 |

Required Attributes

35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
AttributeDescription
columnThe column name of the ignored column.
45 | 46 |

Optional Attributes

47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 57 | 58 |
AttributeDescription
delimitedColumnNameIf true then MBG will perform a case-sensitive exact 55 | match when matching against returned columns from the database. If 56 | false (default) then the name is considered case-insensitive.
59 | 60 |

Child Elements

61 |

None

62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/configreference/ignoreColumnsByRegex.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | The <ignoreColumnsByRegex> Element 24 | 25 | 26 | 27 |

The <ignoreColumnsByRegex> Element

28 |

The <ignoreColumnsByRegex> element is used to tell MyBatis Generator (MBG) to ignore a 29 | set of columns in an introspected table - the set is determined by matching against a regular 30 | expression specified in this element. No generated SQL will refer to the ignored columns, and no 31 | properties will be generated for the ignored columns in the model objects. 32 | This element is an optional child 33 | element of the <table> element.

34 |

You can specify exceptions to the pattern through use of an 35 | <except> element.

36 |

Required Attributes

37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 |
AttributeDescription
patternThe regular expression used to match column names. The regular expression 45 | engine is the standard java.util.regex.Pattern engine.
48 | 49 |

Optional Attributes

50 |

None

51 | 52 |

Child Elements

53 | 56 | 57 |

Example

58 |

This example tells MyBatis to ignore every column in the Foo table that begins with 59 | the characters "col" (case-insensitive) except for "col01" and "col13".

60 |
61 |     <table tableName="Foo">
62 |       <ignoreColumnsByRegex pattern="(?i)col.*">
63 |         <except column="col01"/>
64 |         <except column="col13"/>
65 |       </ignoreColumnsByRegex>
66 |     </table>
67 | 
68 | 69 | 70 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/configreference/plugin.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | The <plugin> Element 24 | 25 | 26 | 27 |

The <plugin> Element

28 |

The <plugin> element is used to define a plugin. Plugins can be used 29 | to extend or modify the code generated by MyBatis Generator (MBG). This element is a child element of the 30 | <context> element. Any number of 31 | plugins may be specified in a context. The plugins will be called in 32 | the order that are listed in the configuration.

33 | 34 |

For more information about implementing plugins, see the 35 | Implementing Plugins reference 36 | page.

37 | 38 |

For more information about plugins supplied with MyBatis Generator, see the 39 | Supplied Plugins reference 40 | page.

41 | 42 |

Required Attributes

43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 57 | 58 |
AttributeDescription
typeThe fully qualified name of the class that implements the plugin. 51 | The class must implement the interface 52 | org.mybatis.generator.api.Plugin, 53 | and must have a public default constructor. Note that it is far 54 | easier to extend the adapter class 55 | org.mybatis.generator.api.PluginAdapter 56 | than to implement the entire interface.
59 | 60 |

Optional Attributes

61 |

None

62 | 63 |

Child Elements

64 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/configreference/property.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | The <property> Element 24 | 25 | 26 | 27 |

The <property> Element

28 |

The <property> element is used to specify properties for many of the 29 | other elements. The documentation page for each element that supports the 30 | property element lists the different values that are valid. This element 31 | can also be used to pass properties to any custom code generators that 32 | you implement.

33 | 34 |

Required Attributes

35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
AttributeDescription
nameThe name of the property (case sensitive).
valueThe value of the property (typically case insensitive).
49 | 50 |

Optional Attributes

51 |

None

52 | 53 |

Child Elements

54 |

None

55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/generatedobjects/results.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | Using the Generated Objects 24 | 25 | 26 | 27 |

Using the Generated Objects

28 |

MyBatis Generator (MBG) generates these types of objects:

29 |
    30 |
  1. Java Model Objects (always)
  2. 31 |
  3. SQL Map Files (always for iBATIS, usually for MyBatis)
  4. 32 |
  5. Java Client Objects (optional)
  6. 33 |
  7. A class for use in the xxxByExample methods. See the following pages for 34 | information about that class: 35 | 39 |
  8. 40 |
41 | 42 |

The individual pages describe these objects, and their usage.

43 | 44 | 45 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/license.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | Licensing Information 24 | 25 | 26 | 27 |

Licensing Information

28 |

Licensed under the Apache License, Version 2.0 (the "License"); 29 | you may not use this product except in compliance with the License. 30 | You may obtain a copy of the License at 31 |

32 |

33 | http://www.apache.org/licenses/LICENSE-2.0

34 |

35 | Unless required by applicable law or agreed to in writing, software 36 | distributed under the License is distributed on an "AS IS" BASIS, 37 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 | See the License for the specific language governing permissions and 39 | limitations under the License. 40 |

41 | 42 |

This product includes software developed by the Apache Software 43 | Foundation (http://www.apache.org/).

44 | 45 |

This product includes the EqualsUtil and HashCodeUtil classes 46 | from http://www.javapractices.com.

47 | 48 | 49 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/reference/intro.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | Reference Information 24 | 25 | 26 | 27 |

Reference Information

28 |

This section collects useful information related to technical topics 29 | with MyBatis Generator.

30 | 31 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/usage/db2.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | DB2 Usage Notes 24 | 25 | 26 | 27 |

DB2 Usage Notes

28 |

LONG VARCHAR Fields

29 |

By default MyBatis Generator will map LONG VARCHAR fields to the java.lang.String data type, 30 | and will mark these fields as jdbcType="LONGVARCHAR". This 31 | mapping will cause errors when retrieving data from DB2. DB2 LONG VARCHAR fields should be mapped 32 | to the java.lang.String data type with jdbcType="VARCHAR". To overcome 33 | this problem, use a <columnOverride> as follows:

34 |
35 |   <table schema="DB2ADMIN" tableName="ALLTYPES" >
36 |     <columnOverride column="LONG_VARCHAR_FIELD" javaType="java.lang.String" jdbcType="VARCHAR" />
37 |   </table>
38 | 
39 | 40 | 41 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/usage/intro.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | Usage Notes 24 | 25 | 26 | 27 |

Usage Notes

28 |

This section collects usage information for different databases.

29 | 30 | 36 |

Please let us know about any quirks you discover for the database you are using - we will 37 | be happy to add the information 38 | to this section for future reference.

39 | 40 | 41 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/usage/mysql.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | MySql Usage Notes 24 | 25 | 26 | 27 |

MySql Usage Notes

28 |

Unsigned Fields

29 |

MySql supports both signed, and unsigned, numeric fields. These are not JDBC types, so MyBatis 30 | generator cannot automatically account for these types of fields. The Java data types are always signed. 31 | This can 32 | lead to a loss of precision when using unsigned fields. The solution is to provide a 33 | <columnOverride> for any unsigned numeric field in MySql. Here is an example 34 | of how to deal with an unsigned bigint field in MySql:

35 |
36 |   <table tableName="ALLTYPES" >
37 |     <columnOverride column="UNSIGNED_BIGINT_FIELD" javaType="java.lang.Object" jdbcType="LONG" />
38 |   </table>
39 | 
40 |

You will have to cast the returned value to the appropriate type yourself (in this case, 41 | java.math.BigInteger).

42 |

Catalogs and Schema

43 |

MySql does not properly support SQL catalogs and schema. If you run the create schema 44 | command in Mysql, it actually creates a database - and the JDBC driver reports it back as a catalog. 45 | But MySql syntax does not support the standard catalog..table SQL syntax.

46 |

For this reason, it is best to not specify either catalog or schema in generator configurations. 47 | Just specify table names and specify the database in the JDBC URL.

48 | 49 | 50 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/usage/oracle.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | Oracle Usage Notes 24 | 25 | 26 | 27 |

Oracle Usage Notes

28 |

Public Synonyms

29 |

If you want to generate objects for a table that has a public synonym, you 30 | should actually generate the objects against the real table - and then change the 31 | table name at runtime. MyBatis Generator supports this automatically.

32 |

For example, assume there is a public alias "FRED" that points to the 33 | table "HR.EMPLOYEES". The following table configuration will generate the objects 34 | based on HR.EMPLOYEES, but the runtime SQL will only refer to FRED:

35 |
36 |   <table schema="HR" tableName="EMPLOYEES">
37 |     <property name="ignoreQualifiersAtRuntime" value="true" />
38 |     <property name="runtimeTableName" value="FRED" />
39 |   </table>
40 | 
41 |

Oracle LONG Datatype

42 |

The Oracle JDBC driver will report that a LONG column is JDBC type LONGVARCHAR. 43 | MyBatis will map LONGVARCHAR to CLOB which is unsupported by the Oracle driver. 44 | So, when using LONG datatype, you should do a column override in the generator 45 | to map it to VARCHAR JDBC type.

46 | 47 | 48 | -------------------------------------------------------------------------------- /java-generator-core/src/site/xhtml/usage/postgresql.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | PostgreSQL Usage Notes 24 | 25 | 26 | 27 |

PostgreSQL Usage Notes

28 |

Case Sensitivity

29 |

PostgreSQL is case sensitive with regards to all database identifiers 30 | (table names, schema names, column names, etc.) In addition, PostgreSQL 31 | has a distinct preference for all identifiers being in all lower case letters. 32 | If you use all lower case identifiers for PostgreSQL, then MyBatis Generator will find tables 33 | and write correct SQL with no additional consideration. If you used mixed cased, 34 | or upper case, identifiers you will 35 | need to configure MyBatis Generator appropriately:

36 |
    37 |
  • Use the delimitIdentifiers option if your table or schema 38 | is mixed case or all upper case.
  • 39 |
  • For each mixed case or upper case column you could specify a 40 | <columnOverride> element to specifically delimit the column, 41 | or you could specify the delimitAllColumns attribute 42 | to delimit all column names.
  • 43 |
44 |

Examples:

45 |
46 |   <table schema="HR" tableName="Employees"
47 |       delimitIdentifiers="true" delimitAllColumns="true"/>
48 | 
49 |

Or...

50 |
51 |   <table schema="HR" tableName="Employees" delimitIdentifiers="true" >
52 |     <columnOverride column="EmployeeId" delimitedColumnName="true" />
53 |     <columnOverride column="EmployeeName" delimitedColumnName="true" />
54 |   </table>
55 | 
56 | 57 | 58 | -------------------------------------------------------------------------------- /java-generator-core/src/test/java/org/mybatis/generator/api/GeneratedJavaFileTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | import static org.junit.Assert.*; 19 | import org.junit.Test; 20 | import org.mybatis.generator.api.dom.DefaultJavaFormatter; 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | 24 | public class GeneratedJavaFileTest { 25 | 26 | @Test 27 | public void testReqularInterface() { 28 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType("org.mybatis.test.TestInterface"); 29 | Interface ifc = new Interface(fqjt); 30 | JavaFormatter jf = new DefaultJavaFormatter(); 31 | GeneratedJavaFile gjf = new GeneratedJavaFile(ifc, "src", jf); 32 | 33 | assertEquals("TestInterface.java", gjf.getFileName()); 34 | assertEquals("org.mybatis.test", gjf.getTargetPackage()); 35 | } 36 | 37 | @Test 38 | public void testGenericInterface() { 39 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType("org.mybatis.test.TestInterface"); 40 | fqjt.addTypeArgument(new FullyQualifiedJavaType("T")); 41 | Interface ifc = new Interface(fqjt); 42 | JavaFormatter jf = new DefaultJavaFormatter(); 43 | GeneratedJavaFile gjf = new GeneratedJavaFile(ifc, "src", jf); 44 | 45 | assertEquals("TestInterface.java", gjf.getFileName()); 46 | assertEquals("org.mybatis.test", gjf.getTargetPackage()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /java-generator-core/src/test/java/org/mybatis/generator/internal/util/StringUtilityTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.util; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import org.junit.Test; 21 | 22 | public class StringUtilityTest { 23 | 24 | @Test 25 | public void testNoCatalog() { 26 | String answer = StringUtility.composeFullyQualifiedTableName(null, "schema", "table", '.'); 27 | assertEquals("schema.table", answer); 28 | } 29 | 30 | @Test 31 | public void testNoSchema() { 32 | String answer = StringUtility.composeFullyQualifiedTableName("catalog", null, "table", '.'); 33 | assertEquals("catalog..table", answer); 34 | } 35 | 36 | @Test 37 | public void testAllPresent() { 38 | String answer = StringUtility.composeFullyQualifiedTableName("catalog", "schema", "table", '.'); 39 | assertEquals("catalog.schema.table", answer); 40 | } 41 | 42 | @Test 43 | public void testTableOnly() { 44 | String answer = StringUtility.composeFullyQualifiedTableName(null, null, "table", '.'); 45 | assertEquals("table", answer); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java-generator-core/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2006-2016 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # log4j.properties for 18 | 19 | # Set root category priority to ERROR and its only appender to LOGFILE. 20 | log4j.rootCategory=ERROR, CONSOLE 21 | 22 | #Spring Framework 23 | #log4j.logger.org.springframework=DEBUG 24 | #log4j.logger.org.springframework.orm=DEBUG 25 | #log4j.logger.org.springframework.transaction=DEBUG 26 | 27 | # CONSOLE is set to be a ConsoleAppender using a PatternLayout. 28 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 29 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 30 | log4j.appender.CONSOLE.layout.ConversionPattern=%-d{HH:mm:ss} %-5p %60.60c %-25.25M %m%n 31 | -------------------------------------------------------------------------------- /java-generator-core/src/test/resources/scripts/database.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2006-2016 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | database.url=jdbc:hsqldb:mem:aname 18 | -------------------------------------------------------------------------------- /java-generator-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.btjf.generator 7 | java-generator 8 | 1.0-SNAPSHOT 9 | 10 | 11 | java-generator-maven-plugin 12 | maven-plugin 13 | Java Generator Maven Plugin 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-plugin-plugin 20 | 21 | 22 | default-descriptor 23 | process-classes 24 | 25 | 26 | help-goal 27 | 28 | helpmojo 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.apache.maven 39 | maven-core 40 | 41 | 42 | org.apache.maven 43 | maven-plugin-api 44 | 45 | 46 | org.apache.maven.plugin-tools 47 | maven-plugin-annotations 48 | 49 | 50 | com.btjf.generator 51 | java-generator-core 52 | ${project.version} 53 | 54 | 55 | 56 | Maven plugin for Java Generator. 57 | 58 | -------------------------------------------------------------------------------- /java-generator-maven-plugin/src/main/java/org/mybatis/generator/maven/MavenLogFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.maven; 17 | 18 | import org.apache.maven.plugin.Mojo; 19 | import org.mybatis.generator.logging.AbstractLogFactory; 20 | import org.mybatis.generator.logging.Log; 21 | 22 | public class MavenLogFactory implements AbstractLogFactory { 23 | 24 | private final MavenLogImpl logImplementation; 25 | 26 | MavenLogFactory(Mojo mojo) { 27 | logImplementation = new MavenLogImpl(mojo.getLog()); 28 | } 29 | 30 | public Log getLog(Class aClass) { 31 | return logImplementation; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-generator-maven-plugin/src/main/java/org/mybatis/generator/maven/MavenLogImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.maven; 17 | 18 | import org.apache.maven.plugin.logging.Log; 19 | 20 | public class MavenLogImpl implements org.mybatis.generator.logging.Log { 21 | private final Log mavenLog; 22 | 23 | MavenLogImpl(Log log) { 24 | mavenLog = log; 25 | } 26 | 27 | public boolean isDebugEnabled() { 28 | return mavenLog.isDebugEnabled(); 29 | } 30 | 31 | public void error(String s, Throwable e) { 32 | mavenLog.error(s, e); 33 | } 34 | 35 | public void error(String s) { 36 | mavenLog.error(s); 37 | } 38 | 39 | public void debug(String s) { 40 | mavenLog.debug(s); 41 | } 42 | 43 | public void warn(String s) { 44 | mavenLog.warn(s); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /java-generator-maven-plugin/src/main/java/org/mybatis/generator/maven/MavenProgressCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.maven; 17 | 18 | import org.apache.maven.plugin.logging.Log; 19 | import org.mybatis.generator.internal.NullProgressCallback; 20 | 21 | /** 22 | * This callback logs progress messages with the Maven logger 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class MavenProgressCallback extends NullProgressCallback { 28 | 29 | private Log log; 30 | private boolean verbose; 31 | 32 | /** 33 | * 34 | */ 35 | public MavenProgressCallback(Log log, boolean verbose) { 36 | super(); 37 | this.log = log; 38 | this.verbose = verbose; 39 | } 40 | 41 | @Override 42 | public void startTask(String subTaskName) { 43 | if (verbose) { 44 | log.info(subTaskName); 45 | } 46 | } 47 | } 48 | --------------------------------------------------------------------------------