[prev in list] [next in list] [prev in thread] [next in thread] 

List:       slide-dev
Subject:    cvs commit: jakarta-slide/src/stores/slidestore/reference JDBCContentStore.java
From:       dirkv () apache ! org
Date:       2001-07-26 21:31:23
[Download RAW message or body]

dirkv       01/07/26 14:31:23

  Modified:    src/stores/slidestore/reference JDBCContentStore.java
  Log:
  change e.printStackTrace() to log(e)
  add extra debug info for IOException
  
  Revision  Changes    Path
  1.8       +59 -41    \
jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java  
  Index: JDBCContentStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JDBCContentStore.java	2001/07/18 13:40:07	1.7
  +++ JDBCContentStore.java	2001/07/26 21:31:22	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v \
                1.7 2001/07/18 13:40:07 dirkv Exp $
  - * $Revision: 1.7 $
  - * $Date: 2001/07/18 13:40:07 $
  + * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v \
1.8 2001/07/26 21:31:22 dirkv Exp $  + * $Revision: 1.8 $
  + * $Date: 2001/07/26 21:31:22 $
    *
    * ====================================================================
    *
  @@ -84,12 +84,13 @@
   import org.apache.slide.structure.*;
   import org.apache.slide.security.*;
   import org.apache.slide.content.*;
  +import org.apache.slide.util.logger.Logger;
   
   /**
    * JDBC 2.0 compliant implementation of ContentStore.
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class JDBCContentStore extends AbstractSimpleService
       implements ContentStore {
  @@ -156,14 +157,14 @@
           
           // Connection url
           url = (String) parameters.get("url");
  -		
  -		// FIXME: before slide 1.0.12 the database url was passed without "jdbc:"
  -		//        this compatibility code sould be removed in the future
  -		//        code changed 18 jul 2001
  -		if (!url.startsWith("jdbc:"))
  -			url="jdbc:" + url;
  -		// end compatibility code
           
  +        // FIXME: before slide 1.0.12 the database url was passed without "jdbc:"
  +        //        this compatibility code sould be removed in the future
  +        //        code changed 18 jul 2001
  +        if (!url.startsWith("jdbc:"))
  +            url="jdbc:" + url;
  +        // end compatibility code
  +        
           // User name
           user = (String) parameters.get("user");
           if (user == null) {
  @@ -187,10 +188,13 @@
        */
       public synchronized void connect()
           throws ServiceConnectionFailedException {
  +
  +        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);  throw new \
ServiceConnectionFailedException(this, e);  }
           Statement statement = null;
  @@ -233,25 +237,32 @@
           throws ServiceInitializationFailedException {
           try {
               // Loading and registering driver
  +            token.getLogger().log("Loading and registering driver: " + \
driver,LOG_CHANNEL,Logger.INFO);  Class driverClass = Class.forName(driver);
               Driver databaseDriver = (Driver) driverClass.newInstance();
               DriverManager.registerDriver(databaseDriver);
           } catch (ClassNotFoundException e) {
  +            token.getLogger().log("Loading and registering driver " + driver + " \
failed",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);  throw new ServiceInitializationFailedException
                   (this, e.getMessage());
           } catch (IllegalAccessException e) {
  +            token.getLogger().log("Loading and registering driver " + driver + " \
failed",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);  throw new ServiceInitializationFailedException
                   (this, e.getMessage());
           } catch (ClassCastException e) {
  +            token.getLogger().log("Loading and registering driver " + driver + " \
failed",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);  throw new ServiceInitializationFailedException
                   (this, e.getMessage());
           }
  @@ -402,10 +413,10 @@
               // FIXME ?
               
           } catch (SQLException e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           } catch (Exception e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           }
           
  @@ -453,15 +464,15 @@
                            revisionContent);
               
           } catch (SQLException e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           } catch (IOException e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           } catch(RevisionAlreadyExistException e) {
               throw e; // we do NOT want this caught by next clause.
           } catch (Exception e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           } finally {
               closeStatement(selectStatement);
  @@ -510,15 +521,15 @@
                            revisionContent);
               
           } catch (SQLException e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           } catch (IOException e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           } catch(RevisionNotFoundException e) {
               throw e; // we do NOT want this caught by next clause.
           } catch (Exception e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           } finally {
               closeStatement(selectStatement);
  @@ -546,7 +557,7 @@
               removeContent(revisionUri, revisionNumber);
               
           } catch (Exception e) {
  -            e.printStackTrace();
  +            getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e.getMessage());
           }
           
  @@ -580,33 +591,40 @@
               
               long contentLength = revisionDescriptor.getContentLength();
               File tempFile = null;
  +            String tempFileName = null;
               
               if (contentLength == -1) {
  -                
                   // If content length is unspecified, we have to buffer
                   // to a temp file.
  -                String tempFileName = revisionUri + "-" + revisionNumber;
  -                tempFileName = tempFileName.replace('/', '.');
  -                int tempFileNameLength = tempFileName.length();
  -                if (tempFileNameLength > 200)
  -                    tempFileName = tempFileName.substring
  -                        (tempFileNameLength - 200, tempFileNameLength);
  -                tempFile = File.createTempFile(tempFileName, null);
  -                
  -                FileOutputStream fos = new FileOutputStream(tempFile);
  -                while (true) {
  -                    int nChar = is.read(buffer);
  -                    if (nChar == -1) {
  -                        break;
  +                try {
  +                    tempFileName = revisionUri + "-" + revisionNumber;
  +                    tempFileName = tempFileName.replace('/', '.');
  +                    int tempFileNameLength = tempFileName.length();
  +                    if (tempFileNameLength > 200)
  +                        tempFileName = tempFileName.substring
  +                            (tempFileNameLength - 200, tempFileNameLength);
  +                    tempFile = File.createTempFile(tempFileName, null);
  +                    
  +                    FileOutputStream fos = new FileOutputStream(tempFile);
  +                    while (true) {
  +                        int nChar = is.read(buffer);
  +                        if (nChar == -1) {
  +                            break;
  +                        }
  +                        fos.write(buffer, 0, nChar);
  +                        position = position + nChar;
                       }
  -                    fos.write(buffer, 0, nChar);
  -                    position = position + nChar;
  +                    fos.close();
  +                    
  +                    is = new FileInputStream(tempFile);
  +                    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);  \
+                    throw ex;  }
  -                fos.close();
  -                
  -                is = new FileInputStream(tempFile);
  -                contentLength = tempFile.length();
  -                
               }
               
               // FIXME ? Cast from long to int won't allow files > 4GB.
  
  
  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic