├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── maven-plugin ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── ihansen │ └── mbp │ └── extend │ └── maven │ ├── MavenLogFactory.java │ ├── MavenLogImpl.java │ ├── MavenProgressCallback.java │ ├── MavenShellCallback.java │ ├── MyBatisGeneratorMojo.java │ └── SqlScriptRunner.java ├── pom.xml └── src ├── main ├── java │ └── org │ │ ├── ihansen │ │ └── mbp │ │ │ └── extend │ │ │ ├── CustJavaTypeResolver.java │ │ │ ├── CustomPlugin.java │ │ │ ├── CustomSerializablePlugin.java │ │ │ ├── DBSupport.java │ │ │ ├── dbSupport │ │ │ ├── MysqlSupport.java │ │ │ ├── OracleSupport.java │ │ │ └── SqlServerSupport.java │ │ │ ├── generator │ │ │ ├── AbstractJavaMapperMethodGenerator.java │ │ │ ├── AbstractXmlElementGenerator.java │ │ │ ├── SelectByBigOffsetMethodGenerator.java │ │ │ ├── SelectByBigOffsetMysqlElementGenerator.java │ │ │ ├── UpdateByOptimisticLockMethodGenerator.java │ │ │ └── UpdateByOptimisticLockMysqlElementGenerator.java │ │ │ └── java │ │ │ └── CustomInterface.java │ │ └── mybatis │ │ └── generator │ │ ├── api │ │ ├── CommentGenerator.java │ │ ├── DAOMethodNameCalculator.java │ │ ├── FullyQualifiedTable.java │ │ ├── GeneratedFile.java │ │ ├── GeneratedJavaFile.java │ │ ├── GeneratedXmlFile.java │ │ ├── IntrospectedColumn.java │ │ ├── IntrospectedTable.java │ │ ├── JavaFormatter.java │ │ ├── JavaTypeResolver.java │ │ ├── MyBatisGenerator.java │ │ ├── Plugin.java │ │ ├── PluginAdapter.java │ │ ├── ProgressCallback.java │ │ ├── ShellCallback.java │ │ ├── ShellRunner.java │ │ ├── VerboseProgressCallback.java │ │ ├── XmlFormatter.java │ │ ├── dom │ │ │ ├── DefaultJavaFormatter.java │ │ │ ├── DefaultXmlFormatter.java │ │ │ ├── OutputUtilities.java │ │ │ ├── java │ │ │ │ ├── CompilationUnit.java │ │ │ │ ├── Field.java │ │ │ │ ├── FullyQualifiedJavaType.java │ │ │ │ ├── InitializationBlock.java │ │ │ │ ├── InnerClass.java │ │ │ │ ├── InnerEnum.java │ │ │ │ ├── Interface.java │ │ │ │ ├── JavaElement.java │ │ │ │ ├── JavaVisibility.java │ │ │ │ ├── Method.java │ │ │ │ ├── Parameter.java │ │ │ │ ├── PrimitiveTypeWrapper.java │ │ │ │ ├── TopLevelClass.java │ │ │ │ └── TopLevelEnumeration.java │ │ │ └── xml │ │ │ │ ├── Attribute.java │ │ │ │ ├── Document.java │ │ │ │ ├── Element.java │ │ │ │ ├── TextElement.java │ │ │ │ └── XmlElement.java │ │ └── package.html │ │ ├── codegen │ │ ├── AbstractGenerator.java │ │ ├── AbstractJavaClientGenerator.java │ │ ├── AbstractJavaGenerator.java │ │ ├── AbstractXmlGenerator.java │ │ ├── RootClassInfo.java │ │ ├── XmlConstants.java │ │ ├── ibatis2 │ │ │ ├── Ibatis2FormattingUtilities.java │ │ │ ├── IntrospectedTableIbatis2Java2Impl.java │ │ │ ├── IntrospectedTableIbatis2Java5Impl.java │ │ │ ├── dao │ │ │ │ ├── DAOGenerator.java │ │ │ │ ├── elements │ │ │ │ │ ├── AbstractDAOElementGenerator.java │ │ │ │ │ ├── CountByExampleMethodGenerator.java │ │ │ │ │ ├── DeleteByExampleMethodGenerator.java │ │ │ │ │ ├── DeleteByPrimaryKeyMethodGenerator.java │ │ │ │ │ ├── InsertMethodGenerator.java │ │ │ │ │ ├── InsertSelectiveMethodGenerator.java │ │ │ │ │ ├── SelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── SelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── SelectByPrimaryKeyMethodGenerator.java │ │ │ │ │ ├── UpdateByExampleParmsInnerclassGenerator.java │ │ │ │ │ ├── UpdateByExampleSelectiveMethodGenerator.java │ │ │ │ │ ├── UpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ ├── UpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ ├── UpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ │ └── templates │ │ │ │ │ ├── AbstractDAOTemplate.java │ │ │ │ │ ├── GenericCIDAOTemplate.java │ │ │ │ │ ├── GenericSIDAOTemplate.java │ │ │ │ │ ├── IbatisDAOTemplate.java │ │ │ │ │ └── SpringDAOTemplate.java │ │ │ ├── model │ │ │ │ ├── BaseRecordGenerator.java │ │ │ │ ├── ExampleGenerator.java │ │ │ │ ├── PrimaryKeyGenerator.java │ │ │ │ └── RecordWithBLOBsGenerator.java │ │ │ └── sqlmap │ │ │ │ ├── SqlMapGenerator.java │ │ │ │ └── elements │ │ │ │ ├── AbstractXmlElementGenerator.java │ │ │ │ ├── BaseColumnListElementGenerator.java │ │ │ │ ├── BlobColumnListElementGenerator.java │ │ │ │ ├── CountByExampleElementGenerator.java │ │ │ │ ├── DeleteByExampleElementGenerator.java │ │ │ │ ├── DeleteByPrimaryKeyElementGenerator.java │ │ │ │ ├── ExampleWhereClauseElementGenerator.java │ │ │ │ ├── InsertElementGenerator.java │ │ │ │ ├── InsertSelectiveElementGenerator.java │ │ │ │ ├── ResultMapWithBLOBsElementGenerator.java │ │ │ │ ├── ResultMapWithoutBLOBsElementGenerator.java │ │ │ │ ├── SelectByExampleWithBLOBsElementGenerator.java │ │ │ │ ├── SelectByExampleWithoutBLOBsElementGenerator.java │ │ │ │ ├── SelectByPrimaryKeyElementGenerator.java │ │ │ │ ├── UpdateByExampleSelectiveElementGenerator.java │ │ │ │ ├── UpdateByExampleWithBLOBsElementGenerator.java │ │ │ │ ├── UpdateByExampleWithoutBLOBsElementGenerator.java │ │ │ │ ├── UpdateByPrimaryKeySelectiveElementGenerator.java │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsElementGenerator.java │ │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java │ │ └── mybatis3 │ │ │ ├── IntrospectedTableMyBatis3Impl.java │ │ │ ├── IntrospectedTableMyBatis3SimpleImpl.java │ │ │ ├── MyBatis3FormattingUtilities.java │ │ │ ├── javamapper │ │ │ ├── AnnotatedClientGenerator.java │ │ │ ├── JavaMapperGenerator.java │ │ │ ├── MixedClientGenerator.java │ │ │ ├── SimpleAnnotatedClientGenerator.java │ │ │ ├── SimpleJavaClientGenerator.java │ │ │ ├── SqlProviderGenerator.java │ │ │ └── elements │ │ │ │ ├── AbstractJavaMapperMethodGenerator.java │ │ │ │ ├── CountByExampleMethodGenerator.java │ │ │ │ ├── DeleteByExampleMethodGenerator.java │ │ │ │ ├── DeleteByPrimaryKeyMethodGenerator.java │ │ │ │ ├── InsertMethodGenerator.java │ │ │ │ ├── InsertSelectiveMethodGenerator.java │ │ │ │ ├── SelectAllMethodGenerator.java │ │ │ │ ├── SelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── SelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ ├── SelectByPrimaryKeyMethodGenerator.java │ │ │ │ ├── UpdateByExampleSelectiveMethodGenerator.java │ │ │ │ ├── UpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── UpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ ├── UpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ ├── UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ │ ├── annotated │ │ │ │ ├── AnnotatedCountByExampleMethodGenerator.java │ │ │ │ ├── AnnotatedDeleteByExampleMethodGenerator.java │ │ │ │ ├── AnnotatedDeleteByPrimaryKeyMethodGenerator.java │ │ │ │ ├── AnnotatedInsertMethodGenerator.java │ │ │ │ ├── AnnotatedInsertSelectiveMethodGenerator.java │ │ │ │ ├── AnnotatedSelectAllMethodGenerator.java │ │ │ │ ├── AnnotatedSelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── AnnotatedSelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ ├── AnnotatedSelectByPrimaryKeyMethodGenerator.java │ │ │ │ ├── AnnotatedUpdateByExampleSelectiveMethodGenerator.java │ │ │ │ ├── AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ ├── AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ ├── AnnotatedUpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ └── AnnotatedUpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ │ └── sqlprovider │ │ │ │ ├── AbstractJavaProviderMethodGenerator.java │ │ │ │ ├── ProviderApplyWhereMethodGenerator.java │ │ │ │ ├── ProviderCountByExampleMethodGenerator.java │ │ │ │ ├── ProviderDeleteByExampleMethodGenerator.java │ │ │ │ ├── ProviderInsertSelectiveMethodGenerator.java │ │ │ │ ├── ProviderSelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── ProviderSelectByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ ├── ProviderUpdateByExampleSelectiveMethodGenerator.java │ │ │ │ ├── ProviderUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ ├── ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ └── ProviderUpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ ├── model │ │ │ ├── BaseRecordGenerator.java │ │ │ ├── ExampleGenerator.java │ │ │ ├── PrimaryKeyGenerator.java │ │ │ ├── RecordWithBLOBsGenerator.java │ │ │ └── SimpleModelGenerator.java │ │ │ └── xmlmapper │ │ │ ├── MixedMapperGenerator.java │ │ │ ├── SimpleXMLMapperGenerator.java │ │ │ ├── XMLMapperGenerator.java │ │ │ └── elements │ │ │ ├── AbstractXmlElementGenerator.java │ │ │ ├── BaseColumnListElementGenerator.java │ │ │ ├── BlobColumnListElementGenerator.java │ │ │ ├── CountByExampleElementGenerator.java │ │ │ ├── DeleteByExampleElementGenerator.java │ │ │ ├── DeleteByPrimaryKeyElementGenerator.java │ │ │ ├── ExampleWhereClauseElementGenerator.java │ │ │ ├── InsertElementGenerator.java │ │ │ ├── InsertSelectiveElementGenerator.java │ │ │ ├── ResultMapWithBLOBsElementGenerator.java │ │ │ ├── ResultMapWithoutBLOBsElementGenerator.java │ │ │ ├── SelectByExampleWithBLOBsElementGenerator.java │ │ │ ├── SelectByExampleWithoutBLOBsElementGenerator.java │ │ │ ├── SelectByPrimaryKeyElementGenerator.java │ │ │ ├── SimpleSelectAllElementGenerator.java │ │ │ ├── SimpleSelectByPrimaryKeyElementGenerator.java │ │ │ ├── UpdateByExampleSelectiveElementGenerator.java │ │ │ ├── UpdateByExampleWithBLOBsElementGenerator.java │ │ │ ├── UpdateByExampleWithoutBLOBsElementGenerator.java │ │ │ ├── UpdateByPrimaryKeySelectiveElementGenerator.java │ │ │ ├── UpdateByPrimaryKeyWithBLOBsElementGenerator.java │ │ │ └── UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java │ │ ├── config │ │ ├── ColumnOverride.java │ │ ├── ColumnRenamingRule.java │ │ ├── CommentGeneratorConfiguration.java │ │ ├── Configuration.java │ │ ├── Context.java │ │ ├── GeneratedKey.java │ │ ├── IgnoredColumn.java │ │ ├── JDBCConnectionConfiguration.java │ │ ├── JavaClientGeneratorConfiguration.java │ │ ├── JavaModelGeneratorConfiguration.java │ │ ├── JavaTypeResolverConfiguration.java │ │ ├── MergeConstants.java │ │ ├── ModelType.java │ │ ├── PluginConfiguration.java │ │ ├── PropertyHolder.java │ │ ├── PropertyRegistry.java │ │ ├── SqlMapGeneratorConfiguration.java │ │ ├── TableConfiguration.java │ │ ├── TypedPropertyHolder.java │ │ └── xml │ │ │ ├── ConfigurationParser.java │ │ │ ├── IbatorConfigurationParser.java │ │ │ ├── MyBatisGeneratorConfigurationParser.java │ │ │ ├── ParserEntityResolver.java │ │ │ ├── ParserErrorHandler.java │ │ │ ├── ibator-config_1_0.dtd │ │ │ └── mybatis-generator-config_1_0.dtd │ │ ├── exception │ │ ├── InvalidConfigurationException.java │ │ ├── ShellException.java │ │ └── XMLParserException.java │ │ ├── internal │ │ ├── DefaultCommentGenerator.java │ │ ├── DefaultDAOMethodNameCalculator.java │ │ ├── DefaultShellCallback.java │ │ ├── DomWriter.java │ │ ├── ExtendedDAOMethodNameCalculator.java │ │ ├── NullProgressCallback.java │ │ ├── ObjectFactory.java │ │ ├── PluginAggregator.java │ │ ├── XmlFileMergerJaxp.java │ │ ├── db │ │ │ ├── ActualTableName.java │ │ │ ├── ConnectionFactory.java │ │ │ ├── DatabaseDialects.java │ │ │ ├── DatabaseIntrospector.java │ │ │ └── SqlReservedWords.java │ │ ├── rules │ │ │ ├── BaseRules.java │ │ │ ├── ConditionalModelRules.java │ │ │ ├── FlatModelRules.java │ │ │ ├── HierarchicalModelRules.java │ │ │ ├── Rules.java │ │ │ └── RulesDelegate.java │ │ ├── types │ │ │ ├── JavaTypeResolverDefaultImpl.java │ │ │ ├── Jdbc4Types.java │ │ │ └── JdbcTypeNameTranslator.java │ │ └── util │ │ │ ├── ClassloaderUtility.java │ │ │ ├── EqualsUtil.java │ │ │ ├── HashCodeUtil.java │ │ │ ├── JavaBeansUtil.java │ │ │ ├── StringUtility.java │ │ │ └── messages │ │ │ ├── Messages.java │ │ │ └── messages.properties │ │ ├── logging │ │ ├── AbstractLogFactory.java │ │ ├── JdkLoggingImpl.java │ │ ├── Log.java │ │ ├── Log4jImpl.java │ │ └── LogFactory.java │ │ └── plugins │ │ ├── CachePlugin.java │ │ ├── CaseInsensitiveLikePlugin.java │ │ ├── EqualsHashCodePlugin.java │ │ ├── MapperConfigPlugin.java │ │ ├── RenameExampleClassPlugin.java │ │ ├── RowBoundsPlugin.java │ │ ├── SerializablePlugin.java │ │ ├── SqlMapConfigPlugin.java │ │ ├── ToStringPlugin.java │ │ └── VirtualPrimaryKeyPlugin.java └── resources │ └── log4j.properties └── test ├── java └── demo │ ├── HelloTest.java │ ├── MBPMain.java │ ├── domain │ ├── oob │ │ ├── OperateLog.java │ │ └── OperateLogExample.java │ └── ooc │ │ ├── UserVisitLog.java │ │ └── UserVisitLogExample.java │ └── mapper │ ├── oob │ └── OperateLogMapper.java │ └── ooc │ └── UserVisitLogMapper.java └── resources ├── MybatisGeneratorCfg.xml ├── dbconfig.properties ├── demo └── mapperxml │ ├── oob │ └── OperateLogMapper.xml │ └── ooc │ └── UserVisitLogMapper.xml └── mybatis-config.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings/ 4 | 5 | *.iml 6 | .idea/ 7 | 8 | # Others 9 | target/ 10 | logs/ 11 | bak/ 12 | 13 | .DS_Store 14 | .tern-project 15 | .war 16 | .zip 17 | .rar 18 | 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | 4 | jdk: 5 | - oraclejdk8 6 | # - oraclejdk7 7 | - openjdk7 8 | 9 | script: 10 | - mvn package -Dmaven.test.skip=true -Dmaven.javadoc.skip=true 11 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/ihansen/mbp/extend/maven/MavenLogFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.ihansen.mbp.extend.maven; 17 | 18 | import org.apache.maven.plugin.Mojo; 19 | import org.mybatis.generator.logging.AbstractLogFactory; 20 | import org.mybatis.generator.logging.Log; 21 | 22 | public class MavenLogFactory implements AbstractLogFactory { 23 | 24 | private final MavenLogImpl logImplementation; 25 | 26 | MavenLogFactory(Mojo mojo) { 27 | logImplementation = new MavenLogImpl(mojo.getLog()); 28 | } 29 | 30 | @Override 31 | public Log getLog(Class targetClass) { 32 | return logImplementation; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/ihansen/mbp/extend/maven/MavenLogImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.ihansen.mbp.extend.maven; 17 | 18 | import org.apache.maven.plugin.logging.Log; 19 | 20 | public class MavenLogImpl implements org.mybatis.generator.logging.Log { 21 | private final Log mavenLog; 22 | 23 | MavenLogImpl(Log log) { 24 | mavenLog = log; 25 | } 26 | 27 | @Override 28 | public boolean isDebugEnabled() { 29 | return mavenLog.isDebugEnabled(); 30 | } 31 | 32 | @Override 33 | public void error(String s, Throwable e) { 34 | mavenLog.error(s, e); 35 | } 36 | 37 | @Override 38 | public void error(String s) { 39 | mavenLog.error(s); 40 | } 41 | 42 | @Override 43 | public void debug(String s) { 44 | mavenLog.debug(s); 45 | } 46 | 47 | @Override 48 | public void warn(String s) { 49 | mavenLog.warn(s); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/ihansen/mbp/extend/maven/MavenProgressCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.ihansen.mbp.extend.maven; 17 | 18 | import org.apache.maven.plugin.logging.Log; 19 | import org.mybatis.generator.internal.NullProgressCallback; 20 | 21 | /** 22 | * This callback logs progress messages with the Maven logger. 23 | * 24 | * @author Jeff Butler 25 | * 26 | */ 27 | public class MavenProgressCallback extends NullProgressCallback { 28 | 29 | private Log log; 30 | private boolean verbose; 31 | 32 | public MavenProgressCallback(Log log, boolean verbose) { 33 | super(); 34 | this.log = log; 35 | this.verbose = verbose; 36 | } 37 | 38 | @Override 39 | public void startTask(String subTaskName) { 40 | if (verbose) { 41 | log.info(subTaskName); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/ihansen/mbp/extend/maven/MavenShellCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.ihansen.mbp.extend.maven; 17 | 18 | import org.mybatis.generator.exception.ShellException; 19 | import org.mybatis.generator.internal.DefaultShellCallback; 20 | import org.mybatis.generator.internal.util.messages.Messages; 21 | 22 | import java.io.File; 23 | import java.util.StringTokenizer; 24 | 25 | /** 26 | * Shell callback that calculates the Maven output directory. 27 | * 28 | * @author Jeff Butler 29 | */ 30 | public class MavenShellCallback extends DefaultShellCallback { 31 | private MyBatisGeneratorMojo mybatisGeneratorMojo; 32 | 33 | public MavenShellCallback(MyBatisGeneratorMojo mybatisGeneratorMojo, boolean overwrite) { 34 | super(overwrite); 35 | this.mybatisGeneratorMojo = mybatisGeneratorMojo; 36 | } 37 | 38 | @Override 39 | public File getDirectory(String targetProject, String targetPackage) 40 | throws ShellException { 41 | if (!"MAVEN".equals(targetProject)) { 42 | return super.getDirectory(targetProject, targetPackage); 43 | } 44 | 45 | // targetProject is the output directory from the MyBatis generator 46 | // Mojo. It will be created if necessary 47 | // 48 | // targetPackage is interpreted as a sub directory, but in package 49 | // format (with dots instead of slashes). The sub directory will be created 50 | // if it does not already exist 51 | 52 | File project = mybatisGeneratorMojo.getOutputDirectory(); 53 | if (!project.exists()) { 54 | project.mkdirs(); 55 | } 56 | 57 | if (!project.isDirectory()) { 58 | throw new ShellException(Messages.getString("Warning.9", //$NON-NLS-1$ 59 | project.getAbsolutePath())); 60 | } 61 | 62 | StringBuilder sb = new StringBuilder(); 63 | StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ 64 | while (st.hasMoreTokens()) { 65 | sb.append(st.nextToken()); 66 | sb.append(File.separatorChar); 67 | } 68 | 69 | File directory = new File(project, sb.toString()); 70 | if (!directory.isDirectory()) { 71 | boolean rc = directory.mkdirs(); 72 | if (!rc) { 73 | throw new ShellException(Messages.getString("Warning.10", //$NON-NLS-1$ 74 | directory.getAbsolutePath())); 75 | } 76 | } 77 | 78 | return directory; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/ihansen/mbp/extend/DBSupport.java: -------------------------------------------------------------------------------- 1 | package org.ihansen.mbp.extend; 2 | 3 | import org.mybatis.generator.api.IntrospectedTable; 4 | import org.mybatis.generator.api.dom.java.Interface; 5 | import org.mybatis.generator.api.dom.xml.Document; 6 | import org.mybatis.generator.api.dom.xml.XmlElement; 7 | 8 | public interface DBSupport { 9 | /** 10 | * 向<mapper>中添加子节点 11 | * 12 | * @author 吴帅 13 | * @parameter @param document 14 | * @parameter @param introspectedTable 15 | * @createDate 2015年9月29日 上午10:20:11 16 | */ 17 | void sqlDialect(Document document, IntrospectedTable introspectedTable); 18 | 19 | /** 20 | * 增加批量插入的xml配置 21 | * 22 | * @author 吴帅 23 | * @parameter @param document 24 | * @parameter @param introspectedTable 25 | * @createDate 2015年8月9日 下午6:57:43 26 | */ 27 | void addBatchInsertXml(Document document, IntrospectedTable introspectedTable); 28 | 29 | /** 30 | * 条件查询sql适配 31 | * 32 | * @return 33 | * @author 吴帅 34 | * @parameter @param element 35 | * @parameter @param preFixId 36 | * @parameter @param sufFixId 37 | * @createDate 2015年9月29日 上午11:59:06 38 | */ 39 | XmlElement adaptSelectByExample(XmlElement element, IntrospectedTable introspectedTable); 40 | 41 | /** 42 | * 插入sql适配 43 | * 44 | * @author 吴帅 45 | * @parameter @param element 46 | * @parameter @param introspectedTable 47 | * @createDate 2015年9月29日 下午12:00:37 48 | */ 49 | void adaptInsertSelective(XmlElement element, IntrospectedTable introspectedTable); 50 | 51 | /** 52 | * 大偏移批量查询 53 | * @param interfaze 54 | * @param introspectedTable 55 | */ 56 | void addSelectByBigOffsetMethod(Interface interfaze, IntrospectedTable introspectedTable); 57 | 58 | /** 59 | * 乐观锁更新 60 | * @param interfaze 61 | * @param introspectedTable 62 | */ 63 | void addUpdateByOptimisticLockMethod(Interface interfaze, IntrospectedTable introspectedTable); 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/ihansen/mbp/extend/generator/AbstractJavaMapperMethodGenerator.java: -------------------------------------------------------------------------------- 1 | package org.ihansen.mbp.extend.generator; 2 | 3 | import org.mybatis.generator.api.IntrospectedTable; 4 | import org.mybatis.generator.api.dom.java.Interface; 5 | 6 | /** 7 | * @author wus 8 | */ 9 | public interface AbstractJavaMapperMethodGenerator { 10 | void addMethod(Interface interfaze, IntrospectedTable introspectedTable); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/ihansen/mbp/extend/generator/AbstractXmlElementGenerator.java: -------------------------------------------------------------------------------- 1 | package org.ihansen.mbp.extend.generator; 2 | 3 | import org.mybatis.generator.api.IntrospectedTable; 4 | import org.mybatis.generator.api.dom.xml.XmlElement; 5 | 6 | /** 7 | * @author wus 8 | */ 9 | public interface AbstractXmlElementGenerator { 10 | void addElements(XmlElement parentElement, IntrospectedTable introspectedTable); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/ihansen/mbp/extend/generator/SelectByBigOffsetMethodGenerator.java: -------------------------------------------------------------------------------- 1 | package org.ihansen.mbp.extend.generator; 2 | 3 | import org.mybatis.generator.api.IntrospectedTable; 4 | import org.mybatis.generator.api.dom.java.*; 5 | 6 | /** 7 | * @author wus 8 | */ 9 | public class SelectByBigOffsetMethodGenerator implements AbstractJavaMapperMethodGenerator { 10 | 11 | public static final String METHOD_NAME = "selectByBigOffset"; 12 | 13 | public void addMethod(Interface interfaze,IntrospectedTable introspectedTable) { 14 | Method method = new Method(); 15 | // 1.设置方法可见性 16 | method.setVisibility(JavaVisibility.PUBLIC); 17 | // 2.设置返回值类型 18 | FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance(); 19 | FullyQualifiedJavaType paramListType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()); 20 | returnType.addTypeArgument(paramListType); 21 | method.setReturnType(returnType); 22 | // 3.设置方法名 23 | method.setName(METHOD_NAME); 24 | // 4.设置方法入参 25 | FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType()); 26 | method.addParameter(new Parameter(type, "example")); 27 | interfaze.addMethod(method); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/ihansen/mbp/extend/generator/UpdateByOptimisticLockMethodGenerator.java: -------------------------------------------------------------------------------- 1 | package org.ihansen.mbp.extend.generator; 2 | 3 | import org.mybatis.generator.api.IntrospectedTable; 4 | import org.mybatis.generator.api.dom.java.*; 5 | import org.mybatis.generator.config.TableConfiguration; 6 | 7 | import java.util.Properties; 8 | import java.util.Set; 9 | import java.util.TreeSet; 10 | 11 | /** 12 | * @author wus 13 | */ 14 | public class UpdateByOptimisticLockMethodGenerator implements AbstractJavaMapperMethodGenerator { 15 | 16 | public static final String METHOD_NAME = "updateByOptimisticLock"; 17 | 18 | @Override 19 | public void addMethod(Interface interfaze, IntrospectedTable introspectedTable) { 20 | TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); 21 | Properties properties = tableConfiguration.getProperties(); 22 | String versionField = properties.getProperty("versionField"); 23 | if (versionField == null || versionField == "") { 24 | return; 25 | } 26 | Set importedTypes = new TreeSet<>(); 27 | FullyQualifiedJavaType parameterType; 28 | if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { 29 | parameterType = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType()); 30 | } else { 31 | parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()); 32 | } 33 | importedTypes.add(parameterType); 34 | Method method = new Method(); 35 | method.setVisibility(JavaVisibility.PUBLIC); 36 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 37 | method.setName(METHOD_NAME); 38 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 39 | interfaze.addImportedTypes(importedTypes); 40 | interfaze.addMethod(method); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/ihansen/mbp/extend/java/CustomInterface.java: -------------------------------------------------------------------------------- 1 | package org.ihansen.mbp.extend.java; 2 | 3 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 4 | import org.mybatis.generator.api.dom.java.Interface; 5 | 6 | public class CustomInterface extends Interface { 7 | 8 | public CustomInterface(FullyQualifiedJavaType type) { 9 | super(type); 10 | } 11 | 12 | public CustomInterface(String type) { 13 | super(type); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/api/dom/java/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.api.dom.java; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * @author Jeff Butler 23 | */ 24 | public class Parameter { 25 | private String name; 26 | private FullyQualifiedJavaType type; 27 | private boolean isVarargs; 28 | 29 | private List annotations; 30 | 31 | public Parameter(FullyQualifiedJavaType type, String name, boolean isVarargs) { 32 | super(); 33 | this.name = name; 34 | this.type = type; 35 | this.isVarargs = isVarargs; 36 | annotations = new ArrayList(); 37 | } 38 | 39 | public Parameter(FullyQualifiedJavaType type, String name) { 40 | this(type, name, false); 41 | } 42 | 43 | public Parameter(FullyQualifiedJavaType type, String name, String annotation) { 44 | this(type, name, false); 45 | addAnnotation(annotation); 46 | } 47 | 48 | public Parameter(FullyQualifiedJavaType type, String name, String annotation, boolean isVarargs) { 49 | this(type, name, isVarargs); 50 | addAnnotation(annotation); 51 | } 52 | 53 | /** 54 | * @return Returns the name. 55 | */ 56 | public String getName() { 57 | return name; 58 | } 59 | 60 | /** 61 | * @return Returns the type. 62 | */ 63 | public FullyQualifiedJavaType getType() { 64 | return type; 65 | } 66 | 67 | public List getAnnotations() { 68 | return annotations; 69 | } 70 | 71 | public void addAnnotation(String annotation) { 72 | annotations.add(annotation); 73 | } 74 | 75 | public String getFormattedContent() { 76 | StringBuilder sb = new StringBuilder(); 77 | 78 | for (String annotation : annotations) { 79 | sb.append(annotation); 80 | sb.append(' '); 81 | } 82 | 83 | sb.append(type.getShortName()); 84 | sb.append(' '); 85 | if (isVarargs) { 86 | sb.append("... "); //$NON-NLS-1$ 87 | } 88 | sb.append(name); 89 | 90 | return sb.toString(); 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return getFormattedContent(); 96 | } 97 | 98 | public boolean isVarargs() { 99 | return isVarargs; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/codegen/ibatis2/dao/templates/IbatisDAOTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.ibatis2.dao.templates; 17 | 18 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 19 | import org.mybatis.generator.api.dom.java.JavaVisibility; 20 | import org.mybatis.generator.api.dom.java.Method; 21 | import org.mybatis.generator.api.dom.java.Parameter; 22 | 23 | /** 24 | * @author Jeff Butler 25 | */ 26 | public class IbatisDAOTemplate extends AbstractDAOTemplate { 27 | 28 | private FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType( 29 | "com.ibatis.dao.client.DaoManager"); //$NON-NLS-1$ 30 | 31 | /** 32 | * 33 | */ 34 | public IbatisDAOTemplate() { 35 | super(); 36 | } 37 | 38 | @Override 39 | protected void configureConstructorTemplate() { 40 | Method method = new Method(); 41 | method.setConstructor(true); 42 | method.setVisibility(JavaVisibility.PUBLIC); 43 | method.addParameter(new Parameter(fqjt, "daoManager")); //$NON-NLS-1$ 44 | method.addBodyLine("super(daoManager);"); //$NON-NLS-1$ 45 | setConstructorTemplate(method); 46 | } 47 | 48 | @Override 49 | protected void configureDeleteMethodTemplate() { 50 | setDeleteMethodTemplate("delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 51 | } 52 | 53 | @Override 54 | protected void configureImplementationImports() { 55 | addImplementationImport(fqjt); 56 | } 57 | 58 | @Override 59 | protected void configureInsertMethodTemplate() { 60 | setInsertMethodTemplate("insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 61 | } 62 | 63 | @Override 64 | protected void configureQueryForListMethodTemplate() { 65 | setQueryForListMethodTemplate("queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 66 | } 67 | 68 | @Override 69 | protected void configureQueryForObjectMethodTemplate() { 70 | setQueryForObjectMethodTemplate("queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 71 | } 72 | 73 | @Override 74 | protected void configureSuperClass() { 75 | setSuperClass(new FullyQualifiedJavaType( 76 | "com.ibatis.dao.client.template.SqlMapDaoTemplate")); //$NON-NLS-1$ 77 | } 78 | 79 | @Override 80 | protected void configureUpdateMethodTemplate() { 81 | setUpdateMethodTemplate("update(\"{0}.{1}\", {2});"); //$NON-NLS-1$ 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByExampleSelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByExampleSelectiveMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | @Override 36 | public void addInterfaceElements(Interface interfaze) { 37 | Set importedTypes = new TreeSet(); 38 | Method method = new Method(); 39 | method.setVisibility(JavaVisibility.PUBLIC); 40 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 41 | method.setName(introspectedTable 42 | .getUpdateByExampleSelectiveStatementId()); 43 | 44 | FullyQualifiedJavaType parameterType = 45 | introspectedTable.getRules().calculateAllFieldsClass(); 46 | method.addParameter(new Parameter(parameterType, 47 | "record", "@Param(\"record\")")); //$NON-NLS-1$ //$NON-NLS-2$ 48 | importedTypes.add(parameterType); 49 | 50 | FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType( 51 | introspectedTable.getExampleType()); 52 | method.addParameter(new Parameter(exampleType, 53 | "example", "@Param(\"example\")")); //$NON-NLS-1$ //$NON-NLS-2$ 54 | importedTypes.add(exampleType); 55 | 56 | importedTypes.add(new FullyQualifiedJavaType( 57 | "org.apache.ibatis.annotations.Param")); //$NON-NLS-1$ 58 | 59 | context.getCommentGenerator().addGeneralMethodComment(method, 60 | introspectedTable); 61 | 62 | addMapperAnnotations(interfaze, method); 63 | 64 | if (context.getPlugins() 65 | .clientUpdateByExampleSelectiveMethodGenerated(method, interfaze, 66 | introspectedTable)) { 67 | interfaze.addImportedTypes(importedTypes); 68 | interfaze.addMethod(method); 69 | } 70 | } 71 | 72 | public void addMapperAnnotations(Interface interfaze, Method method) { 73 | return; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByPrimaryKeySelectiveMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByPrimaryKeySelectiveMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public UpdateByPrimaryKeySelectiveMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType parameterType; 43 | 44 | if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { 45 | parameterType = new FullyQualifiedJavaType(introspectedTable 46 | .getRecordWithBLOBsType()); 47 | } else { 48 | parameterType = new FullyQualifiedJavaType(introspectedTable 49 | .getBaseRecordType()); 50 | } 51 | 52 | importedTypes.add(parameterType); 53 | 54 | Method method = new Method(); 55 | method.setVisibility(JavaVisibility.PUBLIC); 56 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 57 | method.setName(introspectedTable 58 | .getUpdateByPrimaryKeySelectiveStatementId()); 59 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 60 | 61 | context.getCommentGenerator().addGeneralMethodComment(method, 62 | introspectedTable); 63 | 64 | addMapperAnnotations(interfaze, method); 65 | 66 | if (context.getPlugins() 67 | .clientUpdateByPrimaryKeySelectiveMethodGenerated(method, 68 | interfaze, introspectedTable)) { 69 | interfaze.addImportedTypes(importedTypes); 70 | interfaze.addMethod(method); 71 | } 72 | } 73 | 74 | public void addMapperAnnotations(Interface interfaze, Method method) { 75 | return; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/UpdateByPrimaryKeyWithBLOBsMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.codegen.mybatis3.javamapper.elements; 17 | 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | 21 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 22 | import org.mybatis.generator.api.dom.java.Interface; 23 | import org.mybatis.generator.api.dom.java.JavaVisibility; 24 | import org.mybatis.generator.api.dom.java.Method; 25 | import org.mybatis.generator.api.dom.java.Parameter; 26 | 27 | /** 28 | * 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class UpdateByPrimaryKeyWithBLOBsMethodGenerator extends 33 | AbstractJavaMapperMethodGenerator { 34 | 35 | public UpdateByPrimaryKeyWithBLOBsMethodGenerator() { 36 | super(); 37 | } 38 | 39 | @Override 40 | public void addInterfaceElements(Interface interfaze) { 41 | Set importedTypes = new TreeSet(); 42 | FullyQualifiedJavaType parameterType; 43 | 44 | if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { 45 | parameterType = new FullyQualifiedJavaType(introspectedTable 46 | .getRecordWithBLOBsType()); 47 | } else { 48 | parameterType = new FullyQualifiedJavaType(introspectedTable 49 | .getBaseRecordType()); 50 | } 51 | 52 | importedTypes.add(parameterType); 53 | 54 | Method method = new Method(); 55 | method.setVisibility(JavaVisibility.PUBLIC); 56 | method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 57 | 58 | method.setName(introspectedTable 59 | .getUpdateByPrimaryKeyWithBLOBsStatementId()); 60 | method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ 61 | 62 | context.getCommentGenerator().addGeneralMethodComment(method, 63 | introspectedTable); 64 | 65 | addMapperAnnotations(interfaze, method); 66 | 67 | if (context.getPlugins() 68 | .clientUpdateByPrimaryKeyWithBLOBsMethodGenerated(method, 69 | interfaze, introspectedTable)) { 70 | interfaze.addImportedTypes(importedTypes); 71 | interfaze.addMethod(method); 72 | } 73 | } 74 | 75 | public void addMapperAnnotations(Interface interfaze, Method method) { 76 | return; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.TopLevelClass; 19 | import org.mybatis.generator.codegen.AbstractGenerator; 20 | 21 | /** 22 | * 23 | * @author Jeff Butler 24 | */ 25 | public abstract class AbstractJavaProviderMethodGenerator extends 26 | AbstractGenerator { 27 | 28 | public AbstractJavaProviderMethodGenerator() { 29 | super(); 30 | } 31 | 32 | public abstract void addClassElements(TopLevelClass topLevelClass); 33 | } 34 | -------------------------------------------------------------------------------- /src/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() { 33 | super(); 34 | } 35 | 36 | @Override 37 | public List getColumns() { 38 | return introspectedTable.getAllColumns(); 39 | } 40 | 41 | @Override 42 | public String getMethodName() { 43 | return introspectedTable.getSelectByExampleWithBLOBsStatementId(); 44 | } 45 | 46 | @Override 47 | public boolean callPlugins(Method method, TopLevelClass topLevelClass) { 48 | return context.getPlugins().providerSelectByExampleWithBLOBsMethodGenerated(method, topLevelClass, 49 | introspectedTable); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/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() { 33 | super(); 34 | } 35 | 36 | @Override 37 | public String getMethodName() { 38 | return introspectedTable.getUpdateByExampleWithBLOBsStatementId(); 39 | } 40 | 41 | @Override 42 | public List getColumns() { 43 | return introspectedTable.getAllColumns(); 44 | } 45 | 46 | @Override 47 | public boolean callPlugins(Method method, TopLevelClass topLevelClass) { 48 | return context.getPlugins().providerUpdateByExampleWithBLOBsMethodGenerated(method, topLevelClass, 49 | introspectedTable); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/config/ColumnRenamingRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.config; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.util.List; 22 | 23 | import org.mybatis.generator.api.dom.xml.Attribute; 24 | import org.mybatis.generator.api.dom.xml.XmlElement; 25 | 26 | /** 27 | * This class is used to specify a renaming rule for columns in a table. This 28 | * renaming rule will be run against all column names before calculating the 29 | * corresponding property name. The most common use case is when columns in a 30 | * table are all prefixed by a certain value. 31 | * 32 | * For example, if columns in a table are named: 33 | * 34 | *
    35 | *
  • CUST_NAME
  • 36 | *
  • CUST_ADDRESS
  • 37 | *
  • CUST_CITY
  • 38 | *
  • CUST_STATE
  • 39 | *
