You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Milinda Pathirage <mi...@gmail.com> on 2009/12/16 07:36:44 UTC

Wrong prepared statements generated when directory called 'mysql' is in the path of embedded derby location

Hi Devs,

There is a strange bug which caused JDBC exceptions when my embdded derby
path contains directory called 'mysql' or 'oracle'. I am using OpenJPA 1.1.
Is this a known bug. When this happens embedded derby URL is look like
following:

jdbc:derby:/home/milinda/mysql/bps/database/daojpa

Do anyone have any idea about the reason for incorrect generation of
prepared statement.

Thanks
Milinda



-- 
Milinda Pathirage
Senior Software Engineer & Product Manager WSO2 BPS; http://wso2.org/bps
WSO2 Inc.; http://wso2.com
E-mail: milinda@wso2.com, milinda.pathirage@gmail.com
Web: http://mpathirage.com
Blog: http://blog.mpathirage.com

Re: Re: Wrong prepared statements generated when directory called 'mysql' is in the path of embedded derby location

Posted by Milinda Pathirage <mi...@gmail.com>.
Hi Donald and Milosz,

Thanks you for your answers. I think code fragment you mentioned is correct.
When I tested using a path which has both mysql and oracle, OpenJPA select
it as oracle. I'll set the DBDictionary explicitly in my application and
test.

Thanks
Milinda

On Thu, Dec 17, 2009 at 2:08 AM, Miłosz <mt...@o2.pl> wrote:

