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 th...@apache.org on 2013/02/21 09:21:55 UTC
svn commit: r1448538 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index:
IndexDefinitionImpl.java IndexHookManager.java IndexHookManagerDiff.java
p2/Property2IndexDiff.java p2/Property2IndexLookup.java
Author: thomasm
Date: Thu Feb 21 08:21:55 2013
New Revision: 1448538
URL: http://svn.apache.org/r1448538
Log:
OAK-511 Query PropertyIndex (rename fields / parameters / variables)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java?rev=1448538&r1=1448537&r2=1448538&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java Thu Feb 21 08:21:55 2013
@@ -21,19 +21,19 @@ package org.apache.jackrabbit.oak.plugin
*/
public class IndexDefinitionImpl implements IndexDefinition, IndexConstants {
- private final String name;
+ private final String indexName;
private final String type;
private final String path;
public IndexDefinitionImpl(String name, String type, String path) {
- this.name = name;
+ this.indexName = name;
this.type = type;
this.path = path;
}
@Override
public String getName() {
- return name;
+ return indexName;
}
@Override
@@ -48,7 +48,7 @@ public class IndexDefinitionImpl impleme
@Override
public String toString() {
- return "IndexDefinitionImpl [name=" + name + ", type=" + type
+ return "IndexDefinitionImpl [name=" + indexName + ", type=" + type
+ ", path=" + path + "]";
}
@@ -56,7 +56,7 @@ public class IndexDefinitionImpl impleme
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((indexName == null) ? 0 : indexName.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
@@ -71,10 +71,10 @@ public class IndexDefinitionImpl impleme
if (getClass() != obj.getClass())
return false;
IndexDefinitionImpl other = (IndexDefinitionImpl) obj;
- if (name == null) {
- if (other.name != null)
+ if (indexName == null) {
+ if (other.indexName != null)
return false;
- } else if (!name.equals(other.name))
+ } else if (!indexName.equals(other.indexName))
return false;
if (path == null) {
if (other.path != null)
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java?rev=1448538&r1=1448537&r2=1448538&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java Thu Feb 21 08:21:55 2013
@@ -54,27 +54,28 @@ public class IndexHookManager implements
throws CommitFailedException {
NodeBuilder builder = after.builder();
- // <type, <path, indexhook>>
- Map<String, Map<String, List<IndexHook>>> updates = new HashMap<String, Map<String, List<IndexHook>>>();
+ // key: index type
+ // value: map of path to indexhook
+ Map<String, Map<String, List<IndexHook>>> indexMap = new HashMap<String, Map<String, List<IndexHook>>>();
after.compareAgainstBaseState(before, new IndexHookManagerDiff(
- provider, builder, updates));
- apply(updates);
+ provider, builder, indexMap));
+ apply(indexMap);
return builder.getNodeState();
}
- private void apply(Map<String, Map<String, List<IndexHook>>> updates)
+ private void apply(Map<String, Map<String, List<IndexHook>>> indexMap)
throws CommitFailedException {
try {
- for (String type : updates.keySet()) {
- for (List<IndexHook> hooks : updates.get(type).values()) {
+ for (String type : indexMap.keySet()) {
+ for (List<IndexHook> hooks : indexMap.get(type).values()) {
for (IndexHook hook : hooks) {
hook.apply();
}
}
}
} finally {
- for (String type : updates.keySet()) {
- for (List<IndexHook> hooks : updates.get(type).values()) {
+ for (String type : indexMap.keySet()) {
+ for (List<IndexHook> hooks : indexMap.get(type).values()) {
for (IndexHook hook : hooks) {
try {
hook.close();
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java?rev=1448538&r1=1448537&r2=1448538&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java Thu Feb 21 08:21:55 2013
@@ -64,7 +64,7 @@ class IndexHookManagerDiff implements No
private final NodeBuilder node;
- private final String name;
+ private final String nodeName;
private String path;
@@ -82,22 +82,22 @@ class IndexHookManagerDiff implements No
}
private IndexHookManagerDiff(IndexHookProvider provider,
- IndexHookManagerDiff parent, String name)
+ IndexHookManagerDiff parent, String nodeName)
throws CommitFailedException {
- this(provider, parent, getChildNode(parent.node, name), name, null,
+ this(provider, parent, getChildNode(parent.node, nodeName), nodeName, null,
parent.indexMap);
}
private IndexHookManagerDiff(IndexHookProvider provider,
IndexHookManagerDiff parent, NodeBuilder node, String name,
- String path, Map<String, Map<String, List<IndexHook>>> updates)
+ String path, Map<String, Map<String, List<IndexHook>>> indexMap)
throws CommitFailedException {
this.provider = provider;
this.parent = parent;
this.node = node;
- this.name = name;
+ this.nodeName = name;
this.path = path;
- this.indexMap = updates;
+ this.indexMap = indexMap;
if (node != null && isIndexNodeType(node.getProperty(JCR_PRIMARYTYPE))) {
// to prevent double-reindex we only call reindex if:
@@ -179,9 +179,9 @@ class IndexHookManagerDiff implements No
}
}
- private static NodeBuilder getChildNode(NodeBuilder node, String name) {
- if (node != null && node.hasChildNode(name)) {
- return node.child(name);
+ private static NodeBuilder getChildNode(NodeBuilder node, String nodeName) {
+ if (node != null && node.hasChildNode(nodeName)) {
+ return node.child(nodeName);
} else {
return null;
}
@@ -190,7 +190,7 @@ class IndexHookManagerDiff implements No
private String getPath() {
if (path == null) {
// => parent != null
- path = concat(parent.getPath(), name);
+ path = concat(parent.getPath(), nodeName);
}
return path;
}
@@ -217,6 +217,8 @@ class IndexHookManagerDiff implements No
/**
* Returns IndexHooks of the given type that have the best match (are
* situated the closest on the hierarchy) for the current path.
+ *
+ * @param type the index type ("p2")
*/
private Map<String, List<IndexHook>> getIndexes(String type) {
Map<String, List<IndexHook>> hooks = new HashMap<String, List<IndexHook>>();
@@ -294,20 +296,20 @@ class IndexHookManagerDiff implements No
}
@Override
- public void childNodeAdded(String name, NodeState after) {
- childNodeChanged(name, MemoryNodeState.EMPTY_NODE, after);
+ public void childNodeAdded(String nodeName, NodeState after) {
+ childNodeChanged(nodeName, MemoryNodeState.EMPTY_NODE, after);
}
@Override
- public void childNodeChanged(String name, NodeState before, NodeState after) {
- if (NodeStateUtils.isHidden(name)) {
+ public void childNodeChanged(String nodeName, NodeState before, NodeState after) {
+ if (NodeStateUtils.isHidden(nodeName)) {
return;
}
- getIndexesWithRelativePaths(concat(getPath(), name), getIndexes());
+ getIndexesWithRelativePaths(concat(getPath(), nodeName), getIndexes());
try {
after.compareAgainstBaseState(before, new IndexHookManagerDiff(
- provider, this, name));
+ provider, this, nodeName));
} catch (CommitFailedException e) {
// TODO ignore exception - is this a hack?
LOG.error(e.getMessage(), e);
@@ -315,7 +317,7 @@ class IndexHookManagerDiff implements No
}
@Override
- public void childNodeDeleted(String name, NodeState before) {
- childNodeChanged(name, before, MemoryNodeState.EMPTY_NODE);
+ public void childNodeDeleted(String nodeName, NodeState before) {
+ childNodeChanged(nodeName, before, MemoryNodeState.EMPTY_NODE);
}
}
\ No newline at end of file
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java?rev=1448538&r1=1448537&r2=1448538&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java Thu Feb 21 08:21:55 2013
@@ -74,7 +74,7 @@ class Property2IndexDiff implements Inde
/**
* The node name (the path element). Null for the root node.
*/
- private final String name;
+ private final String nodeName;
/**
* The path of the changed node (built lazily).
@@ -93,20 +93,20 @@ class Property2IndexDiff implements Inde
new HashMap<String, List<Property2IndexUpdate>>());
}
- private Property2IndexDiff(Property2IndexDiff parent, String name) {
- this(parent, getChildNode(parent.node, name),
- name, null, parent.indexMap);
+ private Property2IndexDiff(Property2IndexDiff parent, String nodeName) {
+ this(parent, getChildNode(parent.node, nodeName),
+ nodeName, null, parent.indexMap);
}
private Property2IndexDiff(
Property2IndexDiff parent,
- NodeBuilder node, String name, String path,
- Map<String, List<Property2IndexUpdate>> updates) {
+ NodeBuilder node, String nodeName, String path,
+ Map<String, List<Property2IndexUpdate>> indexMap) {
this.parent = parent;
this.node = node;
- this.name = name;
+ this.nodeName = nodeName;
this.path = path;
- this.indexMap = updates;
+ this.indexMap = indexMap;
if (node != null && node.hasChildNode(INDEX_DEFINITIONS_NAME)) {
NodeBuilder index = node.child(INDEX_DEFINITIONS_NAME);
@@ -131,7 +131,7 @@ class Property2IndexDiff implements Inde
public String getPath() {
// build the path lazily
if (path == null) {
- path = concat(parent.getPath(), name);
+ path = concat(parent.getPath(), nodeName);
}
return path;
}
@@ -139,11 +139,11 @@ class Property2IndexDiff implements Inde
/**
* Get all the indexes for the given property name.
*
- * @param name the property name
+ * @param propertyName the property name
* @return the indexes
*/
- private Iterable<Property2IndexUpdate> getIndexes(String name) {
- List<Property2IndexUpdate> indexes = indexMap.get(name);
+ private Iterable<Property2IndexUpdate> getIndexes(String propertyName) {
+ List<Property2IndexUpdate> indexes = indexMap.get(propertyName);
if (indexes == null) {
return ImmutableList.of();
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java?rev=1448538&r1=1448537&r2=1448538&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java Thu Feb 21 08:21:55 2013
@@ -69,19 +69,19 @@ public class Property2IndexLookup {
* path. Lookup starts at the current path (at the root of this object) and
* traverses down the path.
*
- * @param name property name
+ * @param propertyName property name
* @param path lookup path
* @return true if the property is indexed
*/
- public boolean isIndexed(String name, String path) {
- return isIndexed(root, name, path);
+ public boolean isIndexed(String propertyName, String path) {
+ return isIndexed(root, propertyName, path);
}
- private static boolean isIndexed(NodeState root, String name, String path) {
+ private static boolean isIndexed(NodeState root, String propertyName, String path) {
NodeState node = root;
Iterator<String> it = PathUtils.elements(path).iterator();
while (true) {
- if (getIndexDataNode(node, name) != null) {
+ if (getIndexDataNode(node, propertyName) != null) {
return true;
}
if (!it.hasNext()) {
@@ -92,13 +92,13 @@ public class Property2IndexLookup {
return false;
}
- public Iterable<String> query(Filter filter, String name, PropertyValue value) {
- NodeState state = getIndexDataNode(root, name);
+ public Iterable<String> query(Filter filter, String propertyName, PropertyValue value) {
+ NodeState state = getIndexDataNode(root, propertyName);
if (state == null) {
- throw new IllegalArgumentException("No index for " + name);
+ throw new IllegalArgumentException("No index for " + propertyName);
}
List<String> values = value == null ? null : Property2Index.encode(value);
- return store.query(filter, name, state, values);
+ return store.query(filter, propertyName, state, values);
}
public double getCost(String name, PropertyValue value) {
@@ -114,12 +114,12 @@ public class Property2IndexLookup {
* Get the node with the index data for the given property, if there is an
* applicable index with data.
*
- * @param name the property name
+ * @param propertyName the property name
* @return the node where the index data is stored, or null if no index
* definition or index data node was found
*/
@Nullable
- private static NodeState getIndexDataNode(NodeState node, String name) {
+ private static NodeState getIndexDataNode(NodeState node, String propertyName) {
NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME);
if (state != null) {
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
@@ -130,7 +130,7 @@ public class Property2IndexLookup {
PropertyState names = entry.getNodeState().getProperty("propertyNames");
if (names != null) {
for (int i = 0; i < names.count(); i++) {
- if (name.equals(names.getValue(Type.STRING, i))) {
+ if (propertyName.equals(names.getValue(Type.STRING, i))) {
NodeState indexDef = entry.getNodeState();
NodeState index = indexDef.getChildNode(":index");
if (index != null) {