ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Carpenter" <mcarpen...@summa-tech.com>
Subject Can you add a table alias in Abator?
Date Thu, 11 May 2006 16:08:28 GMT
I'd like to add a table alias to the tables in my Abator config.
Something like this:

...
    <table tableName="PRODUCT" domainObjectName="Product" alias="PROD">
      <property name="useActualColumnNames" value="false"/>
      <generatedKey column="PRODUCT_ID" identity="false"
sqlStatement="SELECT PRODUCT_SEQ.NEXTVAL FROM DUAL"/>
    </table>
...

Notice the addition of the "alias" attribute. This would then crate a
mapping like this:

...
  <resultMap id="abatorgenerated_ProductResult" class="Product">
    <!--
      WARNING - This element is automatically generated by Abator for
iBATIS, do not modify.
      This element was generated on Thu May 11 10:36:25 EDT 2006.
    -->
    <result column="PROD.PRODUCT_ID" property="productId"
jdbcType="DECIMAL" />
    <result column="PROD.NAME" property="unitName" jdbcType="VARCHAR" />
    <result column="PROD.CREATED_DATE" property="createdDate"
jdbcType="DATE" />
    <result column="PROD.CREATED_BY" property="createdBy"
jdbcType="DECIMAL" />
  </resultMap>
...

Additionally all the sql statements generated would use this alias.

This is useful if I want to extend the Abator generated resultMap in
another mapping that might add relationships, like this:

...
  <resultMap id="productsAndBids" class="ProductsBids"
groupBy="productId" extends="PRODUCT.abatorgenerated_ProductResult">
    <result property="bids" resultMap="BIDS.abatorgenerated_BidResult"
/>
  </resultMap>
...

Where "bids" would be a list of bids for the product associated by
foreign key.

And in my sql query to get the data for this resultMap I can use the
alias for the joins to ensure there are no field name collisions:

 select PROD.PRODUCT_ID as "PROD.PRODUCT_ID",
      PROD.NAME as "PROD.NAME",
      PROD.CREATED_BY AS "PROD.CREATED_BY",
      PROD.CREATED_DATE AS "PROD.CREATED_DATE",
    B.BID_ID AS "B.BID_ID",
      B.PRODUCT_ID as "B.PRODUCT_ID",
      B.AMOUNT AS "B.AMOUNT",
      B.CREATED_BY AS "B.CREATED_BY",
      B.CREATED_DATE AS "B.CREATED_DATE"
    from PRODUCT PROD
    LEFT OUTER JOIN BID B ON PROD.PRODUCT_ID = B.PRODUCT_ID

This way CREATED_BY and CREATED_DATE will resolve to the correct field
due to the alias.

I'd like to do this because I am creating a new application and database
and want to continuously generate the POJOs and sql maps during the
build. This way I can extend the POJOs and sql maps Abator generates so
changes to the database will always be synchronized with my code on
build.

So, is there some way to mimic this behavior in Abator today or would it
be an enhancement request?

Thanks for your help,

Mike Carpenter



Mime
View raw message