This page lists scripts for testing the different parts of the MyBatis Generator UI. This information may also be helpful in learning how to use the different parts of the Eclipse user interface for MyBatis Generator.
The following tests are intended to be executed in the order listed. Some tests build on items created in previous tests.
src
generatedsrc
src
folder called config
config
packagesrc
folder called base
base
package named BaseModel
private Integer id
to BaseModel
and generate
getters and setters. Then mark the getter and setter final
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" > <generatorConfiguration> <context id="context1" targetRuntime="MyBatis3Simple" > <jdbcConnection driverClass="${driver}" connectionURL="jdbc:hsqldb:mem:aname" userId="sa" > </jdbcConnection> <javaModelGenerator targetPackage="gen.model" targetProject="MBGTest" > <!-- <property name="rootClass" value="base.BaseModel" /> --> </javaModelGenerator> <sqlMapGenerator targetPackage="gen.mapper" targetProject="MBGTest" /> <javaClientGenerator targetPackage="gen.mapper" targetProject="MBGTest" type="XMLMAPPER" /> <table tableName="a" /> </context> <context id="context2" targetRuntime="MyBatis3Simple" > <connectionFactory type="DEFAULT" > <property name="driverClass" value="org.hsqldb.jdbcDriver" /> <property name="connectionURL" value="jdbc:hsqldb:mem:aname" /> <property name="userId" value="sa" /> </connectionFactory> <javaModelGenerator targetPackage="gen.src.model" targetProject="MBGTest/generatedsrc" /> <sqlMapGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" /> <javaClientGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" type="XMLMAPPER" /> <table schema="mbgtest" tableName="%" /> </context> </generatorConfiguration>
drop table a if exists; drop table mbgtest.b if exists; drop table mbgtest.b if exists; drop table mbgtest.c if exists; drop table mbgtest.d if exists; drop table mbgtest.e if exists; drop table mbgtest.f if exists; drop table mbgtest.g if exists; drop table mbgtest.h if exists; drop table mbgtest.i if exists; drop table mbgtest.j if exists; drop schema if exists mbgtest; create schema mbgtest; create table a (id int not null, description varchar(50), primary key(id)); create table mbgtest.b (id int not null, description varchar(50), primary key(id)); create table mbgtest.c (id int not null, description varchar(50), primary key(id)); create table mbgtest.d (id int not null, description varchar(50), primary key(id)); create table mbgtest.e (id int not null, description varchar(50), primary key(id)); create table mbgtest.f (id int not null, description varchar(50), primary key(id)); create table mbgtest.g (id int not null, description varchar(50), primary key(id)); create table mbgtest.h (id int not null, description varchar(50), primary key(id)); create table mbgtest.i (id int not null, description varchar(50), primary key(id)); create table mbgtest.j (id int not null, description varchar(50), primary key(id));
gen.model.A.java
in the "src" folder@mbg.generated
commentsmergetest
and generate a getter and setter
for the field.gen.model.A.java
in the "src" foldermergetest
, and its getter and setter remain
in the file (they will have been moved to the bottom of the file)gen.model.A
now extends BaseModel
. You should not have needed to
alter the launch configuration classpath - the launch configuration automatically adds the project
to the classpath of the generator.gen.model.A
- the generator
should not have generated a get and set method that override the final
methods in the base classgen.model.A
doesn't extend anything. There will be one
warning in the file related to an unused import (the Java merger does not reconcile all
imports). Delete the import and verify that there are no other errors in the
workspace. Also, verify that the field mergetest
and its
associated getter and setter still exist, and that the id field and its
getter and setter are back in the class.build.xml
in the "MBGTest/src/config" package.<project default="runMyBatisGenerator"> <target name="runMyBatisGenerator"> <eclipse.convertPath resourcepath="MBGTest/src/config/create_db.sql" property="theScriptPath"/> <sql driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:mem:aname" userid="sa" password="" src="${theScriptPath}"/> <eclipse.convertPath resourcepath="MBGTest/src/config/generatorConfig.xml" property="thePath"/> <mybatis.generate configfile="${thePath}" /> </target> </project>
gen.src.model.A
. There will now be errors in the
workspace.build.xml
file, then select the
menu option "Run As>Ant Build...". You should see the Ant launch configuration
dialog open.${driver}
with org.hsqldb.jdbcDriver
.
There is a limitation in Eclipse that you cannot change environment variables for builds that run in the same
JRE as the workspace.
build.xml
file, then select the
menu option "Run As>Ant Build...". You should see the Ant launch configuration
dialog open.