MyBatis - 1.2
Extension ID
com.castsoftware.ibatis
What’s new ?
Please see MyBatis - 1.2 - Release Notes for more information.
Description
This extension provides support for:
-
MyBatis for Java using:
-
Mapper XML file containing SQL queries
-
MyBatis Annotations for JAVA
-
MyBatis-Spring integration
-
-
MyBatis for .NET using:
- Mapper XML file containing SQL queries only
-
TkMyBatis using:
- Methods provided by mapper class
In what situation should you install this extension?
This extension should be installed when analyzing a Java/.NET project that uses a MyBatis framework or TkMyBatis 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.
Supported MyBatis versions
The following table displays the supported versions matrix:
Language Supported | Version | Support |
---|---|---|
Java | 3.4.0 | Mapper XML files MyBatis Annotation for Java MyBatis-Spring Integration |
.NET | 4.5.2 | Mapper XML file |
Supported TkMyBatis Libraries
The following table displays the supported versions matrix:
mapper-spring-boot-starter | 2.1.5 |
Supported TkMyBatis Operations
Operation |
Methods |
Supported |
---|---|---|
Insert |
|
|
|
||
Update |
|
|
|
||
|
||
|
||
Select |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Delete |
|
|
|
||
|
AIP Core compatibility
This extension is compatible with:
CAST AIP release | Supported |
---|---|
8.3.x |
Prerequisites
An installation of any compatible release of AIP Core (see table above). | |
SQL database should already be extracted and DDL created if it requires analysis. |
Dependencies with other extensions
Some extensions require the presence of other extensions in order to function correctly. The MyBatis extension requires that the following other CAST extensions are also installed:
- CAST AIP Internal extension (internal technical extension)
- SQL Analyzer extension
When using the CAST Extension Downloader to download the MyBatis extension and the Manage Extensions interface in CAST Server Manager to install the extension:
- the CAST AIP Internal extension will be automatically downloaded and installed for you. You do not need to do anything.
- the SQL Analyzer extension - is not configured
as a “dependent” extension and will therefore not be automatically
downloaded and installed for you. However:
- When using CAST AIP ≥ 8.3.x, the SQL Analyzer extension is installed by default, therefore you do not need to do anything.
- When using CAST AIP ≤ 8.2.x, the SQL Analyzer extension is not installed by default, therefore you will need to download and install it manually if you want to handle the SQL source code in your MyBatis application.
Download and installation instructions
The extension will be automatically downloaded and installed in CAST Console.
Source code discovery
The MyBatis extension does not contain any discoverers or extractors, therefore, no “MyBatis” projects will be discovered. However, since the code delivered is Java/.NET and SQL, when using AIP Console, all source should be detected automatically. You should therefore ensure that your code is organised as follows before delivery:
Java
- one folder containing all the Java related code along with MyBatis.
- one folder containing the SQL DDL extraction
.NET
- one folder containing all the .NET related code and the XML related files
- one folder containing the SQL DDL extraction
Delivery and analysis configuration
Using AIP Console
When using AIP Console, after delivery you should end up with the following technologies:
- JEE or .NET for the main source code
- Universal for the SQL source code
All dependencies will be automatically configured (example for JEE):
Note that:
- When working with .NET, the package discovered is equivalent to the main source code package described in .NET - Prepare and deliver the source code.
- you may need to create additional packages, for example, for .NET an additional package may be required to package the .NET Assemblies. Please refer to .NET - Prepare and deliver the source code.
What results can you expect?
Once the analysis/snapshot generation has completed, you can view the results in the normal manner. Below are the transactions obtained after analysis as shown in CAST Enlighten:
For Java
Mapper XML files
For Mapper XML files - this extension will detect SQL queries and create objects and links. Below is a Mapper XML file with its result in Enlighten:
Support of “Include” tag
This extension provide support of “Include” tag used in Mapper XML file. Below is a sample of “Include” tag with its result in Enlighten:
Support of Dynamic SQL Tags
This extension provide support of following Dynamic SQL tag used in Mapper XML file. Below is list of tags support with sample source code and result in Enlighten:
Element | Description |
---|---|
isEmpty | Checks to see if the value of a Collection, String property is null or empty. |
isNotEmpty | Checks to see if the value of a Collection, String property is not null and not empty. |
isNotNull | Checks if a property is not null. |
isNull | Checks if a property is null. |
isPropertyAvailable | Checks if a property is available. |
isNotPropertyAvailable | Checks if a property is unavailable. |
isParameterPresent | Checks to see if the parameter object is present (not null). |
isNotParameterPresent | Checks to see if the parameter object is not present (null). |
isEqual | Checks the equality of a property and a value, or another property. |
isNotEqual | Checks the inequality of a property and a value, or another property. |
isGreaterThan | Checks if a property is greater than a value or another property. |
isGreaterEqual | Checks if a property is greater than or equal to a value or another property. |
isLessEqual | Checks if a property is less than or equal to a value or another property. |
list of Add-on Dynamic SQL tags support with sample source code and result in Enlighten:
Tags |
where |
foreach |
if |
<select id="getSelectVillage" resultMap="SelectVillage">
select ID,Name,district from Village
<where>
file.ID in
<foreach collection="interNames" item="interName">#{interName}</foreach>
<if test="District != null and !District.isEmpty">
and District in
<foreach collection="District" item="district" open="(" separator="," close=")">#{district}</foreach>
</if>
</where>
group by ID
) as import_errors
on persist_errors.ID = import_errors.ID
</select>
MyBatis for Annotation / MyBatis-Spring Integration
Supported Annotations
This extension supports the following Annotations used in MyBatis Annotations for Java and MyBatis-Spring integration applications:
-
@Select - org.apache.ibatis.annotations.Select
-
@Insert - org.apache.ibatis.annotations.Insert
-
@Update - org.apache.ibatis.annotations.Update
-
@Delete - org.apache.ibatis.annotations.Delete
For MyBatis Annotations
In Java mapper File, when we pass the SQL Queries with annotation parameter directly. Below is a MyBatis-Annotation sample source code with its result in Enlighten
In the Java Mapper file, when the annotation parameter contains variables which are initialized with a query instead of a query statement itself. Below is a sample source code with its result in Enlighten:
For MyBatis-Spring
Below a Mybatis Spring Integration sample source code with its result in Enlighten:
For .NET
For Mapper XML files, below is a mapper XML file with its result in Enlighten:
MYBATIS DOTNET SQLNAMEDQUERY are created to link between C# method and tables
For TkMyBatis
TkMyBatis source code scenario - 1
Insert operation:
public int addVillageCore(VillagePropertysTypeDao card) throws IOException
{
int chck = villagePropertysTypeDao.insertSelective(entity);
return chck;
}
Select operation:
private List<VillagePropertysTypeDTO> getVillagePropertysTypeAll() {
return VillageNameutil.get("VillagePropertysType_All", new Callable<List<VillagePropertysTypeDTO>>() {
public List<VillagePropertysTypeDTO> call() throws IOException {
var list = villagePropertysTypeDao.selectAll();
return Districtvillageutil.copyList(list, VillagePropertysTypeDTO.class);
}
});
}
Update operation:
public int updateVillageCore(villageEntity entity) {
entity.setModifyTime(new Date());
entity.setVillageID(null);
entity.setName(null);
return villagePropertysTypeDao.updateByExampleSelective(entity,example);
}
TkMyBatis source code scenario - 2
A quick introduction of how to create the project with its result in Enlighten:
Configuration Entity class:
@Table(name = "`village`")
public class Village_data
{
.....
}
Create the interface:
import tk.mybatis.mapper.common.Mapper;
@Component
public interface VillageDao<T> extends Mapper<T>{
}
Create the DAO interface:
public interface VillagePropertysTypeDao extends VillageDao<Village_data>{
}
Test case - Use of Interface:
public List<VillagePropertysTypeDTO> getVillagePropertysCore(String memberId) {
var queryVillage = new Village_data();
queryVillage.setMemberID(memberId);
var list = villagePropertysTypeDao.selectByRowBounds(queryVillage);
return BeanUtil.copyList(list, VillagePropertysTypeDTO.class);
}
Objects
The following specific objects are displayed in CAST Enlighten:
- Mapper xml file - this object is created by the JEE Analyzer/.NET Analyzer.
- SQL_Named query - this object(s) is created by the MyBatis extension for Java Projects.
- MYBATIS DOTNET SQLNAMEDQUERY - this object(s) is created by the MyBatis extension for .NET Projects.
Links
Various links are created but the following are the links specific to the MyBatis extension:
MyBatis for Java
- Call link between a Java Method object and an SQL_Named query object.
- Use (typed with Select, Delete, Insert, Update) link between an SQL_Named query object and a Table object.
MyBatis for .NET
- Call link between a .NET Method object and an MYBATIS DOTNET SQLNAMEDQUERY object.
- Use (typed with Select, Delete, Insert, Update) link between an MYBATIS DOTNET SQLNAMEDQUERY object and a Table object.
- Refer link between a .NET Constructor object and an MYBATIS DOTNET SQLNAMEDQUERY object.
TkMyBatis
- Use (typed with Select, Delete, Insert, Update) link between an Java Method object and a Table object.
public int addUpdateVillageCore(VillagePropertysTypeDao card) throws IOException
{
Village_data entity =new Village_data();
int chck = villagePropertysTypeDao.insertSelective(entity);
var type = new typed(Village_data.class);
entity.setModifyTime(new Date());
entity.setVillageID(null);
entity.setName(null);
return villagePropertysTypeDao.updateByExampleSelective(entity,type);
}
Structural Rules
The following structural rules are provided with MyBatis extension: