<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<!-- Be sure to always use the appropriate header as above!  Note the 2.0 DTDs. -->

<sqlMap>

  <!-- A type alias can be used to declare a shorter name for a long fully qualified
       classname.  There can be any number of typeAlias elements.  -->

  <typeAlias alias="shortname2" type="com.long.class.path.Class2"/>

  <!-- A cacheModel stanza is used to configure a cache.  In this case a cache
       named accountCache will be created using least recently used semantics (LRU).
       The cache has been flagged as readOnly indicating that objects retrieved
       from the cache might be modified.  This cache will be flushed every
       24 hours and when one of the identified statements is executed.
       Finally, the LRU cache takes only one optional property, which is the
       size (in this case 100).  There can be any number of cacheModel
       stanzas. Of course, cache models are optional. -->

  <cacheModel id="accountCache" type="LRU" readOnly="true" >
    <flushInterval hours="24"/>
    <flushOnExecute statement="insertAccount"/>
    <flushOnExecute statement="updateAccount"/>
    <flushOnExecute statement="deleteAccount"/>
    <property name="cacheSize" value="100"/>
  </cacheModel>

  <!-- The resultMap stanza is used to map the result set to the result object.
       A result object could be many things, including JavaBean, a Map, a primitive
       type wrapper, or even an XML document. Result maps are referred to by their
       id attribute by mapped statements (see below).  The result map contains
       any number of result elements, each of which maps a single column to
       a property.  The property might be a JavaBean property, a map key, or
       an XML element.  In the case of a primitive type wrapper (e.g. Integer or
       String), there can be only one result, with any property name. -->

  <resultMap id="myResultMap" class="domain.MyClass">
    <result property="id" column="MY_ID" />
    <result property="name" column="MY_NAME" />
    <result property="city" column="MY_CITY" />
    <!--
    <result property="" column="" columnIndex="" jdbcType="" javaType="" nullValue="" select=""/>
    -->
  </resultMap>

  <!-- The parameterMap stanza maps a parameter object to the input parameters of a
       PreparedStatement (question marks "?").  A parameter object could be many things,
       including JavaBean, a Map, a primitive type wrapper, or even an XML document.
       Parameter maps are referred to by their id attribute by mapped statements
       (see below).  The parameter map contains any number of parameter elements,
       each of which maps a property to a single statement parameter.  The property
       might be a JavaBean property, a map key, or an XML element.  In the case of a
       primitive type wrapper (e.g. Integer or String), there can be only one result,
       with any property name.  In the case of a prepared statement, the parameter
       might be an output parameter, which are fully supported.  There can be any
       number of parameterMap stanzas.

       IMPORTANT: Using the parameterMap stanza is usually more verbose than necessary,
       and for that reason statements can use inline parameter maps (using #property#
       tokens) within the SQL statement itself.  This makes the SQL easier to read.
       See below for more.

       NOTE: Most of the attributes are OPTIONAL, but are included here for completeness. -->

  <parameterMap id="myParameterMap" class="domain.MyClass">
    <parameter property="id"   mode="IN" />
    <parameter property="name" mode="OUT" />
    <parameter property="city" mode="INOUT" />
    <!--
    <parameter property="" jdbcType="" javaType="" nullValue="" mode="IN" />
    -->
  </parameterMap>

  <!-- The remainder of this example document shows the various SQL statement
       stanzas that can be used to describe your mapped statements.  These statements
       can be complete SQL statements and can include aggregations, concatenations,
       sub-selects functions and anything else SQL can do.  They can also include
       inline parameters (e.g. #property#) and also dynamic elements for building
       different SQL statements based on the state of the parameter object.
       There can be any number of statement stanzas -->

  <!-- Notice the inline parameter maps in use by the insert statement below.
       Insert statements also have a special selectKey element in their structure
       that allows auto-generated keys to be easily retrieved. -->

  <insert id="myInsert" parameterMap="domain.MyClass">
    insert into MY_TABLE (MY_ID, MY_NAME, MY_CITY) values (#id#, #name#, #city#)
    <selectKey resultClass="int" keyProperty="id" >
      select @@IDENTITY;
    </selectKey>
  </insert>

  <update id="myUpdate" parameterClass="domain.MyClass">
    update MY_TABLE set MY_NAME = "name" where MY_ID = #id#
  </update>

  <delete id="myDelete" parameterClass="domain.MyClass">
    delete from MY_TABLE where MY_ID = #id#
  </delete>

  <select id="mySelect" parameterClass="int" resultMap="myResultMap" cacheModel="myCacheModel">
    select
      MY_ID,
      MY_NAME,
      MY_CITY
    from
      MY_TABLE
    where MY_ID = #id#
  </select>

  <!-- This procedure statement uses a parameter map that defines its output parameters
       that will be set on the parameter object after successful execution.  -->

  <procedure id="myProcedure" resultMap="myResultMap" parameterMap="myParamMap">
    {call myproc(?,?,?)}
  </procedure>

  <!-- The statement stanza is a catch-all that allows any kind of statement
       to be run.  -->

  <statement id="myStatement" >
     update MY_TABLE set MY_ID = 9999999 where MY_ID is null
  </statement>

</sqlMap>

