You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@roller.apache.org by Allen Gilliland <Al...@Sun.COM> on 2006/03/01 05:45:39 UTC
Roller persistence transactions, do we need begin(), commit(),
rollback()?
I have been going through some of the Roller backend and looking at some
parts of our Hibernate implementation and I have gotten myself to
wondering if we really need the transaction methods begin() and commit()
which are part of the Roller and PersistenceStrategy interfaces.
I think I understand where the idea for these methods came from and they
make some sense, but after inspecting the code a bit it seems like we
definitely don't actually use them.
In the current code I only see this ...
Roller.begin() - 6 uses
Roller.begin(user) - 4 uses
Roller.commit() - 7 uses
Roller.rollback() - 0 uses
PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
I also noticed that in our Hibernate implementation we aren't actually
using Transactions anyways, so even if these methods were in full use we
wouldn't have been taking advantage of them.
So, the deal is that if we want to use these transaction methods then we
need to make sure we are using them *everywhere*, otherwise they are
doing us no good and only confusing things. Alternatively I would
propose that we drop these methods and let implementors of a persistence
strategy handle the details of transactions within their own
implementations.
My vote is to drop these methods. I can see the potential value in
having them (if they were working properly), but my opinion is that we
aren't really doing any persistence transactions complicated enough to
really warrant the additional complexity and overhead of having them.
We have to go one way or the other, so we either remove them or add them
in everywhere.
Who else has an opinion?
-- Allen
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Wed, 2006-03-01 at 10:18, David M Johnson wrote:
> On Mar 1, 2006, at 1:06 PM, Allen Gilliland wrote:
> > On Wed, 2006-03-01 at 05:28, David M Johnson wrote:
> >>> In the current code I only see this ...
> >>>
> >>> Roller.begin() - 6 uses
> >>> Roller.begin(user) - 4 uses
> >>> Roller.commit() - 7 uses
> >>> Roller.rollback() - 0 uses
> >>> PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
> >>> PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
> >>
> >> Where are you getting that data? Netbeans reports 159 usages of
> >> Roller.commit() and 17 usages of Roller.rollback().
> >
> > hmm, i am using netbeans as well.
> >
> > i was using the "Find Usages" function and only counting uses in
> > the "src" directory, not tests, etc. it does look like netbeans
> > isn't including some usages of "commit" for some reason, i do see
> > it appear more times if i do a search. however, i would say that
> > uses of begin() and rollback() are the same numbers that i gave
> > before, they are obviously not being used everywhere.
>
> I would expect the numbers for begin() to be small. The pattern is
> that we call begin() when we start processing a request, if changes
> are made during the request the action that makes them MUST call
> commit(), and then when we finish processing a request we call
> rollback() just for good measure.
I don't understand that procedure. That sounds like a little bit of a mixup between the concept of a "session" and a "transaction". I am basing this off of the way Hibernate is patterned, but a "session" is often associated with an entire request/response cycle, while a "transaction" represents a single opertion on the data store. So you may have multiple "transactions" in a single "session".
I don't think we want to open a transaction at the beginning of the request. A transaction should be open and closed *only* when you are actually accessing the data store and performing an operation. A transaction also should not span more operations that it is supposed to. Each individual load(), store(), or delete() should be its own transaction unless you are doing multiple interdependent operations which must all happen atomically.
My understanding is that the begin() method starts a transaction and either commit() or rollback() ends the transaction, we then have release() to close a session that may still be open. So the procedure is ...
begin() - opens session if needed, starts transaction
... do your work ... load, store, delete ...
if(success)
commit() - transaction completed and saved
else
rollback() - transaction completed and not saved
release() - when we no longer need to do any transactions
I'm sorry, but this is not the way we are really using these functions.
And just to make sure I am properly representing my view point, I am not saying that we don't need to support transactions. I am merely saying that the way things are currently setup I don't believe we are properly using the transaction methods we have and those methods are not actually doing what they suggest. For that reason I believe our current implementation is a little broken.
At the same time, and partly based on that observation, I am posing the question of ... do we really need those methods to be called from outside the persistence layer by classes in the presentation layer? Instead, could we not simply leave the transaction logic up to the implementor of the persistence strategy?
-- Allen
>
> - Dave
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 1, 2006, at 1:06 PM, Allen Gilliland wrote:
> On Wed, 2006-03-01 at 05:28, David M Johnson wrote:
>>> In the current code I only see this ...
>>>
>>> Roller.begin() - 6 uses
>>> Roller.begin(user) - 4 uses
>>> Roller.commit() - 7 uses
>>> Roller.rollback() - 0 uses
>>> PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
>>> PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
>>
>> Where are you getting that data? Netbeans reports 159 usages of
>> Roller.commit() and 17 usages of Roller.rollback().
>
> hmm, i am using netbeans as well.
>
> i was using the "Find Usages" function and only counting uses in
> the "src" directory, not tests, etc. it does look like netbeans
> isn't including some usages of "commit" for some reason, i do see
> it appear more times if i do a search. however, i would say that
> uses of begin() and rollback() are the same numbers that i gave
> before, they are obviously not being used everywhere.
I would expect the numbers for begin() to be small. The pattern is
that we call begin() when we start processing a request, if changes
are made during the request the action that makes them MUST call
commit(), and then when we finish processing a request we call
rollback() just for good measure.
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Wed, 2006-03-01 at 05:28, David M Johnson wrote:
> >
> > In the current code I only see this ...
> >
> > Roller.begin() - 6 uses
> > Roller.begin(user) - 4 uses
> > Roller.commit() - 7 uses
> > Roller.rollback() - 0 uses
> > PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
> > PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
>
> Where are you getting that data? Netbeans reports 159 usages of
> Roller.commit() and 17 usages of Roller.rollback().
hmm, i am using netbeans as well.
i was using the "Find Usages" function and only counting uses in the "src" directory, not tests, etc. it does look like netbeans isn't including some usages of "commit" for some reason, i do see it appear more times if i do a search. however, i would say that uses of begin() and rollback() are the same numbers that i gave before, they are obviously not being used everywhere.
>
>
> > I also noticed that in our Hibernate implementation we aren't actually
> > using Transactions anyways, so even if these methods were in full
> > use we
> > wouldn't have been taking advantage of them.
> >
> > So, the deal is that if we want to use these transaction methods
> > then we
> > need to make sure we are using them *everywhere*, otherwise they are
> > doing us no good and only confusing things. Alternatively I would
> > propose that we drop these methods and let implementors of a
> > persistence
> > strategy handle the details of transactions within their own
> > implementations.
> >
> > My vote is to drop these methods. I can see the potential value in
> > having them (if they were working properly), but my opinion is that we
> > aren't really doing any persistence transactions complicated enough to
> > really warrant the additional complexity and overhead of having them.
> > We have to go one way or the other, so we either remove them or add
> > them
> > in everywhere.
> >
> > Who else has an opinion?
>
> I feel pretty strongly that we need to follow that very simple and easy
> to follow pattern, keep the transaction methods and make sure they
> work properly. There are definitely situations where we want to be
> atomic.
I agree, we certainly need to maintain proper transactions for some of our writes, but my biggest question is ... can that transaction logic be handled in the persistence layer itself? meaning, can the transaction logic happen behind the scenes of our manager classes?
>
> Roller was originally developed with a database that didn't support
> referential integrity or transactions, but I still tried to do the
> right thing
> so that, at some point in the future it would be easy to move to a
> database
> that did support those things.
>
> I vote that we turn on transaction support in Hibernate and make sure
> those begin(), commit() and rollback() methods are working properly.
this is the tricky part, because proper transactions also means that you must begin() and commit() or rollback() even when you are only doing a query. basically, every access to the persistence layer should be wrapped inside a transaction, and i don't believe we are doing that right now.
i have more comments in response to Anil's email.
-- Allen
>
> - Dave
>
>
>
>
> >
> > -- Allen
> >
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Feb 28, 2006, at 11:45 PM, Allen Gilliland wrote:
> I have been going through some of the Roller backend and looking at
> some
> parts of our Hibernate implementation and I have gotten myself to
> wondering if we really need the transaction methods begin() and
> commit()
> which are part of the Roller and PersistenceStrategy interfaces.
>
> I think I understand where the idea for these methods came from and
> they
> make some sense, but after inspecting the code a bit it seems like we
> definitely don't actually use them.
>
> In the current code I only see this ...
>
> Roller.begin() - 6 uses
> Roller.begin(user) - 4 uses
> Roller.commit() - 7 uses
> Roller.rollback() - 0 uses
> PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
> PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
Where are you getting that data? Netbeans reports 159 usages of
Roller.commit() and 17 usages of Roller.rollback().
> I also noticed that in our Hibernate implementation we aren't actually
> using Transactions anyways, so even if these methods were in full
> use we
> wouldn't have been taking advantage of them.
>
> So, the deal is that if we want to use these transaction methods
> then we
> need to make sure we are using them *everywhere*, otherwise they are
> doing us no good and only confusing things. Alternatively I would
> propose that we drop these methods and let implementors of a
> persistence
> strategy handle the details of transactions within their own
> implementations.
>
> My vote is to drop these methods. I can see the potential value in
> having them (if they were working properly), but my opinion is that we
> aren't really doing any persistence transactions complicated enough to
> really warrant the additional complexity and overhead of having them.
> We have to go one way or the other, so we either remove them or add
> them
> in everywhere.
>
> Who else has an opinion?
I feel pretty strongly that we need to follow that very simple and easy
to follow pattern, keep the transaction methods and make sure they
work properly. There are definitely situations where we want to be
atomic.
Roller was originally developed with a database that didn't support
referential integrity or transactions, but I still tried to do the
right thing
so that, at some point in the future it would be easy to move to a
database
that did support those things.
I vote that we turn on transaction support in Hibernate and make sure
those begin(), commit() and rollback() methods are working properly.
- Dave
>
> -- Allen
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 2, 2006, at 8:39 PM, Allen Gilliland wrote:
> Unfortunately, this is where I will be even more bitchy and say
> that I am not willing to wait around for everyone else. My
> personal opinion is that any code that isn't going to be commited
> within a week or two will just have to be modified to keep up with
> what's in the trunk. Obviously there are exceptions to this which
> can be coordinated through the community, but I consider those
> exceptions and not the default.
>
> These are all valid reasons to possibly delay, but ...
>
> 1. I have not heard a single thing from Craig Russell on this list
> and still very little status about a JDO backend. In any case,
> waiting wouldn't change anything because the JDO classes would
> still have to be modified at some point.
>
> 2. You haven't even started on the EJB3 implementation yet based on
> what you said. Why not reverse things and you wait a little while
> until I cleanup the backend so that you have less work to do
> whenever you do start an EJB3 implementation.
>
> 3. The tagging code would likely require little to no changes based
> on what I am proposing. If anything they would only have to remove
> some method calls to begin()/commit()/rollback() and possibly tidy
> up a couple things in any manager classes they created.
That's a valid point of view and I think it reveals a disconnect
here. I'm thinking that refactoring the back-end to support
transactions (but not to use the begin(), commit() and rollback()
mechanism we have now), would be a very large change. You're
indicating that it is small and would not change the back-end API
much at all. So let's see a proposal that details the changes.
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Thu, 2006-03-02 at 17:03, David M Johnson wrote:
> On Mar 2, 2006, at 6:53 PM, Allen Gilliland wrote:
> > On Thu, 2006-03-02 at 14:31, David M Johnson wrote:
> >> On Mar 2, 2006, at 1:55 PM, Allen Gilliland wrote:
> >>> On Wed, 2006-03-01 at 22:00, Anil Gangolli wrote:
> >>>> OK. -1. I'm against dropping them until we understand the
> >>>> pattern that
> >>>> is being proposed to replace them.
> >>> The pattern would be to encapsulate things in logical operations in
> >>> the manager classes. When you do things like weblog.delete() or
> >>> user.delete() or register a weblog, those things are multi step
> >>> operations to the persistence layer, but they are a single
> >>> operation logically.
> >>
> >> That's a good goal to have, but we're not there yet and it will take
> >> significant refactoring to get there. I totally agree that there is
> >> too much app logic in the presentation layer. That stuff should be
> >> moved into the manager classes behind the Roller interface.
> >
> > I'm sorry if this sounds like badgering, but "we're not there yet"
> > because nobody has stepped up and 1) identified the problem and 2)
> > said they will do the work. I am saying right now that I will do
> > that work because I think it's an extremely important and
> > fundamental aspect of the application which I believe is currently
> > not working properly.
>
> I'm definitely for refactoring to move app and persistence logic to
> the back end, would like to see some proposals and would love to
> help, but we should take somethings into consideration before we
> starting making changes.
>
> It's mostly about timing:
>
> - We have tagging work from Elias being that we need to get into the
> trunk. Probably want to hold off on refactoring until that is
> integrated as any changes will make the work harder to integrate.
>
> - Craig Russell was working on a JDO port of the back-end.
> Refactoring will clash with his work to (assuming it is still underway).
>
> - While refactoring is going on it will be more difficult for others
> to work on EJB3 or JDO stuff. For example, now that I'm getting my
> free time back (book is done next week) I'm personally interested in
> pursuing the EJB3 alternative.
Unfortunately, this is where I will be even more bitchy and say that I am not willing to wait around for everyone else. My personal opinion is that any code that isn't going to be commited within a week or two will just have to be modified to keep up with what's in the trunk. Obviously there are exceptions to this which can be coordinated through the community, but I consider those exceptions and not the default.
These are all valid reasons to possibly delay, but ...
1. I have not heard a single thing from Craig Russell on this list and still very little status about a JDO backend. In any case, waiting wouldn't change anything because the JDO classes would still have to be modified at some point.
2. You haven't even started on the EJB3 implementation yet based on what you said. Why not reverse things and you wait a little while until I cleanup the backend so that you have less work to do whenever you do start an EJB3 implementation.
3. The tagging code would likely require little to no changes based on what I am proposing. If anything they would only have to remove some method calls to begin()/commit()/rollback() and possibly tidy up a couple things in any manager classes they created.
>
> But there are also technical issues:
>
> - We don't want to do things that will reduce our ability to move to
> JDO or EJB3 in the future (e.g. Matt mentioned Spring's declarative
> transactions, would that cause problems or redundancy if we moved to
> EJB3 at some point?)
I don't see that that could happen. I am not proposing that we remove any functionality, I am suggesting that our code be refactored a bit so that some functionality (for persistence transactions) be handled behind the scenes of the persistence layer.
>
>
> Also, what specific thing are you referring to when you say "not
> working properly"
I am referring to the fact that we are not actively calling begin() before each transaction, and even though we call commit() quite a lot we never call rollback(). This coupled with the fact that we aren't using Hibernate's Transaction functionality leads me to believe that we are not truly using transactions right now.
>>From what I see in the code it looks like an unfinished thought where much of the work is there, but it isn't completed to the point of full functionality.
-- Allen
>
>
> >>> We may open and close our db connection many times in a given
> >>> request/response cycle in order to fetch data and/or save it.
> >>
> >> That's not a good idea. The design has always been to use *at most*
> >> one database connection in the processing a request. If that's not
> >> happening, then we have a bug.
> >
> > I think we are mixing concepts again. First off, unless someone is
> > not using a connection pool then technically their database
> > connection is always open. A normal connection pool keeps all of
> > its connections to the database open at all times.
>
> That's what I thought too, but I found though experience that the
> most performant approach was to get a connection at the start of a
> request and return it to the pool at the end.
>
>
> > Secondly, a transaction is more like opening a Statement for
> > execution, not opening an entirely new database connection. I am
> > not positive, but I believe Hibernate ensures that only a single
> > database connection is associated with a Session until the Session
> > is closed.
>
> Yes, that is correct. A session has a one connection.
>
>
> > So we are agreeing on the same pattern, you open a Session once per
> > request and during that Session you perform any number of
> > Transactions.
>
> Yes.
>
>
> > again, I think we are crossing our vocabulary. I think of a
> > transaction as being a single atomic unit of work done against the
> > database. You may do multiple sql operations in a single
> > transaction, but the transaction as a whole represents one unit of
> > work. An entire request does not have to be a single transaction
> > in my mind.
>
> Yes, I was using transaction in a more general sense, but it is true
> that most Roller requests do one database transaction (i.e. issue one
> commit() call to make changes to the database).
>
>
> > Consider. In a single request you may start by querying for a
> > dozen objects which you will use along the way, perhaps the
> > UserData for the user who is logged in, etc. Then the request hits
> > the proper struts action class where it collects data from the
> > request object, formats it, and uses it to store a new weblog
> > entry. Then you continue on to the view where you find you need to
> > query for a few more objects used to populate the display.
>
> I see what you mean. I wasn't considering a query to be a transaction.
>
>
> >> Maybe so, but until we've refactored all app and persistence logic
> >> into the back-end managers, we need begin(), commit() and rollback().
> >
> > Ok, then how about I go ahead and do that?
> >> And even after we've done that, we may still need Open Session in
> >> View:
> >> http://www.hibernate.org/43.html
> >
> > There is nothing that prevents us from doing this.
>
> I think we two are in agreement on this.
>
> - Dave
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Sean Gilligan <se...@msgilligan.com>.
I still don't know the Roller code, but...
I think the Spring declarative transaction approach could be a good fit
for Roller. The transactions would be implemented in proxied versions
of the manager classes and would be defined in an XML file and not
require any explicit code.
The same declarations should be able to be used for Hibernate, JDO, OJB,
or EJB3/JPA.
Wiring up the Managers with Spring would facilitate plugging in
alternate implementations of the Managers as well and make it easier to
co-ordinate the different back-end projects in process or under
consideration.
David M Johnson wrote:
>
> - While refactoring is going on it will be more difficult for others to
> work on EJB3 or JDO stuff. For example, now that I'm getting my free
> time back (book is done next week) I'm personally interested in pursuing
> the EJB3 alternative.
I assume you mean the JPA part of EJB3 that can work outside of a J2EE
server, right?
>
> But there are also technical issues:
>
> - We don't want to do things that will reduce our ability to move to JDO
> or EJB3 in the future (e.g. Matt mentioned Spring's declarative
> transactions, would that cause problems or redundancy if we moved to
> EJB3 at some point?)
It looks like Spring 2.0 has support for JPA, so it should be possible
to use Spring transactions for Hibernate, JDO, and EJB3/JPA.
There's some discussion of Spring + EJB3/JPA here:
http://www.theserverside.com/news/thread.tss?thread_id=38538
-- Sean
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Wed, 2006-03-08 at 23:24, Anil Gangolli wrote:
> Allen Gilliland wrote:
> > just a reminder, silence == consent. i am planning to move forward with development on this.
> >
> > -- Allen
> >
> I added some comments to the proposal page (Design Overview Section 2).
> There are some considerations you really should take into account if you
> move the transaction demarcation into the managers.
sorry, i didn't see that.
>
> I understand your goals, and I'd just urge taking a couple of
> precautions. There are some dangerous curves on that road. You might
> want to do the development in a branch and integrate back when you've
> got the kinks out. You might also want to talk with some folks whose
> knowledge of transaction management you trust.
>
> Finally, (though I know I'm unlikely to convince you), you might want to
> consider an alternate strategy that removes explicit transaction
> demarcation calls from the app layer, but rather than putting them into
> the manager layer, puts them at a small number of well-defined points in
> the request dispatch infrastructure (above/outside the app layer proper
> rather than below it). I think this is closer to the existing Roller
> design (before such calls proliferated into the present mess).
I'm not sure exactly what points you are talking about. You mean like before/after a struts action? beginning/end of a request/response?
The only reason I am reluctant to push this logic anywhere outside the persistence layer is because I find that in some cases I may want to do 2 or more transactions in a single request, but those transactions should be independent of each other. So I would need to know that transaction 1 had succeeded before deciding to do transaction 2. If the transaction demarcation was pushed somewhere outside my ability to notice it then my operations may not be wrapped in transactions the way I expect.
>
> Matt's suggestion of using Spring's declarative demarcation is another
> good alternative.
>
> My number one suggestion is that no matter which way you go, pick one of
> the known and commonly used patterns and adopt it, and depending on the
> choice you may find existing infrastructure that supports it that you
> can also adopt.
I am actually of the belief that the pattern I suggested is commonly known and used. Maybe it's just me, but in all of my experience with apps of similar complexity to Roller I have never had the need to push transaction demarcation outside the persistence layer. Granted that, like Roller, the persistence layer is more generalized type Manager layer.
As I said in my proposal I believe that increases complexity and introduces a potential for problems if someone accidentally (or purposely) doesn't include the correct transaction demarcation methods around their code. I think I could reasonably argue that is the case with the Roller codebase right now. The methods are there, but they are not fully implemented, which is confusing.
-- Allen
>
> --a.
>
>
>
> >
> > On Mon, 2006-03-06 at 13:25, Allen Gilliland wrote:
> >
> >> Okay, here is a more flushed out proposal of what I think should be done ...
> >>
> >> http://rollerweblogger.org/wiki/Wiki.jsp?page=Proposal_BackendRefactorings
> >>
> >> Note that the driving force behind these changes is to 1) prevent direct access to the PersistenceStrategy from outside the business layer and 2) limit persistence logic (like transaction details) to the business layer.
> >>
> >> I think those are very appropriate goals to have for the architecture of our code.
> >>
> >> -- Allen
> >>
> >>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
Allen Gilliland wrote:
> just a reminder, silence == consent. i am planning to move forward with development on this.
>
> -- Allen
>
I added some comments to the proposal page (Design Overview Section 2).
There are some considerations you really should take into account if you
move the transaction demarcation into the managers.
I understand your goals, and I'd just urge taking a couple of
precautions. There are some dangerous curves on that road. You might
want to do the development in a branch and integrate back when you've
got the kinks out. You might also want to talk with some folks whose
knowledge of transaction management you trust.
Finally, (though I know I'm unlikely to convince you), you might want to
consider an alternate strategy that removes explicit transaction
demarcation calls from the app layer, but rather than putting them into
the manager layer, puts them at a small number of well-defined points in
the request dispatch infrastructure (above/outside the app layer proper
rather than below it). I think this is closer to the existing Roller
design (before such calls proliferated into the present mess).
Matt's suggestion of using Spring's declarative demarcation is another
good alternative.
My number one suggestion is that no matter which way you go, pick one of
the known and commonly used patterns and adopt it, and depending on the
choice you may find existing infrastructure that supports it that you
can also adopt.
--a.
>
> On Mon, 2006-03-06 at 13:25, Allen Gilliland wrote:
>
>> Okay, here is a more flushed out proposal of what I think should be done ...
>>
>> http://rollerweblogger.org/wiki/Wiki.jsp?page=Proposal_BackendRefactorings
>>
>> Note that the driving force behind these changes is to 1) prevent direct access to the PersistenceStrategy from outside the business layer and 2) limit persistence logic (like transaction details) to the business layer.
>>
>> I think those are very appropriate goals to have for the architecture of our code.
>>
>> -- Allen
>>
>>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
Anil, thanks for taking a look. I have some comments inline ...
Anil Gangolli wrote:
> Hi Allen:
>
> I took a quick, not very thorough look. A couple of comments/questions:
>
> (1) In the manager implementations, there are some method bodies now
> that have the following pattern:
>
> try {
> this.strategy.getSession().beginTransaction();
> ... do some work
> this.strategy.getSession().getTransaction().commit();
> } catch (HibernateException ex) {
> try {
> this.strategy.getSession().getTransaction().rollback();
> } catch (HibernateException ex) {
> log.error("Error during rollback", he);
> }
> strategy.release();
> throw new RollerException(ex);
> }
>
> The first catch probably needs to be much more general, catching either
> Exception or Throwable. Perhaps the second too, or put the release in
> a finally at that scope. This form of exception handling recurs often
> enough to make it an additional method (on the Hibernate strategy?)
I can change it to catch a greater scope of exceptions, but I believe
Hibernate wraps all of its exceptions in some version of the
HibernateException, so I imagine this should be fine.
>
> (2) Some methods commit, but some do not; they use
> beginTransaction() (which does have the appropriate conditional
> semantics) but do not commit. This seems to be intentional and intended
> to facilitate composition of calls within one transaction for those
> methods. However, I coudn't see an easy way to tell which methods are
> of which type without looking at the method bodies. This could be
> handled in the JavaDoc comments or perhaps better by some naming
> conventions.
All XXXManager methods are committed before ending. Some methods in the
HibernatePersistenceStrategy class do not commit for the reason you
mentioned, so that they can be used multiple times before committing.
There are some methods of the HibernatePersistenceStrategy which do
commit, but I think they are clearly marked as xxxAndCommit().
So I'm not really sure where the confusion is coming from. In general,
the assumption moving forward is that any call to XXXManager.method()
results in a commit, assuming it is a write operation.
>
> (3) Concern/question: With this scoping of commit() we might see
> increased likelihood of weird behavior in views immediately after
> commits on some databases. In particular (a) in some databases they
> might not yet reflect committed changes of the transaction just
> committed in other transactions and (b) we might hit
> LazyInitializationExceptions . For some background on the latter issue
> see the Hibernate reference manual Section 11.1 and 11.1.1, and
> http://www.hibernate.org/43.html, particularly the FAQ 'Can I commit the
> transaction before rendering the view?' The latter problem could be
> addressed by ensuring we create a second transaction for the view before
> any objects in the session get referenced by the view code; maybe this
> is what you are already doing, but it wasn't clear this is happening.
> Is it already dealt with?
This sounds more like a Hibernate issue than an architecture issue to
me. The fact is that this issue will exist in any implementation
because thread1 could have just committed some changes a split second
after thread2 read those same objects for use. Obviously we don't want
to be getting LazyInitializationExceptions, but again, that is a
Hibernate issue, not an architecture issue.
Hibernate demands that all operations happen within a transaction, so if
you peek at the code you will see that all XXXManager methods begin with
a call to session.beginTransaction().
>
> (4) Impertinent comment: The approach of moving the demarcation up to a
> Filter (rather than down to the manager code) still seems cleaner and
> more conventional to me.
I am still not sure I believe this, but I am happy to do it if we really
need to.
-- Allen
>
> --a.
>
>
> ----- Original Message ----- From: "Allen Gilliland"
> <Al...@Sun.COM>
> To: <ro...@incubator.apache.org>
> Sent: Saturday, April 08, 2006 6:26 PM
> Subject: Re: Roller persistence transactions, do we need begin(),
> commit(), rollback()?
>
>
>> Ok, first set of changes have been committed for anyone who wants to
>> take a look.
>>
>> Most of the re-architecting has been done now and I have begun
>> cleaning up the things that got broken in the process. So far I have
>> cleaned up pretty much all of the basic stuff, including operations on
>> users, roles, websites, permissions, and website templates.
>>
>> The next things I'll be cleaning up will be pings, weblog contents
>> (entries, categories, bookmarks, comments, referers), and then the
>> planet manager.
>>
>> -- Allen
>>
>>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
a couple more comments inline ...
Anil Gangolli wrote:
> Inlining again. Sorry.
>
*snip*
>>
>> I can change it to catch a greater scope of exceptions, but I believe
>> Hibernate wraps all of its exceptions in some version of the
>> HibernateException, so I imagine this should be fine.
>>
>
> The concern is that other calls made, not just Hibernate work, in the
> "...do some work" sections can throw different runtime exceptions and
> errors between the two points.
that makes sense. i'll change it to catch all Throwables.
*snip*
>
>>>
>>> (3) Concern/question: With this scoping of commit() we might see
>>> increased likelihood of weird behavior in views immediately after
>>> commits on some databases. In particular (a) in some databases they
>>> might not yet reflect committed changes of the transaction just
>>> committed in other transactions and (b) we might hit
>>> LazyInitializationExceptions . For some background on the latter
>>> issue see the Hibernate reference manual Section 11.1 and 11.1.1, and
>>> http://www.hibernate.org/43.html, particularly the FAQ 'Can I commit
>>> the transaction before rendering the view?' The latter problem could
>>> be addressed by ensuring we create a second transaction for the view
>>> before any objects in the session get referenced by the view code;
>>> maybe this is what you are already doing, but it wasn't clear this is
>>> happening. Is it already dealt with?
>>
>> This sounds more like a Hibernate issue than an architecture issue to
>> me. The fact is that this issue will exist in any implementation
>> because thread1 could have just committed some changes a split second
>> after thread2 read those same objects for use. Obviously we don't
>> want to be getting LazyInitializationExceptions, but again, that is a
>> Hibernate issue, not an architecture issue.
>>
>
>> Hibernate demands that all operations happen within a transaction, so
>> if you peek at the code you will see that all XXXManager methods begin
>> with a call to session.beginTransaction().
>>
>
> No it's not a Hibernate issue. However, if all of our operations
> forward to views which go back to the manager methods as you indicate to
> repopulate a session, then we're probably fine.
I still think this is somewhat related to the way Hibernate works and is
not necessarily a problem with our architecture. In either case I still
don't see this as a problem because the Hibernate Session remains open
throughout the entire request/response cycle, so it should be impossible
to end up with a detached object that ends up causing problems.
The only thing that happens after an XXXManager write method is called
is that we commit a transaction, but a single Session can use multiple
transactions without any problems. The Open Session in View link you
sent out even suggests this can be a good idea ...
"Can I use two transactions in one Session?
Yes, this is actually a better implementation of this pattern. One
database transaction is used to read and write data during the
processing of the request event. The second database transaction is only
used to read data, during rendering of the view. ... "
That is the exact pattern that I am implementing. Namely, the first
time something is fetched from the db the Session is opened and a
Transaction begins. *If* a write operation occurs we do it once and
commit the changes to the db, then open up a new Transaction for any
other queries that need to happen in order to render the view. At the
end of the request we close the Session and return the response.
-- Allen
Re: Roller persistence transactions, do we need begin(), commit(), rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
Inlining again. Sorry.
----- Original Message -----
From: "Allen Gilliland" <Al...@Sun.COM>
To: <ro...@incubator.apache.org>
Sent: Monday, April 10, 2006 9:28 AM
Subject: Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
> Anil, thanks for taking a look. I have some comments inline ...
>
> Anil Gangolli wrote:
>> Hi Allen:
>>
>> I took a quick, not very thorough look. A couple of comments/questions:
>>
>> (1) In the manager implementations, there are some method bodies now that
>> have the following pattern:
>>
>> try {
>> this.strategy.getSession().beginTransaction();
>> ... do some work
>> this.strategy.getSession().getTransaction().commit();
>> } catch (HibernateException ex) {
>> try {
>> this.strategy.getSession().getTransaction().rollback();
>> } catch (HibernateException ex) {
>> log.error("Error during rollback", he);
>> }
>> strategy.release();
>> throw new RollerException(ex);
>> }
>>
>> The first catch probably needs to be much more general, catching either
>> Exception or Throwable. Perhaps the second too, or put the release in
>> a finally at that scope. This form of exception handling recurs often
>> enough to make it an additional method (on the Hibernate strategy?)
>
> I can change it to catch a greater scope of exceptions, but I believe
> Hibernate wraps all of its exceptions in some version of the
> HibernateException, so I imagine this should be fine.
>
The concern is that other calls made, not just Hibernate work, in the "...do
some work" sections can throw different runtime exceptions and errors
between the two points.
>>
>> (2) Some methods commit, but some do not; they use
>> beginTransaction() (which does have the appropriate conditional
>> semantics) but do not commit. This seems to be intentional and intended
>> to facilitate composition of calls within one transaction for those
>> methods. However, I coudn't see an easy way to tell which methods are of
>> which type without looking at the method bodies. This could be handled in
>> the JavaDoc comments or perhaps better by some naming conventions.
>
> All XXXManager methods are committed before ending. Some methods in the
> HibernatePersistenceStrategy class do not commit for the reason you
> mentioned, so that they can be used multiple times before committing.
> There are some methods of the HibernatePersistenceStrategy which do
> commit, but I think they are clearly marked as xxxAndCommit().
>
> So I'm not really sure where the confusion is coming from. In general,
> the assumption moving forward is that any call to XXXManager.method()
> results in a commit, assuming it is a write operation.
>
OK. I must have missed this pattern.
>>
>> (3) Concern/question: With this scoping of commit() we might see
>> increased likelihood of weird behavior in views immediately after commits
>> on some databases. In particular (a) in some databases they might not
>> yet reflect committed changes of the transaction just committed in other
>> transactions and (b) we might hit LazyInitializationExceptions . For
>> some background on the latter issue see the Hibernate reference manual
>> Section 11.1 and 11.1.1, and http://www.hibernate.org/43.html,
>> particularly the FAQ 'Can I commit the transaction before rendering the
>> view?' The latter problem could be addressed by ensuring we create a
>> second transaction for the view before any objects in the session get
>> referenced by the view code; maybe this is what you are already doing,
>> but it wasn't clear this is happening. Is it already dealt with?
>
> This sounds more like a Hibernate issue than an architecture issue to me.
> The fact is that this issue will exist in any implementation because
> thread1 could have just committed some changes a split second after
> thread2 read those same objects for use. Obviously we don't want to be
> getting LazyInitializationExceptions, but again, that is a Hibernate
> issue, not an architecture issue.
>
> Hibernate demands that all operations happen within a transaction, so if
> you peek at the code you will see that all XXXManager methods begin with a
> call to session.beginTransaction().
>
No it's not a Hibernate issue. However, if all of our operations forward to
views which go back to the manager methods as you indicate to repopulate a
session, then we're probably fine.
>
>>
>> (4) Impertinent comment: The approach of moving the demarcation up to a
>> Filter (rather than down to the manager code) still seems cleaner and
>> more conventional to me.
>
> I am still not sure I believe this, but I am happy to do it if we really
> need to.
>
> -- Allen
>
>
>>
>> --a.
>>
>>
>> ----- Original Message ----- From: "Allen Gilliland"
>> <Al...@Sun.COM>
>> To: <ro...@incubator.apache.org>
>> Sent: Saturday, April 08, 2006 6:26 PM
>> Subject: Re: Roller persistence transactions, do we need begin(),
>> commit(), rollback()?
>>
>>
>>> Ok, first set of changes have been committed for anyone who wants to
>>> take a look.
>>>
>>> Most of the re-architecting has been done now and I have begun cleaning
>>> up the things that got broken in the process. So far I have cleaned up
>>> pretty much all of the basic stuff, including operations on users,
>>> roles, websites, permissions, and website templates.
>>>
>>> The next things I'll be cleaning up will be pings, weblog contents
>>> (entries, categories, bookmarks, comments, referers), and then the
>>> planet manager.
>>>
>>> -- Allen
>>>
>>>
>>
>
Re: Roller persistence transactions, do we need begin(), commit(), rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
Hi Allen:
I took a quick, not very thorough look. A couple of comments/questions:
(1) In the manager implementations, there are some method bodies now that
have the following pattern:
try {
this.strategy.getSession().beginTransaction();
... do some work
this.strategy.getSession().getTransaction().commit();
} catch (HibernateException ex) {
try {
this.strategy.getSession().getTransaction().rollback();
} catch (HibernateException ex) {
log.error("Error during rollback", he);
}
strategy.release();
throw new RollerException(ex);
}
The first catch probably needs to be much more general, catching either
Exception or Throwable. Perhaps the second too, or put the release in
a finally at that scope. This form of exception handling recurs often
enough to make it an additional method (on the Hibernate strategy?)
(2) Some methods commit, but some do not; they use
beginTransaction() (which does have the appropriate conditional semantics)
but do not commit. This seems to be intentional and intended to facilitate
composition of calls within one transaction for those methods. However, I
coudn't see an easy way to tell which methods are of which type without
looking at the method bodies. This could be handled in the JavaDoc comments
or perhaps better by some naming conventions.
(3) Concern/question: With this scoping of commit() we might see increased
likelihood of weird behavior in views immediately after commits on some
databases. In particular (a) in some databases they might not yet reflect
committed changes of the transaction just committed in other transactions
and (b) we might hit LazyInitializationExceptions . For some background on
the latter issue see the Hibernate reference manual Section 11.1 and 11.1.1,
and http://www.hibernate.org/43.html, particularly the FAQ 'Can I commit the
transaction before rendering the view?' The latter problem could be
addressed by ensuring we create a second transaction for the view before any
objects in the session get referenced by the view code; maybe this is what
you are already doing, but it wasn't clear this is happening. Is it already
dealt with?
(4) Impertinent comment: The approach of moving the demarcation up to a
Filter (rather than down to the manager code) still seems cleaner and more
conventional to me.
--a.
----- Original Message -----
From: "Allen Gilliland" <Al...@Sun.COM>
To: <ro...@incubator.apache.org>
Sent: Saturday, April 08, 2006 6:26 PM
Subject: Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
> Ok, first set of changes have been committed for anyone who wants to take
> a look.
>
> Most of the re-architecting has been done now and I have begun cleaning up
> the things that got broken in the process. So far I have cleaned up
> pretty much all of the basic stuff, including operations on users, roles,
> websites, permissions, and website templates.
>
> The next things I'll be cleaning up will be pings, weblog contents
> (entries, categories, bookmarks, comments, referers), and then the planet
> manager.
>
> -- Allen
>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
Ok, first set of changes have been committed for anyone who wants to
take a look.
Most of the re-architecting has been done now and I have begun cleaning
up the things that got broken in the process. So far I have cleaned up
pretty much all of the basic stuff, including operations on users,
roles, websites, permissions, and website templates.
The next things I'll be cleaning up will be pings, weblog contents
(entries, categories, bookmarks, comments, referers), and then the
planet manager.
-- Allen
David M Johnson wrote:
>
> On Apr 5, 2006, at 12:53 PM, Allen Gilliland wrote:
>
>> I have a couple additional changes that I think should be part of this
>> process ...
>>
>> 1. Remove some old classes.
>
>> 2. Remove user role CRUD methods from UserManager
>>
>> 3. Remove PersistenceStrategy interface.
>>
>> after beginning to work on the backend refactorings i found that the
>> PersistenceStrategy was actually causing some problems because even
>> though it is meant to be simple it forces some of its own ideology
>> about how persistence should be implemented. in particular the
>> PersistenceStrategy methods do not identify what the transaction
>> strategy for those methods are, meaning are they commited after being
>> called? or not? and since the abstract manager impls actually use
>> those methods there is the potential for a mixup.
>>
>> my belief is that the implementor of a given backend implementation
>> should be allowed to do persistence any way they want, as long as they
>> fully implement all the methods defined in the manager interfaces. so
>> for this reason i think it makes sense to not force the use of the
>> PersistenceStrategy.
>>
>> keep in mind that this is a little hard to describe and i believe it
>> becomes a little more clear once you get into the code and see what is
>> happening. also note that i still intend to keep a
>> HibernatePersistenceStrategy class because it does fit nicely with a
>> hibernate implementation, but it is more like a Hibernate utility
>> class rather than a required part of all persistence implementations.
>
> All sounds good to me.
>
> At this point, the PersistenceStrategy is just a thin wrapper and I
> don't think it buys us much in supporting multiple implementations. So,
> no objection here.
>
> - Dave
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Apr 5, 2006, at 12:53 PM, Allen Gilliland wrote:
> I have a couple additional changes that I think should be part of
> this process ...
>
> 1. Remove some old classes.
> 2. Remove user role CRUD methods from UserManager
>
> 3. Remove PersistenceStrategy interface.
>
> after beginning to work on the backend refactorings i found that
> the PersistenceStrategy was actually causing some problems because
> even though it is meant to be simple it forces some of its own
> ideology about how persistence should be implemented. in
> particular the PersistenceStrategy methods do not identify what the
> transaction strategy for those methods are, meaning are they
> commited after being called? or not? and since the abstract
> manager impls actually use those methods there is the potential for
> a mixup.
>
> my belief is that the implementor of a given backend implementation
> should be allowed to do persistence any way they want, as long as
> they fully implement all the methods defined in the manager
> interfaces. so for this reason i think it makes sense to not force
> the use of the PersistenceStrategy.
>
> keep in mind that this is a little hard to describe and i believe
> it becomes a little more clear once you get into the code and see
> what is happening. also note that i still intend to keep a
> HibernatePersistenceStrategy class because it does fit nicely with
> a hibernate implementation, but it is more like a Hibernate utility
> class rather than a required part of all persistence implementations.
All sounds good to me.
At this point, the PersistenceStrategy is just a thin wrapper and I
don't think it buys us much in supporting multiple implementations.
So, no objection here.
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
I have a couple additional changes that I think should be part of this
process ...
1. Remove some old classes.
src/org/roller/business/PubTimeData.java
src/org/roller/business/hibernate/Messages.java
src/org/roller/business/hibernate/HibernatePersistenceSession.java
src/org/roller/business/hibernate/messages.properties
src/org/roller/business/HitCountData.java
we don't need the PersistenceSession thing anymore because Hibernate 3.1
handles Session/Transaction scoping via thread local storage for us.
the other classes don't seem to be used anymore.
2. Remove user role CRUD methods from UserManager
since roles are strictly an attribute of a user, then we have no real
reason to allow direct CRUD methods on that data. i have checked the
code an the only methods which currently use these methods are the
grantRole() and revokeRole() methods of UserData. with hibernate we can
simply set the cascade option for the set of roles in UserData to
"all-delete-orphan" and then all you do is grant/revoke a role and then
save the user.
i have tested this and it works nicely. does anyone object to this
approach?
3. Remove PersistenceStrategy interface.
after beginning to work on the backend refactorings i found that the
PersistenceStrategy was actually causing some problems because even
though it is meant to be simple it forces some of its own ideology about
how persistence should be implemented. in particular the
PersistenceStrategy methods do not identify what the transaction
strategy for those methods are, meaning are they commited after being
called? or not? and since the abstract manager impls actually use
those methods there is the potential for a mixup.
my belief is that the implementor of a given backend implementation
should be allowed to do persistence any way they want, as long as they
fully implement all the methods defined in the manager interfaces. so
for this reason i think it makes sense to not force the use of the
PersistenceStrategy.
keep in mind that this is a little hard to describe and i believe it
becomes a little more clear once you get into the code and see what is
happening. also note that i still intend to keep a
HibernatePersistenceStrategy class because it does fit nicely with a
hibernate implementation, but it is more like a Hibernate utility class
rather than a required part of all persistence implementations.
this is a pretty busy week for me, but i hope to have some code
committed to the roller-newbackend branch either late this week or early
next week.
-- Allen
David M Johnson wrote:
> done - Dave
>
>
> On Apr 2, 2006, at 2:59 PM, Allen Gilliland wrote:
>
>> Dave,
>>
>> can you create a branch for "roller-newbackend" when you get a
>> chance? i'd like to start working on this.
>>
>> -- Allen
>>
>>
>> Allen Gilliland wrote:
>>
>>> I don't think we need to involve Spring for any of these
>>> modifications. Migrating to Spring is a separate step.
>>> -- Allen
>>> Max Rudman wrote:
>>>
>>>> Hi Allen,
>>>>
>>>> Have you looked at Spring transaction management support yet? Your
>>>> proposal doesn't address how you plan to implement multi- step
>>>> operations and I think Spring can really help you there. I am
>>>> more than happy to help with getting that to work.
>>>>
>>>> Max
>>>>
>>>>
>>>> On Mar 27, 2006, at 2:17 PM, Allen Gilliland wrote:
>>>>
>>>>>
>>>>>
>>>>> David M Johnson wrote:
>>>>>
>>>>>> On Mar 27, 2006, at 1:04 PM, Allen Gilliland wrote:
>>>>>>
>>>>>>> so we would be pushing the logic outside the persistence layer
>>>>>>> and expecting someone else to do authentication/authorization,
>>>>>>> not the persistence layer.
>>>>>>
>>>>>> I agree that somebody else should do the authentication, but the
>>>>>> rules about who can do what (authorization) are part of the
>>>>>> application logic of Roller. The more of that we can encapsulate
>>>>>> the better.
>>>>>> Having said that, I can't object to ripping out setUser() and
>>>>>> getUser(). Currently, we double check things. The presentation
>>>>>> layer calls an "is user X authorized to perform action Y on
>>>>>> object Z" style method and then, in the save() method in the
>>>>>> back-end does another check -- but by that time it's too late,
>>>>>> the change has already been made to the persistent instance.
>>>>>> Ripping out the setUser() and getUser() methods will only affect
>>>>>> that second check that the back-end does -- so it's fine by me.
>>>>>> Are you going to leave the existing "is user authorized to edit"
>>>>>> methods in place so that checks can be made from the
>>>>>> presentation layer as they are now?
>>>>>
>>>>>
>>>>> i'm not sure exactly what methods you are talking about, are you
>>>>> talking about the PersistentObject.canSave() methods?
>>>>>
>>>>> i don't think there is any problem with leaving those in place
>>>>> right now, but i think long term we can come up with a better
>>>>> solution.
>>>>>
>>>>> -- Allen
>>>>>
>>>>>
>>>>>> - Dave
>>>>>
>>>>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
done - Dave
On Apr 2, 2006, at 2:59 PM, Allen Gilliland wrote:
> Dave,
>
> can you create a branch for "roller-newbackend" when you get a
> chance? i'd like to start working on this.
>
> -- Allen
>
>
> Allen Gilliland wrote:
>> I don't think we need to involve Spring for any of these
>> modifications. Migrating to Spring is a separate step.
>> -- Allen
>> Max Rudman wrote:
>>> Hi Allen,
>>>
>>> Have you looked at Spring transaction management support yet?
>>> Your proposal doesn't address how you plan to implement multi-
>>> step operations and I think Spring can really help you there. I
>>> am more than happy to help with getting that to work.
>>>
>>> Max
>>>
>>>
>>> On Mar 27, 2006, at 2:17 PM, Allen Gilliland wrote:
>>>
>>>>
>>>>
>>>> David M Johnson wrote:
>>>>> On Mar 27, 2006, at 1:04 PM, Allen Gilliland wrote:
>>>>>> so we would be pushing the logic outside the persistence layer
>>>>>> and expecting someone else to do authentication/authorization,
>>>>>> not the persistence layer.
>>>>> I agree that somebody else should do the authentication, but
>>>>> the rules about who can do what (authorization) are part of the
>>>>> application logic of Roller. The more of that we can
>>>>> encapsulate the better.
>>>>> Having said that, I can't object to ripping out setUser() and
>>>>> getUser(). Currently, we double check things. The presentation
>>>>> layer calls an "is user X authorized to perform action Y on
>>>>> object Z" style method and then, in the save() method in the
>>>>> back-end does another check -- but by that time it's too late,
>>>>> the change has already been made to the persistent instance.
>>>>> Ripping out the setUser() and getUser() methods will only
>>>>> affect that second check that the back-end does -- so it's fine
>>>>> by me.
>>>>> Are you going to leave the existing "is user authorized to
>>>>> edit" methods in place so that checks can be made from the
>>>>> presentation layer as they are now?
>>>>
>>>> i'm not sure exactly what methods you are talking about, are you
>>>> talking about the PersistentObject.canSave() methods?
>>>>
>>>> i don't think there is any problem with leaving those in place
>>>> right now, but i think long term we can come up with a better
>>>> solution.
>>>>
>>>> -- Allen
>>>>
>>>>
>>>>> - Dave
>>>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
Dave,
can you create a branch for "roller-newbackend" when you get a chance?
i'd like to start working on this.
-- Allen
Allen Gilliland wrote:
> I don't think we need to involve Spring for any of these modifications.
> Migrating to Spring is a separate step.
>
> -- Allen
>
>
> Max Rudman wrote:
>> Hi Allen,
>>
>> Have you looked at Spring transaction management support yet? Your
>> proposal doesn't address how you plan to implement multi-step
>> operations and I think Spring can really help you there. I am more
>> than happy to help with getting that to work.
>>
>> Max
>>
>>
>> On Mar 27, 2006, at 2:17 PM, Allen Gilliland wrote:
>>
>>>
>>>
>>> David M Johnson wrote:
>>>> On Mar 27, 2006, at 1:04 PM, Allen Gilliland wrote:
>>>>> so we would be pushing the logic outside the persistence layer and
>>>>> expecting someone else to do authentication/authorization, not the
>>>>> persistence layer.
>>>> I agree that somebody else should do the authentication, but the
>>>> rules about who can do what (authorization) are part of the
>>>> application logic of Roller. The more of that we can encapsulate the
>>>> better.
>>>> Having said that, I can't object to ripping out setUser() and
>>>> getUser(). Currently, we double check things. The presentation layer
>>>> calls an "is user X authorized to perform action Y on object Z"
>>>> style method and then, in the save() method in the back-end does
>>>> another check -- but by that time it's too late, the change has
>>>> already been made to the persistent instance. Ripping out the
>>>> setUser() and getUser() methods will only affect that second check
>>>> that the back-end does -- so it's fine by me.
>>>> Are you going to leave the existing "is user authorized to edit"
>>>> methods in place so that checks can be made from the presentation
>>>> layer as they are now?
>>>
>>> i'm not sure exactly what methods you are talking about, are you
>>> talking about the PersistentObject.canSave() methods?
>>>
>>> i don't think there is any problem with leaving those in place right
>>> now, but i think long term we can come up with a better solution.
>>>
>>> -- Allen
>>>
>>>
>>>> - Dave
>>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
I don't think we need to involve Spring for any of these modifications.
Migrating to Spring is a separate step.
-- Allen
Max Rudman wrote:
> Hi Allen,
>
> Have you looked at Spring transaction management support yet? Your
> proposal doesn't address how you plan to implement multi-step
> operations and I think Spring can really help you there. I am more than
> happy to help with getting that to work.
>
> Max
>
>
> On Mar 27, 2006, at 2:17 PM, Allen Gilliland wrote:
>
>>
>>
>> David M Johnson wrote:
>>> On Mar 27, 2006, at 1:04 PM, Allen Gilliland wrote:
>>>> so we would be pushing the logic outside the persistence layer and
>>>> expecting someone else to do authentication/authorization, not the
>>>> persistence layer.
>>> I agree that somebody else should do the authentication, but the
>>> rules about who can do what (authorization) are part of the
>>> application logic of Roller. The more of that we can encapsulate the
>>> better.
>>> Having said that, I can't object to ripping out setUser() and
>>> getUser(). Currently, we double check things. The presentation layer
>>> calls an "is user X authorized to perform action Y on object Z" style
>>> method and then, in the save() method in the back-end does another
>>> check -- but by that time it's too late, the change has already been
>>> made to the persistent instance. Ripping out the setUser() and
>>> getUser() methods will only affect that second check that the
>>> back-end does -- so it's fine by me.
>>> Are you going to leave the existing "is user authorized to edit"
>>> methods in place so that checks can be made from the presentation
>>> layer as they are now?
>>
>> i'm not sure exactly what methods you are talking about, are you
>> talking about the PersistentObject.canSave() methods?
>>
>> i don't think there is any problem with leaving those in place right
>> now, but i think long term we can come up with a better solution.
>>
>> -- Allen
>>
>>
>>> - Dave
>
Re: Roller persistence transactions, do we need begin(), commit(), rollback()?
Posted by Max Rudman <mr...@steelbrick.com>.
Hi Allen,
Have you looked at Spring transaction management support yet? Your
proposal doesn't address how you plan to implement multi-step
operations and I think Spring can really help you there. I am more
than happy to help with getting that to work.
Max
On Mar 27, 2006, at 2:17 PM, Allen Gilliland wrote:
>
>
> David M Johnson wrote:
>> On Mar 27, 2006, at 1:04 PM, Allen Gilliland wrote:
>>> so we would be pushing the logic outside the persistence layer
>>> and expecting someone else to do authentication/authorization,
>>> not the persistence layer.
>> I agree that somebody else should do the authentication, but the
>> rules about who can do what (authorization) are part of the
>> application logic of Roller. The more of that we can encapsulate
>> the better.
>> Having said that, I can't object to ripping out setUser() and
>> getUser(). Currently, we double check things. The presentation
>> layer calls an "is user X authorized to perform action Y on object
>> Z" style method and then, in the save() method in the back-end
>> does another check -- but by that time it's too late, the change
>> has already been made to the persistent instance. Ripping out the
>> setUser() and getUser() methods will only affect that second check
>> that the back-end does -- so it's fine by me.
>> Are you going to leave the existing "is user authorized to edit"
>> methods in place so that checks can be made from the presentation
>> layer as they are now?
>
> i'm not sure exactly what methods you are talking about, are you
> talking about the PersistentObject.canSave() methods?
>
> i don't think there is any problem with leaving those in place
> right now, but i think long term we can come up with a better
> solution.
>
> -- Allen
>
>
>> - Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
David M Johnson wrote:
>
> On Mar 27, 2006, at 1:04 PM, Allen Gilliland wrote:
>> so we would be pushing the logic outside the persistence layer and
>> expecting someone else to do authentication/authorization, not the
>> persistence layer.
>
> I agree that somebody else should do the authentication, but the rules
> about who can do what (authorization) are part of the application logic
> of Roller. The more of that we can encapsulate the better.
>
> Having said that, I can't object to ripping out setUser() and getUser().
> Currently, we double check things. The presentation layer calls an "is
> user X authorized to perform action Y on object Z" style method and
> then, in the save() method in the back-end does another check -- but by
> that time it's too late, the change has already been made to the
> persistent instance. Ripping out the setUser() and getUser() methods
> will only affect that second check that the back-end does -- so it's
> fine by me.
>
> Are you going to leave the existing "is user authorized to edit" methods
> in place so that checks can be made from the presentation layer as they
> are now?
i'm not sure exactly what methods you are talking about, are you talking
about the PersistentObject.canSave() methods?
i don't think there is any problem with leaving those in place right
now, but i think long term we can come up with a better solution.
-- Allen
>
> - Dave
>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 27, 2006, at 1:04 PM, Allen Gilliland wrote:
> so we would be pushing the logic outside the persistence layer and
> expecting someone else to do authentication/authorization, not the
> persistence layer.
I agree that somebody else should do the authentication, but the
rules about who can do what (authorization) are part of the
application logic of Roller. The more of that we can encapsulate the
better.
Having said that, I can't object to ripping out setUser() and getUser
(). Currently, we double check things. The presentation layer calls
an "is user X authorized to perform action Y on object Z" style
method and then, in the save() method in the back-end does another
check -- but by that time it's too late, the change has already been
made to the persistent instance. Ripping out the setUser() and getUser
() methods will only affect that second check that the back-end does
-- so it's fine by me.
Are you going to leave the existing "is user authorized to edit"
methods in place so that checks can be made from the presentation
layer as they are now?
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
comments inline ...
David M Johnson wrote:
>
> On Mar 26, 2006, at 8:34 PM, Allen Gilliland wrote:
>> I have updated my backend refactoring proposal to include a bit more
>> implementation details.
>> http://rollerweblogger.org/wiki/Wiki.jsp?page=Proposal_BackendRefactorings
>>
>>
>> I have basically listed all the manager classes which use the database
>> and then listed each method of those classes which involves writing data.
>>
>> I still stand behind my proposal that we should remove all persistence
>> specific logic from existing outside the business/presentation layer.
>> I am planning to begin work on this for April and hopefully will get
>> it completed for Roller 2.3
>
> The more I think about this idea, the more I like it. I'd like to see
> the Roller backend be a self-contained API and this appears to be the
> way to achieve that.
cool. glad to hear my powers of persuasion aren't totally defunct ;)
>
> But I'm still opposed to doing this work in the trunk. It involves
> dramatic sweeping changes to the code base and requires that almost
> every Struts action be rewritten. It should done done in a separate
> branch and not merged back until it's been tested an evaluated.
yep. i think that's a good idea as well.
>
> Plus, I've got a couple questions about the plan:
>
> 1) You propose to remove the setUser() and getUser() methods from the
> Roller interface. What is the plan for determining that the current user
> has permission to perform an operation?
ah. i didn't address this specifically anywhere in the proposal, but i
believe there are a couple problems with trying to do permissions
checking the way it is now. my feeling is that this type of check
should not be happening at the persistence layer because the persistence
layer has no way of forcing proper authentication.
right now the system is basically trying to force permission checks on
access to java methods, and i think that is a little tough to do. i
think it's better to leave the persistence layer open to anyone who has
access to the java code and instead expect that our struts actions are
ensuring proper permissions. so instead of trying to enforce
permissions on java methods we are enforcing permissions on access to
various struts actions.
also, we don't really have the right code in place to effectively
enforce permissions on persistence methods for a couple reasons.
1. we never force the appropriate user to be set before a given method
is called. there is nothing in the code preventing someone from just
always setting the user to UserData.SYSTEM_USER. and the code that does
the permissions checking just assumes that the set user is correct.
2. the user can be changed at any time and isn't required to stay the
same once it is set. so even if the code does properly set the user it
can just be overridden. the same way it happens in the
PropertiesManagerImpl.init() method.
so we would be pushing the logic outside the persistence layer and
expecting someone else to do authentication/authorization, not the
persistence layer.
>
> 2) You mention that some operation are "single step persistence
> operations which do not require special transaction considerations."
> What does that mean in practice? Does each of these operations do it's
> own begin() and then end with a commit() or rollback()? Will these
> single step operations be called from the multi-step operations?
this is ultimately up to the implementor of the persistence strategy.
they can do things however they want, as long as they ensure that a call
to any method that writes data is properly transacted.
but yes, i imagine that a singe step operation like
saveWeblogComment(comment) would just begin, then commit/rollback.
speaking specifically about Hibernate, note that calling begin() will
open a new transaction if needed, or join the current transaction if one
is already open. after a commit or rollback a new transaction can begin
if needed, but this will all happen within the same Session.
>
> 3) What is the plan for unit testing the changes to the Struts Actions
> and other presentation classes?
well, most of our unit tests should still work fine, we just need to rip
out the methods I mentioned in the proposal. some of the unit tests
will have to be rewritten/updated though.
>
> 4) How did you come up with the list of changes? I assume you reviewed
> each of the Struts actions. Did you also review the MetaWeblog API and
> Atom protocol implementations?
I built the list initially from our current Manager interfaces and then
modified based on struts actions. I didn't look extensively at the
MetaWeblog API or Atom protocol.
-- Allen
>
> - Dave
>
>
>>
>> -- Allen
>>
>>
>> Allen Gilliland wrote:
>>> Anil Gangolli wrote:
>>>> Allen:
>>>>
>>>> Your suggested pattern is workable, but you'll need to make begin()
>>>> and commit() conditional and smart about transaction demarcation; it
>>>> is a common pattern to conditionally begin a transaction only if
>>>> there isn't one on the current thread, and you'll find that in many
>>>> infrastructures (see my comments on Section 2 in the design proposal).
>>> I agree with this and believe it's fairly easy to do.
>>>>
>>>> What happens if you don't have that logic? You'll find that the
>>>> operations that you choose to make transactional can't be easily
>>>> composed, which is a very awkward property to have. If you ever
>>>> need to compose two operations, you would need to write a third
>>>> method that includes all of the operations of the originals, and not
>>>> just calling the two original methods, but copying their innards. I
>>>> actually went through a period of trying to code apps this way in
>>>> the 90's before infrastructures like EJB started to normalize the
>>>> conditional demarcation patterns in Java. Lesson learned.
>>> You are correct, that is absolutely a possible ramification and we
>>> could end up making it more difficult to properly wrap some steps
>>> together in a transaction. However, I would also argue that the
>>> reverse scenerio is true for our current setup using more open
>>> transaction demarcation. Allowing business/presentation code to
>>> control transaction demarcation allows for transactions to become
>>> overly inclusive and actually end up including more operations than
>>> they should.
>>>>
>>>> The patterns for transaction demarcation in the dispatch layers
>>>> involve three parts: (1) demarcation for requests on a per-request
>>>> basis in a Filter or some other centralized dispatch point (e.g. in
>>>> Axis or Struts apps in extensions of these servlets wrapping the
>>>> entry points) (2) for scheduled tasks, wrapping the run() method in
>>>> a base class (3) providing a mechanism to get an independent
>>>> transaction for individual units of work at smaller granularities
>>>> (REQUIRES_NEW style semantics), which I expect would be used very
>>>> rarely in Roller. Patterns like this work well for two-tier web
>>>> apps like Roller where the persistence container and the webapp
>>>> container are the same. They don't work (or require much stronger
>>>> transaction infrastructure) if you separate the webapp container
>>>> from the persistence container which does not apply in Roller's case.
>>> In order to get a better grasp on some Hibernate details I am
>>> currently skimming through "Hibernate in Action" and they say ...
>>> "We merely observe that, in our opinion, overengineering has been
>>> endemic in the Java community, and overly ambitious multilayered
>>> architectures have significanly contributed to the cose of Java
>>> development and to the perceived complexity of J2EE. On the other
>>> hand, we do agree that a dedicated persistence layer is a sensible
>>> choice for most applications and that persistence-related code
>>> shouldn't be moxed with business logic or presentation." (page 296)
>>> In their examples for designing a layered application (webapp
>>> specifically) they do not provide transaction demarcation outside of
>>> the DAO layer. Of course this is only a single opinion and does not
>>> mean it's what's best for Roller, but I would say that my opinions
>>> are more in line with the sentiments from the quote above.
>>> Speaking more specifically about applying transaction demarcation at
>>> points in the dispatch layer ... I think I still see this as allowing
>>> persistence logic into the business/presentation layer. The other
>>> reason why this makes me nervous is that I think it creates some
>>> potential for two situations ...
>>> 1. catching a persistence exception too late. if the transaction
>>> demarcation doesn't actually commit the transaction data until a
>>> while after the app thinks the data has been written then we may end
>>> up putting ourselves in a situation where we catch an exception after
>>> we have already commited some of the response and are no longer in a
>>> situation where we can respond appropriately. This seems especially
>>> true if we consider each request/response cycle as a single
>>> transaction and only flush/commit the data in a filter as we exit the
>>> app.
>>> 2. commiting data changes we don't want, specifically users being bad
>>> with their templates. I suppose our wrapper objects may take care of
>>> the potential problem with users making changes to their data that we
>>> don't want, but there may also be an issue of app code doing the same
>>> thing. It has always seemed ideal to me to only commit changes
>>> specifically when needed. If a filter simply commits data at the end
>>> of the request/response cycle there is no guarantee that someone
>>> hasn't modified an object that is not meant to be saved back to the
>>> database.
>>>>
>>>> Like your proposal, the dispatch-level patterns remove begin() and
>>>> commit() from app code, and we should end up with only a few places
>>>> that call them.
>>> I like the idea of the dispatch-level pattern much more than our
>>> current pattern. After I spend a bit more time on the proposal and
>>> get things more flushed out I think I'll have a better idea of which
>>> approaches make the most sense.
>>> -- Allen
>>>>
>>>> --a.
>>>>
>>>>
>>>> Allen Gilliland wrote:
>>>>
>>>>> On Thu, 2006-03-09 at 14:21, David M Johnson wrote:
>>>>>
>>>>>> On Mar 9, 2006, at 5:02 PM, Allen Gilliland wrote:
>>>>>>
>>>>>>> i feel like we are still a little disconnected here. my
>>>>>>> approach will not alter anything about our ability to use the
>>>>>>> open session in view pattern. the only difference i see is the
>>>>>>> difference between these 2 code blocks ...
>>>>>>>
>>>>>>> old way:
>>>>>>> begin();
>>>>>>> website.store();
>>>>>>> commit();
>>>>>>>
>>>>>>> new way:
>>>>>>> WeblogManager wmgr = roller.getWeblogManager();
>>>>>>> wmgr.saveWebsite(website);
>>>>>>>
>>>>>>
>>>>>> But what if saving a website is just one step in a multi-part
>>>>>> transaction? OK, scratch that. If you start by doing the analysis
>>>>>> and designing one of the new Manager interfaces, I think we'll
>>>>>> have a much better understanding of this proposed refactoring.
>>>>>>
>>>>>
>>>>>
>>>>> i'll just give the short answer now. usually things that are
>>>>> multipart operations are still part of a single logical operation.
>>>>> in fact, we already do this in some places. take a look at the
>>>>> UserManager.createWebsite() method. that is a logical method which
>>>>> wraps a series of persistence operations. so the difference would
>>>>> be ...
>>>>>
>>>>> old way (in struts action or servlet):
>>>>> begin();
>>>>> // setup website
>>>>> website.store();
>>>>> // setup template
>>>>> template.store();
>>>>> // setup category
>>>>> category.store();
>>>>> // etc etc
>>>>> commit();
>>>>>
>>>>> new way (logical method in manager class):
>>>>> UserManager umgr = roller.getUserManager();
>>>>> umgr.createWebsite(newWebsite, possible, other, data);
>>>>>
>>>>> when i use the new way i only care wether or not the operation
>>>>> succeeded and i don't have to think about the persistence
>>>>> implications because they are hidden from me. now if it turns out
>>>>> that we have way too many transactions that would need their own
>>>>> logical method in a manager class then maybe this approach won't
>>>>> work, but i believe that in most request/response cycles the
>>>>> operations are pretty isolated and simple. in most of them you are
>>>>> only creating/updating/deleting a single object at a time.
>>>>>
>>>>> -- Allen
>>>>>
>>>>>
>>>>>
>>>>>> - Dave
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 26, 2006, at 8:34 PM, Allen Gilliland wrote:
> I have updated my backend refactoring proposal to include a bit
> more implementation details.
> http://rollerweblogger.org/wiki/Wiki.jsp?
> page=Proposal_BackendRefactorings
>
> I have basically listed all the manager classes which use the
> database and then listed each method of those classes which
> involves writing data.
>
> I still stand behind my proposal that we should remove all
> persistence specific logic from existing outside the business/
> presentation layer. I am planning to begin work on this for April
> and hopefully will get it completed for Roller 2.3
The more I think about this idea, the more I like it. I'd like to see
the Roller backend be a self-contained API and this appears to be the
way to achieve that.
But I'm still opposed to doing this work in the trunk. It involves
dramatic sweeping changes to the code base and requires that almost
every Struts action be rewritten. It should done done in a separate
branch and not merged back until it's been tested an evaluated.
Plus, I've got a couple questions about the plan:
1) You propose to remove the setUser() and getUser() methods from the
Roller interface. What is the plan for determining that the current
user has permission to perform an operation?
2) You mention that some operation are "single step persistence
operations which do not require special transaction considerations."
What does that mean in practice? Does each of these operations do
it's own begin() and then end with a commit() or rollback()? Will
these single step operations be called from the multi-step operations?
3) What is the plan for unit testing the changes to the Struts
Actions and other presentation classes?
4) How did you come up with the list of changes? I assume you
reviewed each of the Struts actions. Did you also review the
MetaWeblog API and Atom protocol implementations?
- Dave
>
> -- Allen
>
>
> Allen Gilliland wrote:
>> Anil Gangolli wrote:
>>> Allen:
>>>
>>> Your suggested pattern is workable, but you'll need to make begin
>>> () and commit() conditional and smart about transaction
>>> demarcation; it is a common pattern to conditionally begin a
>>> transaction only if there isn't one on the current thread, and
>>> you'll find that in many infrastructures (see my comments on
>>> Section 2 in the design proposal).
>> I agree with this and believe it's fairly easy to do.
>>>
>>> What happens if you don't have that logic? You'll find that the
>>> operations that you choose to make transactional can't be easily
>>> composed, which is a very awkward property to have. If you ever
>>> need to compose two operations, you would need to write a third
>>> method that includes all of the operations of the originals, and
>>> not just calling the two original methods, but copying their
>>> innards. I actually went through a period of trying to code apps
>>> this way in the 90's before infrastructures like EJB started to
>>> normalize the conditional demarcation patterns in Java. Lesson
>>> learned.
>> You are correct, that is absolutely a possible ramification and we
>> could end up making it more difficult to properly wrap some steps
>> together in a transaction. However, I would also argue that the
>> reverse scenerio is true for our current setup using more open
>> transaction demarcation. Allowing business/presentation code to
>> control transaction demarcation allows for transactions to become
>> overly inclusive and actually end up including more operations
>> than they should.
>>>
>>> The patterns for transaction demarcation in the dispatch layers
>>> involve three parts: (1) demarcation for requests on a per-
>>> request basis in a Filter or some other centralized dispatch
>>> point (e.g. in Axis or Struts apps in extensions of these
>>> servlets wrapping the entry points) (2) for scheduled tasks,
>>> wrapping the run() method in a base class (3) providing a
>>> mechanism to get an independent transaction for individual units
>>> of work at smaller granularities (REQUIRES_NEW style semantics),
>>> which I expect would be used very rarely in Roller. Patterns
>>> like this work well for two-tier web apps like Roller where the
>>> persistence container and the webapp container are the same.
>>> They don't work (or require much stronger transaction
>>> infrastructure) if you separate the webapp container from the
>>> persistence container which does not apply in Roller's case.
>> In order to get a better grasp on some Hibernate details I am
>> currently skimming through "Hibernate in Action" and they say ...
>> "We merely observe that, in our opinion, overengineering has been
>> endemic in the Java community, and overly ambitious multilayered
>> architectures have significanly contributed to the cose of Java
>> development and to the perceived complexity of J2EE. On the other
>> hand, we do agree that a dedicated persistence layer is a sensible
>> choice for most applications and that persistence-related code
>> shouldn't be moxed with business logic or presentation." (page 296)
>> In their examples for designing a layered application (webapp
>> specifically) they do not provide transaction demarcation outside
>> of the DAO layer. Of course this is only a single opinion and
>> does not mean it's what's best for Roller, but I would say that my
>> opinions are more in line with the sentiments from the quote above.
>> Speaking more specifically about applying transaction demarcation
>> at points in the dispatch layer ... I think I still see this as
>> allowing persistence logic into the business/presentation layer.
>> The other reason why this makes me nervous is that I think it
>> creates some potential for two situations ...
>> 1. catching a persistence exception too late. if the transaction
>> demarcation doesn't actually commit the transaction data until a
>> while after the app thinks the data has been written then we may
>> end up putting ourselves in a situation where we catch an
>> exception after we have already commited some of the response and
>> are no longer in a situation where we can respond appropriately.
>> This seems especially true if we consider each request/response
>> cycle as a single transaction and only flush/commit the data in a
>> filter as we exit the app.
>> 2. commiting data changes we don't want, specifically users being
>> bad with their templates. I suppose our wrapper objects may take
>> care of the potential problem with users making changes to their
>> data that we don't want, but there may also be an issue of app
>> code doing the same thing. It has always seemed ideal to me to
>> only commit changes specifically when needed. If a filter simply
>> commits data at the end of the request/response cycle there is no
>> guarantee that someone hasn't modified an object that is not meant
>> to be saved back to the database.
>>>
>>> Like your proposal, the dispatch-level patterns remove begin()
>>> and commit() from app code, and we should end up with only a few
>>> places that call them.
>> I like the idea of the dispatch-level pattern much more than our
>> current pattern. After I spend a bit more time on the proposal
>> and get things more flushed out I think I'll have a better idea of
>> which approaches make the most sense.
>> -- Allen
>>>
>>> --a.
>>>
>>>
>>> Allen Gilliland wrote:
>>>
>>>> On Thu, 2006-03-09 at 14:21, David M Johnson wrote:
>>>>
>>>>> On Mar 9, 2006, at 5:02 PM, Allen Gilliland wrote:
>>>>>
>>>>>> i feel like we are still a little disconnected here. my
>>>>>> approach will not alter anything about our ability to use the
>>>>>> open session in view pattern. the only difference i see is
>>>>>> the difference between these 2 code blocks ...
>>>>>>
>>>>>> old way:
>>>>>> begin();
>>>>>> website.store();
>>>>>> commit();
>>>>>>
>>>>>> new way:
>>>>>> WeblogManager wmgr = roller.getWeblogManager();
>>>>>> wmgr.saveWebsite(website);
>>>>>>
>>>>>
>>>>> But what if saving a website is just one step in a multi-part
>>>>> transaction? OK, scratch that. If you start by doing the
>>>>> analysis and designing one of the new Manager interfaces, I
>>>>> think we'll have a much better understanding of this proposed
>>>>> refactoring.
>>>>>
>>>>
>>>>
>>>> i'll just give the short answer now. usually things that are
>>>> multipart operations are still part of a single logical
>>>> operation. in fact, we already do this in some places. take a
>>>> look at the UserManager.createWebsite() method. that is a
>>>> logical method which wraps a series of persistence operations.
>>>> so the difference would be ...
>>>>
>>>> old way (in struts action or servlet):
>>>> begin();
>>>> // setup website
>>>> website.store();
>>>> // setup template
>>>> template.store();
>>>> // setup category
>>>> category.store();
>>>> // etc etc
>>>> commit();
>>>>
>>>> new way (logical method in manager class):
>>>> UserManager umgr = roller.getUserManager();
>>>> umgr.createWebsite(newWebsite, possible, other, data);
>>>>
>>>> when i use the new way i only care wether or not the operation
>>>> succeeded and i don't have to think about the persistence
>>>> implications because they are hidden from me. now if it turns
>>>> out that we have way too many transactions that would need their
>>>> own logical method in a manager class then maybe this approach
>>>> won't work, but i believe that in most request/response cycles
>>>> the operations are pretty isolated and simple. in most of them
>>>> you are only creating/updating/deleting a single object at a time.
>>>>
>>>> -- Allen
>>>>
>>>>
>>>>
>>>>> - Dave
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
guys,
I have updated my backend refactoring proposal to include a bit more
implementation details.
http://rollerweblogger.org/wiki/Wiki.jsp?page=Proposal_BackendRefactorings
I have basically listed all the manager classes which use the database
and then listed each method of those classes which involves writing data.
I still stand behind my proposal that we should remove all persistence
specific logic from existing outside the business/presentation layer. I
am planning to begin work on this for April and hopefully will get it
completed for Roller 2.3
-- Allen
Allen Gilliland wrote:
>
>
> Anil Gangolli wrote:
>
>> Allen:
>>
>> Your suggested pattern is workable, but you'll need to make begin()
>> and commit() conditional and smart about transaction demarcation; it
>> is a common pattern to conditionally begin a transaction only if there
>> isn't one on the current thread, and you'll find that in many
>> infrastructures (see my comments on Section 2 in the design proposal).
>
>
> I agree with this and believe it's fairly easy to do.
>
>>
>> What happens if you don't have that logic? You'll find that the
>> operations that you choose to make transactional can't be easily
>> composed, which is a very awkward property to have. If you ever need
>> to compose two operations, you would need to write a third method that
>> includes all of the operations of the originals, and not just calling
>> the two original methods, but copying their innards. I actually went
>> through a period of trying to code apps this way in the 90's before
>> infrastructures like EJB started to normalize the conditional
>> demarcation patterns in Java. Lesson learned.
>
>
> You are correct, that is absolutely a possible ramification and we could
> end up making it more difficult to properly wrap some steps together in
> a transaction. However, I would also argue that the reverse scenerio is
> true for our current setup using more open transaction demarcation.
> Allowing business/presentation code to control transaction demarcation
> allows for transactions to become overly inclusive and actually end up
> including more operations than they should.
>
>>
>> The patterns for transaction demarcation in the dispatch layers
>> involve three parts: (1) demarcation for requests on a per-request
>> basis in a Filter or some other centralized dispatch point (e.g. in
>> Axis or Struts apps in extensions of these servlets wrapping the entry
>> points) (2) for scheduled tasks, wrapping the run() method in a base
>> class (3) providing a mechanism to get an independent transaction for
>> individual units of work at smaller granularities (REQUIRES_NEW style
>> semantics), which I expect would be used very rarely in Roller.
>> Patterns like this work well for two-tier web apps like Roller where
>> the persistence container and the webapp container are the same. They
>> don't work (or require much stronger transaction infrastructure) if
>> you separate the webapp container from the persistence container which
>> does not apply in Roller's case.
>
>
> In order to get a better grasp on some Hibernate details I am currently
> skimming through "Hibernate in Action" and they say ...
>
> "We merely observe that, in our opinion, overengineering has been
> endemic in the Java community, and overly ambitious multilayered
> architectures have significanly contributed to the cose of Java
> development and to the perceived complexity of J2EE. On the other hand,
> we do agree that a dedicated persistence layer is a sensible choice for
> most applications and that persistence-related code shouldn't be moxed
> with business logic or presentation." (page 296)
>
> In their examples for designing a layered application (webapp
> specifically) they do not provide transaction demarcation outside of the
> DAO layer. Of course this is only a single opinion and does not mean
> it's what's best for Roller, but I would say that my opinions are more
> in line with the sentiments from the quote above.
>
> Speaking more specifically about applying transaction demarcation at
> points in the dispatch layer ... I think I still see this as allowing
> persistence logic into the business/presentation layer. The other
> reason why this makes me nervous is that I think it creates some
> potential for two situations ...
>
> 1. catching a persistence exception too late. if the transaction
> demarcation doesn't actually commit the transaction data until a while
> after the app thinks the data has been written then we may end up
> putting ourselves in a situation where we catch an exception after we
> have already commited some of the response and are no longer in a
> situation where we can respond appropriately. This seems especially
> true if we consider each request/response cycle as a single transaction
> and only flush/commit the data in a filter as we exit the app.
>
> 2. commiting data changes we don't want, specifically users being bad
> with their templates. I suppose our wrapper objects may take care of
> the potential problem with users making changes to their data that we
> don't want, but there may also be an issue of app code doing the same
> thing. It has always seemed ideal to me to only commit changes
> specifically when needed. If a filter simply commits data at the end of
> the request/response cycle there is no guarantee that someone hasn't
> modified an object that is not meant to be saved back to the database.
>
>>
>> Like your proposal, the dispatch-level patterns remove begin() and
>> commit() from app code, and we should end up with only a few places
>> that call them.
>
>
> I like the idea of the dispatch-level pattern much more than our current
> pattern. After I spend a bit more time on the proposal and get things
> more flushed out I think I'll have a better idea of which approaches
> make the most sense.
>
> -- Allen
>
>>
>> --a.
>>
>>
>> Allen Gilliland wrote:
>>
>>> On Thu, 2006-03-09 at 14:21, David M Johnson wrote:
>>>
>>>
>>>> On Mar 9, 2006, at 5:02 PM, Allen Gilliland wrote:
>>>>
>>>>> i feel like we are still a little disconnected here. my approach
>>>>> will not alter anything about our ability to use the open session
>>>>> in view pattern. the only difference i see is the difference
>>>>> between these 2 code blocks ...
>>>>>
>>>>> old way:
>>>>> begin();
>>>>> website.store();
>>>>> commit();
>>>>>
>>>>> new way:
>>>>> WeblogManager wmgr = roller.getWeblogManager();
>>>>> wmgr.saveWebsite(website);
>>>>>
>>>>
>>>> But what if saving a website is just one step in a multi-part
>>>> transaction? OK, scratch that. If you start by doing the analysis
>>>> and designing one of the new Manager interfaces, I think we'll have
>>>> a much better understanding of this proposed refactoring.
>>>>
>>>
>>>
>>> i'll just give the short answer now. usually things that are
>>> multipart operations are still part of a single logical operation.
>>> in fact, we already do this in some places. take a look at the
>>> UserManager.createWebsite() method. that is a logical method which
>>> wraps a series of persistence operations. so the difference would be
>>> ...
>>>
>>> old way (in struts action or servlet):
>>> begin();
>>> // setup website
>>> website.store();
>>> // setup template
>>> template.store();
>>> // setup category
>>> category.store();
>>> // etc etc
>>> commit();
>>>
>>> new way (logical method in manager class):
>>> UserManager umgr = roller.getUserManager();
>>> umgr.createWebsite(newWebsite, possible, other, data);
>>>
>>> when i use the new way i only care wether or not the operation
>>> succeeded and i don't have to think about the persistence
>>> implications because they are hidden from me. now if it turns out
>>> that we have way too many transactions that would need their own
>>> logical method in a manager class then maybe this approach won't
>>> work, but i believe that in most request/response cycles the
>>> operations are pretty isolated and simple. in most of them you are
>>> only creating/updating/deleting a single object at a time.
>>>
>>> -- Allen
>>>
>>>
>>>
>>>
>>>> - Dave
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>>
>>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 12, 2006, at 10:06 PM, Allen Gilliland wrote:
> Speaking more specifically about applying transaction demarcation
> at points in the dispatch layer ... I think I still see this as
> allowing persistence logic into the business/presentation layer.
> The other reason why this makes me nervous is that I think it
> creates some potential for two situations ...
>
> 1. catching a persistence exception too late. if the transaction
> demarcation doesn't actually commit the transaction data until a
> while after the app thinks the data has been written then we may
> end up putting ourselves in a situation where we catch an exception
> after we have already commited some of the response and are no
> longer in a situation where we can respond appropriately. This
> seems especially true if we consider each request/response cycle as
> a single transaction and only flush/commit the data in a filter as
> we exit the app.
>
> 2. commiting data changes we don't want, specifically users being
> bad with their templates. I suppose our wrapper objects may take
> care of the potential problem with users making changes to their
> data that we don't want, but there may also be an issue of app code
> doing the same thing. It has always seemed ideal to me to only
> commit changes specifically when needed. If a filter simply commits
> data at the end of the request/response cycle there is no guarantee
> that someone hasn't modified an object that is not meant to be
> saved back to the database.
Yes, the persistence filter should never do a commit. It should do a
rollback and I thought it did that, but it appears that right now it
just closes the connection and Hibernate session via call to
Roller.release() -- effectively the same thing, but I'd rather see an
explicit rollback.
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
Anil Gangolli wrote:
> Allen:
>
> Your suggested pattern is workable, but you'll need to make begin()
> and commit() conditional and smart about transaction demarcation; it
> is a common pattern to conditionally begin a transaction only if there
> isn't one on the current thread, and you'll find that in many
> infrastructures (see my comments on Section 2 in the design proposal).
I agree with this and believe it's fairly easy to do.
>
> What happens if you don't have that logic? You'll find that the
> operations that you choose to make transactional can't be easily
> composed, which is a very awkward property to have. If you ever need
> to compose two operations, you would need to write a third method that
> includes all of the operations of the originals, and not just calling
> the two original methods, but copying their innards. I actually went
> through a period of trying to code apps this way in the 90's before
> infrastructures like EJB started to normalize the conditional
> demarcation patterns in Java. Lesson learned.
You are correct, that is absolutely a possible ramification and we could
end up making it more difficult to properly wrap some steps together in
a transaction. However, I would also argue that the reverse scenerio is
true for our current setup using more open transaction demarcation.
Allowing business/presentation code to control transaction demarcation
allows for transactions to become overly inclusive and actually end up
including more operations than they should.
>
> The patterns for transaction demarcation in the dispatch layers
> involve three parts: (1) demarcation for requests on a per-request
> basis in a Filter or some other centralized dispatch point (e.g. in
> Axis or Struts apps in extensions of these servlets wrapping the entry
> points) (2) for scheduled tasks, wrapping the run() method in a base
> class (3) providing a mechanism to get an independent transaction for
> individual units of work at smaller granularities (REQUIRES_NEW style
> semantics), which I expect would be used very rarely in Roller.
> Patterns like this work well for two-tier web apps like Roller where
> the persistence container and the webapp container are the same. They
> don't work (or require much stronger transaction infrastructure) if
> you separate the webapp container from the persistence container which
> does not apply in Roller's case.
In order to get a better grasp on some Hibernate details I am currently
skimming through "Hibernate in Action" and they say ...
"We merely observe that, in our opinion, overengineering has been
endemic in the Java community, and overly ambitious multilayered
architectures have significanly contributed to the cose of Java
development and to the perceived complexity of J2EE. On the other hand,
we do agree that a dedicated persistence layer is a sensible choice for
most applications and that persistence-related code shouldn't be moxed
with business logic or presentation." (page 296)
In their examples for designing a layered application (webapp
specifically) they do not provide transaction demarcation outside of the
DAO layer. Of course this is only a single opinion and does not mean
it's what's best for Roller, but I would say that my opinions are more
in line with the sentiments from the quote above.
Speaking more specifically about applying transaction demarcation at
points in the dispatch layer ... I think I still see this as allowing
persistence logic into the business/presentation layer. The other
reason why this makes me nervous is that I think it creates some
potential for two situations ...
1. catching a persistence exception too late. if the transaction
demarcation doesn't actually commit the transaction data until a while
after the app thinks the data has been written then we may end up
putting ourselves in a situation where we catch an exception after we
have already commited some of the response and are no longer in a
situation where we can respond appropriately. This seems especially
true if we consider each request/response cycle as a single transaction
and only flush/commit the data in a filter as we exit the app.
2. commiting data changes we don't want, specifically users being bad
with their templates. I suppose our wrapper objects may take care of
the potential problem with users making changes to their data that we
don't want, but there may also be an issue of app code doing the same
thing. It has always seemed ideal to me to only commit changes
specifically when needed. If a filter simply commits data at the end of
the request/response cycle there is no guarantee that someone hasn't
modified an object that is not meant to be saved back to the database.
>
> Like your proposal, the dispatch-level patterns remove begin() and
> commit() from app code, and we should end up with only a few places
> that call them.
I like the idea of the dispatch-level pattern much more than our current
pattern. After I spend a bit more time on the proposal and get things
more flushed out I think I'll have a better idea of which approaches
make the most sense.
-- Allen
>
> --a.
>
>
> Allen Gilliland wrote:
>
>> On Thu, 2006-03-09 at 14:21, David M Johnson wrote:
>>
>>
>>> On Mar 9, 2006, at 5:02 PM, Allen Gilliland wrote:
>>>
>>>
>>>> i feel like we are still a little disconnected here. my approach
>>>> will not alter anything about our ability to use the open session
>>>> in view pattern. the only difference i see is the difference
>>>> between these 2 code blocks ...
>>>>
>>>> old way:
>>>> begin();
>>>> website.store();
>>>> commit();
>>>>
>>>> new way:
>>>> WeblogManager wmgr = roller.getWeblogManager();
>>>> wmgr.saveWebsite(website);
>>>>
>>>
>>> But what if saving a website is just one step in a multi-part
>>> transaction? OK, scratch that. If you start by doing the analysis
>>> and designing one of the new Manager interfaces, I think we'll have
>>> a much better understanding of this proposed refactoring.
>>>
>>
>>
>> i'll just give the short answer now. usually things that are
>> multipart operations are still part of a single logical operation.
>> in fact, we already do this in some places. take a look at the
>> UserManager.createWebsite() method. that is a logical method which
>> wraps a series of persistence operations. so the difference would be
>> ...
>>
>> old way (in struts action or servlet):
>> begin();
>> // setup website
>> website.store();
>> // setup template
>> template.store();
>> // setup category
>> category.store();
>> // etc etc
>> commit();
>>
>> new way (logical method in manager class):
>> UserManager umgr = roller.getUserManager();
>> umgr.createWebsite(newWebsite, possible, other, data);
>>
>> when i use the new way i only care wether or not the operation
>> succeeded and i don't have to think about the persistence
>> implications because they are hidden from me. now if it turns out
>> that we have way too many transactions that would need their own
>> logical method in a manager class then maybe this approach won't
>> work, but i believe that in most request/response cycles the
>> operations are pretty isolated and simple. in most of them you are
>> only creating/updating/deleting a single object at a time.
>>
>> -- Allen
>>
>>
>>
>>
>>> - Dave
>>>
>>>
>>>
>>
>>
>>
>>
>
>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
Allen:
Your suggested pattern is workable, but you'll need to make begin() and
commit() conditional and smart about transaction demarcation; it is a
common pattern to conditionally begin a transaction only if there isn't
one on the current thread, and you'll find that in many infrastructures
(see my comments on Section 2 in the design proposal).
What happens if you don't have that logic? You'll find that the
operations that you choose to make transactional can't be easily
composed, which is a very awkward property to have. If you ever need to
compose two operations, you would need to write a third method that
includes all of the operations of the originals, and not just calling
the two original methods, but copying their innards. I actually went
through a period of trying to code apps this way in the 90's before
infrastructures like EJB started to normalize the conditional
demarcation patterns in Java. Lesson learned.
The patterns for transaction demarcation in the dispatch layers involve
three parts: (1) demarcation for requests on a per-request basis in a
Filter or some other centralized dispatch point (e.g. in Axis or Struts
apps in extensions of these servlets wrapping the entry points) (2) for
scheduled tasks, wrapping the run() method in a base class (3) providing
a mechanism to get an independent transaction for individual units of
work at smaller granularities (REQUIRES_NEW style semantics), which I
expect would be used very rarely in Roller. Patterns like this work
well for two-tier web apps like Roller where the persistence container
and the webapp container are the same. They don't work (or require much
stronger transaction infrastructure) if you separate the webapp
container from the persistence container which does not apply in
Roller's case.
Like your proposal, the dispatch-level patterns remove begin() and
commit() from app code, and we should end up with only a few places that
call them.
--a.
Allen Gilliland wrote:
> On Thu, 2006-03-09 at 14:21, David M Johnson wrote:
>
>> On Mar 9, 2006, at 5:02 PM, Allen Gilliland wrote:
>>
>>> i feel like we are still a little disconnected here. my approach
>>> will not alter anything about our ability to use the open session
>>> in view pattern. the only difference i see is the difference
>>> between these 2 code blocks ...
>>>
>>> old way:
>>> begin();
>>> website.store();
>>> commit();
>>>
>>> new way:
>>> WeblogManager wmgr = roller.getWeblogManager();
>>> wmgr.saveWebsite(website);
>>>
>> But what if saving a website is just one step in a multi-part
>> transaction? OK, scratch that. If you start by doing the analysis and
>> designing one of the new Manager interfaces, I think we'll have a
>> much better understanding of this proposed refactoring.
>>
>
> i'll just give the short answer now. usually things that are multipart operations are still part of a single logical operation. in fact, we already do this in some places. take a look at the UserManager.createWebsite() method. that is a logical method which wraps a series of persistence operations. so the difference would be ...
>
> old way (in struts action or servlet):
> begin();
> // setup website
> website.store();
> // setup template
> template.store();
> // setup category
> category.store();
> // etc etc
> commit();
>
> new way (logical method in manager class):
> UserManager umgr = roller.getUserManager();
> umgr.createWebsite(newWebsite, possible, other, data);
>
> when i use the new way i only care wether or not the operation succeeded and i don't have to think about the persistence implications because they are hidden from me. now if it turns out that we have way too many transactions that would need their own logical method in a manager class then maybe this approach won't work, but i believe that in most request/response cycles the operations are pretty isolated and simple. in most of them you are only creating/updating/deleting a single object at a time.
>
> -- Allen
>
>
>
>> - Dave
>>
>>
>>
>
>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Thu, 2006-03-09 at 14:21, David M Johnson wrote:
> On Mar 9, 2006, at 5:02 PM, Allen Gilliland wrote:
> > i feel like we are still a little disconnected here. my approach
> > will not alter anything about our ability to use the open session
> > in view pattern. the only difference i see is the difference
> > between these 2 code blocks ...
> >
> > old way:
> > begin();
> > website.store();
> > commit();
> >
> > new way:
> > WeblogManager wmgr = roller.getWeblogManager();
> > wmgr.saveWebsite(website);
>
>
> But what if saving a website is just one step in a multi-part
> transaction? OK, scratch that. If you start by doing the analysis and
> designing one of the new Manager interfaces, I think we'll have a
> much better understanding of this proposed refactoring.
i'll just give the short answer now. usually things that are multipart operations are still part of a single logical operation. in fact, we already do this in some places. take a look at the UserManager.createWebsite() method. that is a logical method which wraps a series of persistence operations. so the difference would be ...
old way (in struts action or servlet):
begin();
// setup website
website.store();
// setup template
template.store();
// setup category
category.store();
// etc etc
commit();
new way (logical method in manager class):
UserManager umgr = roller.getUserManager();
umgr.createWebsite(newWebsite, possible, other, data);
when i use the new way i only care wether or not the operation succeeded and i don't have to think about the persistence implications because they are hidden from me. now if it turns out that we have way too many transactions that would need their own logical method in a manager class then maybe this approach won't work, but i believe that in most request/response cycles the operations are pretty isolated and simple. in most of them you are only creating/updating/deleting a single object at a time.
-- Allen
>
> - Dave
>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 9, 2006, at 5:02 PM, Allen Gilliland wrote:
> i feel like we are still a little disconnected here. my approach
> will not alter anything about our ability to use the open session
> in view pattern. the only difference i see is the difference
> between these 2 code blocks ...
>
> old way:
> begin();
> website.store();
> commit();
>
> new way:
> WeblogManager wmgr = roller.getWeblogManager();
> wmgr.saveWebsite(website);
But what if saving a website is just one step in a multi-part
transaction? OK, scratch that. If you start by doing the analysis and
designing one of the new Manager interfaces, I think we'll have a
much better understanding of this proposed refactoring.
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
You make a lot of good points. Comments inline ...
On Thu, 2006-03-09 at 13:44, David M Johnson wrote:
> I'm going to respond to your points in a different order than you
> posed them, because I want to make one thing clear up-front.
>
>
> On Mar 9, 2006, at 3:06 PM, Allen Gilliland wrote:
> > 3. finally, because of the issues that i saw from item #2 i wanted
> > to suggest what i believe is far more simplified approach than what
> > we have now. that approach is quite simply to push all the
> > transaction demarcation code back behind the XXXManager
> > implementations and let the various persistence classes take
> > control over that logic. this pulls a reasonable amount of code
> > outside of the web layer and allows our servlets and struts actions
> > to do persistence operations in a more abstracted fashion. i.e.
> > rather than creating 6 objects and saving them in a struts action
> > as part of new weblog creation, instead we have a method called
> > createWeblog() which takes in all the required data and handles the
> > details of how to persist that data.
>
> If you are really going to move all application and persistence logic
> from the Struts Actions and Servlets and completely remove the need
> for the front-end to ever call fine-grained methods like
> retrieveObject(), removeObject(), saveObject() then I am am FOR this
> effort and would like to participate. However, this is a large job
> and will mean sweeping change across the system. I'm not comfortable
> with this happening without more up-front design and I'm not
> comfortable with it happening in the trunk -- plus, I'm more than
> willing to do the branch management work.
cool. i didn't mean to suggest that i just wanted to do this without anyone looking at it, so i am more than happy to pull together a more detailed proposal for this and to do the work in a branch until it's ready.
>
>
> Allen Gilliland wrote:
> > Doing an exhaustive explanation of every piece of code that would
> > move is pretty tough. anything that truly requires a transaction
> > would be moved into a logical method in a manager class.
>
> I don't think it would be asking to much to see what the new manager
> interfaces will look like. To design the new interfaces you'll have
> to review the Actions and Servlets (comment, trackback, MetaWeblog,
> Atom protocol, etc.) and how they all use transactions. You need to
> do that any way. Doing it up-front is important because it 1) should
> reveal any problems that you'll might encounter along the way, 2)
> will make it easier to determine level of effort for this work and 3)
> will make it easier to divide up the work of implementing and testing
> the new methods.
you are correct, it isn't asking too much. i'll work on elaborating on the proposal before we commit to anything. in particular i'll focus on the Manager interfaces and how i see them changing.
>
>
> > 1. the first and foremost issue is performance. i have spent a
> > considerable amount of time over the recent months evaluating where
> > i believe Roller is having performance bottlenecks and trying to
> > sort them out as best i can. after looking more closely at
> > Hibernate as it is used by Roller i have seen some very troubling
> > performance issues. for example, we are generating more traffic
> > talking to the db than we are serving requests and the Hibernate L2
> > cache is of essentially no help to us right now. this is a huge
> > problem for large sites and it has to be fixed.
>
> Those are definitely important issues and I think it's very important
> that we understand their root cause. I don't think that simply moving
> transactions around alone is necessarily a solution for those problems.
this is true. i actually didn't mean to suggest that this was a real cause for the refactoring, more that it was the beginning of my inspiration. at the end of the day the caching issue is an issue of how we query for things and transaction support is more about how we store things, so they are separate issues. somewhat related though, since they both happen in the persistence layer.
>
>
> > 2. while doing my debugging on the performance issues i noticed
> > that the current Roller transaction demarcation code really isn't
> > implemented completely. calls to the begin() methods are used
> > somewhat sporatically, and most important, calls to rollback() are
> > non-existent. i don't know how we can claim true transaction
> > support if we aren't doing rollbacks. we also are not using
> > Hibernates Transaction wrappers either, which is highly recommended
> > in the Hibernate docs. this leads me to believe that we need a bit
> > of an overhaul on the general backend code structure.
>
> I don't think that is a reason for this specific refactoring either,
> I believe begin(), commit() and rollback() are called systematically
> and the pattern we are using is fundamentally sound. If we were using
> a database that supported that, we could test this.
you are right, there is nothing wrong with the pattern. my observeration was more along the lines of 1) that we haven't actually implemented things to actually make use of the pattern we have now and 2) that i think we can simplify our current pattern to make things easier on ourselves.
i'm not sure what you mean by a database that supports it. mysql innodb databases support transactions AFAIK. and i'm sure that oracle does as well, which some people appear to be using.
>
> I really want to make sure we get transactions right. Personally, I'd
> like to turn on transaction support on all Roller systems that I'm
> involved with and drop databases that can't handle that.
i agree, i want to get it right as well. maybe more appropriately, we *need* to get it right. I don't think the underlying database is really our problem though. i think we solve the problem assuming the database supports transactions and if it doesn't that's someone elses problem.
>
>
> > i believe this approach will work fine for Roller and since i am
> > already planning to dig into the backend code to resolve issues #1
> > and #2 i thought i would suggest making some simplifications (#3)
> > at the same time.
> >
> > at the end of the day this may be a case where either method will
> > work and it's just a matter of choosing one. we can either upgrade/
> > fix our current transaction demarcation code or migrate to the
> > approach i proposed which pushes the transaction logic behind the
> > manager classes. there may not be a "correct" approach.
>
> I think moving the transactions behind the interface wall is
> basically a good approach and probably the right approach, but I've
> never developed a web app that was able to achieve that goal (I'm not
> trying to say it is unattainable). I've always used the open session
> in view, each request is a transaction approach. You gain a lot of
> flexibility by being able to do CRUD operations straight from the
> presentation layer and it's hard to give that up.
i feel like we are still a little disconnected here. my approach will not alter anything about our ability to use the open session in view pattern. the only difference i see is the difference between these 2 code blocks ...
old way:
begin();
website.store();
commit();
new way:
WeblogManager wmgr = roller.getWeblogManager();
wmgr.saveWebsite(website);
that's it. if saving a website requires multiple steps then that will be handled behind the scenes by the implementing weblog manager and if something goes wrong at any point during that operation then an exception is thrown and a rollback happens. the only difference is that outside of the persistence layer you are no longer required to deal with calling transaction specific methods.
this is how i have always done things and i have never had a problem with it. but i will fully admit that this only works for reasonably simple transactions and if our transactions really are *that* complex then maybe it won't work. i'll work on flushing out the proposal further with more details about what manager methods will be added/changed, but i still feel that this should be possible in Roller.
-- Allen
>
> - Dave
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
I'm going to respond to your points in a different order than you
posed them, because I want to make one thing clear up-front.
On Mar 9, 2006, at 3:06 PM, Allen Gilliland wrote:
> 3. finally, because of the issues that i saw from item #2 i wanted
> to suggest what i believe is far more simplified approach than what
> we have now. that approach is quite simply to push all the
> transaction demarcation code back behind the XXXManager
> implementations and let the various persistence classes take
> control over that logic. this pulls a reasonable amount of code
> outside of the web layer and allows our servlets and struts actions
> to do persistence operations in a more abstracted fashion. i.e.
> rather than creating 6 objects and saving them in a struts action
> as part of new weblog creation, instead we have a method called
> createWeblog() which takes in all the required data and handles the
> details of how to persist that data.
If you are really going to move all application and persistence logic
from the Struts Actions and Servlets and completely remove the need
for the front-end to ever call fine-grained methods like
retrieveObject(), removeObject(), saveObject() then I am am FOR this
effort and would like to participate. However, this is a large job
and will mean sweeping change across the system. I'm not comfortable
with this happening without more up-front design and I'm not
comfortable with it happening in the trunk -- plus, I'm more than
willing to do the branch management work.
Allen Gilliland wrote:
> Doing an exhaustive explanation of every piece of code that would
> move is pretty tough. anything that truly requires a transaction
> would be moved into a logical method in a manager class.
I don't think it would be asking to much to see what the new manager
interfaces will look like. To design the new interfaces you'll have
to review the Actions and Servlets (comment, trackback, MetaWeblog,
Atom protocol, etc.) and how they all use transactions. You need to
do that any way. Doing it up-front is important because it 1) should
reveal any problems that you'll might encounter along the way, 2)
will make it easier to determine level of effort for this work and 3)
will make it easier to divide up the work of implementing and testing
the new methods.
> 1. the first and foremost issue is performance. i have spent a
> considerable amount of time over the recent months evaluating where
> i believe Roller is having performance bottlenecks and trying to
> sort them out as best i can. after looking more closely at
> Hibernate as it is used by Roller i have seen some very troubling
> performance issues. for example, we are generating more traffic
> talking to the db than we are serving requests and the Hibernate L2
> cache is of essentially no help to us right now. this is a huge
> problem for large sites and it has to be fixed.
Those are definitely important issues and I think it's very important
that we understand their root cause. I don't think that simply moving
transactions around alone is necessarily a solution for those problems.
> 2. while doing my debugging on the performance issues i noticed
> that the current Roller transaction demarcation code really isn't
> implemented completely. calls to the begin() methods are used
> somewhat sporatically, and most important, calls to rollback() are
> non-existent. i don't know how we can claim true transaction
> support if we aren't doing rollbacks. we also are not using
> Hibernates Transaction wrappers either, which is highly recommended
> in the Hibernate docs. this leads me to believe that we need a bit
> of an overhaul on the general backend code structure.
I don't think that is a reason for this specific refactoring either,
I believe begin(), commit() and rollback() are called systematically
and the pattern we are using is fundamentally sound. If we were using
a database that supported that, we could test this.
I really want to make sure we get transactions right. Personally, I'd
like to turn on transaction support on all Roller systems that I'm
involved with and drop databases that can't handle that.
> i believe this approach will work fine for Roller and since i am
> already planning to dig into the backend code to resolve issues #1
> and #2 i thought i would suggest making some simplifications (#3)
> at the same time.
>
> at the end of the day this may be a case where either method will
> work and it's just a matter of choosing one. we can either upgrade/
> fix our current transaction demarcation code or migrate to the
> approach i proposed which pushes the transaction logic behind the
> manager classes. there may not be a "correct" approach.
I think moving the transactions behind the interface wall is
basically a good approach and probably the right approach, but I've
never developed a web app that was able to achieve that goal (I'm not
trying to say it is unattainable). I've always used the open session
in view, each request is a transaction approach. You gain a lot of
flexibility by being able to do CRUD operations straight from the
presentation layer and it's hard to give that up.
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Thu, 2006-03-09 at 10:07, David M Johnson wrote:
> I'm definitely -1 on part item 2 of your proposal.
>
> I do not understand what you are proposing to do and I'd like to see
> specifically how each action and method in the back-end will change.
> There are many multi-step queries, updates, inserts, etc. in the code
> and application logic is expressed in both Struts actions and in the
> back-end. I don't think you are adequately explaining how you will
> keep transaction demarcation in place. And I don't understand how you
> can move begin() and commit() the back-end without moving lots of
> code from the Struts actions into the manager classes.
Doing an exhaustive explanation of every piece of code that would move is pretty tough. anything that truly requires a transaction would be moved into a logical method in a manager class.
>
> To do this right you'll have to do some trail and error
> experimentation and in the end I believe you'll have to make
> extensive changes. I'd like to have community review of those changes
> before they goes in trunk. For that reason, I strongly suggest doing
> item 2 in a separate branch.
yes, the changes will touch a number of classes and in the case of some of our larger transactions we may need to push some logic from the action classes into the manager classes. i find that in *most* cases an action class is really only working on a single object at a time, so i don't really think we do very long and complicated transactions. i am fine with doing this work in a branch.
i think this discussion is losing sight of its original purpose though, so i'd like to step back for a second and just talk about why i think the backend needs some reforming.
1. the first and foremost issue is performance. i have spent a considerable amount of time over the recent months evaluating where i believe Roller is having performance bottlenecks and trying to sort them out as best i can. after looking more closely at Hibernate as it is used by Roller i have seen some very troubling performance issues. for example, we are generating more traffic talking to the db than we are serving requests and the Hibernate L2 cache is of essentially no help to us right now. this is a huge problem for large sites and it has to be fixed.
2. while doing my debugging on the performance issues i noticed that the current Roller transaction demarcation code really isn't implemented completely. calls to the begin() methods are used somewhat sporatically, and most important, calls to rollback() are non-existent. i don't know how we can claim true transaction support if we aren't doing rollbacks. we also are not using Hibernates Transaction wrappers either, which is highly recommended in the Hibernate docs. this leads me to believe that we need a bit of an overhaul on the general backend code structure.
3. finally, because of the issues that i saw from item #2 i wanted to suggest what i believe is far more simplified approach than what we have now. that approach is quite simply to push all the transaction demarcation code back behind the XXXManager implementations and let the various persistence classes take control over that logic. this pulls a reasonable amount of code outside of the web layer and allows our servlets and struts actions to do persistence operations in a more abstracted fashion. i.e. rather than creating 6 objects and saving them in a struts action as part of new weblog creation, instead we have a method called createWeblog() which takes in all the required data and handles the details of how to persist that data.
i believe this approach will work fine for Roller and since i am already planning to dig into the backend code to resolve issues #1 and #2 i thought i would suggest making some simplifications (#3) at the same time.
at the end of the day this may be a case where either method will work and it's just a matter of choosing one. we can either upgrade/fix our current transaction demarcation code or migrate to the approach i proposed which pushes the transaction logic behind the manager classes. there may not be a "correct" approach.
-- Allen
>
> - Dave
>
>
> On Mar 8, 2006, at 6:40 PM, Allen Gilliland wrote:
>
> > just a reminder, silence == consent. i am planning to move forward
> > with development on this.
> >
> > -- Allen
> >
> >
> > On Mon, 2006-03-06 at 13:25, Allen Gilliland wrote:
> >> Okay, here is a more flushed out proposal of what I think should
> >> be done ...
> >>
> >> http://rollerweblogger.org/wiki/Wiki.jsp?
> >> page=Proposal_BackendRefactorings
> >>
> >> Note that the driving force behind these changes is to 1) prevent
> >> direct access to the PersistenceStrategy from outside the business
> >> layer and 2) limit persistence logic (like transaction details) to
> >> the business layer.
> >>
> >> I think those are very appropriate goals to have for the
> >> architecture of our code.
> >>
> >> -- Allen
> >>
> >>
> >> On Sun, 2006-03-05 at 10:10, Anil Gangolli wrote:
> >>> Anil Gangolli wrote:
> >>>>
> >>>> Actually, you want those two queries to be in one transaction, not
> >>>> two; otherwise they can see inconsistent state if there is another
> >>>> transaction committed between the two.
> >>>>
> >>> Red herring on my part. Not really a new issue for us though
> >>> since we
> >>> are typically using default READ_COMMITTED isolation anyway.
> >>>
> >>> --a.
> >>>
> >>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
I'm definitely -1 on part item 2 of your proposal.
I do not understand what you are proposing to do and I'd like to see
specifically how each action and method in the back-end will change.
There are many multi-step queries, updates, inserts, etc. in the code
and application logic is expressed in both Struts actions and in the
back-end. I don't think you are adequately explaining how you will
keep transaction demarcation in place. And I don't understand how you
can move begin() and commit() the back-end without moving lots of
code from the Struts actions into the manager classes.
To do this right you'll have to do some trail and error
experimentation and in the end I believe you'll have to make
extensive changes. I'd like to have community review of those changes
before they goes in trunk. For that reason, I strongly suggest doing
item 2 in a separate branch.
- Dave
On Mar 8, 2006, at 6:40 PM, Allen Gilliland wrote:
> just a reminder, silence == consent. i am planning to move forward
> with development on this.
>
> -- Allen
>
>
> On Mon, 2006-03-06 at 13:25, Allen Gilliland wrote:
>> Okay, here is a more flushed out proposal of what I think should
>> be done ...
>>
>> http://rollerweblogger.org/wiki/Wiki.jsp?
>> page=Proposal_BackendRefactorings
>>
>> Note that the driving force behind these changes is to 1) prevent
>> direct access to the PersistenceStrategy from outside the business
>> layer and 2) limit persistence logic (like transaction details) to
>> the business layer.
>>
>> I think those are very appropriate goals to have for the
>> architecture of our code.
>>
>> -- Allen
>>
>>
>> On Sun, 2006-03-05 at 10:10, Anil Gangolli wrote:
>>> Anil Gangolli wrote:
>>>>
>>>> Actually, you want those two queries to be in one transaction, not
>>>> two; otherwise they can see inconsistent state if there is another
>>>> transaction committed between the two.
>>>>
>>> Red herring on my part. Not really a new issue for us though
>>> since we
>>> are typically using default READ_COMMITTED isolation anyway.
>>>
>>> --a.
>>>
>>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
just a reminder, silence == consent. i am planning to move forward with development on this.
-- Allen
On Mon, 2006-03-06 at 13:25, Allen Gilliland wrote:
> Okay, here is a more flushed out proposal of what I think should be done ...
>
> http://rollerweblogger.org/wiki/Wiki.jsp?page=Proposal_BackendRefactorings
>
> Note that the driving force behind these changes is to 1) prevent direct access to the PersistenceStrategy from outside the business layer and 2) limit persistence logic (like transaction details) to the business layer.
>
> I think those are very appropriate goals to have for the architecture of our code.
>
> -- Allen
>
>
> On Sun, 2006-03-05 at 10:10, Anil Gangolli wrote:
> > Anil Gangolli wrote:
> > >
> > > Actually, you want those two queries to be in one transaction, not
> > > two; otherwise they can see inconsistent state if there is another
> > > transaction committed between the two.
> > >
> > Red herring on my part. Not really a new issue for us though since we
> > are typically using default READ_COMMITTED isolation anyway.
> >
> > --a.
> >
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
Okay, here is a more flushed out proposal of what I think should be done ...
http://rollerweblogger.org/wiki/Wiki.jsp?page=Proposal_BackendRefactorings
Note that the driving force behind these changes is to 1) prevent direct access to the PersistenceStrategy from outside the business layer and 2) limit persistence logic (like transaction details) to the business layer.
I think those are very appropriate goals to have for the architecture of our code.
-- Allen
On Sun, 2006-03-05 at 10:10, Anil Gangolli wrote:
> Anil Gangolli wrote:
> >
> > Actually, you want those two queries to be in one transaction, not
> > two; otherwise they can see inconsistent state if there is another
> > transaction committed between the two.
> >
> Red herring on my part. Not really a new issue for us though since we
> are typically using default READ_COMMITTED isolation anyway.
>
> --a.
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
Anil Gangolli wrote:
>
> Actually, you want those two queries to be in one transaction, not
> two; otherwise they can see inconsistent state if there is another
> transaction committed between the two.
>
Red herring on my part. Not really a new issue for us though since we
are typically using default READ_COMMITTED isolation anyway.
--a.
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
David M Johnson wrote:
>
> On Mar 2, 2006, at 6:53 PM, Allen Gilliland wrote:
>> On Thu, 2006-03-02 at 14:31, David M Johnson wrote:
>>> On Mar 2, 2006, at 1:55 PM, Allen Gilliland wrote:
>>>> On Wed, 2006-03-01 at 22:00, Anil Gangolli wrote:
>>>>> OK. -1. I'm against dropping them until we understand the
>>>>> pattern that
>>>>> is being proposed to replace them.
>>>> The pattern would be to encapsulate things in logical operations in
>>>> the manager classes. When you do things like weblog.delete() or
>>>> user.delete() or register a weblog, those things are multi step
>>>> operations to the persistence layer, but they are a single
>>>> operation logically.
>>>
>>> That's a good goal to have, but we're not there yet and it will take
>>> significant refactoring to get there. I totally agree that there is
>>> too much app logic in the presentation layer. That stuff should be
>>> moved into the manager classes behind the Roller interface.
>>
>> I'm sorry if this sounds like badgering, but "we're not there yet"
>> because nobody has stepped up and 1) identified the problem and 2)
>> said they will do the work. I am saying right now that I will do
>> that work because I think it's an extremely important and fundamental
>> aspect of the application which I believe is currently not working
>> properly.
>
> I'm definitely for refactoring to move app and persistence logic to
> the back end, would like to see some proposals and would love to help,
> but we should take somethings into consideration before we starting
> making changes.
>
> It's mostly about timing:
>
> - We have tagging work from Elias being that we need to get into the
> trunk. Probably want to hold off on refactoring until that is
> integrated as any changes will make the work harder to integrate.
>
> - Craig Russell was working on a JDO port of the back-end. Refactoring
> will clash with his work to (assuming it is still underway).
>
> - While refactoring is going on it will be more difficult for others
> to work on EJB3 or JDO stuff. For example, now that I'm getting my
> free time back (book is done next week) I'm personally interested in
> pursuing the EJB3 alternative.
>
> But there are also technical issues:
>
> - We don't want to do things that will reduce our ability to move to
> JDO or EJB3 in the future (e.g. Matt mentioned Spring's declarative
> transactions, would that cause problems or redundancy if we moved to
> EJB3 at some point?)
>
>
> Also, what specific thing are you referring to when you say "not
> working properly"
>
>
>>>> We may open and close our db connection many times in a given
>>>> request/response cycle in order to fetch data and/or save it.
>>>
>>> That's not a good idea. The design has always been to use *at most*
>>> one database connection in the processing a request. If that's not
>>> happening, then we have a bug.
>>
>> I think we are mixing concepts again. First off, unless someone is
>> not using a connection pool then technically their database
>> connection is always open. A normal connection pool keeps all of its
>> connections to the database open at all times.
>
> That's what I thought too, but I found though experience that the most
> performant approach was to get a connection at the start of a request
> and return it to the pool at the end.
>
>
>> Secondly, a transaction is more like opening a Statement for
>> execution, not opening an entirely new database connection. I am not
>> positive, but I believe Hibernate ensures that only a single database
>> connection is associated with a Session until the Session is closed.
>
> Yes, that is correct. A session has a one connection.
>
>
>> So we are agreeing on the same pattern, you open a Session once per
>> request and during that Session you perform any number of Transactions.
>
> Yes.
>
>
>> again, I think we are crossing our vocabulary. I think of a
>> transaction as being a single atomic unit of work done against the
>> database. You may do multiple sql operations in a single
>> transaction, but the transaction as a whole represents one unit of
>> work. An entire request does not have to be a single transaction in
>> my mind.
>
> Yes, I was using transaction in a more general sense, but it is true
> that most Roller requests do one database transaction (i.e. issue one
> commit() call to make changes to the database).
>
>
>> Consider. In a single request you may start by querying for a dozen
>> objects which you will use along the way, perhaps the UserData for
>> the user who is logged in, etc. Then the request hits the proper
>> struts action class where it collects data from the request object,
>> formats it, and uses it to store a new weblog entry. Then you
>> continue on to the view where you find you need to query for a few
>> more objects used to populate the display.
>
> I see what you mean. I wasn't considering a query to be a transaction.
>
Actually, you want those two queries to be in one transaction, not two;
otherwise they can see inconsistent state if there is another
transaction committed between the two.
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 2, 2006, at 6:53 PM, Allen Gilliland wrote:
> On Thu, 2006-03-02 at 14:31, David M Johnson wrote:
>> On Mar 2, 2006, at 1:55 PM, Allen Gilliland wrote:
>>> On Wed, 2006-03-01 at 22:00, Anil Gangolli wrote:
>>>> OK. -1. I'm against dropping them until we understand the
>>>> pattern that
>>>> is being proposed to replace them.
>>> The pattern would be to encapsulate things in logical operations in
>>> the manager classes. When you do things like weblog.delete() or
>>> user.delete() or register a weblog, those things are multi step
>>> operations to the persistence layer, but they are a single
>>> operation logically.
>>
>> That's a good goal to have, but we're not there yet and it will take
>> significant refactoring to get there. I totally agree that there is
>> too much app logic in the presentation layer. That stuff should be
>> moved into the manager classes behind the Roller interface.
>
> I'm sorry if this sounds like badgering, but "we're not there yet"
> because nobody has stepped up and 1) identified the problem and 2)
> said they will do the work. I am saying right now that I will do
> that work because I think it's an extremely important and
> fundamental aspect of the application which I believe is currently
> not working properly.
I'm definitely for refactoring to move app and persistence logic to
the back end, would like to see some proposals and would love to
help, but we should take somethings into consideration before we
starting making changes.
It's mostly about timing:
- We have tagging work from Elias being that we need to get into the
trunk. Probably want to hold off on refactoring until that is
integrated as any changes will make the work harder to integrate.
- Craig Russell was working on a JDO port of the back-end.
Refactoring will clash with his work to (assuming it is still underway).
- While refactoring is going on it will be more difficult for others
to work on EJB3 or JDO stuff. For example, now that I'm getting my
free time back (book is done next week) I'm personally interested in
pursuing the EJB3 alternative.
But there are also technical issues:
- We don't want to do things that will reduce our ability to move to
JDO or EJB3 in the future (e.g. Matt mentioned Spring's declarative
transactions, would that cause problems or redundancy if we moved to
EJB3 at some point?)
Also, what specific thing are you referring to when you say "not
working properly"
>>> We may open and close our db connection many times in a given
>>> request/response cycle in order to fetch data and/or save it.
>>
>> That's not a good idea. The design has always been to use *at most*
>> one database connection in the processing a request. If that's not
>> happening, then we have a bug.
>
> I think we are mixing concepts again. First off, unless someone is
> not using a connection pool then technically their database
> connection is always open. A normal connection pool keeps all of
> its connections to the database open at all times.
That's what I thought too, but I found though experience that the
most performant approach was to get a connection at the start of a
request and return it to the pool at the end.
> Secondly, a transaction is more like opening a Statement for
> execution, not opening an entirely new database connection. I am
> not positive, but I believe Hibernate ensures that only a single
> database connection is associated with a Session until the Session
> is closed.
Yes, that is correct. A session has a one connection.
> So we are agreeing on the same pattern, you open a Session once per
> request and during that Session you perform any number of
> Transactions.
Yes.
> again, I think we are crossing our vocabulary. I think of a
> transaction as being a single atomic unit of work done against the
> database. You may do multiple sql operations in a single
> transaction, but the transaction as a whole represents one unit of
> work. An entire request does not have to be a single transaction
> in my mind.
Yes, I was using transaction in a more general sense, but it is true
that most Roller requests do one database transaction (i.e. issue one
commit() call to make changes to the database).
> Consider. In a single request you may start by querying for a
> dozen objects which you will use along the way, perhaps the
> UserData for the user who is logged in, etc. Then the request hits
> the proper struts action class where it collects data from the
> request object, formats it, and uses it to store a new weblog
> entry. Then you continue on to the view where you find you need to
> query for a few more objects used to populate the display.
I see what you mean. I wasn't considering a query to be a transaction.
>> Maybe so, but until we've refactored all app and persistence logic
>> into the back-end managers, we need begin(), commit() and rollback().
>
> Ok, then how about I go ahead and do that?
>> And even after we've done that, we may still need Open Session in
>> View:
>> http://www.hibernate.org/43.html
>
> There is nothing that prevents us from doing this.
I think we two are in agreement on this.
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Thu, 2006-03-02 at 14:31, David M Johnson wrote:
> On Mar 2, 2006, at 1:55 PM, Allen Gilliland wrote:
> > On Wed, 2006-03-01 at 22:00, Anil Gangolli wrote:
> >> OK. -1. I'm against dropping them until we understand the
> >> pattern that
> >> is being proposed to replace them.
> > The pattern would be to encapsulate things in logical operations in
> > the manager classes. When you do things like weblog.delete() or
> > user.delete() or register a weblog, those things are multi step
> > operations to the persistence layer, but they are a single
> > operation logically.
>
> That's a good goal to have, but we're not there yet and it will take
> significant refactoring to get there. I totally agree that there is
> too much app logic in the presentation layer. That stuff should be
> moved into the manager classes behind the Roller interface.
I'm sorry if this sounds like badgering, but "we're not there yet" because nobody has stepped up and 1) identified the problem and 2) said they will do the work. I am saying right now that I will do that work because I think it's an extremely important and fundamental aspect of the application which I believe is currently not working properly.
>
>
> >> Ideally there should be very few places in the app where explicit
> >> transaction demarcation is needed. If we really have that many
> >> calls,
> >> it probably is a sign that it isn't being done right. Typically the
> >> demarcation should be very early on request stacks in generic places
> >> (filters, async task execution, etc.).
> >
> > This part I disagree with. My opinion is that each time a db
> > connection is opened and closed that represents a "transaction"
> > with the database.
>
> That's not true. You can open a connection at the start of a request,
> do several transactions, and then close the connection.
>
>
> > We may open and close our db connection many times in a given
> > request/response cycle in order to fetch data and/or save it.
>
> That's not a good idea. The design has always been to use *at most*
> one database connection in the processing a request. If that's not
> happening, then we have a bug.
I think we are mixing concepts again. First off, unless someone is not using a connection pool then technically their database connection is always open. A normal connection pool keeps all of its connections to the database open at all times. Secondly, a transaction is more like opening a Statement for execution, not opening an entirely new database connection. I am not positive, but I believe Hibernate ensures that only a single database connection is associated with a Session until the Session is closed.
So we are agreeing on the same pattern, you open a Session once per request and during that Session you perform any number of Transactions.
>
>
> > You can't just lump the entire request/response cycle into a single
> > transaction.
>
> In most cases, at least in Roller, a request is exactly one transaction.
again, I think we are crossing our vocabulary. I think of a transaction as being a single atomic unit of work done against the database. You may do multiple sql operations in a single transaction, but the transaction as a whole represents one unit of work. An entire request does not have to be a single transaction in my mind.
Consider. In a single request you may start by querying for a dozen objects which you will use along the way, perhaps the UserData for the user who is logged in, etc. Then the request hits the proper struts action class where it collects data from the request object, formats it, and uses it to store a new weblog entry. Then you continue on to the view where you find you need to query for a few more objects used to populate the display.
In my mind that single request included multiple transactions.
>
>
> >> Regarding existing transaction behavior, there are a couple of
> >> things to
> >> keep in mind: (a) generally there is an implicit transaction
> >> associated
> >> with all work on the JDBC connection between commits, (b) Roller code
> >> may in places be relying on automatic rollback on return to the pool,
> >> which strictly speaking it shouldn't.
> >
> > a. fine, but that transaction logic should be hidden from the
> > application and masked by our persistence layer classes. the whole
> > point of architecting the persistence layer interfaces is to keep
> > persistence specific logic out of the rest of the code.
>
> Maybe so, but until we've refactored all app and persistence logic
> into the back-end managers, we need begin(), commit() and rollback().
Ok, then how about I go ahead and do that?
>
> And even after we've done that, we may still need Open Session in View:
> http://www.hibernate.org/43.html
There is nothing that prevents us from doing this.
>
>
> >> I don't think we need to refer to Hibernate Transactions explicitly.
> >> That doesn't mean we don't use transactions now.
> >
> > well, i think that our Hibernate persistence implementation should
> > use Hibernate Transactions explicitly.
>
> Yeah, that's what the Hibernate docs recommend. It does add a
> dependency on the JTA jars though.
I would have to look into it further, but I don't think you have to use JTA. Hibernate's built-in Transaction support is meant to allow for plugging in various transaction strategies, like JTA.
-- Allen
>
>
> > I still claim that our current code does not support transactions.
>
> Have you turned auto-commit off and tried to verify that?
>
> - Dave
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by David M Johnson <Da...@Sun.COM>.
On Mar 2, 2006, at 1:55 PM, Allen Gilliland wrote:
> On Wed, 2006-03-01 at 22:00, Anil Gangolli wrote:
>> OK. -1. I'm against dropping them until we understand the
>> pattern that
>> is being proposed to replace them.
> The pattern would be to encapsulate things in logical operations in
> the manager classes. When you do things like weblog.delete() or
> user.delete() or register a weblog, those things are multi step
> operations to the persistence layer, but they are a single
> operation logically.
That's a good goal to have, but we're not there yet and it will take
significant refactoring to get there. I totally agree that there is
too much app logic in the presentation layer. That stuff should be
moved into the manager classes behind the Roller interface.
>> Ideally there should be very few places in the app where explicit
>> transaction demarcation is needed. If we really have that many
>> calls,
>> it probably is a sign that it isn't being done right. Typically the
>> demarcation should be very early on request stacks in generic places
>> (filters, async task execution, etc.).
>
> This part I disagree with. My opinion is that each time a db
> connection is opened and closed that represents a "transaction"
> with the database.
That's not true. You can open a connection at the start of a request,
do several transactions, and then close the connection.
> We may open and close our db connection many times in a given
> request/response cycle in order to fetch data and/or save it.
That's not a good idea. The design has always been to use *at most*
one database connection in the processing a request. If that's not
happening, then we have a bug.
> You can't just lump the entire request/response cycle into a single
> transaction.
In most cases, at least in Roller, a request is exactly one transaction.
>> Regarding existing transaction behavior, there are a couple of
>> things to
>> keep in mind: (a) generally there is an implicit transaction
>> associated
>> with all work on the JDBC connection between commits, (b) Roller code
>> may in places be relying on automatic rollback on return to the pool,
>> which strictly speaking it shouldn't.
>
> a. fine, but that transaction logic should be hidden from the
> application and masked by our persistence layer classes. the whole
> point of architecting the persistence layer interfaces is to keep
> persistence specific logic out of the rest of the code.
Maybe so, but until we've refactored all app and persistence logic
into the back-end managers, we need begin(), commit() and rollback().
And even after we've done that, we may still need Open Session in View:
http://www.hibernate.org/43.html
>> I don't think we need to refer to Hibernate Transactions explicitly.
>> That doesn't mean we don't use transactions now.
>
> well, i think that our Hibernate persistence implementation should
> use Hibernate Transactions explicitly.
Yeah, that's what the Hibernate docs recommend. It does add a
dependency on the JTA jars though.
> I still claim that our current code does not support transactions.
Have you turned auto-commit off and tried to verify that?
- Dave
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Wed, 2006-03-01 at 22:00, Anil Gangolli wrote:
> OK. -1. I'm against dropping them until we understand the pattern that
> is being proposed to replace them.
The pattern would be to encapsulate things in logical operations in the manager classes. When you do things like weblog.delete() or user.delete() or register a weblog, those things are multi step operations to the persistence layer, but they are a single operation logically.
This is how I have always done things in the past and I have never needed direct control over the transactional state of persistence operations before.
>
> It does sound like we need to clean things up.
In my mind this basically proves my point that we don't need control over persistence transactions in the presentation layer. The fact is that currently those transaction methods are not doing anything to provide transactions like they suggest. The way the application is running now is without transaction support, and it seems to be doing fine like that.
>
> Here are some things to keep in mind regarding the questions posed in
> your message.
>
> In general we need to demarcate transactions around the entire unit of
> work. The persistence layer generally does not know the unit of work
> boundaries. Each call to the persistence layer is not its own
> transaction. It is part of a transaction, the boundaries of which
> generally need to span multiple calls from the app layer and also calls
> *between* managers in the persistence layer.
I agree that we need to provide transactions for multi step persistence operations. However, I believe that our Manager classes provide a bridge between logical operations like weblog.delete() or createWeblog() and the actual persistence operations which are needed to carry out those logical operations.
The exact implementation of how createWeblog() works to persist the data is meant to be masked by the Manager classes specifically so that the presentation layer doesn't have to deal with it.
>
> Ideally there should be very few places in the app where explicit
> transaction demarcation is needed. If we really have that many calls,
> it probably is a sign that it isn't being done right. Typically the
> demarcation should be very early on request stacks in generic places
> (filters, async task execution, etc.).
This part I disagree with. My opinion is that each time a db connection is opened and closed that represents a "transaction" with the database. We may open and close our db connection many times in a given request/response cycle in order to fetch data and/or save it. You can't just lump the entire request/response cycle into a single transaction.
>
> Regarding existing transaction behavior, there are a couple of things to
> keep in mind: (a) generally there is an implicit transaction associated
> with all work on the JDBC connection between commits, (b) Roller code
> may in places be relying on automatic rollback on return to the pool,
> which strictly speaking it shouldn't.
a. fine, but that transaction logic should be hidden from the application and masked by our persistence layer classes. the whole point of architecting the persistence layer interfaces is to keep persistence specific logic out of the rest of the code.
b. that's just bad coding.
>
> I don't think we need to refer to Hibernate Transactions explicitly.
> That doesn't mean we don't use transactions now.
well, i think that our Hibernate persistence implementation should use Hibernate Transactions explicitly.
I still claim that our current code does not support transactions.
-- Allen
>
> --a.
>
>
>
> Allen Gilliland wrote:
> > On Wed, 2006-03-01 at 08:55, Anil Gangolli wrote:
> >
> >> We definitely need transactions with our coding pattern. We will get
> >> inconsistent data states without them if the server goes down or a
> >> request hits an exception after partially updating.
> >>
> >
> > That's fine, we can have transactions, but does the transaction logic need to be controlled from outside of our persistence layer?
> >
> > I would expect that calling WeblogManager.createWeblog() would perform a number of writes which are wrapped in a transaction, but the caller of that method doesn't need to know about that. All it needs to know is if the operation as a whole was successful.
> >
> > I will admit that I haven't yet taken the time to truly analyze all the places in which we are doing persistence operations that require full transaction support, but even without that info I am asking the basic question of whether or not we need to expose persistence specific methods like begin(), commit(), and rollback() into presentation layer code. In my perfect world the details of how a persitence operation is handled is black boxed from the point of view of the presentation code.
> >
> >
> >> We are using transactions, or were as of about 1.2. I'm not sure why
> >> you say we aren't using them. I fixed some bugs related to this in 1.0
> >> or so. It does require that your db and db configuration support
> >> transactions.
> >>
> >
> > well, I am looking at our Hibernate implementation and we never use the Transaction class of hibernate, so that is one indication. another indication is that we aren't using the Roller.rollback() function, so whatever transactions we are trying to do we aren't rolling them back if they fail.
> >
> >
> >> Only a few calls are necessary, so the number of calls is not an
> >> indication of lack of use; the transaction demarcation calls should be
> >> early in the entry points of requests into the system or in tasks
> >> executed asynchronously in their own threads. These are supposed to
> >> associate a transaction with the thread. Everything else gets the
> >> current transaction on the thread. It's a standard pattern.
> >>
> >
> > well, a few calls multiplied times the number of places where the transaction needs to be started and commited/rolled back. i consider all communication with the persistence layer to be a "transaction".
> >
> > Please note that I am not suggesting that we abandon the use of any transaction support. I am only trying to question whether we need to expose persistence transaction methods outside of our actual persistence layer. I fully agree that behind the scenes of the persistence layer transactions should be supported.
> >
> > -- Allen
> >
> >
> >
> >> --a.
> >>
> >>
> >>
> >>
> >> Allen Gilliland wrote:
> >>
> >>> I have been going through some of the Roller backend and looking at some
> >>> parts of our Hibernate implementation and I have gotten myself to
> >>> wondering if we really need the transaction methods begin() and commit()
> >>> which are part of the Roller and PersistenceStrategy interfaces.
> >>>
> >>> I think I understand where the idea for these methods came from and they
> >>> make some sense, but after inspecting the code a bit it seems like we
> >>> definitely don't actually use them.
> >>>
> >>> In the current code I only see this ...
> >>>
> >>> Roller.begin() - 6 uses
> >>> Roller.begin(user) - 4 uses
> >>> Roller.commit() - 7 uses
> >>> Roller.rollback() - 0 uses
> >>> PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
> >>> PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
> >>>
> >>> I also noticed that in our Hibernate implementation we aren't actually
> >>> using Transactions anyways, so even if these methods were in full use we
> >>> wouldn't have been taking advantage of them.
> >>>
> >>> So, the deal is that if we want to use these transaction methods then we
> >>> need to make sure we are using them *everywhere*, otherwise they are
> >>> doing us no good and only confusing things. Alternatively I would
> >>> propose that we drop these methods and let implementors of a persistence
> >>> strategy handle the details of transactions within their own
> >>> implementations.
> >>>
> >>> My vote is to drop these methods. I can see the potential value in
> >>> having them (if they were working properly), but my opinion is that we
> >>> aren't really doing any persistence transactions complicated enough to
> >>> really warrant the additional complexity and overhead of having them.
> >>> We have to go one way or the other, so we either remove them or add them
> >>> in everywhere.
> >>>
> >>> Who else has an opinion?
> >>>
> >>> -- Allen
> >>>
> >>>
> >>>
> >>>
> >>>
> >
> >
> >
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
OK. -1. I'm against dropping them until we understand the pattern that
is being proposed to replace them.
It does sound like we need to clean things up.
Here are some things to keep in mind regarding the questions posed in
your message.
In general we need to demarcate transactions around the entire unit of
work. The persistence layer generally does not know the unit of work
boundaries. Each call to the persistence layer is not its own
transaction. It is part of a transaction, the boundaries of which
generally need to span multiple calls from the app layer and also calls
*between* managers in the persistence layer.
Ideally there should be very few places in the app where explicit
transaction demarcation is needed. If we really have that many calls,
it probably is a sign that it isn't being done right. Typically the
demarcation should be very early on request stacks in generic places
(filters, async task execution, etc.).
Regarding existing transaction behavior, there are a couple of things to
keep in mind: (a) generally there is an implicit transaction associated
with all work on the JDBC connection between commits, (b) Roller code
may in places be relying on automatic rollback on return to the pool,
which strictly speaking it shouldn't.
I don't think we need to refer to Hibernate Transactions explicitly.
That doesn't mean we don't use transactions now.
--a.
Allen Gilliland wrote:
> On Wed, 2006-03-01 at 08:55, Anil Gangolli wrote:
>
>> We definitely need transactions with our coding pattern. We will get
>> inconsistent data states without them if the server goes down or a
>> request hits an exception after partially updating.
>>
>
> That's fine, we can have transactions, but does the transaction logic need to be controlled from outside of our persistence layer?
>
> I would expect that calling WeblogManager.createWeblog() would perform a number of writes which are wrapped in a transaction, but the caller of that method doesn't need to know about that. All it needs to know is if the operation as a whole was successful.
>
> I will admit that I haven't yet taken the time to truly analyze all the places in which we are doing persistence operations that require full transaction support, but even without that info I am asking the basic question of whether or not we need to expose persistence specific methods like begin(), commit(), and rollback() into presentation layer code. In my perfect world the details of how a persitence operation is handled is black boxed from the point of view of the presentation code.
>
>
>> We are using transactions, or were as of about 1.2. I'm not sure why
>> you say we aren't using them. I fixed some bugs related to this in 1.0
>> or so. It does require that your db and db configuration support
>> transactions.
>>
>
> well, I am looking at our Hibernate implementation and we never use the Transaction class of hibernate, so that is one indication. another indication is that we aren't using the Roller.rollback() function, so whatever transactions we are trying to do we aren't rolling them back if they fail.
>
>
>> Only a few calls are necessary, so the number of calls is not an
>> indication of lack of use; the transaction demarcation calls should be
>> early in the entry points of requests into the system or in tasks
>> executed asynchronously in their own threads. These are supposed to
>> associate a transaction with the thread. Everything else gets the
>> current transaction on the thread. It's a standard pattern.
>>
>
> well, a few calls multiplied times the number of places where the transaction needs to be started and commited/rolled back. i consider all communication with the persistence layer to be a "transaction".
>
> Please note that I am not suggesting that we abandon the use of any transaction support. I am only trying to question whether we need to expose persistence transaction methods outside of our actual persistence layer. I fully agree that behind the scenes of the persistence layer transactions should be supported.
>
> -- Allen
>
>
>
>> --a.
>>
>>
>>
>>
>> Allen Gilliland wrote:
>>
>>> I have been going through some of the Roller backend and looking at some
>>> parts of our Hibernate implementation and I have gotten myself to
>>> wondering if we really need the transaction methods begin() and commit()
>>> which are part of the Roller and PersistenceStrategy interfaces.
>>>
>>> I think I understand where the idea for these methods came from and they
>>> make some sense, but after inspecting the code a bit it seems like we
>>> definitely don't actually use them.
>>>
>>> In the current code I only see this ...
>>>
>>> Roller.begin() - 6 uses
>>> Roller.begin(user) - 4 uses
>>> Roller.commit() - 7 uses
>>> Roller.rollback() - 0 uses
>>> PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
>>> PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
>>>
>>> I also noticed that in our Hibernate implementation we aren't actually
>>> using Transactions anyways, so even if these methods were in full use we
>>> wouldn't have been taking advantage of them.
>>>
>>> So, the deal is that if we want to use these transaction methods then we
>>> need to make sure we are using them *everywhere*, otherwise they are
>>> doing us no good and only confusing things. Alternatively I would
>>> propose that we drop these methods and let implementors of a persistence
>>> strategy handle the details of transactions within their own
>>> implementations.
>>>
>>> My vote is to drop these methods. I can see the potential value in
>>> having them (if they were working properly), but my opinion is that we
>>> aren't really doing any persistence transactions complicated enough to
>>> really warrant the additional complexity and overhead of having them.
>>> We have to go one way or the other, so we either remove them or add them
>>> in everywhere.
>>>
>>> Who else has an opinion?
>>>
>>> -- Allen
>>>
>>>
>>>
>>>
>>>
>
>
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Allen Gilliland <Al...@Sun.COM>.
On Wed, 2006-03-01 at 08:55, Anil Gangolli wrote:
> We definitely need transactions with our coding pattern. We will get
> inconsistent data states without them if the server goes down or a
> request hits an exception after partially updating.
That's fine, we can have transactions, but does the transaction logic need to be controlled from outside of our persistence layer?
I would expect that calling WeblogManager.createWeblog() would perform a number of writes which are wrapped in a transaction, but the caller of that method doesn't need to know about that. All it needs to know is if the operation as a whole was successful.
I will admit that I haven't yet taken the time to truly analyze all the places in which we are doing persistence operations that require full transaction support, but even without that info I am asking the basic question of whether or not we need to expose persistence specific methods like begin(), commit(), and rollback() into presentation layer code. In my perfect world the details of how a persitence operation is handled is black boxed from the point of view of the presentation code.
>
> We are using transactions, or were as of about 1.2. I'm not sure why
> you say we aren't using them. I fixed some bugs related to this in 1.0
> or so. It does require that your db and db configuration support
> transactions.
well, I am looking at our Hibernate implementation and we never use the Transaction class of hibernate, so that is one indication. another indication is that we aren't using the Roller.rollback() function, so whatever transactions we are trying to do we aren't rolling them back if they fail.
>
> Only a few calls are necessary, so the number of calls is not an
> indication of lack of use; the transaction demarcation calls should be
> early in the entry points of requests into the system or in tasks
> executed asynchronously in their own threads. These are supposed to
> associate a transaction with the thread. Everything else gets the
> current transaction on the thread. It's a standard pattern.
well, a few calls multiplied times the number of places where the transaction needs to be started and commited/rolled back. i consider all communication with the persistence layer to be a "transaction".
Please note that I am not suggesting that we abandon the use of any transaction support. I am only trying to question whether we need to expose persistence transaction methods outside of our actual persistence layer. I fully agree that behind the scenes of the persistence layer transactions should be supported.
-- Allen
>
> --a.
>
>
>
>
> Allen Gilliland wrote:
> > I have been going through some of the Roller backend and looking at some
> > parts of our Hibernate implementation and I have gotten myself to
> > wondering if we really need the transaction methods begin() and commit()
> > which are part of the Roller and PersistenceStrategy interfaces.
> >
> > I think I understand where the idea for these methods came from and they
> > make some sense, but after inspecting the code a bit it seems like we
> > definitely don't actually use them.
> >
> > In the current code I only see this ...
> >
> > Roller.begin() - 6 uses
> > Roller.begin(user) - 4 uses
> > Roller.commit() - 7 uses
> > Roller.rollback() - 0 uses
> > PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
> > PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
> >
> > I also noticed that in our Hibernate implementation we aren't actually
> > using Transactions anyways, so even if these methods were in full use we
> > wouldn't have been taking advantage of them.
> >
> > So, the deal is that if we want to use these transaction methods then we
> > need to make sure we are using them *everywhere*, otherwise they are
> > doing us no good and only confusing things. Alternatively I would
> > propose that we drop these methods and let implementors of a persistence
> > strategy handle the details of transactions within their own
> > implementations.
> >
> > My vote is to drop these methods. I can see the potential value in
> > having them (if they were working properly), but my opinion is that we
> > aren't really doing any persistence transactions complicated enough to
> > really warrant the additional complexity and overhead of having them.
> > We have to go one way or the other, so we either remove them or add them
> > in everywhere.
> >
> > Who else has an opinion?
> >
> > -- Allen
> >
> >
> >
> >
>
Re: Roller persistence transactions, do we need begin(), commit(),
rollback()?
Posted by Anil Gangolli <an...@busybuddha.org>.
We definitely need transactions with our coding pattern. We will get
inconsistent data states without them if the server goes down or a
request hits an exception after partially updating.
We are using transactions, or were as of about 1.2. I'm not sure why
you say we aren't using them. I fixed some bugs related to this in 1.0
or so. It does require that your db and db configuration support
transactions.
Only a few calls are necessary, so the number of calls is not an
indication of lack of use; the transaction demarcation calls should be
early in the entry points of requests into the system or in tasks
executed asynchronously in their own threads. These are supposed to
associate a transaction with the thread. Everything else gets the
current transaction on the thread. It's a standard pattern.
--a.
Allen Gilliland wrote:
> I have been going through some of the Roller backend and looking at some
> parts of our Hibernate implementation and I have gotten myself to
> wondering if we really need the transaction methods begin() and commit()
> which are part of the Roller and PersistenceStrategy interfaces.
>
> I think I understand where the idea for these methods came from and they
> make some sense, but after inspecting the code a bit it seems like we
> definitely don't actually use them.
>
> In the current code I only see this ...
>
> Roller.begin() - 6 uses
> Roller.begin(user) - 4 uses
> Roller.commit() - 7 uses
> Roller.rollback() - 0 uses
> PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
> PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
>
> I also noticed that in our Hibernate implementation we aren't actually
> using Transactions anyways, so even if these methods were in full use we
> wouldn't have been taking advantage of them.
>
> So, the deal is that if we want to use these transaction methods then we
> need to make sure we are using them *everywhere*, otherwise they are
> doing us no good and only confusing things. Alternatively I would
> propose that we drop these methods and let implementors of a persistence
> strategy handle the details of transactions within their own
> implementations.
>
> My vote is to drop these methods. I can see the potential value in
> having them (if they were working properly), but my opinion is that we
> aren't really doing any persistence transactions complicated enough to
> really warrant the additional complexity and overhead of having them.
> We have to go one way or the other, so we either remove them or add them
> in everywhere.
>
> Who else has an opinion?
>
> -- Allen
>
>
>
>
Re: Roller persistence transactions, do we need begin(), commit(), rollback()?
Posted by Matt Raible <mr...@gmail.com>.
My opinion? Use Spring to wire up our backend and use its declarative
transactions to wrap methods that should be transactional.
;-)
Matt
On 2/28/06, Allen Gilliland <Al...@sun.com> wrote:
> I have been going through some of the Roller backend and looking at some
> parts of our Hibernate implementation and I have gotten myself to
> wondering if we really need the transaction methods begin() and commit()
> which are part of the Roller and PersistenceStrategy interfaces.
>
> I think I understand where the idea for these methods came from and they
> make some sense, but after inspecting the code a bit it seems like we
> definitely don't actually use them.
>
> In the current code I only see this ...
>
> Roller.begin() - 6 uses
> Roller.begin(user) - 4 uses
> Roller.commit() - 7 uses
> Roller.rollback() - 0 uses
> PersistenceStrategy.begin() - 4 uses, just from RollerImpl classes
> PersistenceStrategy.commit() - 4 uses, mainly RollerImpl classes
>
> I also noticed that in our Hibernate implementation we aren't actually
> using Transactions anyways, so even if these methods were in full use we
> wouldn't have been taking advantage of them.
>
> So, the deal is that if we want to use these transaction methods then we
> need to make sure we are using them *everywhere*, otherwise they are
> doing us no good and only confusing things. Alternatively I would
> propose that we drop these methods and let implementors of a persistence
> strategy handle the details of transactions within their own
> implementations.
>
> My vote is to drop these methods. I can see the potential value in
> having them (if they were working properly), but my opinion is that we
> aren't really doing any persistence transactions complicated enough to
> really warrant the additional complexity and overhead of having them.
> We have to go one way or the other, so we either remove them or add them
> in everywhere.
>
> Who else has an opinion?
>
> -- Allen
>
>
>