You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Chang <da...@yahoo.com> on 2009/07/27 14:20:14 UTC

the effective ways of wicket models to access database

Hello, I am reading <<Wicket in Action>> to learn Wicket. The example on Page 99 is about teaching detachable models. Here it goes:

-----------
public class CheeseModel extends Model {
	private Long id;
	private transient Cheese cheese;
		public CheeseModel() {
	}
	public CheeseModel(Cheese cheese) {
		setObject(cheese);
	}
	public CheeseModel(Long id) {
		this.id = id;
	}
	@Override
	public Object getObject() {
		if(cheese != null) return cheese;
		if(id == null ) {
			cheese = new Cheese();
		} else {
			CheeseDao dao = ...
			cheese = dao.getCheese(id);
	}
	return cheese;
	}
	@Override
	public void setObject(Object object) {
		this. cheese = (Cheese)object;
		id = (cheese == null) ? null : cheese.getId();
	}
	@Override
	public void detach() {
		this. cheese = null;
	}
}
-----------

I would like to know how dao is obtained as indicated as follows:

			CheeseDao dao = ...

Use a locator pattern? Or should I let CheeseModel extend a custom model in which dao is set via Spring? Does the latter way create more memory footprint? What are the effective ways of getting DAO avaiable to wicket models?

Thanks for your input!

Cheers!


      

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


Re: the effective ways of wicket models to access database

Posted by Linda van der Pal <lv...@heritageagenturen.nl>.
Well the reason the book leaves it open is that it really is up to you 
how you get your DAOs. That has nothing to do with Wicket anymore and 
depends wholly on your own preferences.

Regards,
Linda

David Chang wrote:
> Hello, I am reading <<Wicket in Action>> to learn Wicket. The example on Page 99 is about teaching detachable models. Here it goes:
>
> -----------
> public class CheeseModel extends Model {
> 	private Long id;
> 	private transient Cheese cheese;
> 		public CheeseModel() {
> 	}
> 	public CheeseModel(Cheese cheese) {
> 		setObject(cheese);
> 	}
> 	public CheeseModel(Long id) {
> 		this.id = id;
> 	}
> 	@Override
> 	public Object getObject() {
> 		if(cheese != null) return cheese;
> 		if(id == null ) {
> 			cheese = new Cheese();
> 		} else {
> 			CheeseDao dao = ...
> 			cheese = dao.getCheese(id);
> 	}
> 	return cheese;
> 	}
> 	@Override
> 	public void setObject(Object object) {
> 		this. cheese = (Cheese)object;
> 		id = (cheese == null) ? null : cheese.getId();
> 	}
> 	@Override
> 	public void detach() {
> 		this. cheese = null;
> 	}
> }
> -----------
>
> I would like to know how dao is obtained as indicated as follows:
>
> 			CheeseDao dao = ...
>
> Use a locator pattern? Or should I let CheeseModel extend a custom model in which dao is set via Spring? Does the latter way create more memory footprint? What are the effective ways of getting DAO avaiable to wicket models?
>
> Thanks for your input!
>
> Cheers!
>
>
>       
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.392 / Virus Database: 270.13.32/2266 - Release Date: 07/27/09 05:58:00
>
>   


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


AW: the effective ways of wicket models to access database

Posted by Arthur Leigh Allen <ar...@yahoo.de>.
what about the LoadableDetachableModel?
 
IModel model = new LoadableDetachableModel() {
    protected Object load() {
        return dao.getX();
    }
};




________________________________
Von: David Chang <da...@yahoo.com>
An: users@wicket.apache.org
Gesendet: Montag, den 27. Juli 2009, 14:20:14 Uhr
Betreff: the effective ways of wicket models to access database


Hello, I am reading <<Wicket in Action>> to learn Wicket. The example on Page 99 is about teaching detachable models. Here it goes:

-----------
public class CheeseModel extends Model {
    private Long id;
    private transient Cheese cheese;
        public CheeseModel() {
    }
    public CheeseModel(Cheese cheese) {
        setObject(cheese);
    }
    public CheeseModel(Long id) {
        this.id = id;
    }
    @Override
    public Object getObject() {
        if(cheese != null) return cheese;
        if(id == null ) {
            cheese = new Cheese();
        } else {
            CheeseDao dao = ...
            cheese = dao.getCheese(id);
    }
    return cheese;
    }
    @Override
    public void setObject(Object object) {
        this. cheese = (Cheese)object;
        id = (cheese == null) ? null : cheese.getId();
    }
    @Override
    public void detach() {
        this. cheese = null;
    }
}
-----------

I would like to know how dao is obtained as indicated as follows:

            CheeseDao dao = ...

Use a locator pattern? Or should I let CheeseModel extend a custom model in which dao is set via Spring? Does the latter way create more memory footprint? What are the effective ways of getting DAO avaiable to wicket models?

Thanks for your input!

Cheers!


      

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


      

Re: the effective ways of wicket models to access database

Posted by Maarten Bosteels <mb...@gmail.com>.
On Mon, Jul 27, 2009 at 2:58 PM, David Chang <da...@yahoo.com>wrote:

>
> Martin and all, thanks for your input.
>
> >>You can use spring to inject the service, using @SpringBean and
> calling in the constructor InjectorHolder.getInjector().inject(this);
> (or use salve)
>
> You mean add a member to this CheeseModel class and use @SpringBean to
> inject it? From reading this book, I know it works. How about creating a
> super custom model (implements IModel) which has DAO ready and other classes
> such as CheeseModel simply extends it?
>
> What do you mean by "salve"?


http://code.google.com/p/salve/

Maarten

>
>
> Thanks.
>
>
>
> --- On Mon, 7/27/09, Martijn Dashorst <ma...@gmail.com> wrote:
>
> > From: Martijn Dashorst <ma...@gmail.com>
> > Subject: Re: the effective ways of wicket models to access database
> > To: users@wicket.apache.org
> > Date: Monday, July 27, 2009, 8:29 AM
> > You can use spring to inject the
> > service, using @SpringBean and
> > calling in the constructor
> > InjectorHolder.getInjector().inject(this);
> > (or use salve)
> >
> > Service locator is also a possibility. That is why we left
> > it open :)
> >
> > Martijn
> >
> > On Mon, Jul 27, 2009 at 2:20 PM, David Chang<da...@yahoo.com>
> > wrote:
> > >
> > > Hello, I am reading <<Wicket in Action>>
> > to learn Wicket. The example on Page 99 is about teaching
> > detachable models. Here it goes:
> > >
> > > -----------
> > > public class CheeseModel extends Model {
> > >        private Long id;
> > >        private transient Cheese cheese;
> > >                public CheeseModel() {
> > >        }
> > >        public CheeseModel(Cheese cheese) {
> > >                setObject(cheese);
> > >        }
> > >        public CheeseModel(Long id) {
> > >                this.id = id;
> > >        }
> > >        @Override
> > >        public Object getObject() {
> > >                if(cheese != null) return
> > cheese;
> > >                if(id == null ) {
> > >                        cheese = new
> > Cheese();
> > >                } else {
> > >                        CheeseDao dao =
> > ...
> > >                        cheese =
> > dao.getCheese(id);
> > >        }
> > >        return cheese;
> > >        }
> > >        @Override
> > >        public void setObject(Object object) {
> > >                this. cheese = (Cheese)object;
> > >                id = (cheese == null) ? null :
> > cheese.getId();
> > >        }
> > >        @Override
> > >        public void detach() {
> > >                this. cheese = null;
> > >        }
> > > }
> > > -----------
> > >
> > > I would like to know how dao is obtained as indicated
> > as follows:
> > >
> > >                        CheeseDao dao =
> > ...
> > >
> > > Use a locator pattern? Or should I let CheeseModel
> > extend a custom model in which dao is set via Spring? Does
> > the latter way create more memory footprint? What are the
> > effective ways of getting DAO avaiable to wicket models?
> > >
> > > Thanks for your input!
> > >
> > > Cheers!
> > >
> > >
> > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> >
> >
> >
> > --
> > Become a Wicket expert, learn from the best: http://wicketinaction.com
> > Apache Wicket 1.3.5 is released
> > Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: the effective ways of wicket models to access database

Posted by David Chang <da...@yahoo.com>.
Martin and all, thanks for your input.

>>You can use spring to inject the service, using @SpringBean and
calling in the constructor InjectorHolder.getInjector().inject(this);
(or use salve)

You mean add a member to this CheeseModel class and use @SpringBean to inject it? From reading this book, I know it works. How about creating a super custom model (implements IModel) which has DAO ready and other classes such as CheeseModel simply extends it?

What do you mean by "salve"?

Thanks.



--- On Mon, 7/27/09, Martijn Dashorst <ma...@gmail.com> wrote:

> From: Martijn Dashorst <ma...@gmail.com>
> Subject: Re: the effective ways of wicket models to access database
> To: users@wicket.apache.org
> Date: Monday, July 27, 2009, 8:29 AM
> You can use spring to inject the
> service, using @SpringBean and
> calling in the constructor
> InjectorHolder.getInjector().inject(this);
> (or use salve)
> 
> Service locator is also a possibility. That is why we left
> it open :)
> 
> Martijn
> 
> On Mon, Jul 27, 2009 at 2:20 PM, David Chang<da...@yahoo.com>
> wrote:
> >
> > Hello, I am reading <<Wicket in Action>>
> to learn Wicket. The example on Page 99 is about teaching
> detachable models. Here it goes:
> >
> > -----------
> > public class CheeseModel extends Model {
> >        private Long id;
> >        private transient Cheese cheese;
> >                public CheeseModel() {
> >        }
> >        public CheeseModel(Cheese cheese) {
> >                setObject(cheese);
> >        }
> >        public CheeseModel(Long id) {
> >                this.id = id;
> >        }
> >        @Override
> >        public Object getObject() {
> >                if(cheese != null) return
> cheese;
> >                if(id == null ) {
> >                        cheese = new
> Cheese();
> >                } else {
> >                        CheeseDao dao =
> ...
> >                        cheese =
> dao.getCheese(id);
> >        }
> >        return cheese;
> >        }
> >        @Override
> >        public void setObject(Object object) {
> >                this. cheese = (Cheese)object;
> >                id = (cheese == null) ? null :
> cheese.getId();
> >        }
> >        @Override
> >        public void detach() {
> >                this. cheese = null;
> >        }
> > }
> > -----------
> >
> > I would like to know how dao is obtained as indicated
> as follows:
> >
> >                        CheeseDao dao =
> ...
> >
> > Use a locator pattern? Or should I let CheeseModel
> extend a custom model in which dao is set via Spring? Does
> the latter way create more memory footprint? What are the
> effective ways of getting DAO avaiable to wicket models?
> >
> > Thanks for your input!
> >
> > Cheers!
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> 
> 
> -- 
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.3.5 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

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


Re: the effective ways of wicket models to access database

Posted by Martijn Dashorst <ma...@gmail.com>.
You can use spring to inject the service, using @SpringBean and
calling in the constructor InjectorHolder.getInjector().inject(this);
(or use salve)

Service locator is also a possibility. That is why we left it open :)

Martijn

On Mon, Jul 27, 2009 at 2:20 PM, David Chang<da...@yahoo.com> wrote:
>
> Hello, I am reading <<Wicket in Action>> to learn Wicket. The example on Page 99 is about teaching detachable models. Here it goes:
>
> -----------
> public class CheeseModel extends Model {
>        private Long id;
>        private transient Cheese cheese;
>                public CheeseModel() {
>        }
>        public CheeseModel(Cheese cheese) {
>                setObject(cheese);
>        }
>        public CheeseModel(Long id) {
>                this.id = id;
>        }
>        @Override
>        public Object getObject() {
>                if(cheese != null) return cheese;
>                if(id == null ) {
>                        cheese = new Cheese();
>                } else {
>                        CheeseDao dao = ...
>                        cheese = dao.getCheese(id);
>        }
>        return cheese;
>        }
>        @Override
>        public void setObject(Object object) {
>                this. cheese = (Cheese)object;
>                id = (cheese == null) ? null : cheese.getId();
>        }
>        @Override
>        public void detach() {
>                this. cheese = null;
>        }
> }
> -----------
>
> I would like to know how dao is obtained as indicated as follows:
>
>                        CheeseDao dao = ...
>
> Use a locator pattern? Or should I let CheeseModel extend a custom model in which dao is set via Spring? Does the latter way create more memory footprint? What are the effective ways of getting DAO avaiable to wicket models?
>
> Thanks for your input!
>
> Cheers!
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

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