Reuse of statement in an other statement

View: New views
2 Messages — Rating Filter:   Alert me  

Reuse of statement in an other statement

by Régis BRULEY :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

It's my first post in this mail-list ... so hi everybody.

I writing this mail, because I don't know if it's possible to reuse some previous statements in an other statement ? ...

Let me explain myself :

I have a class UniverseFilter which is mapped. Every thing works.
I have an class UniverseDefinition which contains a list of UniverseFilter.

I get every UniverseFilter in my object with a resultMap like this :

<resultMaps>
    <resultMap id="UniverseDefinitionMap" class="UniverseDefinition" groupBy="IdRessource">
      <result column="id_universedef" property="IdUniverseDefinition" />
      <result column="id_ressource" property="IdRessource" />
      <result column="dateval" property="Date" />
      <result column="generatortype" property="GeneratorType" />
      <result column="filterorder" property="FilterOrder" />

      <result column="id_universedef" property="FilterList" select="UniverseFilterSelectByIdUnivRef" />
[...]

Every works well for the select statements.


But, i'd like to make an insert statement, and reuse the insert statement i made for the class UniverseFilter.

    <insert id="UniverseDefinitionInsert" parameterClass="UniverseDefinition" resultClass="int">
      insert into dbo.r_universedef (id_universedef, id_ressource, dateval, generatortype, filterorder)
      values (#IdUniverseDefinition:int#, #IdRessource:int#, #Date:DATETIME#, #GeneratorType:int#, #FilterOrder:VARCHAR# );
     
      <dynamic prepend="">
       <isGreaterThan prepend="" property="FilterList.Count" compareValue="0">
          <iterate prepend="" open="" close="" property="FilterList" conjunction="; ">
           
                       REUSE OF STATEMENT "INSERT_UNIVERSEFILTER" ... with paramater FilterList[] (typed UniverseFilter)

          </iterate>
        </isGreaterThan>
      </dynamic>
    </insert>

Is it possible ?

Thanks

Régis



NB: iBatis is really great !
NB2: sorry, i'm french and my english is suffering ...




Re: Reuse of statement in an other statement

by Michael McCurrey-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can, but not directly in how you have it.

IBatis includes a feature called fragements.  In your map file, put your *core* sql in a statement such as
    <sql id="Fragment">
      insert something
    </sql>

Then down in your real insert statement reference it as such:
    <insert id="test">
      <include refid="Fragment"></include>
    </insert>

Does this help?


On Fri, Jul 10, 2009 at 8:19 AM, Régis BRULEY <regis@...> wrote:
Hi,

It's my first post in this mail-list ... so hi everybody.

I writing this mail, because I don't know if it's possible to reuse some previous statements in an other statement ? ...

Let me explain myself :

I have a class UniverseFilter which is mapped. Every thing works.
I have an class UniverseDefinition which contains a list of UniverseFilter.

I get every UniverseFilter in my object with a resultMap like this :

<resultMaps>
    <resultMap id="UniverseDefinitionMap" class="UniverseDefinition" groupBy="IdRessource">
      <result column="id_universedef" property="IdUniverseDefinition" />
      <result column="id_ressource" property="IdRessource" />
      <result column="dateval" property="Date" />
      <result column="generatortype" property="GeneratorType" />
      <result column="filterorder" property="FilterOrder" />

      <result column="id_universedef" property="FilterList" select="UniverseFilterSelectByIdUnivRef" />
[...]

Every works well for the select statements.


But, i'd like to make an insert statement, and reuse the insert statement i made for the class UniverseFilter.

    <insert id="UniverseDefinitionInsert" parameterClass="UniverseDefinition" resultClass="int">
      insert into dbo.r_universedef (id_universedef, id_ressource, dateval, generatortype, filterorder)
      values (#IdUniverseDefinition:int#, #IdRessource:int#, #Date:DATETIME#, #GeneratorType:int#, #FilterOrder:VARCHAR# );
     
      <dynamic prepend="">
       <isGreaterThan prepend="" property="FilterList.Count" compareValue="0">
          <iterate prepend="" open="" close="" property="FilterList" conjunction="; ">
           
                       REUSE OF STATEMENT "INSERT_UNIVERSEFILTER" ... with paramater FilterList[] (typed UniverseFilter)

          </iterate>
        </isGreaterThan>
      </dynamic>
    </insert>

Is it possible ?

Thanks

Régis



NB: iBatis is really great !
NB2: sorry, i'm french and my english is suffering ...






--
Michael J. McCurrey
Read with me at http://www.mccurrey.com
http://chaoticmindramblings.blogspot.com/