ibatis inline parameter

프로그래밍/iBatis 2009. 12. 15. 12:16

ibatis 매뉴얼을 보던중 기존의 나의 생각과는 다른 점이 있었다.

Inline Parameter Maps

Although very descriptive, the above syntax for declaring parameterMaps is very verbose.  Inline parameter
maps are less verbose, more descriptive, and we strongly suggest that you use them instead of coding
explicit parameter maps
.  With inline parameter maps, you place the parameter definition inline with the
SQL.  By default, any Mapped Statement that has no explicit parameterMap specified will be parsed for
inline parameters.  The previous example (i.e. product), implemented with an inline parameter map, would
look like this:

위에서 굵게 표시된 부분인데...
parameterMap 을 정의해서 사용하기 보다는 inline parameter 를 사용하라는 충고다.
기존에는 일부러라도 parameterMap 을 정의해서 성능향상을 꾀하려고 했었지만 ibatis 에서는 그 반대로 충고하고 있다.
그렇지 않아도 관리하기 힘들었던 parameterMap 이었는데 오늘 이후로 inline parameter 를 사용하도록 해야겠다.

참고로 inline parameter 는 알다시피 아래와 같이 표시된다.

<insert id="insertPerson" parameterClass="examples.domain.Person">
	INSERT INTO
		PERSON (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
		PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M)
		VALUES (#id#, #firstName#, #lastName#,
		#birthDate#, #weightInKilograms#, #heightInMeters#)
</insert>


#id# 부분이 inline parameter 이며 아래와 같은 형식으로 작성할 수 있다.
jdbcType 에는 java.sql.Types 에 정의된 상수 이름이 기술된다.

#propertyName#  - OR -
#propertyName:jdbcType#  - OR -
#propertyName:jdbcType:nullValue# - OR -
#propertyName,javaType=?,jdbcType=?,mode=?,nullValue=?,handler=?,numericScale=?#

↓↓↓↓↓↓↓↓↓↓↓↓

#id# - OR -
#id:NUMERIC# - OR -
#id:NUMERIC:10# - OR -
#id,jdbcType=NUMERIC,nullValue=10#

: