You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris Merrill <ch...@webperformance.com> on 2010/08/06 20:43:38 UTC

relationship of DAO to IDataProvider and DetachableLoadableModel

I've been away from server-side development for quite a while...working on a massively
multi-threaded network-centric Eclipse-based app .  I'm now working on a proof-of-concept for the
technology stack for an upcoming project web-based product and am trying to get my head around
Wicket, JPA, IOC, dependency injection, etc.

I have the first stage of the prototype together, but I'm not sure I have it assembled correctly,
specifically related to DetachableLoadableModel, IDataProvider and container-injected entity managers.

I'm using Spring to inject the Entity Manager into my DAO-ish DB logic wrapper (AppDAO).

There is a "ItemsPage" that lists items from a database table using a DataView with a
SortableItemProvider (SortableDataProvider<Item>) and a PagingNavigator.  It also has a member
AppDAO that is a @SpringBean. The page uses a SortableItemProvider (SortableDataProvider<Item>) to
provide data for the DataView.

The SortableItemProvider receives an AppDAO instance from the page (as a constructor parameter)
during the page constructor and stores it as a member variable.  It then passes the AppDAO off to
the DetachableItemModel (DetachableLoadableModel<Item>) when it creates them.

The DetachableItemModel also keeps the reference to the AppDAO so it can use it to load() the Item.


It seems to be working, but it doesn't feel right to be holding onto the AppDAO in the provider and
model. Actually, I'm a bit surprised it is working.  I expected it to break when navigating to the
second page in the table.  Is it going to break under concurrency or session serialization?

Is there a better way to do this?
(Have I even provided enough context to answer this question?)

TIA!
Chris

-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris@webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

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


Re: relationship of DAO to IDataProvider and DetachableLoadableModel

Posted by Leszek Gawron <lg...@mobilebox.pl>.
On 2010-08-06 22:58, Chris Merrill wrote:
> On 8/6/2010 4:35 PM, Leszek Gawron wrote:
>> you can actually do it in any class you like :)
>
> So I was about to ask how this works on deserialization, since the constructor will not
> be called.  Then I re-read your previous and I think I now understand this
>
> "Injector injects a serializable proxy instead of the bean directly."
>
> So I guess this serializable proxy knows how to re-create the DAO when the bean is
> deserialized (possibly on another server?).  Very nice!  I'm (slowly) starting to
> understand the role that Spring plays.

in fact the dao is not "re-created" as "re-looked up" every time 
deserialization takes place. And yes - it does "survive" clustering (I 
never tried it though).

If you want more insight check the source code of wicket-spring module, 
especially:

org.apache.wicket.spring.injection.annot.AnnotSpringInjector

org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory [1]


javadoc:

	lg

[1] 
http://wicketbyexample.com/api/wicket-spring/latest/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.html

-- 
Leszek Gawron                         http://www.mobilebox.pl/krs.html
CTO at MobileBox Ltd.

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


Re: relationship of DAO to IDataProvider and DetachableLoadableModel

Posted by Chris Merrill <ch...@webperformance.com>.
On 8/6/2010 4:35 PM, Leszek Gawron wrote:
> you can actually do it in any class you like :)

So I was about to ask how this works on deserialization, since the constructor will not
be called.  Then I re-read your previous and I think I now understand this

"Injector injects a serializable proxy instead of the bean directly."

So I guess this serializable proxy knows how to re-create the DAO when the bean is
deserialized (possibly on another server?).  Very nice!  I'm (slowly) starting to
understand the role that Spring plays.

Thanks!



-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris@webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

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


Re: relationship of DAO to IDataProvider and DetachableLoadableModel

Posted by Leszek Gawron <lg...@mobilebox.pl>.
On Fri, Aug 6, 2010 at 10:30 PM, Chris Merrill <ch...@webperformance.com> wrote:
> Wow, that was easy! Thanks!!
>
> Now, do I do the same thing in my LoadableDetachableModel?  (so that load() can get
> access to the DAO as well)  Should detach() be doing anything related to this?

you can actually do it in any class you like :)
you do not have to do anything in detach() for this scenario

  lg

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


Re: relationship of DAO to IDataProvider and DetachableLoadableModel

Posted by Chris Merrill <ch...@webperformance.com>.
Wow, that was easy! Thanks!!

Now, do I do the same thing in my LoadableDetachableModel?  (so that load() can get
access to the DAO as well)  Should detach() be doing anything related to this?


Chris



On 8/6/2010 4:10 PM, Leszek Gawron wrote:
> public class MyDataProvider ... {
> 
> @SpringBean
> private AppDAO appDao;
> 
> public MyDataProvider() {
>  InjectorHolder.getInjector().inject( this );
> }
> 
> }
> 
> and you'll be fine. You do not have to pass it from the page.
> 
> Injector injects a serializable proxy instead of the bean directly.
> 


-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris@webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

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


Re: relationship of DAO to IDataProvider and DetachableLoadableModel

Posted by Leszek Gawron <lg...@mobilebox.pl>.
On 2010-08-06 20:43, Chris Merrill wrote:
> I've been away from server-side development for quite a while...working on a massively
> multi-threaded network-centric Eclipse-based app .  I'm now working on a proof-of-concept for the
> technology stack for an upcoming project web-based product and am trying to get my head around
> Wicket, JPA, IOC, dependency injection, etc.
>
> I have the first stage of the prototype together, but I'm not sure I have it assembled correctly,
> specifically related to DetachableLoadableModel, IDataProvider and container-injected entity managers.
>
> I'm using Spring to inject the Entity Manager into my DAO-ish DB logic wrapper (AppDAO).
>
> There is a "ItemsPage" that lists items from a database table using a DataView with a
> SortableItemProvider (SortableDataProvider<Item>) and a PagingNavigator.  It also has a member
> AppDAO that is a @SpringBean. The page uses a SortableItemProvider (SortableDataProvider<Item>) to
> provide data for the DataView.
>
> The SortableItemProvider receives an AppDAO instance from the page (as a constructor parameter)
> during the page constructor and stores it as a member variable.  It then passes the AppDAO off to
> the DetachableItemModel (DetachableLoadableModel<Item>) when it creates them.

public class MyDataProvider ... {

@SpringBean
private AppDAO appDao;

public MyDataProvider() {
  InjectorHolder.getInjector().inject( this );
}

}

and you'll be fine. You do not have to pass it from the page.

Injector injects a serializable proxy instead of the bean directly.

-- 
Leszek Gawron                         http://www.mobilebox.pl/krs.html
CTO at MobileBox Ltd.

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