cmlenz      2002/08/21 02:35:27

  Modified:    src/stores/org/apache/slide/store/impl/rdbms JDBCStore.java
  Log:
  More cleanup: variable naming, StringBuffer reuse, etc
  No functional changes
  
  Revision  Changes    Path
  1.8       +91 -88    
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JDBCStore.java    21 Aug 2002 09:13:11 -0000      1.7
  +++ JDBCStore.java    21 Aug 2002 09:35:27 -0000      1.8
  @@ -460,7 +460,7 @@
       }
       
       
  -    // ------------------------------------------------------ NodeStore Methods
  +    // ----------------------------------------------- NodeStore Implementation
       
       
       /**
  @@ -604,7 +604,7 @@
                          .append("VALUES (").append(parent).append(", ")
                          .append(getUriId((String)children.nextElement()))
                          .append(")");
  -                    stmt.execute(sql.toString());
  +                    stmt.executeUpdate(sql.toString());
                   }
               }
               
  @@ -619,7 +619,7 @@
                       sql.append("INSERT INTO LINKS (URI_ID, LINK_TO_ID) ")
                          .append("VALUES (").append(parent).append(", ")
                          .append(linkTargetId).append(")");
  -                    stmt.execute(sql.toString());
  +                    stmt.executeUpdate(sql.toString());
                   }
               }
               
  @@ -672,7 +672,7 @@
               sql.append("INSERT INTO OBJECT (URI_ID,CLASS_NAME) ")
                  .append("VALUES (").append(uriId).append(", '")
                  .append(object.getClass().getName()).append("')");
  -            stmt.execute(sql.toString());
  +            stmt.executeUpdate(sql.toString());
               
               // store children
               Enumeration children =
  @@ -684,7 +684,7 @@
                          .append("VALUES (").append(uriId).append(", ")
                          .append(getUriId((String)children.nextElement()))
                          .append(" )");
  -                    stmt.execute(sql.toString());
  +                    stmt.executeUpdate(sql.toString());
                   }
               }
   
  @@ -696,7 +696,7 @@
                       sql.append("INSERT INTO LINKS (URI_ID, LINK_TO_ID) ")
                          .append("VALUES (").append(uriId).append(", ")
                          .append(linkTargetId).append(")");
  -                    stmt.execute(sql.toString());
  +                    stmt.executeUpdate(sql.toString());
                   }
               }
   
  @@ -740,23 +740,21 @@
               sql.setLength(0);
               sql.append("DELETE FROM CHILDREN WHERE URI_ID = ")
                  .append(uriId).append(" OR CHILD_URI_ID = ").append(uriId);
  -            stmt.execute(sql.toString());
  +            stmt.executeUpdate(sql.toString());
               
               // delete link target and/or inbound links
               sql.setLength(0);
               sql.append("DELETE FROM LINKS WHERE URI_ID = ").append(uriId);
  -            stmt.execute(sql.toString());
  +            stmt.executeUpdate(sql.toString());
               
               // delete the object itself
               sql.setLength(0);
               sql.append("DELETE FROM OBJECT WHERE URI_ID = ").append(uriId);
  -            stmt.execute(sql.toString());
  +            stmt.executeUpdate(sql.toString());
               
               // delete the URI
               removeUri(object.getUri());
               
  -            stmt.close();
  -
           } catch (SQLException e) {
               getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e);
  @@ -771,9 +769,9 @@
               }
           }
       }
  -
  -
  -    // -------------------------------------------------- SecurityStore Methods
  +    
  +    
  +    // ------------------------------------------- SecurityStore Implementation
       
       
       /**
  @@ -786,49 +784,50 @@
           throws ServiceAccessException {
   
           Statement stmt = null;
  -
  +        StringBuffer sql = new StringBuffer();
           try {
               stmt = connection.createStatement();
  -            NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
  -            String revisionNumberStr =
  -                (revisionNumber == null) ? "NULL" : revisionNumber.toString();
  +            
               setUriId(permission.getObjectUri());
               setUriId(permission.getSubjectUri());
               setUriId(permission.getActionUri());
  -            long objid = getUriId(permission.getObjectUri());
  -            long subid = getUriId(permission.getSubjectUri());
  -            long actid = getUriId(permission.getActionUri());
  -
  -            StringBuffer sql = new StringBuffer("select 1 from PERMISSIONS");
  -                        sql.append(" where OBJECT_ID = ");
  -            sql.append(objid).append(" and SUBJECT_ID= ")
  -                    .append(subid).append(" and ACTION_ID = " )
  -                    .append(actid);
  +            long objectId = getUriId(permission.getObjectUri());
  +            long subjectId = getUriId(permission.getSubjectUri());
  +            long actionId = getUriId(permission.getActionUri());
  +            
  +            sql.setLength(0);
  +            sql.append("SELECT 1 FROM PERMISSIONS ")
  +               .append("WHERE OBJECT_ID = ").append(objectId)
  +               .append(" AND SUBJECT_ID = ").append(subjectId)
  +               .append(" AND ACTION_ID = " ).append(actionId);
               ResultSet rs = stmt.executeQuery(sql.toString());
  -
  -            if (! rs.next()) {
  -                sql = new StringBuffer("insert into PERMISSIONS ");
  -                sql.append("(OBJECT_ID,SUBJECT_ID,ACTION_ID,VERSION_NO,");
  -                sql.append("IS_INHERITABLE,IS_NEGATIVE) values( ");
  -                sql.append(objid).append(", ").append(subid)
  -                        .append(", ").append(actid)
  -                        .append(", ").append(revisionNumberStr)
  -                        .append(", ").append(permission.isInheritable())
  -                        .append(", ").append(permission.isNegative()).append(")");
  -                stmt.execute(sql.toString());
  +            if (!rs.next()) {
  +                NodeRevisionNumber nrn = permission.getRevisionNumber();
  +                sql.setLength(0);
  +                sql.append("INSERT INTO PERMISSIONS ")
  +                   .append("(OBJECT_ID, SUBJECT_ID, ACTION_ID, VERSION_NO, ")
  +                   .append("IS_INHERITABLE, IS_NEGATIVE) VALUES (")
  +                   .append(objectId).append(", ").append(subjectId)
  +                   .append(", ").append(actionId)
  +                   .append(", ").append((nrn == null) ? "NULL" : nrn.toString())
  +                   .append(", ").append(permission.isInheritable())
  +                   .append(", ").append(permission.isNegative())
  +                   .append(")");
  +                stmt.executeUpdate(sql.toString());
               }
           } catch (SQLException e) {
               getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e);
           } finally {
               try {
  -                stmt.close();
  +                if (stmt != null) {
  +                    stmt.close();
  +                }
               } catch (SQLException e) {
                   getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
                   throw new ServiceAccessException(this, e);
               }
           }
  -
       }
   
   
  @@ -841,40 +840,36 @@
       public void revokePermission(Uri uri, NodePermission permission)
           throws ServiceAccessException {
   
  -
           Statement stmt = null;
  -
  +        StringBuffer sql = new StringBuffer();
           try {
               stmt = connection.createStatement();
  -            NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
  -            StringBuffer sql = new StringBuffer("delete from PERMISSIONS ");
  -            sql.append("where OBJECT_ID= ");
  -            sql.append(getUriId(permission.getObjectUri()))
  -                  .append(" and SUBJECT_ID = ")
  -                  .append(getUriId(permission.getSubjectUri()))
  -                  .append(" and ACTION_ID = " )
  -                  .append(getUriId(permission.getActionUri()));
  -
  -            if(revisionNumber != null) {
  -                stmt.execute(sql.append(" and VERSION_NO = ")
  -                            .append(revisionNumber.toString()).toString());
  -            }
  -            else {
  -                stmt.execute(
  -                        sql.append(" and VERSION_NO = NULL").toString());
  -            }
  +            
  +            NodeRevisionNumber nrn = permission.getRevisionNumber();
  +            sql.setLength(0);
  +            sql.append("DELETE FROM PERMISSIONS ")
  +               .append("WHERE OBJECT_ID = ")
  +               .append(getUriId(permission.getObjectUri()))
  +               .append(" AND SUBJECT_ID = ")
  +               .append(getUriId(permission.getSubjectUri()))
  +               .append(" AND ACTION_ID = ")
  +               .append(getUriId(permission.getActionUri()))
  +               .append(" AND VERSION_NO ")
  +               .append((nrn != null) ? "= '" + nrn + "'" : "IS NULL");
  +            stmt.executeUpdate(sql.toString());
           } catch (SQLException e) {
               getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e);
           } finally {
               try {
  -                stmt.close();
  +                if (stmt != null) {
  +                    stmt.close();
  +                }
               } catch (SQLException e) {
                   getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
                   throw new ServiceAccessException(this, e);
               }
           }
  -
       }
   
   
  @@ -888,21 +883,23 @@
           throws ServiceAccessException {
   
           Statement stmt = null;
  -
  +        StringBuffer sql = new StringBuffer();
           try {
  -
               stmt = connection.createStatement();
  -            StringBuffer sql = new StringBuffer("delete from PERMISSIONS");
  -            sql.append(" where OBJECT_ID= ");
  -            sql.append(getUriId(uri.toString()));
  -            stmt.execute(sql.toString());
  +            
  +            sql.setLength(0);
  +            sql.append("DELETE FROM PERMISSIONS WHERE OBJECT_ID = ")
  +               .append(getUriId(uri.toString()));
  +            stmt.executeUpdate(sql.toString());
   
           } catch (SQLException e) {
               getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
               throw new ServiceAccessException(this, e);
           } finally {
               try {
  -                stmt.close();
  +                if (stmt != null) {
  +                    stmt.close();
  +                }
               } catch (SQLException e) {
                   getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
                   throw new ServiceAccessException(this, e);
  @@ -921,33 +918,28 @@
       public Enumeration enumeratePermissions(Uri uri)
           throws ServiceAccessException {
   
  -        Vector permissionVector = new Vector();
  +        Vector permissions = new Vector();
           Statement stmt = null;
  -
  +        StringBuffer sql = new StringBuffer();
           try {
               stmt = connection.createStatement();
  -
  -            StringBuffer sql = new StringBuffer("select * from PERMISSIONS ");
  -            sql.append("where OBJECT_ID = ");
  -            sql.append(getUriId(uri.toString()));
  -            stmt.execute(sql.toString());
  -
  +            
  +            sql.setLength(0);
  +            sql.append("SELECT * FROM PERMISSIONS ")
  +               .append("WHERE OBJECT_ID = ")
  +               .append(getUriId(uri.toString()));
               ResultSet rs = stmt.executeQuery(sql.toString());
  -            String object = null;
               while (rs.next()) {
  -                if (object == null) {
  -                    object   = getUri(rs.getLong("OBJECT_ID"));
  -                }
  +                String subject = getUri(rs.getLong("SUBJECT_ID"));
  +                String action = getUri(rs.getLong("ACTION_ID"));
                   String revision = rs.getString("VERSION_NO");
  -                String subject  = getUri(rs.getLong("SUBJECT_ID"));
  -                String action   = getUri(rs.getLong("ACTION_ID"));
   
                   boolean inheritable = rs.getBoolean("IS_INHERITABLE");
                   boolean negative = rs.getBoolean("IS_NEGATIVE");
                   NodePermission permission =
  -                    new NodePermission(object,revision,subject,
  -                                       action,inheritable,negative);
  -                permissionVector.addElement(permission);
  +                    new NodePermission(uri.toString(), revision, subject,
  +                                       action, inheritable, negative);
  +                permissions.addElement(permission);
               }
   
           } catch (SQLException e) {
  @@ -955,17 +947,22 @@
               throw new ServiceAccessException(this, e);
           } finally {
               try {
  -                stmt.close();
  +                if (stmt != null) {
  +                    stmt.close();
  +                }
               } catch (SQLException e) {
                   getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
                   throw new ServiceAccessException(this, e);
               }
           }
   
  -        return permissionVector.elements();
  +        return permissions.elements();
       }
   
   
  +    // ----------------------------------------------- LockStore Implementation
  +    
  +    
       /**
        * Create a new lock.
        *
  @@ -1154,6 +1151,9 @@
       }
   
   
  +    // -------------------------------- RevisionDescriptorsStore Implementation
  +    
  +    
       /**
        * Retrieve the revisions informations of an object.
        *
  @@ -1393,6 +1393,9 @@
       }
   
   
  +    // --------------------------------- RevisionDescriptorStore Implementation
  +    
  +    
       /**
        * Retrieve an individual object's revision descriptor.
        *
  @@ -1674,7 +1677,7 @@
       }
   
   
  -    // --------------------------------------------------- ContentStore Methods
  +    // -------------------------------------------- ContentStore Implementation
       
       
       /**
  
  
  

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

Reply via email to