feat: DB 분리 적용

main
minuk926 2 years ago
parent cd3ce2fc34
commit 6345c50f54

@ -5,6 +5,8 @@ package com.xit;
import com.xit.core.config.support.CustomBeanNameGenerator; import com.xit.core.config.support.CustomBeanNameGenerator;
import com.xit.core.oauth2.config.properties.AppProperties; import com.xit.core.oauth2.config.properties.AppProperties;
import com.xit.core.oauth2.config.properties.CorsProperties; 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 com.xit.core.util.Checks;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -32,7 +34,9 @@ import java.io.IOException;
@ServletComponentScan @ServletComponentScan
@EnableConfigurationProperties({ @EnableConfigurationProperties({
CorsProperties.class, CorsProperties.class,
AppProperties.class AppProperties.class,
MasterDatabaseProperties.class,
SlaveDatabaseProperties.class
}) })
@ComponentScan( @ComponentScan(
nameGenerator = CustomBeanNameGenerator.class, nameGenerator = CustomBeanNameGenerator.class,

@ -6,6 +6,9 @@ import lombok.Getter;
public class CtgyConstants { public class CtgyConstants {
public static final String DB_MASTER = "master";
public static final String DB_SLAVE = "slave";
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum Judge { public enum Judge {

@ -2,6 +2,7 @@ package com.xit.biz.ctgy.v2.repository;
import com.xit.biz.ctgy.dto.BoardDto; import com.xit.biz.ctgy.dto.BoardDto;
import com.xit.core.config.database.BaseMpowerDaoSupport; 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.support.sql.parser.QueryGenerator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -16,6 +17,10 @@ import java.util.*;
public class BoardDao extends BaseMpowerDaoSupport { public class BoardDao extends BaseMpowerDaoSupport {
private static final String NAME_SPACE = "board"; private static final String NAME_SPACE = "board";
public BoardDao(MasterDatabaseProperties databaseProperties) {
super(databaseProperties);
}
public Page<BoardDto> findAll(@NotNull final BoardDto dto, @NotNull final Pageable pageable) { public Page<BoardDto> findAll(@NotNull final BoardDto dto, @NotNull final Pageable pageable) {
final String cntSql = getSql("selectBoardListCnt", dto, pageable); final String cntSql = getSql("selectBoardListCnt", dto, pageable);
final String listSql = getSql("selectBoardList", dto, pageable); final String listSql = getSql("selectBoardList", dto, pageable);

@ -3,6 +3,7 @@ package com.xit.biz.ctgy.v2.repository;
import com.xit.biz.cmm.dto.ComboCodeDto; import com.xit.biz.cmm.dto.ComboCodeDto;
import com.xit.biz.ctgy.dto.MinUserinfoDto; import com.xit.biz.ctgy.dto.MinUserinfoDto;
import com.xit.core.config.database.BaseMpowerDaoSupport; 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.support.sql.parser.QueryGenerator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -16,6 +17,10 @@ import java.util.Optional;
public class CmmCodeDao extends BaseMpowerDaoSupport { public class CmmCodeDao extends BaseMpowerDaoSupport {
private static final String NAME_SPACE = "cmmCode"; private static final String NAME_SPACE = "cmmCode";
public CmmCodeDao(MasterDatabaseProperties databaseProperties) {
super(databaseProperties);
}
public List<ComboCodeDto> queryComboCodeClass(@NotNull final String codeGrpId, @NotNull final String codeLcd, @NotNull final String codeMcd) { public List<ComboCodeDto> queryComboCodeClass(@NotNull final String codeGrpId, @NotNull final String codeLcd, @NotNull final String codeMcd) {
final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectComboCodes") final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectComboCodes")
.setParameter("codeGrpId", codeGrpId) .setParameter("codeGrpId", codeGrpId)

@ -2,8 +2,11 @@ package com.xit.biz.ctgy.v2.repository;
import com.xit.biz.ctgy.dto.*; import com.xit.biz.ctgy.dto.*;
import com.xit.core.config.database.BaseMpowerDaoSupport; 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.oauth2.utils.HeaderUtil;
import com.xit.core.support.sql.parser.QueryGenerator; 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.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -17,6 +20,10 @@ import java.util.Map;
public class ParkingDao extends BaseMpowerDaoSupport { public class ParkingDao extends BaseMpowerDaoSupport {
private static final String NAME_SPACE = "parking"; private static final String NAME_SPACE = "parking";
public ParkingDao(MasterDatabaseProperties masterDatabaseProperties) {
super(masterDatabaseProperties);
}
public Page<JudgeListDto> findParkings(@NotNull final JudgeListDto dto, @NotNull final Pageable pageable) { public Page<JudgeListDto> findParkings(@NotNull final JudgeListDto dto, @NotNull final Pageable pageable) {
final String cntSql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectParkingListCnt") final String cntSql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectParkingListCnt")
.setParameter("msYear", dto.getMsYear()) .setParameter("msYear", dto.getMsYear())

@ -2,6 +2,7 @@ package com.xit.biz.ctgy.v2.repository;
import com.xit.biz.ctgy.dto.MinInfoBoard680Dto; import com.xit.biz.ctgy.dto.MinInfoBoard680Dto;
import com.xit.core.config.database.BaseMpowerDaoSupport; 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.support.sql.parser.QueryGenerator;
import com.xit.core.util.Checks; import com.xit.core.util.Checks;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -18,6 +19,10 @@ import java.util.List;
public class PublicBoardDao extends BaseMpowerDaoSupport { public class PublicBoardDao extends BaseMpowerDaoSupport {
private static final String NAME_SPACE = "pboard"; 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"; private static final String fieldStrs = "inCode, inBgubun, inContentno, inContents, inDept, inEtc, inFilename, inFilesize, inFileurl, inHit, inNalja, inName, inTime, inTitle";
public Page<MinInfoBoard680Dto> findAll(@NotNull final MinInfoBoard680Dto dto, @NotNull final Pageable pageable) { public Page<MinInfoBoard680Dto> findAll(@NotNull final MinInfoBoard680Dto dto, @NotNull final Pageable pageable) {

@ -6,6 +6,8 @@ import com.xit.biz.ctgy.dto.JudgeListDto;
import com.xit.biz.ctgy.dto.JudgeTargetDto; import com.xit.biz.ctgy.dto.JudgeTargetDto;
import com.xit.biz.ctgy.dto.MinSimsaUser680ScDto; import com.xit.biz.ctgy.dto.MinSimsaUser680ScDto;
import com.xit.core.config.database.BaseMpowerDaoSupport; 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.oauth2.utils.HeaderUtil;
import com.xit.core.support.sql.parser.QueryGenerator; import com.xit.core.support.sql.parser.QueryGenerator;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -22,6 +24,10 @@ public class ResidentAndDisabledDao extends BaseMpowerDaoSupport {
private static final String NAME_SPACE = "residentAndDisabled"; private static final String NAME_SPACE = "residentAndDisabled";
public ResidentAndDisabledDao(SlaveDatabaseProperties databaseProperties) {
super(databaseProperties);
}
public Page<GnRecallScDto> findJudgeDatas(@NotNull final String scDatagb, @NotNull final Pageable pageable) { public Page<GnRecallScDto> findJudgeDatas(@NotNull final String scDatagb, @NotNull final Pageable pageable) {
final String cntSql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectJudgeDataListCnt") final String cntSql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectJudgeDataListCnt")
.setParameter("scDatagb", scDatagb) .setParameter("scDatagb", scDatagb)

@ -3,6 +3,8 @@ package com.xit.biz.ctgy.v2.repository;
import com.xit.biz.ctgy.dto.MinUserinfoDto; import com.xit.biz.ctgy.dto.MinUserinfoDto;
import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.biz.ctgy.entity.MinUserinfo;
import com.xit.core.config.database.BaseMpowerDaoSupport; 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 com.xit.core.support.sql.parser.QueryGenerator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -18,6 +20,10 @@ import java.util.Optional;
public class UserDao extends BaseMpowerDaoSupport { public class UserDao extends BaseMpowerDaoSupport {
private static final String NAME_SPACE = "user"; private static final String NAME_SPACE = "user";
public UserDao(MasterDatabaseProperties databaseProperties) {
super(databaseProperties);
}
public Optional<MinUserinfoDto> findByUserid(@NotNull final String userid){ public Optional<MinUserinfoDto> findByUserid(@NotNull final String userid){
final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectUserInfo") final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectUserInfo")
.setParameter("userid", userid) .setParameter("userid", userid)

@ -2,8 +2,15 @@ package com.xit.core.config.database;
import com.plf.client.Client; import com.plf.client.Client;
import com.xit.biz.cmm.dto.ComboCodeDto; import com.xit.biz.cmm.dto.ComboCodeDto;
import com.xit.biz.ctgy.CtgyConstants;
import com.xit.core.constant.ErrorCode; import com.xit.core.constant.ErrorCode;
import com.xit.core.exception.MpowerException; 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -20,19 +27,13 @@ import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
@Slf4j @Slf4j
@RequiredArgsConstructor
public abstract class BaseMpowerDaoSupport { public abstract class BaseMpowerDaoSupport {
@Value("${mpower.dbName}") private final IDatabaseProperties databaseProperties;
private String dbName;
@Value("${mpower.hostIp}") @Setter
private String hostIp; @Getter
private String dbTarget = "master";
@Value("${mpower.port}")
private int port;
public void setDbName(String dbName){
this.dbName = dbName;
}
public <T> T selectOne(Class<T> type, String sql, String fields){ public <T> T selectOne(Class<T> type, String sql, String fields){
Objects.requireNonNull(type, "Class cannot be null"); Objects.requireNonNull(type, "Class cannot be null");
@ -342,7 +343,8 @@ public abstract class BaseMpowerDaoSupport {
return String.format( return String.format(
"%s%s%s%s%s%s%s", "%s%s%s%s%s%s%s",
"<?xml version='1.0' encoding='euc-kr'?>\n<QUERYS DBNAME='", "<?xml version='1.0' encoding='euc-kr'?>\n<QUERYS DBNAME='",
dbName, //CtgyConstants.DB_MASTER.equals(dbTarget)? masterDatabaseProperties.getDbName() : slaveDatabaseProperties.getDbName(),
databaseProperties.getDbName(),
"' DEBUG='true'>\n<QUERY TYPE='", "' DEBUG='true'>\n<QUERY TYPE='",
syntax, syntax,
"' BATCH='false'>\n<SQL><![CDATA[\n", "' BATCH='false'>\n<SQL><![CDATA[\n",
@ -351,7 +353,11 @@ public abstract class BaseMpowerDaoSupport {
} }
private Client getConnection(){ private Client getConnection(){
Client mpowerClient = new Client(hostIp, port); // Client mpowerClient =
// CtgyConstants.DB_MASTER.equals(dbTarget)?
// new Client(masterDatabaseProperties.getHostIp(), masterDatabaseProperties.getPort()) :
// new Client(slaveDatabaseProperties.getHostIp(), slaveDatabaseProperties.getPort());
Client mpowerClient = new Client(databaseProperties.getHostIp(), databaseProperties.getPort());
mpowerClient.setCryptEnable(false); mpowerClient.setCryptEnable(false);
try { try {
mpowerClient.getConnection("MPowerXmlToQuery.xmlQuery1"); mpowerClient.getConnection("MPowerXmlToQuery.xmlQuery1");

@ -2,6 +2,7 @@ package com.xit.core.oauth2.api.dao;
import com.xit.core.config.database.BaseMpowerDaoSupport; import com.xit.core.config.database.BaseMpowerDaoSupport;
import com.xit.core.oauth2.api.entity.RefreshToken; import com.xit.core.oauth2.api.entity.RefreshToken;
import com.xit.core.oauth2.config.properties.MasterDatabaseProperties;
import com.xit.core.support.sql.parser.QueryGenerator; import com.xit.core.support.sql.parser.QueryGenerator;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -9,6 +10,11 @@ import java.util.Optional;
@Repository @Repository
public class RefreshTokenDao extends BaseMpowerDaoSupport { public class RefreshTokenDao extends BaseMpowerDaoSupport {
public RefreshTokenDao(MasterDatabaseProperties databaseProperties) {
super(databaseProperties);
}
public RefreshToken findByKey(String key){ public RefreshToken findByKey(String key){
String sql = QueryGenerator.createNamedQuery("refreshToken", "selectRefreshToken") String sql = QueryGenerator.createNamedQuery("refreshToken", "selectRefreshToken")
.setParameter("key", key) .setParameter("key", key)

@ -0,0 +1,7 @@
package com.xit.core.oauth2.config.properties;
public interface IDatabaseProperties {
String getHostIp();
String getDbName();
int getPort();
}

@ -0,0 +1,14 @@
package com.xit.core.oauth2.config.properties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Getter
@Setter
@ConfigurationProperties(prefix = "mpower.master")
public class MasterDatabaseProperties implements IDatabaseProperties{
private String hostIp;
private int port;
private String dbName;
}

@ -0,0 +1,14 @@
package com.xit.core.oauth2.config.properties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Getter
@Setter
@ConfigurationProperties(prefix = "mpower.slave")
public class SlaveDatabaseProperties implements IDatabaseProperties{
private String hostIp;
private int port;
private String dbName;
}

@ -30,6 +30,12 @@ file:
size: 10000000 size: 10000000
mpower: mpower:
hostIp: 127.0.0.1 master:
port: 9999 hostIp: 127.0.0.1
dbName: gn port: 9999
dbName: gn
slave:
hostIp: 127.0.0.1
port: 9999
dbName: gn_seconddb

Loading…
Cancel
Save