jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r105832 - incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core
Date Fri, 19 Nov 2004 16:55:18 GMT
Author: stefan
Date: Fri Nov 19 08:55:15 2004
New Revision: 105832

Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
Log:
oops, fix introduced new bug, reverting to previous state

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemManager.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemManager.java	Fri Nov
19 08:55:15 2004
@@ -24,9 +24,7 @@
 import javax.jcr.nodetype.NodeDef;
 import javax.jcr.nodetype.PropertyDef;
 import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
 
 /**
  * There's one <code>ItemManager</code> instance per <code>Session</code>
@@ -45,7 +43,7 @@
  * <code>Node</code> or <code>Property</code> associated with the
same
  * <code>Session</code> instance.
  * <li>maintaining a cache of the item instances it created.
- * <li>respecting access rights of associated <code>Session</code> in all
methods.
+ * <li>checking access rights of associated <code>Session</code> in all
methods.
  * </ul>
  * <p/>
  * If the parent <code>Session</code> is an <code>XASession</code>,
there is
@@ -145,96 +143,36 @@
 
     //--------------------------------------------------< item access methods >
     /**
-     * Checks if the item with the given path exists.
-     *
-     * @param path path to the item to be checked
-     * @return true if the specified item exists
+     * @param path
+     * @return
      */
     boolean itemExists(Path path) {
-/*
         try {
             getItem(path);
             return true;
         } catch (PathNotFoundException pnfe) {
             return false;
         } catch (AccessDeniedException ade) {
-            // item exists but the session has not been granted read access
-            return false;
-        } catch (RepositoryException re) {
-            return false;
-        }
-*/
-        try {
-            // check sanity of session
-            session.sanityCheck();
-
-            ItemId id = hierMgr.resolvePath(path);
-
-            // check if state exists for the given item
-            if (!itemStateProvider.hasItemState(id)) {
-                return false;
-            }
-
-            // check privileges
-            if (!session.getAccessManager().isGranted(id, AccessManager.READ)) {
-                // clear cache
-                if (isCached(id)) {
-                    evictItem(id);
-                }
-                // item exists but the session has not been granted read access
-                return false;
-            }
             return true;
-        } catch (PathNotFoundException pnfe) {
-            return false;
-        } catch (ItemNotFoundException infe) {
-            return false;
         } catch (RepositoryException re) {
             return false;
         }
     }
 
     /**
-     * Checks if the item with the given id exists.
+     * Checks if the item with the given id exists
      *
-     * @param id id of the item to be checked
-     * @return true if the specified item exists
+     * @param id
+     * @return
      */
     boolean itemExists(ItemId id) {
-/*
         try {
             getItem(id);
             return true;
         } catch (ItemNotFoundException infe) {
             return false;
         } catch (AccessDeniedException ade) {
-            // item exists but the session has not been granted read access
-            return false;
-        } catch (RepositoryException re) {
-            return false;
-        }
-*/
-        try {
-            // check sanity of session
-            session.sanityCheck();
-
-            // check if state exists for the given item
-            if (!itemStateProvider.hasItemState(id)) {
-                return false;
-            }
-
-            // check privileges
-            if (!session.getAccessManager().isGranted(id, AccessManager.READ)) {
-                // clear cache
-                if (isCached(id)) {
-                    evictItem(id);
-                }
-                // item exists but the session has not been granted read access
-                return false;
-            }
             return true;
-        } catch (ItemNotFoundException infe) {
-            return false;
         } catch (RepositoryException re) {
             return false;
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java	Fri Nov 19
08:55:15 2004
@@ -45,9 +45,6 @@
 
     protected NodeDef definition;
 
-    // flag set in status passed to getOrCreateProperty if property was created
-    protected static final short CREATED = 0;
-
     /**
      * Package private constructor.
      *
@@ -167,10 +164,15 @@
         return genValues;
     }
 
-    protected PropertyImpl getOrCreateProperty(String name, int type,
-                                               boolean multiValued,
-                                               BitSet status)
+    protected PropertyImpl getOrCreateProperty(String name, int type, boolean multiValued)
             throws RepositoryException {
+        try {
+            return (PropertyImpl) getProperty(name);
+        } catch (PathNotFoundException pnfe) {
+            // fall through
+        }
+
+        // property does not exist yet...
         QName qName;
         try {
             qName = QName.fromJCRName(name, session.getNamespaceResolver());
@@ -179,25 +181,21 @@
         } catch (UnknownPrefixException upe) {
             throw new RepositoryException("invalid property name: " + name, upe);
         }
-        return getOrCreateProperty(qName, type, multiValued, status);
+        // find definition for the specified property and create property
+        PropertyDefImpl def = getApplicablePropertyDef(qName, type, multiValued);
+        return createChildProperty(qName, type, def);
     }
 
-    protected synchronized PropertyImpl getOrCreateProperty(QName name, int type,
-                                                            boolean multiValued,
-                                                            BitSet status)
+    protected PropertyImpl getOrCreateProperty(QName name, int type, boolean multiValued)
             throws RepositoryException {
-        status.clear();
-
-        PropertyId propId = new PropertyId(((NodeState) state).getUUID(), name);
-        if (itemMgr.itemExists(propId)) {
-            return getProperty(name);
+        try {
+            return (PropertyImpl) getProperty(name);
+        } catch (ItemNotFoundException e) {
+            // does not exist yet:
+            // find definition for the specified property and create property
+            PropertyDefImpl def = getApplicablePropertyDef(name, type, multiValued);
+            return createChildProperty(name, type, def);
         }
-        // does not exist yet:
-        // find definition for the specified property and create property
-        PropertyDefImpl def = getApplicablePropertyDef(name, type, multiValued);
-        PropertyImpl prop = createChildProperty(name, type, def);
-        status.set(CREATED);
-        return prop;
     }
 
     protected synchronized PropertyImpl createChildProperty(QName name, int type, PropertyDefImpl
def)
@@ -321,19 +319,6 @@
         return (NodeImpl) itemMgr.getItem(targetId);
     }
 
-
-    protected void removeChildProperty(String propName) throws RepositoryException {
-        QName qName;
-        try {
-            qName = QName.fromJCRName(propName, session.getNamespaceResolver());
-        } catch (IllegalNameException ine) {
-            throw new RepositoryException("invalid property name: " + propName, ine);
-        } catch (UnknownPrefixException upe) {
-            throw new RepositoryException("invalid property name: " + propName, upe);
-        }
-        removeChildProperty(qName);
-    }
-
     protected void removeChildProperty(QName propName) throws RepositoryException {
         // modify the state of 'this', i.e. the parent node
         NodeState thisState = (NodeState) getOrCreateTransientItemState();
@@ -704,22 +689,11 @@
         } else {
             type = value.getType();
         }
-
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, type, false, status);
-        try {
-            if (value == null) {
-                prop.internalSetValue((InternalValue[]) null, type);
-            } else {
-                prop.internalSetValue(new InternalValue[]{value}, type);
-            }
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
+        PropertyImpl prop = getOrCreateProperty(name, type, false);
+        if (value == null) {
+            prop.internalSetValue((InternalValue[]) null, type);
+        } else {
+            prop.internalSetValue(new InternalValue[]{value}, type);
         }
         return prop;
     }
@@ -748,19 +722,8 @@
         } else {
             type = values[0].getType();
         }
-
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, type, true, status);
-        try {
-            prop.internalSetValue(values, type);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, type, true);
+        prop.internalSetValue(values, type);
         return prop;
     }
 
@@ -936,18 +899,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.NAME, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.NAME, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -966,18 +919,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.NAME, true, status);
-        try {
-            prop.setValue(values);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.NAME, true);
+        prop.setValue(values);
         return prop;
     }
 
@@ -1003,18 +946,8 @@
         } else {
             type = values[0].getType();
         }
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, type, true, status);
-        try {
-            prop.setValue(values);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, type, true);
+        prop.setValue(values);
         return prop;
     }
 
@@ -1035,19 +968,8 @@
         sanityCheck();
 
         int type = (value == null) ? PropertyType.STRING : value.getType();
-
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, type, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, type, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1282,19 +1204,8 @@
         } else {
             type = values[0].getType();
         }
-
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, type, true, status);
-        try {
-            prop.setValue(values);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, type, true);
+        prop.setValue(values);
         return prop;
     }
 
@@ -1306,18 +1217,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.STRING, true, status);
-        try {
-            prop.setValue(values);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.STRING, true);
+        prop.setValue(values);
         return prop;
     }
 
@@ -1328,18 +1229,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.STRING, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.STRING, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1352,19 +1243,8 @@
         sanityCheck();
 
         int type = (value == null) ? PropertyType.STRING : value.getType();
-
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, type, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, type, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1376,18 +1256,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.BINARY, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.BINARY, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1399,18 +1269,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.BOOLEAN, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.BOOLEAN, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1422,18 +1282,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.DOUBLE, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.DOUBLE, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1445,18 +1295,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.LONG, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.LONG, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1468,18 +1308,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.DATE, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.DATE, false);
+        prop.setValue(value);
         return prop;
     }
 
@@ -1491,18 +1321,8 @@
         // check state of this instance
         sanityCheck();
 
-        BitSet status = new BitSet();
-        PropertyImpl prop = getOrCreateProperty(name, PropertyType.REFERENCE, false, status);
-        try {
-            prop.setValue(value);
-        } catch (RepositoryException re) {
-            if (status.get(CREATED)) {
-                // setting value failed, get rid of newly created property
-                removeChildProperty(name);
-            }
-            // rethrow
-            throw re;
-        }
+        PropertyImpl prop = getOrCreateProperty(name, PropertyType.REFERENCE, false);
+        prop.setValue(value);
         return prop;
     }
 

Mime
View raw message