Re: Restlet and DAO
Hi Jerome Thanks for breaking it down in babysteps for me. ;-) Cheers, Nico -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-and-DAO-tp4962381p4973512.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2597893
Re: Restlet and DAO
Hi Nico, Here is the process: - create a subclass of ConnectorService - override the afterSend(Representation) method - test the representation instance against your base MyRepresentation class - cast it to your MyRepresentation class and invoke your commit/rollaback logic I would however recommend to use the ServerResource#onSent callback mechanism instead as it will be easier to use, especially if you rely on automatic bean <-> representation conversion and Restlet annotations. Best regards, Jerome 2010/4/28 Nico Van Cleemput > Hi Jerome > > Thanks for your pointers. If it isn't obvious, I'm quite new to this > framework (and actually I'm just an amateur who is also new to web > applications ;-)). I also need to apologize, because after searching a bit > more I noticed that there was already a similar question in this list about > a year ago. > > I do have a follow-up question. Is there somewhere some example code on how > this could be achieved? More specific I'm struggling with the following: if > I create my DAO and start the transaction in doInit() of UniformResource, > then how do I get a reference to it in ConnectorService, so I can commit or > rollback in afterSend? > > Just let me finish by giving you some more praise. ;-) The framework looks > really good, but at the moment it still a bit opaque. I'm looking forward > your In Action book and hope that you describe somewhere the steps that are > taken from when a request enters the frameworks to when the response > leaves, > because I still have the feeling I'm missing a lot of the details. (or if > you already have a blogpost or something like that describing that in > detail, you may always point me in the right direction ;)) > > Kind regards, > Nico > > > jlouvel wrote: > > > > Hi Nico, > > > > UniformResource has two methods, doInit() and doRelease() that can be > used > > for this. However, be careful with your transaction strategy if your > > representations need access to the DAO at writing time (after > > afterHandle() > > is called, in the connector).You can used ServerResource#onSent callback > > for > > this or the ConnectorService#afterSend method. > > > > Best regards, > > Jerome Louvel > > > > -- > View this message in context: > http://restlet-discuss.1400322.n2.nabble.com/Restlet-and-DAO-tp4962381p4972782.html > Sent from the Restlet Discuss mailing list archive at Nabble.com. > > -- > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2597753 > -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2597819
Re: Restlet and DAO
Hi Jerome Thanks for your pointers. If it isn't obvious, I'm quite new to this framework (and actually I'm just an amateur who is also new to web applications ;-)). I also need to apologize, because after searching a bit more I noticed that there was already a similar question in this list about a year ago. I do have a follow-up question. Is there somewhere some example code on how this could be achieved? More specific I'm struggling with the following: if I create my DAO and start the transaction in doInit() of UniformResource, then how do I get a reference to it in ConnectorService, so I can commit or rollback in afterSend? Just let me finish by giving you some more praise. ;-) The framework looks really good, but at the moment it still a bit opaque. I'm looking forward your In Action book and hope that you describe somewhere the steps that are taken from when a request enters the frameworks to when the response leaves, because I still have the feeling I'm missing a lot of the details. (or if you already have a blogpost or something like that describing that in detail, you may always point me in the right direction ;)) Kind regards, Nico jlouvel wrote: > > Hi Nico, > > UniformResource has two methods, doInit() and doRelease() that can be used > for this. However, be careful with your transaction strategy if your > representations need access to the DAO at writing time (after > afterHandle() > is called, in the connector).You can used ServerResource#onSent callback > for > this or the ConnectorService#afterSend method. > > Best regards, > Jerome Louvel > -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-and-DAO-tp4962381p4972782.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2597753
Re: Restlet and DAO
Hi Nico, UniformResource has two methods, doInit() and doRelease() that can be used for this. However, be careful with your transaction strategy if your representations need access to the DAO at writing time (after afterHandle() is called, in the connector).You can used ServerResource#onSent callback for this or the ConnectorService#afterSend method. Best regards, Jerome Louvel -- Restlet ~ Founder and Technical Lead ~ http://www.restlet.org Noelios Technologies ~ http://www.noelios.com 2010/4/26 Nico Van Cleemput > Yes, I had thought about that, but a filter has a beforeHandle() and a > afterHandle() method, so I can easily set up a transaction before the > handling and easily perform a commit or a rollback in after the handling. > > If I would use a BaseResource I would need to add these calls for each > extending class, or are there provisions for such a use? Although thinking > it through again at this moment, I probably need to overwrite the handle() > method in ServerResource to obtain this behaviour? > > Thanks, > Nico > -- > View this message in context: > http://restlet-discuss.1400322.n2.nabble.com/Restlet-and-DAO-tp4962381p4962438.html > Sent from the Restlet Discuss mailing list archive at Nabble.com. > > -- > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2595911 > -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2596144
Re: Restlet and DAO
Yes, I had thought about that, but a filter has a beforeHandle() and a afterHandle() method, so I can easily set up a transaction before the handling and easily perform a commit or a rollback in after the handling. If I would use a BaseResource I would need to add these calls for each extending class, or are there provisions for such a use? Although thinking it through again at this moment, I probably need to overwrite the handle() method in ServerResource to obtain this behaviour? Thanks, Nico -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-and-DAO-tp4962381p4962438.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2595911
Re: Restlet and DAO
Hi Nico, How about injecting your DAO on a BaseResource class and extending this in every resource? -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-and-DAO-tp4962381p4962395.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2595901