You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Graeme Knight <gr...@gmail.com> on 2008/11/07 04:12:40 UTC

LoadableDetachableModels with replicated data fed in through constructors.

Hi.

I have a number of LoadableDetachableModels that are each designed to
perform a task of getting data from a database. Each model is dependent on a
couple of pieces of information (1) an identifier about the current user (2)
a primary key of a parent data object. I'm trying to work out the mechanics
and life cycle of the model object...

So, my class might look like:

public class GetAccountsModel extends LoadableDetachableModel
{
    private Long userId;
    private Long parentPrimaryKey;

   public GetAccountsModel( Long userId, Long parentPrimaryKey )
   {
      this.userId = userId;
      this.parentPrimaryKey = parentPrimaryKey;
   }

   ...... override load here .....
}

Let's say I have ten similar LoadableDetachableModels all of which take the
same parameters in the constructor, but all of which return different data
from the database.

When I create a LoadableDetachableModel as above and call the super
constructor of (for example) a ListView, the model is fed into the ListView
and load is called (with the transient object being detached). 

The userId and primaryKey get serialized. So if I have ten similar models
which get different data, I am serializing the same (or very similar) data
10 times, specifically the userid.

If figured I could probably make the userID and primaryKey transient then
they would not serialize. I'm not sure if this would have a negative affect
if I go to another page (i.e. current page is out of memory) and come back -
what happens?

Now my example above is not too bad resource wize - you may only be talking
about a couple of Longs being serialized ten times (not a massive hit), but
what about if the objects in my LoadableDetachableModel are fairly big?

Is there a way of destructing and reconstructing the model automatically so
I don't need to worry about this serialization of the model private data?

Or... am I panicking about nothing? I may be completely misunderstanding the
whole concept here.

Any explanation welcome.

Regards, Graeme.
-- 
View this message in context: http://www.nabble.com/LoadableDetachableModels-with-replicated-data-fed-in-through-constructors.-tp20374062p20374062.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: LoadableDetachableModels with replicated data fed in through constructors.

Posted by Graeme Knight <gr...@gmail.com>.
Thanks Jeremy.

I have those conversations often - especially over silly things.

I need to go back and look at the ins and outs of serialization. I guess if
I have several private references to the same object in multiple
LoadableDetachableModels I guess the actual object itself only gets
serialized once (i.e. there are never multiple copies of it being stored
over time on disk)... Not to concerned. Just a mad moment :-) One of many
:-) More to come :-)

Cheers, Graeme. 


Jeremy Thomerson-5 wrote:
> 
> I hate to interrupt your conversation with yourself (I've had those days
> myself) :)
> 
> Basically, I would say you needn't worry so much about serializing a
> couple
> of Longs - that's the point of the LoadableDetachableModel - serializing a
> couple of Longs rather than dozens (or hundreds) of User / Customer /
> Article / WhateverYourDomainObject instances.
> 
> You can't make the private variables in your example transient - then they
> wouldn't get serialized, which means they wouldn't be available later when
> the page is deserialized and the model is supposed to reinflate itself.
> 
> Hope this helps put your mind at ease.  Get some rest.  :)
> 
> -- 
> Jeremy Thomerson
> http://www.wickettraining.com
> 
> On Thu, Nov 6, 2008 at 9:58 PM, Graeme Knight <gr...@gmail.com>
> wrote:
> 
>>
>> Oh - tired! Long hard days working with spaghetti in my day job and
>> lasagna
>> in my night time...
>>
>> I realized this may be a dumb question. Doesn't an object only get
>> serialized once no matter how many references would be made to it in a
>> LoadableDetatchableModel? I.e. you wouldn't get 10 userIds serialized,
>> just
>> 1... (which would be just peachy and fine).
>>
>> Thanks, Graeme. :-)
>>
>>
>> Graeme Knight wrote:
>> >
>> > Hi.
>> >
>> > I have a number of LoadableDetachableModels that are each designed to
>> > perform a task of getting data from a database. Each model is dependent
>> on
>> > a couple of pieces of information (1) an identifier about the current
>> user
>> > (2) a primary key of a parent data object. I'm trying to work out the
>> > mechanics and life cycle of the model object...
>> >
>> > So, my class might look like:
>> >
>> > public class GetAccountsModel extends LoadableDetachableModel
>> > {
>> >     private Long userId;
>> >     private Long parentPrimaryKey;
>> >
>> >    public GetAccountsModel( Long userId, Long parentPrimaryKey )
>> >    {
>> >       this.userId = userId;
>> >       this.parentPrimaryKey = parentPrimaryKey;
>> >    }
>> >
>> >    ...... override load here .....
>> > }
>> >
>> > Let's say I have ten similar LoadableDetachableModels all of which take
>> > the same parameters in the constructor, but all of which return
>> different
>> > data from the database.
>> >
>> > When I create a LoadableDetachableModel as above and call the super
>> > constructor of (for example) a ListView, the model is fed into the
>> > ListView and load is called (with the transient object being detached).
>> >
>> > The userId and primaryKey get serialized. So if I have ten similar
>> models
>> > which get different data, I am serializing the same (or very similar)
>> data
>> > 10 times, specifically the userid.
>> >
>> > If figured I could probably make the userID and primaryKey transient
>> then
>> > they would not serialize. I'm not sure if this would have a negative
>> > affect if I go to another page (i.e. current page is out of memory) and
>> > come back - what happens?
>> >
>> > Now my example above is not too bad resource wize - you may only be
>> > talking about a couple of Longs being serialized ten times (not a
>> massive
>> > hit), but what about if the objects in my LoadableDetachableModel are
>> > fairly big?
>> >
>> > Is there a way of destructing and reconstructing the model
>> automatically
>> > so I don't need to worry about this serialization of the model private
>> > data?
>> >
>> > Or... am I panicking about nothing? I may be completely
>> misunderstanding
>> > the whole concept here.
>> >
>> > Any explanation welcome - I appreciate your time reading this post.
>> >
>> > Thanks, Graeme.
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/LoadableDetachableModels-with-replicated-data-fed-in-through-constructors.-tp20374062p20374412.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/LoadableDetachableModels-with-replicated-data-fed-in-through-constructors.-tp20374062p20380030.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: LoadableDetachableModels with replicated data fed in through constructors.

