Due to the lack of in-depth understanding of ibator, resolutely began to modify the process of Ibator plug-ins, the process of modification of the harvest is very large, understand the many uses of this plug-in skills.
1. Automatically generated code in the annoying example how to rename.
This is also driving me to modify Ibator plugin's driving force, because I lazy, do not want to generate code every time after the replacement of example words, using Ultraeditor automatically ibator source program All example are replaced, replaced after found, Ibator Plug-ins can automatically help us replace, configure a parameter on it, Khan AH. The replacement content is as follows:
<!--
ID This ID can be specified when running abator using the command line to handle a single ibatorcontext
Targetruntime IBATIS2JAVA5 generates classes that are suitable for JDK5.0, and another option is IBATIS2JAVA2, which generates classes that are suitable for Java2.
-->
<ibatorplugin type= "Org.apache.ibatis.ibator.plugins.RenameExampleClassPlugin" >
<property name= "searchstring" value= "example$"/>
<property name= "replacestring" value= "Criteria"/>
</ibatorPlugin>
<!--
Ibatorplugin inherits from Ibatorpluginadapter, the package name must be org.apache.ibatis.ibator.plugins, the concrete implementation may refer to the official document
Must have replacement and replaced character attributes.
-->
2. Since the start of the change, it is not pleasing to see where all the change it, the following is convenient for future changes when you want to see the content:
Code comments in the Defaultcommentgenerator.java under the package of org.apache.ibatis.ibator.internal, you can change the English annotation to Chinese, but the annotation in the sqlmap can not be directly changed to Chinese, because Sqlmap When the. xml file is UTF-8 encoded, writing the Chinese annotation directly will appear garbled.
In the Mergeconstants.java under Org.apache.ibatis.ibator.config This package contains some words in the code annotation that can be considered for modification.
3. Here are some of the things that come from someone else's blog:
1. When Abator generates Java class files, the attributes and methods based on annotations are either system-generated or user-defined, which determines whether to retain or overwrite them.
2, abator generate sqlmap XML file, depending on whether the element ID contains a prefix ibatorgenerated_ distinguishing elements is the system
Build or user-defined, so that you decide to keep or overwrite ...
3, note the order of the nodes in the Ibatorconfig.xm file
4, the generated data object
Primary Key class all the constituent fields of the primary key are in a class
Record Class A class that is not a BLOB field that is not a primary key field and inherits from the primary key class
A class that consists of all BLOB fields of the record with BLOBs class, inherited from the record class (if not present), inherits the primary Key class
Tables that contain only BLOB fields are not supported.
Example class to generate a dynamic where condition
5, example Class use (you can use the binding law of logical operations to simplify where conditions)
Code:
testtableexample example = new Testtableexample ();
Example.createcriteria (). Andfield1equalto (5);
Production conditions:
where field1 = 5
Code:
testtableexample example = new Testtableexample ();
Example.createcriteria ()
. Andfield1equalto (5)
. Andfield2isnull ();
Example.or (Example.createcriteria ()
. Andfield3notequalto (9)
. Andfield4isnotnull ());
list<integer> field5values = new arraylist<integer> ();
Field5values.add (8);
Field5values.add (11);
Field5values.add (14);
Field5values.add (22);
Example.or (Example.createcriteria ()
. andfield5in (Field5values));
Example.or (Example.createcriteria ()
. Andfield6between (3, 7));
Production conditions:
WHERE (field1 = 5 and field2 is null)
or (field3 <> 9 and field4 is not null)
or (Field5 in (8, 11, 14, 22))
or (Field6 between 3 and 7)
6, IBATORCONFIG.XM file analysis
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE ibatorconfiguration Public "-//apache Software foundation//dtd Apache iBATIS ibator Configuration 1.0//en" "http: Ibatis.apache.org/dtd/ibator-config_1_0.dtd ">
<ibatorConfiguration>
<properties url= "File:/home/guo/workspace_google/ibatis/config/config.properties"/>
<!--
The URL specifies the absolute path to the property file. Note the difference with the specified database JDBC-driven Jar pack path ha.
You can use the format of ${property} to refer to property values in the property file.
-->
<classpathentry location= "/home/guo/java/workspace/newbee/lib/ibatis/postgresql-8.3-604.jdbc3.jar"/>
<!--
CLASSPATHENTRY specifies the absolute path of the database JDBC driver jar package.
-->
<ibatorcontext id= "Context1" targetruntime= "Ibatis2java5" >
<!--
ID This ID can be specified when running abator using the command line to handle a single ibatorcontext
Targetruntime IBATIS2JAVA5 generates classes that are suitable for JDK5.0, and another option is IBATIS2JAVA2, which generates classes that are suitable for Java2.
-->
<ibatorplugin type= "Org.apache.ibatis.ibator.plugins.RenameExampleClassPlugin" >
<property name= "searchstring" value= "example$"/>
<property name= "replacestring" value= "Criteria"/>
</ibatorPlugin>
<!--
Ibatorplugin inherits from Ibatorpluginadapter, the package name must be org.apache.ibatis.ibator.plugins, the concrete implementation may refer to the official document
Must have replacement and replaced character attributes.
-->
<jdbcconnection driverclass= "Org.postgresql.Driver" connectionurl= "Jdbc:postgresql://192.168.1.2:5432/newbee" userid= "sa" password= "Esoon"/>
<!--
Driverclass database Driver Class
Connectionurl Database Connection Address
UserId Users
Password Password
You can also add additional connection properties for a database using the following format
<property name= "" value= ""/>
-->
<javatyperesolver >
<property name= "Forcebigdecimals" value= "false"/>
<!--
Default false to resolve JDBC DECIMAL and NUMERIC types to Integer
True to resolve the JDBC DECIMAL and NUMERIC types to Java.math.BigDecimal
-->
</javaTypeResolver>
<javamodelgenerator targetpackage= "Com.newbee.bean" targetproject= "Newbee/src"/>
<!--
Targetproject the Java bean generated is placed in which directory of which project
Targetpackage the package name of the generated Java bean
A useful property
<property name= "Trimstrings" value= "true"/>
Space before and after the value returned from the database is cleaned
<property name= "Enablesubpackages" value= "false"/>
Whether to add scheme name after package name
-->
<sqlmapgenerator targetpackage= "Com.newbee.xml" targetproject= "Newbee/src"/>
<!--
Targetproject the generated sqlmap.xml files are placed in which directory of which project
Targetpackage the package name of the generated sqlmap.xml file
<property name= "Enablesubpackages" value= "false"/>
Whether to add scheme name after package name
-->
<daogenerator targetpackage= "Com.newbee.dao" targetproject= "newbee/src" type= "Generic-ci"/>
<!--
Which directory is the targetproject generated DAO class files placed in
Targetpackage the package name of the generated DAO class file
<property name= "Enablesubpackages" value= "false"/>
Whether to add scheme name after package name
Type to generate a DAO file, optionally Ibatis, SPRING, Generic-ci, Generic-si. Default Use Generic-ci
The DAO class gets the Sqlmapclient in the constructor.
-->
<table tablename= "Alltypes" domainobjectname= "Customer" >
<!--
The TableName database indicates that it is said to contain SQL wildcard characters% and _.
Domainobjectname the data object name for the database table, using the table name as the object name by default.
-->
<property name= "Useactualcolumnnames" value= "true"/>
<!--
Whether the object's property name uses the field name
-->
<generatedkey column= "ID" sqlstatement= "DB2" identity= "true"/>
<!--
Column from growing or using sequence-generated field names
SQLStatement the SQL fragment that generated the field or its abbreviation (refer to official documentation)
Build after identity true, false to pre-build
For example:
Postgresql:<generatedkey
column= "Lid"
Sqlstatement= "Select Nextval (' Tb000000producttype_lid_seq ')"
Identity= "false"/>
Sqlserver:<generatedkey
column= "Lid"
sqlstatement= "SQL Server"
Identity= "true"/>
Oracle:<generatedkey
column= "Lid"
Sqlstatement= "Select Tb000000producttype_lid_seq.nextval from Dual"
Identity= "false"/>
-->
<columnoverride column= "Date_field" property= "StartDate"/>
<!--
column Field name
Property name corresponding to the Properties field. (using the field name by default)
Javatype corresponding Java type
Jdbctype corresponding JDBC Type
The settings here override the designation in the Javatyperesolver
-->
<ignorecolumn column= "FRED"/>
<!--
Column database fields that need to be ignored
-->
<columnrenamingrule searchstring= "^cust_" replacestring= ""/>
<!--
The mapping relationship between the database field name and the object property name. is a substitution process.
-->
</table>
</ibatorContext>
</ibatorConfiguration>