AbatorForEclipse是IbatorForEclipse之前的一个老版插件。
插件装好后,我们来使用看看:
1,新建一个工程AbatorTest,点击右键,新建一个abatorConfig.xml,如图:

建好后如下图:


2,
我这里是用的mysql,修改abatisconfig.xml文件如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE abatorConfiguration PUBLIC
"-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN"
"http://ibatis.apache.org/dtd/abator-config_1_0.dtd" >
<abatorConfiguration >

<abatorContext>
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/otm" userId="root" password="sa" >
<classPathEntry location="D:\apache-tomcat-6.0.20\webapps\ibatis_stu\WEB-INF\lib\mysql-connector-java-5.1.7-bin.jar" />
</jdbcConnection>
<javaModelGenerator targetPackage="com.test.dto" targetProject="AbatorTest" >
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.test.sqlmap" targetProject="AbatorTest" />
<daoGenerator targetPackage="com.test.dao" targetProject="AbatorTest" type="GENERIC-CI" />
<table? tableName="customer" >
<generatedKey column="ID" sqlStatement="select LAST_INSERT_ID()" identity="true" />
</table>
<table? tableName="orders"/>
</abatorContext>
</abatorConfiguration>

建立数据库和表信息如下:
create database otm;
use otm
----测试onetomany
/*==============================================================*/
/* Table: customer????????????????????????????????????????????? */
/*==============================================================*/
create table customer
(
id?????????????????? bigint not null,
address????????????? varchar(120),
postcode???????????? varchar(6),
sex????????????????? varchar(2),
name???????????????? varchar(24),
primary key (id)
);

alter table customer comment '客户';

/*==============================================================*/
/* Table: orders??????????????????????????????????????????????? */
/*==============================================================*/
create table orders
(
id?????????????????? bigint not null,
code???????????????? varchar(24),
customerId?????????? bigint not null,
primary key (id)
);

alter table orders comment '订单';

alter table orders add constraint FK_rf1 foreign key (customerId)
references customer (id) on delete restrict on update restrict;

select * from orders;
select * from customer

select LAST_INSERT_ID()

3,选择abatorConfig.xml文件,工程结构图如下:

4,我们在使用之前先要配好SqlMapConfig.xml,这里没有整合其他框架,最原始的了:

sqlmapconfig.xml内容如下;
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="jdbc.properties" />
<settings cacheModelsEnabled="true" errorTracingEnabled="true"
enhancementEnabled="true" lazyLoadingEnabled="true" maxRequests="32"
maxSessions="10" maxTransactions="5" useStatementNamespaces="true" />
<!--
Configure a built-in transaction manager. If you're using an app
server, you probably want to use its transaction manager and a managed
datasource
-->
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${jdbc.driver}" />
<property name="JDBC.ConnectionURL" value="${jdbc.url}" />
<property name="JDBC.Username" value="${jdbc.username}" />
<property name="JDBC.Password" value="${jdbc.password}" />
</dataSource>
</transactionManager>
<!--
List the SQL Map XML files. They can be loaded from the classpath, as
they are here (com.domain.data...)
-->
<sqlMap resource="com/test/sqlmap/customer_SqlMap.xml" />
<sqlMap resource="com/test/sqlmap/orders_SqlMap.xml" />
<!-- List more here...-->
</sqlMapConfig>
jdbc.proteries文件中内容如下:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/otm
jdbc.username=root
jdbc.password=sa
为了让控制太能出现sql语句方便我们调试,log4j.properties文件中内容如下:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.logger.com.ibatis=debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug,stdout

以Customer为例:

public static void main(String[] args) throws IOException {
// 读取SqlMapConfig的资源配置
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient sqlMapClient=SqlMapClientBuilder.buildSqlMapClient(reader);
CustomerDAOImpl cus=new CustomerDAOImpl(sqlMapClient);
Customer c=new Customer();
c.setAddress("haha");
c.setName("xixi");
c.setId(new Long(1));

try {
cus.updateByPrimaryKeySelective(c);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
对应的一段配置文件如下:
<update id="abatorgenerated_updateByPrimaryKeySelective" parameterClass="com.test.dto.Customer" >
update customer
<dynamic prepend="set" >
<isNotNull prepend="," property="address"? >
address = #address:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="postcode" >
postcode = #postcode:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="sex" >
sex = #sex:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="name" >
name = #name:VARCHAR#
</isNotNull>
</dynamic>
where id = #id:BIGINT#
</update>

下面是打印出的结果。

log4j:WARN No appenders could be found for logger (com.ibatis.common.jdbc.SimpleDataSource).
log4j:WARN Please initialize the log4j system properly.
2010-03-14 16:13:21,812 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Executing Statement:????? update customer???? set??????????????? address = ???????????????????????????? ,???????? name = ????????????????? where id = ???
2010-03-14 16:13:21,812 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Parameters: [haha, xixi, 1]
2010-03-14 16:13:21,812 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Types: [java.lang.String, java.lang.String, java.lang.Long]

在自动生成pojo类中,对应就有一个xxxexample类,我们在用一下这个类。
public static void main(String[] args) throws IOException {
// 读取SqlMapConfig的资源配置
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient sqlMapClient=SqlMapClientBuilder.buildSqlMapClient(reader);
CustomerDAOImpl cus=new CustomerDAOImpl(sqlMapClient);

CustomerExample ce=new CustomerExample();
CustomerExample.Criteria cr=ce.createCriteria();
cr.andAddressIsNotNull();
cr.andAddressLike("h");
ce.setOrderByClause("id");

try {
cus.selectByExample(ce);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在XXXexample类中有个静态的内部内:部分内容如下:
public static class Criteria {
protected List criteriaWithoutValue;

protected List criteriaWithSingleValue;

protected List criteriaWithListValue;

protected List criteriaWithBetweenValue;

protected Criteria() {
super();
criteriaWithoutValue = new ArrayList();
criteriaWithSingleValue = new ArrayList();
criteriaWithListValue = new ArrayList();
criteriaWithBetweenValue = new ArrayList();
}

public boolean isValid() {
return criteriaWithoutValue.size() > 0
|| criteriaWithSingleValue.size() > 0
|| criteriaWithListValue.size() > 0
|| criteriaWithBetweenValue.size() > 0;
}

public List getCriteriaWithoutValue() {
return criteriaWithoutValue;
}

public List getCriteriaWithSingleValue() {
return criteriaWithSingleValue;
}

public List getCriteriaWithListValue() {
return criteriaWithListValue;
}

public List getCriteriaWithBetweenValue() {
return criteriaWithBetweenValue;
}

protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteriaWithoutValue.add(condition);
}

protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
Map map = new HashMap();
map.put("condition", condition);
map.put("value", value);
criteriaWithSingleValue.add(map);
}

protected void addCriterion(String condition, List values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property + " cannot be null or empty");
}
Map map = new HashMap();
map.put("condition", condition);
map.put("values", values);
criteriaWithListValue.add(map);
}

protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
List list = new ArrayList();
list.add(value1);
list.add(value2);
Map map = new HashMap();
map.put("condition", condition);
map.put("values", list);
criteriaWithBetweenValue.add(map);
}

很关键的对应的配置文件部分内容如下:
<sql id="abatorgenerated_Example_Where_Clause"? >
<iterate property="oredCriteria" conjunction="or" prepend="where" removeFirstPrepend="iterate" >
<isEqual property="oredCriteria[].valid" compareValue="true"? >
(
<iterate prepend="and" property="oredCriteria[].criteriaWithoutValue" conjunction="and" >
$oredCriteria[].criteriaWithoutValue[]$
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithSingleValue" conjunction="and"? >
$oredCriteria[].criteriaWithSingleValue[].condition$
#oredCriteria[].criteriaWithSingleValue[].value#
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithListValue" conjunction="and" >
$oredCriteria[].criteriaWithListValue[].condition$
<iterate property="oredCriteria[].criteriaWithListValue[].values" open="(" close=")" conjunction="," >
#oredCriteria[].criteriaWithListValue[].values[]#
</iterate>
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >
$oredCriteria[].criteriaWithBetweenValue[].condition$
#oredCriteria[].criteriaWithBetweenValue[].values[0]# and
#oredCriteria[].criteriaWithBetweenValue[].values[1]#
</iterate>
)
</isEqual>
</iterate>
</sql>
下载:http://download.csdn.net/user/fatbear007