Posted by Jeremy Thomerson <je...@wickettraining.com>.
I hate to interrupt your conversation with yourself (I've had those days
myself) :)

Basically, I would say you needn't worry so much about serializing a couple
of Longs - that's the point of the LoadableDetachableModel - serializing a
couple of Longs rather than dozens (or hundreds) of User / Customer /
Article / WhateverYourDomainObject instances.

You can't make the private variables in your example transient - then they
wouldn't get serialized, which means they wouldn't be available later when
the page is deserialized and the model is supposed to reinflate itself.

Hope this helps put your mind at ease.  Get some rest.  :)

-- 
Jeremy Thomerson
http://www.wickettraining.com

On Thu, Nov 6, 2008 at 9:58 PM, Graeme Knight <gr...@gmail.com> wrote:

>
> Oh - tired! Long hard days working with spaghetti in my day job and lasagna
> in my night time...
>
> I realized this may be a dumb question. Doesn't an object only get
> serialized once no matter how many references would be made to it in a
> LoadableDetatchableModel? I.e. you wouldn't get 10 userIds serialized, just
> 1... (which would be just peachy and fine).
>
> Thanks, Graeme. :-)
>
>
> Graeme Knight wrote:
> >
> > Hi.
> >
> > I have a number of LoadableDetachableModels that are each designed to
> > perform a task of getting data from a database. Each model is dependent
> on
> > a couple of pieces of information (1) an identifier about the current
> user
> > (2) a primary key of a parent data object. I'm trying to work out the
> > mechanics and life cycle of the model object...
> >
> > So, my class might look like:
> >
> > public class GetAccountsModel extends LoadableDetachableModel
> > {
> >     private Long userId;
> >     private Long parentPrimaryKey;
> >
> >    public GetAccountsModel( Long userId, Long parentPrimaryKey )
> >    {
> >       this.userId = userId;
> >       this.parentPrimaryKey = parentPrimaryKey;
> >    }
> >
> >    ...... override load here .....
> > }
> >
> > Let's say I have ten similar LoadableDetachableModels all of which take
> > the same parameters in the constructor, but all of which return different
> > data from the database.
> >
> > When I create a LoadableDetachableModel as above and call the super
> > constructor of (for example) a ListView, the model is fed into the
> > ListView and load is called (with the transient object being detached).
> >
> > The userId and primaryKey get serialized. So if I have ten similar models
> > which get different data, I am serializing the same (or very similar)
> data
> > 10 times, specifically the userid.
> >
> > If figured I could probably make the userID and primaryKey transient then
> > they would not serialize. I'm not sure if this would have a negative
> > affect if I go to another page (i.e. current page is out of memory) and
> > come back - what happens?
> >
> > Now my example above is not too bad resource wize - you may only be
> > talking about a couple of Longs being serialized ten times (not a massive
> > hit), but what about if the objects in my LoadableDetachableModel are
> > fairly big?
> >
> > Is there a way of destructing and reconstructing the model automatically
> > so I don't need to worry about this serialization of the model private
> > data?
> >
> > Or... am I panicking about nothing? I may be completely misunderstanding
> > the whole concept here.
> >
> > Any explanation welcome - I appreciate your time reading this post.
> >
> > Thanks, Graeme.
> >
>
> --
> View this message in context:
> http://www.nabble.com/LoadableDetachableModels-with-replicated-data-fed-in-through-constructors.-tp20374062p20374412.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: LoadableDetachableModels with replicated data fed in through constructors.

Posted by Graeme Knight <gr...@gmail.com>.
Oh - tired! Long hard days working with spaghetti in my day job and lasagna
in my night time... 

I realized this may be a dumb question. Doesn't an object only get
serialized once no matter how many references would be made to it in a
LoadableDetatchableModel? I.e. you wouldn't get 10 userIds serialized, just
1...

Thanks, Graeme. :-)


