[eGovFrame] Table Id Generation Service
ÀüÀÚÁ¤ºÎ ÇÁ·¹ÀÓ¿öÅ© Wiki ¿¡¼´Â ½Ã½ºÅÛ °³¹ß½Ã¿¡ »ç¿ëÇÒ ¼ö ÀÖ´Â À¯ÀÏÇÑ ID¸¦ »ý¼ºÇÒ ¼ö ÀÖµµ·Ï Á¦°øÇÏ´Â ¼ºñ½º¶ó°í ¼³¸íÇÏ°í ÀÖ´Ù. ¾÷·ÎµåµÈ ÆÄÀÏÀÇ À¯ÀÏÇÑ À̸§ ¶Ç´Â Å×À̺íÀÇ Primary Key ¿ªÇÒÀ» ÇÒ ID¸¦ »ý¼ºÇÏ´Â ¿ëµµ·Î »ç¿ëÇÒ ¼ö ÀÖ´Ù. ID¸¦ »ý¼ºÇÏ´Â ¹æ¹ýÀº 3°¡Áö°¡ ÀÖ´Ù.
- UUID Generation Service
- Sequence Id Generation Service
- Table Id Generation Service
Table Id Generation Service ¿¡ ´ëÇؼ ¾Ë¾Æº¸ÀÚ. Table Id Generation Service ´Â »õ·Î¿î ¾ÆÀ̵𸦠¾ò±â À§Çؼ º°µµÀÇ Å×À̺íÀ» »ý¼ºÇÏ¿© Å°°ª°ú Å°°ª¿¡ ÇØ´çÇÏ´Â ¾ÆÀ̵ð°ªÀ» ÀÔ·ÂÇÏ¿© °ü¸®Çؼ Á¦°øÇÏ´Â ¼ºñ½º·Î Basic Service ¿Í prefix ¿Í ä¿ï ¹®ÀÚ¿À» ÁöÁ¤Çؼ String ID ¸¦ »ý¼ºÇÏ´Â Strategy Base Service ¸¦ Á¦°øÇÑ´Ù.
Basic Service
1. ¸ÕÀú »ç¿ëÇÏ°íÀÚ ÇÏ´Â ½Ã½ºÅÛÀÇ DB¿¡ ´ÙÀ½Äڵ带 ½ÇÇàÇؼ Å×À̺íÀ» »ý¼ºÇÏÀÚ
CREATE TABLE ids ( table_name varchar(16) NOT NULL, next_id DECIMAL(30) NOT NULL, PRIMARY KEY (table_name)); INSERT INTO ids VALUES('id','0');
- ids´Â ID¸¦ °ü¸®ÇÏ°íÀÚ ÇÏ´Â Å×ÀÌºí ¸íÀÌ´Ù.
- table_name ¿¡´Â ID°ªÀ» »ç¿ëÇÏ°íÀÚ ÇÏ´Â Å×ÀÌºíº°·Î °ªÀ» ÁöÁ¤ÇÑ´Ù.
- next_id ´Â ¸¶Áö¸· ID°ªÀÌ´Ù. ÀÌ °ªÀÌ 1¾¿ Áõ°¡ÇÏ°Ô µÈ´Ù.
2. ÇÁ·ÎÁ§Æ®ÀÇ /src/main/resources/egoframework/spring/com/context-idgen.xml ¿¡ ´ÙÀ½ Äڵ带 ÀÔ·ÂÇÑ´Ù.
<bean name="basicService" class="egovframework.rte.fdl.idgnr.impl.EgovTableIdGnrService" destroy-method="destroy"> <property name="dataSource" ref="dataSource"/> <property name="blockSize" value="10"/> <property name="table" value="ids"/> <property name="tableName" value="id"/> </bean>
- dataSource ´Â /src/main/resources/egoframework/spring/com/context-datasource.xml ¿¡ Á¤ÀÇÇÑ ºóÀÇ id °ªÀÌ´Ù.
- blockSize ´Â Id Generation ³»ºÎÀûÀ¸·Î »ç¿ëÇÏ´Â Á¤º¸·Î ID ¿äû½Ã ÁöÁ¤µÈ Ƚ¼ö°¡ µÉ °æ¿ì¸¸ DB¿¡ Á¢±ÙÇؼ ¾÷µ¥ÀÌÆ® ÇÑ´Ù.
- table Àº ID°ªÀ» °ü¸®ÇÏ´Â Å×ÀÌºí ¸íÀÌ´Ù.
- tableName Àº table ¿¡¼ ÁöÁ¤ÇÑ Å×À̺íÀÌ °ü¸®ÇÏ´Â °¢ Å×À̺íÀÇ °íÀ¯ °ªÀÌ´Ù.
Áï, ids ¶ó°í ÇÏ´Â Å×ÀÌºí¿¡ table_name ÇʵåÀÇ °ªÀÌ id ÀÎ ÇàÀÇ Çʵå next_id ÀÇ °ªÀ» °¡Á®¿Â´Ù.
3. ¼Ò½º¿¡¼ »ç¿ë
@Resource(name="basicService") private EgovIdGnrService basicService; @Test public void testBasicService() throws Exception { //int assertNotNull(basicService.getNextIntegerId()); //short assertNotNull(basicService.getNextShortId()); //byte assertNotNull(basicService.getNextByteId()); //long assertNotNull(basicService.getNextLongId()); //BigDecimal assertNotNull(basicService.getNextBigDecimalId()); //String assertNotNull(basicService.getNextStringId()); }
Strategy Base Service
¾ÆÀ̵ð »ý¼ºÀ» À§ÇÑ ·êÀ» µî·ÏÇÏ°í ·ê¿¡ ¸Â´Â ¾ÆÀ̵𸦠»ý¼ºÇÒ ¼ö ÀÖµµ·Ï Áö¿øÇÏ´Â ¼ºñ½ºÀÌ´Ù. Basic Service ¿¡ Ãß°¡·Î Strategy Á¤º¸¸¦ Ãß°¡ ¼³Á¤Çؼ »ç¿ëÀÌ °¡´ÉÇÏ´Ù. ´Ü, ÀÌ ¼ºñ½º´Â String ŸÀÔÀÇ ID¸¸ °¡´ÉÇÏ´Ù.
1. /src/main/resources/egoframework/spring/com/context-idgen.xml ¿¡ Ãß°¡·Î ´ÙÀ½ Äڵ带 »ðÀÔÇÑ´Ù.
<bean name="strategy" class="egovframework.rte.fdl.idgnr.impl.strategy.EgovIdGnrStrategyImpl"> <property name="prefix" value="TEST-"/> <property name="cipers" value="5"/> <property name="fillChar" value="*"/> </bean>
À§ Äڵ尡 Ãß°¡µÈ ¼Ò½º´Â ´ÙÀ½°ú °°´Ù.
<bean name="Ids-TestWithGenerationStrategy" class="egovframework.rte.fdl.idgnr.impl.EgovTableIdGnrService" destroy-method="destroy"> <property name="dataSource" ref="dataSource"/> <property name="strategy" ref="strategy"/> <property name="blockSize" value="1"/> <property name="table" value="idttest"/> <property name="tableName" value="test"/> </bean> <bean name="strategy" class="egovframework.rte.fdl.idgnr.impl.strategy.EgovIdGnrStrategyImpl"> <property name="prefix" value="TEST-"/> <property name="cipers" value="5"/> <property name="fillChar" value="*"/> </bean>
- strategy ´Â ¾Æ·¡¿¡ Á¤ÀÇµÈ MixPrefix ÀÇ ºó À̸§ÀÌ´Ù.
- prefix ´Â ID ¾Õ¿¡ °íÁ¤ÀûÀ¸·Î ºÙÀÌ°íÀÚ ÇÏ´Â ¹®ÀÚ¿ÀÌ´Ù.
- cipers ´Â prefix¸¦ Á¦¿ÜÇÑ IDÀÇ ±æÀÌÀÌ´Ù.
- fillChar Àº 0À» ´ë½ÅÇؼ Ç¥ÇöµÉ ¹®ÀÚÀÌ´Ù.
ID °ªÀÌ 1 ÀÎ °æ¿ì À§ÀÇ ¼³Á¤ÀÌ Àû¿ëµÇ¸é 'TEST-****1' ÀÌ µÈ´Ù.
Ãâó: https://roadrunner.tistory.com/410 [»îÀÇ Á¶°¢µé]