You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2006/05/26 02:55:54 UTC
svn commit: r409532 -
/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Author: jukka
Date: Thu May 25 17:55:54 2006
New Revision: 409532
URL: http://svn.apache.org/viewvc?rev=409532&view=rev
Log:
1.0: Merged revision 393020: JCR-336
Modified:
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=409532&r1=409531&r2=409532&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Thu May 25 17:55:54 2006
@@ -423,22 +423,41 @@
throws ConstraintViolationException, RepositoryException {
status.clear();
- NodeState thisState = (NodeState) state;
- if (thisState.hasPropertyName(name)) {
- /**
- * the following call will throw ItemNotFoundException if the
- * current session doesn't have read access
- */
- return getProperty(name);
- }
+ /*
+ * Please note, that this implementation does not win a price for beauty
+ * or speed. It's never a good idea to use exceptions for semantical
+ * control flow.
+ * However, compared to the previous version, this one is thread save
+ * and makes the test/get block atomic in respect to transactional
+ * commits. the test/set can still fail.
+ *
+ * Old Version:
+
+ NodeState thisState = (NodeState) state;
+ if (thisState.hasPropertyName(name)) {
+ /**
+ * the following call will throw ItemNotFoundException if the
+ * current session doesn't have read access
+ /
+ return getProperty(name);
+ }
+ [...create block...]
- // does not exist yet:
- // find definition for the specified property and create property
- PropertyDefinitionImpl def = getApplicablePropertyDefinition(
- name, type, multiValued, exactTypeMatch);
- PropertyImpl prop = createChildProperty(name, type, def);
- status.set(CREATED);
- return prop;
+ */
+ try {
+ PropertyId propId = new PropertyId(getNodeId(), name);
+ return (PropertyImpl) itemMgr.getItem(propId);
+ } catch (AccessDeniedException ade) {
+ throw new ItemNotFoundException(name.toString());
+ } catch (ItemNotFoundException e) {
+ // does not exist yet:
+ // find definition for the specified property and create property
+ PropertyDefinitionImpl def = getApplicablePropertyDefinition(
+ name, type, multiValued, exactTypeMatch);
+ PropertyImpl prop = createChildProperty(name, type, def);
+ status.set(CREATED);
+ return prop;
+ }
}
protected synchronized PropertyImpl createChildProperty(QName name, int type,
@@ -3920,12 +3939,15 @@
LockManager lockMgr = session.getLockManager();
synchronized (lockMgr) {
- lockMgr.unlock(this);
+ if (lockMgr.holdsLock(this)) {
+ // save first, and unlock later. this guards concurrent access
- // remove properties in content
- internalSetProperty(QName.JCR_LOCKOWNER, (InternalValue) null);
- internalSetProperty(QName.JCR_LOCKISDEEP, (InternalValue) null);
- save();
+ // remove properties in content
+ internalSetProperty(QName.JCR_LOCKOWNER, (InternalValue) null);
+ internalSetProperty(QName.JCR_LOCKISDEEP, (InternalValue) null);
+ save();
+ }
+ lockMgr.unlock(this);
}
}