Skip to end of metadata
Go to start of metadata

 

Based on the altibase_mybatis_sidu example, this explains in more detail how to integrate MyBatis with ALTIBASE. Note that the IDE used is Eclipse.

 

Creating DB Table and Sequence


Create the following table and sequence in the database.

 

Create Project


In Eclipse, create a project named altibase_mybatis_sidu.

  1. Menu – File – Click Java Project

  2. Enter Project name: Altibase_mybatis_sidu

  3. Click the Finish button

 

Package Naming Convention


The package name explained in the appendix is basically named com.altibase.sidu, which follows common package classification rules. Each part has the following meaning:

 

  • com: The first part defines the leading group of the project, where com stands for company. For smaller organizations, org (organization) might be used instead.
  • altibase: The second part defines the company or group name. For companies, it’s usually the company name; for groups, the group name. Since this document is from Altibase, it is named altibase.

 

  • sidu: The third part represents the artifact structure of this project. Since this sample covers general DML commands (Select/Insert/Delete/Update), it is named sidu.

 

Creating Configuration File


1. Create a properties file (db.properties) that defines properties for connecting to Altibase.

(In the altibase_mybatis_sidu project – right-click the src directory, select New – File, and name the file db.properties.)

2. In the configuration file (mybatis-config.xml), set the dataSource and SqlMap files for integration with ALTIBASE.

    (In the altibase_mybatis_sidu project – right-click the src directory, click New – File, and name the file mybatis-config.xml.)

 

Create Mapper File


Create a Mapper file (Person.xml) that defines methods mapped to CRUD SQL statements for the Users table.

The Mapper is created in the com.altibase.sidu.mapper package.

1. In the altibase_mybatis_sidu project – right-click the src directory, click New – Package, and create a new package named com.altibase.sidu.mapper.

2. In the newly created package (com.altibase.sidu.mapper), right-click, select New – File, and name the file UserMapper.xml.

3. Write the following content into UserMapper.xml.

When the application calls the insert, update, or delete methods in the configuration, the SQL statements defined in the <insert>, <update>, <delete>, and <select> tags with matching ids in the above file are automatically executed.

 

Creating the Application


1. Create a VO (Value Object) class for the users table called UserVO (UserVo.java).
1-1. In the altibase_mybatis_sidu project, right-click the src directory and select New – Class.
1-2. Enter com.altibase.sidu.model in the Package field and UserVo in the Name field.

1-3. Write the following content into the UserVo.java file.

2. Create the MyBatisUtil.java class, which includes the DB connection and necessary methods.

2-1. In the altibase_mybatis_sidu project, right-click the src directory and select New – Class.
2-2. Enter com.altibase.sidu.util in the Package field and MybatisUtil in the Name field.

2-3. Write the following content into the MybatisUtil.java file.

3. Create a class that obtains a SqlSession object from the MybatisUtil class and executes queries.

    In the example, separate classes were declared for each DML operation. This example explains only the Select case.

    3.1 In the altibase\_mybatis\_sidu project, right-click the src directory and select New – Class.

    3.2 Enter com.altibase.sidu.application in the Package field and SiduSampleSelect in the Name field.

3.3 Write the following content in the SiduSampleSelect.java file.

4. Write the Main class, where the actual program runs, in the SiduMain.java file.

 

Add related JAR files


Add the Altibase.jar and mybatis-3.2.8.jar files.

In the altibase_mybatis_sidu project, right-click and select Properties – Java Build Path – Libraries, then click Add External JARs and add the Altibase.jar and mybatis-3.2.8.jar files.

 

Run the Application


Run the altibase_mybatis_sidu project.

Click the altibase_mybatis_sidu project and select Run from the menu, or open the SiduMain.java class in the com.altibase.sidu.application package by double-clicking it, then run it.

 

 

  • No labels