Profile
src/main/resources/application-{active profile name}.yml
application-dxp-loc.yml
spring: profiles: active: dxp-loc
YML
ice-mybatis: mapper-locations: classpath:mybatis/*.xml
Datasource
src/main/resources/schema/profiles/{active profile name}/datasource.json
[ { "typeId" : "datasource", "id" : "mySqlDb", "ssl" : false, "dsName" : "Test DB (Maria)", "jdbcUrl" : "jdbc:mysql://125.131.88.77:3306/ice2", "dbType" : "maria", "username" : "ice2", "password" : "ice2" }, { "typeId" : "datasource", "id" : "oracleDb", "ssl" : false, "dsName" : "Test DB (Oracle)", "jdbcUrl" : "jdbc:oracle:thin:@125.131.88.69:8200:ORCL", "dbType" : "oracle", "username" : "ICE", "password" : "ICE1234" }, { "typeId" : "datasource", "id" : "msDb", "ssl" : false, "dsName" : "Test DB (MS)", "jdbcUrl" : "jdbc:sqlserver://125.131.88.94:1500;databaseName=IPS", "dbType" : "msSql", "username" : "icafe13", "password" : "icafe1234!@" } ]
XML
src/main/resources/mybatis/
<mapper namespace="net.ion.ice.services.mybatis.mapper.SampleLogicMybatis">
src/main/resources/mybatis/sampleLogicMybatis.xml
<?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="net.ion.ice.services.mybatis.mapper.SampleLogicMybatis"> <select id="list" resultType="org.springframework.util.LinkedCaseInsensitiveMap"> select a.NID as id , a.CONTENTS_TITLE as title , a.RELEASE_DATE as releaseDate , a.CONTENTS_SYNOPSIS as contents , a.BASE_PRICE as price , b.SERIES_ID as seriesId , b.TITLE as seriesTitle from MOVIE a, MOVIE_SERIES b where a.SERIES_ID = b.SERIES_ID <if test="id != null"> and a.NID = #{id} </if> </select> </mapper>
Mapper
src/main/java/net/ion/ice/services/mybatis/mapper/
/src/main/java/net/ion/ice/services/mybatis/mapper/SampleLogicMybatis.java
@Mapper public interface SampleLogicMybatis { public List<Map> list(); }
Service
src/main/java/net/ion/ice/services/
mybatisService.getSqlSessionTemplate("datasource id")
src/main/java/net/ion/ice/test/SampleLogicMybatisService.java
@Autowired private MybatisService mybatisService; private SqlSessionTemplate sqlSessionTemplate; public SqlSessionTemplate getSessionTemplate() { if (sqlSessionTemplate == null) { sqlSessionTemplate = mybatisService.getSqlSessionTemplate("oracleDb"); } return sqlSessionTemplate; } public List<Map<String, Object>> list(QueryContext context) { List<Map<String, Object>> list = getSessionTemplate().selectList("net.ion.ice.services.mybatis.mapper.SampleLogicMybatis.list"); return list; }
LogicRepository
"repositoryType": "logic"
"serviceName": "sampleLogicMybatisService"
[ { "tid": "sampleLogicMybatis", "parentId": "test", "typeId": "nodeType", "repositoryType": "logic", "microservice": "test", "typeName": "Sample Logic Mybatis", "serviceName": "sampleLogicMybatisService", "propertyTypes":[ ... ] } ]
@Service("sampleLogicMybatisService")
implements LogicRepository
@Service("sampleLogicMybatisService") public class SampleLogicMybatisService implements LogicRepository { @Autowired private MybatisService mybatisService; private SqlSessionTemplate sqlSessionTemplate; public SqlSessionTemplate getSessionTemplate() { if (sqlSessionTemplate == null) { sqlSessionTemplate = mybatisService.getSqlSessionTemplate("oracleDb"); } return sqlSessionTemplate; } @Override public List<Map<String, Object>> list(QueryContext context) { List<Map<String, Object>> list = getSessionTemplate().selectList("net.ion.ice.services.mybatis.mapper.SampleLogicMybatis.list"); return list; } @Override public Map<String, Object> read(String id) { Map<String, Object> map = new LinkedHashMap<>(); map.put("id", id); Map<String, Object> result = getSessionTemplate().selectOne("net.ion.ice.services.mybatis.mapper.SampleLogicMybatis.list", map); return result; } @Override public int create(Node node) { return 0; } @Override public int update(Node node) { return 0; } @Override public int delete(String id) { return 0; } }