feat: keySequence 서비스 추가

p6spy log 출력 변경
      - connection ID 출력 추가 적용
      - sql 로그 포맷 적용
main
Jonguk. Lim 2 months ago
parent 0e3fd7c23b
commit d2acc24567

@ -2,64 +2,46 @@ package cokr.xit.ens.core.config.logging;
import java.util.Locale; import java.util.Locale;
import javax.annotation.PostConstruct;
import org.hibernate.engine.jdbc.internal.FormatStyle; import org.hibernate.engine.jdbc.internal.FormatStyle;
import com.p6spy.engine.logging.Category; import com.p6spy.engine.logging.Category;
import com.p6spy.engine.spy.P6SpyOptions;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy; import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class P6spySqlFormatConfiguration implements MessageFormattingStrategy { public class P6spySqlFormatConfiguration implements MessageFormattingStrategy {
private static final String NEW_LINE = "\n";
private static final String TAP = "\t";
private static final String CREATE = "create"; private static final String CREATE = "create";
private static final String ALTER = "alter"; private static final String ALTER = "alter";
private static final String DROP = "drop"; private static final String DROP = "drop";
private static final String COMMENT = "comment"; private static final String COMMENT = "comment";
@Override @PostConstruct
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) { public void setLogMessageFormat() {
if (sql.trim().isEmpty()) { P6SpyOptions.getActiveInstance().setLogMessageFormat(this.getClass().getName());
return formatByCommand(category);
} return formatBySql(sql, category) + getAdditionalMessages(elapsed);
}
private static String formatByCommand(String category) {
return NEW_LINE
+ "Execute Command : "
+ NEW_LINE
+ NEW_LINE
+ TAP
+ category
+ NEW_LINE
+ NEW_LINE
+ "----------------------------------------------------------------------------------------------------";
} }
private String formatBySql(String sql, String category) {
@Override
public String formatMessage(final int connectionId, final String now, final long elapsed, final String category, final String prepared, final String sql, final String url) {
// FIXME: JPA 미사용시 SQL format 적용
//return "connection " + connectionId + " | took " + elapsed + "ms | " + category + "\n" + sql;
// FIXME: JPA 사용시 SQL format 적용
if(isStatementDDL(sql, category)) { if(isStatementDDL(sql, category)) {
return NEW_LINE
+ "Execute DDL : " return "connection " + connectionId + " | took " + elapsed + "ms | " + category + "\n" + FormatStyle.DDL.getFormatter().format(sql);
+ NEW_LINE
+ FormatStyle.DDL
.getFormatter()
.format(sql);
} return NEW_LINE
+ "Execute DML : "
+ NEW_LINE
+ FormatStyle.BASIC
.getFormatter()
.format(sql);
} }
private String getAdditionalMessages(long elapsed) { return "connection " + connectionId + " | took " + elapsed + "ms | " + category + "\n" + FormatStyle.BASIC.getFormatter().format(sql);
return NEW_LINE
+ NEW_LINE
+ String.format("Execution Time: %s ms", elapsed)
+ NEW_LINE
+ "----------------------------------------------------------------------------------------------------";
} }
private boolean isStatementDDL(String sql, String category) { private boolean isStatementDDL(String sql, String category) {
return isStatement(category) && isDDL(sql.trim().toLowerCase(Locale.ROOT)); return isStatement(category) && isDDL(sql.trim().toLowerCase(Locale.ROOT));
} }
private boolean isStatement(String category) { private boolean isStatement(String category) {
return Category.STATEMENT.getName().equals(category); return Category.STATEMENT.getName().equals(category);
} }

@ -1,10 +1,14 @@
package cokr.xit.ens.modules.common.ctgy.sys.mng.mapper; package cokr.xit.ens.modules.common.ctgy.sys.mng.mapper;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
/** /**
* <pre> * <pre>
* description : * description :
* packageName : cokr.xit.ens.modules.common.ctgy.sys.mng.mapper * packageName : cokr.xit.ens.modules.common.ctgy.sys.mng.mapper
* fileName : IOrgMngMapper * fileName : IKeySequenceMapper
* author : limju * author : limju
* date : 2024 9 03 * date : 2024 9 03
* ====================================================================== * ======================================================================
@ -14,5 +18,9 @@ package cokr.xit.ens.modules.common.ctgy.sys.mng.mapper;
* *
* </pre> * </pre>
*/ */
public interface IOrgMngMapper { // FIXME: 카카오톡 신규 추가
@Mapper
public interface IKeySequenceMapper {
Long selectKeySequence(String seqName);
void saveKeySequence(Map<String, Object> map);
} }

@ -0,0 +1,36 @@
package cokr.xit.ens.modules.common.ctgy.sys.mng.service;
import java.util.HashMap;
import java.util.Map;
import javax.transaction.Transactional;
import org.springframework.stereotype.Service;
import cokr.xit.ens.modules.common.ctgy.sys.mng.mapper.IKeySequenceMapper;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class KeySequenceService {
private final IKeySequenceMapper mapper;
/**
* 퀀
* @param seqName 퀀
* @return Long
*/
@Transactional
public Long getKeySequence(String seqName) {
Long nextSeq = mapper.selectKeySequence(seqName);
if(nextSeq == null) {
nextSeq = 1L;
}
Map<String, Object> map = new HashMap<>();
map.put("seqName", seqName);
map.put("nextVal", nextSeq);
mapper.saveKeySequence(map);
return nextSeq;
}
}

@ -39,6 +39,7 @@ import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.entity.repository.Bil
import cokr.xit.ens.modules.common.ctgy.mblpage.domain.SendDetailMblPage; import cokr.xit.ens.modules.common.ctgy.mblpage.domain.SendDetailMblPage;
import cokr.xit.ens.modules.common.ctgy.mblpage.domain.repository.SendDetailMblPageRepository; import cokr.xit.ens.modules.common.ctgy.mblpage.domain.repository.SendDetailMblPageRepository;
import cokr.xit.ens.modules.common.ctgy.sys.mng.domain.OrgMng; import cokr.xit.ens.modules.common.ctgy.sys.mng.domain.OrgMng;
import cokr.xit.ens.modules.common.ctgy.sys.mng.service.KeySequenceService;
import cokr.xit.ens.modules.common.ctgy.sys.mng.service.OrgMngService; import cokr.xit.ens.modules.common.ctgy.sys.mng.service.OrgMngService;
import cokr.xit.ens.modules.common.ctgy.sys.mng.service.TmpltMngService; import cokr.xit.ens.modules.common.ctgy.sys.mng.service.TmpltMngService;
import cokr.xit.ens.modules.common.domain.SendMast; import cokr.xit.ens.modules.common.domain.SendMast;
@ -57,6 +58,7 @@ public class KkoTalkAcceptor implements EnsPhaseProcSupport<EnsResponseVO<?>, Kk
private final SendMastRepository sendMastRepository; private final SendMastRepository sendMastRepository;
private final IKkoTalkMapper kkoTalkMapper; private final IKkoTalkMapper kkoTalkMapper;
private final KeySequenceService keySequenceService;
private final SendDetailMblPageRepository sendDetailMblPageRepository; private final SendDetailMblPageRepository sendDetailMblPageRepository;
private final BillRepository billRepository; private final BillRepository billRepository;
private final OrgMngService orgMngService; private final OrgMngService orgMngService;
@ -235,7 +237,10 @@ public class KkoTalkAcceptor implements EnsPhaseProcSupport<EnsResponseVO<?>, Kk
); );
// kkotalk 발송상세 저장 // kkotalk 발송상세 저장
sendDetails.forEach(kkoTalkMapper::saveSndDtlKkoTalk); sendDetails.forEach(d -> {
d.setSendDetailId(keySequenceService.getKeySequence("SendDetailKkoTalk_id"));
kkoTalkMapper.saveSndDtlKkoTalk(d);
});
if (!sendDetailMblPages.isEmpty()) if (!sendDetailMblPages.isEmpty())

