cmlenz      2002/08/19 01:32:55

  Modified:    src/stores/org/apache/slide/store/impl/rdbms JDBCStore.java
  Log:
  Some cleanup
  
  Revision  Changes    Path
  1.3       +62 -77    
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/JDBCStore.java
  
  Index: JDBCStore.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/JDBCStore.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JDBCStore.java    19 Aug 2002 07:51:27 -0000      1.2
  +++ JDBCStore.java    19 Aug 2002 08:32:54 -0000      1.3
  @@ -307,13 +307,13 @@
        */
       public synchronized void connect()
           throws ServiceConnectionFailedException {
  -        getLogger().log("Connecting to \"" + url + "\" as user \"" + user + 
"\"",LOG_CHANNEL, Logger.INFO);
  +        getLogger().log("Connecting to \"" + url + "\" as user \"" + user + "\"", 
LOG_CHANNEL, Logger.INFO);
           try {
               connection = DriverManager.getConnection
                   (url, user, password);
           } catch (SQLException e) {
  -            getLogger().log("Connecting to \"" + url + "\" as user \"" + user + "\" 
failed",LOG_CHANNEL, Logger.ERROR);
  -            getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log("Connecting to \"" + url + "\" as user \"" + user + "\" 
failed", LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceConnectionFailedException(this, e);
           }
   
  @@ -351,14 +351,14 @@
        */
       public void disconnect()
           throws ServiceDisconnectionFailedException {
  -        getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user + 
"\"",LOG_CHANNEL, Logger.INFO);
  +        getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user + 
"\"", LOG_CHANNEL, Logger.INFO);
           try {
               if (connection != null)
                   connection.close();
               connection = null;
           } catch (SQLException e) {
  -            getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user 
+ "\" failed",LOG_CHANNEL, Logger.ERROR);
  -            getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user 
+ "\" failed", LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceDisconnectionFailedException(this, e);
           }
       }
  @@ -380,7 +380,7 @@
        * <p/>
        * Occurs in four steps :
        * <li>Driver class is loaded</li>
  -     * <li>Driver is intantiated</li>
  +     * <li>Driver is instantiated</li>
        * <li>Driver registration in the driver manager</li>
        * <li>Creation of the basic tables, if they didn't exist before</li>
        * 
  @@ -389,35 +389,36 @@
        */
       public synchronized void initialize(NamespaceAccessToken token)
           throws ServiceInitializationFailedException {
  +        
           try {
               // Loading and registering driver
  -            token.getLogger().log("Loading and registering driver: " + 
driver,LOG_CHANNEL, Logger.INFO);
  +            token.getLogger().log("Loading and registering driver: " + driver, 
LOG_CHANNEL, Logger.INFO);
               Class driverClass = Class.forName(driver);
  -            Driver databaseDriver = (Driver) driverClass.newInstance();
  +            Driver databaseDriver = (Driver)driverClass.newInstance();
               DriverManager.registerDriver(databaseDriver);
           } catch (ClassNotFoundException e) {
  -            token.getLogger().log("Loading and registering driver " + driver + " 
failed",LOG_CHANNEL, Logger.ERROR);
  -            token.getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log("Loading and registering driver " + driver + " 
failed", LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceInitializationFailedException(this, e.getMessage());
           } catch (InstantiationException e) {
  -            token.getLogger().log("Loading and registering driver " + driver + " 
failed",LOG_CHANNEL, Logger.ERROR);
  -            token.getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log("Loading and registering driver " + driver + " 
failed", LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceInitializationFailedException(this, e.getMessage());
           } catch (IllegalAccessException e) {
  -            token.getLogger().log("Loading and registering driver " + driver + " 
failed",LOG_CHANNEL, Logger.ERROR);
  -            token.getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log("Loading and registering driver " + driver + " 
failed", LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceInitializationFailedException(this, e.getMessage());
           } catch (SQLException e) {
  -            token.getLogger().log("Loading and registering driver " + driver + " 
failed",LOG_CHANNEL, Logger.ERROR);
  -            token.getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log("Loading and registering driver " + driver + " 
failed", LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceInitializationFailedException(this, e.getMessage());
           } catch (ClassCastException e) {
  -            token.getLogger().log("Loading and registering driver " + driver + " 
failed",LOG_CHANNEL, Logger.ERROR);
  -            token.getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log("Loading and registering driver " + driver + " 
failed", LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceInitializationFailedException(this, e.getMessage());
           } catch (Exception e) {
  -            token.getLogger().log("Loading and registering driver " + driver + " 
failed",LOG_CHANNEL, Logger.ERROR);
  -            token.getLogger().log(e.toString(),LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log("Loading and registering driver " + driver + " 
failed", LOG_CHANNEL, Logger.ERROR);
  +            token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
               throw new ServiceInitializationFailedException(this, e.getMessage());
           }
       }
  @@ -495,24 +496,19 @@
       /**
        * This function tells whether or not the data source is connected.
        *
  -     * @return boolean true if we are connected
  +     * @return true if we are connected
        * @exception ServiceAccessException Error accessing DataSource
        */
       public boolean isConnected()
           throws ServiceAccessException {
  +        
           try {
               if ((connection == null) || (connection.isClosed())) {
                   return false;
               }
  -            
  -            PreparedStatement statement = 
  -                connection.prepareStatement(getDatabaseConnectionTestStatement());
  -            statement.executeQuery();
  -            statement.close();
  -            
  -            // testStatement executed without throwing an exception
  -            return true;
  -            
  +            Statement stmt = connection.createStatement();
  +            stmt.executeQuery("select 1 from objects where uri is null");
  +            return true; // test executed without throwing an exception
           } catch (SQLException e) {
               throw new ServiceAccessException(this, e);
           }
  @@ -528,8 +524,8 @@
       public void commit(Xid xid, boolean onePhase)
           throws XAException {
           super.commit(xid, onePhase);
  +        
           try {
  -//            getLogger().log("commit",LOG_CHANNEL, Logger.DEBUG);
               connection.commit();
           } catch (SQLException e) {
               throw new XAException(XAException.XA_RBCOMMFAIL);
  @@ -545,8 +541,8 @@
       public void rollback(Xid xid)
           throws XAException {
           super.rollback(xid);
  +        
           try {
  -//            getLogger().log("rollback",LOG_CHANNEL, Logger.DEBUG);
               connection.rollback();
           } catch (SQLException e) {
               throw new XAException(XAException.XA_HEURCOM);
  @@ -561,15 +557,10 @@
       public void start(Xid xid, int flags)
           throws XAException {
           super.start(xid, flags);
  -        if (!alreadyEnlisted) 
  -        {
  +        
  +        if (!alreadyEnlisted) {
               try {
  -                // getLogger().log("start",LOG_CHANNEL, Logger.DEBUG);
  -
  -                // test connection
                   connectIfNeeded();
  -                
  -                // discard changes made outside a tranaction
                   connection.rollback();
               } catch (Exception e) {
                   throw new XAException(XAException.XAER_RMERR);
  @@ -583,7 +574,7 @@
       
       
       /**
  -     * Retrive an object.
  +     * Retrieve an object.
        * 
        * @param uri Uri of the object we want to retrieve
        * @exception ServiceAccessException Error accessing the Service
  @@ -686,7 +677,7 @@
               }
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -773,7 +764,7 @@
               }
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -859,7 +850,7 @@
               }
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -911,7 +902,7 @@
               closeStatement(statement);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           }
  @@ -954,7 +945,7 @@
               statement.setInt(6, negative);
               statement.execute();
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -995,7 +986,7 @@
           
               statement.execute();
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1023,7 +1014,7 @@
               statement.setString(1, uri.toString());
               statement.execute();
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1072,7 +1063,7 @@
               }
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1117,7 +1108,7 @@
               statement.setInt(7, exclusive);
               statement.execute();
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1170,7 +1161,7 @@
               statement.execute();
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1207,7 +1198,7 @@
               statement.execute(s);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1274,7 +1265,7 @@
               }
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1383,7 +1374,7 @@
                    latestRevisionNumbers, branches, isVersioned);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1451,7 +1442,7 @@
               // TODO
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1518,7 +1509,7 @@
               closeStatement(statement);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1608,7 +1599,7 @@
                                              labels, properties);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1688,7 +1679,7 @@
               closeStatement(statement);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1755,7 +1746,7 @@
               statement.execute();
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e);
           } finally {
  @@ -1814,7 +1805,7 @@
               result.setContent( new JDBCAwareInputStream(is,selectStatement) );
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           } catch (RevisionNotFoundException e) {
  @@ -1823,7 +1814,7 @@
                               LOG_CHANNEL, Logger.WARNING);
               throw e; // we do NOT want this caught by next clause.
           } catch (Exception e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           }
  @@ -1872,11 +1863,11 @@
                            revisionContent);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           } catch (IOException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           } catch(RevisionAlreadyExistException e) {
  @@ -1885,7 +1876,7 @@
                               LOG_CHANNEL, Logger.WARNING);
               throw e; // we do NOT want this caught by next clause.
           } catch (Exception e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           } finally {
  @@ -1935,11 +1926,11 @@
                            revisionContent);
               
           } catch (SQLException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           } catch (IOException e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           } catch(RevisionNotFoundException e) {
  @@ -1948,7 +1939,7 @@
                               LOG_CHANNEL, Logger.WARNING);
               throw e; // we do NOT want this caught by next clause.
           } catch (Exception e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           } finally {
  @@ -1977,7 +1968,7 @@
               removeContent(revisionUri, revisionNumber);
               
           } catch (Exception e) {
  -            getLogger().log(e,LOG_CHANNEL, Logger.ERROR);
  +            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               connectIfNeededAndPossible();
               throw new ServiceAccessException(this, e.getMessage());
           }
  @@ -2055,9 +2046,9 @@
                       contentLength = tempFile.length();
                   }
                   catch (IOException ex) {
  -                    getLogger().log(ex.toString() + " during the calculation of the 
content length.",LOG_CHANNEL, Logger.ERROR);
  -                    getLogger().log("tempFileName: " + tempFileName,LOG_CHANNEL, 
Logger.ERROR);
  -                    getLogger().log("tempFile: " + 
tempFile.getAbsolutePath(),LOG_CHANNEL, Logger.ERROR);
  +                    getLogger().log(ex.toString() + " during the calculation of the 
content length.", LOG_CHANNEL, Logger.ERROR);
  +                    getLogger().log("tempFileName: " + tempFileName, LOG_CHANNEL, 
Logger.ERROR);
  +                    getLogger().log("tempFile: " + tempFile.getAbsolutePath(), 
LOG_CHANNEL, Logger.ERROR);
                       throw ex;
                   }
               }
  @@ -2135,12 +2126,6 @@
               "    xnumber varchar(20), content LONGVARBINARY)"};
   
           return statements;
  -    }
  -    
  -    
  -    private String getDatabaseConnectionTestStatement() {
  -        
  -        return "select 1 from objects where uri is null";
       }
       
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to