You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Amita Vadhavkar <am...@gmail.com> on 2007/07/19 08:26:32 UTC

Re: Tuscany DAS M2 Exception with default useGetGeneratedKeys = true

some more thoughts on https://issues.apache.org/jira/browse/TUSCANY-1353
and https://issues.apache.org/jira/browse/TUSCANY-1417, as both JIRAs
are effectively for solving the same problem.

Another ML thread on the same issue is -
http://www.mail-archive.com/tuscany-dev@ws.apache.org/msg19752.html

1)one suggestion from Ron (based on 1353 JIRA comments) is to pass list of
vendors using system properties

2)Another approach can be add in config at <Config> level a new attribute
like
boolean - databaseGeneratedKeys - default TRUE

With this, setting of ConnectionImpl.useGetGeneratedKeys can be based on
this new attribute from Config.

3)And to further make the solution bullet proof,
ConnectionImpl.prepareStatement(queryString, returnKeys[])
can be changed as follows:-

public PreparedStatement prepareStatement(String queryString, String[]
returnKeys) throws SQLException {
    try{
        if (this.logger.isDebugEnabled()) {
        this.logger.debug("Preparing Statement: " + queryString);
        }

        if (useGetGeneratedKeys) {
        System.out.println("if true for gen keys");
        return connection.prepareStatement(queryString,
Statement.RETURN_GENERATED_KEYS);
        } else if (returnKeys.length > 0) {
        System.out.println("if false for gen keys and ret keys > 0");
        return connection.prepareStatement(queryString, returnKeys);
        }

        return connection.prepareStatement(queryString);
    }catch(Exception e){
        //try with different setting of useGetGeneratedKeys, if required
        if(this.useGetGeneratedKeys){
            System.out.println("if true for gen keys - exception - set to
false and try");
            this.useGetGeneratedKeys = false;
            return prepareStatement(queryString, returnKeys);

        }
        else{
            //this mean, we tried to manipulate this.useGetGeneratedKeys to
false,
            //but was of no use, so reset it back as per user Config
            if(DAS.databaseGeneratedKeys) {
                this.useGetGeneratedKeys = true;
            }
            System.out.println("if false for gen keys - exception - work
further");
            if(e instanceof SQLException){
                throw (SQLException)e;
            }
            else{
                throw new RuntimeException(e);
            }
        }
    }
}

With this change, irrespective of what is the Class of Exception occuring,
at maximum one attempt will be made to try with "useGetGeneratedKeys" false.

4)Also, I could see one design change - as -
In DASImpl, we contain java.sql.Connection and then in 2 different places in
BaseCommandImpl, we create new instances of ConnectionImpl. Will it be a
good idea, if DASImpl itself can contain ConnectionImpl (instead of
java.sql.Connection) and pass it to the Commands? This way,  we will be
reducing references to java.sql.Connection and number of ConnectionImpl
instances in  the DAS Runtime. This can have some benefit in the context of
memory utilization

Thoughts?

Regards,
Amita

On 6/27/07, Luciano Resende <lu...@gmail.com> wrote:
>
> Hi Ron
>
>    Could you please provide the das configuration file being used for this
> app.
>
> Thanks
>
> On 6/26/07, Ron Gavlin <rg...@yahoo.com> wrote:
> > Hi Amita,
> >
> > Yes, the driver supports this statement. However, is it legal to use
> this type of PreparedStatement if the corresponding table has no generated
> keys?
> >
> > - Ron
> >
> > ----- Original Message ----
> > From: Amita Vadhavkar <am...@gmail.com>
> > To: tuscany-user@ws.apache.org
> > Sent: Tuesday, June 26, 2007 7:51:12 AM
> > Subject: Re: Tuscany DA S M2 Exception with default useGetGeneratedKeys
> = true
> >
> >  Please check if the driver you are using is supporting
> > connection.prepareStatement(queryString,
> Statement.*RETURN_GENERATED_KEYS*);
> >
> >
> > Regards,
> > Amita
> >
> > On 6/18/07, Ron Gavlin <rg...@yahoo.com> wrote:
> > >
> > > Greetings,
> > >
> > > I am having problems inserting rows with Tuscany DAS M2 using the BEA
> > > WebLogic Sybase JDBC driver (BEA WebLogic 8.1). The code below
> generates
> > > the following stacktrace:
> > >
> > > ...
> > > Command insert = das.createCommand("insert into Test (testCol1,
> testCol2)
> > > values (?, ?)");
> > > insert.setParameter(1, "str1");
> > > insert.setParameter(2, "str2");
> > > insert.execute();
> > >
> > > Stacktrace:
> > >
> > > Caused by: java.sql.SQLException: [BEA][Sybase JDBC Driver]No rows
> > > affected.
> > >    at weblogic.jdbc.base.BaseExceptions.createException(Unknown
> Source)
> > >    at weblogic.jdbc.base.BaseException.getException(Unknown Source)
> > >    at weblogic.jdbc.base.BaseStatement.executeUpdateInternal(Unknown
> > > Source)
> > >    at weblogic.jdbc.base.BasePreparedStatement.executeUpdate(Unknown
> > > Source)
> > >    at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(
> > > PreparedStatement.java:159)
> > >    at org.apache.tusany.das.rdb.impl.Statement.executeUpdate(
> > > Statement.java:173)
> > >    at org.apache.tusany.das.rdb.impl.Statement.executeUpdate(
> > > Statement.java:133)
> > >
> > >    at org.apache.tusany.das.rdb.impl.InsertCommandImpl.execute(
> > > InsertCommandImpl.java:44)
> > >
> > >
> > >
> > > While interactively debugging
> > > org.apache.tuscany.das.rdb.impl.ConnectionImpl.prepareStatement(String
> > > queryString, String[] returnKeys), I noticed if I manually change the
> > > boolean member variable useGetGeneratedKeys to false, no exception is
> > > generated and the insert works as designed. What is the correct fix
> here?
> > >
> > > - Ron
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: tuscany-user-help@ws.apache.org
> > >
> > >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: tuscany-user-help@ws.apache.org
> >
> >
>
>
> --
> Luciano Resende
> Apache Tuscany Committer
> http://people.apache.org/~lresende
> http://lresende.blogspot.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
>
>