5 Multivendor database support - Reference Documentation
Authors: Franjo Žilić
Version: 0.0.2
5 Multivendor database support
Support multiple database vendors
Configuration
Add following to your configuration if you want to support H2, Microsoft SQL and IBM Informix databasesmybatis.multivendor.enabled = truemybatis.multivendor.mapping = [
'Microsoft SQL Server': 'mssql',
'H2': 'h2',
'Informix Dynamic Server': 'informix'
]
Mapper support
Let's say you want to query a databse for persons full name. You have to concat two fields in legacy PERSON table, here is sample mapper to do just that.<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.grails.mybatis.example.person"> <sql id="fullNameDatabaseSpecificQuery"> <choose> <when test="_databaseId == 'mssql'">FIRST_NAME + ' ' + LAST_NAME</when> <when test="_databaseId == 'informix'">FIRST_NAME || ' ' || LAST_NAME</when> <otherwise>CONCAT(FIRST_NAME, ' ', LAST_NAME</otherwise> </choose> </sql> <select id="loadPersonFullNameById>" resultType="String" parameterType="Integer"> SELECT <include refid="fullNameDatabaseSpecificQuery"/> FROM PERSON WHERE ID = #{value} </select></mapper>