├── .gitignore ├── NOTICE ├── src ├── main │ ├── java │ │ └── org │ │ │ └── mybatis │ │ │ └── generator │ │ │ ├── api │ │ │ ├── package.html │ │ │ ├── dom │ │ │ │ ├── xml │ │ │ │ │ ├── Element.java │ │ │ │ │ ├── TextElement.java │ │ │ │ │ ├── Attribute.java │ │ │ │ │ └── Document.java │ │ │ │ └── java │ │ │ │ │ ├── JavaVisibility.java │ │ │ │ │ ├── CompilationUnit.java │ │ │ │ │ └── Parameter.java │ │ │ ├── VerboseProgressCallback.java │ │ │ ├── GeneratedXmlFile.java │ │ │ ├── GeneratedJavaFile.java │ │ │ └── GeneratedFile.java │ │ │ ├── update │ │ │ └── update.txt │ │ │ ├── logging │ │ │ ├── AbstractLogFactory.java │ │ │ ├── Log.java │ │ │ ├── Log4jImpl.java │ │ │ ├── JdkLoggingImpl.java │ │ │ └── LogFactory.java │ │ │ ├── codegen │ │ │ ├── AbstractXmlGenerator.java │ │ │ ├── ibatis2 │ │ │ │ ├── IntrospectedTableIbatis2Java5Impl.java │ │ │ │ ├── sqlmap │ │ │ │ │ └── elements │ │ │ │ │ │ ├── DeleteByExampleElementGenerator.java │ │ │ │ │ │ ├── BaseColumnListElementGenerator.java │ │ │ │ │ │ ├── BlobColumnListElementGenerator.java │ │ │ │ │ │ └── CountByExampleElementGenerator.java │ │ │ │ └── dao │ │ │ │ │ └── templates │ │ │ │ │ ├── SpringDAOTemplate.java │ │ │ │ │ └── IbatisDAOTemplate.java │ │ │ ├── mybatis3 │ │ │ │ ├── javamapper │ │ │ │ │ └── elements │ │ │ │ │ │ ├── sqlprovider │ │ │ │ │ │ ├── AbstractJavaProviderMethodGenerator.java │ │ │ │ │ │ ├── ProviderSelectByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ │ └── ProviderUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ │ ├── annotated │ │ │ │ │ │ ├── AnnotatedCountByExampleMethodGenerator.java │ │ │ │ │ │ ├── AnnotatedDeleteByExampleMethodGenerator.java │ │ │ │ │ │ ├── AnnotatedUpdateByExampleSelectiveMethodGenerator.java │ │ │ │ │ │ ├── AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java │ │ │ │ │ │ ├── AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java │ │ │ │ │ │ ├── AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ │ │ └── AnnotatedInsertSelectiveMethodGenerator.java │ │ │ │ │ │ ├── InsertMethodGenerator.java │ │ │ │ │ │ ├── CountByExampleMethodGenerator.java │ │ │ │ │ │ ├── DeleteByExampleMethodGenerator.java │ │ │ │ │ │ ├── InsertSelectiveMethodGenerator.java │ │ │ │ │ │ ├── UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java │ │ │ │ │ │ ├── UpdateByPrimaryKeyWithBLOBsMethodGenerator.java │ │ │ │ │ │ ├── UpdateByPrimaryKeySelectiveMethodGenerator.java │ │ │ │ │ │ └── UpdateByExampleSelectiveMethodGenerator.java │ │ │ │ └── xmlmapper │ │ │ │ │ ├── MixedMapperGenerator.java │ │ │ │ │ └── elements │ │ │ │ │ ├── DeleteByExampleElementGenerator.java │ │ │ │ │ ├── CountByExampleElementGenerator.java │ │ │ │ │ ├── BaseColumnListElementGenerator.java │ │ │ │ │ └── BlobColumnListElementGenerator.java │ │ │ ├── AbstractJavaClientGenerator.java │ │ │ ├── AbstractGenerator.java │ │ │ └── XmlConstants.java │ │ │ ├── exception │ │ │ ├── InvalidConfigurationException.java │ │ │ ├── XMLParserException.java │ │ │ └── ShellException.java │ │ │ ├── config │ │ │ ├── MergeConstants.java │ │ │ ├── JavaTypeResolverConfiguration.java │ │ │ ├── CommentGeneratorConfiguration.java │ │ │ ├── TypedPropertyHolder.java │ │ │ ├── ModelType.java │ │ │ ├── PluginConfiguration.java │ │ │ ├── PropertyHolder.java │ │ │ ├── xml │ │ │ │ ├── ParserEntityResolver.java │ │ │ │ └── ParserErrorHandler.java │ │ │ ├── SqlMapGeneratorConfiguration.java │ │ │ └── JavaModelGeneratorConfiguration.java │ │ │ ├── ant │ │ │ └── AntProgressCallback.java │ │ │ ├── internal │ │ │ ├── NullProgressCallback.java │ │ │ ├── rules │ │ │ │ ├── FlatModelRules.java │ │ │ │ ├── HierarchicalModelRules.java │ │ │ │ └── ConditionalModelRules.java │ │ │ ├── db │ │ │ │ └── ActualTableName.java │ │ │ └── util │ │ │ │ ├── EqualsUtil.java │ │ │ │ ├── ClassloaderUtility.java │ │ │ │ └── messages │ │ │ │ └── Messages.java │ │ │ └── plugins │ │ │ └── AnnotationPlugin.java │ ├── resources │ │ ├── log4j.properties │ │ ├── generatorConfigIbatis2.xml │ │ ├── grid.xml │ │ ├── mysql_bank.xml │ │ ├── ConfigIbatis_bank.xml │ │ └── ConfigIbatis_wht.xml │ └── assembly │ │ └── src.xml └── test │ ├── resources │ ├── log4j.properties │ ├── generatorConfigIbatis2.xml │ ├── grid.xml │ ├── grid1.xml │ ├── authority_mysql.xml │ └── datacheck_mysql.xml │ └── java │ ├── test │ └── _Ibator_Run_Test.java │ └── org │ └── mybatis │ └── generator │ └── MyBatisGeneratorTest.java ├── doc ├── html │ ├── index.html │ ├── reference │ │ ├── intro.html │ │ └── building.html │ ├── usage │ │ ├── intro.html │ │ ├── db2.html │ │ ├── oracle.html │ │ ├── mysql.html │ │ └── postgresql.html │ ├── generatedobjects │ │ └── results.html │ ├── configreference │ │ ├── generatorConfiguration.html │ │ ├── property.html │ │ ├── ignoreColumn.html │ │ ├── properties.html │ │ ├── classPathEntry.html │ │ └── jdbcConnection.html │ ├── license.html │ ├── running │ │ └── running.html │ └── migratingFromIbator.html └── todo.txt ├── README.md └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .springBeans 4 | .settings/ 5 | target/ 6 | logs/ 7 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This product includes software developed by 2 | The Apache Software Foundation (http://www.apache.org/). 3 | 4 | This product includes the EqualsUtil and HashCodeUtil classes 5 | from http://www.javapractices.com. 6 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/api/package.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |Provides the main classes and interfaces used by clients of MyBatis Generator.
7 | 8 | 9 | -------------------------------------------------------------------------------- /doc/html/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |This section collects useful information related to technical topics 20 | with MyBatis Generator.
21 | 22 |This section collects usage information for different databases.
20 | 21 |Please let us know about any quirks you discover for the database you are using - we will 28 | be happy to add the information 29 | to this section for future reference.
30 | 31 | 32 | -------------------------------------------------------------------------------- /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/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/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 ListBy default MyBatis Generator will map LONG VARCHAR fields to the java.lang.String data type,
21 | and will mark these fields as jdbcType="LONGVARCHAR". This
22 | mapping will cause errors when retrieving data from DB2. DB2 LONG VARCHAR fields should be mapped
23 | to the java.lang.String data type with jdbcType="VARCHAR". To overcome
24 | this problem, use a <columnOverride> as follows:
26 | <table schema="DB2ADMIN" tableName="ALLTYPES" > 27 | <columnOverride column="LONG_VARCHAR_FIELD" javaType="java.lang.String" jdbcType="VARCHAR" /> 28 | </table> 29 |30 | 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 | -------------------------------------------------------------------------------- /doc/html/usage/oracle.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |
If you want to generate objects for a table that has a public synonym, you 21 | should actually generate the objects against the real table - and then change the 22 | table name at runtime. MyBatis Generator supports this automatically.
23 |For example, assume there is a public alias "FRED" that points to the 24 | table "HR.EMPLOYEES". The following table configuration will generate the objects 25 | based on HR.EMPLOYEES, but the runtime SQL will only refer to FRED:
26 |27 | <table schema="HR" tableName="EMPLOYEES"> 28 | <property name="ignoreQualifiersAtRuntime" value="true" /> 29 | <property name="runtimeTableName" value="FRED" /> 30 | </table> 31 |32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/html/generatedobjects/results.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |
MyBatis Generator (MBG) generates these types of objects:
20 |The individual pages describe these objects, and their usage.
34 | 35 | 36 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /doc/html/usage/mysql.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |MySql supports both signed, and unsigned, numeric fields. These are not JDBC types, so MyBatis
21 | generator cannot automatically account for these types of fields. The Java data types are always signed.
22 | This can
23 | lead to a loss of precision when using unsigned fields. The solution is to provide a
24 | <columnOverride> for any unsigned numeric field in MySql. Here is an example
25 | of how to deal with an unsigned bigint field in MySql:
27 | <table tableName="ALLTYPES" > 28 | <columnOverride column="UNSIGNED_BIGINT_FIELD" javaType="java.lang.Object" jdbcType="LONG" /> 29 | </table> 30 |31 |
You will have to cast the returned value to the appropriate type yourself (in this case,
32 | java.math.BigInteger).
The <generatorConfiguration> element is the root element of a 20 | MyBatis Generator configuration file. The file should contain the following DOCTYPE: 21 |
22 |23 | <!DOCTYPE generatorConfiguration PUBLIC 24 | "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" 25 | "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 26 |27 | 28 |
None
30 | 31 |None
33 | 34 |The <property> element is used to specify properties for many of the 20 | other elements. The documentation page for each element that supports the 21 | property element lists the different values that are valid. This element 22 | can also be used to pass properties to any custom code generators that 23 | you implement.
24 | 25 || Attribute | 29 |Description | 30 |
|---|---|
| name | 33 |The name of the property (case sensitive). | 34 |
| value | 37 |The value of the property (typically case insensitive). | 38 |
None
43 | 44 |None
46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/generator/ant/AntProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The Apache Software Foundation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.mybatis.generator.ant; 18 | 19 | import org.apache.tools.ant.Project; 20 | import org.apache.tools.ant.Task; 21 | import org.mybatis.generator.internal.NullProgressCallback; 22 | 23 | /** 24 | * This callback logs progress messages with the Ant logger 25 | * 26 | * @author Jeff Butler 27 | * 28 | */ 29 | public class AntProgressCallback extends NullProgressCallback { 30 | 31 | private Task task; 32 | private boolean verbose; 33 | 34 | /** 35 | * 36 | */ 37 | public AntProgressCallback(Task task, boolean verbose) { 38 | super(); 39 | this.task = task; 40 | this.verbose = verbose; 41 | } 42 | 43 | @Override 44 | public void startTask(String subTaskName) { 45 | if (verbose) { 46 | task.log(subTaskName, Project.MSG_VERBOSE); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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/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/test/java/test/_Ibator_Run_Test.java: -------------------------------------------------------------------------------- 1 | package test; 2 | import org.apache.log4j.Logger; 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import org.mybatis.generator.api.MyBatisGenerator; 7 | import org.mybatis.generator.config.Configuration; 8 | import org.mybatis.generator.config.xml.ConfigurationParser; 9 | import org.mybatis.generator.internal.DefaultShellCallback; 10 | 11 | public class _Ibator_Run_Test { 12 | private static final Logger logger = Logger.getLogger(_Ibator_Run_Test.class); 13 | 14 | public static void main(String[] args) { 15 | _Ibator_Run_Test test = new _Ibator_Run_Test(); 16 | // test.main1("grid1.xml"); 17 | // test.main1("mysql.xml"); 18 | // test.main1("mysql_bank.xml"); 19 | test.main1("authority_mysql.xml"); 20 | // test.main1("authority_oracle.xml"); 21 | // test.main1("tsm_oracle.xml"); 22 | // test.main1("ejt_oracle.xml"); 23 | // test.main1("datacheck_sql_2.xml"); 24 | // test.main1("oracle.xml"); 25 | } 26 | 27 | public void main1(String fileName) { 28 | try { 29 | ListLicensed under the Apache License, Version 2.0 (the "License"); 20 | you may not use this product except in compliance with the License. 21 | You may obtain a copy of the License at 22 |
23 |24 | http://www.apache.org/licenses/LICENSE-2.0
25 |26 | Unless required by applicable law or agreed to in writing, software 27 | distributed under the License is distributed on an "AS IS" BASIS, 28 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | See the License for the specific language governing permissions and 30 | limitations under the License. 31 |
32 | 33 |This product includes software developed by the Apache Software 34 | Foundation (http://www.apache.org/).
35 | 36 |This product includes the EqualsUtil and HashCodeUtil classes
37 | from http://www.javapractices.com.
The <ignoreColumn> element is used to tell MyBatis Generator (MBG) to ignore a column 20 | in an introspected table. No generated SQL will refer to the column, and no 21 | property will be generated for the column in the model objects. 22 | This element is an optional child 23 | element of the <table> element.
24 | 25 || Attribute | 29 |Description | 30 |
|---|---|
| column | 33 |The column name of the ignored column. | 34 |
| Attribute | 41 |Description | 42 |
|---|---|
| delimitedColumnName | 45 |If true then MBG will perform a case-sensitive exact
46 | match when matching against returned columns from the database. If
47 | false (default) then the name is considered case-insensitive. |
48 |
None
53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /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 an XML 20 | * generator is required to match the methods in the Java client. For example, a 21 | * Java client built entirely with annotations does not need matching XML. 22 | * 23 | * @author Jeff Butler 24 | * 25 | */ 26 | public abstract class AbstractJavaClientGenerator extends AbstractJavaGenerator { 27 | 28 | private boolean requiresXMLGenerator; 29 | 30 | public AbstractJavaClientGenerator(boolean requiresXMLGenerator) { 31 | super(); 32 | this.requiresXMLGenerator = requiresXMLGenerator; 33 | } 34 | 35 | /** 36 | * @return true if matching XML is required 37 | */ 38 | public boolean requiresXMLGenerator() { 39 | return requiresXMLGenerator; 40 | } 41 | 42 | /** 43 | * This method returns an instance of the XML generator associated with this 44 | * client generator. 45 | * 46 | * @return the matched XML generator. May return null if no XML is required 47 | * by this generator 48 | */ 49 | public abstract AbstractXmlGenerator getMatchedXMLGenerator(); 50 | } 51 | -------------------------------------------------------------------------------- /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 ProviderSelectByExampleWithoutBLOBsMethodGenerator { 30 | 31 | public ProviderSelectByExampleWithBLOBsMethodGenerator() { 32 | super(); 33 | } 34 | 35 | @Override 36 | public ListPostgreSQL is case sensitive with regards to all database identifiers 21 | (table names, schema names, column names, etc.) In addition, PostgreSQL 22 | has a distinct preference for all identifiers being in all lower case letters. 23 | If you use all lower case identifiers for PostgreSQL, then MyBatis Generator will find tables 24 | and write correct SQL with no additional consideration. If you used mixed cased, 25 | or upper case, identifiers you will 26 | need to configure MyBatis Generator appropriately:
27 |delimitIdentifiers option if your table or schema
29 | is mixed case or all upper case.<columnOverride> element to specifically delimit the column,
32 | or you could specify the delimitAllColumns attribute
33 | to delimit all column names.Examples:
36 |37 | <table schema="HR" tableName="Employees" 38 | delimitIdentifiers="true" delimitAllColumns="true"/> 39 |40 |
Or...
41 |42 | <table schema="HR" tableName="Employees" delimitIdentifiers="true" > 43 | <columnOverride column="EmployeeId" delimitedColumnName="true" /> 44 | <columnOverride column="EmployeeName" delimitedColumnName="true" /> 45 | </table> 46 |47 | 48 | 49 | -------------------------------------------------------------------------------- /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
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) && EqualsUtil.areEqual(this.fNumDoors, that.fNumDoors)
20 | * && EqualsUtil.areEqual(this.fGasMileage, that.fGasMileage) && EqualsUtil.areEqual(this.fColor, that.fColor)
21 | * && Arrays.equals(this.fMaintenanceChecks, that.fMaintenanceChecks); // array!
22 | * }
23 | *
24 | *
25 | * Arrays are not handled by this class. This is because the
26 | * Arrays.equals methods should be used for array fields.
27 | */
28 | public final class EqualsUtil {
29 |
30 | static public boolean areEqual(boolean aThis, boolean aThat) {
31 | return aThis == aThat;
32 | }
33 |
34 | static public boolean areEqual(char aThis, char aThat) {
35 | return aThis == aThat;
36 | }
37 |
38 | static public boolean areEqual(long aThis, long aThat) {
39 | /*
40 | * Implementation Note Note that byte, short, and int are handled by
41 | * this method, through implicit conversion.
42 | */
43 | return aThis == aThat;
44 | }
45 |
46 | static public boolean areEqual(float aThis, float aThat) {
47 | return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat);
48 | }
49 |
50 | static public boolean areEqual(double aThis, double aThat) {
51 | return Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat);
52 | }
53 |
54 | /**
55 | * Possibly-null object field.
56 | *
57 | * Includes type-safe enumerations and collections, but does not include
58 | * arrays. See class comment.
59 | */
60 | static public boolean areEqual(Object aThis, Object aThat) {
61 | return aThis == null ? aThat == null : aThis.equals(aThat);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/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 |
28 | private ListThe <properties> element is used to specify an external properties file
20 | for use in the parsing of the configuration. Any attribute in the
21 | configuration will accept a property in the form ${property}.
22 | The specified properties file will be searched for a matching value and the
23 | matching value will be substituted. The properties file is of the normal
24 | format for a Java properties file.
The <properties> element is a child element of the 27 | <generatorConfiguration> 28 | element.
29 | 30 | 31 |One, and only one, of the following attributes is required.
33 || Attribute | 36 |Description | 37 |
|---|---|
| resource | 40 |The qualified name of the property file. When specifying the resource, the
41 | classpath will be searched for the properties file. So a file specified as
42 | com/myproject/generatorConfig.properties must exist in the
43 | com.myproject package. |
44 |
| url | 47 |A URL value to use for the property file. This can be used to specify a property
48 | file in a specific place on the file system when used in a form like
49 | file:///C:/myfolder/generatorConfig.properties. |
50 |
None
55 | 56 |None
58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /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 InsertSelectiveMethodGenerator { 29 | 30 | public AnnotatedInsertSelectiveMethodGenerator() { 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.InsertProvider")); //$NON-NLS-1$ 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append("@InsertProvider(type="); //$NON-NLS-1$ 40 | sb.append(fqjt.getShortName()); 41 | sb.append(".class, method=\""); //$NON-NLS-1$ 42 | sb.append(introspectedTable.getInsertSelectiveStatementId()); 43 | sb.append("\")"); //$NON-NLS-1$ 44 | 45 | method.addAnnotation(sb.toString()); 46 | 47 | GeneratedKey gk = introspectedTable.getGeneratedKey(); 48 | if (gk != null) { 49 | addGeneratedKeyAnnotation(interfaze, method, gk); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /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.getBundle(BUNDLE_NAME); 29 | 30 | private Messages() { 31 | } 32 | 33 | public static String getString(String key) { 34 | try { 35 | return RESOURCE_BUNDLE.getString(key); 36 | } catch (MissingResourceException e) { 37 | return '!' + key + '!'; 38 | } 39 | } 40 | 41 | public static String getString(String key, String parm1) { 42 | try { 43 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), new Object[] { parm1 }); 44 | } catch (MissingResourceException e) { 45 | return '!' + key + '!'; 46 | } 47 | } 48 | 49 | public static String getString(String key, String parm1, String parm2) { 50 | try { 51 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), new Object[] { parm1, parm2 }); 52 | } catch (MissingResourceException e) { 53 | return '!' + key + '!'; 54 | } 55 | } 56 | 57 | public static String getString(String key, String parm1, String parm2, String parm3) { 58 | try { 59 | return MessageFormat.format(RESOURCE_BUNDLE.getString(key), new Object[] { parm1, parm2, parm3 }); 60 | } catch (MissingResourceException e) { 61 | return '!' + key + '!'; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/resources/mysql_bank.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |MyBatis Generator (MBG) can be run in the following ways:
20 |Each method is described in detail on the linked pages.
30 |Note: there is also an Eclipse 31 | plugin for MBG that adds extra function - namely good integration into Eclipse, 32 | an Eclipse enabled Ant task, and support for automatic merging of 33 | Java files. See the 34 | MyBatis 35 | web site page for information on installing the Eclipse plugin.
36 | 37 |Important: When running outside of an IDE environment like Eclipse,
38 | MBG interprets the targetProject and
39 | targetPackage attributes in all XML configurations as follows:
targetProject is assumed to be an existing directory structure.
42 | MBG will fail if this directory structure does not exist. There is one exception to this
43 | rule - when MBG is running through the Maven plugin. See the Maven plugin page
44 | for information about how targetProject is interpreted in Maven.targetPackage will be translated to a suitable subdirectory
46 | structure of the targetProject
47 | directory structure. MBG will create these subdirectories if necessary.This page details changes between MyBatis Generator (MBG) 20 | and Ibator. For most users, the changes should be simple. 21 | If you extended any of Ibator's classes to supply custom implementations 22 | of code generators or the Java type resolver, you will need to rework 23 | those custom classes.
24 |Changes 25 | are described assuming you are using XML configuration for MBG. If you 26 | are using Java based configuration, then the changes are still required 27 | and should be easy to deduce from the description of the XML changes.
28 |Important Note: MBG will correctly parse older Ibator configuration files, so no change is actually 29 | required. However, new features will only be implemented in configuration files 30 | that conform to the MyBatis Generator DTD.
31 |35 | 36 | <!DOCTYPE generatorConfiguration 37 | PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" 38 | "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 39 |40 |
<ibatorConfiguration> element is renamed to
43 | <generatorConfiguration><ibatorContext> element is renamed to
45 | <context><ibatorPlugin> element is renamed to
47 | <plugin><daoGenerator> element is renamed to
49 | <javaClientGenerator>daoXXX methods have been renamed
51 | to clientXXX.The <classPathEntry> element is used to add classpath locations to the 20 | classpath of the MyBatis Generator (MBG) run. The <classPathEntry> element is an option child 21 | element of the <generatorConfiguration> element. 22 | MBG loads classes from these locations in these instances:
23 |This element is optional and is not required if you setup the classpath externally to MBG
30 | (e.g. with the -cp argument of the java command
Important Note: these locations are NOT used when loading classes that
33 | extend one of MBG's classes or implement one of MBG's interfaces. In those cases
34 | you must add your external classes to the runtime classpath in the same way you
35 | add MBG to the classpath (e.g. with the -cp argument of the
36 | java command).
| Attribute | 42 |Description | 43 |
|---|---|
| location | 46 |The full path name of a JAR/ZIP file to add to the classpath, or 47 | a directory to add to the classpath. | 48 |
None
53 | 54 |None
56 | 57 | 58 |This element specifies the location of a DB2 JDBC driver:
60 |61 | <classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" /> 62 |63 | 64 | 65 | -------------------------------------------------------------------------------- /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 AbstractXmlElementGenerator { 28 | 29 | public DeleteByExampleElementGenerator() { 30 | super(); 31 | } 32 | 33 | @Override 34 | public void addElements(XmlElement parentElement) { 35 | XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$ 36 | 37 | answer.addAttribute(new Attribute("id", introspectedTable.getDeleteByExampleStatementId())); //$NON-NLS-1$ 38 | answer.addAttribute(new Attribute("parameterClass", introspectedTable.getExampleType())); //$NON-NLS-1$ 39 | 40 | context.getCommentGenerator().addComment(answer); 41 | 42 | StringBuilder sb = new StringBuilder(); 43 | sb.append("delete from "); //$NON-NLS-1$ 44 | sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()); 45 | answer.addElement(new TextElement(sb.toString())); 46 | 47 | XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$ 48 | sb.setLength(0); 49 | sb.append(introspectedTable.getIbatis2SqlMapNamespace()); 50 | sb.append('.'); 51 | sb.append(introspectedTable.getExampleWhereClauseId()); 52 | includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$ 53 | sb.toString())); 54 | 55 | answer.addElement(includeElement); 56 | 57 | if (context.getPlugins().sqlMapDeleteByExampleElementGenerated(answer, introspectedTable)) { 58 | parentElement.addElement(answer); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /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
The <jdbcConnection> element is used to specify the properties of 20 | the database connection required to introspect tables. MyBatis Generator uses JDBC's 21 | DatabaseMetaData class to discover the properties of the tables you specify 22 | in the configuration. One <jdbcConnection> element is required for 23 | each <context> element.
24 | 25 || Attribute | 29 |Description | 30 |
|---|---|
| driverClass | 33 |The fully qualified class name for the JDBC driver used to access the 34 | database. 35 | | 36 |
| connectionURL | 39 |The JDBC connection URL used to access the database. | 40 |
| Attribute | 47 |Description | 48 |
|---|---|
| userId | 51 |The user ID used to connect to the database. | 52 |
| password | 55 |The password used to connect to the database. | 56 |
This element will connect to a DB2 database configured as 68 | MBGTEST in the DB2 client configuration utility, using 69 | the default install location for the JDBC driver:
70 |71 | <jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver" 72 | connectionURL="jdbc:db2:MBGTEST" 73 | userId="db2admin" 74 | password="db2admin"> 75 | </jdbcConnection> 76 |77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /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
All MyBatis Generator (MBG) distributions include source code. The only compile time dependency
20 | is on ant.jar - for successful compilation of the included Ant task.
21 | It is straight forward to compile MBG from source - simply unzip the source in
22 | a distribution and compile it with your favorite tool.
The MBG distribution does not contain the tests that are run during the build, 24 | or other classes that are a necessary part of the build. If you would like to 25 | inspect those classes, or build MBG from the very latest version of the source code 26 | at Google then follow these steps:
27 |mvn clean install - or any of the other Maven lifecycle commands.
48 | You can use the mvn site command to generate the code coverage reports, but the
49 | MyBatis website is not built with Maven at this time.
50 |