Re: DataObject becomes hollow when passed through a tapestry DirectLink

From: Craig Turner (crai..ecalldesign.com)
Date: Wed Mar 30 2005 - 21:11:53 EST

  • Next message: Andrus Adamchik: "Re: DataObject becomes hollow when passed through a tapestry DirectLink"

    Andrus Adamchik wrote:
    > Craig,
    >
    > Objects likely become HOLLOW due to serialization/deserialization
    > cycle between requests. But is this really a problem? I mean when
    > you call a getter on such HOLLOW object, no query should be
    > executed, as object snapshot is taken from the cache. And
    > definitely you shouldn't have to manually refetch it..
    >
    > Are you seeing different behavior?

    Yes. The getter on my method getFirstname() returns null (incorrect)
    before I refetch it, and the correct String after a refetch. So maybe
    there's a break in my situation in the cache or between the object and
    the cache. Notably, the object seems to be losing its datacontext along
    the way, but I'm not doing anything in my code that would obviously
    cause this.

    In case it's relevant, here's the appropriate section of the page file
    and the methods.

    <component id="personSearchResults_Link" type="DirectLink">
         <!-- first method in email below -->
         <binding name="listener" expression="listeners.linkLoadPerson" />

         <!-- second method in email below -->
         <binding name="parameters" expression="linkParameters" />
    </component>

         /**
          * Creates a list of parameters consisting of a single entry: the
          * Person object referred to by the current row. If the user later
          * clicks on a link in the sidebar, then that will be interpreted
          * by linkLoadPerson. So make sure that any changes to the way
          * this list is formed are matched with updates to the method
          * linkLoadPerson(IRequestCycle).
          */
         public Object[] getLinkParameters() {
             Object[] params = new Object[1];
             params[0] = getSearchPersonResult_CurrentRow();

             return params;
         }

         /**
          * This function populates the person workflow with the entity the
          * user has selected from the list. This method is dependent on
          * getLinkParameters(), which populates the list of parameters
          * that we interepret here.
          */
         public void linkLoadPerson(IRequestCycle cycle) {
             Object[] obList = cycle.getServiceParameters();

             Person p = (Person) obList[0];

             /* this next line prints out "[null]" */
             System.out.println("["+p.getFirstname()+"]");

             if (p.getPersistenceState() == PersistenceState.HOLLOW) {
                 System.out.println("refetch necessary");
                 p = (Person) getWorkflow().refetchObject( p );
             }

             /* this next line prints out the firstname as you'd expect */
             System.out.println("["+p.getFirstname()+"]");

             getWorkflow().getPerson().setEntity(p);
         }

    This is the output when the action is fired

    --
          [java] test getter [null]
          [java] dc [null]
          [java] refetch necessary
          [java] cayenne INFO  [PoolThread-1 03-31 11:34:27] QueryLogger: 
    --- will run 1 query.
          [java] cayenne INFO  [PoolThread-1 03-31 11:34:27] QueryLogger: 
    --- transaction started.
          [java] cayenne INFO  [PoolThread-1 03-31 11:34:27] QueryLogger: 
    SELECT t0.active, t0.can_crew, t0.can_pilot, t0.commission_earned, 
    t0.country, t0.date_created, t0.email, t0.firstname, t0.is_employee, 
    t0.lastname, t0.notes, t0.password, t0.phone_fax, t0.phone_home, 
    t0.phone_mobile, t0.phone_work, t0.postcode, t0.state, t0.street1, 
    t0.street2, t0.suburb, t0.username, t0.weight, t0.id, t0.agency_id FROM 
    person t0 WHERE t0.id = ? [bind: 240]
          [java] cayenne INFO  [PoolThread-1 03-31 11:34:27] QueryLogger: 
    === returned 1 row. - took 35 ms.
          [java] cayenne INFO  [PoolThread-1 03-31 11:34:27] QueryLogger: 
    +++ transaction committed.
          [java] [new]
    

    We've just been talking about thsi situation in the office, and there's an easier workaround than the one I'm using above: I could just pass the id into the parameters instead of the whole object and then fetch the object out of a list. But I'd like to follow up to all the same in order to understand why it's not working as I'd expect it to.

    - C



    This archive was generated by hypermail 2.0.0 : Wed Mar 30 2005 - 21:11:43 EST