Jelajahi Sumber

TB_SEQUENCE 테이블 추가. 시퀀스 로직 추가

gagamel 5 tahun lalu
induk
melakukan
800863c8f5

+ 19 - 0
style24.admin/src/main/java/com/style24/admin/biz/dao/TsaCommonDao.java

@@ -2,6 +2,7 @@ package com.style24.admin.biz.dao;
 
 import com.style24.core.support.annotation.ShopDs;
 import com.style24.persistence.domain.SearchData;
+import com.style24.persistence.domain.Sequence;
 
 /**
  * 공용 Dao
@@ -12,6 +13,24 @@ import com.style24.persistence.domain.SearchData;
 @ShopDs
 public interface TsaCommonDao {
 
+	/**
+	 * 시퀀스 조회
+	 * @param value - 시퀀스명
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 1. 4
+	 */
+	Integer getNextSequence(String value);
+
+	/**
+	 * 시퀀스 생성
+	 * @param sequence - 시퀀스정보
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 1. 4
+	 */
+	void createNextSequence(Sequence sequence);
+
 	/**
 	 * 엑셀조회를 위한 SEARCH 테이블 삭제
 	 *

+ 23 - 1
style24.admin/src/main/java/com/style24/admin/biz/service/TsaCommonService.java

@@ -2,9 +2,13 @@ package com.style24.admin.biz.service;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.style24.admin.biz.dao.TsaCommonDao;
 import com.style24.persistence.domain.SearchData;
+import com.style24.persistence.domain.Sequence;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -21,6 +25,25 @@ public class TsaCommonService {
 	@Autowired
 	private TsaCommonDao commonDao;
 
+	/**
+	 * 시퀀스 조회(중첩트랜잭션으로 처리. 부모 트랜잭션의 커밋과 롤백에는 영향을 받지만 자신의 커밋과 롤백은 부모 트랜잭션에게 영향을 주지 않는다.)
+	 * @param sequenceNm - 시퀀스명
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 1. 4
+	 */
+	@Transactional(value = "shopTxnManager", isolation = Isolation.SERIALIZABLE, propagation = Propagation.NESTED)
+	public Integer getNextSequence(String sequenceNm) {
+		Integer nextVal = commonDao.getNextSequence(sequenceNm);
+
+		Sequence sequence = new Sequence();
+		sequence.setSequenceNm(sequenceNm);
+		sequence.setNextVal(nextVal);
+		commonDao.createNextSequence(sequence);
+
+		return sequence.getNextVal();
+	}
+
 	/**
 	 * 엑셀조회를 위한 SEARCH 테이블 삭제
 	 *
@@ -80,5 +103,4 @@ public class TsaCommonService {
 		return commonDao.getErpSyncYn();
 	}
 
-
 }

+ 20 - 0
style24.admin/src/main/java/com/style24/persistence/domain/Sequence.java

@@ -0,0 +1,20 @@
+package com.style24.persistence.domain;
+
+import java.io.Serializable;
+
+import lombok.Data;
+
+/**
+ * SEQUENCE Domain
+ * 
+ * @author gagamel
+ * @since 2021. 1. 4
+ */
+@SuppressWarnings("serial")
+@Data
+public class Sequence implements Serializable {
+
+	private String sequenceNm;	// 시퀀스명
+	private Integer nextVal;	// 다음값
+
+}

+ 17 - 0
style24.admin/src/main/java/com/style24/persistence/mybatis/shop/TsaCommon.xml

@@ -2,6 +2,22 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.style24.admin.biz.dao.TsaCommonDao">
 
+	<!-- 시퀀스 값 조회 -->
+	<select id="getNextSequence" parameterType="String" resultType="Integer">
+		/* TsaCommon.getNextSequence */
+		SELECT IFNULL((SELECT NEXT_VAL
+		               FROM   TB_SEQUENCE
+		               WHERE  SEQUENCE_NM = #{sequenceNm}
+		              ),0) + 1 AS NEXT_VAL
+	</select>
+
+	<!-- 시퀀스 생성 -->
+	<insert id="createNextSequence" parameterType="Sequence">
+		/* TsaCommon.createNextSequence */
+		INSERT INTO TB_SEQUENCE (SEQUENCE_NM, NEXT_VAL) VALUES (#{sequenceNm}, #{nextVal})
+		ON DUPLICATE KEY UPDATE NEXT_VAL = #{nextVal}
+	</insert>
+	
 	<!-- 엑셀조회를 위한 SEARCH 테이블 삭제  -->
 	<delete id="deleteExceluploadSearCh" parameterType="SearchData">
 		/* TsaCommon.deleteExceluploadSearCh */
@@ -71,4 +87,5 @@
 		WHERE CD_GB = 'G077'
 		AND CD = 'ERPSYNCYN'
 	</select>
+	
 </mapper>