ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lieven De Keyzer" <lieven_dekey...@hotmail.com>
Subject complex inserts?
Date Tue, 24 May 2005 01:15:04 GMT
I have a mapping for a Java class Bookmark that looks like this:

  <resultMap id="bookmarkResult" class="bookmark">
    <result property="bookmarkId" column="bookmark_id"/>
    <result property="folderId" column="folder_id"/>
    <result property="url" column="url"/>
    <result property="bookmarkname" column="bookmarkname"/>
    <result property="updated" column="updated"/>
    <result property="changed" column="changed"/>
    <result property="scanInterval" column="scan_interval"/>
    <result property="cache" column="cache" jdbcType="BLOB"/>
    <result property="notificationWays" column="bookmark_id"

Now, getting a bookmark is no problem with:

  <select id="getBookmarkById" resultMap="bookmarkResult" 
    SELECT *
    FROM bookmark
    WHERE bookmark_id = #value#

  <select id="getNotificationListByBookmarkId" resultMap="bookmarkResult"
    SELECT notification_way
    FROM notifications
    WHERE bookmark_id = #value#

But if I insert a bookmark, this Bookmark's NotificationWays array, can have 
values. This number is not a constant. Can I, when I insert, or update a 
bookmark, also insert or update these notificationWays in the notifications 
Now I have:

  <update id="updateBookmark" parameterClass="bookmark">
   UPDATE bookmark
   SET folder_id = #folderId#, bookmarkname = #bookmarkname#,
       url = #url#, changed = #changed#, updated= #updated#,
       scan_interval = #scanInterval#, cache = #cache#
   WHERE bookmark_id = #bookmarkId#

which updates the bookmark table allright, but of course does nothing to the 
notifications table.

In fact, it's even complexer than this, because when a certain notification 
is given as parameter and it is not present yet, is should be inserted, when 
it is present, nothing should happen, and when it's not given as parameter, 
it should be deleted.

View raw message