Graeme Knight wrote:
> 
> Hi.
> 
> I have a number of LoadableDetachableModels that are each designed to
> perform a task of getting data from a database. Each model is dependent on
> a couple of pieces of information (1) an identifier about the current user
> (2) a primary key of a parent data object. I'm trying to work out the
> mechanics and life cycle of the model object...
> 
> So, my class might look like:
> 
> public class GetAccountsModel extends LoadableDetachableModel
> {
>     private Long userId;
>     private Long parentPrimaryKey;
> 
>    public GetAccountsModel( Long userId, Long parentPrimaryKey )
>    {
>       this.userId = userId;
>       this.parentPrimaryKey = parentPrimaryKey;
>    }
> 
>    ...... override load here .....
> }
> 
> Let's say I have ten similar LoadableDetachableModels all of which take
> the same parameters in the constructor, but all of which return different
> data from the database.
> 
> When I create a LoadableDetachableModel as above and call the super
> constructor of (for example) a ListView, the model is fed into the
> ListView and load is called (with the transient object being detached). 
> 
> The userId and primaryKey get serialized. So if I have ten similar models
> which get different data, I am serializing the same (or very similar) data
> 10 times, specifically the userid.
> 
> If figured I could probably make the userID and primaryKey transient then
> they would not serialize. I'm not sure if this would have a negative
> affect if I go to another page (i.e. current page is out of memory) and
> come back - what happens?
> 
> Now my example above is not too bad resource wize - you may only be
> talking about a couple of Longs being serialized ten times (not a massive
> hit), but what about if the objects in my LoadableDetachableModel are
> fairly big?
> 
> Is there a way of destructing and reconstructing the model automatically
> so I don't need to worry about this serialization of the model private
> data?
> 
> Or... am I panicking about nothing? I may be completely misunderstanding
> the whole concept here.
> 
> Any explanation welcome - I appreciate your time reading this post.
> 
> Thanks, Graeme.
> 

-- 
View this message in context: http://www.nabble.com/LoadableDetachableModels-with-replicated-data-fed-in-through-constructors.-tp20374062p20374412.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: LoadableDetachableModels with replicated data fed in through constructors.

Posted by Graeme Knight <gr...@gmail.com>.
Timo,

You are the man! Thanks!  

              long userId = MySession.get().getUser().getId() 

Of course!

Cheers, Graeme.



Timo Rantalaiho wrote:
> 
> On Thu, 06 Nov 2008, Graeme Knight wrote:
>> perform a task of getting data from a database. Each model is dependent
>> on a
>> couple of pieces of information (1) an identifier about the current user
>> (2)
>> a primary key of a parent data object. I'm trying to work out the
>> mechanics
> 
> If "the current user" means what it sounds like, I would 
> probably have it stored in the Wicket Session and get it
> each time like this
> 
>   long userId = MySession.get().getUser().getId()
> 
> (Or you can make your user available in a custom ThreadLocal
> which is populated and depopulated in a custom RequestCycle.)
> 
>> Now my example above is not too bad resource wize - you may only be
>> talking
>> about a couple of Longs being serialized ten times (not a massive hit),
>> but
>> what about if the objects in my LoadableDetachableModel are fairly big?
> 
> The point of LoadableDetachableModel is to store in it only
> so little data that it doesn't matter, but load the big data
> again in load() on each request that needs it. The big data 
> is referenced directly only during the request, so it does
> not get serialised.
> 
>> Is there a way of destructing and reconstructing the model automatically
>> so
>> I don't need to worry about this serialization of the model private data?
> 
> The only automatic part is that if the model is "the default
> model" of a rendered component, its detach() will be called
> automatically at the end of the request processing. The 
> wrapping models that come with Wicket also detach their
> wrapped models in their own detach() (and any custom model
> should in general do the same).
> 
> Best wishes,
> Timo
> 
> -- 
> Timo Rantalaiho           
> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/LoadableDetachableModels-with-replicated-data-fed-in-through-constructors.-tp20374062p20402019.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: LoadableDetachableModels with replicated data fed in through constructors.

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Thu, 06 Nov 2008, Graeme Knight wrote:
> perform a task of getting data from a database. Each model is dependent on a
> couple of pieces of information (1) an identifier about the current user (2)
> a primary key of a parent data object. I'm trying to work out the mechanics

If "the current user" means what it sounds like, I would 
probably have it stored in the Wicket Session and get it
each time like this

  long userId = MySession.get().getUser().getId()

(Or you can make your user available in a custom ThreadLocal
which is populated and depopulated in a custom RequestCycle.)

> Now my example above is not too bad resource wize - you may only be talking
> about a couple of Longs being serialized ten times (not a massive hit), but
> what about if the objects in my LoadableDetachableModel are fairly big?

The point of LoadableDetachableModel is to store in it only
so little data that it doesn't matter, but load the big data
again in load() on each request that needs it. The big data 
is referenced directly only during the request, so it does
not get serialised.

> Is there a way of destructing and reconstructing the model automatically so
> I don't need to worry about this serialization of the model private data?

The only automatic part is that if the model is "the default
model" of a rendered component, its detach() will be called
automatically at the end of the request processing. The 
wrapping models that come with Wicket also detach their
wrapped models in their own detach() (and any custom model
should in general do the same).

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org