Clean Code that Works.

시큐리티 ACL이 동작을 하면서 acl 관련 정보들을 insert한 후 이 데이터들에 대한 id 값들을 가져와야 하는데.
기본적으로 identity 하는 방식이 아래와 같이 사용하고 있다.

private String classIdentityQuery = "call identity()";
private String sidIdentityQuery = "call identity()";

하지만 내가 사용하고 있는 MYSQL에는 저런게 없기 때문에.. -ㅁ-.. 어디서 사용하는 거지.. postrege sql??
아무튼 저것들을 변경해 주어야 한다.

구글링 해서 http://forum.springsource.org/showthread.php?t=67461 이 스레드에서 해결책을 발견.

뭐 그냥 쿼리만 mysql로 변경해 주면 된다

그래서 바꾸면 아래와 같이 MYSQL에서 사용하는 방식으로 쿼리를 변경 해 주면 된다. ㅋ
http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/
여기도 참고 하면 괜찮은 URL(스레드에 있는 url이다)
<bean id="aclService" class="org.springframework.security.acls.jdbc.JdbcMutableAclService">
        <constructor-arg ref="dataSource"/>
        <constructor-arg ref="lookupStrategy"/>
        <constructor-arg ref="aclCache"/>
        <property name="classIdentityQuery" value="SELECT @@IDENTITY"/>
       <property name="sidIdentityQuery" value="SELECT @@IDENTITY"/>
</bean>

이제 거의 다 진행 되간다 ~_~

JdbcMutableAclService 클래스에 acl과 관련된 쿼리들이 다 담겨 있고, 이것들은 위와 같은 방식으로 각각 DB환경에 맞는 쿼리로 수정하여 사용하면 된다.

2010.08.27일에 추가
PostgreSQL에서는 다른 방법으로 identity를 확인한다.

You will have to set the classIdentityQuery and sidIdentityQuery properties of JdbcMutableAclService to the following values, respectively:

  • select currval(pg_get_serial_sequence('acl_class', 'id'))

  • select currval(pg_get_serial_sequence('acl_sid', 'id'))