├── .gitignore ├── .travis.yml ├── LICENSE ├── NOTICE ├── README ├── mybatis-generator-core ├── LICENSE ├── NOTICE ├── README.txt ├── doc │ ├── ReleaseNotes.txt │ ├── releasing.txt │ └── todo.txt ├── pom.xml └── src │ ├── main │ ├── assembly │ │ └── src.xml │ ├── java │ │ └── org │ │ │ └── mybatis │ │ │ └── generator │ │ │ ├── ant │ │ │ ├── AntProgressCallback.java │ │ │ └── GeneratorAntTask.java │ │ │ ├── api │ │ │ ├── CommentGenerator.java │ │ │ ├── DAOMethodNameCalculator.java │ │ │ ├── FullyQualifiedTable.java │ │ │ ├── GeneratedFile.java │ │ │ ├── GeneratedJavaFile.java │ │ │ ├── GeneratedXmlFile.java │ │ │ ├── IntrospectedColumn.java │ │ │ ├── IntrospectedTable.java │ │ │ ├── JavaFormatter.java │ │ │ ├── JavaTypeResolver.java │ │ │ ├── MyBatisGenerator.java │ │ │ ├── Plugin.java │ │ │ ├── PluginAdapter.java │ │ │ ├── ProgressCallback.java │ │ │ ├── ShellCallback.java │ │ │ ├── ShellRunner.java │ │ │ ├── VerboseProgressCallback.java │ │ │ ├── XmlFormatter.java │ │ │ ├── dom │ │ │ │ ├── DefaultJavaFormatter.java │ │ │ │ ├── DefaultXmlFormatter.java │ │ │ │ ├── OutputUtilities.java │ │ │ │ ├── java │ │ │ │ │ ├── CompilationUnit.java │ │ │ │ │ ├── Field.java │ │ │ │ │ ├── FullyQualifiedJavaType.java │ │ │ │ │ ├── InitializationBlock.java │ │ │ │ │ ├── InnerClass.java │ │ │ │ │ ├── InnerEnum.java │ │ │ │ │ ├── Interface.java │ │ │ │ │ ├── JavaElement.java │ │ │ │ │ ├── JavaVisibility.java │ │ │ │ │ ├── Method.java │ │ │ │ │ ├── Parameter.java │ │ │ │ │ ├── PrimitiveTypeWrapper.java │ │ │ │ │ ├── TopLevelClass.java │ │ │ │ │ └── TopLevelEnumeration.java │ │ │ │ └── xml │ │ │ │ │ ├── Attribute.java │ │ │ │ │ ├── Document.java │ │ │ │ │ ├── Element.java │ │ │ │ │ ├── TextElement.java │ │ │ │ │ └── XmlElement.java │ │ │ └── package.html │ │ │ ├── codegen │ │ │ ├── AbstractGenerator.java │ │ │ ├── AbstractJavaClientGenerator.java │ │ │ ├── AbstractJavaGenerator.java │ │ │ ├── AbstractXmlGenerator.java │ │ │ ├── RootClassInfo.java │ │ │ ├── XmlConstants.java │ │ │ ├── ibatis2 │ │ │ │ ├── Ibatis2FormattingUtilities.java │ │ │ │ ├── IntrospectedTableIbatis2Java2Impl.java │ │ │ │ ├── IntrospectedTableIbatis2Java5Impl.java │ │ │ │ ├── dao │ │ │ │ │ ├── DAOGenerator.java │ │ │ │ │ ├── elements │ │ │ │ │ │ ├── AbstractDAOElementGenerator.java │ │ │ │ │ │ ├── CountByExampleMethodGenerator.java │ │ │ │ │ │ ├── DeleteByExampleMethodGenerator.java │ │ │ │ │ │ ├── DeleteByPrimaryKeyMethodGenerator.java │ │ │ │ │ │ ├── InsertMethodGenerator.java │ │ │ │ │ │ ├── InsertSelectiveMethodGenerator.java │ │ │ │ │ │ ├── SelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ │ ├── SelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ │ ├── SelectByPrimaryKeyMethodGenerator.java │ │ │ │ │ │ ├── UpdateByExampleParmsInnerclassGenerator.java │ │ │ │ │ │ ├── UpdateByExampleSelectiveMethodGenerator.java │ │ │ │ │ │ ├── UpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ │ ├── UpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ │ ├── UpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ │ │ └── templates │ │ │ │ │ │ ├── AbstractDAOTemplate.java │ │ │ │ │ │ ├── GenericCIDAOTemplate.java │ │ │ │ │ │ ├── GenericSIDAOTemplate.java │ │ │ │ │ │ ├── IbatisDAOTemplate.java │ │ │ │ │ │ └── SpringDAOTemplate.java │ │ │ │ ├── model │ │ │ │ │ ├── BaseRecordGenerator.java │ │ │ │ │ ├── ExampleGenerator.java │ │ │ │ │ ├── PrimaryKeyGenerator.java │ │ │ │ │ └── RecordWithBLOBsGenerator.java │ │ │ │ └── sqlmap │ │ │ │ │ ├── SqlMapGenerator.java │ │ │ │ │ └── elements │ │ │ │ │ ├── AbstractXmlElementGenerator.java │ │ │ │ │ ├── BaseColumnListElementGenerator.java │ │ │ │ │ ├── BlobColumnListElementGenerator.java │ │ │ │ │ ├── CountByExampleElementGenerator.java │ │ │ │ │ ├── DeleteByExampleElementGenerator.java │ │ │ │ │ ├── DeleteByPrimaryKeyElementGenerator.java │ │ │ │ │ ├── ExampleWhereClauseElementGenerator.java │ │ │ │ │ ├── InsertElementGenerator.java │ │ │ │ │ ├── InsertSelectiveElementGenerator.java │ │ │ │ │ ├── ResultMapWithBLOBsElementGenerator.java │ │ │ │ │ ├── ResultMapWithoutBLOBsElementGenerator.java │ │ │ │ │ ├── SelectByExampleWithBLOBsElementGenerator.java │ │ │ │ │ ├── SelectByExampleWithoutBLOBsElementGenerator.java │ │ │ │ │ ├── SelectByPrimaryKeyElementGenerator.java │ │ │ │ │ ├── UpdateByExampleSelectiveElementGenerator.java │ │ │ │ │ ├── UpdateByExampleWithBLOBsElementGenerator.java │ │ │ │ │ ├── UpdateByExampleWithoutBLOBsElementGenerator.java │ │ │ │ │ ├── UpdateByPrimaryKeySelectiveElementGenerator.java │ │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsElementGenerator.java │ │ │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java │ │ │ └── mybatis3 │ │ │ │ ├── IntrospectedTableMyBatis3Impl.java │ │ │ │ ├── IntrospectedTableMyBatis3SimpleImpl.java │ │ │ │ ├── MyBatis3FormattingUtilities.java │ │ │ │ ├── javamapper │ │ │ │ ├── AnnotatedClientGenerator.java │ │ │ │ ├── JavaMapperGenerator.java │ │ │ │ ├── MixedClientGenerator.java │ │ │ │ ├── SimpleAnnotatedClientGenerator.java │ │ │ │ ├── SimpleJavaClientGenerator.java │ │ │ │ ├── SqlProviderGenerator.java │ │ │ │ └── elements │ │ │ │ │ ├── AbstractJavaMapperMethodGenerator.java │ │ │ │ │ ├── CountByExampleMethodGenerator.java │ │ │ │ │ ├── DeleteByExampleMethodGenerator.java │ │ │ │ │ ├── DeleteByPrimaryKeyMethodGenerator.java │ │ │ │ │ ├── InsertMethodGenerator.java │ │ │ │ │ ├── InsertSelectiveMethodGenerator.java │ │ │ │ │ ├── SelectAllMethodGenerator.java │ │ │ │ │ ├── SelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── SelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── SelectByPrimaryKeyMethodGenerator.java │ │ │ │ │ ├── UpdateByExampleSelectiveMethodGenerator.java │ │ │ │ │ ├── UpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── UpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── UpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ │ ├── UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── annotated │ │ │ │ │ ├── AnnotatedCountByExampleMethodGenerator.java │ │ │ │ │ ├── AnnotatedDeleteByExampleMethodGenerator.java │ │ │ │ │ ├── AnnotatedDeleteByPrimaryKeyMethodGenerator.java │ │ │ │ │ ├── AnnotatedInsertMethodGenerator.java │ │ │ │ │ ├── AnnotatedInsertSelectiveMethodGenerator.java │ │ │ │ │ ├── AnnotatedSelectAllMethodGenerator.java │ │ │ │ │ ├── AnnotatedSelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── AnnotatedSelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── AnnotatedSelectByPrimaryKeyMethodGenerator.java │ │ │ │ │ ├── AnnotatedUpdateByExampleSelectiveMethodGenerator.java │ │ │ │ │ ├── AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ │ ├── AnnotatedUpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ │ └── AnnotatedUpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ │ │ └── sqlprovider │ │ │ │ │ ├── AbstractJavaProviderMethodGenerator.java │ │ │ │ │ ├── ProviderApplyWhereMethodGenerator.java │ │ │ │ │ ├── ProviderCountByExampleMethodGenerator.java │ │ │ │ │ ├── ProviderDeleteByExampleMethodGenerator.java │ │ │ │ │ ├── ProviderInsertSelectiveMethodGenerator.java │ │ │ │ │ ├── ProviderSelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── ProviderSelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── ProviderUpdateByExampleSelectiveMethodGenerator.java │ │ │ │ │ ├── ProviderUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ └── ProviderUpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ ├── model │ │ │ │ ├── BaseRecordGenerator.java │ │ │ │ ├── ExampleGenerator.java │ │ │ │ ├── PrimaryKeyGenerator.java │ │ │ │ ├── RecordWithBLOBsGenerator.java │ │ │ │ └── SimpleModelGenerator.java │ │ │ │ └── xmlmapper │ │ │ │ ├── MixedMapperGenerator.java │ │ │ │ ├── SimpleXMLMapperGenerator.java │ │ │ │ ├── XMLMapperGenerator.java │ │ │ │ └── elements │ │ │ │ ├── AbstractXmlElementGenerator.java │ │ │ │ ├── BaseColumnListElementGenerator.java │ │ │ │ ├── BlobColumnListElementGenerator.java │ │ │ │ ├── CountByExampleElementGenerator.java │ │ │ │ ├── DeleteByExampleElementGenerator.java │ │ │ │ ├── DeleteByPrimaryKeyElementGenerator.java │ │ │ │ ├── ExampleWhereClauseElementGenerator.java │ │ │ │ ├── InsertElementGenerator.java │ │ │ │ ├── InsertSelectiveElementGenerator.java │ │ │ │ ├── ResultMapWithBLOBsElementGenerator.java │ │ │ │ ├── ResultMapWithoutBLOBsElementGenerator.java │ │ │ │ ├── SelectByExampleWithBLOBsElementGenerator.java │ │ │ │ ├── SelectByExampleWithoutBLOBsElementGenerator.java │ │ │ │ ├── SelectByPrimaryKeyElementGenerator.java │ │ │ │ ├── SimpleSelectAllElementGenerator.java │ │ │ │ ├── SimpleSelectByPrimaryKeyElementGenerator.java │ │ │ │ ├── UpdateByExampleSelectiveElementGenerator.java │ │ │ │ ├── UpdateByExampleWithBLOBsElementGenerator.java │ │ │ │ ├── UpdateByExampleWithoutBLOBsElementGenerator.java │ │ │ │ ├── UpdateByPrimaryKeySelectiveElementGenerator.java │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsElementGenerator.java │ │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java │ │ │ ├── config │ │ │ ├── ColumnOverride.java │ │ │ ├── ColumnRenamingRule.java │ │ │ ├── CommentGeneratorConfiguration.java │ │ │ ├── Configuration.java │ │ │ ├── Context.java │ │ │ ├── GeneratedKey.java │ │ │ ├── IgnoredColumn.java │ │ │ ├── JDBCConnectionConfiguration.java │ │ │ ├── JavaClientGeneratorConfiguration.java │ │ │ ├── JavaModelGeneratorConfiguration.java │ │ │ ├── JavaTypeResolverConfiguration.java │ │ │ ├── MergeConstants.java │ │ │ ├── ModelType.java │ │ │ ├── PluginConfiguration.java │ │ │ ├── PropertyHolder.java │ │ │ ├── PropertyRegistry.java │ │ │ ├── SqlMapGeneratorConfiguration.java │ │ │ ├── TableConfiguration.java │ │ │ ├── TypedPropertyHolder.java │ │ │ └── xml │ │ │ │ ├── ConfigurationParser.java │ │ │ │ ├── IbatorConfigurationParser.java │ │ │ │ ├── MyBatisGeneratorConfigurationParser.java │ │ │ │ ├── ParserEntityResolver.java │ │ │ │ └── ParserErrorHandler.java │ │ │ ├── exception │ │ │ ├── InvalidConfigurationException.java │ │ │ ├── ShellException.java │ │ │ └── XMLParserException.java │ │ │ ├── internal │ │ │ ├── DefaultCommentGenerator.java │ │ │ ├── DefaultDAOMethodNameCalculator.java │ │ │ ├── DefaultShellCallback.java │ │ │ ├── DomWriter.java │ │ │ ├── ExtendedDAOMethodNameCalculator.java │ │ │ ├── NullProgressCallback.java │ │ │ ├── ObjectFactory.java │ │ │ ├── PluginAggregator.java │ │ │ ├── XmlFileMergerJaxp.java │ │ │ ├── db │ │ │ │ ├── ActualTableName.java │ │ │ │ ├── ConnectionFactory.java │ │ │ │ ├── DatabaseDialects.java │ │ │ │ ├── DatabaseIntrospector.java │ │ │ │ └── SqlReservedWords.java │ │ │ ├── rules │ │ │ │ ├── BaseRules.java │ │ │ │ ├── ConditionalModelRules.java │ │ │ │ ├── FlatModelRules.java │ │ │ │ ├── HierarchicalModelRules.java │ │ │ │ ├── Rules.java │ │ │ │ └── RulesDelegate.java │ │ │ ├── types │ │ │ │ ├── JavaTypeResolverDefaultImpl.java │ │ │ │ └── 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 │ │ │ ├── MapperConfigPlugin.java │ │ │ ├── RenameExampleClassPlugin.java │ │ │ ├── RowBoundsPlugin.java │ │ │ ├── SerializablePlugin.java │ │ │ ├── SqlMapConfigPlugin.java │ │ │ ├── ToStringPlugin.java │ │ │ └── VirtualPrimaryKeyPlugin.java │ └── resources │ │ └── org │ │ └── mybatis │ │ └── generator │ │ ├── config │ │ └── xml │ │ │ ├── ibator-config_1_0.dtd │ │ │ └── mybatis-generator-config_1_0.dtd │ │ └── internal │ │ └── util │ │ └── messages │ │ └── messages.properties │ ├── site │ ├── resources │ │ ├── images │ │ │ └── logo.png │ │ └── mbgstyle.css │ ├── site.xml │ └── xhtml │ │ ├── afterRunning.xhtml │ │ ├── configreference │ │ ├── classPathEntry.xhtml │ │ ├── columnOverride.xhtml │ │ ├── columnRenamingRule.xhtml │ │ ├── commentGenerator.xhtml │ │ ├── context.xhtml │ │ ├── generatedKey.xhtml │ │ ├── generatorConfiguration.xhtml │ │ ├── ignoreColumn.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 │ │ ├── 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 │ │ ├── runningWithJava.xhtml │ │ └── runningWithMaven.xhtml │ │ ├── usage │ │ ├── db2.xhtml │ │ ├── intro.xhtml │ │ ├── mysql.xhtml │ │ ├── oracle.xhtml │ │ └── postgresql.xhtml │ │ └── whatsNew.xhtml │ └── test │ ├── java │ └── org │ │ └── mybatis │ │ └── generator │ │ ├── MyBatisGeneratorTest.java │ │ ├── SqlScriptRunner.java │ │ ├── api │ │ └── dom │ │ │ └── java │ │ │ └── FullyQualifiedJavaTypeTest.java │ │ └── internal │ │ └── util │ │ └── JavaBeansUtilTest.java │ └── resources │ ├── generatorConfigIbatis2.xml │ ├── generatorConfigMyBatis3.xml │ └── log4j.properties ├── mybatis-generator-maven-plugin ├── LICENSE ├── NOTICE ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── mybatis │ └── generator │ └── maven │ ├── MavenProgressCallback.java │ ├── MavenShellCallback.java │ ├── MyBatisGeneratorMojo.java │ └── SqlScriptRunner.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # /core/ 2 | /core/.project 3 | /core/.settings 4 | /core/build.log 5 | /core/target 6 | 7 | # /core/mybatis-generator-core/ 8 | /core/mybatis-generator-core/.classpath 9 | /core/mybatis-generator-core/.project 10 | /core/mybatis-generator-core/.settings 11 | /core/mybatis-generator-core/target 12 | 13 | # /core/mybatis-generator-maven-plugin/ 14 | /core/mybatis-generator-maven-plugin/.classpath 15 | /core/mybatis-generator-maven-plugin/.project 16 | /core/mybatis-generator-maven-plugin/.settings 17 | /core/mybatis-generator-maven-plugin/target 18 | 19 | # /core/mybatis-generator-systests-common/ 20 | /core/mybatis-generator-systests-common/.classpath 21 | /core/mybatis-generator-systests-common/.project 22 | /core/mybatis-generator-systests-common/.settings 23 | /core/mybatis-generator-systests-common/target 24 | 25 | # /core/mybatis-generator-systests-ibatis2-java2/ 26 | /core/mybatis-generator-systests-ibatis2-java2/.classpath 27 | /core/mybatis-generator-systests-ibatis2-java2/.project 28 | /core/mybatis-generator-systests-ibatis2-java2/.settings 29 | /core/mybatis-generator-systests-ibatis2-java2/target 30 | 31 | # /core/mybatis-generator-systests-ibatis2-java5/ 32 | /core/mybatis-generator-systests-ibatis2-java5/.classpath 33 | /core/mybatis-generator-systests-ibatis2-java5/.project 34 | /core/mybatis-generator-systests-ibatis2-java5/.settings 35 | /core/mybatis-generator-systests-ibatis2-java5/target 36 | 37 | .idea 38 | target 39 | *.iml -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk7 4 | - openjdk7 5 | - openjdk6 6 | before_install: cd core 7 | after_success: 8 | - "git clone -b travis `git config --get remote.origin.url` target/travis" 9 | - "mvn deploy --settings target/travis/settings.xml" 10 | 11 | branches: 12 | except: 13 | - travis 14 | 15 | env: 16 | global: 17 | - secure: "Py3H6JFD9LeXN8mGcc3tIkxSQTKV6mLOXuYXSKNXXyOrCYpgtIjgquVKhV+K\nQnIDneZw45kDsB63Em1QUiGmKchGuO4QmHTnwYKxL3gpiGCurMcLR4dxs+cx\nitmTTo7UnmRbERV0YxMS26Dlcm1zn4DVGdJlWPU/qIJhAmnusPQ=" 18 | - secure: "N03lqVWTF1Nuhny9tGM/jlf188eZvN3F/7zjLnRW+b07QQ+zTty/T0QZu4tj\niOvmOCgwWBDjh+kv9MNadwZzPIWqWHrQpGe9ef6XZskwj/9gvtMz4s0Ur0Fi\nI2fSaWhfg6jhbM8OiUCalHsJDenEjLU8WtSIUal6c6zD/h+liyY=" 19 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This product includes software developed by 2 | The Apache Software Foundation (http://www.apache.org/). 3 | 4 | This product includes the EqualsUtil and HashCodeUtil classes 5 | from http://www.javapractices.com. 6 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | MyBatis Generator (MBG) is a code generator for MyBatis and iBATIS. 2 | 3 | It will generate code for all versions of MyBatis, and versions of iBATIS after version 2.2.0. It will introspect a database table (or many tables) and will generate artifacts that can be used to access the table(s). This lessens the initial nuisance of setting up objects and configuration files to interact with database tables. MBG seeks to make a major impact on the large percentage of database operations that are simple CRUD (Create, Retrieve, Update, Delete). 4 | -------------------------------------------------------------------------------- /mybatis-generator-core/NOTICE: -------------------------------------------------------------------------------- 1 | This product includes software developed by 2 | The Apache Software Foundation (http://www.apache.org/). 3 | 4 | This product includes the EqualsUtil and HashCodeUtil classes 5 | from http://www.javapractices.com. 6 | -------------------------------------------------------------------------------- /mybatis-generator-core/README.txt: -------------------------------------------------------------------------------- 1 | =============================================================================== 2 | Overview 3 | -------- 4 | MyBatis Generator (MBG) is a code generator for the MyBatis (and iBATIS) SQL 5 | mapping framework. MBG will introspect database tables (through JDBC 6 | DatabaseMetaData) and generate SQL Map XML files, Java model object (POJOs) 7 | that match the table, and (optionally) Java client classes that use the other 8 | generated objects. 9 | 10 | For full documentation, please refer to the user's manual at 11 | docs/index.html in this distribution. 12 | 13 | Dependencies 14 | ------------ 15 | There are no dependencies beyond the JRE. JRE 5.0 or above is required. 16 | Also required is a JDBC driver that implements the DatabaseMetaData interface, 17 | especially the "getColumns" and "getPrimaryKeys" methods. 18 | 19 | Support 20 | ------- 21 | Support is provided through the user mailing list. Mail 22 | questions or bug reports to: 23 | 24 | mybatis-user@googlegroups.com 25 | -------------------------------------------------------------------------------- /mybatis-generator-core/doc/releasing.txt: -------------------------------------------------------------------------------- 1 | Releasing MyBatis Generator 2 | =========================== 3 | 4 | Core Release Process 5 | ==================== 6 | 7 | Setup encrypted server passwords for Maven as shown here: 8 | 9 | http://code.google.com/p/mybatis/wiki/ProcessRelease 10 | 11 | Also, make sure that SVN and GPG are in your path, and that your gpg key 12 | has been published properly. 13 | 14 | 1. (optional) mvn release:prepare -DdryRun=true 15 | 16 | Make sure the new POMs look OK (pom.xml.next and pom.xml.tag) 17 | 18 | 2. (if you did #1) mvn release:clean 19 | 20 | 3. mvn release:prepare [-Dusername=xxx -Dpassword=xxx] 21 | 22 | The username and password properties are only required if you have not saved 23 | your SVN authentication information. 24 | 25 | This build might fail if the the newly versioned artifacts don't get installed 26 | in the local repository properly. If so, then run "mvn install" for the individual 27 | projects: core, maven-plugin, systests-common (in that order). Then, resume the 28 | release with 29 | 30 | mvn release:prepare -Dresume=true [-Dusername=xxx -Dpassword=xxx] 31 | 32 | 4. mvn release:perform 33 | 34 | This step should upload to sonatype, as well as uploading the core bundle to google code. If 35 | the google upload fails, you will need to upload the bundle manually. 36 | 37 | 5. On google code, set the prior version of the generator to deprecated 38 | 39 | 6. Log in to sonatype at http://oss.sonatype.org 40 | 41 | Go to "staging repositories" - you should see the uploaded artifacts. 42 | Close, and then release the staging repository. 43 | 44 | 7. Update the DTD on the site if required 45 | 46 | 8. Send out the announcement notice 47 | 48 | Eclipse Release Process 49 | ======================= 50 | 51 | 1. Build the new version of the Eclipse feature: 52 | - Increment the version number of the feature 53 | - Increment the version number of any plugin that has changed 54 | - Add the new version to the category.xml in the build project 55 | - Run the build.xml script in the build project (creates a new feature version 56 | at \temp\mybatis.generator.build\etc.) 57 | 58 | 2. Install a fresh version of Eclipse, and install the new version of the feature 59 | from \temp\mybatis.generator.build\buildRepo. Run through the manual test 60 | scripts for the Eclipse feature 61 | 62 | 3. If everything is OK, run the publish.xml script in the build project. 63 | This will merge the new plugin into the update site. 64 | 65 | 4. Commit the update site 66 | 67 | 5. Update the wiki with new version information 68 | 69 | 6. Send out the announcement notice 70 | 71 | -------------------------------------------------------------------------------- /mybatis-generator-core/doc/todo.txt: -------------------------------------------------------------------------------- 1 | Core: 2 | 3 | Future 4 | 5 | 1. Write page explaining how to use the GENERIC DAOs 6 | 2. Change the base API to allow specifying a connection at 7 | runtime, rather than requiring a connection in the 8 | XML config. 9 | 3. Relationships? 10 | 4. Java merger with ANTLR? 11 | 5. Add a way to override default types in the JavaTypeResolver 12 | 6. - to allow specification of common attributes for a set of 13 | tables 14 | 15 | 16 | 17 | Eclipse: 18 | 19 | Future 20 | 21 | 1. Write a launch configuration for the plugin to allow better 22 | control of the class path. 23 | 24 | 2. Get rid of the "Generate iBATIS Artifacts" popup menu - should 25 | only run with a launch configuration or with Ant. 26 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 4 | bundle 5 | 6 | zip 7 | 8 | 9 | 10 | 11 | ${project.basedir}/README* 12 | ${project.basedir}/LICENSE* 13 | ${project.basedir}/NOTICE* 14 | 15 | 16 | 17 | ${project.build.directory} 18 | lib 19 | 20 | *.jar 21 | 22 | 23 | 24 | ${project.build.directory}/site 25 | docs 26 | 27 | **/*.* 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/ant/AntProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.ant; 18 | 19 | import org.apache.tools.ant.Project; 20 | import org.apache.tools.ant.Task; 21 | import org.mybatis.generator.internal.NullProgressCallback; 22 | 23 | /** 24 | * This callback logs progress messages with the Ant logger 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class AntProgressCallback extends NullProgressCallback { 30 | 31 | private Task task; 32 | private boolean verbose; 33 | 34 | /** 35 | * 36 | */ 37 | public AntProgressCallback(Task task, boolean verbose) { 38 | super(); 39 | this.task = task; 40 | this.verbose = verbose; 41 | } 42 | 43 | @Override 44 | public void startTask(String subTaskName) { 45 | if (verbose) { 46 | task.log(subTaskName, Project.MSG_VERBOSE); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/GeneratedFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | 19 | /** 20 | * Abstract class that holds information common to all generated files. 21 | * 22 | * @author Jeff Butler 23 | */ 24 | public abstract class GeneratedFile { 25 | protected String targetProject; 26 | 27 | /** 28 | * 29 | */ 30 | public GeneratedFile(String targetProject) { 31 | super(); 32 | this.targetProject = targetProject; 33 | } 34 | 35 | /** 36 | * This method returns the entire contents of the generated file. Clients 37 | * can simply save the value returned from this method as the file contents. 38 | * Subclasses such as @see org.mybatis.generator.api.GeneratedJavaFile offer 39 | * more fine grained access to file parts, but still implement this method 40 | * in the event that the entire contents are desired. 41 | * 42 | * @return Returns the content. 43 | */ 44 | public abstract String getFormattedContent(); 45 | 46 | /** 47 | * Get the file name (without any path). Clients should use this method to 48 | * determine how to save the results. 49 | * 50 | * @return Returns the file name. 51 | */ 52 | public abstract String getFileName(); 53 | 54 | /** 55 | * Gets the target project. Clients can call this method to determine how to 56 | * save the results. 57 | * 58 | * @return the target project 59 | */ 60 | public String getTargetProject() { 61 | return targetProject; 62 | } 63 | 64 | /** 65 | * Get the target package for the file. Clients should use this method to 66 | * determine how to save the results. 67 | * 68 | * @return Returns the target project. 69 | */ 70 | public abstract String getTargetPackage(); 71 | 72 | @Override 73 | public String toString() { 74 | return getFormattedContent(); 75 | } 76 | 77 | public abstract boolean isMergeable(); 78 | } 79 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/GeneratedJavaFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | import org.mybatis.generator.api.dom.java.CompilationUnit; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class GeneratedJavaFile extends GeneratedFile { 24 | private CompilationUnit compilationUnit; 25 | private String fileEncoding; 26 | private JavaFormatter javaFormatter; 27 | 28 | /** 29 | * Default constructor 30 | */ 31 | public GeneratedJavaFile(CompilationUnit compilationUnit, 32 | String targetProject, 33 | String fileEncoding, 34 | JavaFormatter javaFormatter) { 35 | super(targetProject); 36 | this.compilationUnit = compilationUnit; 37 | this.fileEncoding = fileEncoding; 38 | this.javaFormatter = javaFormatter; 39 | } 40 | 41 | public GeneratedJavaFile(CompilationUnit compilationUnit, 42 | String targetProject, 43 | JavaFormatter javaFormatter) { 44 | this(compilationUnit, targetProject, null, javaFormatter); 45 | } 46 | 47 | @Override 48 | public String getFormattedContent() { 49 | return javaFormatter.getFormattedContent(compilationUnit); 50 | } 51 | 52 | @Override 53 | public String getFileName() { 54 | return compilationUnit.getType().getShortName() + ".java"; //$NON-NLS-1$ 55 | } 56 | 57 | public String getTargetPackage() { 58 | return compilationUnit.getType().getPackageName(); 59 | } 60 | 61 | /** 62 | * This method is required by the Eclipse Java merger. If you are not 63 | * running in Eclipse, or some other system that implements the Java merge 64 | * function, you may return null from this method. 65 | * 66 | * @return the CompilationUnit associated with this file, or null if the 67 | * file is not mergeable. 68 | */ 69 | public CompilationUnit getCompilationUnit() { 70 | return compilationUnit; 71 | } 72 | 73 | /** 74 | * A Java file is mergeable if the getCompilationUnit() method returns a 75 | * valid compilation unit. 76 | * 77 | */ 78 | @Override 79 | public boolean isMergeable() { 80 | return true; 81 | } 82 | 83 | public String getFileEncoding() { 84 | return fileEncoding; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/GeneratedXmlFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | import org.mybatis.generator.api.dom.xml.Document; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class GeneratedXmlFile extends GeneratedFile { 24 | private Document document; 25 | 26 | private String fileName; 27 | 28 | private String targetPackage; 29 | 30 | private boolean isMergeable; 31 | 32 | private XmlFormatter xmlFormatter; 33 | 34 | /** 35 | * 36 | * @param document 37 | * @param fileName 38 | * @param targetPackage 39 | * @param targetProject 40 | * @param isMergeable 41 | * true if the file can be merged by the built in XML file 42 | * merger. 43 | */ 44 | public GeneratedXmlFile(Document document, String fileName, 45 | String targetPackage, String targetProject, boolean isMergeable, 46 | XmlFormatter xmlFormatter) { 47 | super(targetProject); 48 | this.document = document; 49 | this.fileName = fileName; 50 | this.targetPackage = targetPackage; 51 | this.isMergeable = isMergeable; 52 | this.xmlFormatter = xmlFormatter; 53 | } 54 | 55 | @Override 56 | public String getFormattedContent() { 57 | return xmlFormatter.getFormattedContent(document); 58 | } 59 | 60 | /** 61 | * @return Returns the fileName. 62 | */ 63 | @Override 64 | public String getFileName() { 65 | return fileName; 66 | } 67 | 68 | /** 69 | * @return Returns the targetPackage. 70 | */ 71 | @Override 72 | public String getTargetPackage() { 73 | return targetPackage; 74 | } 75 | 76 | @Override 77 | public boolean isMergeable() { 78 | return isMergeable; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/JavaFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | import org.mybatis.generator.api.dom.java.CompilationUnit; 19 | import org.mybatis.generator.config.Context; 20 | 21 | /** 22 | * Objects implementing this interface are used to convert the internal 23 | * representation of the Java DOM classes into a string suitable for 24 | * saving to the file system. Note that the string generated by this 25 | * class will be saved directly to the file system with no additional modifications. 26 | * 27 | * Only one instance of the class will be created in each context. Configuration can 28 | * be passed into the class through the use of properties in the Context. 29 | * 30 | * @author Jeff Butler 31 | * 32 | */ 33 | public interface JavaFormatter { 34 | void setContext(Context context); 35 | String getFormattedContent(CompilationUnit compilationUnit); 36 | } 37 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/VerboseProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.api; 18 | 19 | import org.mybatis.generator.internal.NullProgressCallback; 20 | 21 | /** 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public class VerboseProgressCallback extends NullProgressCallback { 26 | 27 | /** 28 | * 29 | */ 30 | public VerboseProgressCallback() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void startTask(String taskName) { 36 | System.out.println(taskName); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/XmlFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api; 17 | 18 | import org.mybatis.generator.api.dom.xml.Document; 19 | import org.mybatis.generator.config.Context; 20 | 21 | /** 22 | * Objects implementing this interface are used to convert the internal 23 | * representation of the XML DOM classes into a string suitable for 24 | * saving to the file system. Note that the string generated by this 25 | * class will be saved directly to the file system with no additional modifications. 26 | * 27 | * Only one instance of the class will be created in each context. Configuration can 28 | * be passed into the class through the use of properties in the Context. 29 | * 30 | * @author Jeff Butler 31 | * 32 | */ 33 | public interface XmlFormatter { 34 | void setContext(Context context); 35 | String getFormattedContent(Document document); 36 | } 37 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/DefaultJavaFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom; 17 | 18 | import org.mybatis.generator.api.JavaFormatter; 19 | import org.mybatis.generator.api.dom.java.CompilationUnit; 20 | import org.mybatis.generator.config.Context; 21 | 22 | /** 23 | * This class is the default formatter for generated Java. This class will use the 24 | * built in formatting of the DOM classes directly. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class DefaultJavaFormatter implements JavaFormatter { 30 | protected Context context; 31 | 32 | public String getFormattedContent(CompilationUnit compilationUnit) { 33 | return compilationUnit.getFormattedContent(); 34 | } 35 | 36 | public void setContext(Context context) { 37 | this.context = context; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/DefaultXmlFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom; 17 | 18 | import org.mybatis.generator.api.XmlFormatter; 19 | import org.mybatis.generator.api.dom.xml.Document; 20 | import org.mybatis.generator.config.Context; 21 | 22 | /** 23 | * This class is the default formatter for generated XML. This class will use the 24 | * built in formatting of the DOM classes directly. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class DefaultXmlFormatter implements XmlFormatter { 30 | protected Context context; 31 | 32 | public String getFormattedContent(Document document) { 33 | return document.getFormattedContent(); 34 | } 35 | 36 | public void setContext(Context context) { 37 | this.context = context; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/CompilationUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.java; 17 | 18 | import java.util.List; 19 | import java.util.Set; 20 | 21 | /** 22 | * This interface describes methods common to all Java compilation units (Java 23 | * classes, interfaces, and enums). 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public interface CompilationUnit { 28 | String getFormattedContent(); 29 | 30 | Set getImportedTypes(); 31 | 32 | Set getStaticImports(); 33 | 34 | FullyQualifiedJavaType getSuperClass(); 35 | 36 | boolean isJavaInterface(); 37 | 38 | boolean isJavaEnumeration(); 39 | 40 | Set getSuperInterfaceTypes(); 41 | 42 | FullyQualifiedJavaType getType(); 43 | 44 | void addImportedType(FullyQualifiedJavaType importedType); 45 | 46 | void addImportedTypes(Set importedTypes); 47 | 48 | void addStaticImport(String staticImport); 49 | 50 | void addStaticImports(Set staticImports); 51 | 52 | /** 53 | * Comments will be written at the top of the file as is, we do not append 54 | * any start or end comment characters. 55 | * 56 | * Note that in the Eclipse plugin, file comments will not be merged. 57 | * 58 | * @param commentLine 59 | */ 60 | void addFileCommentLine(String commentLine); 61 | 62 | List getFileCommentLines(); 63 | } 64 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/JavaVisibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.java; 17 | 18 | /** 19 | * Typesafe enum of possible Java visibility settings 20 | * 21 | * @author Jeff Butler 22 | */ 23 | public enum JavaVisibility { 24 | PUBLIC("public "), //$NON-NLS-1$ 25 | PRIVATE("private "), //$NON-NLS-1$ 26 | PROTECTED("protected "), //$NON-NLS-1$ 27 | DEFAULT(""); //$NON-NLS-1$ 28 | 29 | private String value; 30 | 31 | private JavaVisibility(String value) { 32 | this.value = value; 33 | } 34 | 35 | public String getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/Attribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.xml; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public class Attribute { 22 | private String name; 23 | private String value; 24 | 25 | /** 26 | * 27 | */ 28 | public Attribute(String name, String value) { 29 | super(); 30 | this.name = name; 31 | this.value = value; 32 | } 33 | 34 | /** 35 | * @return Returns the name. 36 | */ 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | /** 42 | * @return Returns the value. 43 | */ 44 | public String getValue() { 45 | return value; 46 | } 47 | 48 | public String getFormattedContent() { 49 | StringBuilder sb = new StringBuilder(); 50 | sb.append(name); 51 | sb.append("=\""); //$NON-NLS-1$ 52 | sb.append(value); 53 | sb.append('\"'); 54 | 55 | return sb.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/Document.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.xml; 17 | 18 | import org.mybatis.generator.api.dom.OutputUtilities; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class Document { 24 | private String publicId; 25 | 26 | private String systemId; 27 | 28 | private XmlElement rootElement; 29 | 30 | /** 31 | * 32 | */ 33 | public Document(String publicId, String systemId) { 34 | super(); 35 | this.publicId = publicId; 36 | this.systemId = systemId; 37 | } 38 | 39 | public Document() { 40 | super(); 41 | } 42 | 43 | /** 44 | * @return Returns the rootElement. 45 | */ 46 | public XmlElement getRootElement() { 47 | return rootElement; 48 | } 49 | 50 | /** 51 | * @param rootElement 52 | * The rootElement to set. 53 | */ 54 | public void setRootElement(XmlElement rootElement) { 55 | this.rootElement = rootElement; 56 | } 57 | 58 | /** 59 | * @return Returns the publicId. 60 | */ 61 | public String getPublicId() { 62 | return publicId; 63 | } 64 | 65 | /** 66 | * @return Returns the systemId. 67 | */ 68 | public String getSystemId() { 69 | return systemId; 70 | } 71 | 72 | public String getFormattedContent() { 73 | StringBuilder sb = new StringBuilder(); 74 | 75 | sb.append(""); //$NON-NLS-1$ 76 | 77 | if (publicId != null && systemId != null) { 78 | OutputUtilities.newLine(sb); 79 | sb.append(""); //$NON-NLS-1$ 86 | } 87 | 88 | OutputUtilities.newLine(sb); 89 | sb.append(rootElement.getFormattedContent(0)); 90 | 91 | return sb.toString(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/Element.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.xml; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public abstract class Element { 22 | 23 | /** 24 | * 25 | */ 26 | public Element() { 27 | super(); 28 | } 29 | 30 | public abstract String getFormattedContent(int indentLevel); 31 | } 32 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/TextElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.xml; 17 | 18 | import org.mybatis.generator.api.dom.OutputUtilities; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class TextElement extends Element { 24 | private String content; 25 | 26 | /** 27 | * 28 | */ 29 | public TextElement(String content) { 30 | super(); 31 | this.content = content; 32 | } 33 | 34 | @Override 35 | public String getFormattedContent(int indentLevel) { 36 | StringBuilder sb = new StringBuilder(); 37 | OutputUtilities.xmlIndent(sb, indentLevel); 38 | sb.append(content); 39 | return sb.toString(); 40 | } 41 | 42 | public String getContent() { 43 | return content; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/api/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Package Description for Main MyBatis Generator API Classes 4 | 5 | 6 |

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

