You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Colin Paul Adams <co...@colina.demon.co.uk> on 2004/07/06 09:24:18 UTC
Flowscript, CForms and one writer, many readers
I have a simple diary application.
At present, it reads the events data from an XML file.
Using CForms and the XML file binding, anyone can update the events
data.
Of course, this suffers from the usual problems if two people try to
update the data at the same time.
So I think I need to use a database and transactions to solve this.
Reading around, it seems binding to a bean using JDO is a decent way
to go.
I can't find a tutorial on JDO, so I've been looking at the JDO Cforms
example and the JDO javadocs from SUN's site.
As far as I can tell, I need a single application-wide
PersistenceManager.
But I can't find a way to store such a singleton object in
flowscript. There is a request object, a saession object, but no
application object (like ASP has).
What's the way to do this in flowscript?
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Flowscript, CForms and one writer, many readers
Posted by Antonio Gallardo <ag...@agssa.net>.
Ugo Cei dijo:
> Il giorno 06/lug/04, alle 09:24, Colin Paul Adams ha scritto:
>> Reading around, it seems binding to a bean using JDO is a decent way
>> to go.
>
> Don't know about JDO, but Hibernate supports automatic versioning
> out-of-the-box.
Yep. JDO support it.
Best Regards,
Antonio Gallardo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Session timeouts
Posted by Ralph Goers <Ra...@dslextreme.com>.
That is a funny way to put it. Cocoon doesn't provide anything regarding
session listeners nor does it prevent you from doing so. In fact, it
is extremely easy. I created a single "SessionData" class that is nothing
more than a container for all my other session-based objects. This class
registers itself as an HttpSessionListener. When a timeout occurs it calls
methods in the objects registered with it so that they can clean
up. Cocoon doesn't require any cleaning up so it isn't a problem.
You said below, "I would have expected coccon to make use of the
sessionDestroyed method on this object". What object are you referring
to? AFAIK, all Cocoon requires is that it's Session-based objects be
deleted at Session termination - which the container takes care of
automatically.
Ralph
At 7/6/2004 08:54 AM, you wrote:
>But it is important to be able to take control when a session expires,
>so you can free up any resources in use (such as a database
>connection).
>The interface HttpSessionListener is available for objects to
>receive notification of session binding and unbinding.
>I would have expected coccon to make use of the sessionDestroyed
>method on this object to be able to pass control at session
>termination, but I cannot find any reference in the source code to
>HttpSessionListener so I conclude that it does not allow this.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Session timeouts
Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Ugo" == Ugo Cei <ug...@apache.org> writes:
Ugo> Il giorno 06/lug/04, alle 11:26, Colin Paul Adams ha scritto:
>> Except having now looked on the documentation for session
>> support in Cocoon, there does not appear to be any support for
>> session timeouts.
Ugo> Session timeouts are the concern of the servlet container. It
Ugo> should be configured somewhere in WEB-INF/web.xml, if I
Ugo> remember correctly.
But it is important to be able to take control when a session expires,
so you can free up any resources in use (such as a database
connection).
The interface HttpSessionListener is available for objects to
receive notification of session binding and unbinding.
I would have expected coccon to make use of the sessionDestroyed
method on this object to be able to pass control at session
termination, but I cannot find any reference in the source code to
HttpSessionListener so I conclude that it does not allow this.
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Session timeouts
Posted by Ugo Cei <ug...@apache.org>.
Il giorno 06/lug/04, alle 11:26, Colin Paul Adams ha scritto:
> Except having now looked on the documentation for session support in
> Cocoon, there does not appear to be any support for session timeouts.
Session timeouts are the concern of the servlet container. It should be
configured somewhere in WEB-INF/web.xml, if I remember correctly.
--
Ugo Cei - http://beblogging.com/
Session timeouts
Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Colin" == Colin Paul Adams <co...@colina.demon.co.uk> writes:
>>>>> "Ugo" == Ugo Cei <ug...@apache.org> writes:
Ugo> the user never submits the form, but just closes the browser,
Ugo> walks away or surfs to some other website? The transaction is
Ugo> never closed and the records are locked forever (unless you
Ugo> implement some kind of timeout).
Colin> That is what I was intending to do.
Except having now looked on the documentation for session support in
Cocoon, there does not appear to be any support for session timeouts.
Not can I see anything about transaction timeouts in JDO.
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Flowscript, CForms and one writer, many readers
Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Ugo" == Ugo Cei <ug...@apache.org> writes:
Ugo> the user never submits the form, but just closes the browser,
Ugo> walks away or surfs to some other website? The transaction is
Ugo> never closed and the records are locked forever (unless you
Ugo> implement some kind of timeout).
That is what I was intending to do.
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Flowscript, CForms and one writer, many readers
Posted by Ugo Cei <ug...@apache.org>.
Il giorno 06/lug/04, alle 09:24, Colin Paul Adams ha scritto:
> I have a simple diary application.
> At present, it reads the events data from an XML file.
> Using CForms and the XML file binding, anyone can update the events
> data.
>
> Of course, this suffers from the usual problems if two people try to
> update the data at the same time.
>
> So I think I need to use a database and transactions to solve this.
No, you don't. What you're trying to do is called "pessimistic locking"
and unfortunately it is very hard to implement in a web application.
Imagine a user selects the data for updating, therefore locking it.
Then the user is presented with a form for editing. You have a pending
transaction and one or more locked records. What happens if the user
never submits the form, but just closes the browser, walks away or
surfs to some other website? The transaction is never closed and the
records are locked forever (unless you implement some kind of timeout).
A possible solution is the so-called "optimistic locking" strategy.
First user select the data but does not lock it. When the form is
submitted, before applying the updates the system checks if the data
have been modified since the select and in this case it either refuses
to update or, if possible, merges the updates.
This is how CVS works, for instance, and the easiest way to implement
it is via a "version" attribute on the data. Whenever an update is
performed, the version number is incremented. If I retrieved data at
version "1", before committing my updates the system has to verify that
the data in storage is still at version "1". If it is, it commits and
increments the version number to "2". If it isn't, it either attempts a
merge or fails. If it fails, it can present the user with the latest
version of stored data and ask him to apply his changes again.
Optimistic locking increases concurrency at the expense of the
occasional conflict. You're being optimistic in that you assume the
conflicts are rare. Pessimistic locking decreases concurrency (some
users may be forced to wait) but guarantees that you won't get any
conflict. Unfortunately, as I wrote above, implementing pessimistic
locking in a web aplication is hard. Since your data is XML, it might
be possible to easily implement a merging algorithm, so that even in
the event of conflicts, most of them might be solved without the user
knowing about them. In this case, I'd opt for the optimistic locking
strategy.
Now, you don't need an RDBMS to implement an optimistic locking
strategy. You just have to add a "version" attribute to your records,
the logic to manage it and make sure that only one thread at a time is
allowed to write the data.
> Reading around, it seems binding to a bean using JDO is a decent way
> to go.
Don't know about JDO, but Hibernate supports automatic versioning
out-of-the-box.
> But I can't find a way to store such a singleton object in
> flowscript. There is a request object, a saession object, but no
> application object (like ASP has).
> What's the way to do this in flowscript?
If you have a Java class implementing the singleton pattern, it's
supposed to have a method like:
public static MySingleton getInsance();
which returns the only existing instance of the class. Then you just
have to call it from your flowscript code.
Ugo
--
Ugo Cei - http://beblogging.com/