portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlest...@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl PreferencesImpl.java CommonQueries.java PropertyManagerImpl.java PropertyException.java
Date Sat, 06 Mar 2004 18:31:01 GMT
dlestrat    2004/03/06 10:31:01

  Modified:    components/prefs/src/java/org/apache/jetspeed/prefs/impl
                        PreferencesImpl.java CommonQueries.java
                        PropertyManagerImpl.java PropertyException.java
  Log:
  Prefs impl.
  
  Revision  Changes    Path
  1.2       +186 -190  jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PreferencesImpl.java
  
  Index: PreferencesImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PreferencesImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PreferencesImpl.java	26 Feb 2004 04:30:46 -0000	1.1
  +++ PreferencesImpl.java	6 Mar 2004 18:31:01 -0000	1.2
  @@ -14,6 +14,7 @@
    */
   package org.apache.jetspeed.prefs.impl;
   
  +import java.sql.Timestamp;
   import java.io.InputStream;
   import java.io.InputStreamReader;
   import java.io.Reader;
  @@ -33,16 +34,13 @@
   import org.apache.jetspeed.components.ComponentManager;
   import org.apache.jetspeed.components.persistence.store.PersistenceStore;
   import org.apache.jetspeed.components.persistence.store.PersistenceStoreContainer;
  -import org.apache.jetspeed.components.persistence.store.impl.LockFailedException;
  -import org.apache.jetspeed.components.util.system.ClassLoaderSystemResourceUtilImpl;
  -import org.apache.jetspeed.components.util.system.SystemResourceUtil;
  +import org.apache.jetspeed.components.persistence.store.impl.DefaultPersistenceStoreContainer;
  +import org.apache.jetspeed.prefs.PreferencesComponent;
   import org.apache.jetspeed.prefs.om.Node;
   import org.apache.jetspeed.prefs.om.Property;
   import org.apache.jetspeed.prefs.om.PropertyKey;
   import org.apache.jetspeed.prefs.om.impl.NodeImpl;
   import org.apache.jetspeed.prefs.om.impl.PropertyImpl;
  -import org.apache.jetspeed.prefs.om.impl.PropertyKeyImpl;
  -import org.apache.jetspeed.prefs.PropertyManager;
   import org.apache.jetspeed.util.ArgUtil;
   
   /**
  @@ -53,9 +51,7 @@
    */
   public class PreferencesImpl extends AbstractPreferences
   {
  -    /** Preferences assembly script. */
  -    private static String PREFS_CONTAINER_GROOVY = "org/apache/jetspeed/containers/prefs.container.groovy";
  - 
  +
       /** User <tt>Preferences<tt> node type. */
       private static final short USER_NODE_TYPE = 0;
   
  @@ -74,9 +70,6 @@
       /** Common queries. **/
       private CommonQueries commonQueries;
   
  -    /** The property manager. */
  -    private PropertyManager pms;
  -
       /** BackingStore availability flag. */
       private boolean isBackingStoreAvailable = true;
   
  @@ -86,9 +79,6 @@
       /** The current <code>Node</code> object. */
       private Node node = null;
   
  -    /** The current node parent node id. */
  -    private int parentNodeId = -1;
  -
       /** The current node type. */
       private short nodeType = -1;
   
  @@ -128,25 +118,11 @@
       {
           super(parent, nodeName);
   
  -        ClassLoader cl = Thread.currentThread().getContextClassLoader();
  -        SystemResourceUtil sysRes = new ClassLoaderSystemResourceUtilImpl(cl);
  -        InputStream is = cl.getResourceAsStream(PREFS_CONTAINER_GROOVY);
  -        
  -        Reader scriptReader = new InputStreamReader(is);
  -        try
  -        {
  -            cm = new ComponentManager(scriptReader, ComponentManager.GROOVY);
  -            Class containerClass = Class.forName("org.apache.jetspeed.components.persistence.store.PersistenceStoreContainer");
  -            this.storeContainer = (PersistenceStoreContainer) cm.getComponent(containerClass);
  -            Class propertyMgrClass = Class.forName("org.apache.jetspeed.prefs.PropertyManager");
  -            this.pms = (PropertyManager) cm.getComponent(propertyMgrClass);
  -            // TODO We should get the store name from assembly
  -            this.jetspeedStoreName = "jetspeed";
  -        }
  -        catch (ClassNotFoundException cnfe)
  -        {
  -            if(log.isErrorEnabled()) log.error("ClassNotFoundException: " + cnfe);
  -        }
  +        if (log.isDebugEnabled())
  +            log.debug("Constructing node: " + nodeName);
  +        PreferencesComponent prefComponent = PreferencesComponentImpl.prefComponent;
  +        this.storeContainer = prefComponent.getStoreContainer();
  +        this.jetspeedStoreName = prefComponent.getStoreKeyName();
           this.commonQueries = new CommonQueries(storeContainer, jetspeedStoreName);
   
           this.nodeType = nodeType;
  @@ -180,32 +156,40 @@
       {
           int[] result = new int[ARRAY_SIZE];
           Integer parentNodeId = null;
  -        
  +
           if (null != parent)
           {
  -            // Get parent node id.
  -            int[] parentRetrievalResult = getParentNodeId(parent, nodeType);
  -            if (parentRetrievalResult[ERROR_CODE] != ERROR_SUCCESS)
  -            {
  -                result[ERROR_CODE] = parentRetrievalResult[ERROR_CODE];
  +            if (log.isDebugEnabled())
  +                log.debug("Current node parent: " + parent.nodeId);
  +            // Get child node
  +            Object[] nodeFromParentRetrievalResult = getChildNode(new Integer(parent.nodeId), nodeName, new Short(nodeType));
  +            if (((Integer) nodeFromParentRetrievalResult[ERROR_CODE]).intValue() == ERROR_SUCCESS)
  +            {
  +                result[NODE_ID] = ((Integer) nodeFromParentRetrievalResult[NODE_ID]).intValue();
  +                result[ERROR_CODE] = ERROR_SUCCESS;
  +                result[DISPOSITION] = DISPOSITION_EXISTING_NODE;
                   return result;
               }
  -            parentNodeId = new Integer(parentRetrievalResult[NODE_ID]);
  +            else
  +            {
  +                parentNodeId = new Integer(parent.nodeId);
  +            }
   
           }
           // Check if node exists.
  -        Object[] nodeRetrievalResult = getNode(this.absolutePath(), nodeType);
  +        Object[] nodeRetrievalResult = getNode(fullPath, nodeType);
           if (((Integer) nodeRetrievalResult[ERROR_CODE]).intValue() == ERROR_SUCCESS)
           {
               result[NODE_ID] = ((Integer) nodeRetrievalResult[NODE_ID]).intValue();
               result[ERROR_CODE] = ERROR_SUCCESS;
               result[DISPOSITION] = DISPOSITION_EXISTING_NODE;
  -
               return result;
           }
   
           // If does not exist, create.
  -        Node nodeObj = new NodeImpl(parentNodeId, null, nodeName, nodeType, fullPath);
  +        Node nodeObj = new NodeImpl(parentNodeId, nodeName, nodeType, fullPath);
  +        if (log.isDebugEnabled())
  +            log.debug("New node: " + nodeObj.toString());
           PersistenceStore store = getPersistenceStore();
           try
           {
  @@ -215,9 +199,16 @@
               result[NODE_ID] = nodeObj.getNodeId();
               result[ERROR_CODE] = ERROR_SUCCESS;
               result[DISPOSITION] = DISPOSITION_NEW_NODE;
  +
  +            this.nodeId = nodeObj.getNodeId();
  +            this.node = nodeObj;
           }
  -        catch (LockFailedException lfe)
  +        catch (Exception e)
           {
  +            String msg = "Unable to store Node.";
  +            log.error(msg, e);
  +            store.getTransaction().rollback();
  +
               result[ERROR_CODE] = ERROR_NODE_CREATION_FAILED;
           }
   
  @@ -225,46 +216,53 @@
       }
   
       /**
  -     * <p>Get the parent node id from the parent object.</p>
  -     * @param parent The parent.
  +     * <p>Get the node id from the full path.</p>
  +     * @param fullPath The full path.
        * @param nodeType The node type.
        * @return An array of value returned including:
        *         <ul>
  -     *          <li>At index NODE_ID: The parent node id.</li>
  +     *          <li>At index NODE_ID: The node id.</li>
  +     *          <li>At index NODE: The node object.</li>
        *          <li>At index ERROR_CODE: The error code.</li>
        *         </ul>
        */
  -    private int[] getParentNodeId(PreferencesImpl parent, short nodeType)
  +    private Object[] getNode(String fullPath, short nodeType)
       {
  -        int[] result = new int[ARRAY_SIZE];
  +        Object[] result = new Object[ARRAY_SIZE];
  +        if (log.isDebugEnabled())
  +            log.debug("Getting node: [[nodeId, " + this.nodeId + "], [fullPath, " + fullPath + "], [nodeType, " + nodeType + "]]");
   
  -        if (this.parentNodeId != -1)
  +        if (this.nodeId != -1 && (null != this.node))
           {
  -            result[NODE_ID] = this.parentNodeId;
  -            result[ERROR_CODE] = ERROR_SUCCESS;
  +            result[NODE_ID] = new Integer(this.nodeId);
  +            result[NODE] = this.node;
  +            result[ERROR_CODE] = new Integer(ERROR_SUCCESS);
               return result;
           }
   
           PersistenceStore store = getPersistenceStore();
  -        Node nodeObj =
  -            (Node) store.getObjectByQuery(commonQueries.newNodeQueryByPathAndType(parent.absolutePath(), new Short(nodeType)));
  +        Node nodeObj = (Node) store.getObjectByQuery(commonQueries.newNodeQueryByPathAndType(fullPath, new Short(nodeType)));
           if (null != nodeObj)
           {
  -            result[NODE_ID] = nodeObj.getNodeId();
  -            result[ERROR_CODE] = ERROR_SUCCESS;
  +            result[NODE_ID] = new Integer(nodeObj.getNodeId());
  +            result[NODE] = nodeObj;
  +            result[ERROR_CODE] = new Integer(ERROR_SUCCESS);
  +            if (log.isDebugEnabled())
  +                log.debug("Found node: " + nodeObj.getFullPath());
  +            this.node = nodeObj;
  +            this.nodeId = nodeObj.getNodeId();
               return result;
           }
           else
           {
  -            result[ERROR_CODE] = ERROR_PARENT_NOT_FOUND;
  +            result[ERROR_CODE] = new Integer(ERROR_NODE_NOT_FOUND);
               return result;
           }
       }
   
       /**
  -     * <p>Get the node id from the full path.</p>
  -     * @param fullPath The full path.
  -     * @param nodeType The node type.
  +     * <p>Get the child node from the parent node.</p>
  +     * @param parentIdObject The parent node id.
        * @return An array of value returned including:
        *         <ul>
        *          <li>At index NODE_ID: The node id.</li>
  @@ -272,25 +270,21 @@
        *          <li>At index ERROR_CODE: The error code.</li>
        *         </ul>
        */
  -    private Object[] getNode(String fullPath, short nodeType)
  +    private Object[] getChildNode(Integer parentIdObject, String nodeName, Short nodeType)
       {
           Object[] result = new Object[ARRAY_SIZE];
  -
  -        if (this.nodeId != -1 && (null != this.node))
  -        {
  -            result[NODE_ID] = new Integer(this.nodeId);
  -            result[NODE] = this.node;
  -            result[ERROR_CODE] = new Integer(ERROR_SUCCESS);
  -            return result;
  -        }
  -
           PersistenceStore store = getPersistenceStore();
  -        Node nodeObj = (Node) store.getObjectByQuery(commonQueries.newNodeQueryByPathAndType(fullPath, new Short(nodeType)));
  +        Node nodeObj =
  +            (Node) store.getObjectByQuery(commonQueries.newNodeQueryByParentIdNameAndType(parentIdObject, nodeName, nodeType));
           if (null != nodeObj)
           {
               result[NODE_ID] = new Integer(nodeObj.getNodeId());
               result[NODE] = nodeObj;
               result[ERROR_CODE] = new Integer(ERROR_SUCCESS);
  +            if (log.isDebugEnabled())
  +                log.debug("Found child node: " + nodeObj.getFullPath());
  +            this.nodeId = nodeObj.getNodeId();
  +            this.node = nodeObj;
               return result;
           }
           else
  @@ -341,6 +335,9 @@
        */
       public AbstractPreferences childSpi(String name)
       {
  +        System.out.println("Child: " + name);
  +        if (null != this.node)
  +            System.out.println("Parent: " + this.node.getFullPath());
           return new PreferencesImpl(this, name, this.nodeType);
       }
   
  @@ -358,15 +355,25 @@
       public String getSpi(String key)
       {
           String value = null;
  -        PropertyKey propKey = getPropertyKeyByName(key.toLowerCase());
  -        if (null != propKey)
  +        Object[] nodeResult = getNode(this.absolutePath(), this.nodeType);
  +
  +        if (((Integer) nodeResult[ERROR_CODE]).intValue() != ERROR_SUCCESS)
           {
  -            PersistenceStore store = getPersistenceStore();
  -            Property prop =
  -                (Property) store.getObjectByQuery(commonQueries.newPropertyQueryById(new Integer(propKey.getPropertyKeyId())));
  -            if (null != prop)
  +            log.error("Could not get node id. Returned error code " + nodeResult[ERROR_CODE]);
  +            return value;
  +        }
  +
  +        // Get the property set def.
  +        Node nodeObj = (Node) nodeResult[NODE];
  +        Collection properties = nodeObj.getNodeProperties();
  +        if (log.isDebugEnabled())
  +            log.debug("Node properties: " + properties.size());
  +        for (Iterator i = properties.iterator(); i.hasNext();)
  +        {
  +            Property curProp = (Property) i.next();
  +            if (curProp.getPropertyKey().getPropertyKeyName().equals(key))
               {
  -                value = prop.getPropertyValue(propKey.getPropertyKeyType());
  +                value = curProp.getPropertyValue(curProp.getPropertyKey().getPropertyKeyType());
               }
           }
           return value;
  @@ -381,9 +388,11 @@
   
           PersistenceStore store = getPersistenceStore();
           Node nodeObj = (Node) store.getObjectByQuery(commonQueries.newNodeQueryById(new Integer(this.nodeId)));
  +        if (log.isDebugEnabled())
  +            log.debug("Fetching keys for node: " + nodeObj.toString());
           if (null != nodeObj)
           {
  -            Collection propCol = nodeObj.getProperties();
  +            Collection propCol = nodeObj.getNodeProperties();
               if ((null != propCol) && propCol.size() > 0)
               {
                   for (Iterator j = propCol.iterator(); j.hasNext();)
  @@ -409,7 +418,6 @@
        */
       public void putSpi(String key, String value)
       {
  -        int propertySetDefId = 0;
           Object[] nodeResult = getNode(this.absolutePath(), this.nodeType);
   
           if (((Integer) nodeResult[ERROR_CODE]).intValue() != ERROR_SUCCESS)
  @@ -418,109 +426,77 @@
               return;
           }
   
  -        // Check that node name is a property set.
  -        //        try
  -        //        {
  -        //            // TODO This broke
  -        //            propertySetDefId = pms.getPropertySetDefIdByType(this.name().toLowerCase(), this.nodeType);
  -        //        }
  -        //        catch (PropertyException pe)
  -        //        {
  -        //            log.error(PropertyException.PROPERTYSET_DEFINITION_NOT_FOUND);
  -        //            return;
  -        //        }
  -        // The property set exists. Add the property key/value if defined.
  -        PropertyKey propKey = getPropertyKeyByName(key);
  -        if (null != propKey)
  +        // Get the property set def.
  +        Node nodeObj = (Node) nodeResult[NODE];
  +        Collection nodeKeys = nodeObj.getNodeKeys();
  +        Collection properties = nodeObj.getNodeProperties();
  +        ArrayList newProperties = new ArrayList(properties.size() + 1);
  +        boolean foundProp = false;
  +        boolean foundKey = false;
  +        // First if the property exists, update its value.
  +        for (Iterator i = properties.iterator(); i.hasNext();)
  +        {
  +            Property curProp = (Property) i.next();
  +            if (curProp.getPropertyKey().getPropertyKeyName().equals(key))
  +            {
  +                foundProp = true;
  +                foundKey = true;
  +                if (log.isDebugEnabled())
  +                    log.debug("Update existing property: [" + key + ", " + value + "]");
  +
  +                curProp.setPropertyValue(curProp.getPropertyKey().getPropertyKeyType(), value);
  +                curProp.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  +            }
  +            newProperties.add(curProp);
  +        }
  +        // The property does not already exist.  Create a new property, if
  +        // the property key exits and is associated to this node.
  +        if (!foundProp)
           {
  -            addProperty((Node) nodeResult[NODE], new Integer(propertySetDefId), propKey, value);
  -        }
  -        else
  -        {
  -            log.error(PropertyException.PROPERTYKEY_NOT_FOUND);
  -        }
  -    }
  -
  -    /**
  -     * <p>Add property key/value pair to a property set node.</p>
  -     * @param nodeObj The node object.
  -     * @param propertySetDefId The property set definition id.
  -     * @param propKey The property key id.
  -     * @param value The property value.
  -     */
  -    private void addProperty(Node nodeObj, Integer propertySetDefId, PropertyKey propKey, String value)
  -    {
  -        PersistenceStore store = getPersistenceStore();
  -        // Check that the node has been associated to a property set definition.
  -        Integer nodePropSetDefId = nodeObj.getPropertySetDefId();
  -        if (null == nodePropSetDefId)
  -        {
  -            // TODO Should be able to add property directly to node.
  -            // Associate the node to the property set definition.
  -            nodeObj.setPropertySetDefId(propertySetDefId);
  -            try
  -            {
  -                store.lockForWrite(nodeObj);
  -                store.getTransaction().checkpoint();
  -            }
  -            catch (LockFailedException lfe)
  +            for (Iterator i = nodeKeys.iterator(); i.hasNext();)
               {
  -                log.error("Unable to lock Node for update: " + lfe.toString());
  -            }
  -        }
  +                PropertyKey curpk = (PropertyKey) i.next();
  +                if (curpk.getPropertyKeyName().equals(key))
  +                {
  +                    foundKey = true;
  +                    if (log.isDebugEnabled())
  +                        log.debug("New property value: [" + key + ", " + value + "]");
   
  -        // Check if the property value already exists.
  -        Property prop = getPropertyById(propKey.getPropertyKeyId());
  -        // If the property does not exist, create it.
  -        if (null == prop)
  -        {
  -            prop = new PropertyImpl(propKey.getPropertyKeyId(), nodeObj.getNodeId(), propKey.getPropertyKeyType(), value);
  +                    newProperties.add(
  +                        new PropertyImpl(nodeObj.getNodeId(), curpk.getPropertyKeyId(), curpk, curpk.getPropertyKeyType(), value));
  +                }
  +            }
           }
  -        else
  +        if (!foundKey)
           {
  -            prop.setPropertyValue(propKey.getPropertyKeyType(), value);
  +            if (log.isWarnEnabled())
  +                log.warn(PropertyException.PROPERTYKEY_NOT_FOUND);
  +            return;
           }
  +        // Update node.
  +        PersistenceStore store = getPersistenceStore();
  +        if (log.isDebugEnabled())
  +            log.debug("Updated properties: " + newProperties.size());
  +        // What going on:
  +        if (newProperties.size() > 0)
  +            log.debug("Properties: " + ((Property) newProperties.get(0)).toString());
   
  -        // Update the property.
           try
           {
  -            store.lockForWrite(prop);
  +            store.lockForWrite(nodeObj);
  +            nodeObj.setNodeProperties(newProperties);
  +            nodeObj.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  +            if (log.isDebugEnabled())
  +                log.debug("Node for update: " + nodeObj.toString());
               store.getTransaction().checkpoint();
           }
  -        catch (LockFailedException lfe)
  +        catch (Exception e)
           {
  -            log.error("Unable to lock Property for update: " + lfe.toString());
  +            String msg = "Unable to update Node.";
  +            log.error(msg, e);
  +            store.getTransaction().rollback();
           }
  -    }
  -
  -    /**
  -     * <p>Get property by id.</p>
  -     * @param propertyKeyId The property key id.
  -     * @return The property.
  -     */
  -    private Property getPropertyById(int propertyKeyId)
  -    {
  -        Integer propertyKeyIdObject = new Integer(propertyKeyId);
  -
  -        ArgUtil.notNull(new Object[] { propertyKeyIdObject }, new String[] { "propertyKeyId" }, "getPropertyById(int)");
   
  -        PersistenceStore store = getPersistenceStore();
  -        Property prop = (Property) store.getObjectByQuery(commonQueries.newPropertyQueryById(propertyKeyIdObject));
  -        return prop;
  -    }
  -
  -    /**
  -     * <p>Get property key by id.</p>
  -     * @param key The property key name.
  -     * @return The property key.
  -     */
  -    private PropertyKey getPropertyKeyByName(String key)
  -    {
  -        ArgUtil.notNull(new Object[] { key }, new String[] { "propertyKeyName" }, "getPropertyKeyByName(java.lang.String)");
  -
  -        PersistenceStore store = getPersistenceStore();
  -        PropertyKey propKey = (PropertyKey) store.getObjectByQuery(commonQueries.newPropertyKeyQueryByName(key.toLowerCase()));
  -        return propKey;
       }
   
       /**
  @@ -528,6 +504,8 @@
        */
       public void removeNodeSpi() throws BackingStoreException
       {
  +        if (log.isDebugEnabled())
  +            log.debug("Attempting to remove: " + this.absolutePath());
           Object[] nodeResult = getNode(this.absolutePath(), this.nodeType);
   
           if (((Integer) nodeResult[ERROR_CODE]).intValue() != ERROR_SUCCESS)
  @@ -539,16 +517,20 @@
               }
               throw new BackingStoreException(warning);
           }
  -
  -        // Delete the node.
  +        PersistenceStore store = getPersistenceStore();
           try
           {
  -            PersistenceStore store = getPersistenceStore();
  -            store.deletePersistent(nodeResult[NODE]);
  +            Node nodeObj = (Node) nodeResult[NODE];
  +            if (log.isDebugEnabled())
  +                log.debug("Remove node: " + nodeObj.getNodeName());
  +            store.deletePersistent(nodeObj);
  +            store.getTransaction().checkpoint();
           }
  -        catch (LockFailedException lfe)
  +        catch (Exception e)
           {
  -            throw new BackingStoreException("Unable to lock Node for deletion: " + lfe.toString());
  +            String msg = "Unable to remove Node.";
  +            log.error(msg, e);
  +            store.getTransaction().rollback();
           }
       }
   
  @@ -559,24 +541,38 @@
       {
           Object[] nodeResult = getNode(this.absolutePath(), this.nodeType);
   
  -        if (((Integer) nodeResult[ERROR_CODE]).intValue() == ERROR_SUCCESS)
  +        if (((Integer) nodeResult[ERROR_CODE]).intValue() != ERROR_SUCCESS)
           {
  -            PropertyKey propKey = getPropertyKeyByName(key);
  -            if (null != propKey)
  +            log.error("Could not get node id. Returned error code " + nodeResult[ERROR_CODE]);
  +            return;
  +        }
  +
  +        // Get the property set def.
  +        Node nodeObj = (Node) nodeResult[NODE];
  +        Collection properties = nodeObj.getNodeProperties();
  +        ArrayList newProperties = new ArrayList(properties.size());
  +        for (Iterator i = properties.iterator(); i.hasNext();)
  +        {
  +            Property curProp = (Property) i.next();
  +            if (!(curProp.getPropertyKey().getPropertyKeyName().equals(key)))
               {
  -                try
  -                {
  -                    PersistenceStore store = getPersistenceStore();
  -                    store.deleteAll(
  -                        commonQueries.newPropertyQueryByNodeIdAndPropertyKeyId(
  -                            new Integer(((Node) nodeResult[NODE]).getNodeId()),
  -                            new Integer(propKey.getPropertyKeyId())));
  -                }
  -                catch (LockFailedException lfe)
  -                {
  -                    log.error("Unable to remove property keys: " + lfe.toString());
  -                }
  +                newProperties.add(curProp);
               }
  +        }
  +        // Update node.
  +        PersistenceStore store = getPersistenceStore();
  +        try
  +        {
  +            store.lockForWrite(nodeObj);
  +            nodeObj.setNodeProperties(newProperties);
  +            nodeObj.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  +            store.getTransaction().checkpoint();
  +        }
  +        catch (Exception e)
  +        {
  +            String msg = "Unable to update Node.";
  +            log.error(msg, e);
  +            store.getTransaction().rollback();
           }
       }
   
  
  
  
  1.2       +10 -69    jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/CommonQueries.java
  
  Index: CommonQueries.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/CommonQueries.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CommonQueries.java	26 Feb 2004 04:30:46 -0000	1.1
  +++ CommonQueries.java	6 Mar 2004 18:31:01 -0000	1.2
  @@ -16,7 +16,6 @@
   
   import org.apache.jetspeed.prefs.om.impl.NodeImpl;
   import org.apache.jetspeed.prefs.om.impl.PropertyImpl;
  -import org.apache.jetspeed.prefs.om.impl.PropertySetDefImpl;
   import org.apache.jetspeed.prefs.om.impl.PropertyKeyImpl;
   import org.apache.jetspeed.components.persistence.store.PersistenceStore;
   import org.apache.jetspeed.components.persistence.store.PersistenceStoreContainer;
  @@ -46,53 +45,6 @@
       }
   
       /**
  -     * <p>Utility method to create a new <code>PropertySetDef</code>
  -     * by propertySetDefId query.</p>
  -     * @param propertySetDefIdObject The propertySetDefId object.
  -     * @return The new query.
  -     */
  -   /* Object newPropertySetDefQueryById(Object propertySetDefIdObject)
  -    {
  -        PersistenceStore store = getPersistenceStore();
  -        Filter filter = store.newFilter();
  -        filter.addEqualTo("propertySetDefId", propertySetDefIdObject);
  -        Object query = store.newQuery(PropertySetDefImpl.class, filter);
  -        return query;
  -    }*/
  -
  -    /**
  -     * <p>Utility method to create a new <code>PropertySetDef</code>
  -     * by propertySetType query.
  -     * @param propertySetTypeObject The propertySetType object.
  -     * @return The new query.
  -     */
  -    Object newPropertySetDefQueryByType(Object propertySetTypeObject)
  -    {
  -        PersistenceStore store = getPersistenceStore();
  -        Filter filter = store.newFilter();
  -        filter.addEqualTo("propertySetType", propertySetTypeObject);
  -        Object query = store.newQuery(PropertySetDefImpl.class, filter);
  -        return query;
  -    }
  -
  -    /**
  -     * <p>Utility method to create a new <code>PropertySetDef</code>
  -     * by propertySetName and propertySetType query.</p>
  -     * @param propertySetName The propertySetName.
  -     * @param propertySetTypeObject The propertySetType object.
  -     * @return The new query.
  -     */
  -    Object newPropertySetDefQueryByNameAndType(Object propertySetName, Object propertySetTypeObject)
  -    {
  -        PersistenceStore store = getPersistenceStore();
  -        Filter filter = store.newFilter();
  -        filter.addEqualTo("propertySetName", propertySetName);
  -        filter.addEqualTo("propertySetType", propertySetTypeObject);
  -        Object query = store.newQuery(PropertySetDefImpl.class, filter);
  -        return query;
  -    }
  -
  -    /**
        * <p>Utility method to create a new <code>PropertyKey</code>
        * by propertyKeyId query.</p>
        * @param propertyKeyIdObject The propertyKeyId object.
  @@ -109,21 +61,6 @@
   
       /**
        * <p>Utility method to create a new <code>PropertyKey</code>
  -     * by propertySetDefId query.</p>
  -     * @param propertySetDefIdObject The propertySetDefId object.
  -     * @return The new query.
  -     */
  -    /*Object newPropertyKeyQueryByPropertySetDefId(Object propertySetDefIdObject)
  -    {
  -        PersistenceStore store = getPersistenceStore();
  -        Filter filter = store.newFilter();
  -        filter.addEqualTo("propertySetDefId", propertySetDefIdObject);
  -        Object query = store.newQuery(PropertyKeyImpl.class, filter);
  -        return query;
  -    }*/
  -
  -    /**
  -     * <p>Utility method to create a new <code>PropertyKey</code>
        * by propertyKeyName query.</p>
        * @param propertyKeyNameObject The propertyKeyName object.
        * @return The new query.
  @@ -186,30 +123,34 @@
   
       /**
        * <p>Utility method to create a new <code>Node</code>
  -     * by parentNodeId query.</p>
  +     * by parentNodeId, name and type query.</p>
        * @param parentNodeIdObject The parentNodeId object.
  +     * @param nodeName The node name.
  +     * @param nodeType The node type.
        * @return The new query.
        */
  -    Object newNodeQueryByParentId(Object parentNodeIdObject)
  +    Object newNodeQueryByParentIdNameAndType(Object parentNodeIdObject, Object nodeName, Object nodeType)
       {
           PersistenceStore store = getPersistenceStore();
           Filter filter = store.newFilter();
           filter.addEqualTo("parentNodeId", parentNodeIdObject);
  +        filter.addEqualTo("nodeName", nodeName);
  +        filter.addEqualTo("nodeType", nodeType);
           Object query = store.newQuery(NodeImpl.class, filter);
           return query;
       }
   
       /**
        * <p>Utility method to create a new <code>Node</code>
  -     * by propertySetDefId query.</p>
  -     * @param propertySetDefIdObject The propertySetDefId object.
  +     * by parentNodeId query.</p>
  +     * @param parentNodeIdObject The parentNodeId object.
        * @return The new query.
        */
  -    Object newNodeQueryByPropertySetDefId(Object propertySetDefIdObject)
  +    Object newNodeQueryByParentId(Object parentNodeIdObject)
       {
           PersistenceStore store = getPersistenceStore();
           Filter filter = store.newFilter();
  -        filter.addEqualTo("propertySetDefId", propertySetDefIdObject);
  +        filter.addEqualTo("parentNodeId", parentNodeIdObject);
           Object query = store.newQuery(NodeImpl.class, filter);
           return query;
       }
  
  
  
  1.2       +173 -273  jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PropertyManagerImpl.java
  
  Index: PropertyManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PropertyManagerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertyManagerImpl.java	26 Feb 2004 04:30:46 -0000	1.1
  +++ PropertyManagerImpl.java	6 Mar 2004 18:31:01 -0000	1.2
  @@ -20,6 +20,7 @@
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Collection;
  +import java.util.prefs.Preferences;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -28,11 +29,10 @@
   import org.apache.jetspeed.components.persistence.store.PersistenceStoreContainer;
   import org.apache.jetspeed.components.persistence.store.impl.LockFailedException;
   import org.apache.jetspeed.prefs.PropertyManager;
  -import org.apache.jetspeed.prefs.om.PropertySetDef;
  +import org.apache.jetspeed.prefs.om.Node;
  +import org.apache.jetspeed.prefs.om.Property;
   import org.apache.jetspeed.prefs.om.PropertyKey;
  -import org.apache.jetspeed.prefs.om.impl.PropertyImpl;
   import org.apache.jetspeed.prefs.om.impl.PropertyKeyImpl;
  -import org.apache.jetspeed.prefs.om.impl.PropertySetDefImpl;
   import org.apache.jetspeed.components.persistence.store.Filter;
   import org.apache.jetspeed.util.ArgUtil;
   
  @@ -46,6 +46,12 @@
   {
       private static final Log log = LogFactory.getLog(PropertyManagerImpl.class);
   
  +    /** User <tt>Preferences<tt> node type. */
  +    private static final short USER_NODE_TYPE = 0;
  +
  +    /** System <tt>Preferences</tt> node type. */
  +    private static final short SYSTEM_NODE_TYPE = 1;
  +
       /** The persistence store container. */
       private PersistenceStoreContainer storeContainer;
   
  @@ -71,353 +77,247 @@
       }
   
       /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#addPropertySetDef(java.lang.String, short)
  +     * @see org.apache.jetspeed.prefs.PropertyManager#addPropertyKeys(java.util.prefs.Preferences, java.util.Map)
        */
  -    public void addPropertySetDef(String propertySetName, short propertySetType) throws PropertyException
  +    public void addPropertyKeys(Preferences prefNode, Map propertyKeysMap) throws PropertyException
       {
  -        Short propertySetTypeObject = new Short(propertySetType);
           ArgUtil.notNull(
  -            new Object[] { propertySetName, propertySetTypeObject },
  -            new String[] { "propertySetName", "propertySetType" },
  -            "addPropertySetDef(java.lang.String, java.lang.String)");
  +            new Object[] { prefNode, propertyKeysMap },
  +            new String[] { "prefNode", "propertyKeysMap", },
  +            "addPropertyKeys(java.util.prefs.Preferences, java.util.Collection)");
   
  -        // We should not have duplicated property set definition for a
  -        // specific type.
           PersistenceStore store = getPersistenceStore();
  -        PropertySetDef ppsd =
  -            (PropertySetDef) store.getObjectByQuery(
  -                commonQueries.newPropertySetDefQueryByNameAndType(propertySetName, propertySetTypeObject));
  -        if (null == ppsd)
  +        Node nodeObj;
  +        if (prefNode.isUserNode())
  +        {
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(USER_NODE_TYPE)));
  +        }
  +        else
           {
  -            ppsd = new PropertySetDefImpl(propertySetName, propertySetType);
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(SYSTEM_NODE_TYPE)));
  +        }
  +        if (null != nodeObj)
  +        {
  +            // Get the existing property keys.
  +            Collection propertyKeys = nodeObj.getNodeKeys();
  +            ArrayList newPropertyKeys = new ArrayList(propertyKeysMap.size());
  +            for (Iterator i = propertyKeysMap.keySet().iterator(); i.hasNext();)
  +            {
  +                boolean foundKey = false;
  +                String currentPropertyKeyName = (String) i.next();
  +                for (Iterator j = propertyKeys.iterator(); j.hasNext();)
  +                {
  +                    PropertyKey existingPpk = (PropertyKey) j.next();
  +                    if (existingPpk.getPropertyKeyName().equals((String) propertyKeysMap.get(currentPropertyKeyName)))
  +                    {
  +                        if (log.isDebugEnabled())
  +                            log.debug("Existing Property: " + (String) propertyKeysMap.get(currentPropertyKeyName));
  +                        foundKey = true;
  +                        newPropertyKeys.add(existingPpk);
  +                        break;
  +                    }
  +                }
  +                if (!foundKey)
  +                {
  +                    if (log.isDebugEnabled())
  +                        log.debug("New Property: " + currentPropertyKeyName);
  +                    PropertyKey ppk =
  +                        new PropertyKeyImpl(
  +                            currentPropertyKeyName,
  +                            ((Short) propertyKeysMap.get(currentPropertyKeyName)).shortValue());
  +                    newPropertyKeys.add(ppk);
  +                }
  +            }
  +
  +            // Add the properties keys.
               try
               {
  -                store.lockForWrite(ppsd);
  +                if (log.isDebugEnabled())
  +                    log.debug("Node: " + nodeObj.toString());
  +                if (log.isDebugEnabled())
  +                    log.debug("Node property keys: " + newPropertyKeys.toString());
  +                store.lockForWrite(nodeObj);
  +                nodeObj.setNodeKeys(newPropertyKeys);
  +                nodeObj.setModifiedDate(new Timestamp(System.currentTimeMillis()));
                   store.getTransaction().checkpoint();
               }
               catch (LockFailedException lfe)
               {
  -                throw new PropertyException("Unable to lock PropertySetDef for update: " + lfe.toString(), lfe);
  +                throw new PropertyException("Unable to lock Node for update: " + lfe.toString(), lfe);
               }
           }
           else
           {
  -            throw new PropertyException(PropertyException.PROPERTYSET_DEFINITION_ALREADY_EXISTS);
  +            throw new PropertyException(PropertyException.NODE_NOT_FOUND);
           }
       }
   
       /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#getPropertySetDefIdByType(java.lang.String, short)
  +     * @see org.apache.jetspeed.prefs.PropertyManager#getPropertyKeys(java.util.prefs.Preferences)
        */
  -    //    public int getPropertySetDefIdByType(String propertySetName, short propertySetType) throws PropertyException
  -    //    {
  -    //        Short propertySetTypeObject = new Short(propertySetType);
  -    //        ArgUtil.notNull(
  -    //            new Object[] { propertySetName, propertySetTypeObject },
  -    //            new String[] { "propertySetName", "propertySetType" },
  -    //            "getPropertySetDefIdByType(java.lang.String, java.lang.String)");
  -    //
  -    //        PersistenceStore store = getPersistenceStore();
  -    //        PropertySetDef ppsd =
  -    //            (PropertySetDef) store.getObjectByQuery(
  -    //                commonQueries.newPropertySetDefQueryByNameAndType(propertySetName, propertySetTypeObject));
  -    //        if (null != ppsd)
  -    //        {
  -    //            return ppsd.getPropertySetDefId();
  -    //        }
  -    //        else
  -    //        {
  -    //            throw new PropertyException(PropertyException.PROPERTYSET_DEFINITION_NOT_FOUND);
  -    //        }
  -    //    }
  -
  -    /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#removePropertySetDef(java.lang.String, short)
  -     */
  -    public void removePropertySetDef(String propertySetName, short propertySetType) throws PropertyException
  +    public Map getPropertyKeys(Preferences prefNode)
       {
  -        Short propertySetTypeObject = new Short(propertySetType);
  -        ArgUtil.notNull(
  -            new Object[] { propertySetName, propertySetTypeObject },
  -            new String[] { "propertySetName", "propertySetType" },
  -            "removePropertySetDef(java.lang.String, short)");
  +        ArgUtil.notNull(new Object[] { prefNode }, new String[] { "prefNode" }, "getPropertyKeys(java.util.prefs.Preferences)");
   
  -        // We need to remove all property set, property values and
  -        // keys associated to that set definition.
           PersistenceStore store = getPersistenceStore();
  -        PropertySetDef ppsd =
  -            (PropertySetDef) store.getObjectByQuery(
  -                commonQueries.newPropertySetDefQueryByNameAndType(propertySetName, propertySetTypeObject));
  -        if (null == ppsd)
  +        Node nodeObj;
  +        if (prefNode.isUserNode())
           {
  -            if (log.isDebugEnabled())
  -                log.debug("Property set definition is null. Nothing to remove.");
  -            return;
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(USER_NODE_TYPE)));
           }
  -        try
  +        else
           {
  -            store.deletePersistent(ppsd);
  -            store.getTransaction().checkpoint();
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(SYSTEM_NODE_TYPE)));
           }
  -        catch (LockFailedException lfe)
  +        if (null != nodeObj)
           {
  -            throw new PropertyException("Unable to remove property set definition: " + lfe.toString(), lfe);
  -
  -        }
  -    }
  -
  -    /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#updatePropertySetDef(java.lang.String, java.lang.String, short)
  -     */
  -    public void updatePropertySetDef(String newPropertySetName, String oldPropertySetName, short propertySetType)
  -        throws PropertyException
  -    {
  -        Short propertySetTypeObject = new Short(propertySetType);
  -
  -        ArgUtil.notNull(
  -            new Object[] { newPropertySetName, oldPropertySetName, propertySetTypeObject },
  -            new String[] { "newPropertySetName", "oldPropertySetName", "propertySetType" },
  -            "updatePropertySetDef(java.lang.String, java.lang.String, short)");
  -
  -        PersistenceStore store = getPersistenceStore();
  -        PropertySetDef ppsd =
  -            (PropertySetDef) store.getObjectByQuery(
  -                commonQueries.newPropertySetDefQueryByNameAndType(oldPropertySetName, propertySetTypeObject));
  -        try
  -        {
  -            store.lockForWrite(ppsd);
  -            ppsd.setPropertySetName(newPropertySetName);
  -            ppsd.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  -            store.getTransaction().checkpoint();
  +            Collection keys = nodeObj.getNodeKeys();
  +            HashMap propertyKeysMap = new HashMap(keys.size());
  +            for (Iterator i = keys.iterator(); i.hasNext();)
  +            {
  +                PropertyKey curpk = (PropertyKey) i.next();
  +                propertyKeysMap.put(curpk.getPropertyKeyName(), new Short(curpk.getPropertyKeyType()));
  +            }
  +            return propertyKeysMap;
           }
  -        catch (LockFailedException lfe)
  +        else
           {
  -            throw new PropertyException("Unable to lock PropertySetDef for update: " + lfe.toString(), lfe);
  +            return new HashMap(0);
           }
       }
   
       /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#getAllPropertySetsByType(short)
  +     * @see org.apache.jetspeed.prefs.PropertyManager#removePropertyKeys(java.util.prefs.Preferences, java.util.Collection)
        */
  -    public Collection getAllPropertySetsByType(short propertySetType) throws PropertyException
  +    public void removePropertyKeys(Preferences prefNode, Collection propertyKeys) throws PropertyException
       {
  -        Short propertySetTypeObject = new Short(propertySetType);
           ArgUtil.notNull(
  -            new Object[] { propertySetTypeObject },
  -            new String[] { "propertySetType" },
  -            "getAllPropertySetsByType(short)");
  +            new Object[] { prefNode, propertyKeys },
  +            new String[] { "prefNode", "propertyKeys" },
  +            "removePropertyKeys(java.util.prefs.Preferences, java.util.Collection)");
   
           PersistenceStore store = getPersistenceStore();
  -        Collection propertySetDefs = store.getCollectionByQuery(commonQueries.newPropertySetDefQueryByType(propertySetTypeObject));
  -        if (null != propertySetDefs)
  +        Node nodeObj;
  +        if (prefNode.isUserNode())
           {
  -            ArrayList propertySetsByType = new ArrayList(propertySetDefs.size());
  -            for (Iterator i = propertySetDefs.iterator(); i.hasNext();)
  -            {
  -                PropertySetDef curppsd = (PropertySetDef) i.next();
  -                propertySetsByType.add(curppsd.getPropertySetName());
  -            }
  -            return propertySetsByType;
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(USER_NODE_TYPE)));
           }
           else
           {
  -            throw new PropertyException(PropertyException.PROPERTYSET_DEFINITION_NOT_FOUND);
  -        }
  -
  -    }
  -
  -    /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#addPropertyKeys(java.lang.String, short, java.util.Collection)
  -     */
  -    public void addPropertyKeys(String propertySetName, short propertySetType, Collection propertyKeys) throws PropertyException
  -    {
  -        Short propertySetTypeObject = new Short(propertySetType);
  -        ArgUtil.notNull(
  -            new Object[] { propertySetName, propertySetTypeObject, propertyKeys },
  -            new String[] { "propertySetName", "propertySetType", "propertyKeys" },
  -            "addPropertyKeys(java.lang.String, short, java.util.Collection)");
  -
  -        PersistenceStore store = getPersistenceStore();
  -        PropertySetDef ppsd =
  -            (PropertySetDef) store.getObjectByQuery(
  -                commonQueries.newPropertySetDefQueryByNameAndType(propertySetName, propertySetTypeObject));
  -        if (null != ppsd)
  -        {
  -            // Create a set of property keys to add to the property set definition.
  -            Collection propertyKeysObj = new ArrayList(propertyKeys.size());
  -            for (Iterator i = propertyKeys.iterator(); i.hasNext();)
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(SYSTEM_NODE_TYPE)));
  +        }
  +        if (null != nodeObj)
  +        {
  +            Collection properties = nodeObj.getNodeProperties();
  +            ArrayList newProperties = new ArrayList(properties.size());
  +            Collection keys = nodeObj.getNodeKeys();
  +            ArrayList newKeys = new ArrayList(keys.size());
  +            for (Iterator i = properties.iterator(); i.hasNext();)
  +            {
  +                Property curProp = (Property) i.next();
  +                PropertyKey curPropKey = (PropertyKey) curProp.getPropertyKey();
  +                if ((null != curPropKey) && (!propertyKeys.contains(curProp.getPropertyKey().getPropertyKeyName())))
  +                {
  +                    newProperties.add(curProp);
  +                }
  +            }
  +            for (Iterator j = newKeys.iterator(); j.hasNext();)
               {
  -                Map currentPropertyKey = (Map) i.next();
  -                PropertyKey ppk =
  -                    new PropertyKeyImpl(
  -                        ppsd.getPropertySetDefId(),
  -                        (String) currentPropertyKey.get(PROPERTYKEY_NAME),
  -                        ((Short) currentPropertyKey.get(PROPERTYKEY_TYPE)).shortValue());
  -                propertyKeysObj.add(ppk);
  +                PropertyKey curPropKey = (PropertyKey) j.next();
  +                if (!propertyKeys.contains(curPropKey.getPropertyKeyName()))
  +                {
  +                    newKeys.add(curPropKey);
  +                }
               }
  -
  -            // Add the properties to the set.
  +            // Remove the properties keys.
               try
               {
  -                store.lockForWrite(ppsd);
  -                ppsd.setPropertyKeys(propertyKeysObj);
  -                ppsd.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  +                store.lockForWrite(nodeObj);
  +                nodeObj.setNodeKeys(newKeys);
  +                nodeObj.setNodeProperties(newProperties);
  +                nodeObj.setModifiedDate(new Timestamp(System.currentTimeMillis()));
                   store.getTransaction().checkpoint();
               }
               catch (LockFailedException lfe)
               {
  -                throw new PropertyException("Unable to lock PropertySetDef for update: " + lfe.toString(), lfe);
  +                throw new PropertyException("Unable to lock Node for update: " + lfe.toString(), lfe);
               }
           }
           else
           {
  -            throw new PropertyException(PropertyException.PROPERTYSET_DEFINITION_NOT_FOUND);
  +            throw new PropertyException(PropertyException.NODE_NOT_FOUND);
           }
       }
   
       /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#removePropertyKeysBySet(int)
  +     * @see org.apache.jetspeed.prefs.PropertyManager#updatePropertyKey(java.lang.String, java.util.prefs.Preferences, java.util.Map)
        */
  -    /*public void removePropertyKeysBySetDef(int propertySetDefId) throws PropertyException
  +    public void updatePropertyKey(String oldPropertyKeyName, Preferences prefNode, Map newPropertyKey) throws PropertyException
       {
  -        Integer propertySetDefIdObject = new Integer(propertySetDefId);
  -    
           ArgUtil.notNull(
  -            new Object[] { propertySetDefIdObject },
  -            new String[] { "propertySetDefId" },
  -            "removePropertyKeysBySet(int)");
  -    
  -        Map propertyKeys = getPropertyKeysBySetDef(propertySetDefId);
  -    
  -        PersistenceStore store = getPersistenceStore();
  -        log.info("\n\n_______________ HERE0_____________\n\n");
  -        try
  -        {
  -            // Remove properties.
  -            if ((null != propertyKeys) && (propertyKeys.size() > 0))
  -            {
  -                log.info("\n\n_______________ HERE1_____________\n\n");
  -    
  -                Filter filter = store.newFilter();
  -                filter.addIn("propertyKeyId", propertyKeys.keySet());
  -                Object query = store.newQuery(PropertyImpl.class, filter);
  -                store.deleteAll(query);
  -            }
  -            // Remove property keys.
  -            store.deleteAll(commonQueries.newPropertyKeyQueryByPropertySetDefId(propertySetDefIdObject));
  -        }
  -        catch (LockFailedException lfe)
  -        {
  -            throw new PropertyException("Unable to remove property keys: " + lfe.toString(), lfe);
  -        }
  -    }
  -    */
  -
  -    /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#getPropertyKeysBySetDef(java.lang.String, short)
  -     */
  -    public Collection getPropertyKeysBySetDef(String propertySetName, short propertySetType) throws PropertyException
  -    {
  -        Short propertySetTypeObject = new Short(propertySetType);
  -        ArgUtil.notNull(
  -            new Object[] { propertySetName, propertySetTypeObject },
  -            new String[] { "propertySetName", "propertySetType" },
  -            "getPropertyKeysBySetDef(java.lang.String, java.lang.String)");
  +            new Object[] { oldPropertyKeyName, prefNode, newPropertyKey },
  +            new String[] { "oldPropertyKeyName", "prefNode", "newPropertyKey" },
  +            "updatePropertyKey(java.lang.String, java.util.prefs.Preferences, java.util.Map)");
   
           PersistenceStore store = getPersistenceStore();
  -        PropertySetDef ppsd =
  -            (PropertySetDef) store.getObjectByQuery(
  -                commonQueries.newPropertySetDefQueryByNameAndType(propertySetName, propertySetTypeObject));
  -        if (null != ppsd)
  -        {
  -            Collection propertyKeys = ppsd.getPropertyKeys();
  -            ArrayList propertyKeyNames = new ArrayList(propertyKeys.size());
  -            for (Iterator i = propertyKeys.iterator(); i.hasNext();)
  -            {
  -                PropertyKey curppk = (PropertyKey) i.next();
  -                propertyKeyNames.add(curppk.getPropertyKeyName());
  -            }
  -            return propertyKeyNames;
  -        }
  -        else
  +        Node nodeObj;
  +        if (prefNode.isUserNode())
           {
  -            throw new PropertyException(PropertyException.PROPERTYSET_DEFINITION_NOT_FOUND);
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(USER_NODE_TYPE)));
           }
  -    }
  -
  -    /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#removePropertyKey(int)
  -     */
  -    public void removePropertyKey(int propertyKeyId) throws PropertyException
  -    {
  -        Integer propertyKeyIdObject = new Integer(propertyKeyId);
  -
  -        ArgUtil.notNull(new Object[] { propertyKeyIdObject }, new String[] { "propertyKeyId" }, "removePropertyKey(int)");
  -
  -        PersistenceStore store = getPersistenceStore();
  -        try
  +        else
           {
  -            // First we remove all property values associated with this key.
  -            store.deleteAll(commonQueries.newPropertyQueryById(propertyKeyIdObject));
  -            // Second we delete the property key.
  -            store.deleteAll(commonQueries.newPropertyKeyQueryById(propertyKeyIdObject));
  +            nodeObj =
  +                (Node) store.getObjectByQuery(
  +                    commonQueries.newNodeQueryByPathAndType(prefNode.absolutePath(), new Short(SYSTEM_NODE_TYPE)));
           }
  -        catch (LockFailedException lfe)
  +        if (null != nodeObj)
           {
  -            throw new PropertyException("Unable to remove property key: " + lfe.toString(), lfe);
  -        }
  -    }
  -
  -    /**
  -     * @see org.apache.jetspeed.prefs.PropertyManager#updatePropertyKey(java.lang.String, java.lang.String, java.lang.String, short)
  -     */
  -    public void updatePropertyKey(
  -        String newPropertyKeyName,
  -        String oldPropertyKeyName,
  -        String propertySetName,
  -        short propertySetType)
  -        throws PropertyException
  -    {
  -        Short propertySetTypeObject = new Short(propertySetType);
  -        ArgUtil.notNull(
  -            new Object[] { newPropertyKeyName, oldPropertyKeyName, propertySetName, propertySetTypeObject },
  -            new String[] { "newPropertyKeyName", "oldPropertyKeyName", "propertySetName", "propertySetType" },
  -            "updatePropertyKey(java.lang.String, java.lang.String, java.lang.String, short)");
  -
  -        PersistenceStore store = getPersistenceStore();
  -        PropertySetDef ppsd =
  -            (PropertySetDef) store.getObjectByQuery(
  -                commonQueries.newPropertySetDefQueryByNameAndType(propertySetName, propertySetTypeObject));
  -        if (null != ppsd)
  -        {
  -            Collection propertyKeys = ppsd.getPropertyKeys();
  -            ArrayList newPropertyKeys = new ArrayList(propertyKeys.size());
  -            for (Iterator i = propertyKeys.iterator(); i.hasNext();)
  +            Collection keys = nodeObj.getNodeKeys();
  +            for (Iterator i = keys.iterator(); i.hasNext();)
               {
  -                PropertyKey curPropertyKey = (PropertyKey) i.next();
  -                if (curPropertyKey.getPropertyKeyName().equals(oldPropertyKeyName))
  +                PropertyKey curPropKey = (PropertyKey) i.next();
  +                if (curPropKey.getPropertyKeyName().equals(oldPropertyKeyName))
                   {
  -                    curPropertyKey.setPropertyKeyName(newPropertyKeyName);
  -                    curPropertyKey.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  +                    for (Iterator j = newPropertyKey.keySet().iterator(); j.hasNext();)
  +                    {
  +                        String newKey = (String) j.next();
  +                        // Update the property key.
  +                        try
  +                        {
  +                            store.lockForWrite(curPropKey);
  +                            curPropKey.setPropertyKeyName(newKey);
  +                            curPropKey.setPropertyKeyType(((Short) newPropertyKey.get(newKey)).shortValue());
  +                            curPropKey.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  +                            if (log.isDebugEnabled())
  +                                log.debug("Updated property key: " + curPropKey.toString());
  +                            store.getTransaction().checkpoint();
  +                        }
  +                        catch (LockFailedException lfe)
  +                        {
  +                            throw new PropertyException("Unable to lock Node for update: " + lfe.toString(), lfe);
  +                        }
  +                    }
                   }
  -                newPropertyKeys.add(curPropertyKey);
  -            }
  -
  -            try
  -            {
  -                store.lockForWrite(ppsd);
  -                ppsd.setPropertyKeys(newPropertyKeys);
  -                ppsd.setModifiedDate(new Timestamp(System.currentTimeMillis()));
  -                store.getTransaction().checkpoint();
  -            }
  -            catch (LockFailedException lfe)
  -            {
  -                throw new PropertyException("Unable to lock PropertyKey for update: " + lfe.toString(), lfe);
               }
           }
           else
           {
  -            throw new PropertyException(PropertyException.PROPERTYSET_DEFINITION_NOT_FOUND);
  +            throw new PropertyException(PropertyException.NODE_NOT_FOUND);
           }
       }
   
  
  
  
  1.2       +6 -6      jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PropertyException.java
  
  Index: PropertyException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PropertyException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertyException.java	26 Feb 2004 04:30:46 -0000	1.1
  +++ PropertyException.java	6 Mar 2004 18:31:01 -0000	1.2
  @@ -25,12 +25,12 @@
   public class PropertyException extends JetspeedException
   {
   
  -    /** Property set definition not found exception message. */
  -    public static final String PROPERTYSET_DEFINITION_NOT_FOUND
  -                        = "The specified property set definition does not exist.";
  -    /** Property set definition already exists exception message. */
  -    public static final String  PROPERTYSET_DEFINITION_ALREADY_EXISTS
  -                        = "The specified property set definition already exists.";
  +    /** Preferences node not found exception message. */
  +    public static final String NODE_NOT_FOUND
  +                        = "The specified preferences node does not exist.";
  +    /** Preferences node already exists exception message. */
  +    public static final String  NODE_ALREADY_EXISTS
  +                        = "The specified preferences node already exists.";
       /** Property key not found exception message. */
       public static final String PROPERTYKEY_NOT_FOUND
                           = "The specified property key does not exist.";
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message