@ -0,0 +1,27 @@
<?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="cokr.xit.ens.modules.common.ctgy.sys.mng.mapper.IKeySequenceMapper">
<select id="selectKeySequence" parameterType="string" resultType="long">
/** iup-keyseq-mapper|selectKeySequence-key sequence 조회|julim */
SELECT next_val + 1
FROM ens_seq_generator
WHERE seq_name = #{seqName}
FOR UPDATE
</select>
<insert id="saveKeySequence" parameterType="map">
/** iup-keyseq-mapper|saveKeySequence-key sequence 저장|julim */
MERGE
INTO ens_seq_generator tgt
USING (SELECT #{seqName} AS seq_name, #{nextVal} AS next_val FROM dual) src
ON (tgt.seq_name = src.seq_name)
WHEN MATCHED THEN
UPDATE SET tgt.next_val = src.next_val
WHEN NOT MATCHED THEN
INSERT (seq_name, next_val)
VALUES (src.seq_name, src.next_val)
</insert>
</mapper>

@ -29,7 +29,7 @@
send_mast_id, send_mast_id,
regist_dt regist_dt
) VALUES ( ) VALUES (
#{sendDetailId}, select ens_seq_generator.nextval from dual,
#{title}, #{title},
#{link}, #{link},
#{hash}, #{hash},

Loading…
Cancel
Save