From 6345c50f5410ba71d0870adb1dee4ab408cca36f Mon Sep 17 00:00:00 2001 From: minuk926 Date: Tue, 12 Jul 2022 16:43:58 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20DB=20=EB=B6=84=EB=A6=AC=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/xit/Application.java | 6 +++- .../java/com/xit/biz/ctgy/CtgyConstants.java | 3 ++ .../xit/biz/ctgy/v2/repository/BoardDao.java | 5 +++ .../biz/ctgy/v2/repository/CmmCodeDao.java | 5 +++ .../biz/ctgy/v2/repository/ParkingDao.java | 7 ++++ .../ctgy/v2/repository/PublicBoardDao.java | 5 +++ .../v2/repository/ResidentAndDisabledDao.java | 6 ++++ .../xit/biz/ctgy/v2/repository/UserDao.java | 6 ++++ .../config/database/BaseMpowerDaoSupport.java | 32 +++++++++++-------- .../core/oauth2/api/dao/RefreshTokenDao.java | 6 ++++ .../properties/IDatabaseProperties.java | 7 ++++ .../properties/MasterDatabaseProperties.java | 14 ++++++++ .../properties/SlaveDatabaseProperties.java | 14 ++++++++ src/main/resources/config/conf.yml | 12 +++++-- 14 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/xit/core/oauth2/config/properties/IDatabaseProperties.java create mode 100644 src/main/java/com/xit/core/oauth2/config/properties/MasterDatabaseProperties.java create mode 100644 src/main/java/com/xit/core/oauth2/config/properties/SlaveDatabaseProperties.java diff --git a/src/main/java/com/xit/Application.java b/src/main/java/com/xit/Application.java index 03a28b6..5a6384b 100644 --- a/src/main/java/com/xit/Application.java +++ b/src/main/java/com/xit/Application.java @@ -5,6 +5,8 @@ package com.xit; import com.xit.core.config.support.CustomBeanNameGenerator; import com.xit.core.oauth2.config.properties.AppProperties; import com.xit.core.oauth2.config.properties.CorsProperties; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; +import com.xit.core.oauth2.config.properties.SlaveDatabaseProperties; import com.xit.core.util.Checks; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -32,7 +34,9 @@ import java.io.IOException; @ServletComponentScan @EnableConfigurationProperties({ CorsProperties.class, - AppProperties.class + AppProperties.class, + MasterDatabaseProperties.class, + SlaveDatabaseProperties.class }) @ComponentScan( nameGenerator = CustomBeanNameGenerator.class, diff --git a/src/main/java/com/xit/biz/ctgy/CtgyConstants.java b/src/main/java/com/xit/biz/ctgy/CtgyConstants.java index ccf57c4..8f0205c 100644 --- a/src/main/java/com/xit/biz/ctgy/CtgyConstants.java +++ b/src/main/java/com/xit/biz/ctgy/CtgyConstants.java @@ -6,6 +6,9 @@ import lombok.Getter; public class CtgyConstants { + public static final String DB_MASTER = "master"; + public static final String DB_SLAVE = "slave"; + @Getter @AllArgsConstructor public enum Judge { diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java index 237f31e..b18e839 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java @@ -2,6 +2,7 @@ package com.xit.biz.ctgy.v2.repository; import com.xit.biz.ctgy.dto.BoardDto; import com.xit.core.config.database.BaseMpowerDaoSupport; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; import com.xit.core.support.sql.parser.QueryGenerator; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -16,6 +17,10 @@ import java.util.*; public class BoardDao extends BaseMpowerDaoSupport { private static final String NAME_SPACE = "board"; + public BoardDao(MasterDatabaseProperties databaseProperties) { + super(databaseProperties); + } + public Page findAll(@NotNull final BoardDto dto, @NotNull final Pageable pageable) { final String cntSql = getSql("selectBoardListCnt", dto, pageable); final String listSql = getSql("selectBoardList", dto, pageable); diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/CmmCodeDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/CmmCodeDao.java index d83d465..b1d92f0 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/CmmCodeDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/CmmCodeDao.java @@ -3,6 +3,7 @@ package com.xit.biz.ctgy.v2.repository; import com.xit.biz.cmm.dto.ComboCodeDto; import com.xit.biz.ctgy.dto.MinUserinfoDto; import com.xit.core.config.database.BaseMpowerDaoSupport; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; import com.xit.core.support.sql.parser.QueryGenerator; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Repository; @@ -16,6 +17,10 @@ import java.util.Optional; public class CmmCodeDao extends BaseMpowerDaoSupport { private static final String NAME_SPACE = "cmmCode"; + public CmmCodeDao(MasterDatabaseProperties databaseProperties) { + super(databaseProperties); + } + public List queryComboCodeClass(@NotNull final String codeGrpId, @NotNull final String codeLcd, @NotNull final String codeMcd) { final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectComboCodes") .setParameter("codeGrpId", codeGrpId) diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/ParkingDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/ParkingDao.java index fef2336..675cc9e 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/ParkingDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/ParkingDao.java @@ -2,8 +2,11 @@ package com.xit.biz.ctgy.v2.repository; import com.xit.biz.ctgy.dto.*; import com.xit.core.config.database.BaseMpowerDaoSupport; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; +import com.xit.core.oauth2.config.properties.SlaveDatabaseProperties; import com.xit.core.oauth2.utils.HeaderUtil; import com.xit.core.support.sql.parser.QueryGenerator; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; @@ -17,6 +20,10 @@ import java.util.Map; public class ParkingDao extends BaseMpowerDaoSupport { private static final String NAME_SPACE = "parking"; + public ParkingDao(MasterDatabaseProperties masterDatabaseProperties) { + super(masterDatabaseProperties); + } + public Page findParkings(@NotNull final JudgeListDto dto, @NotNull final Pageable pageable) { final String cntSql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectParkingListCnt") .setParameter("msYear", dto.getMsYear()) diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java index 73318a6..69df46c 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java @@ -2,6 +2,7 @@ package com.xit.biz.ctgy.v2.repository; import com.xit.biz.ctgy.dto.MinInfoBoard680Dto; import com.xit.core.config.database.BaseMpowerDaoSupport; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; import com.xit.core.support.sql.parser.QueryGenerator; import com.xit.core.util.Checks; import lombok.extern.slf4j.Slf4j; @@ -18,6 +19,10 @@ import java.util.List; public class PublicBoardDao extends BaseMpowerDaoSupport { private static final String NAME_SPACE = "pboard"; + public PublicBoardDao(MasterDatabaseProperties databaseProperties) { + super(databaseProperties); + } + private static final String fieldStrs = "inCode, inBgubun, inContentno, inContents, inDept, inEtc, inFilename, inFilesize, inFileurl, inHit, inNalja, inName, inTime, inTitle"; public Page findAll(@NotNull final MinInfoBoard680Dto dto, @NotNull final Pageable pageable) { diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/ResidentAndDisabledDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/ResidentAndDisabledDao.java index b99635e..6e83e38 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/ResidentAndDisabledDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/ResidentAndDisabledDao.java @@ -6,6 +6,8 @@ import com.xit.biz.ctgy.dto.JudgeListDto; import com.xit.biz.ctgy.dto.JudgeTargetDto; import com.xit.biz.ctgy.dto.MinSimsaUser680ScDto; import com.xit.core.config.database.BaseMpowerDaoSupport; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; +import com.xit.core.oauth2.config.properties.SlaveDatabaseProperties; import com.xit.core.oauth2.utils.HeaderUtil; import com.xit.core.support.sql.parser.QueryGenerator; import org.springframework.data.domain.Page; @@ -22,6 +24,10 @@ public class ResidentAndDisabledDao extends BaseMpowerDaoSupport { private static final String NAME_SPACE = "residentAndDisabled"; + public ResidentAndDisabledDao(SlaveDatabaseProperties databaseProperties) { + super(databaseProperties); + } + public Page findJudgeDatas(@NotNull final String scDatagb, @NotNull final Pageable pageable) { final String cntSql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectJudgeDataListCnt") .setParameter("scDatagb", scDatagb) diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java index 1d7b950..8eb8ed2 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java @@ -3,6 +3,8 @@ package com.xit.biz.ctgy.v2.repository; import com.xit.biz.ctgy.dto.MinUserinfoDto; import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.core.config.database.BaseMpowerDaoSupport; +import com.xit.core.oauth2.config.properties.IDatabaseProperties; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; import com.xit.core.support.sql.parser.QueryGenerator; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -18,6 +20,10 @@ import java.util.Optional; public class UserDao extends BaseMpowerDaoSupport { private static final String NAME_SPACE = "user"; + public UserDao(MasterDatabaseProperties databaseProperties) { + super(databaseProperties); + } + public Optional findByUserid(@NotNull final String userid){ final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectUserInfo") .setParameter("userid", userid) diff --git a/src/main/java/com/xit/core/config/database/BaseMpowerDaoSupport.java b/src/main/java/com/xit/core/config/database/BaseMpowerDaoSupport.java index 12692c7..93bf442 100644 --- a/src/main/java/com/xit/core/config/database/BaseMpowerDaoSupport.java +++ b/src/main/java/com/xit/core/config/database/BaseMpowerDaoSupport.java @@ -2,8 +2,15 @@ package com.xit.core.config.database; import com.plf.client.Client; import com.xit.biz.cmm.dto.ComboCodeDto; +import com.xit.biz.ctgy.CtgyConstants; import com.xit.core.constant.ErrorCode; import com.xit.core.exception.MpowerException; +import com.xit.core.oauth2.config.properties.IDatabaseProperties; +import com.xit.core.oauth2.config.properties.MasterDatabaseProperties; +import com.xit.core.oauth2.config.properties.SlaveDatabaseProperties; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; @@ -20,19 +27,13 @@ import java.time.format.DateTimeFormatter; import java.util.*; @Slf4j +@RequiredArgsConstructor public abstract class BaseMpowerDaoSupport { - @Value("${mpower.dbName}") - private String dbName; + private final IDatabaseProperties databaseProperties; - @Value("${mpower.hostIp}") - private String hostIp; - - @Value("${mpower.port}") - private int port; - - public void setDbName(String dbName){ - this.dbName = dbName; - } + @Setter + @Getter + private String dbTarget = "master"; public T selectOne(Class type, String sql, String fields){ Objects.requireNonNull(type, "Class cannot be null"); @@ -342,7 +343,8 @@ public abstract class BaseMpowerDaoSupport { return String.format( "%s%s%s%s%s%s%s", "\n\n\n