You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by di...@apache.org on 2001/08/18 15:11:39 UTC

cvs commit: jakarta-slide/src/stores/slidestore/reference JDBCDescriptorsStore.java JDBCContentStore.java

dirkv       01/08/18 06:11:39

  Modified:    src/stores/slidestore/reference JDBCDescriptorsStore.java
                        JDBCContentStore.java
  Log:
  improve error message when loading driver
  indent cleanup
  
  Revision  Changes    Path
  1.24      +69 -67    jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java
  
  Index: JDBCDescriptorsStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- JDBCDescriptorsStore.java	2001/08/10 21:49:19	1.23
  +++ JDBCDescriptorsStore.java	2001/08/18 13:11:39	1.24
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v 1.23 2001/08/10 21:49:19 dirkv Exp $
  - * $Revision: 1.23 $
  - * $Date: 2001/08/10 21:49:19 $
  + * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v 1.24 2001/08/18 13:11:39 dirkv Exp $
  + * $Revision: 1.24 $
  + * $Date: 2001/08/18 13:11:39 $
    *
    * ====================================================================
    *
  @@ -86,7 +86,7 @@
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Dirk Verbeeck
  - * @version $Revision: 1.23 $
  + * @version $Revision: 1.24 $
    */
   
   public class JDBCDescriptorsStore
  @@ -229,9 +229,9 @@
           // without "jdbc:" this compatibility code sould be removed in the
           // future code changed 18 jul 2001
           if (!url.startsWith("jdbc:"))
  -        	url="jdbc:" + url;
  +            url="jdbc:" + url;
           // end compatibility code
  -		
  +        
           // User name
           user = (String) parameters.get("user");
           if (user == null) {
  @@ -268,6 +268,7 @@
                   (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);
               throw new ServiceConnectionFailedException(this, e);
           }
           
  @@ -347,11 +348,14 @@
        */
       public void disconnect()
           throws ServiceDisconnectionFailedException {
  +        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);
               throw new ServiceDisconnectionFailedException(this, e);
           }
       }
  @@ -379,28 +383,28 @@
               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());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
  +            throw new ServiceInitializationFailedException(this, e.getMessage());
           }
       }
       
  @@ -555,7 +559,7 @@
               
               statement = connection.prepareStatement
                   ("select * from objects where uri= ?");
  -	    statement.setString(1, uri.toString());
  +            statement.setString(1, uri.toString());
               
               ResultSet res = statement.executeQuery();
               
  @@ -576,7 +580,7 @@
               // Then, retrieve the children
               statement = connection.prepareStatement
                   ("select * from children where uri= ?");
  -	    statement.setString(1,uri.toString());
  +            statement.setString(1,uri.toString());
               res = statement.executeQuery();
               
               Vector childrenVector = new Vector();
  @@ -592,17 +596,17 @@
                   ("select * from links where linkto= ?");
               statement.setString(1,uri.toString());
               res = statement.executeQuery();
  -            
  +
               Vector linksVector = new Vector();
  -            
  +
               // Parse result set
               while (res.next()) {
                   // Load each permission
                   linksVector.addElement(res.getString(LINKS_LINKTO));
               }
  -            
  +
               closeStatement(statement);
  -            
  +
               if (className.equals("org.apache.slide.structure.LinkNode")) {
                   
                   String linkTo = new String();
  @@ -681,22 +685,22 @@
               // Updating children
               statement = connection.prepareStatement
                   ("delete from children where uri= ?");
  -	    statement.setString(1, object.getUri());
  -	    statement.execute();
  +            statement.setString(1, object.getUri());
  +            statement.execute();
               closeStatement(statement);
               
  -	    statement = null;
  +            statement = null;
               Enumeration children = object.enumerateChildren();
               while (children.hasMoreElements()) {
  -		if (statement == null){
  -		    statement = connection.prepareStatement
  -			("insert into children values(?, ?)");
  -		}
  +                if (statement == null){
  +                    statement = connection.prepareStatement
  +                        ("insert into children values(?, ?)");
  +                }
                   statement.setString(1, object.getUri());
                   statement.setString(2, (String)children.nextElement());
                   statement.execute();
               }
  -	    closeStatement(statement);
  +            closeStatement(statement);
               
               // Updating inbound links
               /*
  @@ -777,19 +781,19 @@
               statement.execute();
               closeStatement(statement);
               
  -	    statement = null;
  +            statement = null;
               // Inserting children
               Enumeration children = object.enumerateChildren();
               while (children.hasMoreElements()) {
  -		if (statement == null){
  -		    statement = connection.prepareStatement
  -			("insert into children values(?,?)");
  -		}
  +                if (statement == null){
  +                    statement = connection.prepareStatement
  +                        ("insert into children values(?,?)");
  +                }
                   statement.setString(1, uri.toString());
                   statement.setString(2, (String) children.nextElement());
                   statement.execute();
               }
  -	    closeStatement(statement);
  +            closeStatement(statement);
               
               // Updating inbound links
               /*
  @@ -804,7 +808,7 @@
               
               // If the object is a link, also store the link information
               if (object instanceof LinkNode) {
  -		statement = connection.prepareStatement
  +                statement = connection.prepareStatement
                       ("insert into links values(?,?)");
                   statement.setString(1, uri.toString());
                   statement.setString(2, ((LinkNode) object).getLinkedUri());
  @@ -928,11 +932,11 @@
           
           try {
               NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
  -	    if(revisionNumber != null) {
  +            if(revisionNumber != null) {
                   statement = connection.prepareStatement
                       ("delete from permissions where object= ? and subject = ? and action = ?  and revisionnumber = ? ");
                   statement.setString(4, revisionNumber.toString());
  -	    }
  +            }
               else {
                   statement = connection.prepareStatement
                       ("delete from permissions where object = ? and subject = ? and action = ? and revisionnumber is NULL");
  @@ -941,7 +945,7 @@
               statement.setString(1, permission.getObjectUri());
               statement.setString(2, permission.getSubjectUri());
               statement.setString(3, permission.getActionUri());
  -		
  +        
               statement.execute();
           } catch (SQLException e) {
               getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
  @@ -1252,7 +1256,7 @@
               
               statement = connection.prepareStatement
                   ("select * from revisions where uri= ?");
  -	    statement.setString(1, uri.toString());
  +            statement.setString(1, uri.toString());
               res = statement.executeQuery();
               
               if (res.next()) {
  @@ -1299,10 +1303,10 @@
                   String currentRevisionNumber = res.getString(REVISION_NUMBER);
                   
                   // We parse the revision list of the object
  -		if (statement2 == null){
  -		    statement2 = connection.prepareStatement
  -			("select * from branches where uri = ? and xnumber = ?");
  -		}
  +                if (statement2 == null){
  +                    statement2 = connection.prepareStatement
  +                        ("select * from branches where uri = ? and xnumber = ?");
  +                }
                   statement2.setString(1, uri.toString());
                   statement2.setString(2, currentRevisionNumber);
                   ResultSet res2 = statement2.executeQuery();
  @@ -1318,7 +1322,7 @@
                   
                   res2.close();
               }
  -	    closeStatement(statement2);
  +            closeStatement(statement2);
               
               revisionDescriptors = new NodeRevisionDescriptors
                   (uri.toString(), initialRevision, workingRevisions, 
  @@ -1379,10 +1383,10 @@
               if (revisionDescriptors.getLatestRevision() != null) {
                   statement = connection.prepareStatement
                       ("insert into latestrevisions values(?,?,?)");
  -		statement.setString(1, uri.toString());
  -		statement.setString
  +                statement.setString(1, uri.toString());
  +                statement.setString
                       (2, NodeRevisionDescriptors.MAIN_BRANCH.toString());
  -		statement.setString
  +                statement.setString
                       (3, revisionDescriptors.getLatestRevision().toString());
                   statement.execute();
                   closeStatement(statement);
  @@ -1480,8 +1484,8 @@
           NodeRevisionDescriptor revisionDescriptor = null;
           PreparedStatement statement = null;
   
  -	if(revisionNumber == null)
  -	    throw new RevisionDescriptorNotFoundException(uri.toString());
  +    if(revisionNumber == null)
  +        throw new RevisionDescriptorNotFoundException(uri.toString());
           
           try {
               
  @@ -1587,20 +1591,20 @@
               statement = null;
               Enumeration labels = revisionDescriptor.enumerateLabels();
               while (labels.hasMoreElements()) {
  -		if (statement == null){
  -		    statement = connection.prepareStatement
  -			("insert into label values(?,?,?)");
  -		}
  +                if (statement == null){
  +                    statement = connection.prepareStatement
  +                        ("insert into label values(?,?,?)");
  +                }
                   statement.setString(1, uri.toString());
                   statement.setString
                       (2, revisionDescriptor.getRevisionNumber().toString());
                   statement.setString(3, (String)labels.nextElement());
                   statement.execute();
               }
  -	    closeStatement(statement);
  +            closeStatement(statement);
  +
               // Creating associated properties
  -            
  -	    statement = null;
  +            statement = null;
               Enumeration properties = revisionDescriptor.enumerateProperties();
               while (properties.hasMoreElements()) {
                   NodeProperty property = 
  @@ -1609,10 +1613,10 @@
                   if (property.isProtected()) {
                       protectedProperty = 1;
                   }
  -		if (statement == null){
  -		    statement = connection.prepareStatement
  -			("insert into property values(?,?,?,?,?,?,?)");
  -		}
  +                if (statement == null){
  +                    statement = connection.prepareStatement
  +                        ("insert into property values(?,?,?,?,?,?,?)");
  +                }
                   statement.setString(1, uri.toString());
                   statement.setString
                       (2, revisionDescriptor.getRevisionNumber().toString());
  @@ -1623,8 +1627,7 @@
                   statement.setInt(7, protectedProperty);
                   statement.execute();
               }
  -	    closeStatement(statement);
  -
  +            closeStatement(statement);
               
           } catch (SQLException e) {
               getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
  @@ -1651,7 +1654,6 @@
           
           removeRevisionDescriptor(uri, revisionDescriptor.getRevisionNumber());
           createRevisionDescriptor(uri, revisionDescriptor);
  -        
       }
       
       
  
  
  
  1.9       +20 -16    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JDBCContentStore.java	2001/07/26 21:31:22	1.8
  +++ JDBCContentStore.java	2001/08/18 13:11:39	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v 1.9 2001/08/18 13:11:39 dirkv Exp $
  + * $Revision: 1.9 $
  + * $Date: 2001/08/18 13:11:39 $
    *
    * ====================================================================
    *
  @@ -90,7 +90,7 @@
    * JDBC 2.0 compliant implementation of ContentStore.
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public class JDBCContentStore extends AbstractSimpleService
       implements ContentStore {
  @@ -195,6 +195,7 @@
                   (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);
               throw new ServiceConnectionFailedException(this, e);
           }
           Statement statement = null;
  @@ -217,11 +218,14 @@
        */
       public synchronized void disconnect()
           throws ServiceDisconnectionFailedException {
  +        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);
               throw new ServiceDisconnectionFailedException(this, e);
           }
       }
  @@ -243,28 +247,28 @@
               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());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            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);
  -            throw new ServiceInitializationFailedException
  -                (this, e.getMessage());
  +            token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
  +            throw new ServiceInitializationFailedException(this, e.getMessage());
           }
       }