ozeigermann    2004/01/07 06:06:03

  Modified:    src/stores/org/apache/slide/store/impl/rdbms
                        MySqlRDBMSAdapter.java MySqlSchema.sql
                        SybaseRDBMSAdapter.java SQLServerSchema.sql
                        StandardRDBMSAdapter.java JDBCStore.java
                        SQLServerRDBMSAdapter.java SybaseSchema.sql
  Log:
  - ported all RDBMS adapters to binding
  - added mechanism for deadlock detection
  - added graceful handling of constraint violations useful with low isolation levels
  
  Revision  Changes    Path
  1.2       +25 -5     
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySqlRDBMSAdapter.java
  
  Index: MySqlRDBMSAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySqlRDBMSAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MySqlRDBMSAdapter.java    3 Dec 2003 12:00:46 -0000       1.1
  +++ MySqlRDBMSAdapter.java    7 Jan 2004 14:06:02 -0000       1.2
  @@ -63,7 +63,10 @@
   
   package org.apache.slide.store.impl.rdbms;
   
  +import java.sql.SQLException;
  +
   import org.apache.slide.common.*;
  +import org.apache.slide.macro.ConflictException;
   import org.apache.slide.util.logger.Logger;
   
   /**
  @@ -80,5 +83,22 @@
       public MySqlRDBMSAdapter(Service service, Logger logger) {
           super(service, logger);
       }
  -}
   
  +    protected ServiceAccessException createException(SQLException e, String uri) {
  +
  +        switch (e.getErrorCode()) {
  +            case 1213 : // thread was deadlock victim
  +                getLogger().log(e.getErrorCode() + ": Deadlock resolved on " + uri, 
LOG_CHANNEL, Logger.WARNING);
  +                return new ServiceAccessException(service, new 
ConflictException(uri));
  +
  +            default :
  +                getLogger().log(
  +                    "SQL error " + e.getErrorCode() + " on " + uri + ": " + 
e.getMessage(),
  +                    LOG_CHANNEL,
  +                    Logger.ERROR);
  +
  +                return new ServiceAccessException(service, e);
  +        }
  +    }
  +
  +}
  \ No newline at end of file
  
  
  
  1.2       +24 -8     
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySqlSchema.sql
  
  Index: MySqlSchema.sql
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySqlSchema.sql,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MySqlSchema.sql   3 Dec 2003 12:00:46 -0000       1.1
  +++ MySqlSchema.sql   7 Jan 2004 14:06:02 -0000       1.2
  @@ -2,6 +2,8 @@
   
   drop table if exists OBJECT;
   drop table if exists CHILDREN;
  +drop table if exists BINDING;
  +drop table if exists PARENT_BINDING;
   drop table if exists LINKS;
   drop table if exists LOCKS;
   drop table if exists VERSION_CONTENT;
  @@ -37,17 +39,31 @@
   
   # --------------------------------------------------------
   
  -CREATE TABLE CHILDREN (
  +CREATE TABLE BINDING (
     URI_ID         bigint  NOT NULL,
  -  CHILD_URI_ID   bigint  NOT NULL,
  -  PRIMARY KEY    (URI_ID,CHILD_URI_ID),
  -  key CHILD_IX2  (CHILD_URI_ID)
  +  NAME           varchar(255)  NOT NULL,
  +  CHILD_UURI_ID  bigint  NOT NULL,
  +  PRIMARY KEY    (URI_ID, NAME, CHILD_UURI_ID),
  +  KEY BINDING_IX  (CHILD_UURI_ID)
   ) TYPE=InnoDB;
   
  -ALTER TABLE CHILDREN ADD CONSTRAINT CHILDREN_FK1 FOREIGN KEY
  -CHILDREN_FK1(URI_ID) REFERENCES URI (URI_ID);
  -ALTER TABLE CHILDREN ADD CONSTRAINT CHILDREN_FK2 FOREIGN KEY
  -CHILDREN_FK2(CHILD_URI_ID) REFERENCES URI (URI_ID);
  +ALTER TABLE BINDING ADD CONSTRAINT BINDING_FK1 FOREIGN KEY
  +BINDING_FK1(URI_ID) REFERENCES URI (URI_ID);
  +ALTER TABLE BINDING ADD CONSTRAINT BINDING_FK2 FOREIGN KEY
  +BINDING_FK2(CHILD_UURI_ID) REFERENCES URI (URI_ID);
  +
  +CREATE TABLE PARENT_BINDING (
  +  URI_ID         bigint  NOT NULL,
  +  NAME           varchar(255)  NOT NULL,
  +  PARENT_UURI_ID bigint  NOT NULL,
  +  PRIMARY KEY    (URI_ID, NAME, PARENT_UURI_ID),
  +  KEY PARENT_BINDING_IX  (PARENT_UURI_ID)
  +) TYPE=InnoDB;
  +
  +ALTER TABLE PARENT_BINDING ADD CONSTRAINT PARENT_BINDING_FK1 FOREIGN KEY
  +PARENT_BINDING_FK1(URI_ID) REFERENCES URI (URI_ID);
  +ALTER TABLE PARENT_BINDING ADD CONSTRAINT PARENT_BINDING_FK2 FOREIGN KEY
  +PARENT_BINDING_FK2(PARENT_UURI_ID) REFERENCES URI (URI_ID);
   
   # --------------------------------------------------------
   
  
  
  
  1.2       +4 -4      
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SybaseRDBMSAdapter.java
  
  Index: SybaseRDBMSAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SybaseRDBMSAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SybaseRDBMSAdapter.java   3 Dec 2003 12:00:46 -0000       1.1
  +++ SybaseRDBMSAdapter.java   7 Jan 2004 14:06:02 -0000       1.2
  @@ -67,13 +67,13 @@
   import org.apache.slide.util.logger.Logger;
   
   /**
  - * Adapter for Sybase. Actually does not change a thing from StandardRDBMSAdapter.
  + * Adapter for Sybase. Actually does not change a thing from SQLServerRDBMSAdapter.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Oliver Zeigermann</a>
    * @version $Revision$
    */
   
  -public class SybaseRDBMSAdapter extends StandardRDBMSAdapter {
  +public class SybaseRDBMSAdapter extends SQLServerRDBMSAdapter {
   
       protected static final String LOG_CHANNEL = SybaseRDBMSAdapter.class.getName();
   
  
  
  
  1.5       +23 -11    
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerSchema.sql
  
  Index: SQLServerSchema.sql
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerSchema.sql,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SQLServerSchema.sql       3 Dec 2003 12:00:46 -0000       1.4
  +++ SQLServerSchema.sql       7 Jan 2004 14:06:02 -0000       1.5
  @@ -6,6 +6,14 @@
   DROP TABLE [dbo].[OBJECT]
   GO
   
  +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[BINDING]') 
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  +DROP TABLE [dbo].[BINDING]
  +GO
  +
  +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = 
OBJECT_ID(N'[dbo].[PARENT_BINDING]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  +DROP TABLE [dbo].[PARENT_BINDING]
  +GO
  +
   IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CHILDREN]') 
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
   DROP TABLE [dbo].[CHILDREN]
   GO
  @@ -131,20 +139,24 @@
   )
   GO    
   
  -CREATE TABLE dbo.CHILDREN (
  -    URI_ID          id_type               NOT NULL  FOREIGN KEY 
  -     REFERENCES  URI (URI_ID),
  -    CHILD_URI_ID    id_type               NOT NULL  FOREIGN KEY 
  -     REFERENCES  URI (URI_ID),
  -    --UNIQUE CLUSTERED (URI_ID, CHILD_URI_ID)
  +CREATE TABLE dbo.BINDING (
  +    URI_ID          id_type               NOT NULL
  +        REFERENCES  URI (URI_ID),
  +    NAME            uri_str_type          NOT NULL,
  +    CHILD_UURI_ID    id_type              NOT NULL
  +        REFERENCES  URI (URI_ID),
  +    UNIQUE CLUSTERED (URI_ID, NAME, CHILD_UURI_ID)
   )
   GO
   
  -CREATE INDEX XCHILDREN1
  -     ON CHILDREN(URI_ID) 
  -GO
  -CREATE INDEX XCHILDREN2
  -     ON CHILDREN(CHILD_URI_ID) 
  +CREATE TABLE dbo.PARENT_BINDING (
  +    URI_ID          id_type               NOT NULL
  +        REFERENCES  URI (URI_ID),
  +    NAME            uri_str_type          NOT NULL,
  +    PARENT_UURI_ID    id_type             NOT NULL
  +        REFERENCES  URI (URI_ID),
  +    UNIQUE CLUSTERED (URI_ID, NAME, PARENT_UURI_ID)
  +) 
   GO
   
   CREATE TABLE dbo.LINKS (
  
  
  
  1.12      +118 -71   
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/StandardRDBMSAdapter.java
  
  Index: StandardRDBMSAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/StandardRDBMSAdapter.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- StandardRDBMSAdapter.java 6 Jan 2004 18:52:37 -0000       1.11
  +++ StandardRDBMSAdapter.java 7 Jan 2004 14:06:02 -0000       1.12
  @@ -173,22 +173,40 @@
                   }
               }
   
  -            // update children...
  +            // update binding...
  +
               try {
  -                statement = connection.prepareStatement("delete from CHILDREN where 
URI_ID = ?");
  -                statement.setLong(1, uriid);
  -                statement.executeUpdate();
  -            } finally {
  -                close(statement);
  +                clearBinding(connection, uri);
  +            } catch (ObjectNotFoundException e1) {
  +                // clear only if it existed
  +            }
  +            
  +            Enumeration bindings = object.enumerateBindings();
  +            while (bindings.hasMoreElements()) {
  +                ObjectNode.Binding binding = (ObjectNode.Binding) 
bindings.nextElement();
  +                try {
  +                    statement =
  +                        connection.prepareStatement(
  +                            "insert into BINDING (URI_ID, NAME, CHILD_UURI_ID) 
select ?, ?, URI_ID from URI where URI_STRING = ?");
  +                    statement.setLong(1, uriid);
  +                    statement.setString(2, binding.getName());
  +                    statement.setString(3, binding.getUuri());
  +                    statement.executeUpdate();
  +                } finally {
  +                    close(statement);
  +                }
               }
  -            Enumeration children = object.enumerateChildren();
  -            while (children.hasMoreElements()) {
  +
  +            Enumeration parentBindings = object.enumerateParentBindings();
  +            while (parentBindings.hasMoreElements()) {
  +                ObjectNode.ParentBinding parentBinding = (ObjectNode.ParentBinding) 
parentBindings.nextElement();
                   try {
                       statement =
                           connection.prepareStatement(
  -                            "insert into CHILDREN (URI_ID, CHILD_URI_ID) select ?, 
URI_ID from URI where URI_STRING = ?");
  +                            "insert into PARENT_BINDING (URI_ID, NAME, 
PARENT_UURI_ID) select ?, ?, URI_ID from URI where URI_STRING = ?");
                       statement.setLong(1, uriid);
  -                    statement.setString(2, (String) children.nextElement());
  +                    statement.setString(2, parentBinding.getName());
  +                    statement.setString(3, parentBinding.getUuri());
                       statement.executeUpdate();
                   } finally {
                       close(statement);
  @@ -216,8 +234,7 @@
                   }
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
           return true;
       }
  @@ -226,17 +243,9 @@
           throws ServiceAccessException, ObjectNotFoundException {
           PreparedStatement statement = null;
           try {
  -            // delete my children and me as child of other objects
  -            try {
  -                statement =
  -                    connection.prepareStatement(
  -                        "delete CHILDREN from CHILDREN c, URI u where c.URI_ID = 
u.URI_ID and u.URI_STRING = ? or c.CHILD_URI_ID = u.URI_ID and u.URI_STRING = ?");
  -                statement.setString(1, uri.toString());
  -                statement.setString(2, uri.toString());
  -                statement.executeUpdate();
  -            } finally {
  -                close(statement);
  -            }
  +
  +            clearBinding(connection, uri);
  +
               // delete links
               try {
                   statement =
  @@ -287,8 +296,8 @@
                   close(statement);
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
  +
           }
       }
   
  @@ -300,6 +309,7 @@
               ResultSet res = null;
               String className;
               Vector children = new Vector();
  +            Vector parents = new Vector();
               Vector links = new Vector();
               try {
                   statement =
  @@ -315,18 +325,33 @@
               } finally {
                   close(statement, res);
               }
  +
               try {
                   statement =
                       connection.prepareStatement(
  -                        "SELECT cu.URI_STRING FROM URI u, URI cu, CHILDREN c WHERE 
cu.URI_ID = c.CHILD_URI_ID AND c.URI_ID = u.URI_ID and u.URI_STRING = ?");
  +                        "SELECT c.NAME, cu.URI_STRING FROM URI u, URI cu, BINDING c 
WHERE cu.URI_ID = c.CHILD_UURI_ID AND c.URI_ID = u.URI_ID and u.URI_STRING = ?");
                   statement.setString(1, uri.toString());
                   res = statement.executeQuery();
                   while (res.next()) {
  -                    children.addElement(res.getString(1));
  +                    children.addElement(new ObjectNode.Binding(res.getString(1), 
res.getString(2)));
                   }
               } finally {
                   close(statement, res);
               }
  +
  +            try {
  +                statement =
  +                    connection.prepareStatement(
  +                        "SELECT c.NAME, cu.URI_STRING FROM URI u, URI cu, 
PARENT_BINDING c WHERE cu.URI_ID = c.PARENT_UURI_ID AND c.URI_ID = u.URI_ID and 
u.URI_STRING = ?");
  +                statement.setString(1, uri.toString());
  +                res = statement.executeQuery();
  +                while (res.next()) {
  +                    parents.addElement(new 
ObjectNode.ParentBinding(res.getString(1), res.getString(2)));
  +                }
  +            } finally {
  +                close(statement, res);
  +            }
  +
               try {
                   statement =
                       connection.prepareStatement(
  @@ -358,17 +383,17 @@
               } else {
                   try {
                       Class objclass = Class.forName(className);
  -                    Class argClasses[] = { String.class, Vector.class, Vector.class 
};
  -                    Object arguments[] = { uri.toString(), children, links };
  +                    Class argClasses[] = { String.class, Vector.class, 
Vector.class, Vector.class };
  +                    Object arguments[] = { uri.toString(), children, parents, links 
};
                       Constructor constructor = objclass.getConstructor(argClasses);
                       result = (ObjectNode) constructor.newInstance(arguments);
  +                    result.setUri(result.getUuri());
                   } catch (Exception e) {
                       throw new ServiceAccessException(service, e);
                   }
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
           return result;
       }
  @@ -408,8 +433,7 @@
                   lockVector.addElement(lock);
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } finally {
               close(statement, res);
           }
  @@ -439,8 +463,7 @@
               statement.setString(7, lock.getTypeUri());
               statement.execute();
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } finally {
               close(statement);
           }
  @@ -463,9 +486,8 @@
               } finally {
                   close(statement, rslt);
               }
  -        } catch (Exception e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +        } catch (SQLException e) {
  +            throw createException(e, uri.toString());
           }
       }
   
  @@ -492,8 +514,7 @@
                   close(statement);
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
       }
   
  @@ -524,8 +545,7 @@
                   permissions.add(permission);
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } finally {
               close(statement, res);
           }
  @@ -586,8 +606,7 @@
                   close(statement);
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
       }
   
  @@ -605,8 +624,7 @@
               statement.setString(3, permission.getActionUri());
               statement.executeUpdate();
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } finally {
               close(statement);
           }
  @@ -621,8 +639,7 @@
               statement.setString(1, uri.toString());
               statement.executeUpdate();
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } finally {
               close(statement);
           }
  @@ -670,8 +687,7 @@
                   }
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
       }
   
  @@ -689,9 +705,8 @@
               } finally {
                   close(statement);
               }
  -        } catch (Exception e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +        } catch (SQLException e) {
  +            throw createException(e, uri.toString());
           }
       }
   
  @@ -720,8 +735,7 @@
                   close(statement);
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
       }
   
  @@ -735,8 +749,7 @@
                       "delete VERSION_PREDS from VERSION_PREDS vp, VERSION_HISTORY 
vh, URI u where vp.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID and 
u.URI_STRING = ?");
               statement.setString(1, uri.toString());
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } finally {
               close(statement, res);
           }
  @@ -792,8 +805,7 @@
                   }
               }
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } catch (RevisionNotFoundException e) {
               // This is not that bad, but only means, no content available. Do not 
warn, as this happens frequently with users / actions 
               /* 
  @@ -877,8 +889,7 @@
               }
               revisionDescriptor = new NodeRevisionDescriptor(revisionNumber, branch, 
labels, properties);
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
           return revisionDescriptor;
       }
  @@ -953,8 +964,7 @@
                       branches,
                       isVersioned);
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
           return revisionDescriptors;
       }
  @@ -1022,8 +1032,7 @@
                   LOG_CHANNEL,
                   Logger.INFO);
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           }
       }
   
  @@ -1082,8 +1091,7 @@
               }
               storeContent(connection, uri, revisionDescriptor, revisionContent);
           } catch (SQLException e) {
  -            getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
  -            throw new ServiceAccessException(service, e);
  +            throw createException(e, uri.toString());
           } catch (IOException e) {
               getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
               throw new ServiceAccessException(service, e);
  @@ -1307,6 +1315,35 @@
           return assureLabelId(connection, label);
       }
   
  +    protected void clearBinding(Connection connection, Uri uri)
  +        throws ServiceAccessException, ObjectNotFoundException, SQLException {
  +        PreparedStatement statement = null;
  +
  +        // clear this uri from having bindings and being bound 
  +
  +        try {
  +            statement =
  +                connection.prepareStatement(
  +                    "delete BINDING from BINDING c, URI u where c.URI_ID = u.URI_ID 
and u.URI_STRING = ? or c.CHILD_UURI_ID = u.URI_ID and u.URI_STRING = ?");
  +            statement.setString(1, uri.toString());
  +            statement.setString(2, uri.toString());
  +            statement.executeUpdate();
  +        } finally {
  +            close(statement);
  +        }
  +
  +        try {
  +            statement =
  +                connection.prepareStatement(
  +                    "delete PARENT_BINDING from PARENT_BINDING c, URI u where 
c.URI_ID = u.URI_ID and u.URI_STRING = ? or c.PARENT_UURI_ID = u.URI_ID and 
u.URI_STRING = ?");
  +            statement.setString(1, uri.toString());
  +            statement.setString(2, uri.toString());
  +            statement.executeUpdate();
  +        } finally {
  +            close(statement);
  +        }
  +    }
  +
       // null means permission is valid for all revisions
       protected String getRevisionNumberAsString(NodeRevisionNumber revisionNumber) {
           return revisionNumber != null ? revisionNumber.toString() : null;
  @@ -1344,4 +1381,14 @@
               }
           }
       }
  +
  +    // overload this method to have a more detailed error handling
  +    protected ServiceAccessException createException(SQLException e, String uri) {
  +        getLogger().log(
  +            "SQL error " + e.getErrorCode() + " on " + uri + ": " + e.getMessage(),
  +            LOG_CHANNEL,
  +            Logger.ERROR);
  +        return new ServiceAccessException(service, e);
  +    }
  +
   }
  
  
  
  1.18      +9 -5      
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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- JDBCStore.java    12 Dec 2003 02:58:43 -0000      1.17
  +++ JDBCStore.java    7 Jan 2004 14:06:02 -0000       1.18
  @@ -73,6 +73,7 @@
   import org.apache.commons.dbcp.PoolableConnectionFactory;
   import org.apache.commons.dbcp.PoolingDriver;
   import org.apache.commons.pool.impl.GenericObjectPool;
  +import org.apache.commons.pool.impl.StackKeyedObjectPoolFactory;
   import org.apache.slide.common.NamespaceAccessToken;
   import org.apache.slide.common.ServiceInitializationFailedException;
   import org.apache.slide.common.ServiceParameterErrorException;
  @@ -318,7 +319,10 @@
                       new PoolableConnectionFactory(
                           connectionFactory,
                           connectionPool,
  -                        null,
  +                        // TODO switching on pooling of prepared statements causes 
problems with closing of connections
  +                        // switched off for now
  +//                  new StackKeyedObjectPoolFactory(),
  +                        null, 
                           null,
                           false,
                           false,
  
  
  
  1.2       +28 -3     
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerRDBMSAdapter.java
  
  Index: SQLServerRDBMSAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerRDBMSAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SQLServerRDBMSAdapter.java        3 Dec 2003 12:00:46 -0000       1.1
  +++ SQLServerRDBMSAdapter.java        7 Jan 2004 14:06:02 -0000       1.2
  @@ -63,7 +63,10 @@
   
   package org.apache.slide.store.impl.rdbms;
   
  +import java.sql.SQLException;
  +
   import org.apache.slide.common.*;
  +import org.apache.slide.macro.ConflictException;
   import org.apache.slide.util.logger.Logger;
   
   /**
  @@ -80,5 +83,27 @@
       public SQLServerRDBMSAdapter(Service service, Logger logger) {
           super(service, logger);
       }
  -}
   
  +    protected ServiceAccessException createException(SQLException e, String uri) {
  +
  +        switch (e.getErrorCode()) {
  +            case 1205 : // thread was deadlock victim
  +                getLogger().log(e.getErrorCode() + ": Deadlock resolved on " + uri, 
LOG_CHANNEL, Logger.WARNING);
  +                return new ServiceAccessException(service, new 
ConflictException(uri));
  +                
  +            case 547 : // referential integraty constaint was violated (like in 
storeObject on table URI )
  +            case 2627 : // primary key constraint violation (like in storeContent 
on table VERSION_CONTENT)
  +                getLogger().log(e.getErrorCode() + ": Low isolation conflict for " 
+ uri, LOG_CHANNEL, Logger.WARNING);
  +                return new ServiceAccessException(service, new 
ConflictException(uri));
  +                
  +            default :
  +            getLogger().log("SQL error " + e.getErrorCode() + " on " + uri + ": " + 
e.getMessage(),
  +                LOG_CHANNEL,
  +                Logger.ERROR);
  +            
  +                return new ServiceAccessException(service, e);
  +        }
  +
  +    }
  +
  +}
  
  
  
  1.2       +29 -7     
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SybaseSchema.sql
  
  Index: SybaseSchema.sql
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SybaseSchema.sql,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SybaseSchema.sql  3 Dec 2003 12:00:47 -0000       1.1
  +++ SybaseSchema.sql  7 Jan 2004 14:06:02 -0000       1.2
  @@ -10,6 +10,14 @@
   DROP TABLE CHILDREN
   GO
   
  +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE name = 'BINDING')
  +DROP TABLE BINDING
  +GO
  +
  +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE name = 'PARENT_BINDING')
  +DROP TABLE PARENT_BINDING
  +GO
  +
   IF EXISTS (SELECT * FROM dbo.sysobjects WHERE name = 'LINKS')
   DROP TABLE LINKS
   GO
  @@ -128,15 +136,26 @@
   )
   GO    
   
  -CREATE TABLE dbo.CHILDREN (
  +CREATE TABLE dbo.BINDING (
       URI_ID          id_type               NOT NULL
  -     REFERENCES  URI (URI_ID),
  -    CHILD_URI_ID    id_type               NOT NULL
  -     REFERENCES  URI (URI_ID),
  -    --UNIQUE CLUSTERED (URI_ID, CHILD_URI_ID)
  +        REFERENCES  URI (URI_ID),
  +    NAME            varchar(238)          NOT NULL, -- index must not be more than 
256 bytes
  +    CHILD_UURI_ID    id_type              NOT NULL
  +        REFERENCES  URI (URI_ID),
  +    UNIQUE CLUSTERED (URI_ID, NAME, CHILD_UURI_ID)
   )
   GO
   
  +CREATE TABLE dbo.PARENT_BINDING (
  +    URI_ID          id_type               NOT NULL
  +        REFERENCES  URI (URI_ID),
  +    NAME            varchar(238)          NOT NULL, -- index must not be more than 
256 bytes
  +    PARENT_UURI_ID    id_type             NOT NULL
  +        REFERENCES  URI (URI_ID),
  +    UNIQUE CLUSTERED (URI_ID, NAME, PARENT_UURI_ID)
  +) 
  +GO
  +
   CREATE INDEX XCHILDREN1
        ON CHILDREN(URI_ID) 
   GO
  @@ -144,11 +163,14 @@
        ON CHILDREN(CHILD_URI_ID) 
   GO
   
  +-- early versions of Sybase do not allow more than 16 tables per query
  +-- URI has too many foreign keys which internally add to the tables used in a query 
on it
  +-- remove foreign keys to URI from links as they are likely to be used little
   CREATE TABLE dbo.LINKS (
       URI_ID          id_type               NOT NULL
  -        REFERENCES  URI (URI_ID),
  +/*        REFERENCES  URI (URI_ID) */ ,  
       LINK_TO_ID      id_type               NOT NULL
  -        REFERENCES  URI (URI_ID),
  +/*        REFERENCES  URI (URI_ID) */ ,
       --UNIQUE CLUSTERED (URI_ID, LINK_TO_ID)
   )
   GO
  
  
  

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

Reply via email to