This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

Summary: This document provides basic information about the extension providing MyBatis (for Java/.NET) support.

What's new ?

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

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 wanting 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 SupportedVersionSupport
Java3.4.0

Mapper XML files

MyBatis Annotation for Java

MyBatis-Spring Integration

.NET4.5.2Mapper XML file

CAST AIP Compatibility 

This extension is compatible with:

CAST AIP release
Supported
8.3.x(tick)
8.2.x(tick)
8.1.x
(tick)
8.0.x(tick)
7.3.4

(tick)

Supported DBMS servers

This extension is compatible with the following DBMS servers:

DBMSSupported
CSS(tick)
Oracle(error)
Microsoft SQL Server(error)

Prerequisites

(tick)An installation of any compatible release of CAST AIP (see table above)
(tick)SQL database should already be extracted and DDL created.

Dependencies with other extensions 

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

Please see:

The latest release status of this extension can be seen when downloading it from the CAST Extend server.

Packaging, delivering and analyzing your source code 

Once the extension is installed, no further configuration changes are required before you can package your source code and run an analysis. The process of packaging, delivering and analyzing your source code is as follows:

Packaging and delivery

Note that the MyBatis extension does not contain any CAST Delivery Manager Tool discoverers or extractors, therefore, no "MyBatis" projects will be detected by the DMT. You therefore need to manually create Analysis Units in the CAST Management Studio - this is explained below. You should ensure that your code is organised as follows:

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

Using the CAST Delivery Manager Tool:

  • Create a new Version
  • Create a new Package using the Files on your file system option:

Click to enlarge


  • Define a name for the package and the root folder of your Application source code - this root folder should contain the folder for the Java/XML files or .NET/XML files and the folder for the SQL DDL:

Click to enlarge

Note that:

  • Run the Package action: the CAST Delivery Manager Tool will find Eclipse/Maven Java or .NET related "projects" associated with the MyBatis application source code - this is the expected behavior. However, if your Java/.NET related source code is part of a larger application, then other projects may also be found during the package action:

  • Finally, Deliver the version.

Analyzing

Using the CAST Management Studio:

  • Accept and deploy the Version in the CAST Management Studio. JEE / .NET Analysis Units will be created automatically - this is the expected behavior. However, if your MyBatis related source code is part of a larger application, then other Analysis Units may be created automatically:

Example for JEE

  • In the Current Version tab, you now need to add manually one Analysis Units for the  SQL source code:
    • Add a Universal Analyzer Analysis Unit for your SQL source code, selecting the Add new Universal Analysis Unit option and then:
      • ticking the SQL option
      • including the folder containing the SQL DDL:

 

  • Now move into the Dependencies tab within the Application editor, and create a dependency between the JEE Analysis Unit or .NET Analysis Unit as Source and the Universal Analysis Unit as Target:

Example for JEE

  • Finally run a test analysis on the Analysis Unit before you generate a new snapshot.

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

isEmptyChecks to see if the value of a Collection, String property is null or empty.
isNotEmptyChecks to see if the value of a Collection, String property is not null and not empty.
isNotNullChecks if a property is not null.
isNullChecks if a property is null.
isPropertyAvailableChecks if a property is available.
isNotPropertyAvailableChecks if a property is unavailable.
isParameterPresentChecks to see if the parameter object is present (not null).
isNotParameterPresentChecks to see if the parameter object is not present (null).
isEqualChecks the equality of a property and a value, or another property.
isNotEqualChecks the inequality of a property and a value, or another property.
isGreaterThanChecks if a property is greater than a value or another property.
isGreaterEqualChecks if a property is greater than or equal to a value or another property.
isLessEqualChecks if a property is less than or equal to a value or another property.

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

Supported Annotation code

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

Click to enlarge

  

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

Supported Spring code

Below a Mybatis Spring Integration sample source code with its result in Enlighten:

Click to enlarge

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


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:

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. 

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.