You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by tr...@apache.org on 2013/11/16 00:52:50 UTC
svn commit: r1542431 - in /jackrabbit/oak/trunk:
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
oak-jcr/pom.xml
Author: tripod
Date: Fri Nov 15 23:52:49 2013
New Revision: 1542431
URL: http://svn.apache.org/r1542431
Log:
OAK-1194 Missing properties in Node.getReferences()
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
jackrabbit/oak/trunk/oak-jcr/pom.xml
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java?rev=1542431&r1=1542430&r2=1542431&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java Fri Nov 15 23:52:49 2013
@@ -18,19 +18,17 @@ package org.apache.jackrabbit.oak.plugin
import java.text.ParseException;
import java.util.Collections;
+import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Set;
import java.util.UUID;
+
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.jcr.PropertyType;
import javax.jcr.query.Query;
-import com.google.common.base.Charsets;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.PropertyValue;
@@ -47,6 +45,11 @@ import org.apache.jackrabbit.oak.spi.que
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Charsets;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.oak.api.Type.STRING;
@@ -198,17 +201,9 @@ public class IdentifierManager {
"SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference + "') = $uuid",
Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, new NamePathMapper.Default());
- Iterable<String> paths = Iterables.transform(result.getRows(),
- new Function<ResultRow, String>() {
- @Override
- public String apply(ResultRow row) {
- String pName = propertyName == null
- ? findProperty(row.getPath(), uuid)
- : propertyName;
- return PathUtils.concat(row.getPath(), pName);
- }
- });
+ Iterable<String> paths = new ReferencePropertyIterable(result, uuid);
+ // todo: integrate into ReferencePropertyIterable
if (nodeTypeNames.length > 0) {
paths = Iterables.filter(paths, new Predicate<String>() {
@Override
@@ -233,25 +228,85 @@ public class IdentifierManager {
}
}
- private String findProperty(String path, final String uuid) {
- Tree tree = root.getTree(path);
- final PropertyState refProp = Iterables.find(tree.getProperties(), new Predicate<PropertyState>() {
- @Override
- public boolean apply(PropertyState pState) {
- if (pState.isArray()) {
- for (String value : pState.getValue(Type.STRINGS)) {
- if (uuid.equals(value)) {
- return true;
- }
+ private class ReferencePropertyIterable implements Iterable<String> {
+
+ private final Result result;
+
+ private final String uuid;
+
+ private ReferencePropertyIterable(Result result, String uuid) {
+ this.result = result;
+ this.uuid = uuid;
+ }
+
+ @Override
+ public Iterator<String> iterator() {
+
+ return new Iterator<String>() {
+
+ private final Iterator<? extends ResultRow> rows = result.getRows().iterator();
+
+ private Iterator<? extends PropertyState> iter;
+
+ private boolean sought;
+
+ private String rowPath;
+
+ private String next;
+
+ @Override
+ public boolean hasNext() {
+ if (!sought) {
+ seek();
+ sought = true;
}
- return false;
- } else {
- return uuid.equals(pState.getValue(STRING));
+ return next != null;
+ }
+
+ @Override
+ public String next() {
+ if (!sought) {
+ seek();
+ sought = true;
+ }
+ if (next == null) {
+ throw new NoSuchElementException();
+ }
+ sought = false;
+ return next;
}
- }
- });
- return refProp.getName();
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private void seek() {
+ for (next = null; next == null;) {
+ if (iter != null && iter.hasNext()) {
+ PropertyState pState = iter.next();
+ if (pState.isArray()) {
+ for (String value : pState.getValue(Type.STRINGS)) {
+ if (uuid.equals(value)) {
+ next = PathUtils.concat(rowPath, pState.getName());
+ break;
+ }
+ }
+ } else if (uuid.equals(pState.getValue(STRING))) {
+ next = PathUtils.concat(rowPath, pState.getName());
+ }
+
+ } else {
+ if (!rows.hasNext()) {
+ break;
+ }
+ rowPath = rows.next().getPath();
+ iter = root.getTree(rowPath).getProperties().iterator();
+ }
+ }
+ }
+ };
+ }
}
@CheckForNull
Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1542431&r1=1542430&r2=1542431&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Fri Nov 15 23:52:49 2013
@@ -50,11 +50,9 @@
org.apache.jackrabbit.test.api.WorkspaceMoveSameNameSibsTest#testMoveNodesOrderingSupportedByParent <!-- OAK-118 -->
org.apache.jackrabbit.test.api.WorkspaceMoveTest#testMoveNodesLocked <!-- OAK-118 -->
- org.apache.jackrabbit.oak.jcr.ReferencesTest#testMultipleReferencesOnSameNode <!-- OAK-1194 -->
- org.apache.jackrabbit.oak.jcr.ReferencesTest#testVersionReferencesV0 <!-- OAK-1194 -->
- org.apache.jackrabbit.oak.jcr.ReferencesTest#testVersionReferencesV1 <!-- OAK-1194 -->
org.apache.jackrabbit.oak.jcr.ReferencesTest#testMovedReferences <!-- OAK-1195 -->
org.apache.jackrabbit.oak.jcr.ReferencesTest#testMovedVersionedReferences <!-- OAK-1195 -->
+ org.apache.jackrabbit.oak.jcr.ReferencesTest#testVersionReferencesV1 <!-- OAK-1196 -->
org.apache.jackrabbit.oak.jcr.ReferencesTest#testVersionedReferences <!-- OAK-1196 -->
<!-- Locking : not fully implemented -->