ipreparedcomponent_sql_temptables.xaction 3.42 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?xml version="1.0" encoding="UTF-8"?>
<action-sequence> 
  <title>IPreparedComponent Test Temp Tables</title>
  <version>1</version>
  <logging-level>DEBUG</logging-level>
  <documentation> 
    <author>Will Gorman</author>  
    <description>This tests the SQLBaseComponent's implementation of the IPreparedComponent interface, verifying that sql connections are shared across components</description>  
    <help/>  
    <result-type>rule</result-type>
    <icon/> 
  </documentation>

  <inputs/>

	<outputs>
		<a_result>
			<type>result-set</type>
		</a_result>
                <no_results>
                        <type>result-set</type>
                </no_results>
	</outputs>

  <resources/>
  
  <actions>

      <!-- first create a connection -->

    <action-definition>
      <component-name>SQLLookupRule</component-name>
      <action-type>Get Connection</action-type>
      <action-inputs/>
      <action-outputs>
        <prepared_component mapping="connObj"/>
      </action-outputs>
      <component-definition>
        <jndi>SampleDataAdmin</jndi>
      </component-definition>
    </action-definition>

      <!-- second, create temporary table w/ connection and add data -->

      <action-definition>
        <action-inputs>
          <prepared_component mapping="connObj"/>
        </action-inputs>
        <action-outputs/>
        <component-name>SQLExecute</component-name>
        <action-type>Create a temp table</action-type>
        <component-definition>
          <continue_on_exception>true</continue_on_exception>
          <query><![CDATA[
            drop table tmptbl;
            create temp table tmptbl(val int) ON COMMIT PRESERVE ROWS;
            insert into tmptbl values (1)
          ]]></query>
        </component-definition>
      </action-definition>


      <!-- third, extract inserted data from temporary table -->

    <action-definition>
      <component-name>SQLLookupRule</component-name>
      <action-type>Check for Data</action-type>
      <action-inputs>
         <prepared_component mapping="connObj"/>
      </action-inputs>
      <action-outputs>
        <query-result mapping="a_result"/>
      </action-outputs>
      <component-definition>
        <query>SELECT * FROM tmptbl</query>
      </component-definition>
    </action-definition>

    <!-- fourth, with another connection, tmptbl should contain zero results. -->
    <!-- note, in hsqldb, temp tables are available to all, but there data is per session -->
    <!-- http://hsqldb.org/doc/guide/ch09.html#create_table-section -->
    <action-definition>
      <component-name>SQLLookupRule</component-name>
      <action-type>Check for Data</action-type>
      <action-outputs>
        <query-result mapping="no_results"/>
      </action-outputs>
      <component-definition>
        <jndi>SampleDataAdmin</jndi>
        <query>SELECT count(*) FROM tmptbl</query>
      </component-definition>
    </action-definition>

    <!-- fifth, drop the table -->
      <action-definition>
        <action-inputs>
          <prepared_component mapping="connObj"/>
        </action-inputs>
        <action-outputs/>
        <component-name>SQLExecute</component-name>
        <action-type>Drop the Table</action-type>
        <component-definition>
          <continue_on_exception>true</continue_on_exception>
          <query><![CDATA[
            drop table tmptbl
          ]]></query>
        </component-definition>
      </action-definition>
  </actions> 
</action-sequence>