> Hi,
>
> We have been struggling with this for some time: OPENJPA-580 and
> OPENJPA-760. If you know up-front what database your application will
> connect to, it's safer to specify DBDictionary explicitly instead of relying
> on DBDictionary auto-detection.
>
> Cheers,
> Milosz
>
> > Seems like a bug related to the following code in
> > DBDictionaryFactory.java, where the connection URL is being inspected
> > before the driver name -
> >
> >
> >      public static DBDictionary calculateDBDictionary(JDBCConfiguration
> > conf, String url, String driver, String props) {
> >          String dclass = dictionaryClassForString(getProtocol(url),conf);
> >          if (dclass == null)
> >              dclass = dictionaryClassForString(driver, conf);
> >          if (dclass == null)
> >              return null;
> >          return newDBDictionary(conf, dclass, props);
> >      }
> >
> >
> > The above calls the below method, which performs simple substring
> > compares for the supported databases -
> >
> >      private static String dictionaryClassForString(String prod
> >          , JDBCConfiguration conf) {
> >          if (StringUtils.isEmpty(prod))
> >              return null;
> >          prod = prod.toLowerCase();
> >
> >          PluginValue dbdictionaryPlugin = ((JDBCConfigurationImpl) conf)
> >              .dbdictionaryPlugin;
> >
> >          if (prod.indexOf("oracle") != -1)
> >              return dbdictionaryPlugin.unalias("oracle");
> >          if (prod.indexOf("sqlserver") != -1)
> >              return dbdictionaryPlugin.unalias("sqlserver");
> >          if (prod.indexOf("jsqlconnect") != -1)
> >              return dbdictionaryPlugin.unalias("sqlserver");
> >          if (prod.indexOf("mysql") != -1)
> >              return dbdictionaryPlugin.unalias("mysql");
> >          if (prod.indexOf("postgres") != -1)
> >              return dbdictionaryPlugin.unalias("postgres");
> > . . .
> >
> >
> > -Donald
> >
> >
> >
> > Milinda Pathirage wrote:
> > > Hi Devs,
> > >
> > > There is a strange bug which caused JDBC exceptions when my embdded
> derby
> > > path contains directory called 'mysql' or 'oracle'. I am using OpenJPA
> 1.1.
> > > Is this a known bug. When this happens embedded derby URL is look like
> > > following:
> > >
> > > jdbc:derby:/home/milinda/mysql/bps/database/daojpa
> > >
> > > Do anyone have any idea about the reason for incorrect generation of
> > > prepared statement.
> > >
> > > Thanks
> > > Milinda
> > >
> > >
> > >
>
>


-- 
Milinda Pathirage
Senior Software Engineer & Product Manager WSO2 BPS; http://wso2.org/bps
WSO2 Inc.; http://wso2.com
E-mail: milinda@wso2.com, milinda.pathirage@gmail.com
Web: http://mpathirage.com
Blog: http://blog.mpathirage.com

Re: Re: Wrong prepared statements generated when directory called 'mysql' is in the path of embedded derby location

Posted by Miłosz <mt...@o2.pl>.
Hi,

We have been struggling with this for some time: OPENJPA-580 and OPENJPA-760. If you know up-front what database your application will connect to, it's safer to specify DBDictionary explicitly instead of relying on DBDictionary auto-detection.

Cheers,
Milosz

> Seems like a bug related to the following code in 
> DBDictionaryFactory.java, where the connection URL is being inspected 
> before the driver name -
> 
> 
>      public static DBDictionary calculateDBDictionary(JDBCConfiguration 
> conf, String url, String driver, String props) {
>          String dclass = dictionaryClassForString(getProtocol(url),conf);
>          if (dclass == null)
>              dclass = dictionaryClassForString(driver, conf);
>          if (dclass == null)
>              return null;
>          return newDBDictionary(conf, dclass, props);
>      }
> 
> 
> The above calls the below method, which performs simple substring 
> compares for the supported databases -
> 
>      private static String dictionaryClassForString(String prod
>          , JDBCConfiguration conf) {
>          if (StringUtils.isEmpty(prod))
>              return null;
>          prod = prod.toLowerCase();
> 
>          PluginValue dbdictionaryPlugin = ((JDBCConfigurationImpl) conf)
>              .dbdictionaryPlugin;
> 
>          if (prod.indexOf("oracle") != -1)
>              return dbdictionaryPlugin.unalias("oracle");
>          if (prod.indexOf("sqlserver") != -1)
>              return dbdictionaryPlugin.unalias("sqlserver");
>          if (prod.indexOf("jsqlconnect") != -1)
>              return dbdictionaryPlugin.unalias("sqlserver");
>          if (prod.indexOf("mysql") != -1)
>              return dbdictionaryPlugin.unalias("mysql");
>          if (prod.indexOf("postgres") != -1)
>              return dbdictionaryPlugin.unalias("postgres");
> . . .
> 
> 
> -Donald
> 
> 
> 
> Milinda Pathirage wrote:
> > Hi Devs,
> > 
> > There is a strange bug which caused JDBC exceptions when my embdded derby
> > path contains directory called 'mysql' or 'oracle'. I am using OpenJPA 1.1.
> > Is this a known bug. When this happens embedded derby URL is look like
> > following:
> > 
> > jdbc:derby:/home/milinda/mysql/bps/database/daojpa
> > 
> > Do anyone have any idea about the reason for incorrect generation of
> > prepared statement.
> > 
> > Thanks
> > Milinda
> > 
> > 
> > 


Re: Wrong prepared statements generated when directory called 'mysql' is in the path of embedded derby location

Posted by Donald Woods <dw...@apache.org>.
Seems like a bug related to the following code in 
DBDictionaryFactory.java, where the connection URL is being inspected 
before the driver name -


     public static DBDictionary calculateDBDictionary(JDBCConfiguration 
conf, String url, String driver, String props) {
         String dclass = dictionaryClassForString(getProtocol(url),conf);
         if (dclass == null)
             dclass = dictionaryClassForString(driver, conf);
         if (dclass == null)
             return null;
         return newDBDictionary(conf, dclass, props);
     }


The above calls the below method, which performs simple substring 
compares for the supported databases -

     private static String dictionaryClassForString(String prod
         , JDBCConfiguration conf) {
         if (StringUtils.isEmpty(prod))
             return null;
         prod = prod.toLowerCase();

         PluginValue dbdictionaryPlugin = ((JDBCConfigurationImpl) conf)
             .dbdictionaryPlugin;

         if (prod.indexOf("oracle") != -1)
             return dbdictionaryPlugin.unalias("oracle");
         if (prod.indexOf("sqlserver") != -1)
             return dbdictionaryPlugin.unalias("sqlserver");
         if (prod.indexOf("jsqlconnect") != -1)
             return dbdictionaryPlugin.unalias("sqlserver");
         if (prod.indexOf("mysql") != -1)
             return dbdictionaryPlugin.unalias("mysql");
         if (prod.indexOf("postgres") != -1)
             return dbdictionaryPlugin.unalias("postgres");
. . .


-Donald



Milinda Pathirage wrote:
> Hi Devs,
> 
> There is a strange bug which caused JDBC exceptions when my embdded derby
> path contains directory called 'mysql' or 'oracle'. I am using OpenJPA 1.1.
> Is this a known bug. When this happens embedded derby URL is look like
> following:
> 
> jdbc:derby:/home/milinda/mysql/bps/database/daojpa
> 
> Do anyone have any idea about the reason for incorrect generation of
> prepared statement.
> 
> Thanks
> Milinda
> 
> 
>