Hi Everyone,

I'm not sure if this is useful for you or not.  But, I created an XSL file to 
transform iBatis configurations into beans and SQL fragments into full SQL 
output.

I have attached an example.


It is helpful to open the xml file in your browser, as the XSL file will 
automatically create a "full" SQL output for you.  For example, the fragment 
below, uses a fragment called "ledgerTypeSelect"...

  <select id="getLedger" resultMap="LedgerTypes"
          parameterClass="java.util.Map">
    <include refid="ledgerTypeSelect"/>

     WHERE ledger_id = #ledgerID#;
  </select>

  <sql id="ledgerTypeSelect">
    SELECT ledger_id,
           ledger_name,
           ledger_description,
           ledger_number
      FROM ledger_types
  </sql>

If opening the ledger.xml in the browser, it will translate the "getLedger" 
select statement into a complete select statement for you, by automatically 
including the refid element into the output.  And, it even includes one line 
comments to let you know which fragment was included.  Pretty cool.  That way 
it is easy to copy and paste SQL into tora, toad, or some other SQL tool, etc, 
for testing.

So, the output is like so.  As you can see, it tells you the beginning of the 
included fragment.
    -- BEGIN getLedger
    
      -- BEGIN ledgerTypeSelect
    SELECT ledger_id,
           ledger_name,
           ledger_description,
           ledger_number
      FROM ledger_types
  
      -- END ledgerTypeSelect
     WHERE ledger_id = #ledgerID#;
  
    -- END getLedger

Trenton D. Adams
Systems Analyst/Web Software Engineer
Navy Penguins at your service!
Athabasca University
(780) 675-6195
:wq!

__ 
    This communication is intended for the use of the recipient to whom it
    is addressed, and may contain confidential, personal, and or privileged
    information. Please contact us immediately if you are not the intended
    recipient of this communication, and do not copy, distribute, or take
    action relying on it. Any communications received in error, or
    subsequent reply, should be deleted or destroyed.
---
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="map.xsl"?>
<!DOCTYPE sqlMap
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd";>

<sqlMap namespace="accounting">

  <!-- Use type aliases to avoid typing the full classname every time. -->
  <typeAlias alias="LedgerType" type="ca.trentonadams.cvacct.rmi.ledger.datatypes.LedgerType"/>

  <!-- Result maps describe the mapping between the columns returned
       from a query, and the class properties.  A result map isn't
       necessary if the columns (or aliases) match to the properties 
       exactly. -->

  <resultMap id="LedgerTypes" class="LedgerType">
    <result property="ledgerID" column="ledger_id"
            javaType="java.lang.Integer"/>
    <result property="ledgerName" column="ledger_name"
            javaType="java.lang.String"/>
    <result property="ledgerDescription" column="ledger_description"
            javaType="java.lang.String"/>
    <result property="ledgerNumber" column="ledger_number"
            javaType="java.lang.Integer"/>
  </resultMap>

  <insert id="insertLedgerType" parameterClass="java.util.Map">
    INSERT INTO ledger_types 
  </insert>

  <parameterMap id="ledgerMap" class="java.util.Map">
    <parameter property="ledgerID"/>
  </parameterMap>

<!--  <select id="getLedger" parameterMap="ledgerMap">
    SELECT ledger_id,
           entry_id,
           description,
           debit,
           credit,
           transaction_date
      FROM ledger
     WHERE ledger_id;
  </select>-->

  <sql id="ledgerTypeSelect">
    SELECT ledger_id,
           ledger_name,
           ledger_description,
           ledger_number
      FROM ledger_types
  </sql>

  <select id="getLedger" resultMap="LedgerTypes"
          parameterClass="java.util.Map">
    <include refid="ledgerTypeSelect"/>
     WHERE ledger_id = #ledgerID#;
  </select>

  <select id="selectLedgerTypes" resultMap="LedgerTypes">
    <include refid="ledgerTypeSelect"/>
    ORDER BY ledger_number, ledger_name;
  </select>

  <insert id="ledgerInsert" parameterClass="java.util.Map">
    INSERT
      INTO ledger (ledger_id, description, debit, credit)
    VALUES (#ledgerID#, #description#, #debit#, #credit#);
  </insert>
</sqlMap>

Attachment: map.xsl
Description: XML document

Reply via email to