
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
<?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">
<!--
작성자 : 최정우
작성일 : 2019.11.17
내용 : Mariadb 접속 모듈에 관련된 SQL입니다.
-->
<mapper namespace="MariadbDAO">
<!--
작성자 : 최정우
작성일 : 2020.01.27
내용 : 커넥션된 데이터베이스의 테이블 목록 조회 SQL입니다.
-->
<select id="getDBConnectionTableList" parameterType="ConnectionDB" resultType="Dataset">
SELECT TABLE_SCHEMA AS "databaseNm"
, TABLE_NAME AS "tableNm"
, TABLE_COMMENT AS "tableNmKr"
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = #{databaseNm}
ORDER BY TABLE_NAME ASC
</select>
<!--
작성자 : 최정우
작성일 : 2020.01.27
내용 : 커넥션된 데이터베이스의 테이블의 컬럼 정보 조회 (DB 기준 데이터 타입, 데이터 크기 등)
-->
<select id="getDBConnectionTableColumnList" parameterType="Dataset" resultType="ColumnData">
SELECT
TABLE_SCHEMA AS databaseNm
, TABLE_NAME AS tableNm
, COLUMN_NAME AS columnNm
, COLUMN_NAME AS displyColumnNm
, COLUMN_NAME AS orginlColumnNm
, DATA_TYPE AS dbDataType
, CHARACTER_MAXIMUM_LENGTH AS dataSize
, ORDINAL_POSITION AS ordr
, CASE WHEN COLUMN_KEY = 'PRI' then true else false end as "pkAt"
, CASE WHEN COLUMN_KEY = 'UNI' then true else false end as "uniqeAt"
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = #{databaseNm}
AND
TABLE_NAME = #{tableNm}
ORDER BY
ORDINAL_POSITION
</select>
<!--
작성자: 최정우
작성일: 2020.01.27
내용: 커넥션된 데이터베이스의 테이블의 데이터 목록 조회 SQL입니다.(페이징)
-->
<select id="getDBConnectionTableDataList" parameterType="DataTable" resultType="java.util.LinkedHashMap">
SELECT
*
FROM
`${databaseNm}`.`${tableNm}`
WHERE 1 = 1
<!-- 검색 -->
<choose>
<!-- 컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<when test="columnDatas != null and columnDatas.size() > 0 and (searchCondition == null or searchCondition == '') and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="item" index="index" collection="columnDatas" open="(" separator=" OR " close=")">
<foreach item="keyword" index="index2" collection="searchKeywordList" separator=" OR ">
`${item.columnNm}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</foreach>
</when>
<!-- //컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<!-- 컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
<otherwise>
<if test="searchCondition != null and searchCondition != '' and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="keyword" index="index2" collection="searchKeywordList" open="(" separator=" OR " close=")">
`${searchCondition}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</if>
</otherwise>
<!-- //컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
</choose>
<!-- //검색 -->
<!-- 정렬 -->
<if test="order != null and order != ''">
ORDER BY `${order}`
<choose>
<!-- 오름차순일 때 -->
<when test="isOrderASC == true">
ASC
</when>
<!-- //오름차순일 때 -->
<!-- 내림차순일 때 -->
<otherwise>
DESC
</otherwise>
<!-- 내림차순일 때 -->
</choose>
) AS NUM
</if>
<!-- //정렬 -->
<if test="isUsePaging == true">
LIMIT #{perPage} OFFSET #{startIndex}
</if>
</select>
<!--
작성자: 최정우
작성일: 2020.01.27
내용: 커넥션된 데이터베이스의 테이블의 데이터 목록 총 갯수 조회 SQL입니다.
-->
<select id="getDBConnectionTableDataTotalRows" parameterType="DataTable" resultType="java.lang.Integer">
SELECT
COUNT(0)
FROM
`${databaseNm}`.`${tableNm}`
WHERE 1 = 1
<!-- 검색 -->
<choose>
<!-- 컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<when test="columnDatas != null and columnDatas.size() > 0 and (searchCondition == null or searchCondition == '') and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="item" index="index" collection="columnDatas" open="(" separator=" OR " close=")">
<foreach item="keyword" index="index2" collection="searchKeywordList" separator=" OR ">
`${item.columnNm}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</foreach>
</when>
<!-- //컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<!-- 컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
<otherwise>
<if test="searchCondition != null and searchCondition != '' and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="keyword" index="index2" collection="searchKeywordList" open="(" separator=" OR " close=")">
`${searchCondition}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</if>
</otherwise>
<!-- //컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
</choose>
<!-- //검색 -->
</select>
<!--
작성자: 최정우
작성일: 2020.01.27
내용: 커스텀 테이블 데이터 조회 (페이징사용 유무에 따라 페이징 처리) SQL입니다.
-->
<select id="getDBConnectionCustomQueryDataList" parameterType="DataTable" resultType="java.util.LinkedHashMap">
SELECT
a.*
FROM (
${query}
) a
<if test="limit > 0">
LIMIT #{limit}
</if>
</select>
<!--
작성자: 최정우
작성일: 2020.01.27
내용: 커스텀 테이블 실행형
-->
<update id="executeCustomQuery" parameterType="DataTable">
/*+ RULE */
${query}
</update>
<!--
작성자: 최정우
작성일: 2020.01.27
내용: 커스텀 테이블 데이터 목록 총 갯수 조회 SQL입니다.
-->
<select id="getDBConnectionCustomQueryDataTotalRows" parameterType="DataTable" resultType="java.lang.Integer">
SELECT
COUNT(0)
FROM (
${query}
) a
</select>
<!--
작성자: 최정우
작성일: 2020.01.27
내용: DB연계 데이터 목록 조회 (초기 DB화 때에 등록한 컬럼만 가지고 옴)
-->
<select id="getDBCollectionQueryDataList" parameterType="DataTable" resultType="java.util.LinkedHashMap">
SELECT
<foreach item="item" index="index" collection="columnDatas" open="" separator="," close="">
a.`${item.orginlColumnNm}` AS '${item.columnName}'
</foreach>
FROM (
${query}
) a
<!-- 검색 -->
<choose>
<!-- 컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<when test="columnDatas != null and columnDatas.size() > 0 and (searchCondition == null or searchCondition == '') and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="item" index="index" collection="columnDatas" open="(" separator=" OR " close=")">
<foreach item="keyword" index="index2" collection="searchKeywordList" separator=" OR ">
a.`${item.orginlColumnNm}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</foreach>
</when>
<!-- //컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<!-- 컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
<otherwise>
<if test="searchCondition != null and searchCondition != '' and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="keyword" index="index2" collection="searchKeywordList" open="(" separator=" OR " close=")">
a.`${searchCondition}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</if>
</otherwise>
<!-- //컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
</choose>
<!-- //검색 -->
<!-- 정렬 -->
<if test="order != null and order != ''">
ORDER BY `${order}`
<choose>
<!-- 오름차순일 때 -->
<when test="isOrderASC == true">
ASC
</when>
<!-- //오름차순일 때 -->
<!-- 내림차순일 때 -->
<otherwise>
DESC
</otherwise>
<!-- 내림차순일 때 -->
</choose>
) AS NUM
</if>
<!-- //정렬 -->
<if test="isUsePaging == true">
LIMIT #{perPage} OFFSET #{startIndex}
</if>
</select>
<!--
작성자: 최정우
작성일: 2020.01.27
내용: DB연계 데이터 목록 총 갯수 조회
-->
<select id="getDBCollectionQueryDataTotalRows" parameterType="DataTable" resultType="java.lang.Integer">
SELECT
COUNT(0)
FROM (
${query}
) a
<!-- 검색 -->
<choose>
<!-- 컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<when test="columnDatas != null and columnDatas.size() > 0 and (searchCondition == null or searchCondition == '') and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="item" index="index" collection="columnDatas" open="(" separator=" OR " close=")">
<foreach item="keyword" index="index2" collection="searchKeywordList" separator=" OR ">
a.`${item.orginlColumnNm}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</foreach>
</when>
<!-- //컬럼 데이터 목록이 존재하고, 검색 조건이 없고, 검색 키워드가 있을 때 -->
<!-- 컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
<otherwise>
<if test="searchCondition != null and searchCondition != '' and searchKeyword != null and searchKeyword != ''">
AND
<foreach item="keyword" index="index2" collection="searchKeywordList" open="(" separator=" OR " close=")">
a.`${searchCondition}` LIKE CONCAT('%', #{keyword}, '%')
</foreach>
</if>
</otherwise>
<!-- //컬럼 데이터 목록이 존재하지 않거나, 검색 조건이 있거나, 검색 키워드가 있을 때 -->
</choose>
<!-- //검색 -->
</select>
<!--
작성자: 최정우
작성일: 2020.11.29
내용: 커트텀 쿼리 지정된 PK의 중복 데이터 수 (지정된 PK로 Table 생성이 가능한지 알아보기 위함)
-->
<select id="getCustomQueryPrimaryOverlapCount" parameterType="DataTable" resultType="java.lang.Integer">
SELECT
IFNULL(SUM(a.overlapCount), 0) AS totalOverlapCount
FROM (
SELECT
COUNT(0) AS overlapCount
FROM (
${query}
) t
GROUP BY
<foreach item="item" index="index" collection="columnData" open="" separator="," close="">
t.`${item.columnNm}`
</foreach>
HAVING
COUNT(0) > 1
) a
</select>
<!--
작성자 : 김성원
작성일 : 2021.01.17
내용 : 데이터 셋의 DB화 (테이블 생성)
-->
<update id="datasetTableCreate" parameterType="DataTable">
CREATE TABLE `${tableNm}` (
<foreach item="item" index="index" collection="columnDatas" separator=",">
`${item.columnNm}` ${item.dbDataType}
<if test="item.dbDataType == 'varchar'">(#{item.dataSize})</if>
<choose>
<when test="item.pkAt == true"> NOT NULL</when>
<otherwise> DEFAULT NULL</otherwise>
</choose>
</foreach>
, PRIMARY KEY (
<foreach item="item" index="index" collection="columnDatas" separator=",">
<if test="item.pkAt == true">
`${item.columnNm}`
</if>
</foreach>
)
<foreach item="item" index="index" collection="columnDatas">
<if test="item.isUniq == true">
, UNIQUE INDEX `${tableNm}_${item.columnNm}_UNIQUE` (`${item.columnNm}` ASC)
</if>
</foreach>
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
<if test="datasetSj != null and datasetSj != ''">
COMMENT = #{datasetSj}
</if>
</update>
<!--
작성자 : 김성원
작성일 : 2021.01.17
내용 : 데이터 셋의 DB화 (테이블 생성)
-->
<update id="datasetDefaultTableCreate" parameterType="DataTable">
CREATE TABLE `${tableNm}` (
`ts_row` bigint NOT NULL AUTO_INCREMENT
<foreach item="item" index="index" collection="columnDatas">
,`${item.columnNm}` ${item.dbDataType}
<if test="item.dbDataType == 'varchar'">
(#{item.dataSize})
</if>
DEFAULT NULL
</foreach>
, PRIMARY KEY (`ts_row`)
<foreach item="item" index="index" collection="columnDatas">
<if test="item.isUniq == true">
, UNIQUE INDEX `${tableNm}_${item.columnNm}_UNIQUE` (`${item.columnNm}` ASC)
</if>
</foreach>
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
<if test="datasetSj != null and datasetSj != ''">
COMMENT = #{datasetSj}
</if>
</update>
<!--
작성자 : 김성원
작성일 : 2021.01.17
내용 : 데이터 셋의 DB화 (데이터 생성 및 업데이트)
-->
<update id="datasetDataUpdate" parameterType="DataTable">
REPLACE INTO `${tableNm}`
<foreach item="item" index="index" collection="columnDatas" open="(" separator="," close=")">
`${item.columnNm}`
</foreach>
VALUES
<foreach item="row" collection="rowData" separator=",">
(
<foreach item="cell" index="index" collection="row" separator=",">
<choose>
<when test="columnDatas[index].pkAt == true and cell == ''" >
null
</when>
<otherwise>
#{cell}
</otherwise>
</choose>
<!--
<choose>
<when test="columnDatas[index].dbDataType == 'varchar' or columnDatas[index].dbDataType == 'datetime'">#{cell}</when>
<otherwise>${cell}</otherwise>
</choose>
-->
</foreach>
)
</foreach>
</update>
<!--
작성자 : 김성원
작성일 : 2021.01.17
내용 : 데이터 셋의 ROW 삭제
-->
<update id="datasetDataDelete" parameterType="DataTable">
DELETE FROM ${tableNm}
WHERE
1 = 1
<foreach item="item" index="index" collection="columnDatas" open=" AND " separator=" AND " close="">
`${item.columnNm}` in
<foreach item="items" index="indexs" collection="item.values" open="(" separator=", " close=")">
#{items}
</foreach>
</foreach>
</update>
<!--
작성자 : 김성원
작성일 : 2021.01.17
내용 : 중복 테이블명 체크
-->
<select id="duplicateChecktableNm" parameterType="Map" resultType="INTEGER">
SELECT count(*)
FROM
Information_schema.tables
WHERE
TABLE_SCHEMA = #{schema}
AND
TABLE_NAME = #{tableNm};
</select>
<!--
작성자 : 김성원
작성일 : 2021.01.17
내용: 데이터 셋의 컬럼 정보 목록 조회 SQL에 접근하는 메소드 입니다.(페이징)
-->
<select id="getRowData" parameterType="DataTable" resultType="java.util.LinkedHashMap">
SELECT
<foreach item="item" index="index" collection="columnDatas" open="" separator="," close="">
`${item.columnNm}`
</foreach>
FROM
`${tableNm}`
WHERE 1
<!-- 검색 -->
<if test="searchCondition != null and searchCondition != '' and searchKeyword != null and searchKeyword != ''">
AND
`${searchCondition}` LIKE CONCAT('%', #{searchKeyword}, '%')
</if>
<!-- //검색 -->
<!-- 정렬 -->
<if test="order != null and order != ''">
ORDER BY `${order}`
<choose>
<!-- 오름차순일 때 -->
<when test="isOrderASC == true">
ASC
</when>
<!-- //오름차순일 때 -->
<!-- 내림차순일 때 -->
<otherwise>
DESC
</otherwise>
<!-- 내림차순일 때 -->
</choose>
) AS NUM
</if>
<!-- //정렬 -->
LIMIT #{perPage} OFFSET #{offset}
</select>
<!--
작성자: 김성원
작성일: 2022.01.17
내용: 데이터 셋의 컬럼 정보 목록 조회 SQL에 접근하는 메소드 입니다.(노페이징)
-->
<select id="getRowDataAll" parameterType="DataTable" resultType="java.util.LinkedHashMap">
SELECT
<foreach item="item" index="index" collection="columnDatas" open="" separator="," close="">
`${item.columnNm}` AS `${item.displyColumnNm}`
</foreach>
FROM
`${tableNm}`
<if test="query != null and query != ''">
WHERE 1
${query}
</if>
<if test="perPage != null and perPage > 10">
LIMIT #{perPage} OFFSET #{offset}
</if>
</select>
<!--
작성자: 김성원
작성일: 2022.01.17
내용: 데이터 셋의 컬럼 정보 목록 총 갯수 조회 SQL
-->
<select id="getRowDataTotalRows" parameterType="DataTable" resultType="java.lang.Integer">
SELECT
COUNT(0)
FROM
`${tableNm}`
WHERE 1
<if test="searchCondition != null and searchCondition != '' and searchKeyword != null and searchKeyword != ''">
AND
`${searchCondition}` LIKE CONCAT('%', #{searchKeyword}, '%')
</if>
</select>
<!--
작성자: 김성원
작성일: 2022.01.17
내용 : 데이터 셋의 비우기 (데이터 셋 내용삭제)
-->
<delete id="emptyDataset" parameterType="DataTable">
DELETE FROM `${tableNm}`
</delete>
<!--
작성자 : 김성원
작성일 : 2022.01.20
내용 : 실제 생성된 컬럼 변경
-->
<update id="tableColumnChange" parameterType="TableBasicInfo">
ALTER TABLE `${tableName}` ${process} `${columnName}`
<if test="process == 'CHANGE'">
`${tobeColumnName}` ${dataType}
</if>
<if test="process == 'MODIFY' || process == 'ADD' ">${dataType}</if><if test="dataType == 'varchar' and process != 'DROP'">(${size})</if>
</update>
<!--
작성자 : 김성원
작성일 : 2022.01.20
내용 : 실제 생성된 테이블 PK처리
-->
<update id="changePromaryKey" parameterType="TableBasicInfo">
ALTER TABLE `${tableName}` ${process} PRIMARY KEY
<if test="process != 'DROP'">
<foreach item="item" index="index" collection="primaryList" open=" (" separator=", " close=")">
${item}
</foreach>
</if>
</update>
<!--
작성자 : 김성원
작성일 : 2022.01.20
내용 : AI PK 생성
-->
<update id="createAutoIncrement" parameterType="TableBasicInfo">
ALTER TABLE `${tableName}` ADD `${columnName}`
BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
</update>
<!--
작성자 : 김성원
작성일 : 2022.09.30
내용 : 테이블 메타정보 변경 (comments)
-->
<update id="updateTableMetaInfo" parameterType="DataTable">
ALTER TABLE ${tableNm}
COMMENT = #{datasetSj}
</update>
<!--
작성자 : 김성원
작성일 : 2024.01.17
내용 : 중복 테이블명 체크
-->
<select id="duplicateCheckTableName" parameterType="Map" resultType="Integer">
SELECT count(*)
FROM
Information_schema.tables
WHERE
TABLE_SCHEMA = #{schema}
AND
TABLE_NAME = #{tableName};
</select>
</mapper>