7 | 8 | 9 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/AbstractGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.generator.api.IntrospectedTable; 21 | import org.mybatis.generator.api.ProgressCallback; 22 | import org.mybatis.generator.config.Context; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public abstract class AbstractGenerator { 30 | protected Context context; 31 | protected IntrospectedTable introspectedTable; 32 | protected List warnings; 33 | protected ProgressCallback progressCallback; 34 | 35 | public AbstractGenerator() { 36 | super(); 37 | } 38 | 39 | public Context getContext() { 40 | return context; 41 | } 42 | 43 | public void setContext(Context context) { 44 | this.context = context; 45 | } 46 | 47 | public IntrospectedTable getIntrospectedTable() { 48 | return introspectedTable; 49 | } 50 | 51 | public void setIntrospectedTable(IntrospectedTable introspectedTable) { 52 | this.introspectedTable = introspectedTable; 53 | } 54 | 55 | public List getWarnings() { 56 | return warnings; 57 | } 58 | 59 | public void setWarnings(List warnings) { 60 | this.warnings = warnings; 61 | } 62 | 63 | public ProgressCallback getProgressCallback() { 64 | return progressCallback; 65 | } 66 | 67 | public void setProgressCallback(ProgressCallback progressCallback) { 68 | this.progressCallback = progressCallback; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/AbstractJavaClientGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 17 | 18 | /** 19 | * This class exists to that Java client generators can specify whether 20 | * an XML generator is required to match the methods in the 21 | * Java client. For example, a Java client built entirely with 22 | * annotations does not need matching XML. 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public abstract class AbstractJavaClientGenerator extends AbstractJavaGenerator { 28 | 29 | private boolean requiresXMLGenerator; 30 | 31 | public AbstractJavaClientGenerator(boolean requiresXMLGenerator) { 32 | super(); 33 | this.requiresXMLGenerator = requiresXMLGenerator; 34 | } 35 | 36 | /** 37 | * @return true if matching XML is required 38 | */ 39 | public boolean requiresXMLGenerator() { 40 | return requiresXMLGenerator; 41 | } 42 | 43 | /** 44 | * This method returns an instance of the XML generator associated 45 | * with this client generator. 46 | * 47 | * @return the matched XML generator. May return null if no 48 | * XML is required by this generator 49 | */ 50 | public abstract AbstractXmlGenerator getMatchedXMLGenerator(); 51 | } 52 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/AbstractJavaGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 17 | 18 | import static org.mybatis.generator.internal.util.JavaBeansUtil.getGetterMethodName; 19 | 20 | import java.util.List; 21 | import java.util.Properties; 22 | 23 | import org.mybatis.generator.api.dom.java.CompilationUnit; 24 | import org.mybatis.generator.api.dom.java.Field; 25 | import org.mybatis.generator.api.dom.java.JavaVisibility; 26 | import org.mybatis.generator.api.dom.java.Method; 27 | import org.mybatis.generator.api.dom.java.TopLevelClass; 28 | import org.mybatis.generator.config.PropertyRegistry; 29 | 30 | /** 31 | * 32 | * @author Jeff Butler 33 | * 34 | */ 35 | public abstract class AbstractJavaGenerator extends AbstractGenerator { 36 | public abstract List getCompilationUnits(); 37 | 38 | public static Method getGetter(Field field) { 39 | Method method = new Method(); 40 | method.setName(getGetterMethodName(field.getName(), field 41 | .getType())); 42 | method.setReturnType(field.getType()); 43 | method.setVisibility(JavaVisibility.PUBLIC); 44 | StringBuilder sb = new StringBuilder(); 45 | sb.append("return "); //$NON-NLS-1$ 46 | sb.append(field.getName()); 47 | sb.append(';'); 48 | method.addBodyLine(sb.toString()); 49 | return method; 50 | } 51 | 52 | public String getRootClass() { 53 | String rootClass = introspectedTable 54 | .getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_CLASS); 55 | if (rootClass == null) { 56 | Properties properties = context 57 | .getJavaModelGeneratorConfiguration().getProperties(); 58 | rootClass = properties.getProperty(PropertyRegistry.ANY_ROOT_CLASS); 59 | } 60 | 61 | return rootClass; 62 | } 63 | 64 | protected void addDefaultConstructor(TopLevelClass topLevelClass) { 65 | Method method = new Method(); 66 | method.setVisibility(JavaVisibility.PUBLIC); 67 | method.setConstructor(true); 68 | method.setName(topLevelClass.getType().getShortName()); 69 | method.addBodyLine("super();"); //$NON-NLS-1$ 70 | context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); 71 | topLevelClass.addMethod(method); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/AbstractXmlGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 17 | 18 | import org.mybatis.generator.api.dom.xml.Document; 19 | 20 | /** 21 | * 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public abstract class AbstractXmlGenerator extends AbstractGenerator { 26 | public abstract Document getDocument(); 27 | } 28 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/XmlConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public class XmlConstants { 22 | 23 | /** 24 | * Utility Class, no instances 25 | */ 26 | private XmlConstants() { 27 | super(); 28 | } 29 | 30 | public static final String IBATIS2_SQL_MAP_SYSTEM_ID = "http://ibatis.apache.org/dtd/sql-map-2.dtd"; //$NON-NLS-1$ 31 | 32 | public static final String IBATIS2_SQL_MAP_PUBLIC_ID = "-//ibatis.apache.org//DTD SQL Map 2.0//EN"; //$NON-NLS-1$ 33 | 34 | public static final String IBATIS2_SQL_MAP_CONFIG_SYSTEM_ID = "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"; //$NON-NLS-1$ 35 | 36 | public static final String IBATIS2_SQL_MAP_CONFIG_PUBLIC_ID = "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"; //$NON-NLS-1$ 37 | 38 | public static final String MYBATIS3_MAPPER_SYSTEM_ID = "http://mybatis.org/dtd/mybatis-3-mapper.dtd"; //$NON-NLS-1$ 39 | 40 | public static final String MYBATIS3_MAPPER_PUBLIC_ID = "-//mybatis.org//DTD Mapper 3.0//EN"; //$NON-NLS-1$ 41 | 42 | public static final String MYBATIS3_MAPPER_CONFIG_SYSTEM_ID = "http://mybatis.org/dtd/mybatis-3-config.dtd"; //$NON-NLS-1$ 43 | 44 | public static final String MYBATIS3_MAPPER_CONFIG_PUBLIC_ID = "-//mybatis.org//DTD Config 3.0//EN"; //$NON-NLS-1$ 45 | 46 | public static final String IBATOR_CONFIG_SYSTEM_ID = "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd"; //$NON-NLS-1$ 47 | 48 | public static final String IBATOR_CONFIG_PUBLIC_ID = "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN"; //$NON-NLS-1$ 49 | 50 | public static final String MYBATIS_GENERATOR_CONFIG_SYSTEM_ID = "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"; //$NON-NLS-1$ 51 | 52 | public static final String MYBATIS_GENERATOR_CONFIG_PUBLIC_ID = "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"; //$NON-NLS-1$ 53 | } 54 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/IntrospectedTableIbatis2Java5Impl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2; 17 | 18 | /** 19 | * 20 | * @author Jeff Butler 21 | * 22 | */ 23 | public class IntrospectedTableIbatis2Java5Impl extends 24 | IntrospectedTableIbatis2Java2Impl { 25 | @Override 26 | public boolean isJava5Targeted() { 27 | return true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/dao/templates/SpringDAOTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.dao.templates; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.JavaVisibility; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | 22 | /** 23 | * @author Jeff Butler 24 | */ 25 | public class SpringDAOTemplate extends AbstractDAOTemplate { 26 | 27 | /** 28 | * 29 | */ 30 | public SpringDAOTemplate() { 31 | super(); 32 | } 33 | 34 | @Override 35 | protected void configureConstructorTemplate() { 36 | Method method = new Method(); 37 | method.setConstructor(true); 38 | method.setVisibility(JavaVisibility.PUBLIC); 39 | method.addBodyLine("super();"); //$NON-NLS-1$ 40 | setConstructorTemplate(method); 41 | } 42 | 43 | @Override 44 | protected void configureDeleteMethodTemplate() { 45 | setDeleteMethodTemplate("getSqlMapClientTemplate().delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 46 | } 47 | 48 | @Override 49 | protected void configureInsertMethodTemplate() { 50 | setInsertMethodTemplate("getSqlMapClientTemplate().insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 51 | } 52 | 53 | @Override 54 | protected void configureQueryForListMethodTemplate() { 55 | setQueryForListMethodTemplate("getSqlMapClientTemplate().queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 56 | } 57 | 58 | @Override 59 | protected void configureQueryForObjectMethodTemplate() { 60 | setQueryForObjectMethodTemplate("getSqlMapClientTemplate().queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 61 | } 62 | 63 | @Override 64 | protected void configureSuperClass() { 65 | setSuperClass(new FullyQualifiedJavaType( 66 | "org.springframework.orm.ibatis.support.SqlMapClientDaoSupport")); //$NON-NLS-1$ 67 | } 68 | 69 | @Override 70 | protected void configureUpdateMethodTemplate() { 71 | setUpdateMethodTemplate("getSqlMapClientTemplate().update(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.ibatis2.Ibatis2FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class BaseColumnListElementGenerator extends AbstractXmlElementGenerator { 32 | 33 | public BaseColumnListElementGenerator() { 34 | super(); 35 | } 36 | 37 | @Override 38 | public void addElements(XmlElement parentElement) { 39 | XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$ 40 | 41 | answer.addAttribute(new Attribute("id", //$NON-NLS-1$ 42 | introspectedTable.getBaseColumnListId())); 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | Iterator iter = introspectedTable 48 | .getNonBLOBColumns().iterator(); 49 | while (iter.hasNext()) { 50 | sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter 51 | .next())); 52 | 53 | if (iter.hasNext()) { 54 | sb.append(", "); //$NON-NLS-1$ 55 | } 56 | 57 | if (sb.length() > 80) { 58 | answer.addElement(new TextElement(sb.toString())); 59 | sb.setLength(0); 60 | } 61 | } 62 | 63 | if (sb.length() > 0) { 64 | answer.addElement((new TextElement(sb.toString()))); 65 | } 66 | 67 | if (context.getPlugins().sqlMapBaseColumnListElementGenerated( 68 | answer, introspectedTable)) { 69 | parentElement.addElement(answer); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.ibatis2.Ibatis2FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class BlobColumnListElementGenerator extends AbstractXmlElementGenerator { 32 | 33 | public BlobColumnListElementGenerator() { 34 | super(); 35 | } 36 | 37 | @Override 38 | public void addElements(XmlElement parentElement) { 39 | XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$ 40 | 41 | answer.addAttribute(new Attribute("id", //$NON-NLS-1$ 42 | introspectedTable.getBlobColumnListId())); 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | 48 | Iterator iter = introspectedTable.getBLOBColumns() 49 | .iterator(); 50 | while (iter.hasNext()) { 51 | sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter 52 | .next())); 53 | 54 | if (iter.hasNext()) { 55 | sb.append(", "); //$NON-NLS-1$ 56 | } 57 | 58 | if (sb.length() > 80) { 59 | answer.addElement(new TextElement(sb.toString())); 60 | sb.setLength(0); 61 | } 62 | } 63 | 64 | if (sb.length() > 0) { 65 | answer.addElement((new TextElement(sb.toString()))); 66 | } 67 | 68 | if (context.getPlugins().sqlMapBlobColumnListElementGenerated( 69 | answer, introspectedTable)) { 70 | parentElement.addElement(answer); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/CountByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class CountByExampleElementGenerator extends AbstractXmlElementGenerator { 28 | 29 | public CountByExampleElementGenerator() { 30 | super(); 31 | } 32 | 33 | @Override 34 | public void addElements(XmlElement parentElement) { 35 | XmlElement answer = new XmlElement("select"); //$NON-NLS-1$ 36 | 37 | answer.addAttribute(new Attribute( 38 | "id", introspectedTable.getCountByExampleStatementId())); //$NON-NLS-1$ 39 | answer.addAttribute(new Attribute( 40 | "parameterClass", introspectedTable.getExampleType())); //$NON-NLS-1$ 41 | answer.addAttribute(new Attribute("resultClass", "java.lang.Integer")); //$NON-NLS-1$ //$NON-NLS-2$ 42 | 43 | context.getCommentGenerator().addComment(answer); 44 | 45 | StringBuilder sb = new StringBuilder(); 46 | sb.append("select count(*) from "); //$NON-NLS-1$ 47 | sb.append(introspectedTable 48 | .getAliasedFullyQualifiedTableNameAtRuntime()); 49 | answer.addElement(new TextElement(sb.toString())); 50 | 51 | XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$ 52 | sb.setLength(0); 53 | sb.append(introspectedTable.getIbatis2SqlMapNamespace()); 54 | sb.append('.'); 55 | sb.append(introspectedTable.getExampleWhereClauseId()); 56 | includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$ 57 | sb.toString())); 58 | 59 | answer.addElement(includeElement); 60 | 61 | if (context.getPlugins().sqlMapCountByExampleElementGenerated( 62 | answer, introspectedTable)) { 63 | parentElement.addElement(answer); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/ibatis2/sqlmap/elements/DeleteByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.sqlmap.elements; 17 | 18 | import org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class DeleteByExampleElementGenerator extends 28 | AbstractXmlElementGenerator { 29 | 30 | public DeleteByExampleElementGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addElements(XmlElement parentElement) { 36 | XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$ 37 | 38 | answer.addAttribute(new Attribute( 39 | "id", introspectedTable.getDeleteByExampleStatementId())); //$NON-NLS-1$ 40 | answer.addAttribute(new Attribute( 41 | "parameterClass", introspectedTable.getExampleType())); //$NON-NLS-1$ 42 | 43 | context.getCommentGenerator().addComment(answer); 44 | 45 | StringBuilder sb = new StringBuilder(); 46 | sb.append("delete from "); //$NON-NLS-1$ 47 | sb.append(introspectedTable 48 | .getAliasedFullyQualifiedTableNameAtRuntime()); 49 | answer.addElement(new TextElement(sb.toString())); 50 | 51 | XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$ 52 | sb.setLength(0); 53 | sb.append(introspectedTable.getIbatis2SqlMapNamespace()); 54 | sb.append('.'); 55 | sb.append(introspectedTable.getExampleWhereClauseId()); 56 | includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$ 57 | sb.toString())); 58 | 59 | answer.addElement(includeElement); 60 | 61 | if (context.getPlugins().sqlMapDeleteByExampleElementGenerated( 62 | answer, introspectedTable)) { 63 | parentElement.addElement(answer); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/CountByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class CountByExampleMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public CountByExampleMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType( 42 | introspectedTable.getExampleType()); 43 | 44 | Set importedTypes = new TreeSet(); 45 | importedTypes.add(fqjt); 46 | 47 | Method method = new Method(); 48 | method.setVisibility(JavaVisibility.PUBLIC); 49 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 50 | method.setName(introspectedTable.getCountByExampleStatementId()); 51 | method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ 52 | context.getCommentGenerator().addGeneralMethodComment(method, 53 | introspectedTable); 54 | 55 | addMapperAnnotations(interfaze, method); 56 | 57 | if (context.getPlugins().clientCountByExampleMethodGenerated(method, 58 | interfaze, introspectedTable)) { 59 | interfaze.addImportedTypes(importedTypes); 60 | interfaze.addMethod(method); 61 | } 62 | } 63 | 64 | public void addMapperAnnotations(Interface interfaze, Method method) { 65 | return; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/DeleteByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class DeleteByExampleMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public DeleteByExampleMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType type = new FullyQualifiedJavaType( 43 | introspectedTable.getExampleType()); 44 | importedTypes.add(type); 45 | 46 | Method method = new Method(); 47 | method.setVisibility(JavaVisibility.PUBLIC); 48 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 49 | method.setName(introspectedTable.getDeleteByExampleStatementId()); 50 | method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$ 51 | 52 | context.getCommentGenerator().addGeneralMethodComment(method, 53 | introspectedTable); 54 | 55 | addMapperAnnotations(interfaze, method); 56 | 57 | if (context.getPlugins().clientDeleteByExampleMethodGenerated( 58 | method, interfaze, introspectedTable)) { 59 | interfaze.addImportedTypes(importedTypes); 60 | interfaze.addMethod(method); 61 | } 62 | } 63 | 64 | public void addMapperAnnotations(Interface interfaze, Method method) { 65 | return; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/InsertMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class InsertMethodGenerator extends AbstractJavaMapperMethodGenerator { 33 | 34 | boolean isSimple; 35 | 36 | public InsertMethodGenerator(boolean isSimple) { 37 | super(); 38 | this.isSimple = isSimple; 39 | } 40 | 41 | @Override 42 | public void addInterfaceElements(Interface interfaze) { 43 | Set importedTypes = new TreeSet(); 44 | Method method = new Method(); 45 | 46 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 47 | method.setVisibility(JavaVisibility.PUBLIC); 48 | method.setName(introspectedTable.getInsertStatementId()); 49 | 50 | FullyQualifiedJavaType parameterType; 51 | if (isSimple) { 52 | parameterType = new FullyQualifiedJavaType( 53 | introspectedTable.getBaseRecordType()); 54 | } else { 55 | parameterType = introspectedTable.getRules() 56 | .calculateAllFieldsClass(); 57 | } 58 | 59 | importedTypes.add(parameterType); 60 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 61 | 62 | context.getCommentGenerator().addGeneralMethodComment(method, 63 | introspectedTable); 64 | 65 | addMapperAnnotations(interfaze, method); 66 | 67 | if (context.getPlugins().clientInsertMethodGenerated(method, interfaze, 68 | introspectedTable)) { 69 | interfaze.addImportedTypes(importedTypes); 70 | interfaze.addMethod(method); 71 | } 72 | } 73 | 74 | public void addMapperAnnotations(Interface interfaze, Method method) { 75 | return; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/InsertSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class InsertSelectiveMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public InsertSelectiveMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | Method method = new Method(); 43 | 44 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 45 | method.setVisibility(JavaVisibility.PUBLIC); 46 | method.setName(introspectedTable.getInsertSelectiveStatementId()); 47 | 48 | FullyQualifiedJavaType parameterType = introspectedTable.getRules() 49 | .calculateAllFieldsClass(); 50 | 51 | importedTypes.add(parameterType); 52 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 53 | 54 | context.getCommentGenerator().addGeneralMethodComment(method, 55 | introspectedTable); 56 | 57 | addMapperAnnotations(interfaze, method); 58 | 59 | if (context.getPlugins().clientInsertSelectiveMethodGenerated( 60 | method, interfaze, introspectedTable)) { 61 | interfaze.addImportedTypes(importedTypes); 62 | interfaze.addMethod(method); 63 | } 64 | } 65 | 66 | public void addMapperAnnotations(Interface interfaze, Method method) { 67 | return; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/SelectAllMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | 26 | /** 27 | * The selectAll method is only generated by the Mybatis3Simple runtime. 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class SelectAllMethodGenerator extends AbstractJavaMapperMethodGenerator { 33 | 34 | public SelectAllMethodGenerator() { 35 | super(); 36 | } 37 | 38 | @Override 39 | public void addInterfaceElements(Interface interfaze) { 40 | Set importedTypes = new TreeSet(); 41 | importedTypes.add(FullyQualifiedJavaType.getNewListInstance()); 42 | 43 | Method method = new Method(); 44 | method.setVisibility(JavaVisibility.PUBLIC); 45 | 46 | FullyQualifiedJavaType returnType = FullyQualifiedJavaType 47 | .getNewListInstance(); 48 | FullyQualifiedJavaType listType; 49 | listType = new FullyQualifiedJavaType( 50 | introspectedTable.getBaseRecordType()); 51 | 52 | importedTypes.add(listType); 53 | returnType.addTypeArgument(listType); 54 | method.setReturnType(returnType); 55 | method.setName(introspectedTable.getSelectAllStatementId()); 56 | 57 | context.getCommentGenerator().addGeneralMethodComment(method, 58 | introspectedTable); 59 | 60 | addMapperAnnotations(interfaze, method); 61 | 62 | if (context.getPlugins().clientSelectAllMethodGenerated(method, 63 | interfaze, introspectedTable)) { 64 | interfaze.addImportedTypes(importedTypes); 65 | interfaze.addMethod(method); 66 | } 67 | } 68 | 69 | public void addMapperAnnotations(Interface interfaze, Method method) { 70 | return; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByPrimaryKeyWithoutBLOBsMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public UpdateByPrimaryKeyWithoutBLOBsMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType( 43 | introspectedTable.getBaseRecordType()); 44 | importedTypes.add(parameterType); 45 | 46 | Method method = new Method(); 47 | method.setVisibility(JavaVisibility.PUBLIC); 48 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 49 | method.setName(introspectedTable.getUpdateByPrimaryKeyStatementId()); 50 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 51 | 52 | context.getCommentGenerator().addGeneralMethodComment(method, 53 | introspectedTable); 54 | 55 | addMapperAnnotations(interfaze, method); 56 | 57 | if (context.getPlugins() 58 | .clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method, 59 | interfaze, introspectedTable)) { 60 | interfaze.addImportedTypes(importedTypes); 61 | interfaze.addMethod(method); 62 | } 63 | } 64 | 65 | public void addMapperAnnotations(Interface interfaze, Method method) { 66 | return; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedCountByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.CountByExampleMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedCountByExampleMethodGenerator extends 28 | CountByExampleMethodGenerator { 29 | 30 | public AnnotatedCountByExampleMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.SelectProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@SelectProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getCountByExampleStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedDeleteByExampleMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.DeleteByExampleMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedDeleteByExampleMethodGenerator extends 28 | DeleteByExampleMethodGenerator { 29 | 30 | public AnnotatedDeleteByExampleMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.DeleteProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@DeleteProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getDeleteByExampleStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedInsertSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.InsertSelectiveMethodGenerator; 22 | import org.mybatis.generator.config.GeneratedKey; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | */ 28 | public class AnnotatedInsertSelectiveMethodGenerator extends 29 | InsertSelectiveMethodGenerator { 30 | 31 | public AnnotatedInsertSelectiveMethodGenerator() { 32 | super(); 33 | } 34 | 35 | @Override 36 | public void addMapperAnnotations(Interface interfaze, Method method) { 37 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 38 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.InsertProvider")); //$NON-NLS-1$ 39 | StringBuilder sb = new StringBuilder(); 40 | sb.append("@InsertProvider(type="); //$NON-NLS-1$ 41 | sb.append(fqjt.getShortName()); 42 | sb.append(".class, method=\""); //$NON-NLS-1$ 43 | sb.append(introspectedTable.getInsertSelectiveStatementId()); 44 | sb.append("\")"); //$NON-NLS-1$ 45 | 46 | method.addAnnotation(sb.toString()); 47 | 48 | GeneratedKey gk = introspectedTable.getGeneratedKey(); 49 | if (gk != null) { 50 | addGeneratedKeyAnnotation(interfaze, method, gk); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByExampleSelectiveMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByExampleSelectiveMethodGenerator extends 28 | UpdateByExampleSelectiveMethodGenerator { 29 | 30 | public AnnotatedUpdateByExampleSelectiveMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByExampleSelectiveStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByExampleWithBLOBsMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByExampleWithBLOBsMethodGenerator extends 28 | UpdateByExampleWithBLOBsMethodGenerator { 29 | 30 | public AnnotatedUpdateByExampleWithBLOBsMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByExampleWithBLOBsStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByExampleWithoutBLOBsMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator extends 28 | UpdateByExampleWithoutBLOBsMethodGenerator { 29 | 30 | public AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByExampleStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/annotated/AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.Interface; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.codegen.mybatis3.javamapper.elements.UpdateByPrimaryKeySelectiveMethodGenerator; 22 | 23 | /** 24 | * 25 | * @author Jeff Butler 26 | */ 27 | public class AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator extends 28 | UpdateByPrimaryKeySelectiveMethodGenerator { 29 | 30 | public AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addMapperAnnotations(Interface interfaze, Method method) { 36 | FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); 37 | interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@UpdateProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getUpdateByPrimaryKeySelectiveStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/AbstractJavaProviderMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.sqlprovider; 17 | 18 | import org.mybatis.generator.api.dom.java.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 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderSelectByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.sqlprovider; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.java.Method; 22 | import org.mybatis.generator.api.dom.java.TopLevelClass; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class ProviderSelectByExampleWithBLOBsMethodGenerator extends 30 | ProviderSelectByExampleWithoutBLOBsMethodGenerator { 31 | 32 | public ProviderSelectByExampleWithBLOBsMethodGenerator(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 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderUpdateByExampleWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements.sqlprovider; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.java.Method; 22 | import org.mybatis.generator.api.dom.java.TopLevelClass; 23 | 24 | /** 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class ProviderUpdateByExampleWithBLOBsMethodGenerator extends 30 | ProviderUpdateByExampleWithoutBLOBsMethodGenerator { 31 | 32 | public ProviderUpdateByExampleWithBLOBsMethodGenerator(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 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/MixedMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper; 17 | 18 | import org.mybatis.generator.api.dom.xml.XmlElement; 19 | 20 | /** 21 | * 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public class MixedMapperGenerator extends XMLMapperGenerator { 26 | 27 | @Override 28 | protected void addSelectByPrimaryKeyElement(XmlElement parentElement) { 29 | return; 30 | } 31 | 32 | @Override 33 | protected void addDeleteByPrimaryKeyElement(XmlElement parentElement) { 34 | return; 35 | } 36 | 37 | @Override 38 | protected void addInsertElement(XmlElement parentElement) { 39 | return; 40 | } 41 | 42 | @Override 43 | protected void addUpdateByPrimaryKeyWithBLOBsElement( 44 | XmlElement parentElement) { 45 | return; 46 | } 47 | 48 | @Override 49 | protected void addUpdateByPrimaryKeyWithoutBLOBsElement( 50 | XmlElement parentElement) { 51 | return; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/BaseColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class BaseColumnListElementGenerator extends AbstractXmlElementGenerator { 32 | 33 | public BaseColumnListElementGenerator() { 34 | super(); 35 | } 36 | 37 | @Override 38 | public void addElements(XmlElement parentElement) { 39 | XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$ 40 | 41 | answer.addAttribute(new Attribute("id", //$NON-NLS-1$ 42 | introspectedTable.getBaseColumnListId())); 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | Iterator iter = introspectedTable 48 | .getNonBLOBColumns().iterator(); 49 | while (iter.hasNext()) { 50 | sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter 51 | .next())); 52 | 53 | if (iter.hasNext()) { 54 | sb.append(", "); //$NON-NLS-1$ 55 | } 56 | 57 | if (sb.length() > 80) { 58 | answer.addElement(new TextElement(sb.toString())); 59 | sb.setLength(0); 60 | } 61 | } 62 | 63 | if (sb.length() > 0) { 64 | answer.addElement((new TextElement(sb.toString()))); 65 | } 66 | 67 | if (context.getPlugins().sqlMapBaseColumnListElementGenerated( 68 | answer, introspectedTable)) { 69 | parentElement.addElement(answer); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/BlobColumnListElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import java.util.Iterator; 19 | 20 | import org.mybatis.generator.api.IntrospectedColumn; 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.TextElement; 23 | import org.mybatis.generator.api.dom.xml.XmlElement; 24 | import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class BlobColumnListElementGenerator extends AbstractXmlElementGenerator { 32 | 33 | public BlobColumnListElementGenerator() { 34 | super(); 35 | } 36 | 37 | @Override 38 | public void addElements(XmlElement parentElement) { 39 | XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$ 40 | 41 | answer.addAttribute(new Attribute("id", //$NON-NLS-1$ 42 | introspectedTable.getBlobColumnListId())); 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | 48 | Iterator iter = introspectedTable.getBLOBColumns() 49 | .iterator(); 50 | while (iter.hasNext()) { 51 | sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter 52 | .next())); 53 | 54 | if (iter.hasNext()) { 55 | sb.append(", "); //$NON-NLS-1$ 56 | } 57 | 58 | if (sb.length() > 80) { 59 | answer.addElement(new TextElement(sb.toString())); 60 | sb.setLength(0); 61 | } 62 | } 63 | 64 | if (sb.length() > 0) { 65 | answer.addElement((new TextElement(sb.toString()))); 66 | } 67 | 68 | if (context.getPlugins().sqlMapBlobColumnListElementGenerated( 69 | answer, introspectedTable)) { 70 | parentElement.addElement(answer); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/CountByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class CountByExampleElementGenerator extends AbstractXmlElementGenerator { 28 | 29 | public CountByExampleElementGenerator() { 30 | super(); 31 | } 32 | 33 | @Override 34 | public void addElements(XmlElement parentElement) { 35 | XmlElement answer = new XmlElement("select"); //$NON-NLS-1$ 36 | 37 | String fqjt = introspectedTable.getExampleType(); 38 | 39 | answer.addAttribute(new Attribute( 40 | "id", introspectedTable.getCountByExampleStatementId())); //$NON-NLS-1$ 41 | answer.addAttribute(new Attribute("parameterType", fqjt)); //$NON-NLS-1$ 42 | answer.addAttribute(new Attribute("resultType", "java.lang.Integer")); //$NON-NLS-1$ //$NON-NLS-2$ 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | sb.append("select count(*) from "); //$NON-NLS-1$ 48 | sb.append(introspectedTable 49 | .getAliasedFullyQualifiedTableNameAtRuntime()); 50 | answer.addElement(new TextElement(sb.toString())); 51 | answer.addElement(getExampleIncludeElement()); 52 | 53 | if (context.getPlugins().sqlMapCountByExampleElementGenerated( 54 | answer, introspectedTable)) { 55 | parentElement.addElement(answer); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/xmlmapper/elements/DeleteByExampleElementGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements; 17 | 18 | import org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.TextElement; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class DeleteByExampleElementGenerator extends 28 | AbstractXmlElementGenerator { 29 | 30 | public DeleteByExampleElementGenerator() { 31 | super(); 32 | } 33 | 34 | @Override 35 | public void addElements(XmlElement parentElement) { 36 | XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$ 37 | 38 | String fqjt = introspectedTable.getExampleType(); 39 | 40 | answer.addAttribute(new Attribute( 41 | "id", introspectedTable.getDeleteByExampleStatementId())); //$NON-NLS-1$ 42 | answer.addAttribute(new Attribute("parameterType", fqjt)); //$NON-NLS-1$ 43 | 44 | context.getCommentGenerator().addComment(answer); 45 | 46 | StringBuilder sb = new StringBuilder(); 47 | sb.append("delete from "); //$NON-NLS-1$ 48 | sb.append(introspectedTable 49 | .getAliasedFullyQualifiedTableNameAtRuntime()); 50 | answer.addElement(new TextElement(sb.toString())); 51 | answer.addElement(getExampleIncludeElement()); 52 | 53 | if (context.getPlugins().sqlMapDeleteByExampleElementGenerated( 54 | answer, introspectedTable)) { 55 | parentElement.addElement(answer); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/CommentGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.config; 18 | 19 | import org.mybatis.generator.api.dom.xml.Attribute; 20 | import org.mybatis.generator.api.dom.xml.XmlElement; 21 | 22 | /** 23 | * @author Jeff Butler 24 | * 25 | */ 26 | public class CommentGeneratorConfiguration extends TypedPropertyHolder { 27 | 28 | /** 29 | * 30 | */ 31 | public CommentGeneratorConfiguration() { 32 | } 33 | 34 | public XmlElement toXmlElement() { 35 | XmlElement answer = new XmlElement("commentGenerator"); //$NON-NLS-1$ 36 | if (getConfigurationType() != null) { 37 | answer.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$ 38 | } 39 | 40 | addPropertyXmlElements(answer); 41 | 42 | return answer; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/JavaModelGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class JavaModelGeneratorConfiguration extends PropertyHolder { 30 | 31 | private String targetPackage; 32 | 33 | private String targetProject; 34 | 35 | /** 36 | * 37 | */ 38 | public JavaModelGeneratorConfiguration() { 39 | super(); 40 | } 41 | 42 | public String getTargetProject() { 43 | return targetProject; 44 | } 45 | 46 | public void setTargetProject(String targetProject) { 47 | this.targetProject = targetProject; 48 | } 49 | 50 | public String getTargetPackage() { 51 | return targetPackage; 52 | } 53 | 54 | public void setTargetPackage(String targetPackage) { 55 | this.targetPackage = targetPackage; 56 | } 57 | 58 | public XmlElement toXmlElement() { 59 | XmlElement answer = new XmlElement("javaModelGenerator"); //$NON-NLS-1$ 60 | 61 | if (targetPackage != null) { 62 | answer.addAttribute(new Attribute("targetPackage", targetPackage)); //$NON-NLS-1$ 63 | } 64 | 65 | if (targetProject != null) { 66 | answer.addAttribute(new Attribute("targetProject", targetProject)); //$NON-NLS-1$ 67 | } 68 | 69 | addPropertyXmlElements(answer); 70 | 71 | return answer; 72 | } 73 | 74 | public void validate(List errors, String contextId) { 75 | if (!stringHasValue(targetProject)) { 76 | errors.add(getString("ValidationError.0", contextId)); //$NON-NLS-1$ 77 | } 78 | 79 | if (!stringHasValue(targetPackage)) { 80 | errors.add(getString("ValidationError.12", //$NON-NLS-1$ 81 | "JavaModelGenerator", contextId)); //$NON-NLS-1$ 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/JavaTypeResolverConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import org.mybatis.generator.api.dom.xml.Attribute; 19 | import org.mybatis.generator.api.dom.xml.XmlElement; 20 | 21 | /** 22 | * @author Jeff Butler 23 | */ 24 | public class JavaTypeResolverConfiguration extends TypedPropertyHolder { 25 | 26 | /** 27 | * 28 | */ 29 | public JavaTypeResolverConfiguration() { 30 | super(); 31 | } 32 | 33 | public XmlElement toXmlElement() { 34 | XmlElement answer = new XmlElement("javaTypeResolver"); //$NON-NLS-1$ 35 | if (getConfigurationType() != null) { 36 | answer.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$ 37 | } 38 | 39 | addPropertyXmlElements(answer); 40 | 41 | return answer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/MergeConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | /** 19 | * This class holds constants useful in the XML and Java merging operations. 20 | * 21 | * @author Jeff Butler 22 | * 23 | */ 24 | public class MergeConstants { 25 | 26 | /** 27 | * Utility class - no instances 28 | * 29 | */ 30 | private MergeConstants() { 31 | } 32 | 33 | public static final String[] OLD_XML_ELEMENT_PREFIXES = { 34 | "ibatorgenerated_", "abatorgenerated_" }; //$NON-NLS-1$ //$NON-NLS-2$ 35 | 36 | public static final String NEW_ELEMENT_TAG = "@mbggenerated"; //$NON-NLS-1$ 37 | public static final String[] OLD_ELEMENT_TAGS = { 38 | "@ibatorgenerated", "@abatorgenerated", "@mbggenerated" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/ModelType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.config; 18 | 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | /** 22 | * Typesafe enum of different model types 23 | * 24 | * @author Jeff Butler 25 | */ 26 | public enum ModelType { 27 | HIERARCHICAL("hierarchical"), //$NON-NLS-1$ 28 | FLAT("flat"), //$NON-NLS-1$ 29 | CONDITIONAL("conditional"); //$NON-NLS-1$ 30 | 31 | private final String modelType; 32 | 33 | /** 34 | * 35 | */ 36 | private ModelType(String modelType) { 37 | this.modelType = modelType; 38 | } 39 | 40 | public String getModelType() { 41 | return modelType; 42 | } 43 | 44 | public static ModelType getModelType(String type) { 45 | if (HIERARCHICAL.getModelType().equalsIgnoreCase(type)) { 46 | return HIERARCHICAL; 47 | } else if (FLAT.getModelType().equalsIgnoreCase(type)) { 48 | return FLAT; 49 | } else if (CONDITIONAL.getModelType().equalsIgnoreCase(type)) { 50 | return CONDITIONAL; 51 | } else { 52 | throw new RuntimeException(getString( 53 | "RuntimeError.13", type)); //$NON-NLS-1$ 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/PluginConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * 28 | * @author Jeff Butler 29 | * 30 | */ 31 | public class PluginConfiguration extends TypedPropertyHolder { 32 | public PluginConfiguration() { 33 | } 34 | 35 | public XmlElement toXmlElement() { 36 | XmlElement answer = new XmlElement("plugin"); //$NON-NLS-1$ 37 | if (getConfigurationType() != null) { 38 | answer.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$ 39 | } 40 | 41 | addPropertyXmlElements(answer); 42 | 43 | return answer; 44 | } 45 | 46 | public void validate(List errors, String contextId) { 47 | if (!stringHasValue(getConfigurationType())) { 48 | errors.add(getString("ValidationError.17", //$NON-NLS-1$ 49 | contextId)); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/PropertyHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import java.util.Enumeration; 19 | import java.util.Properties; 20 | 21 | import org.mybatis.generator.api.dom.xml.Attribute; 22 | import org.mybatis.generator.api.dom.xml.XmlElement; 23 | 24 | /** 25 | * @author Jeff Butler 26 | */ 27 | public abstract class PropertyHolder { 28 | private Properties properties; 29 | 30 | /** 31 | * 32 | */ 33 | public PropertyHolder() { 34 | super(); 35 | properties = new Properties(); 36 | } 37 | 38 | public void addProperty(String name, String value) { 39 | properties.setProperty(name, value); 40 | } 41 | 42 | public String getProperty(String name) { 43 | return properties.getProperty(name); 44 | } 45 | 46 | public Properties getProperties() { 47 | return properties; 48 | } 49 | 50 | protected void addPropertyXmlElements(XmlElement xmlElement) { 51 | Enumeration enumeration = properties.propertyNames(); 52 | while (enumeration.hasMoreElements()) { 53 | String propertyName = (String) enumeration.nextElement(); 54 | 55 | XmlElement propertyElement = new XmlElement("property"); //$NON-NLS-1$ 56 | propertyElement.addAttribute(new Attribute("name", propertyName)); //$NON-NLS-1$ 57 | propertyElement.addAttribute(new Attribute( 58 | "value", properties.getProperty(propertyName))); //$NON-NLS-1$ 59 | xmlElement.addElement(propertyElement); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/SqlMapGeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class SqlMapGeneratorConfiguration extends PropertyHolder { 30 | private String targetPackage; 31 | 32 | private String targetProject; 33 | 34 | /** 35 | * 36 | */ 37 | public SqlMapGeneratorConfiguration() { 38 | super(); 39 | } 40 | 41 | public String getTargetProject() { 42 | return targetProject; 43 | } 44 | 45 | public void setTargetProject(String targetProject) { 46 | this.targetProject = targetProject; 47 | } 48 | 49 | public String getTargetPackage() { 50 | return targetPackage; 51 | } 52 | 53 | public void setTargetPackage(String targetPackage) { 54 | this.targetPackage = targetPackage; 55 | } 56 | 57 | public XmlElement toXmlElement() { 58 | XmlElement answer = new XmlElement("sqlMapGenerator"); //$NON-NLS-1$ 59 | 60 | if (targetPackage != null) { 61 | answer.addAttribute(new Attribute("targetPackage", targetPackage)); //$NON-NLS-1$ 62 | } 63 | 64 | if (targetProject != null) { 65 | answer.addAttribute(new Attribute("targetProject", targetProject)); //$NON-NLS-1$ 66 | } 67 | 68 | addPropertyXmlElements(answer); 69 | 70 | return answer; 71 | } 72 | 73 | public void validate(List errors, String contextId) { 74 | if (!stringHasValue(targetProject)) { 75 | errors.add(getString("ValidationError.1", contextId)); //$NON-NLS-1$ 76 | } 77 | 78 | if (!stringHasValue(targetPackage)) { 79 | errors.add(getString("ValidationError.12", //$NON-NLS-1$ 80 | "SQLMapGenerator", contextId)); //$NON-NLS-1$ 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/TypedPropertyHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005, 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | /** 19 | * @author Jeff Butler 20 | */ 21 | public abstract class TypedPropertyHolder extends PropertyHolder { 22 | 23 | private String configurationType; 24 | 25 | /** 26 | * 27 | */ 28 | public TypedPropertyHolder() { 29 | super(); 30 | } 31 | 32 | public String getConfigurationType() { 33 | return configurationType; 34 | } 35 | 36 | /** 37 | * Sets the value of the type specified in the configuration. If the special 38 | * value DEFAULT is specified, then the value will be ignored. 39 | * 40 | * @param configurationType 41 | * the type specified in the configuration 42 | */ 43 | public void setConfigurationType(String configurationType) { 44 | if (!"DEFAULT".equalsIgnoreCase(configurationType)) { //$NON-NLS-1$ 45 | this.configurationType = configurationType; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/xml/ParserEntityResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config.xml; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | 21 | import org.mybatis.generator.codegen.XmlConstants; 22 | import org.xml.sax.EntityResolver; 23 | import org.xml.sax.InputSource; 24 | import org.xml.sax.SAXException; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class ParserEntityResolver implements EntityResolver { 30 | 31 | /** 32 | * 33 | */ 34 | public ParserEntityResolver() { 35 | super(); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, 42 | * java.lang.String) 43 | */ 44 | public InputSource resolveEntity(String publicId, String systemId) 45 | throws SAXException, IOException { 46 | if (XmlConstants.IBATOR_CONFIG_PUBLIC_ID.equalsIgnoreCase(publicId)) { 47 | InputStream is = getClass().getClassLoader().getResourceAsStream( 48 | "org/mybatis/generator/config/xml/ibator-config_1_0.dtd"); //$NON-NLS-1$ 49 | InputSource ins = new InputSource(is); 50 | 51 | return ins; 52 | } else if (XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID 53 | .equalsIgnoreCase(publicId)) { 54 | InputStream is = getClass() 55 | .getClassLoader() 56 | .getResourceAsStream( 57 | "org/mybatis/generator/config/xml/mybatis-generator-config_1_0.dtd"); //$NON-NLS-1$ 58 | InputSource ins = new InputSource(is); 59 | 60 | return ins; 61 | } else { 62 | return null; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/config/xml/ParserErrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config.xml; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | import java.util.List; 21 | 22 | import org.xml.sax.ErrorHandler; 23 | import org.xml.sax.SAXException; 24 | import org.xml.sax.SAXParseException; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class ParserErrorHandler implements ErrorHandler { 30 | private List warnings; 31 | 32 | private List errors; 33 | 34 | /** 35 | * 36 | */ 37 | public ParserErrorHandler(List warnings, List errors) { 38 | super(); 39 | this.warnings = warnings; 40 | this.errors = errors; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * 46 | * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) 47 | */ 48 | public void warning(SAXParseException exception) throws SAXException { 49 | warnings.add(getString("Warning.7", //$NON-NLS-1$ 50 | Integer.toString(exception.getLineNumber()), exception 51 | .getMessage())); 52 | } 53 | 54 | /* 55 | * (non-Javadoc) 56 | * 57 | * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) 58 | */ 59 | public void error(SAXParseException exception) throws SAXException { 60 | errors.add(getString("RuntimeError.4", //$NON-NLS-1$ 61 | Integer.toString(exception.getLineNumber()), exception 62 | .getMessage())); 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * 68 | * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) 69 | */ 70 | public void fatalError(SAXParseException exception) throws SAXException { 71 | errors.add(getString("RuntimeError.4", //$NON-NLS-1$ 72 | Integer.toString(exception.getLineNumber()), exception 73 | .getMessage())); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/exception/InvalidConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.exception; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author Jeff Butler 22 | */ 23 | public class InvalidConfigurationException extends Exception { 24 | static final long serialVersionUID = 4902307610148543411L; 25 | 26 | private List errors; 27 | 28 | /** 29 | * 30 | */ 31 | public InvalidConfigurationException(List errors) { 32 | super(); 33 | this.errors = errors; 34 | } 35 | 36 | public List getErrors() { 37 | return errors; 38 | } 39 | 40 | @Override 41 | public String getMessage() { 42 | if (errors != null && errors.size() > 0) { 43 | return errors.get(0); 44 | } 45 | 46 | return super.getMessage(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/exception/ShellException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.exception; 17 | 18 | /** 19 | * This class is used by the ShellCallback methods to denote unrecoverable 20 | * errors. 21 | * 22 | * @author Jeff Butler 23 | */ 24 | public class ShellException extends Exception { 25 | static final long serialVersionUID = -2026841561754434544L; 26 | 27 | /** 28 | * 29 | */ 30 | public ShellException() { 31 | super(); 32 | } 33 | 34 | /** 35 | * @param arg0 36 | */ 37 | public ShellException(String arg0) { 38 | super(arg0); 39 | } 40 | 41 | /** 42 | * @param arg0 43 | * @param arg1 44 | */ 45 | public ShellException(String arg0, Throwable arg1) { 46 | super(arg0, arg1); 47 | } 48 | 49 | /** 50 | * @param arg0 51 | */ 52 | public ShellException(Throwable arg0) { 53 | super(arg0); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/exception/XMLParserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.exception; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * @author Jeff Butler 23 | */ 24 | public class XMLParserException extends Exception { 25 | 26 | private static final long serialVersionUID = 5172525430401340573L; 27 | 28 | private List errors; 29 | 30 | /** 31 | * 32 | */ 33 | public XMLParserException(List errors) { 34 | super(); 35 | this.errors = errors; 36 | } 37 | 38 | public XMLParserException(String error) { 39 | super(error); 40 | this.errors = new ArrayList(); 41 | errors.add(error); 42 | } 43 | 44 | public List getErrors() { 45 | return errors; 46 | } 47 | 48 | @Override 49 | public String getMessage() { 50 | if (errors != null && errors.size() > 0) { 51 | return errors.get(0); 52 | } 53 | 54 | return super.getMessage(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/NullProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal; 17 | 18 | import org.mybatis.generator.api.ProgressCallback; 19 | 20 | /** 21 | * This class implements a progress callback that does nothing. It is used when 22 | * the client passes in a null for the ProgressCallback. 23 | * 24 | * @author Jeff Butler 25 | */ 26 | public class NullProgressCallback implements ProgressCallback { 27 | 28 | /** 29 | * 30 | */ 31 | public NullProgressCallback() { 32 | super(); 33 | } 34 | 35 | public void generationStarted(int totalTasks) { 36 | } 37 | 38 | public void introspectionStarted(int totalTasks) { 39 | } 40 | 41 | public void saveStarted(int totalTasks) { 42 | } 43 | 44 | public void startTask(String taskName) { 45 | } 46 | 47 | public void checkCancel() throws InterruptedException { 48 | } 49 | 50 | public void done() { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/db/ActualTableName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.internal.db; 18 | 19 | import static org.mybatis.generator.internal.util.StringUtility.composeFullyQualifiedTableName; 20 | 21 | /** 22 | * This class holds the actual catalog, schema, and table name returned from the 23 | * database introspection. 24 | * 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class ActualTableName { 29 | 30 | private String tableName; 31 | private String catalog; 32 | private String schema; 33 | private String fullName; 34 | 35 | public ActualTableName(String catalog, String schema, String tableName) { 36 | this.catalog = catalog; 37 | this.schema = schema; 38 | this.tableName = tableName; 39 | fullName = composeFullyQualifiedTableName(catalog, 40 | schema, tableName, '.'); 41 | } 42 | 43 | public String getCatalog() { 44 | return catalog; 45 | } 46 | 47 | public String getSchema() { 48 | return schema; 49 | } 50 | 51 | public String getTableName() { 52 | return tableName; 53 | } 54 | 55 | @Override 56 | public boolean equals(Object obj) { 57 | if (obj == null || !(obj instanceof ActualTableName)) { 58 | return false; 59 | } 60 | 61 | return obj.toString().equals(this.toString()); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | return fullName.hashCode(); 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return fullName; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/rules/ConditionalModelRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.internal.rules; 18 | 19 | import org.mybatis.generator.api.IntrospectedTable; 20 | 21 | /** 22 | * This class encapsulates all the code generation rules for a table using the 23 | * conditional model. In this model we do not generate primary key or record 24 | * with BLOBs classes if the class would only hold one field. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class ConditionalModelRules extends BaseRules { 30 | 31 | /** 32 | * 33 | */ 34 | public ConditionalModelRules(IntrospectedTable introspectedTable) { 35 | super(introspectedTable); 36 | } 37 | 38 | /** 39 | * We generate a primary key if there is more than one primary key field. 40 | * 41 | * @return true if the primary key should be generated 42 | */ 43 | public boolean generatePrimaryKeyClass() { 44 | return introspectedTable.getPrimaryKeyColumns().size() > 1; 45 | } 46 | 47 | /** 48 | * Generate a base record if there are any base columns, or if there is only 49 | * one primary key coulmn (in which case we will not generate a primary key 50 | * class), or if there is only one BLOB column (in which case we will not 51 | * generate a record with BLOBs class). 52 | * 53 | * @return true if the class should be generated 54 | */ 55 | public boolean generateBaseRecordClass() { 56 | return introspectedTable.getBaseColumns().size() > 0 57 | || introspectedTable.getPrimaryKeyColumns().size() == 1 58 | || (introspectedTable.getBLOBColumns().size() > 0 && !generateRecordWithBLOBsClass()); 59 | 60 | } 61 | 62 | /** 63 | * We generate a record with BLOBs class if there is more than one BLOB 64 | * column. Do not generate a BLOBs class if any other super class would only 65 | * contain one field 66 | * 67 | * @return true if the record with BLOBs class should be generated 68 | */ 69 | public boolean generateRecordWithBLOBsClass() { 70 | int otherColumnCount = introspectedTable.getPrimaryKeyColumns().size() 71 | + introspectedTable.getBaseColumns().size(); 72 | 73 | return otherColumnCount > 1 74 | && introspectedTable.getBLOBColumns().size() > 1; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/rules/FlatModelRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.internal.rules; 18 | 19 | import org.mybatis.generator.api.IntrospectedTable; 20 | 21 | /** 22 | * This class encapsulates all the code generation rules for a table using the 23 | * flat model. 24 | * 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class FlatModelRules extends BaseRules { 29 | 30 | /** 31 | * 32 | */ 33 | public FlatModelRules(IntrospectedTable introspectedTable) { 34 | super(introspectedTable); 35 | } 36 | 37 | /** 38 | * We never generate a primary key in the flat model. 39 | * 40 | * @return true if the primary key should be generated 41 | */ 42 | public boolean generatePrimaryKeyClass() { 43 | return false; 44 | } 45 | 46 | /** 47 | * We always generate a base record in the flat model. 48 | * 49 | * @return true if the class should be generated 50 | */ 51 | public boolean generateBaseRecordClass() { 52 | return true; 53 | } 54 | 55 | /** 56 | * We never generate a record with BLOBs class in the flat model. 57 | * 58 | * @return true if the record with BLOBs class should be generated 59 | */ 60 | public boolean generateRecordWithBLOBsClass() { 61 | return false; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/rules/HierarchicalModelRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.internal.rules; 18 | 19 | import org.mybatis.generator.api.IntrospectedTable; 20 | 21 | /** 22 | * This class encapsulates all the code generation rules for a table using the 23 | * hierarchical model. 24 | * 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class HierarchicalModelRules extends BaseRules { 29 | 30 | /** 31 | * 32 | */ 33 | public HierarchicalModelRules(IntrospectedTable introspectedTable) { 34 | super(introspectedTable); 35 | } 36 | 37 | /** 38 | * Implements the rule for determining whether to generate a primary key 39 | * class. If the physical table has a primary key, then we generate the 40 | * class. 41 | * 42 | * @return true if the primary key should be generated 43 | */ 44 | public boolean generatePrimaryKeyClass() { 45 | return introspectedTable.hasPrimaryKeyColumns(); 46 | } 47 | 48 | /** 49 | * Implements the rule for generating a base record. If the table has fields 50 | * that are not in the primary key, and non-BLOB fields, then generate the 51 | * class. 52 | * 53 | * @return true if the class should be generated 54 | */ 55 | public boolean generateBaseRecordClass() { 56 | return introspectedTable.hasBaseColumns(); 57 | } 58 | 59 | /** 60 | * Implements the rule for generating a record with BLOBs. A record with 61 | * BLOBs is generated if the table contains any BLOB fields. 62 | * 63 | * @return true if the record with BLOBs class should be generated 64 | */ 65 | public boolean generateRecordWithBLOBsClass() { 66 | return introspectedTable.hasBLOBColumns(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/util/ClassloaderUtility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.internal.util; 18 | 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.io.File; 22 | import java.net.MalformedURLException; 23 | import java.net.URL; 24 | import java.net.URLClassLoader; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * This class holds methods useful for constructing custom classloaders. 30 | * 31 | * @author Jeff Butler 32 | * 33 | */ 34 | public class ClassloaderUtility { 35 | 36 | /** 37 | * Utility Class - No Instances 38 | */ 39 | private ClassloaderUtility() { 40 | } 41 | 42 | public static ClassLoader getCustomClassloader(List entries) { 43 | List urls = new ArrayList(); 44 | File file; 45 | 46 | if (entries != null) { 47 | for (String classPathEntry : entries) { 48 | file = new File(classPathEntry); 49 | if (!file.exists()) { 50 | throw new RuntimeException(getString( 51 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 52 | } 53 | 54 | try { 55 | urls.add(file.toURI().toURL()); 56 | } catch (MalformedURLException e) { 57 | // this shouldn't happen, but just in case... 58 | throw new RuntimeException(getString( 59 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 60 | } 61 | } 62 | } 63 | 64 | ClassLoader parent = Thread.currentThread().getContextClassLoader(); 65 | 66 | URLClassLoader ucl = new URLClassLoader(urls.toArray(new URL[urls 67 | .size()]), parent); 68 | 69 | return ucl; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/util/EqualsUtil.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.internal.util; 2 | 3 | /** 4 | * This class is from javapractices.com: 5 | * 6 | * http://www.javapractices.com/Topic17.cjp 7 | * 8 | * Collected methods which allow easy implementation of equals. 9 | * 10 | * Example use case in a class called Car: 11 | * 12 | *
13 |  * public boolean equals(Object that) {
14 |  *     if (this == that)
15 |  *         return true;
16 |  *     if (!(that instanceof Car))
17 |  *         return false;
18 |  *     Car thatCar = (Car) that;
19 |  *     return EqualsUtil.areEqual(this.fName, that.fName)
20 |  *             && EqualsUtil.areEqual(this.fNumDoors, that.fNumDoors)
21 |  *             && EqualsUtil.areEqual(this.fGasMileage, that.fGasMileage)
22 |  *             && EqualsUtil.areEqual(this.fColor, that.fColor)
23 |  *             && Arrays.equals(this.fMaintenanceChecks, that.fMaintenanceChecks); //array!
24 |  * }
25 |  * 
26 | * 27 | * Arrays are not handled by this class. This is because the 28 | * Arrays.equals methods should be used for array fields. 29 | */ 30 | public final class EqualsUtil { 31 | 32 | static public boolean areEqual(boolean aThis, boolean aThat) { 33 | return aThis == aThat; 34 | } 35 | 36 | static public boolean areEqual(char aThis, char aThat) { 37 | return aThis == aThat; 38 | } 39 | 40 | static public boolean areEqual(long aThis, long aThat) { 41 | /* 42 | * Implementation Note Note that byte, short, and int are handled by 43 | * this method, through implicit conversion. 44 | */ 45 | return aThis == aThat; 46 | } 47 | 48 | static public boolean areEqual(float aThis, float aThat) { 49 | return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat); 50 | } 51 | 52 | static public boolean areEqual(double aThis, double aThat) { 53 | return Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat); 54 | } 55 | 56 | /** 57 | * Possibly-null object field. 58 | * 59 | * Includes type-safe enumerations and collections, but does not include 60 | * arrays. See class comment. 61 | */ 62 | static public boolean areEqual(Object aThis, Object aThat) { 63 | return aThis == null ? aThat == null : aThis.equals(aThat); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/internal/util/messages/Messages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.util.messages; 17 | 18 | import java.text.MessageFormat; 19 | import java.util.MissingResourceException; 20 | import java.util.ResourceBundle; 21 | 22 | /** 23 | * @author Jeff Butler 24 | */ 25 | public class Messages { 26 | private static final String BUNDLE_NAME = "org.mybatis.generator.internal.util.messages.messages"; //$NON-NLS-1$ 27 | 28 | private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle 29 | .getBundle(BUNDLE_NAME); 30 | 31 | private Messages() { 32 | } 33 | 34 | public static String getString(String key) { 35 | try { 36 | return RESOURCE_BUNDLE.getString(key); 37 | } catch (MissingResourceException e) { 38 | return '!' + key + '!'; 39 | } 40 | } 41 | 42 | public static String getString(String key, String parm1) { 43 | try { 44 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), 45 | new Object[] { parm1 }); 46 | } catch (MissingResourceException e) { 47 | return '!' + key + '!'; 48 | } 49 | } 50 | 51 | public static String getString(String key, String parm1, String parm2) { 52 | try { 53 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), 54 | new Object[] { parm1, parm2 }); 55 | } catch (MissingResourceException e) { 56 | return '!' + key + '!'; 57 | } 58 | } 59 | 60 | public static String getString(String key, String parm1, String parm2, 61 | String parm3) { 62 | try { 63 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), 64 | new Object[] { parm1, parm2, parm3 }); 65 | } catch (MissingResourceException e) { 66 | return '!' + key + '!'; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/logging/AbstractLogFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.logging; 18 | 19 | /** 20 | * Defines the interface for creating Log implementations. 21 | * 22 | * @author Jeff Butler 23 | * 24 | */ 25 | public interface AbstractLogFactory { 26 | Log getLog(Class aClass); 27 | } 28 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/logging/JdkLoggingImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.logging; 17 | 18 | import java.util.logging.Level; 19 | import java.util.logging.LogRecord; 20 | import java.util.logging.Logger; 21 | 22 | /** 23 | * 24 | * @author Clinton Begin 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class JdkLoggingImpl implements Log { 29 | 30 | private Logger log; 31 | 32 | public JdkLoggingImpl(Class clazz) { 33 | log = Logger.getLogger(clazz.getName()); 34 | } 35 | 36 | public boolean isDebugEnabled() { 37 | return log.isLoggable(Level.FINE); 38 | } 39 | 40 | public void error(String s, Throwable e) { 41 | LogRecord lr = new LogRecord(Level.SEVERE, s); 42 | lr.setSourceClassName(log.getName()); 43 | lr.setThrown(e); 44 | 45 | log.log(lr); 46 | } 47 | 48 | public void error(String s) { 49 | LogRecord lr = new LogRecord(Level.SEVERE, s); 50 | lr.setSourceClassName(log.getName()); 51 | 52 | log.log(lr); 53 | } 54 | 55 | public void debug(String s) { 56 | LogRecord lr = new LogRecord(Level.FINE, s); 57 | lr.setSourceClassName(log.getName()); 58 | 59 | log.log(lr); 60 | } 61 | 62 | public void warn(String s) { 63 | LogRecord lr = new LogRecord(Level.WARNING, s); 64 | lr.setSourceClassName(log.getName()); 65 | 66 | log.log(lr); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/logging/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.logging; 17 | 18 | /** 19 | * 20 | * @author Clinton Begin 21 | */ 22 | public interface Log { 23 | 24 | boolean isDebugEnabled(); 25 | 26 | void error(String s, Throwable e); 27 | 28 | void error(String s); 29 | 30 | public void debug(String s); 31 | 32 | public void warn(String s); 33 | } 34 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/logging/Log4jImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.logging; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | /** 21 | * 22 | * @author Clinton Begin 23 | * 24 | */ 25 | public class Log4jImpl implements Log { 26 | 27 | private Logger log; 28 | 29 | public Log4jImpl(Class clazz) { 30 | log = Logger.getLogger(clazz); 31 | } 32 | 33 | public boolean isDebugEnabled() { 34 | return log.isDebugEnabled(); 35 | } 36 | 37 | public void error(String s, Throwable e) { 38 | log.error(s, e); 39 | } 40 | 41 | public void error(String s) { 42 | log.error(s); 43 | } 44 | 45 | public void debug(String s) { 46 | log.debug(s); 47 | } 48 | 49 | public void warn(String s) { 50 | log.warn(s); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/logging/LogFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.logging; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | import org.mybatis.generator.internal.ObjectFactory; 21 | 22 | /** 23 | * Factory for creating loggers. Uses runtime introspection to determine the 24 | * AbstractLogFactory implementation. 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class LogFactory { 30 | private static AbstractLogFactory logFactory; 31 | 32 | static { 33 | try { 34 | ObjectFactory.internalClassForName("org.apache.log4j.Logger"); //$NON-NLS-1$ 35 | logFactory = new Log4jLoggingLogFactory(); 36 | } catch (Exception e) { 37 | logFactory = new JdkLoggingLogFactory(); 38 | } 39 | } 40 | 41 | public static Log getLog(Class clazz) { 42 | try { 43 | return logFactory.getLog(clazz); 44 | } catch (Throwable t) { 45 | throw new RuntimeException(getString("RuntimeError.21", //$NON-NLS-1$ 46 | clazz.getName(), t.getMessage()), t); 47 | } 48 | } 49 | 50 | /** 51 | * This method will switch the logging implementation to Java native 52 | * logging. This is useful in situations where you want to use Java native 53 | * logging to log activity but Log4J is on the classpath. Note that 54 | * this method is only effective for log classes obtained after calling this 55 | * method. If you intend to use this method you should call it before 56 | * calling any other method. 57 | */ 58 | public static synchronized void forceJavaLogging() { 59 | logFactory = new JdkLoggingLogFactory(); 60 | } 61 | 62 | private static class JdkLoggingLogFactory implements AbstractLogFactory { 63 | public Log getLog(Class clazz) { 64 | return new JdkLoggingImpl(clazz); 65 | } 66 | } 67 | 68 | private static class Log4jLoggingLogFactory implements AbstractLogFactory { 69 | public Log getLog(Class clazz) { 70 | return new Log4jImpl(clazz); 71 | } 72 | } 73 | 74 | public static void setLogFactory(AbstractLogFactory logFactory) { 75 | LogFactory.logFactory = logFactory; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/VirtualPrimaryKeyPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The MyBatis Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.plugins; 17 | 18 | import java.util.List; 19 | import java.util.StringTokenizer; 20 | 21 | import org.mybatis.generator.api.IntrospectedTable; 22 | import org.mybatis.generator.api.PluginAdapter; 23 | 24 | /** 25 | * This plugin can be used to specify columns that act as a primary key, even if 26 | * they are not strictly defined as primary keys in the database. 27 | * 28 | * To use the plugin, add a property to the table configuration specifying a 29 | * comma delimited list of column names to use as a primary key: 30 | * 31 | * 32 | * 33 | * 34 | * 35 | * @author Jeff Butler 36 | * 37 | */ 38 | public class VirtualPrimaryKeyPlugin extends PluginAdapter { 39 | 40 | public boolean validate(List warnings) { 41 | return true; 42 | } 43 | 44 | @Override 45 | public void initialized(IntrospectedTable introspectedTable) { 46 | String virtualKey = introspectedTable.getTableConfiguration() 47 | .getProperty("virtualKeyColumns"); //$NON-NLS-1$ 48 | 49 | if (virtualKey != null) { 50 | StringTokenizer st = new StringTokenizer(virtualKey, ", ", false); //$NON-NLS-1$ 51 | while (st.hasMoreTokens()) { 52 | String column = st.nextToken(); 53 | introspectedTable.addPrimaryKeyColumn(column); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fitzyyf/mybatisn_generator_cn/88f16c343d8540c96b6558de6b8ebbd27e28704e/mybatis-generator-core/src/site/resources/images/logo.png -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/resources/mbgstyle.css: -------------------------------------------------------------------------------- 1 | /* custom stylesheet - used to override any maven style, and as a placeholder 2 | * for the eclipse help stylesheet 3 | */ 4 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/configreference/classPathEntry.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | The <classPathEntry> Element 7 | 8 | 9 | 10 |

The <classPathEntry> Element

11 |

The <classPathEntry> element is used to add classpath locations to the 12 | classpath of the MyBatis Generator (MBG) run. The <classPathEntry> element is an option child 13 | element of the <generatorConfiguration> element. 14 | MBG loads classes from these locations in these instances:

15 |
    16 |
  • When loading the JDBC driver for database introspection
  • 17 |
  • When loading root classes in the JavaModelGenerator to check for overridden 18 | methods
  • 19 |
20 | 21 |

This element is optional and is not required if you setup the classpath externally to MBG 22 | (e.g. with the -cp argument of the java command

23 | 24 |

Important Note: these locations are NOT used when loading classes that 25 | extend one of MBG's classes or implement one of MBG's interfaces. In those cases 26 | you must add your external classes to the runtime classpath in the same way you 27 | add MBG to the classpath (e.g. with the -cp argument of the 28 | java command).

29 | 30 |

Required Attributes

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 |
AttributeDescription
locationThe full path name of a JAR/ZIP file to add to the classpath, or 39 | a directory to add to the classpath.
42 | 43 |

Optional Attributes

44 |

None

45 | 46 |

Child Elements

47 |

None

48 | 49 | 50 |

Example

51 |

This element specifies the location of a DB2 JDBC driver:

52 |
53 | <classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />
54 | 
55 | 56 | 57 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/configreference/generatorConfiguration.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | The <generatorConfiguration> Element 7 | 8 | 9 | 10 |

The <generatorConfiguration> Element

11 |

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

14 |
15 | <!DOCTYPE generatorConfiguration PUBLIC
16 |   "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
17 |   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
18 | 
19 | 20 |

Required Attributes

21 |

None

22 | 23 |

Optional Attributes

24 |

None

25 | 26 |

Child Elements

27 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/configreference/ignoreColumn.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | The <ignoreColumn> Element 7 | 8 | 9 | 10 |

The <ignoreColumn> Element

11 |

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

16 | 17 |

Required Attributes

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
AttributeDescription
columnThe column name of the ignored column.
28 | 29 |

Optional Attributes

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 40 | 41 |
AttributeDescription
delimitedColumnNameIf true then MBG will perform a case-sensitive exact 38 | match when matching against returned columns from the database. If 39 | false (default) then the name is considered case-insensitive.
42 | 43 |

Child Elements

44 |

None

45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/configreference/jdbcConnection.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | The <jdbcConnection> Element 7 | 8 | 9 | 10 |

The <jdbcConnection> Element

11 |

The <jdbcConnection> element is used to specify the properties of 12 | the database connection required to introspect tables. MyBatis Generator uses JDBC's 13 | DatabaseMetaData class to discover the properties of the tables you specify 14 | in the configuration. One <jdbcConnection> element is required for 15 | each <context> element.

16 | 17 |

Required Attributes

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 |
AttributeDescription
driverClassThe fully qualified class name for the JDBC driver used to access the 26 | database. 27 |
connectionURLThe JDBC connection URL used to access the database.
34 | 35 |

Optional Attributes

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
AttributeDescription
userIdThe user ID used to connect to the database.
passwordThe password used to connect to the database.
50 | 51 |

Child Elements

52 |
    53 |
  • <property> (0..N) 54 | Note: any properties specified here will be added to the 55 | properties of the JDBC driver.
  • 56 |
57 | 58 |

Example

59 |

This element will connect to a DB2 database configured as 60 | MBGTEST in the DB2 client configuration utility, using 61 | the default install location for the JDBC driver:

62 |
63 | <jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver"
64 |     connectionURL="jdbc:db2:MBGTEST"
65 |     userId="db2admin"
66 |     password="db2admin">
67 | </jdbcConnection>
68 | 
69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/configreference/plugin.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | The <plugin> Element 7 | 8 | 9 | 10 |

The <plugin> Element

11 |

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

16 | 17 |

For more information about implementing plugins, see the 18 | Implementing Plugins reference 19 | page.

20 | 21 |

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

24 | 25 |

Required Attributes

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 40 | 41 |
AttributeDescription
typeThe fully qualified name of the class that implements the plugin. 34 | The class must implement the interface 35 | org.mybatis.generator.api.Plugin, 36 | and must have a public default constructor. Note that it is far 37 | easier to extend the adapter class 38 | org.mybatis.generator.api.PluginAdapter 39 | than to implement the entire interface.
42 | 43 |

Optional Attributes

44 |

None

45 | 46 |

Child Elements

47 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/configreference/properties.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | The <properties> Element 7 | 8 | 9 | 10 |

The <properties> Element

11 |

The <properties> element is used to specify an external properties file 12 | for use in the parsing of the configuration. Any attribute in the 13 | configuration will accept a property in the form ${property}. 14 | The specified properties file will be searched for a matching value and the 15 | matching value will be substituted. The properties file is of the normal 16 | format for a Java properties file.

17 | 18 |

The <properties> element is a child element of the 19 | <generatorConfiguration> 20 | element.

21 | 22 | 23 |

Required Attributes

24 |

One, and only one, of the following attributes is required.

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 36 | 37 | 38 | 39 | 42 | 43 |
AttributeDescription
resourceThe qualified name of the property file. When specifying the resource, the 33 | classpath will be searched for the properties file. So a file specified as 34 | com/myproject/generatorConfig.properties must exist in the 35 | com.myproject package.
urlA URL value to use for the property file. This can be used to specify a property 40 | file in a specific place on the file system when used in a form like 41 | file:///C:/myfolder/generatorConfig.properties.
44 | 45 |

Optional Attributes

46 |

None

47 | 48 |

Child Elements

49 |

None

50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/configreference/property.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | The <property> Element 7 | 8 | 9 | 10 |

The <property> Element

11 |

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

16 | 17 |

Required Attributes

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
AttributeDescription
nameThe name of the property (case sensitive).
valueThe value of the property (typically case insensitive).
32 | 33 |

Optional Attributes

34 |

None

35 | 36 |

Child Elements

37 |

None

38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/generatedobjects/results.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Using the Generated Objects 7 | 8 | 9 | 10 |

Using the Generated Objects

11 |

MyBatis Generator (MBG) generates these types of objects:

12 |
    13 |
  1. Java Model Objects (always)
  2. 14 |
  3. SQL Map Files (always for iBATIS, usually for MyBatis)
  4. 15 |
  5. Java Client Objects (optional)
  6. 16 |
  7. A class for use in the xxxByExample methods. See the following pages for 17 | information about that class: 18 | 22 |
  8. 23 |
24 | 25 |

The individual pages describe these objects, and their usage.

26 | 27 | 28 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/license.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Licensing Information 7 | 8 | 9 | 10 |

Licensing Information

11 |

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

15 |

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

17 |

18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 |

24 | 25 |

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

27 | 28 |

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

30 | 31 | 32 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/migratingFromIbator.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Migrating from Ibator 7 | 8 | 9 | 10 |

Migrating from Ibator

11 |

This page details changes between MyBatis Generator (MBG) 12 | and Ibator. For most users, the changes should be simple. 13 | If you extended any of Ibator's classes to supply custom implementations 14 | of code generators or the Java type resolver, you will need to rework 15 | those custom classes.

16 |

Changes 17 | are described assuming you are using XML configuration for MBG. If you 18 | are using Java based configuration, then the changes are still required 19 | and should be easy to deduce from the description of the XML changes.

20 |

Important Note: MBG will correctly parse older Ibator configuration files, so no change is actually 21 | required. However, new features will only be implemented in configuration files 22 | that conform to the MyBatis Generator DTD.

23 |

Required for Some Users

24 |
    25 |
  • The DTD has changed. The new DOCTYPE should be 26 |
    27 | 
    28 | <!DOCTYPE generatorConfiguration
    29 |   PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    30 |   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
    31 |     
    32 |
  • 33 |
  • MyBatis3 is now the default target runtime.
  • 34 |
  • The <ibatorConfiguration> element is renamed to 35 | <generatorConfiguration>
  • 36 |
  • The <ibatorContext> element is renamed to 37 | <context>
  • 38 |
  • The <ibatorPlugin> element is renamed to 39 | <plugin>
  • 40 |
  • The <daoGenerator> element is renamed to 41 | <javaClientGenerator>
  • 42 |
  • If you implemented a plugin, the daoXXX methods have been renamed 43 | to clientXXX.
  • 44 |
45 | 46 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/quickstart.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | MyBatis Generator Quick Start Guide 7 | 8 | 9 | 10 |

MyBatis Generator Quick Start Guide

11 |

To get up and running quickly with MyBatis Generator (MBG), follow these steps:

12 |
    13 |
  1. Create and fill out a configuration file appropriately. 14 | At a minimum, you must specify: 15 |
      16 |
    1. A <jdbcConnection> element to specify how to connect to 17 | the target database
    2. 18 |
    3. A <javaModelGenerator> element to specify target package 19 | and target project for generated Java model objects
    4. 20 |
    5. A <sqlMapGenerator> element to specify target package 21 | and target project for generated SQL map files
    6. 22 |
    7. (Optionally) A <javaClientGenerator> element to specify target package 23 | and target project for generated client interfaces and classes (you may 24 | omit the <javaClientGenerator> element if you don't wish to generate Java client code)
    8. 25 |
    9. At least one database <table> element
    10. 26 |
    27 |

    See the XML Configuration File Reference 28 | page for an example of a configuration file.

    29 |
  2. 30 |
  3. Save the file in some convenient location (like \temp\generatorConfig.xml)
  4. 31 |
  5. Run MBG from the command line with a command like this: 32 |
    33 | 
    34 |       java -jar mybatis-generator-core-x.x.x.jar -configfile \temp\generatorConfig.xml -overwrite
    35 |     
    36 |

    This will tell MBG to run using your configuration file. It will also tell MBG 37 | to overwrite any existing Java files with the same name. If you want to save any existing 38 | Java files, then omit the -overwrite parameter. If there is a conflict, MBG 39 | will save the newly generated file with a unique name (e.g. MyClass.java.1).

    40 |
  6. 41 |
  7. After running MBG, you will need to create or modify the standard MyBatis or iBATIS 42 | configuration files to make use of your newly generated code. See the 43 | Tasks After Running MyBatis Generator page for more 44 | information.
  8. 45 |
46 |

Important: Generated code for iBATIS2 requires that statement namespaces are enabled 47 | in your iBATIS configuration. See the Tasks After Running MyBatis Generator 48 | page for more information.

49 | 50 | 51 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/reference/building.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Building from Source 7 | 8 | 9 | 10 |

Building from Source

11 |

All MyBatis Generator (MBG) distributions include source code. The only compile time dependency 12 | is on ant.jar - for successful compilation of the included Ant task. 13 | It is straight forward to compile MBG from source - simply unzip the source in 14 | a distribution and compile it with your favorite tool.

15 |

The MBG distribution does not contain the tests that are run during the build, 16 | or other classes that are a necessary part of the build. If you would like to 17 | inspect those classes, or build MBG from the very latest version of the source code 18 | at Google then follow these steps:

19 |
    20 |
  1. MBG is built with Apache Maven. First you must get maven 21 | running. If you are new to Maven, here are the most simple steps (for Windows): 22 |
      23 |
    1. Download a Maven distribution from 24 | http://maven.apache.org/
    2. 25 |
    3. Unzip the distribution somewhere convenient
    4. 26 |
    5. Setup environment variables and the PATH. Examples:
      27 | set JAVA_HOME=C:\JavaTools\jdk1.6.0_17
      28 | set M2_HOME=C:\JavaTools\apache-maven-3.0
      29 | set PATH=%PATH%;%M2_HOME%\bin; 30 |
    6. 31 |
    32 |
  2. 33 |
  3. Do a Subversion checkout of the source tree from the location 34 | 35 | https://mybatis.googlecode.com/svn/sub-projects/generator/trunk/core/ 36 | (You may use any Subversion client you prefer. We recommend 37 | TortoiseSVN.) 38 |
  4. 39 |
  5. Open a command window in the directory where you checked out the source and 40 | run the command mvn clean install - or any of the other Maven lifecycle commands. 41 | You can use the mvn site command to generate the code coverage reports, but the 42 | MyBatis website is not built with Maven at this time. 43 |
  6. 44 |
45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/reference/intro.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Reference Information 7 | 8 | 9 | 10 |

Reference Information

11 |

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

13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/running/running.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Running MyBatis Generator 7 | 8 | 9 | 10 |

Running MyBatis Generator

11 |

MyBatis Generator (MBG) can be run in the following ways:

12 | 21 |

Each method is described in detail on the linked pages.

22 |

Note: there is also an Eclipse 23 | plugin for MBG that adds extra function - namely good integration into Eclipse, 24 | an Eclipse enabled Ant task, and support for automatic merging of 25 | Java files. See the 26 | MyBatis 27 | web site page for information on installing the Eclipse plugin.

28 | 29 |

Important: When running outside of an IDE environment like Eclipse, 30 | MBG interprets the targetProject and 31 | targetPackage attributes in all XML configurations as follows:

32 |
    33 |
  • targetProject is assumed to be an existing directory structure. 34 | MBG will fail if this directory structure does not exist. There is one exception to this 35 | rule - when MBG is running through the Maven plugin. See the Maven plugin page 36 | for information about how targetProject is interpreted in Maven.
  • 37 |
  • targetPackage will be translated to a suitable subdirectory 38 | structure of the targetProject 39 | directory structure. MBG will create these subdirectories if necessary.
  • 40 |
41 | 42 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/running/runningWithJava.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Running MyBatis Generator With Java 7 | 8 | 9 | 10 |

Running MyBatis Generator With Java

11 |

MyBatis Generator (MBG) may be invoked directly from Java. For configuration, 12 | you may use either an XML configuration file, or configure MBG completely with 13 | Java.

14 |

Running MBG from Java with an XML Configuration File

15 |

The following code sample shows how to call MBG from Java with an XML based configuration. 16 | It does not 17 | show exception handling, but that should be obvious from the compiler 18 | errors :)

19 |
20 |    List<String> warnings = new ArrayList<String>();
21 |    boolean overwrite = true;
22 |    File configFile = new File("generatorConfig.xml");
23 |    ConfigurationParser cp = new ConfigurationParser(warnings);
24 |    Configuration config = cp.parseConfiguration(configFile);
25 |    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
26 |    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
27 |    myBatisGenerator.generate(null);
28 | 
29 | 30 |

Notes:

31 |
    32 |
  • Configuration file properties may be passed to the parser as a parameter on 33 | the ConfigurationParser constructor. If not passed explicitly, the JVM 34 | system properties will be searched for the value of configuration file 35 | properties. For example, the property 36 | generated.source.dir can be 37 | accessed in the configuration file with the escape sequence 38 | ${generated.source.dir} 39 |
  • 40 |
  • If a property is specified in the configuration file and is not resolved, 41 | then the escaped property string will be passed "as is" into the generated code. 42 |
  • 43 |
44 | 45 |

Running MBG from Java with a Java Based Configuration

46 |

The following code sample shows how to call MBG from Java with a Java based configuration. 47 | It does 48 | not show exception handling, but that should be obvious from the compiler 49 | errors :)

50 |
51 |    List<String> warnings = new ArrayList<String>();
52 |    boolean overwrite = true;
53 |    Configuration config = new Configuration();
54 | 
55 |    //   ... fill out the config object as appropriate...
56 | 
57 |    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
58 |    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
59 |    myBatisGenerator.generate(null);
60 | 
61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/usage/db2.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | DB2 Usage Notes 7 | 8 | 9 | 10 |

DB2 Usage Notes

11 |

LONG VARCHAR Fields

12 |

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

17 |
18 |   <table schema="DB2ADMIN" tableName="ALLTYPES" >
19 |     <columnOverride column="LONG_VARCHAR_FIELD" javaType="java.lang.String" jdbcType="VARCHAR" />
20 |   </table>
21 | 
22 | 23 | 24 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/usage/intro.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Usage Notes 7 | 8 | 9 | 10 |

Usage Notes

11 |

This section collects usage information for different databases.

12 | 13 | 19 |

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

22 | 23 | 24 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/usage/mysql.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | MySql Usage Notes 7 | 8 | 9 | 10 |

MySql Usage Notes

11 |

Unsigned Fields

12 |

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

18 |
19 |   <table tableName="ALLTYPES" >
20 |     <columnOverride column="UNSIGNED_BIGINT_FIELD" javaType="java.lang.Object" jdbcType="LONG" />
21 |   </table>
22 | 
23 |

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

25 | 26 | 27 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/usage/oracle.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Oracle Usage Notes 7 | 8 | 9 | 10 |

Oracle Usage Notes

11 |

Public Synonyms

12 |

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

15 |

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

18 |
19 |   <table schema="HR" tableName="EMPLOYEES">
20 |     <property name="ignoreQualifiersAtRuntime" value="true" />
21 |     <property name="runtimeTableName" value="FRED" />
22 |   </table>
23 | 
24 |

Oracle LONG Datatype

25 |

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

29 | 30 | 31 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/site/xhtml/usage/postgresql.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | PostgreSQL Usage Notes 7 | 8 | 9 | 10 |

PostgreSQL Usage Notes

11 |

Case Sensitivity

12 |

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

19 |
    20 |
  • Use the delimitIdentifiers option if your table or schema 21 | is mixed case or all upper case.
  • 22 |
  • For each mixed case or upper case column you could specify a 23 | <columnOverride> element to specifically delimit the column, 24 | or you could specify the delimitAllColumns attribute 25 | to delimit all column names.
  • 26 |
27 |

Examples:

28 |
29 |   <table schema="HR" tableName="Employees"
30 |       delimitIdentifiers="true" delimitAllColumns="true"/>
31 | 
32 |

Or...

33 |
34 |   <table schema="HR" tableName="Employees" delimitIdentifiers="true" >
35 |     <columnOverride column="EmployeeId" delimitedColumnName="true" />
36 |     <columnOverride column="EmployeeName" delimitedColumnName="true" />
37 |   </table>
38 | 
39 | 40 | 41 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/test/java/org/mybatis/generator/MyBatisGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.mybatis.generator.api.MyBatisGenerator; 10 | import org.mybatis.generator.config.Configuration; 11 | import org.mybatis.generator.config.xml.ConfigurationParser; 12 | import org.mybatis.generator.exception.InvalidConfigurationException; 13 | import org.mybatis.generator.internal.DefaultShellCallback; 14 | 15 | public class MyBatisGeneratorTest { 16 | 17 | @Test(expected=InvalidConfigurationException.class) 18 | public void testGenerateMyBatis3() throws Exception { 19 | List warnings = new ArrayList(); 20 | ConfigurationParser cp = new ConfigurationParser(warnings); 21 | Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3.xml")); 22 | 23 | DefaultShellCallback shellCallback = new DefaultShellCallback(true); 24 | 25 | try { 26 | MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings); 27 | myBatisGenerator.generate(null); 28 | } catch (InvalidConfigurationException e) { 29 | assertEquals(2, e.getErrors().size()); 30 | throw e; 31 | } 32 | } 33 | 34 | @Test(expected=InvalidConfigurationException.class) 35 | public void testGenerateIbatis2() throws Exception { 36 | List warnings = new ArrayList(); 37 | ConfigurationParser cp = new ConfigurationParser(warnings); 38 | Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigIbatis2.xml")); 39 | 40 | DefaultShellCallback shellCallback = new DefaultShellCallback(true); 41 | 42 | try { 43 | MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings); 44 | myBatisGenerator.generate(null); 45 | } catch (InvalidConfigurationException e) { 46 | assertEquals(1, e.getErrors().size()); 47 | throw e; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/test/resources/generatorConfigIbatis2.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 |
33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
46 | -------------------------------------------------------------------------------- /mybatis-generator-core/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # log4j.properties for 2 | 3 | # Set root category priority to ERROR and its only appender to LOGFILE. 4 | log4j.rootCategory=ERROR, CONSOLE 5 | 6 | #Spring Framework 7 | #log4j.logger.org.springframework=DEBUG 8 | #log4j.logger.org.springframework.orm=DEBUG 9 | #log4j.logger.org.springframework.transaction=DEBUG 10 | 11 | # CONSOLE is set to be a ConsoleAppender using a PatternLayout. 12 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 13 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 14 | log4j.appender.CONSOLE.layout.ConversionPattern=%-d{HH:mm:ss} %-5p %60.60c %-25.25M %m%n 15 | -------------------------------------------------------------------------------- /mybatis-generator-maven-plugin/NOTICE: -------------------------------------------------------------------------------- 1 | This product includes software developed by 2 | The Apache Software Foundation (http://www.apache.org/). 3 | 4 | This product includes the EqualsUtil and HashCodeUtil classes 5 | from http://www.javapractices.com. 6 | -------------------------------------------------------------------------------- /mybatis-generator-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 4.0.0 23 | 24 | org.mybatis.generator 25 | mybatis-generator 26 | 1.3.3-SNAPSHOT 27 | 28 | 29 | mybatis-generator-maven-plugin 30 | maven-plugin 31 | MyBatis Generator Maven Plugin 32 | 33 | 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-release-plugin 38 | 39 | -Prelease 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.apache.maven 48 | maven-plugin-api 49 | 50 | 51 | junit 52 | junit 53 | test 54 | 55 | 56 | org.mybatis.generator 57 | mybatis-generator-core 58 | ${project.version} 59 | 60 | 61 | org.apache.maven 62 | maven-project 63 | 64 | 65 | 66 | 67 | https://mybatis.googlecode.com/svn/sub-projects/generator/trunk/core/mybatis-generator-maven-plugin 68 | scm:svn:https://mybatis.googlecode.com/svn/sub-projects/generator/trunk/core/mybatis-generator-maven-plugin 69 | scm:svn:https://mybatis.googlecode.com/svn/sub-projects/generator/trunk/core/mybatis-generator-maven-plugin 70 | 71 | 72 | -------------------------------------------------------------------------------- /mybatis-generator-maven-plugin/src/main/java/org/mybatis/generator/maven/MavenProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.maven; 18 | 19 | import org.apache.maven.plugin.logging.Log; 20 | import org.mybatis.generator.internal.NullProgressCallback; 21 | 22 | /** 23 | * This callback logs progress messages with the Maven logger 24 | * 25 | * @author Jeff Butler 26 | * 27 | */ 28 | public class MavenProgressCallback extends NullProgressCallback { 29 | 30 | private Log log; 31 | private boolean verbose; 32 | 33 | /** 34 | * 35 | */ 36 | public MavenProgressCallback(Log log, boolean verbose) { 37 | super(); 38 | this.log = log; 39 | this.verbose = verbose; 40 | } 41 | 42 | @Override 43 | public void startTask(String subTaskName) { 44 | if (verbose) { 45 | log.info(subTaskName); 46 | } 47 | } 48 | } 49 | --------------------------------------------------------------------------------