You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Noll <li...@noll.org> on 2001/05/05 02:31:33 UTC
JDBC driver specific functionality/GenericConnections
Hello,
I would like to access functionality specific to the MM MySql driver in an
application that uses Struts' datasource pool and am having a bit of
troubling casting a GenericConnection back to an
org.gjt.mm.mysql.Connection. Casting from a GenericConnection to an
org.gjt.mm.mysql.Connection results in a class cast exception; casting a
Statement or PreparedStatement generated by the GenericConnection produces a
null pointer exception. I am working with Struts 1.0-beta-1 and MM Mysql
2.0.4.
If it sheds any light on the problem, the MM function I would like to access
is PreparedStatement.getLastInsertID(). Has anyone successfully prosecuted
this?
On a tangential note--why is the getConnection() method in GenericConnection
private? Were it public, I assume I could use it to get an MM Connection and
execute MySql specific functions to my heart's content.
Thanks is advance,
David
Re: Struts questions for evaluation
Posted by Jonathan Asbell <ja...@i-2000.com>.
I am interested in the code. Please send.
> Hello Struts users,
>
> We are currently evaluating Struts and other web (MVC) frameworks and
would like to ask you some questions:
>
> - Is there some struts-config XML-generation from some
> modeling tool (Rose for instance) ?
>
> We would like to design a state or activity diagram in
> such a tool then generate the navigation XML file.
>
> - Can struts behave like a real state machine ?
>
> i.e. how to ensure that some Action is performed only if
> another Action (or view but is not ideal) has been
> performed with some result (success to be simple). We
> would like this to be Struts-controlled, not developper-
> controlled (check session variables, etc.).
>
> We found the built-in Struts token system but this seem
> only to be used to demarcate transactions in a set of
> views. This allow to demarcate a transaction end (token
> value change) but not an inconstency within the
> transaction (i.e. i valide twice the first page of the
> transaction) as the token value will not change.
I hit the same weakness of struts a few months ago and I enhanced some
struts
classes in order to be able for each action to specify which action has to
precede this action. This allows you to implement some kind of control flow.
For
instance you can now define an action that displays a logon page
(displayLogon)
and specify in the next action (logonAction, which gets executed when the
user
presses the submit button of the logon page) that displayLogon needed to be
executed directly before. This is more powerful than the token mechanism.
What I also did at the same time is an enhanced user authentication checking
for
each action. You can now specify a different user authorization class for
each
action, so you can easily implement a very fine grained user authorization.
Exceptions (either control flow or user authentication exceptions) are
handled
by the framework and cause a forward to different error pages.
I plan to propose this enhancement to the struts developer's group after
release
1.0 is out. If you are interested in the meantime I can send you the code.
> - Why does the struts-example perform some scoped-
> variables cleanup at the end of every Action ?
>
> As these variables are defined as scoped in the struts-
> config XML file, they should naturally live during the
> specified scope lifetime. We don't understand that in the
> struts-example (maybe this is not mandatory).
My understanding is: For request scope you normally do not need to clean up,
because the object gets removed automatically, when the request is served.
For
the session scope you pretty often want to remove e. g. a form bean, when it
is
no longer needed to keep your session data lean.
> Thank you very much for your informations about Struts.
>
> Laurent.
--- Matthias
----- Original Message -----
From: "Matthias Bauer" <Ma...@livinglogic.de>
To: <st...@jakarta.apache.org>
Sent: Monday, May 07, 2001 4:05 AM
Subject: Re: JDBC driver specific functionality/GenericConnections
> > Hello,
> >
> > I would like to access functionality specific to the MM MySql driver in
an
> > application that uses Struts' datasource pool and am having a bit of
> > troubling casting a GenericConnection back to an
> > org.gjt.mm.mysql.Connection. Casting from a GenericConnection to an
> > org.gjt.mm.mysql.Connection results in a class cast exception; casting a
> > Statement or PreparedStatement generated by the GenericConnection
produces a
> > null pointer exception. I am working with Struts 1.0-beta-1 and MM Mysql
> > 2.0.4.
> >
> > If it sheds any light on the problem, the MM function I would like to
access
> > is PreparedStatement.getLastInsertID(). Has anyone successfully
prosecuted
> > this?
>
> You must not cast GenericConnection to What you really want to do is call
> DataSource.getConnection which returns a Connection object like so:
>
> DataSource ds = getServlet().findDataSource(null);
> Connection con = ds.getConnection();
>
> You can cast this connection to org.gjt.mm.mysql.Connection without any
> problems!
>
>
> > On a tangential note--why is the getConnection() method in
GenericConnection
> > private? Were it public, I assume I could use it to get an MM Connection
and
> > execute MySql specific functions to my heart's content.
>
> You should never need to call GenericConnection.getConnection()! What you
want
> to do is always call DataSource.getConnection(), as stated above.
>
> > Thanks is advance,
> > David
>
> Hope this helps,
>
> --- Matthias
>
Re: JDBC driver specific functionality/GenericConnections
Posted by Matthias Bauer <Ma...@livinglogic.de>.
> Hello,
>
> I would like to access functionality specific to the MM MySql driver in an
> application that uses Struts' datasource pool and am having a bit of
> troubling casting a GenericConnection back to an
> org.gjt.mm.mysql.Connection. Casting from a GenericConnection to an
> org.gjt.mm.mysql.Connection results in a class cast exception; casting a
> Statement or PreparedStatement generated by the GenericConnection produces a
> null pointer exception. I am working with Struts 1.0-beta-1 and MM Mysql
> 2.0.4.
>
> If it sheds any light on the problem, the MM function I would like to access
> is PreparedStatement.getLastInsertID(). Has anyone successfully prosecuted
> this?
You must not cast GenericConnection to What you really want to do is call
DataSource.getConnection which returns a Connection object like so:
DataSource ds = getServlet().findDataSource(null);
Connection con = ds.getConnection();
You can cast this connection to org.gjt.mm.mysql.Connection without any
problems!
> On a tangential note--why is the getConnection() method in GenericConnection
> private? Were it public, I assume I could use it to get an MM Connection and
> execute MySql specific functions to my heart's content.
You should never need to call GenericConnection.getConnection()! What you want
to do is always call DataSource.getConnection(), as stated above.
> Thanks is advance,
> David
Hope this helps,
--- Matthias