AbatorForEclipse插件使用总结
插件装好后,我们来使用看看:
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插件使用总结的更多相关文章
- Angular杂谈系列1-如何在Angular2中使用jQuery及其插件
jQuery,让我们对dom的操作更加便捷.由于其易用性和可扩展性,jQuer也迅速风靡全球,各种插件也是目不暇接. 我相信很多人并不能直接远离jQuery去做前端,因为它太好用了,我们以前做的东西大 ...
- Jenkins 安装的HTML Publisher Plugin 插件无法展示ant生成的JunitReport报告
最近在做基于jenkins ant junit 的测试持续集成,单独ant junit生成的junitreport报告打开正常,使用Jenkins的HTML Publisher Plugin 插件无 ...
- 常用 Gulp 插件汇总 —— 基于 Gulp 的前端集成解决方案(三)
前两篇文章讨论了 Gulp 的安装部署及基本概念,借助于 Gulp 强大的 插件生态 可以完成很多常见的和不常见的任务.本文主要汇总常用的 Gulp 插件及其基本使用,需要读者对 Gulp 有一个基本 ...
- solr服务中集成IKAnalyzer中文分词器、集成dataimportHandler插件
昨天已经在Tomcat容器中成功的部署了solr全文检索引擎系统的服务:今天来分享一下solr服务在海量数据的网站中是如何实现数据的检索. 在solr服务中集成IKAnalyzer中文分词器的步骤: ...
- 使用Visual Studio SDK制作GLSL词法着色插件
使用Visual Studio SDK制作GLSL词法着色插件 我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader.这时在vs里直接编辑shader就会显得很方便. ...
- 工欲善其事,必先利其器 之 VS2013全攻略(安装,技巧,快捷键,插件)!
如有需要WPF工具的朋友可以移步 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧 之前一篇<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATI ...
- Jquery mobiscroll 移动设备(手机)wap日期时间选择插件以及滑动、滚动插件
Jquery Mobiscroll是一个用于触摸设备(Android phones, iPhone, iPad, Galaxy Tab)的日期和时间选择器jQuery插件.以及各种滑动插件 可以让用户 ...
- 10个最好用的HTML/CSS 工具、插件和资料库
大家在使用HTML/CSS开发项目的过程中,有使用过哪些工具,插件和库?下面介绍的10种HTML/CSS工具,插件和资料库,是国外程序员经常用到的. Firebug Lite FirebugLite ...
- 在Sublime Text 3上安装代码格式化插件CodeFormatter
1.了解CodeFormatter插件 在Sublime Text 3中编写代码,为了能让我们的代码格式变得漂亮整洁,需要一个能自动格式代码的插件.这里发现CodeFormatter插件不错,它能支持 ...
随机推荐
- CRF 及CRF++ 安装与解释
CRF简介 Conditional Random Field:条件随机场,一种机器学习技术(模型) CRF由John Lafferty最早用于NLP技术领域,其在NLP技术领域中主要用于文本标注,并有 ...
- 深入分析JavaWeb Item7 -- HttpServletResponse详解
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象即然代表请求和响应,那我们要 ...
- CVPR14 图像检索papers
CVPR14年关于图像检索方面的papers,汇总成一个list,方便阅读. 图像检索 Triangulation embedding and democratic aggregation for i ...
- P值(P-value),“差异具有显著性”和“具有显著差异”
郑冰刚提到P值,说P值的定义(着重号是笔者加的,英文是从WikiPedia摘来的): P值就是当原假设为真时,比所得到的样本观察结果更极端的结果出现的概率. The P-value is the pr ...
- C语言:内存的分配与管理
1.内存区域的划分标准: 代码段 存储代码 数据段 静态/全局数据.常量(const) 堆区(heap) 动态内存分配(更 ...
- Android NFC近场通信03----读写MifareClassic卡
Android NFC近场通信02----读写MifareClassic卡 一.MifareClassic卡 相关 一般来 ...
- XTU1236 Fraction
Fraction Accepted : 124 Submit : 806 Time Limit : 1000 MS Memory Limit : 65536 KB Fraction Problem D ...
- (算法)Partition方法求数组第k大的数
如题,下面直接贴出代码: #include <iostream> using namespace std; int Partition(int* A,int left,int right) ...
- zookeeperclient代码解读
近期一直在忙WebPageTest(下面简称wpt)开源库的改动工作,当中一项工作须要将zookeeper(下面简称zk)集成到wpt里. zk作为分布式系统的同步工具.实现了写的原子性(要么失败.要 ...
- eclipse开发php的插件
php development tools,简称pdt,在Eclipse marketplace里面可以下载到.