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 03:24:56 UTC
svn commit: r409535 - in
/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core:
./ state/ state/util/ state/xml/ value/
Author: jukka
Date: Thu May 25 18:24:55 2006
New Revision: 409535
URL: http://svn.apache.org/viewvc?rev=409535&view=rev
Log:
1.0: Merged revisions 407709 and 408647: JCR-362 JCR-428
Modified:
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.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=409535&r1=409534&r2=409535&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 18:24:55 2006
@@ -3587,8 +3587,12 @@
NodeIterator niter = getNodes();
while (niter.hasNext()) {
NodeImpl n = (NodeImpl) niter.nextNode();
- // todo: does not work properly for samename siblings
- if (!srcNode.hasNode(n.getQName())) {
+ Path.PathElement name = n.getPrimaryPath().getNameElement();
+ int idx = name.getIndex();
+ if (idx == 0) {
+ idx = 1;
+ }
+ if (!srcNode.hasNode(name.getName(), idx)) {
n.internalRemove(true);
}
}
@@ -3599,21 +3603,29 @@
NodeImpl child = (NodeImpl) niter.nextNode();
NodeImpl dstNode = null;
NodeId childId = child.getNodeId();
- if (hasNode(child.getQName())) {
- // todo: does not work properly for samename siblings
- dstNode = getNode(child.getQName());
- } else if (child.isNodeType(QName.MIX_REFERENCEABLE)) {
- // if child is referenceable, check if correspondance exist in this workspace
+ Path.PathElement name = child.getPrimaryPath().getNameElement();
+ int idx = name.getIndex();
+ if (idx == 0) {
+ idx = 1;
+ }
+
+ if (child.isNodeType(QName.MIX_REFERENCEABLE)) {
+ // check if correspondance exist in
+ // this workspace
try {
dstNode = session.getNodeById(childId);
- if (removeExisting) {
- dstNode.internalRemove(false);
- dstNode = null;
- } else if (replaceExisting) {
- // node exists outside of this update tree, so continue there
- } else {
- throw new ItemExistsException("Unable to update node: " + dstNode.safeGetJCRPath());
+ // check if same parent
+ if (!dstNode.getParent().isSame(srcNode)) {
+ if (removeExisting) {
+ dstNode.internalRemove(false);
+ dstNode = null;
+ } else if (replaceExisting) {
+ // node exists outside of this update tree, so continue there
+ } else {
+ throw new ItemExistsException("Unable to update node: " + dstNode.safeGetJCRPath());
+ }
}
+
} catch (ItemNotFoundException e) {
// does not exist
}
@@ -3621,8 +3633,13 @@
// if child is not referenceable, clear uuid
childId = null;
}
+ if (dstNode == null && hasNode(name.getName(), idx)) {
+ // the exact behaviour for SNS is not specified by the spec
+ // so we just try to find the corresponding one.
+ dstNode = getNode(name.getName(), idx);
+ }
if (dstNode == null) {
- dstNode = internalAddChildNode(child.getQName(), (NodeTypeImpl) child.getPrimaryNodeType(), childId);
+ dstNode = internalAddChildNode(name.getName(), (NodeTypeImpl) child.getPrimaryNodeType(), childId);
// add mixins
NodeType[] mixins = child.getMixinNodeTypes();
for (int i = 0; i < mixins.length; i++) {
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=409535&r1=409534&r2=409535&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java Thu May 25 18:24:55 2006
@@ -293,10 +293,9 @@
for (int i = 0; i < oldValues.length; i++) {
InternalValue old = oldValues[i];
if (old != null && old.getType() == PropertyType.BINARY) {
- // BINARY value
- BLOBFileValue blob = (BLOBFileValue) old.internalValue();
- blob.discard();
- blob = null; // gc hint
+ // make sure temporarily allocated data is discarded
+ // before overwriting it
+ ((BLOBFileValue) old.internalValue()).discard();
}
}
}
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java?rev=409535&r1=409534&r2=409535&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java Thu May 25 18:24:55 2006
@@ -324,7 +324,7 @@
public void close() {
// nop
}
- });
+ }, false);
} else {
values[i] = InternalValue.valueOf(in.readUTF(), type);
}
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java?rev=409535&r1=409534&r2=409535&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java Thu May 25 18:24:55 2006
@@ -218,7 +218,7 @@
} else {
in = blobStore.get(blobId);
try {
- values[i] = InternalValue.create(in);
+ values[i] = InternalValue.create(in, false);
} finally {
try {
in.close();
@@ -291,7 +291,7 @@
} else {
InputStream is = blobStore.get(s);
try {
- val = InternalValue.create(is);
+ val = InternalValue.create(is, false);
} finally {
try {
is.close();
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java?rev=409535&r1=409534&r2=409535&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java Thu May 25 18:24:55 2006
@@ -321,7 +321,7 @@
} else {
InputStream in = blobStore.get(content);
try {
- values.add(InternalValue.create(in));
+ values.add(InternalValue.create(in, false));
} finally {
try {
in.close();
@@ -660,7 +660,7 @@
} else {
in = blobStore.get(blobId);
try {
- values[i] = InternalValue.create(in);
+ values[i] = InternalValue.create(in, false);
} finally {
try {
in.close();
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=409535&r1=409534&r2=409535&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java Thu May 25 18:24:55 2006
@@ -82,7 +82,9 @@
private final File file;
/**
- * flag indicating if this instance is backed by a temporarily allocated resource/buffer
+ * flag indicating if this instance represents a <i>temporary</i> value
+ * whose dynamically allocated resources can be explicitly freed on
+ * {@link #discard()}.
*/
private final boolean temp;
@@ -106,12 +108,37 @@
* <code>InputStream</code>. The contents of the stream is spooled
* to a temporary file or to a byte buffer if its size is smaller than
* {@link #MAX_BUFFER_SIZE}.
+ * <p/>
+ * The new instance represents a <i>temporary</i> value whose dynamically
+ * allocated resources will be freed explicitly on {@link #discard()}.
*
* @param in stream to be represented as a <code>BLOBFileValue</code> instance
* @throws IOException if an error occurs while reading from the stream or
* writing to the temporary file
*/
public BLOBFileValue(InputStream in) throws IOException {
+ this(in, true);
+ }
+
+ /**
+ * Creates a new <code>BLOBFileValue</code> instance from an
+ * <code>InputStream</code>. The contents of the stream is spooled
+ * to a temporary file or to a byte buffer if its size is smaller than
+ * {@link #MAX_BUFFER_SIZE}.
+ * <p/>
+ * The <code>temp</code> parameter governs whether dynamically allocated
+ * resources will be freed explicitly on {@link #discard()}. Note that any
+ * dynamically allocated resources (temp file/buffer) will be freed
+ * implicitly once this instance has been gc'ed.
+ *
+ * @param in stream to be represented as a <code>BLOBFileValue</code> instance
+ * @param temp flag indicating whether this instance represents a
+ * <i>temporary</i> value whose resources can be explicitly freed
+ * on {@link #discard()}.
+ * @throws IOException if an error occurs while reading from the stream or
+ * writing to the temporary file
+ */
+ public BLOBFileValue(InputStream in, boolean temp) throws IOException {
byte[] spoolBuffer = new byte[0x2000];
int read;
int len = 0;
@@ -151,8 +178,7 @@
// init vars
file = spoolFile;
fsResource = null;
- // this instance is backed by a temporarily allocated resource/buffer
- temp = true;
+ this.temp = temp;
}
/**
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=409535&r1=409534&r2=409535&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java Thu May 25 18:24:55 2006
@@ -234,6 +234,16 @@
/**
* @param value
+ * @param temp
+ * @return
+ * @throws IOException
+ */
+ public static InternalValue create(InputStream value, boolean temp) throws IOException {
+ return new InternalValue(new BLOBFileValue(value, temp));
+ }
+
+ /**
+ * @param value
* @return
* @throws IOException
*/