eclipse ibabis代码生成插件abator功能扩展
主要改进有
1为dao添加Integer selectCountByExample或Integer selectCountByExampleWithoutBLOBs接口及相应的sqlmap查询记录总数
2分页子句支持(目前仅支持mysql)
在example中添加属性limitClauseStart和limitClauseCount为接口selectByExample添加物理分页支持
将该项目在eclipse下编译打包后替换原插件下的abator.jar即可
注:目前仅对generatorSet="Java5"有效
生成代码示例:
sqlmap:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="t_role">
<resultMap id="abatorgenerated_TRoleResult">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Tue Jan 22 15:50:00 CST 2008.
-->
<result column="r_ROLE_ID" jdbcType="INTEGER" property="roleId"/>
<result column="r_ROLE_NAME" jdbcType="VARCHAR" property="roleName"/>
</resultMap>
<sql id="abatorgenerated_Example_Where_Clause">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Tue Jan 22 15:50:00 CST 2008.
-->
<iterate conjunction="or" prepend="where" property="oredCriteria" removeFirstPrepend="iterate">
(
<iterate conjunction="and" prepend="and" property="oredCriteria[].criteriaWithoutValue">
$oredCriteria[].criteriaWithoutValue[]$
</iterate>
<iterate conjunction="and" prepend="and" property="oredCriteria[].criteriaWithSingleValue">
$oredCriteria[].criteriaWithSingleValue[].condition$
#oredCriteria[].criteriaWithSingleValue[].value#
</iterate>
<iterate conjunction="and" prepend="and" property="oredCriteria[].criteriaWithListValue">
$oredCriteria[].criteriaWithListValue[].condition$
<iterate close=")" conjunction="," open="(" property="oredCriteria[].criteriaWithListValue[].values">
#oredCriteria[].criteriaWithListValue[].values[]#
</iterate>
</iterate>
<iterate conjunction="and" prepend="and" property="oredCriteria[].criteriaWithBetweenValue">
$oredCriteria[].criteriaWithBetweenValue[].condition$
#oredCriteria[].criteriaWithBetweenValue[].values[0]# and
#oredCriteria[].criteriaWithBetweenValue[].values[1]#
</iterate>
)
</iterate>
</sql>
<select id="abatorgenerated_selectByPrimaryKey" parameterresultMap="abatorgenerated_TRoleResult">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Tue Jan 22 15:50:00 CST 2008.
-->
select r.ROLE_ID as r_ROLE_ID, r.ROLE_NAME as r_ROLE_NAME
from t_role r
where r.ROLE_ID = #roleId:INTEGER#
</select>
<select id="abatorgenerated_selectByExample" parameterresultMap="abatorgenerated_TRoleResult">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Tue Jan 22 15:50:00 CST 2008.
-->
select r.ROLE_ID as r_ROLE_ID, r.ROLE_NAME as r_ROLE_NAME
from t_role r
<isParameterPresent>
<include refid="t_role.abatorgenerated_Example_Where_Clause"/>
<isNotNull property="orderByClause">
order by $orderByClause$
</isNotNull>
<isNotNull property="limitClauseStart">
limit #limitClauseStart:INTEGER#, #limitClauseCount:INTEGER#
</isNotNull>
</isParameterPresent>
</select>
<select id="abatorgenerated_selectCountByExample" parameterresultparameterparameterparameterresultparameterparameterproperty="roleName">
ROLE_NAME = #roleName:VARCHAR#
</isNotNull>
</dynamic>
where ROLE_ID = #roleId#
</update>
</sqlMap>
dao接口:
package com.u2lux.abator.dao;
import com.u2lux.abator.model.TRole;
import com.u2lux.abator.model.TRoleExample;
import java.util.List;
public interface TRoleDAO {
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
Integer insert(TRole record);
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
int updateByPrimaryKey(TRole record);
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
int updateByPrimaryKeySelective(TRole record);
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
List<TRole> selectByExample(TRoleExample example);
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
Integer selectCountByExample(TRoleExample example);
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
TRole selectByPrimaryKey(Integer roleId);
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
int deleteByExample(TRoleExample example);
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
int deleteByPrimaryKey(Integer roleId);
}
dao实现:
package com.u2lux.abator.dao;
import com.u2lux.abator.model.TRole;
import com.u2lux.abator.model.TRoleExample;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
public class TRoleDAOImpl extends SqlMapClientDaoSupport implements TRoleDAO {
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public TRoleDAOImpl() {
super();
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public Integer insert(TRole record) {
Object newKey = getSqlMapClientTemplate().insert(
"t_role.abatorgenerated_insert", record);
return (Integer) newKey;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public int updateByPrimaryKey(TRole record) {
int rows = getSqlMapClientTemplate().update(
"t_role.abatorgenerated_updateByPrimaryKey", record);
return rows;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public int updateByPrimaryKeySelective(TRole record) {
int rows = getSqlMapClientTemplate().update(
"t_role.abatorgenerated_updateByPrimaryKeySelective", record);
return rows;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
@SuppressWarnings("unchecked")
public List<TRole> selectByExample(TRoleExample example) {
List<TRole> list = (List<TRole>) getSqlMapClientTemplate()
.queryForList("t_role.abatorgenerated_selectByExample", example);
return list;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public Integer selectCountByExample(TRoleExample example) {
Object count = getSqlMapClientTemplate().queryForObject(
"t_role.abatorgenerated_selectCountByExample", example);
return (Integer) count;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public TRole selectByPrimaryKey(Integer roleId) {
TRole key = new TRole();
key.setRoleId(roleId);
TRole record = (TRole) getSqlMapClientTemplate().queryForObject(
"t_role.abatorgenerated_selectByPrimaryKey", key);
return record;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public int deleteByExample(TRoleExample example) {
int rows = getSqlMapClientTemplate().delete(
"t_role.abatorgenerated_deleteByExample", example);
return rows;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public int deleteByPrimaryKey(Integer roleId) {
TRole key = new TRole();
key.setRoleId(roleId);
int rows = getSqlMapClientTemplate().delete(
"t_role.abatorgenerated_deleteByPrimaryKey", key);
return rows;
}
}
生成的model:
package com.u2lux.abator.model;
import com.u2lux.abator.SerializableModel;
public class TRole extends SerializableModel {
/**
*
*/
private static final long serialVersionUID = -549201827251112100L;
/**
* This field was generated by Abator for iBATIS. This field corresponds to the database column t_role.ROLE_ID
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
private Integer roleId;
/**
* This field was generated by Abator for iBATIS. This field corresponds to the database column t_role.ROLE_NAME
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
private String roleName;
/**
* This method was generated by Abator for iBATIS. This method returns the value of the database column t_role.ROLE_ID
* @return the value of t_role.ROLE_ID
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public Integer getRoleId() {
return roleId;
}
/**
* This method was generated by Abator for iBATIS. This method sets the value of the database column t_role.ROLE_ID
* @param roleId the value for t_role.ROLE_ID
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
/**
* This method was generated by Abator for iBATIS. This method returns the value of the database column t_role.ROLE_NAME
* @return the value of t_role.ROLE_NAME
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public String getRoleName() {
return roleName;
}
/**
* This method was generated by Abator for iBATIS. This method sets the value of the database column t_role.ROLE_NAME
* @param roleName the value for t_role.ROLE_NAME
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public void setRoleName(String roleName) {
this.roleName = roleName;
}
}
生成的example:
package com.u2lux.abator.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TRoleExample {
/**
* This field was generated by Abator for iBATIS. This field corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
private String orderByClause;
/**
* This field was generated by Abator for iBATIS. This field corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
private Integer limitClauseStart; /**
* This field was generated by Abator for iBATIS. This field corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
private Integer limitClauseCount; /**
* This field was generated by Abator for iBATIS. This field corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
private List<Criteria> oredCriteria = new ArrayList<Criteria>();
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public String getOrderByClause() {
return orderByClause;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public void setLimitClauseStart(Integer limitClauseStart) {
this.limitClauseStart = limitClauseStart;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public Integer getLimitClauseStart() {
return limitClauseStart;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public void setLimitClauseCount(Integer limitClauseCount) {
this.limitClauseCount = limitClauseCount;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public Integer getLimitClauseCount() {
return limitClauseCount;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
/**
* This method was generated by Abator for iBATIS. This method corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public Criteria createCriteria() {
Criteria criteria = new Criteria();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
/**
* This class was generated by Abator for iBATIS. This class corresponds to the database table t_role
* @abatorgenerated Tue Jan 22 15:50:00 CST 2008
*/
public static class Criteria {
private List<String> criteriaWithoutValue;
private List<Map<String, Object>> criteriaWithSingleValue;
private List<Map<String, Object>> criteriaWithListValue;
private List<Map<String, Object>> criteriaWithBetweenValue;
private Criteria() {
super();
criteriaWithoutValue = new ArrayList<String>();
criteriaWithSingleValue = new ArrayList<Map<String, Object>>();
criteriaWithListValue = new ArrayList<Map<String, Object>>();
criteriaWithBetweenValue = new ArrayList<Map<String, Object>>();
}
public List<String> getCriteriaWithoutValue() {
return criteriaWithoutValue;
}
public List<Map<String, Object>> getCriteriaWithSingleValue() {
return criteriaWithSingleValue;
}
public List<Map<String, Object>> getCriteriaWithListValue() {
return criteriaWithListValue;
}
public List<Map<String, Object>> getCriteriaWithBetweenValue() {
return criteriaWithBetweenValue;
}
private void addCriterion(String condition, Object value,
String property) {
if (value == null) {
throw new RuntimeException("Value for " + property
+ " cannot be null");
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("condition", condition);
map.put("value", value);
criteriaWithSingleValue.add(map);
}
private void addCriterion(String condition,
List<? extends Object> values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property
+ " cannot be null or empty");
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("condition", condition);
map.put("values", values);
criteriaWithListValue.add(map);
}
private 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<Object> list = new ArrayList<Object>();
list.add(value1);
list.add(value2);
Map<String, Object> map = new HashMap<String, Object>();
map.put("condition", condition);
map.put("values", list);
criteriaWithBetweenValue.add(map);
}
public Criteria andRoleIdIsNull() {
criteriaWithoutValue.add("r.ROLE_ID is null");
return this;
}
public Criteria andRoleIdIsNotNull() {
criteriaWithoutValue.add("r.ROLE_ID is not null");
return this;
}
public Criteria andRoleIdEqualTo(Integer value) {
addCriterion("r.ROLE_ID =", value, "roleId");
return this;
}
public Criteria andRoleIdNotEqualTo(Integer value) {
addCriterion("r.ROLE_ID <>", value, "roleId");
return this;
}
public Criteria andRoleIdGreaterThan(Integer value) {
addCriterion("r.ROLE_ID >", value, "roleId");
return this;
}
public Criteria andRoleIdGreaterThanOrEqualTo(Integer value) {
addCriterion("r.ROLE_ID >=", value, "roleId");
return this;
}
public Criteria andRoleIdLessThan(Integer value) {
addCriterion("r.ROLE_ID <", value, "roleId");
return this;
}
public Criteria andRoleIdLessThanOrEqualTo(Integer value) {
addCriterion("r.ROLE_ID <=", value, "roleId");
return this;
}
public Criteria andRoleIdIn(List<Integer> values) {
addCriterion("r.ROLE_ID in", values, "roleId");
return this;
}
public Criteria andRoleIdNotIn(List<Integer> values) {
addCriterion("r.ROLE_ID not in", values, "roleId");
return this;
}
public Criteria andRoleIdBetween(Integer value1, Integer value2) {
addCriterion("r.ROLE_ID between", value1, value2, "roleId");
return this;
}
public Criteria andRoleIdNotBetween(Integer value1, Integer value2) {
addCriterion("r.ROLE_ID not between", value1, value2, "roleId");
return this;
}
public Criteria andRoleNameIsNull() {
criteriaWithoutValue.add("r.ROLE_NAME is null");
return this;
}
public Criteria andRoleNameIsNotNull() {
criteriaWithoutValue.add("r.ROLE_NAME is not null");
return this;
}
public Criteria andRoleNameEqualTo(String value) {
addCriterion("r.ROLE_NAME =", value, "roleName");
return this;
}
public Criteria andRoleNameNotEqualTo(String value) {
addCriterion("r.ROLE_NAME <>", value, "roleName");
return this;
}
public Criteria andRoleNameGreaterThan(String value) {
addCriterion("r.ROLE_NAME >", value, "roleName");
return this;
}
public Criteria andRoleNameGreaterThanOrEqualTo(String value) {
addCriterion("r.ROLE_NAME >=", value, "roleName");
return this;
}
public Criteria andRoleNameLessThan(String value) {
addCriterion("r.ROLE_NAME <", value, "roleName");
return this;
}
public Criteria andRoleNameLessThanOrEqualTo(String value) {
addCriterion("r.ROLE_NAME <=", value, "roleName");
return this;
}
public Criteria andRoleNameLike(String value) {
addCriterion("r.ROLE_NAME like", value, "roleName");
return this;
}
public Criteria andRoleNameNotLike(String value) {
addCriterion("r.ROLE_NAME not like", value, "roleName");
return this;
}
public Criteria andRoleNameIn(List<String> values) {
addCriterion("r.ROLE_NAME in", values, "roleName");
return this;
}
public Criteria andRoleNameNotIn(List<String> values) {
addCriterion("r.ROLE_NAME not in", values, "roleName");
return this;
}
public Criteria andRoleNameBetween(String value1, String value2) {
addCriterion("r.ROLE_NAME between", value1, value2, "roleName");
return this;
}
public Criteria andRoleNameNotBetween(String value1, String value2) {
addCriterion("r.ROLE_NAME not between", value1, value2, "roleName");
return this;
}
}
}