AbatorForEclipse插件使用总结的更多相关文章

  1. Angular杂谈系列1-如何在Angular2中使用jQuery及其插件

    jQuery,让我们对dom的操作更加便捷.由于其易用性和可扩展性,jQuer也迅速风靡全球,各种插件也是目不暇接. 我相信很多人并不能直接远离jQuery去做前端,因为它太好用了,我们以前做的东西大 ...

  2. Jenkins 安装的HTML Publisher Plugin 插件无法展示ant生成的JunitReport报告

    最近在做基于jenkins ant  junit 的测试持续集成,单独ant junit生成的junitreport报告打开正常,使用Jenkins的HTML Publisher Plugin 插件无 ...

  3. 常用 Gulp 插件汇总 —— 基于 Gulp 的前端集成解决方案(三)

    前两篇文章讨论了 Gulp 的安装部署及基本概念,借助于 Gulp 强大的 插件生态 可以完成很多常见的和不常见的任务.本文主要汇总常用的 Gulp 插件及其基本使用,需要读者对 Gulp 有一个基本 ...

  4. solr服务中集成IKAnalyzer中文分词器、集成dataimportHandler插件

    昨天已经在Tomcat容器中成功的部署了solr全文检索引擎系统的服务:今天来分享一下solr服务在海量数据的网站中是如何实现数据的检索. 在solr服务中集成IKAnalyzer中文分词器的步骤: ...

  5. 使用Visual Studio SDK制作GLSL词法着色插件

    使用Visual Studio SDK制作GLSL词法着色插件 我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader.这时在vs里直接编辑shader就会显得很方便. ...

  6. 工欲善其事,必先利其器 之 VS2013全攻略(安装,技巧,快捷键,插件)!

    如有需要WPF工具的朋友可以移步 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧 之前一篇<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATI ...

  7. Jquery mobiscroll 移动设备(手机)wap日期时间选择插件以及滑动、滚动插件

    Jquery Mobiscroll是一个用于触摸设备(Android phones, iPhone, iPad, Galaxy Tab)的日期和时间选择器jQuery插件.以及各种滑动插件 可以让用户 ...

  8. 10个最好用的HTML/CSS 工具、插件和资料库

    大家在使用HTML/CSS开发项目的过程中,有使用过哪些工具,插件和库?下面介绍的10种HTML/CSS工具,插件和资料库,是国外程序员经常用到的. Firebug Lite FirebugLite ...

  9. 在Sublime Text 3上安装代码格式化插件CodeFormatter

    1.了解CodeFormatter插件 在Sublime Text 3中编写代码,为了能让我们的代码格式变得漂亮整洁,需要一个能自动格式代码的插件.这里发现CodeFormatter插件不错,它能支持 ...

随机推荐

  1. 机器学习简史brief history of machine learning

    BRIEF HISTORY OF MACHINE LEARNING My subjective ML timeline (click for larger) Since the initial sta ...

  2. Guava 源码分析之 Beta, GwtCompatible, GwtIncompatible, Charset, HashCode

    com.google.common.annotations.Beta /** * 表明一个公用API的未来版本是受不兼容变更或删除限制的 * 拥有这个注释标志的API不受任何兼容性保证 * */ @R ...

  3. IDEA热部署基于maven的web项目

    第一步:首先先创建web项目 按照向导一步一步完成项目创建,我创建的示例项目为hotdeploddemo     第二步:设置项目的web资源         下图中的路径要修改正确,指向src/ma ...

  4. 遇到问题描述:Android Please ensure that adb is correctly located at问题解决

    遇到问题描述: 运行android程序控制台输出 [2013-11-04 16:18:26 - ] The connection to adb is down, and a severe error ...

  5. Android实现圆形的图片边角

    ImageView没有边角圆化的设置,但是可以通过代码设置实现.一个国外的码农写的方法. 效果: 地址:http://www.curious-creature.org/2012 代码: package ...

  6. Android Studio安装&&安装bug

    1.安装SDK:Android SDK安装 2.安装Android Studio 3.配置HTTP Proxy: 转自:Android Studio设置HTTP代理(可用) 因为大陆的内网的防火墙很厉 ...

  7. idea 设置代码的颜色

  8. Database Setup

    Database Setup This library has been developed so that you can use any type of backend storage; rela ...

  9. (算法)Trapping Rain Water I

    题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...

  10. 用10046 跟踪exp

    之前写过一个blog,Oracle expdp为什么比exp快,原理是什么,是从官方文档中获知的,如今通过10046来分析exp的过程. C:\Users\Administrator>exp L ...