cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp AbstractEsqlConnection.java Cocoon2EsqlConnection.java
Date Thu, 01 May 2003 13:03:50 GMT
tcurdt      2003/05/01 06:03:50

  Modified:    src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp
                        AbstractEsqlConnection.java
                        Cocoon2EsqlConnection.java
  Log:
  throw an appropriate exception if no connection could be obtained (fixes bug #15820),
  use the metadata database identifier instead of the url for the database type auto detection
(fixes bug #18547 and adds auto support for sybase ase)
  
  Revision  Changes    Path
  1.2       +37 -21    cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/AbstractEsqlConnection.java
  
  Index: AbstractEsqlConnection.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/AbstractEsqlConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractEsqlConnection.java	20 Mar 2003 21:51:43 -0000	1.1
  +++ AbstractEsqlConnection.java	1 May 2003 13:03:50 -0000	1.2
  @@ -159,49 +159,65 @@
        */
       public AbstractEsqlQuery createQuery(final String type, final String queryString) throws
SQLException {
           AbstractEsqlQuery query;
  +
  +        Connection connection = getConnection();
  +
           if ("".equals(type) || "auto".equalsIgnoreCase(type)) {
  -            String url = getURL();
  +            String database = connection.getMetaData().getDatabaseProductName().toLowerCase();
   
  -            if (url.startsWith("jdbc:postgresql:")) {
  -                query = new PostgresEsqlQuery(getConnection(),queryString);
  +            if (database.indexOf("postgresql") > -1) {
  +                query = new PostgresEsqlQuery(connection,queryString);
               }
  -            else if (url.startsWith("jdbc:mysql:")) {
  -                query = new MysqlEsqlQuery(getConnection(),queryString);
  +            else if (database.indexOf("mysql") > -1) {
  +                query = new MysqlEsqlQuery(connection,queryString);
               }
  -            else if (url.startsWith("jdbc:sybase:")) {
  -                query = new SybaseEsqlQuery(getConnection(),queryString);
  +            else if (database.indexOf("anywhere") > -1 || database.indexOf("sqlserver")
> -1) {
  +                query = new SybaseEsqlQuery(connection,queryString);
               }
  -            else if (url.startsWith("jdbc:oracle:")) {
  -                query = new OracleEsqlQuery(getConnection(),queryString);
  +            else if (database.indexOf("oracle") > -1) {
  +                query = new OracleEsqlQuery(connection,queryString);
               }
  -            else if (url.startsWith("jdbc:pervasive:")) {
  -                query = new PervasiveEsqlQuery(getConnection(),queryString);
  +            else if (database.indexOf("pervasive") > -1) {
  +                query = new PervasiveEsqlQuery(connection,queryString);
               }
  -            else {
  -                getLogger().warn("Cannot guess database type from jdbc url: " + String.valueOf(url)
+" - Defaulting to JDBC");
  +            else if (database.indexOf("hsql") > -1) {
                   query = new JdbcEsqlQuery(getConnection(),queryString);
               }
  +            else {
  +                getLogger().warn("Unrecognized database: \"" + String.valueOf(database)
+ "\"");
  +
  +                // temp start
  +                String message = "The database detection method has changed.\nIf your database
"+
  +                                 "is not being recognized (anymore) you can either fix
it in the Cocoon2EsqlConnection class, "+
  +                                 " file it to bugzilla, report it to cocoon-dev or to me
(tcurdt.at.apache.org) directly.\n" +
  +                                 " Only be sure to include the database string \"" + String.valueOf(database)
+ "\" in your post.";
  +                getLogger().error( message );
  +                throw new SQLException( message );
  +                // temp stop
  +
  +                //query = new JdbcEsqlQuery(getConnection(),queryString);
  +            }
           }
           else if ("sybase".equalsIgnoreCase(type)) {
  -            query = new SybaseEsqlQuery(getConnection(),queryString);
  +            query = new SybaseEsqlQuery(connection,queryString);
           }
           else if ("postgresql".equalsIgnoreCase(type)) {
  -            query = new PostgresEsqlQuery(getConnection(),queryString);
  +            query = new PostgresEsqlQuery(connection,queryString);
           }
           else if ("postgresql-old".equalsIgnoreCase(type)) {
  -            query = new PostgresOldEsqlQuery(getConnection(),queryString);
  +            query = new PostgresOldEsqlQuery(connection,queryString);
           }
           else if ("mysql".equalsIgnoreCase(type)) {
  -            query = new MysqlEsqlQuery(getConnection(),queryString);
  +            query = new MysqlEsqlQuery(connection,queryString);
           }
           else if ("oracle".equalsIgnoreCase(type)) {
  -            query = new OracleEsqlQuery(getConnection(),queryString);
  +            query = new OracleEsqlQuery(connection,queryString);
           }
           else if ("pervasive".equalsIgnoreCase(type)) {
  -            query = new PervasiveEsqlQuery(getConnection(),queryString);
  +            query = new PervasiveEsqlQuery(connection,queryString);
           }
           else if ("jdbc".equalsIgnoreCase(type)) {
  -            query = new JdbcEsqlQuery(getConnection(),queryString);
  +            query = new JdbcEsqlQuery(connection,queryString);
           }
           else {
               getLogger().error("Unknown database type: " + String.valueOf(type));
  
  
  
  1.2       +6 -2      cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/Cocoon2EsqlConnection.java
  
  Index: Cocoon2EsqlConnection.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/Cocoon2EsqlConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Cocoon2EsqlConnection.java	9 Mar 2003 00:03:06 -0000	1.1
  +++ Cocoon2EsqlConnection.java	1 May 2003 13:03:50 -0000	1.2
  @@ -97,12 +97,16 @@
               if (datasource != null) {
                   // get the connection from the pool
                   connection = datasource.getConnection();
  -                return(connection);
               }
               else {
                   // open a new connection
                   connection = DriverManager.getConnection(getURL(), getProperties());
  +            }
  +            if (connection != null) {
                   return(connection);
  +            }
  +            else {
  +                throw new SQLException("Could not obtain connection");
               }
           }
       }
  
  
  

Mime
View raw message