'iBATIS'에 해당되는 글 1건

  1. 2010.10.20 iBatis - Binary Conditional Elements

iBatis - Binary Conditional Elements

ITWeb/개발일반 2010. 10. 20. 13:48
원본링크 : http://ibatis.apache.org/docs/dotnet/datamapper/ch03s09.html

3.9.1. Binary Conditional Elements

Binary conditional elements compare a property value to a static value or another property value. If the result is true, the body content is included in the SQL query.

3.9.1.1. Binary Conditional Attributes:

prepend – the overridable SQL part that will be prepended to the statement (optional)
property – the property to be compared (required)
compareProperty – the other property to be compared (required or compareValue)
compareValue – the value to be compared (required or compareProperty)

Table 3.7. Binary conditional attributes

Element Description
<isEqual> Checks the equality of a property and a value, or another property. Example Usage:
<isEqual prepend="AND" 
             property="status" 
             compareValue="Y">
MARRIED = ‘TRUE'
</isEqual>               
<isNotEqual> Checks the inequality of a property and a value, or another property. Example Usage:
<isNotEqual prepend="AND" 
             property="status" 
             compareValue="N">
MARRIED = ‘FALSE'
</isNotEqual>   
<isGreaterThan> Checks if a property is greater than a value or another property. Example Usage:
<isGreaterThan prepend="AND" 
             property="age" 
             compareValue="18">
ADOLESCENT = ‘FALSE'
</isGreaterThan>   
<isGreaterEqual> Checks if a property is greater than or equal to a value or another property. Example Usage:
<isGreaterEqual prepend="AND" 
             property="shoeSize" 
             compareValue="12">
BIGFOOT = ‘TRUE'
</isGreaterEqual>
<isLessEqual> Checks if a property is less than or equal to a value or another property. Example Usage:
<isLessEqual prepend="AND" 
             property="age" 
             compareValue="18">
ADOLESCENT = ‘TRUE'
</isLessEqual>

3.9.2. Unary Conditional Elements

Unary conditional elements check the state of a property for a specific condition.

3.9.2.1. Unary Conditional Attributes:

prepend – the overridable SQL part that will be prepended to the statement (optional)
property – the property to be checked (required)

Table 3.8. Unary conditional attributes

Element Description
<isPropertyAvailable> Checks if a property is available (i.e is a property of the parameter object). Example Usage:
<isPropertyAvailable property="id" >
  ACCOUNT_ID=#id# 
</isPropertyAvailable>
<isNotPropertyAvailable> Checks if a property is unavailable (i.e not a property of the parameter object). Example Usage:
<isNotPropertyAvailable property="age" >
  STATUS='New' 
</isNotEmpty>
<isNull> Checks if a property is null. Example Usage:
<isNull prepend="AND" property="order.id" >
  ACCOUNT.ACCOUNT_ID = ORDER.ACCOUNT_ID(+) 
</isNotEmpty>
<isNotNull> Checks if a property is not null. Example Usage:
<isNotNull prepend="AND" property="order.id" >
  ORDER.ORDER_ID = #order.id#
</isNotEmpty>
<isEmpty> Checks to see if the value of a Collection, String property is null or empty ("" or size() < 1). Example Usage:
<isEmpty property="firstName" >
  LIMIT 0, 20
</isNotEmpty>
<isNotEmpty> Checks to see if the value of a Collection, String property is not null and not empty ("" or size() < 1). Example Usage:
<isNotEmpty prepend="AND" property="firstName" >
  FIRST_NAME LIKE '%$FirstName$%'
</isNotEmpty>

3.9.3. Parameter Present Elements

These elements check for parameter object existence.

3.9.3.1. Parameter Present Attributes:

prepend – the overridable SQL part that will be prepended to the statement (optional)

Table 3.9. Testing to see if a parameter is present

Element Description
<isParameterPresent> Checks to see if the parameter object is present (not null).
<isParameterPresent prepend="AND">
  EMPLOYEE_TYPE = #empType#
</isParameterPresent>
<isNotParameterPresent> Checks to see if the parameter object is not present (null). Example Usage:
<isNotParameterPresent prepend="AND">
  EMPLOYEE_TYPE = ‘DEFAULT'
</isNotParameterPresent>


3.9.4. Iterate Element

This tag will iterate over a collection and repeat the body content for each item in a List

3.9.4.1. Iterate Attributes:

prepend – the overridable SQL part that will be prepended to the statement (optional)
property – a property of type IList that is to be iterated over (required)
open – the string with which to open the entire block of iterations, useful for brackets (optional)
close – the string with which to close the entire block of iterations, useful for brackets (optional)
conjunction – the string to be applied in between each iteration, useful for AND and OR (optional)

Table 3.10. Creating a list of conditional clauses

Element Description
<iterate> Iterates over a property that is of type IList Example Usage:
<iterate prepend="AND" property="UserNameList"
  open="(" close=")" conjunction="OR">
  username=#UserNameList[]#
</iterate>
Note: It is very important to include the square brackets[] at the end of the List property name when using the Iterate element. These brackets distinguish this object as an List to keep the parser from simply outputting the List as a string.


: