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 re...@apache.org on 2001/01/30 07:16:26 UTC

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

remm        01/01/29 22:16:25

  Modified:    src/stores/slidestore/reference JDBCDescriptorsStore.java
  Log:
  - The roles feature which was introduced as part of M6 wasn't working with
    the JDBC store (the object type management was oversimplified, and had not
    been updated).
  - Thanks to Michael Smith <ms...@xn.com.au> for this great patch.
  
  Revision  Changes    Path
  1.7       +39 -45    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JDBCDescriptorsStore.java	2001/01/20 20:08:29	1.6
  +++ JDBCDescriptorsStore.java	2001/01/30 06:16:24	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v 1.6 2001/01/20 20:08:29 remm Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/01/20 20:08:29 $
  + * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v 1.7 2001/01/30 06:16:24 remm Exp $
  + * $Revision: 1.7 $
  + * $Date: 2001/01/30 06:16:24 $
    *
    * ====================================================================
    *
  @@ -63,6 +63,7 @@
   
   package slidestore.reference;
   
  +import java.lang.reflect.Constructor;
   import java.util.Hashtable;
   import java.util.Enumeration;
   import java.util.Vector;
  @@ -83,7 +84,7 @@
    * JDBC 1.0 and 2.0 compliant store implementation.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   
   public class JDBCDescriptorsStore
  @@ -95,18 +96,12 @@
       // -------------------------------------------------------------- Constants
       
       
  -    // Object types
  -    
  -    protected static final int SUBJECT = 0;
  -    protected static final int ACTION = 1;
  -    protected static final int LINK = 2;
  -    
       // Column numbers
       
       // Structure descriptors
       
       protected static final int OBJECTS_URI = 1;
  -    protected static final int OBJECTS_TYPE = 2;
  +    protected static final int OBJECTS_CLASS = 2;
       
       protected static final int CHILDREN_URI = 1;
       protected static final int CHILDREN_CHILDURI = 2;
  @@ -268,7 +263,7 @@
               Statement statement = connection.createStatement();
               
               String s = "create table objects(uri varchar(65536) " 
  -                + " primary key, type int)";
  +                + " primary key, classname varchar(4096))";
               statement.execute(s);
               
               s = "create table children(uri varchar(65536), childuri " 
  @@ -534,11 +529,11 @@
               
               // Parsing result set
               
  -            int objectType = 0;
  +            String className;
               
               if (res.next()) {
                   // Retrieving and loading the object
  -                objectType = res.getInt(OBJECTS_TYPE);
  +                className = res.getString(OBJECTS_CLASS);
               } else {
                   // Object was not found ...
                   throw new ObjectNotFoundException(uri);
  @@ -569,28 +564,39 @@
                   linksVector.addElement(res.getString(LINKS_LINKTO));
               }
               
  -            switch (objectType) {
  -            case SUBJECT :
  -                result = new SubjectNode(uri.toString(), childrenVector, 
  -                                         linksVector);
  -                break;
  -            case ACTION :
  -                result = new ActionNode(uri.toString(), childrenVector, 
  -                                        linksVector);
  -                break;
  -            case LINK :
  +            if(className.equals("org.apache.slide.structure.LinkNode")) {
  +                
                   String linkTo = new String();
                   s = "select * from links where link='" + uri + "'";
                   statement.execute(s);
                   res = statement.getResultSet();
                   
  -                // Parse result set
  -                if (res.next()) {
  +                if(res.next())
                       linkTo = res.getString(LINKS_LINKTO);
  -                }
  -                result = new LinkNode(uri.toString(), childrenVector, 
  +                
  +                result = new LinkNode(uri.toString(), childrenVector,
                                         linksVector, linkTo);
  -                break;
  +                
  +            } else {
  +                
  +                try {
  +                    Class objclass = Class.forName(className);
  +                    
  +                    Class[] argClasses = { Class.forName("java.lang.String"),
  +                                           Class.forName("java.util.Vector"),
  +                                           Class.forName("java.util.Vector") };
  +                    Object[] arguments = { uri.toString(), 
  +                                           childrenVector, 
  +                                           linksVector };
  +                    
  +                    Constructor constructor = 
  +                        objclass.getConstructor(argClasses);
  +                    result = (ObjectNode)constructor.newInstance(arguments);
  +                } catch(Exception e) { 
  +                    // ClassNotFoundException, NoSuchMethodException, etc. 
  +                    throw new ServiceAccessException(this, e);
  +                }
  +                
               }
               
           } catch (SQLException e) {
  @@ -677,21 +683,9 @@
           throws ServiceAccessException, ObjectAlreadyExistsException {
           
           try {
  -            
  -            int objectType = 0;
               
  -            if (object instanceof SubjectNode) {
  -                objectType = SUBJECT;
  -            }
  +            String className = object.getClass().getName();
               
  -            if (object instanceof LinkNode) {
  -                objectType = LINK;
  -            }
  -            
  -            if (object instanceof ActionNode) {
  -                objectType = ACTION;
  -            }
  -            
               Statement statement = connection.createStatement();
   
               String s = "select * from objects where uri='" + uri + "'";
  @@ -705,8 +699,8 @@
                   throw new ObjectAlreadyExistsException(uri.toString());
               }
               
  -            s = "insert into objects values('" + uri + "', "  
  -                + objectType + ")";
  +            s = "insert into objects values('" + uri + "', '"  
  +                + className + "')";
               
               statement.execute(s);
               
  @@ -730,7 +724,7 @@
               */
               
               // If the object is a link, also store the link information
  -            if (objectType == LINK) {
  +            if (object instanceof LinkNode) {
                   s = "insert into links values('" + uri + "', '" 
                       + ((LinkNode) object).getLinkedUri() + "')";
                   statement.execute(s);