You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by EP...@upstate.com on 2002/08/19 22:07:20 UTC

RE: trying to delete data from db - doSelect shows cached data in stead

When you delete data, it doesn't deleted from the existing java objects.  So
if object A has a collection of objects B, and you delete a member of the
collection B, then you need to do a fresh select on object A.  Take a look
at the torque generated base objects and you will see the issues...

Eric

-----Original Message-----
From: Derek Stevenson [mailto:derek@retrocode.com]
Sent: Monday, August 19, 2002 3:31 PM
To: Turbine Users List
Subject: trying to delete data from db - doSelect shows cached data
instead


I've got the following tables defined in my torque xml:

         <table name="MOCHA_USER" idMethod="none">
                 <column name="USER_ID" required="true" primaryKey="true" 
type="INTEGER"/>
         </table>

         <table name="USER_ATTRIBUTE_CODE">
                 <column name="UA_CODE" required="true" primaryKey="true" 
type="VARCHAR" size="8"/>
                 <column name="UA_DESC" type="VARCHAR" size="255"/>
         </table>

         <table name="USER_ATTRIBUTE">
                 <column name="USER_ID" required="true" primaryKey="true" 
type="INTEGER"/>
                 <column name="UA_CODE" required="true" primaryKey="true" 
type="VARCHAR" size="8"/>
                 <column name="VALUE" type="VARCHAR" size="255"/>

                 <foreign-key foreignTable="MOCHA_USER">
                         <reference local="USER_ID" foreign="USER_ID"/>
                 </foreign-key>
                 <foreign-key foreignTable="USER_ATTRIBUTE_CODE">
                         <reference local="UA_CODE" foreign="UA_CODE"/>
                 </foreign-key>
         </table>


I want to add a new user attribute to the USER_ATTRIBUTE table, but before 
doing so, I want to make sure all existing attributes of a particular class 
are deleted first.  For each of those attributes, I do the delete with the 
following method (in my torque-generated MochaUser object):

     public void clearUserFlag(String flagName) throws Exception {
         if (flagName != null || flagName.length() == 0) {
             Criteria crit = new Criteria();
             int userid = this.getUserId().getBigDecimal().intValue();
             crit.add(UserAttributePeer.USER_ID, userid);
             crit.add(UserAttributePeer.UA_CODE, flagName);
             UserAttributePeer.doDelete(crit);
             this.save();
         }
     }

Then, I add the appropriate attribute via the MochaUser.addUserAttribute() 
method, thus:

     public void addUserFlag(String flagName, String flagValue) throws 
Exception {
         // Add user attribute
         UserAttribute ua = new UserAttribute();
         ua.setUaCode(flagName);
         if (flagValue == null || flagValue == "") {
             flagValue = "true";
         }
         ua.setValue(flagValue);
         this.addUserAttribute(ua);
         ua.save();
     }

However, when I iterate through the Vector from 
MochaUser.getUserAttributes(), I get both the deleted user attributes and 
the newly added one!  When I check the database, though, the deleted user 
attribute is in fact gone.  So, here's my questions:

1. The getUserAttributes() method must be accessing some sort of cache of 
the attributes (from the source it looks like there's a Vector that's 
stored in memory to avoid db hits), and is returning the list of attributes 
initially provided by the database, plus whatever's been added via the 
addUserAttribute() method.  Should I be doing the delete a different way, 
that tells the MochaUser object to requery the database?  Or alternatively 
'notifies' MochaUser to delete the UserAttribute from its cached collection?

2. I'm pretty sure the clearUserFlag method above isn't the most elegant 
way to delete a user attribute.  Any recommendations for modifying the code?

TIA,
Derek


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>