40 | * 41 | * it might be annoying to have the generated properties all containing the CUST 42 | * prefix. This class can be used to remove the prefix by specifying 43 | * 44 | *
    45 | *
  • searchString = "^CUST"
  • 46 | *
  • replaceString=""
  • 47 | *
48 | * 49 | * Note that internally, the generator uses the 50 | * java.util.regex.Matcher.replaceAll method for this function. See 51 | * the documentation of that method for example of the regular expression 52 | * language used in Java. 53 | * 54 | * @author Jeff Butler 55 | * 56 | */ 57 | public class ColumnRenamingRule { 58 | private String searchString; 59 | private String replaceString; 60 | 61 | public String getReplaceString() { 62 | return replaceString; 63 | } 64 | 65 | public void setReplaceString(String replaceString) { 66 | this.replaceString = replaceString; 67 | } 68 | 69 | public String getSearchString() { 70 | return searchString; 71 | } 72 | 73 | public void setSearchString(String searchString) { 74 | this.searchString = searchString; 75 | } 76 | 77 | public void validate(List errors, String tableName) { 78 | if (!stringHasValue(searchString)) { 79 | errors.add(getString("ValidationError.14", tableName)); //$NON-NLS-1$ 80 | } 81 | } 82 | 83 | public XmlElement toXmlElement() { 84 | XmlElement xmlElement = new XmlElement("columnRenamingRule"); //$NON-NLS-1$ 85 | xmlElement.addAttribute(new Attribute("searchString", searchString)); //$NON-NLS-1$ 86 | 87 | if (replaceString != null) { 88 | xmlElement.addAttribute(new Attribute( 89 | "replaceString", replaceString)); //$NON-NLS-1$ 90 | } 91 | 92 | return xmlElement; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/config/IgnoredColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.config; 18 | 19 | import static org.mybatis.generator.internal.util.StringUtility.stringContainsSpace; 20 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 21 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 22 | 23 | import java.util.List; 24 | 25 | import org.mybatis.generator.api.dom.xml.Attribute; 26 | import org.mybatis.generator.api.dom.xml.XmlElement; 27 | 28 | /** 29 | * @author Jeff Butler 30 | * 31 | */ 32 | public class IgnoredColumn { 33 | 34 | private String columnName; 35 | 36 | private boolean isColumnNameDelimited; 37 | 38 | private String configuredDelimitedColumnName; 39 | 40 | /** 41 | * 42 | */ 43 | public IgnoredColumn(String columnName) { 44 | super(); 45 | this.columnName = columnName; 46 | isColumnNameDelimited = stringContainsSpace(columnName); 47 | } 48 | 49 | public String getColumnName() { 50 | return columnName; 51 | } 52 | 53 | public boolean isColumnNameDelimited() { 54 | return isColumnNameDelimited; 55 | } 56 | 57 | public void setColumnNameDelimited(boolean isColumnNameDelimited) { 58 | this.isColumnNameDelimited = isColumnNameDelimited; 59 | configuredDelimitedColumnName = isColumnNameDelimited ? "true" : "false"; //$NON-NLS-1$ //$NON-NLS-2$ 60 | } 61 | 62 | public boolean equals(Object obj) { 63 | if (obj == null || !(obj instanceof IgnoredColumn)) { 64 | return false; 65 | } 66 | 67 | return columnName.equals(((IgnoredColumn) obj).getColumnName()); 68 | } 69 | 70 | public int hashCode() { 71 | return columnName.hashCode(); 72 | } 73 | 74 | public XmlElement toXmlElement() { 75 | XmlElement xmlElement = new XmlElement("ignoreColumn"); //$NON-NLS-1$ 76 | xmlElement.addAttribute(new Attribute("column", columnName)); //$NON-NLS-1$ 77 | 78 | if (stringHasValue(configuredDelimitedColumnName)) { 79 | xmlElement.addAttribute(new Attribute( 80 | "delimitedColumnName", configuredDelimitedColumnName)); //$NON-NLS-1$ 81 | } 82 | 83 | return xmlElement; 84 | } 85 | 86 | public void validate(List errors, String tableName) { 87 | if (!stringHasValue(columnName)) { 88 | errors.add(getString("ValidationError.21", //$NON-NLS-1$ 89 | tableName)); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/internal/DefaultShellCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal; 17 | 18 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 19 | 20 | import java.io.File; 21 | import java.util.StringTokenizer; 22 | 23 | import org.mybatis.generator.api.ShellCallback; 24 | import org.mybatis.generator.exception.ShellException; 25 | 26 | /** 27 | * @author Jeff Butler 28 | */ 29 | public class DefaultShellCallback implements ShellCallback { 30 | private boolean overwrite; 31 | 32 | /** 33 | * 34 | */ 35 | public DefaultShellCallback(boolean overwrite) { 36 | super(); 37 | this.overwrite = overwrite; 38 | } 39 | 40 | public File getDirectory(String targetProject, String targetPackage) 41 | throws ShellException { 42 | // targetProject is interpreted as a directory that must exist 43 | // 44 | // targetPackage is interpreted as a sub directory, but in package 45 | // format (with dots instead of slashes). The sub directory will be 46 | // created 47 | // if it does not already exist 48 | 49 | File project = new File(targetProject); 50 | if (!project.isDirectory()) { 51 | throw new ShellException(getString("Warning.9", //$NON-NLS-1$ 52 | targetProject)); 53 | } 54 | 55 | StringBuilder sb = new StringBuilder(); 56 | StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$ 57 | while (st.hasMoreTokens()) { 58 | sb.append(st.nextToken()); 59 | sb.append(File.separatorChar); 60 | } 61 | 62 | File directory = new File(project, sb.toString()); 63 | if (!directory.isDirectory()) { 64 | boolean rc = directory.mkdirs(); 65 | if (!rc) { 66 | throw new ShellException(getString("Warning.10", //$NON-NLS-1$ 67 | directory.getAbsolutePath())); 68 | } 69 | } 70 | 71 | return directory; 72 | } 73 | 74 | public void refreshProject(String project) { 75 | // nothing to do in the default shell callback 76 | } 77 | 78 | public boolean isMergeSupported() { 79 | return false; 80 | } 81 | 82 | public boolean isOverwriteEnabled() { 83 | return overwrite; 84 | } 85 | 86 | public String mergeJavaFile(String newFileSource, 87 | String existingFileFullPath, String[] javadocTags, String fileEncoding) 88 | throws ShellException { 89 | throw new UnsupportedOperationException(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/internal/db/ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.db; 17 | 18 | import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; 19 | import static org.mybatis.generator.internal.util.messages.Messages.getString; 20 | 21 | import java.sql.Connection; 22 | import java.sql.Driver; 23 | import java.sql.SQLException; 24 | import java.util.Properties; 25 | 26 | import org.mybatis.generator.config.JDBCConnectionConfiguration; 27 | import org.mybatis.generator.internal.ObjectFactory; 28 | 29 | /** 30 | * This class assumes that classes are cached elsewhere for performance reasons, 31 | * but also to make sure that any native libraries are only loaded one time 32 | * (avoids the dreaded UnsatisfiedLinkError library loaded in another 33 | * classloader) 34 | * 35 | * @author Jeff Butler 36 | */ 37 | public class ConnectionFactory { 38 | 39 | private static ConnectionFactory instance = new ConnectionFactory(); 40 | 41 | public static ConnectionFactory getInstance() { 42 | return instance; 43 | } 44 | 45 | /** 46 | * 47 | */ 48 | private ConnectionFactory() { 49 | super(); 50 | } 51 | 52 | public Connection getConnection(JDBCConnectionConfiguration config) 53 | throws SQLException { 54 | Driver driver = getDriver(config); 55 | 56 | Properties props = new Properties(); 57 | 58 | if (stringHasValue(config.getUserId())) { 59 | props.setProperty("user", config.getUserId()); //$NON-NLS-1$ 60 | } 61 | 62 | if (stringHasValue(config.getPassword())) { 63 | props.setProperty("password", config.getPassword()); //$NON-NLS-1$ 64 | } 65 | 66 | props.putAll(config.getProperties()); 67 | 68 | Connection conn = driver.connect(config.getConnectionURL(), props); 69 | 70 | if (conn == null) { 71 | throw new SQLException(getString("RuntimeError.7")); //$NON-NLS-1$ 72 | } 73 | 74 | return conn; 75 | } 76 | 77 | private Driver getDriver(JDBCConnectionConfiguration connectionInformation) { 78 | String driverClass = connectionInformation.getDriverClass(); 79 | Driver driver; 80 | 81 | try { 82 | Class clazz = ObjectFactory.externalClassForName(driverClass); 83 | driver = (Driver) clazz.newInstance(); 84 | } catch (Exception e) { 85 | throw new RuntimeException(getString("RuntimeError.8"), e); //$NON-NLS-1$ 86 | } 87 | 88 | return driver; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/internal/db/DatabaseDialects.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.generator.internal.db; 17 | 18 | /** 19 | * Typesafe enum of known database dialects 20 | * 21 | * @author Jeff Butler 22 | */ 23 | public enum DatabaseDialects { 24 | 25 | DB2("VALUES IDENTITY_VAL_LOCAL()"), //$NON-NLS-1$ 26 | MYSQL("SELECT LAST_INSERT_ID()"), //$NON-NLS-1$ 27 | SQLSERVER("SELECT SCOPE_IDENTITY()"), //$NON-NLS-1$ 28 | CLOUDSCAPE("VALUES IDENTITY_VAL_LOCAL()"), //$NON-NLS-1$ 29 | DERBY("VALUES IDENTITY_VAL_LOCAL()"), //$NON-NLS-1$ 30 | HSQLDB("CALL IDENTITY()"), //$NON-NLS-1$ 31 | SYBASE("SELECT @@IDENTITY"), //$NON-NLS-1$ 32 | DB2_MF("SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"), //$NON-NLS-1$ 33 | INFORMIX("select dbinfo('sqlca.sqlerrd1') from systables where tabid=1"); //$NON-NLS-1$ 34 | 35 | private String identityRetrievalStatement; 36 | 37 | /** 38 | * 39 | */ 40 | private DatabaseDialects(String identityRetrievalStatement) { 41 | this.identityRetrievalStatement = identityRetrievalStatement; 42 | } 43 | 44 | public String getIdentityRetrievalStatement() { 45 | return identityRetrievalStatement; 46 | } 47 | 48 | /** 49 | * 50 | * @param database 51 | * @return the database dialect for the selected database. May return null 52 | * if there is no known dialect for the selected db 53 | */ 54 | public static DatabaseDialects getDatabaseDialect(String database) { 55 | DatabaseDialects returnValue = null; 56 | 57 | if ("DB2".equalsIgnoreCase(database)) { //$NON-NLS-1$ 58 | returnValue = DB2; 59 | } else if ("MySQL".equalsIgnoreCase(database)) { //$NON-NLS-1$ 60 | returnValue = MYSQL; 61 | } else if ("SqlServer".equalsIgnoreCase(database)) { //$NON-NLS-1$ 62 | returnValue = SQLSERVER; 63 | } else if ("Cloudscape".equalsIgnoreCase(database)) { //$NON-NLS-1$ 64 | returnValue = CLOUDSCAPE; 65 | } else if ("Derby".equalsIgnoreCase(database)) { //$NON-NLS-1$ 66 | returnValue = DERBY; 67 | } else if ("HSQLDB".equalsIgnoreCase(database)) { //$NON-NLS-1$ 68 | returnValue = HSQLDB; 69 | } else if ("SYBASE".equalsIgnoreCase(database)) { //$NON-NLS-1$ 70 | returnValue = SYBASE; 71 | } else if ("DB2_MF".equalsIgnoreCase(database)) { //$NON-NLS-1$ 72 | returnValue = DB2_MF; 73 | } else if ("Informix".equalsIgnoreCase(database)) { //$NON-NLS-1$ 74 | returnValue = INFORMIX; 75 | } 76 | 77 | return returnValue; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/internal/types/Jdbc4Types.java: -------------------------------------------------------------------------------- 1 | package org.mybatis.generator.internal.types; 2 | 3 | public class Jdbc4Types { 4 | // these are added manually until we move to JDK 6 5 | // TODO - remove after JDK 6 and use the java.sql.Types constants instead 6 | public static final int LONGNVARCHAR = -16; 7 | public static final int NVARCHAR = -9; 8 | public static final int NCHAR = -15; 9 | public static final int NCLOB = 2011; 10 | } 11 | -------------------------------------------------------------------------------- /src/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.Collection; 27 | import java.util.List; 28 | 29 | /** 30 | * This class holds methods useful for constructing custom classloaders. 31 | * 32 | * @author Jeff Butler 33 | * 34 | */ 35 | public class ClassloaderUtility { 36 | 37 | /** 38 | * Utility Class - No Instances 39 | */ 40 | private ClassloaderUtility() { 41 | } 42 | 43 | public static ClassLoader getCustomClassloader(Collection entries) { 44 | List urls = new ArrayList(); 45 | File file; 46 | 47 | if (entries != null) { 48 | for (String classPathEntry : entries) { 49 | file = new File(classPathEntry); 50 | if (!file.exists()) { 51 | throw new RuntimeException(getString( 52 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 53 | } 54 | 55 | try { 56 | urls.add(file.toURI().toURL()); 57 | } catch (MalformedURLException e) { 58 | // this shouldn't happen, but just in case... 59 | throw new RuntimeException(getString( 60 | "RuntimeError.9", classPathEntry)); //$NON-NLS-1$ 61 | } 62 | } 63 | } 64 | 65 | ClassLoader parent = Thread.currentThread().getContextClassLoader(); 66 | 67 | URLClassLoader ucl = new URLClassLoader(urls.toArray(new URL[urls 68 | .size()]), parent); 69 | 70 | return ucl; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,Console 2 | 3 | log4j.logger.java.sql.ResultSet=DEBUG 4 | log4j.logger.org.apache=DEBUG 5 | log4j.logger.java.sql.Connection=DEBUG 6 | log4j.logger.java.sql.Statement=DEBUG 7 | log4j.logger.java.sql.PreparedStatement=DEBUG 8 | 9 | #### First appender writes to console 10 | log4j.appender.Console=org.apache.log4j.ConsoleAppender 11 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout 12 | log4j.appender.Console.layout.ConversionPattern=[%d] [%t](%F:%L) %-5p %c - %m%n 13 | -------------------------------------------------------------------------------- /src/test/java/demo/HelloTest.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | 4 | import demo.domain.oob.OperateLog; 5 | import demo.domain.oob.OperateLogExample; 6 | import demo.domain.ooc.UserVisitLog; 7 | import demo.domain.ooc.UserVisitLogExample; 8 | import demo.mapper.oob.OperateLogMapper; 9 | import demo.mapper.ooc.UserVisitLogMapper; 10 | import org.apache.ibatis.session.SqlSession; 11 | import org.apache.ibatis.session.SqlSessionFactory; 12 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | 16 | import java.io.FileInputStream; 17 | import java.io.FileNotFoundException; 18 | import java.io.InputStream; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class HelloTest { 23 | 24 | SqlSession sqlSession; 25 | 26 | OperateLogMapper operateLogMapper; 27 | 28 | UserVisitLogMapper userVisitLogMapper; 29 | 30 | @Before 31 | public void before() throws FileNotFoundException { 32 | // Mapper的配置文件 33 | String resource = HelloTest.class.getResource("/mybatis-config.xml").getFile(); 34 | // 使用类加载器加载mybatis的配置文件(它也加载关联的映射文件) 35 | InputStream is = new FileInputStream(resource); 36 | // 构建sqlSession的工厂 37 | SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is); 38 | sqlSession = sessionFactory.openSession(); 39 | operateLogMapper = sqlSession.getMapper(OperateLogMapper.class); 40 | userVisitLogMapper = sqlSession.getMapper(UserVisitLogMapper.class); 41 | } 42 | 43 | /** 44 | * insert Test 45 | * @author 吴帅 46 | * @parameter @throws Exception 47 | * @createDate 2015年12月18日 下午4:11:18 48 | */ 49 | @Test 50 | public void insertTest() throws Exception { 51 | OperateLog operateLog = new OperateLog.Builder() 52 | .action("insert_test") 53 | .build(); 54 | operateLogMapper.insertSelective(operateLog); 55 | sqlSession.commit(); 56 | } 57 | 58 | /** 59 | * insertBatch Test 60 | * @author 吴帅 61 | * @parameter @throws Exception 62 | * @createDate 2015年12月18日 下午4:11:33 63 | */ 64 | @Test 65 | public void insertBatchTest() throws Exception { 66 | List operateLogList = new ArrayList<>(); 67 | for (int i = 0; i < 5; i++) { 68 | OperateLog operateLog = new OperateLog.Builder() 69 | .action("insertBatch_test"+i) 70 | .build(); 71 | operateLogList.add(operateLog); 72 | } 73 | operateLogMapper.insertBatch(operateLogList); 74 | sqlSession.commit(); 75 | } 76 | 77 | 78 | /** 79 | * select page Test 80 | * @throws Exception 81 | */ 82 | @Test 83 | public void selectPageTest() throws Exception { 84 | OperateLogExample relationshipsExample = new OperateLogExample(); 85 | relationshipsExample.setPagination(0l,2l); 86 | List operateLogList = operateLogMapper.selectByExample(relationshipsExample); 87 | //TODO verify 88 | System.out.println(operateLogList); 89 | } 90 | 91 | @Test 92 | public void selectByBigOffsetTest(){ 93 | UserVisitLogExample userVisitLogExample = new UserVisitLogExample(); 94 | userVisitLogExample.createCriteria().andIdLessThan(100); 95 | userVisitLogExample.setPagination(0,10); 96 | List userVisitLogList = userVisitLogMapper.selectByBigOffset(userVisitLogExample); 97 | System.out.println(userVisitLogList); 98 | } 99 | 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/test/java/demo/MBPMain.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import org.mybatis.generator.api.MyBatisGenerator; 4 | import org.mybatis.generator.api.ProgressCallback; 5 | import org.mybatis.generator.config.Configuration; 6 | import org.mybatis.generator.config.xml.ConfigurationParser; 7 | import org.mybatis.generator.exception.InvalidConfigurationException; 8 | import org.mybatis.generator.exception.XMLParserException; 9 | import org.mybatis.generator.internal.DefaultShellCallback; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.sql.SQLException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class MBPMain { 18 | 19 | public static final String CFG_FILE_PATH = MBPMain.class.getResource("/MybatisGeneratorCfg.xml").getFile(); 20 | 21 | public static void main(String[] args) { 22 | List warnings = new ArrayList<>(); 23 | boolean overwrite = true; 24 | File configFile = new File(CFG_FILE_PATH); 25 | ConfigurationParser cp = new ConfigurationParser(warnings); 26 | Configuration config = null; 27 | try { 28 | config = cp.parseConfiguration(configFile); 29 | } 30 | catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | catch (XMLParserException e) { 34 | e.printStackTrace(); 35 | } 36 | DefaultShellCallback callback = new DefaultShellCallback(overwrite); 37 | MyBatisGenerator myBatisGenerator = null; 38 | try { 39 | myBatisGenerator = new MyBatisGenerator(config, callback, warnings); 40 | } 41 | catch (InvalidConfigurationException e) { 42 | e.printStackTrace(); 43 | } 44 | try { 45 | myBatisGenerator.generate(new ProgressCallback() { 46 | @Override 47 | public void startTask(String taskName) { 48 | System.out.println("startTask(String "+taskName+")"); 49 | } 50 | @Override 51 | public void saveStarted(int totalTasks) { 52 | System.out.println("saveStarted(int "+totalTasks+")"); 53 | } 54 | @Override 55 | public void introspectionStarted(int totalTasks) { 56 | System.out.println("introspectionStarted(int "+totalTasks+")"); 57 | } 58 | @Override 59 | public void generationStarted(int totalTasks) { 60 | System.out.println("generationStarted(int "+totalTasks+")"); 61 | } 62 | @Override 63 | public void done() { 64 | System.out.println("done()"); 65 | } 66 | @Override 67 | public void checkCancel() throws InterruptedException { 68 | System.out.println("checkCancel()"); 69 | } 70 | }); 71 | } 72 | catch (SQLException e) { 73 | e.printStackTrace(); 74 | } 75 | catch (IOException e) { 76 | e.printStackTrace(); 77 | } 78 | catch (InterruptedException e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/demo/domain/oob/OperateLog.java: -------------------------------------------------------------------------------- 1 | package demo.domain.oob; 2 | 3 | import java.io.Serializable; 4 | 5 | public class OperateLog implements Serializable { 6 | private Long id; 7 | 8 | private String action; 9 | 10 | private String data; 11 | 12 | private Long authorId; 13 | 14 | private String ip; 15 | 16 | private Long created; 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | 24 | public void setId(Long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getAction() { 29 | return action; 30 | } 31 | 32 | public void setAction(String action) { 33 | this.action = action; 34 | } 35 | 36 | public String getData() { 37 | return data; 38 | } 39 | 40 | public void setData(String data) { 41 | this.data = data; 42 | } 43 | 44 | public Long getAuthorId() { 45 | return authorId; 46 | } 47 | 48 | public void setAuthorId(Long authorId) { 49 | this.authorId = authorId; 50 | } 51 | 52 | public String getIp() { 53 | return ip; 54 | } 55 | 56 | public void setIp(String ip) { 57 | this.ip = ip; 58 | } 59 | 60 | public Long getCreated() { 61 | return created; 62 | } 63 | 64 | public void setCreated(Long created) { 65 | this.created = created; 66 | } 67 | 68 | private OperateLog(Builder b) { 69 | id = b.id; 70 | action = b.action; 71 | data = b.data; 72 | authorId = b.authorId; 73 | ip = b.ip; 74 | created = b.created; 75 | } 76 | 77 | public OperateLog() { 78 | super(); 79 | } 80 | 81 | public static class Builder { 82 | private Long id; 83 | 84 | private String action; 85 | 86 | private String data; 87 | 88 | private Long authorId; 89 | 90 | private String ip; 91 | 92 | private Long created; 93 | 94 | public Builder id(Long id) { 95 | this.id = id; 96 | return this; 97 | } 98 | 99 | public Builder action(String action) { 100 | this.action = action; 101 | return this; 102 | } 103 | 104 | public Builder data(String data) { 105 | this.data = data; 106 | return this; 107 | } 108 | 109 | public Builder authorId(Long authorId) { 110 | this.authorId = authorId; 111 | return this; 112 | } 113 | 114 | public Builder ip(String ip) { 115 | this.ip = ip; 116 | return this; 117 | } 118 | 119 | public Builder created(Long created) { 120 | this.created = created; 121 | return this; 122 | } 123 | 124 | public OperateLog build() { 125 | return new OperateLog(this); 126 | } 127 | } 128 | } -------------------------------------------------------------------------------- /src/test/java/demo/mapper/oob/OperateLogMapper.java: -------------------------------------------------------------------------------- 1 | package demo.mapper.oob; 2 | 3 | import demo.domain.oob.OperateLog; 4 | import demo.domain.oob.OperateLogExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface OperateLogMapper { 9 | public static final String DATA_SOURCE_NAME = "null"; 10 | 11 | int countByExample(OperateLogExample example); 12 | 13 | int deleteByExample(OperateLogExample example); 14 | 15 | int deleteByPrimaryKey(Long id); 16 | 17 | int insert(OperateLog record); 18 | 19 | int insertSelective(OperateLog record); 20 | 21 | List selectByExample(OperateLogExample example); 22 | 23 | OperateLog selectByPrimaryKey(Long id); 24 | 25 | int updateByExampleSelective(@Param("record") OperateLog record, @Param("example") OperateLogExample example); 26 | 27 | int updateByExample(@Param("record") OperateLog record, @Param("example") OperateLogExample example); 28 | 29 | int updateByPrimaryKeySelective(OperateLog record); 30 | 31 | int updateByPrimaryKey(OperateLog record); 32 | 33 | int insertBatch(List records); 34 | } -------------------------------------------------------------------------------- /src/test/java/demo/mapper/ooc/UserVisitLogMapper.java: -------------------------------------------------------------------------------- 1 | package demo.mapper.ooc; 2 | 3 | import demo.domain.ooc.UserVisitLog; 4 | import demo.domain.ooc.UserVisitLogExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface UserVisitLogMapper { 9 | public static final String DATA_SOURCE_NAME = "db6"; 10 | 11 | int countByExample(UserVisitLogExample example); 12 | 13 | int deleteByExample(UserVisitLogExample example); 14 | 15 | int deleteByPrimaryKey(Integer id); 16 | 17 | int insert(UserVisitLog record); 18 | 19 | int insertSelective(UserVisitLog record); 20 | 21 | List selectByExample(UserVisitLogExample example); 22 | 23 | UserVisitLog selectByPrimaryKey(Integer id); 24 | 25 | int updateByExampleSelective(@Param("record") UserVisitLog record, @Param("example") UserVisitLogExample example); 26 | 27 | int updateByExample(@Param("record") UserVisitLog record, @Param("example") UserVisitLogExample example); 28 | 29 | int updateByPrimaryKeySelective(UserVisitLog record); 30 | 31 | int updateByPrimaryKey(UserVisitLog record); 32 | 33 | int insertBatch(List records); 34 | 35 | List selectByBigOffset(UserVisitLogExample example); 36 | } -------------------------------------------------------------------------------- /src/test/resources/dbconfig.properties: -------------------------------------------------------------------------------- 1 | #oralce的jdbc.driver 2 | oracle.jdbc.driver=oracle.jdbc.OracleDriver 3 | #oralce的jdbc.XAdriver 4 | oracle.jdbc.xa.driver=oracle.jdbc.xa.client.OracleXADataSource 5 | #mysql的jdbc.driver 6 | mysql.jdbc.driver=com.mysql.jdbc.Driver 7 | #mysql的jdbc.XAdriver 8 | mysql.jdbc.xa.driver=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource 9 | #sqlserver的jdbc.driver 10 | sqlserver.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver 11 | #sqlserver的jdbc.XAdriver 12 | sqlserver.jdbc.xa.driver=com.microsoft.sqlserver.jdbc.SQLServerXADataSource 13 | 14 | #local mysql 15 | db6.jdbc.url=jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8 16 | db6.jdbc.username=user 17 | db6.jdbc.password=pashwod 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/test/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | --------------------------------------------------------------------------------