MyBatis - 1.3
Extension ID
com.castsoftware.ibatis
What’s new ?
Please see MyBatis - 1.3 - Release Notes for more information.
Description
This extension provides support for the MyBatis/iBatis persistence framework on Java and .NET.
In what situation should you install this extension?
This extension should be installed when analyzing a Java/.NET project that uses a MyBatis framework, and you want to view a transaction consisting of MyBatis objects with their corresponding links. Links to corresponding database tables can also be resolved, provided that the SQL database has been extracted and DDL has been created.
Technology support
The following libraries are supported by this extension:
Language | Library name | Namespace | Version | Supported |
---|---|---|---|---|
Java | iBatis | com.ibatis.sqlmap.client | 1.0.0 to 2.5.0 | ✔️ |
Java | MyBatis | org.apache.ibatis.session | 3.0.0 to 3.5.16 | ✔️ |
Java | MyBatis Spring | org.mybatis.spring | 1.0.0 to 3.0.3 | ✔️ |
Java | Spring Framework: iBATIS | org.springframework.orm.ibatis | 1.0.0 to 3.2.12 | ✔️ |
Java | tk.mybatis | tk.mybatis.mapper.common | 3.1.0 to 4.1.5 | ✔️ |
.NET C# | iBATIS.NET - DataMapper Application Framework | IBatisNet.DataMapper | 1.0.0 upto 2.1.0 | ✔️ |
.NET C# | SqlBatis DataMapper | SqlBatis.DataMapper | 3.0.0 to 5.1.0 | ✔️ |
Compatibility
This extension is compatible with:
CAST Imaging Core release | Supported |
---|---|
8.3.x | ✔️ |
Download and installation instructions
For applications using any of the above mentionned libraries, this extension will be automatically installed by CAST Imaging Console. For upgrade, if the Extension Strategy is not set to Auto update, you can manually upgrade the extension using the Application - Extensions interface.
What results can you expect?
Once the analysis/snapshot generation has completed, you can view the below objects and links created.
Objects
Icon | Description | Comment |
---|---|---|
Java MyBatis SQL Query | An object is created for each native SQL query found in java project and resolved in a method call/xml file | |
Java MyBatis Entity | An object is created for each tk.MyBatis entity | |
Java MyBatis Entity Operation | An object is created for each tk.MyBatis Mapper operation | |
Java MyBatis Unknown SQL Query | An object is created for each native SQL query found in java project and the exact query cannot be resolved | |
Java MyBatis Unknown Entity | An object is created for when tk.MyBatis entity cannot be resolved | |
Java MyBatis Unknown Entity Operation | An object is created for each tk.MyBatis Mapper operation and respective Entity cannot be resolved | |
DotNet MyBatis SQL Query | An object is created for each native SQL query found in .Net project and resolved in a method call/xml file | |
DotNet MyBatis Unknown SQL Query | An object is created for each native SQL query found in .NET project and the exact query cannot be resolved |
Links
Link Type | Caller | Callee | APIs Supported |
---|---|---|---|
callLink | Java Method | Java MyBatis SQL Query | SqlMapClient APIscom.ibatis.sqlmap.client.SqlMapExecutor.updatecom.ibatis.sqlmap.client.SqlMapExecutor.delete com.ibatis.sqlmap.client.SqlMapExecutor.insert com.ibatis.sqlmap.client.SqlMapExecutor.queryForObject com.ibatis.sqlmap.client.SqlMapExecutor.queryForList com.ibatis.sqlmap.client.SqlMapExecutor.queryWithRowHandler com.ibatis.sqlmap.client.SqlMapExecutor.queryForMap com.ibatis.sqlmap.client.SqlMapExecutor.queryForPaginatedList com.ibatis.sqlmap.client.SqlMapClient.update com.ibatis.sqlmap.client.SqlMapClient.delete com.ibatis.sqlmap.client.SqlMapClient.insert com.ibatis.sqlmap.client.SqlMapClient.queryForObject com.ibatis.sqlmap.client.SqlMapClient.queryForList com.ibatis.sqlmap.client.SqlMapClient.queryWithRowHandler com.ibatis.sqlmap.client.SqlMapClient.queryForMap com.ibatis.sqlmap.client.SqlMapClient.queryForPaginatedList SqlSession APIsorg.apache.ibatis.session.SqlSession.selectOneorg.apache.ibatis.session.SqlSession.selectList org.apache.ibatis.session.SqlSession.selectCursor org.apache.ibatis.session.SqlSession.selectMap org.apache.ibatis.session.SqlSession.select org.apache.ibatis.session.SqlSession.insert org.apache.ibatis.session.SqlSession.update org.apache.ibatis.session.SqlSession.delete Annotation APIsorg.apache.ibatis.annotations.Insertorg.apache.ibatis.annotations.Update org.apache.ibatis.annotations.Delete org.apache.ibatis.annotations.Select org.apache.ibatis.annotations.InsertProvider org.apache.ibatis.annotations.UpdateProvider org.apache.ibatis.annotations.DeleteProvider org.apache.ibatis.annotations.SelectProvider SqlSessionTemplate APIsorg.mybatis.spring.SqlSessionTemplate.selectOneorg.mybatis.spring.SqlSessionTemplate.selectList org.mybatis.spring.SqlSessionTemplate.selectCursor org.mybatis.spring.SqlSessionTemplate.selectMap org.mybatis.spring.SqlSessionTemplate.select org.mybatis.spring.SqlSessionTemplate.insert org.mybatis.spring.SqlSessionTemplate.update org.mybatis.spring.SqlSessionTemplate.delete SpringFramework APIsorg.springframework.orm.ibatis.SqlMapClientTemplate.updateorg.springframework.orm.ibatis.SqlMapClientTemplate.delete org.springframework.orm.ibatis.SqlMapClientTemplate.insert org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList org.springframework.orm.ibatis.SqlMapClientTemplate.queryWithRowHandler org.springframework.orm.ibatis.SqlMapClientTemplate.queryForMap org.springframework.orm.ibatis.SqlMapClientTemplate.queryForPaginatedList org.springframework.orm.ibatis.SqlMapClientTemplate.execute org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithMapResult org.springframework.orm.ibatis.SqlMapClientOperations.update org.springframework.orm.ibatis.SqlMapClientOperations.delete org.springframework.orm.ibatis.SqlMapClientOperations.insert org.springframework.orm.ibatis.SqlMapClientOperations.queryForObject org.springframework.orm.ibatis.SqlMapClientOperations.queryForList org.springframework.orm.ibatis.SqlMapClientOperations.queryWithRowHandler org.springframework.orm.ibatis.SqlMapClientOperations.queryForMap org.springframework.orm.ibatis.SqlMapClientOperations.queryForPaginatedList org.springframework.orm.ibatis.SqlMapTemplate.execute org.springframework.orm.ibatis.SqlMapTemplate.executeQueryForList org.springframework.orm.ibatis.SqlMapTemplate.executeQueryForMap org.springframework.orm.ibatis.SqlMapTemplate.executeQueryForObject org.springframework.orm.ibatis.SqlMapTemplate.executeUpdate org.springframework.orm.ibatis.SqlMapTemplate.executeWithListResult org.springframework.orm.ibatis.SqlMapTemplate.executeWithMapResult org.springframework.orm.ibatis.SqlMapOperations.executeQueryForList org.springframework.orm.ibatis.SqlMapOperations.executeQueryForMap org.springframework.orm.ibatis.SqlMapOperations.executeQueryForObject org.springframework.orm.ibatis.SqlMapOperations.executeQueryWithRowHandler org.springframework.orm.ibatis.SqlMapOperations.executeUpdate |
callLink | Java Method | Java MyBatis Entity Operation | tk.mybatis Mapper APIstk.mybatis.mapper.common.condition.UpdateByConditionMapper.updateByConditiontk.mybatis.mapper.common.condition.UpdateByConditionSelectiveMapper.updateByConditionSelective tk.mybatis.mapper.common.base.delete.DeleteByPrimaryKeyMapper.deleteByPrimaryKey tk.mybatis.mapper.common.base.delete.DeleteMapper.delete tk.mybatis.mapper.common.base.insert.InsertMapper.insert tk.mybatis.mapper.common.base.insert.InsertSelectiveMapper.insertSelective tk.mybatis.mapper.common.base.select.ExistsWithPrimaryKeyMapper.existsWithPrimaryKey tk.mybatis.mapper.common.base.select.SelectAllMapper.selectAll tk.mybatis.mapper.common.base.select.SelectByPrimaryKeyMapper.selectByPrimaryKey tk.mybatis.mapper.common.base.select.SelectCountMapper.selectCount tk.mybatis.mapper.common.base.select.SelectMapper.select tk.mybatis.mapper.common.base.select.SelectOneMapper.selectOne<brtk.mybatis.mapper.common.base.update.UpdateByPrimaryKeyMapper.updateByPrimaryKey tk.mybatis.mapper.common.base.update.UpdateByPrimaryKeySelectiveMapper.updateByPrimaryKeySelective tk.mybatis.mapper.common.example.DeleteByExampleMapper.deleteByExample tk.mybatis.mapper.common.example.SelectByExampleMapper.selectByExample tk.mybatis.mapper.common.example.SelectCountByExampleMapper.selectCountByExample tk.mybatis.mapper.common.example.SelectOneByExampleMapper.selectOneByExample tk.mybatis.mapper.common.example.UpdateByExampleMapper.updateByExample tk.mybatis.mapper.common.example.UpdateByExampleSelectiveMapper.updateByExampleSelective tk.mybatis.mapper.common.ids.DeleteByIdsMapper.deleteByIds tk.mybatis.mapper.common.ids.SelectByIdsMapper.selectByIds tk.mybatis.mapper.common.rowbounds.SelectByConditionRowBoundsMapper.selectByConditionAndRowBounds tk.mybatis.mapper.common.rowbounds.SelectByExampleRowBoundsMapper.selectByExampleAndRowBounds tk.mybatis.mapper.common.rowbounds.SelectRowBoundsMapper.selectByRowBounds tk.mybatis.mapper.common.special.InsertListMapper.insertList tk.mybatis.mapper.common.special.InsertUseGeneratedKeysMapper.insertUseGeneratedKeys tk.mybatis.mapper.common.sqlserver.InsertMapper.insert tk.mybatis.mapper.common.sqlserver.InsertSelectiveMapper.insertSelective |
useLink | Java MyBatis SQL Query | Table, View | Created by SQLAnalyzer when DDL source files are analyzed |
callLink | Java MyBatis SQL Query | Procedure | Created by SQLAnalyzer when DDL source files are analyzed |
useLink | Java MyBatis SQL Query | Missing Table | Created by Missing tables and procedures for JEE extension when the table object cannot be resolved |
callLink | Java MyBatis SQL Query | Missing Procedure | Created by Missing tables and procedures for JEE extension when the procedure object cannot be resolved |
useLink | Java MyBatis Entity Operation | Table, View | Created by SQLAnalyzer when DDL source files are analyzed |
callLink | Java MyBatis Entity Operation | Procedure | Created by SQLAnalyzer when DDL source files are analyzed |
callLink | C# Method | DotNet MyBatis SQL Query | IBatisNet APIsIBatisNet.DataMapper.ISqlMapper.QueryForListIBatisNet.DataMapper.ISqlMapper.QueryForObject IBatisNet.DataMapper.ISqlMapper.QueryForDictionary IBatisNet.DataMapper.ISqlMapper.QueryForMap IBatisNet.DataMapper.ISqlMapper.QueryWithRowDelegate IBatisNet.DataMapper.ISqlMapper.Insert IBatisNet.DataMapper.ISqlMapper.Delete IBatisNet.DataMapper.ISqlMapper.Update SqlBatis APIsSqlBatis.DataMapper.ISqlMapper.QueryForListSqlBatis.DataMapper.ISqlMapper.QueryForObject SqlBatis.DataMapper.ISqlMapper.QueryForDictionary SqlBatis.DataMapper.ISqlMapper.QueryForMap SqlBatis.DataMapper.ISqlMapper.QueryWithRowDelegate SqlBatis.DataMapper.ISqlMapper.Insert SqlBatis.DataMapper.ISqlMapper.Delete SqlBatis.DataMapper.ISqlMapper.Update |
useLink | DotNet MyBatis SQL Query | Table, View | Created by SQLAnalyzer when DDL source files are analyzed |
callLink | DotNet MyBatis SQL Query | Procedure | Created by SQLAnalyzer when DDL source files are analyzed |
useLink | DotNet MyBatis SQL Query | Missing Table | Created by Missing tables and procedures for .NET extension when the table object cannot be resolved |
callLink | DotNet MyBatis SQL Query | Missing Procedure | Created by Missing tables and procedures for .NET extension when the procedure object cannot be resolved |
Java Examples
SqlMapExecutor CRUD APIs
package com.alibaba.cobar.client;
import java.sql.SQLException;
import java.util.Collection;
import com.ibatis.sqlmap.client.SqlMapExecutor;
public class CobarSqlMapClientDaoSupport {
public int batchUpdate(final String statementName, final Collection<?> entities)
throws DataAccessException {
{
return (Integer) getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (Object parameterObject : entities) {
executor.update("com.alibaba.cobar.client.entities.Offer.update", parameterObject);
}
return executor.executeBatch();
}
});
}
}
}
<sqlMap namespace="com.alibaba.cobar.client.entities.Offer">
<update id="update">
UPDATE offers SET subject=#subject#, gmtUpdated=#gmtUpdated# WHERE id=#id#
</update>
</sqlMap>
SqlSession CRUD APIs
public void update(Village village)
{
SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession();
session.update("com.rlab.mappers.VillageMapper.updatevillage",village);
session.commit();
session.close();
}
<mapper namespace = "com.rlab.mappers.VillageMapper">
<update id="updatevillage" parameterType = "Village">
UPDATE village SET name=#{name},district=#{district}WHERE id= #{id}
</update>
</mapper>
SpringFramework SqlMapClientTemplate CRUD APIs
package com.alibaba.doris.admin.dao.impl;
import java.util.HashMap;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alibaba.doris.admin.dao.ConsistentReportDao;
public class ConsistentReportDaoImpl extends SqlMapClientDaoSupport implements ConsistentReportDao {
public Integer deleteByGmtCreate(String gmtCreateFrom, String gmtCreateTo) {
Map<String, String> params = new HashMap<String, String>(2);
params.put("gmtCreateFrom", gmtCreateFrom);
params.put("gmtCreateTo", gmtCreateTo);
return getSqlMapClientTemplate().delete("CONSISTENT_REPORT.deleteByGmtCreate", params);
}
}
<sqlMap namespace = "CONSISTENT_REPORT">
<delete id="deleteByGmtCreate" parameterClass="map" >
DELETE FROM CONSISTENT_REPORT
WHERE <![CDATA[ gmt_create >= #gmtCreateFrom:VARCHAR# and gmt_create <= #gmtCreateTo:VARCHAR# ]]>
</delete>
</sqlMap>
Mapper Interface
public interface PersonMapper {
Person insertPerson(Person person);
Person findPersonById(Integer id);
List<Person> findAllPersons();
Person updatePerson(Person person);
void removePerson(Integer idPerson);
}
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="br.com.erudio.mappers.PersonMapper">
<update id="updatePerson" parameterType="Person">
update person set
firstName = #{firstName}
,lastName = #{lastName}
,address = #{address}
where id = #{idPerson}
</update>
</mapper>
Annotations
public interface UserAnnotationMapper {
@Insert("insert into users(name,email) values(#{name},#{email})")
@SelectKey(statement = "call identity()", keyProperty = "id", before = false, resultType = Integer.class)
void insertUser(User user);
@Select("select id, name, email from users WHERE id=#{id}")
User findUserById(Integer id);
@Select("select id, name, email from users")
List<User> findAllUsers();
}
Unknown SQL Query - Annonation Provider APIs
public interface AddressMapper {
@InsertProvider(type = AddressServiceImpl.class, method = "dynamicSQL")
int insertProvider(String record_);
}
tk.MyBatis Mapper
selectCount API
import com.yzx.shop.user.entity.User;
import tk.mybatis.mapper.common.Mapper;
public interface UserMapper extends Mapper<User> {
}
import javax.persistence.Table;
@Table(name = "tb_user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserMapper userMapper;
@Override
public Boolean checkUserData(String data, Integer type) {
User record=new User();
if(type==1){
record.setUsername(data);
}else if(type==2){
record.setPhone(data);
}else {
return null;
}
return userMapper.selectCount(record)==0;
}
}
deleteByPrimaryKey API
import com.yzx.shop.item.entity.Stock;
import tk.mybatis.mapper.common.Mapper;
public interface StockMapper extends Mapper<Stock> {
}
import javax.persistence.Table;
@Table(name = "tb_stock")
public class Stock {
@Id
private Long skuId;
public Long getSkuId() {
return skuId;
}
}
@Service
public class GoodsServiceImpl implements GoodsService {
@Resource
private StockMapper stockMapper;
@Override
@Transactional
public void updateGoods(SpuBo spuBo) {
Sku record=new Sku();
record.setSpuId(spuBo.getId());
List<Sku> skuList=skuMapper.select(record);
skuList.forEach(s->{
stockMapper.deleteByPrimaryKey(s.getId());
skuMapper.deleteByPrimaryKey(s.getId());
});
spuBo.setLastUpdateTime(new Date());
spuMapper.updateByPrimaryKeySelective(spuBo);
spuDetailMapper.updateByPrimaryKey(spuBo.getSpuDetail());
insertSkusBySpuBo(spuBo);
sendMsg(MSG_UPDATA,spuBo.getId());
}
}
Unknown Entity
import tk.mybatis.mapper.common.Mapper;
public abstract class BaseService<T> implements IService<T> {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
protected Mapper<T> mapper;
public Mapper<T> getMapper() {
return mapper;
}
@Override
public int batchSave(List<T> list) {
int result = 0;
for (T record : list) {
int count = mapper.insertSelective(record);
result += count;
}
return result;
}
}
.NET Examples
ISQLMapper APIs
public static string FindDepartment(int deptId){
ISqlMapper mapper = EntityMapper;
string str = mapper.QueryForObject<string>("FindDepartment", deptId);
return str;
}
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="MyBatisApp" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<statements>
<statement id="FindDepartment" parameterClass="System.Int32" resultClass="System.String" >
SELECT Name
FROM Department
WHERE Id = #value#
</statement>
</sqlMap>
Structural Rules
The following structural rules are provided with MyBatis extension:
Release | Link |
---|---|
1.3.0-funcrel | https://technologies.castsoftware.com/rules?sec=srs_ibatis&ref=||1.3.0-funcrel |
Limitations
- SQL Query from Annotation Provider APIs cannot be resolved, therefore Unknown MyBatis SQL Query objects will be created for them
- Unknown Entity and Unknown Entity Operation objects are created for tk.Mybatis in case the entity of the CRUD transaction cannot be resolved