wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Grigorov <mgrigo...@apache.org>
Subject Re: Serialization of DAO
Date Thu, 14 Mar 2013 08:20:16 GMT
Hi,

I don't see how you initialize blogDAO. If you don't use wicket-ioc module
then you will need to lookup the DAO from the application whenever you need
it:

public void onSubmit() {

  BlogDAO blogDao = MyApplication.get().getBlogDAO();
  blogDao.save(blog);
}
This way you wont keep reference to it in the page/component and it wont be
serialized.

If you use wicket-guice module then you can do:

@Inject
private  BlogDAO blogDao;

and use it anywhere.
Wicket will use Guice to lookup the bean at component creation but the bean
will be wrapped in a serializable proxy. That is a lightweight proxy will
be (de)serialized with the page.
This is the recommended way.
wicket-string works the same way.
wicket-cdi leaves the proxy creation to the CDI implementation.



On Thu, Mar 14, 2013 at 5:19 AM, Stephen Walsh <
stephen@connectwithawalsh.com> wrote:

> I'm attempting to implement Guice for my DAO connections as my JBoss server
> keeps running out of memory.  Not entirely sure why that is, but I'm hoping
> this is at least part of it.  I read through
> http://markmail.org/message/sz64l4eytzc3ctkh and understand why the DAO
> needs to be serialized, and I also followed
>
> https://cwiki.apache.org/confluence/display/WICKET/Wicket%2C+Guice+and+Ibatis+exampleto
> try and figure out where and how exactly to inject my DAO.
>
> My DAO already extends a basic DAO class that has all of the basics for
> getting stuff from the database.  Neither of these are interfaces (not sure
> if this is a problem or not).  My DAO works just fine in panels, but as
> soon as it's on a page, it throws the not seralizable exception.
>  Regardless it doesn't really solve the problem of really only needing one
> DAO for the whole application instead of creating one whenever it's needed
> in every place that it's needed.  If I understand dependency injection,
> then this is the whole point.
>
> Here's my class.  Hopefully someone can point me in the right direction for
> this page and my application class:
>
> public class EditBlogEntry extends BasePage {
>
>     private Logger logger = LoggerFactory.getLogger(EditBlogEntry.class);
>
>     private Mongo mongo;
>     private Morphia morphia;
>     private BlogDAO blogDAO;
>
>     public EditBlogEntry(final Blog blogEntry) {
>  // Add edit blogPost form to page
>         Form<?> form = new Form("form");
>         form.add(new Button("postIt") {
>             @Override
>             public void onSubmit() {
>                 // This merely gets a new mongo instance that has my blog
> entry mapped by morphia for saving the whole POJO to mongo
>                 setUpMongo();
>                 blogDAO.save(blogEntry);
>                 BlogEntryDetails details = new BlogEntryDetails(new
> PageParameters().add("id", blogEntry.getObjectId().toString()));
>                 setResponsePage(details);
>             }
>         });
>
>         LoadableDetachableModel ldm = new LoadableDetachableModel() {
>             @Override
>             protected Object load() {
> //                TODO need to set athr only on new blogEntry
>                 blogEntry.setAthr(CampingAwaitsSession.get().getUser());
>                 return blogEntry;
>             }
>         };
>
>         form.add(new BlogEntryPanel("blogEntry", new
> CompoundPropertyModel<Blog>(ldm)));
>         add(form);
>
> }
>
> Any thoughts?  I feel like I understand the concept but the implementation
> is throwing me.
>
> _______________________________________
> Stephen Walsh | http://connectwithawalsh.com
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message