| Tag Name | config:configuration Attribute | Description | Required | Default Value | Child Tag |
| ROOT | address | ||||
| address | 공간 상의 유일성을 보장하기 위해 IP 주소나 네트웍 카드의 MAC 주소를 값으로 지정한다. IP 주소일 경우 필드간의 구분은 “.”로 하고, MAC 주소일 경우는 “:”로 한다. 지정하지 않으면 UUIdGenerationService는 내부에서 MAC 주소를 랜덤하게 생성한다. | False | 랜덤 생성 |
<bean name="UUIdGenerationService" class="anyframe.core.idgen.impl.UUIdGenerationService">
<config:configuration>
<address>00:00:F0:79:19:5B</address>
</config:configuration>
</bean>
/**
* UUIdGeneration을 이용한 testcase
*/
public void testUUIdGeneration() throws Exception {
IIdGenerationService id = (IIdGenerationService) context
.getBean("UUIdGenerationService");
// 신규 ID를 받아온다.
String newId=id.getNextStringId();
if(newId==null)
throw new Exception("fail to get UUIdgeneration");
}
| dataSource | SequenceIdGenerationService를 사용하는 경우 필요하다. Database 연결을 위한 DataSourceService를 지정한다. |
| config:configuration | query | ||||
| config:configuration | big-decimals | long 타입의 ID 대신 BigDecimal 타입의 ID를 사용하고자 할 때 정의한다. | false | ||
| query | SEQUENCE SQL을 value로써 지정한다.(Database에 의존적이다.) |
<bean name="SequenceIdGenerationService"
class="anyframe.core.idgen.impl.SequenceIdGenerationService"
destroy-method="destroy">
<property name="dataSource">
<ref bean="common_datasource"/>
</property>
<config:configuration big-decimals="true">
<query>SELECT NEXT VALUE FOR idsequence FROM DUAL</query>
</config:configuration>
</bean>
/**
* SequenceIdGeneration 이용한 testcase
*/
public void testSequenceIdGeneration() throws Exception {
IIdGenerationService id = (IIdGenerationService) context
.getBean("SequenceIdGenerationService");
// 다음 스트링ID를 받아온다.
String newId = id.getNextStringId();
// 다음 스트링 ID는 초기값 0을 주었으므로 0이 될 것이다.
// cf)CREATE SEQUENCE idsequence START WITH 0
if (!newId.equals("0"))
throw new Exception("fail to get SequenceIdgeneration");
}
| dataSource | TableIdGeneration Service를 사용하는 경우 필요하다. Database 연결을 위한 DataSourceService를 지정한다. | ||
| strategy | Id Generation Strategy를 지정한다. 기본적으로 prefix, 신규 Id, fillChar를 조합한 Id를 전달하는 MixPrefix를 사용한다. |
| config:configuration | block-size | ID를 발급할 때마다 매번 데이터베이스에 접속한다면 시스템 성능 저하를 가져오므로, 한번에 TableIdGenerationService 내에서 발급 받아올 ID의 개수를 정할 수 있다. | |||
| config:configuration | table | 현재까지 발급한 ID를 저장하기 위한 테이블 이름. | |||
| config:configuration | key-table | 어떤 것에 발급하는 ID인지를 저장하기 위한 키 이름. 예를 들어, Order와 Product, 두 가지에 ID를 발급할 상황이라면 하나는 key-table 속성값으로 “order”, 또다른 하나는 "product"라고 지정할 수 있다. | |||
| config:configuration | big-decimals | Long 타입의 ID 대신 BigDecimal 타입의 ID를 사용하고자 할 때 쓴다. |
<bean name="TableIdGenerationService"
class="anyframe.core.idgen.impl.TableIdGenerationService"
destroy-method="destroy">
<property name="dataSource" ref="common_datasource"/>
<property name="strategy" ref="mixPrefix"/>
<config:configuration block-size="1" table="ids" key-table="test"/>
</bean>
/**
* TableIdGeneration 이용한 testcase
*/
public void testTableIdGeneration() throws Exception {
IIdGenerationService id = (IIdGenerationService) context
.getBean("TableIdGenerationService");
// 다음 스트링 ID를 받아온다.
String newId = id.getNextStringId();
//다음 스트링 ID는 초기값 0을
//주었으므로 "TEST-****0"이 될 것이다.
// cf)INSERT INTO ids VALUES('test','0')
// 0앞의 prefix는 configuration의 mixPrefix에서 설정할 수 있다.
if (!newId.equals("TEST-****0"))
throw new Exception("fail to get TableIdgeneration");
}
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:testDS"/>
<property name="jndiTemplate" ref="jnditemplate"/>
</bean>
<bean id="jnditemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">
org.jnp.interfaces.NamingContextFactory
</prop>
<prop key="java.naming.provider.url">
jnp:localhost:1099
</prop>
</props>
</property>
</bean>
<bean id="idgenDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@server.ip:1521:orcl"/>
<property name="username" value="user"/>
<property name="password" value="password"/>
<property name="defaultAutoCommit" value="false"/>
</bean>
<tx:advice id="noTxAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="*" rollback-for="Exception" propagation="NOT_SUPPORTED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="executionMethods" expression="execution(* anyframe.core.idgen..impl.TableIdGenerationService.*(..))"/> <aop:advisor advice-ref="noTxAdvice" pointcut-ref="executionMethods"/> </aop:config>
<bean id="idGenProduct" class="anyframe.core.idgen.impl.TableIdGenerationService"
destroy-method="destroy">
<property name="dataSource" ref="idgenDataSource" />
<property name="strategy" ref="mixPrefixProduct" />
<config:configuration block-size="10" table="ids" key-table="PRODUCT" />
</bean>
<bean name="Ids-TestWithGenerationStrategy"
class="anyframe.core.idgen.impl.TableIdGenerationService"
destroy-method="destroy">
<property name="dataSource" ref="util_datasource"/>
<property name="strategy" ref="mixPrefix"/>
<config:configuration block-size="1" table="idstest" key-table="test"/>
</bean>
<bean name="mixPrefix" class="anyframe.core.idgen.impl.strategy.MixPrefix">
<property name="prefix" value="TEST-"/>
<property name="cipers" value="5"/>
<property name="fillChar" value="*"/>
</bean>
id = idGenerator.getNextStringId("mixPrefix");
MixPrefix strategy = new MixPrefix("SMPL-", 5, '#');
id = idGenerator.getNextStringId(strategy);
<bean name="mixPrefix" class="anyframe.core.idgen.impl.strategy.MixPrefix">
<property name="prefix" value="TEST-"/>
<property name="cipers" value="5"/>
<property name="fillChar" value="*"/>
</bean>
public class MixPrefix implements IdGenerationStrategy
{
public String makeId(String originalId) {
return prefix + StringUtil.fillString(originalId, fillChar, cipers);
}
}