Refactor table wrapper names to avoid confusion

This commit is contained in:
Michael Lieberman
2015-01-26 10:19:56 -05:00
parent 53f7ed4025
commit 49a5a77d1d
16 changed files with 98 additions and 67 deletions

View File

@@ -79,7 +79,7 @@ public class AccumuloEdge extends AccumuloElement implements Edge {
Map<String, Object> props = globals.getEdgeWrapper()
.readProperties(this);
for (String key : props.keySet()) {
globals.getEdgeIndexWrapper().removePropertyFromIndex(this,
globals.getEdgeKeyIndexWrapper().removePropertyFromIndex(this,
key, props.get(key));
}

View File

@@ -86,7 +86,7 @@ public abstract class AccumuloElement implements Element {
@Override
public void setProperty(String key, Object value) {
makeCache();
globals.getKeyIndexWrapper(type).setPropertyForIndex(this, key, value);
globals.getIndexValuesWrapper(type).setPropertyForIndex(this, key, value);
// MDL 31 Dec 2014: The above calls getProperty, so this
// order is important (for now).
globals.getElementWrapper(type).writeProperty(this, key, value);
@@ -118,7 +118,7 @@ public abstract class AccumuloElement implements Element {
globals.getElementWrapper(type).clearProperty(this, key);
globals.checkedFlush();
}
globals.getKeyIndexWrapper(type).removePropertyFromIndex(this, key, value);
globals.getIndexValuesWrapper(type).removePropertyFromIndex(this, key, value);
// MDL 31 Dec 2014: AccumuloGraph.removeProperty
// calls getProperty which populates the cache.
// So the order here is important (for now).

View File

@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.BatchDeleter;
import org.apache.accumulo.core.client.BatchScanner;
@@ -51,7 +52,7 @@ import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import edu.jhuapl.tinkerpop.cache.ElementCaches;
import edu.jhuapl.tinkerpop.tables.VertexIndexTableWrapper;
import edu.jhuapl.tinkerpop.tables.keyindex.VertexKeyIndexTableWrapper;
/**
* This is an implementation of the TinkerPop Blueprints 2.6 API using
@@ -171,7 +172,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
/**
* @deprecated This is used in a unit test that
* needs to be updated to work with
* {@link VertexIndexTableWrapper}.
* {@link VertexKeyIndexTableWrapper}.
* @return
*/
@Deprecated
@@ -400,7 +401,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
public Iterable<Vertex> getVertices(String key, Object value) {
AccumuloGraphUtils.validateProperty(key, value);
if (globals.getConfig().getAutoIndex() || getIndexedKeys(Vertex.class).contains(key)) {
return globals.getVertexIndexWrapper().getVertices(key, value);
return globals.getVertexKeyIndexWrapper().getVertices(key, value);
} else {
return globals.getVertexWrapper().getVertices(key, value);
}
@@ -489,7 +490,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
}
if (globals.getConfig().getAutoIndex() || getIndexedKeys(Edge.class).contains(key)) {
return globals.getEdgeIndexWrapper().getEdges(key, value);
return globals.getEdgeKeyIndexWrapper().getEdges(key, value);
} else {
return globals.getEdgeWrapper().getEdges(key, value);
}
@@ -547,7 +548,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
if (s.iterator().hasNext())
throw ExceptionFactory.indexAlreadyExists(indexName);
globals.getIndexMetadataWrapper().writeIndexMetadataEntry(indexName, indexClass);
globals.getNamedIndexListWrapper().writeIndexNameEntry(indexName, indexClass);
return new AccumuloIndex<T>(globals, indexName, indexClass);
} finally {
@@ -586,8 +587,10 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
public Iterable<Index<? extends Element>> getIndices() {
// TODO Move the below into the suitable index metadata wrapper.
if (globals.getConfig().getIndexableGraphDisabled())
if (globals.getConfig().getIndexableGraphDisabled()) {
throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
}
List<Index<? extends Element>> toRet = new ArrayList<Index<? extends Element>>();
Scanner scan = getScanner(globals.getConfig().getIndexNamesTableName());
try {
@@ -620,7 +623,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
for (Index<? extends Element> index : getIndices()) {
if (index.getIndexName().equals(indexName)) {
globals.getIndexMetadataWrapper().clearIndexMetadataEntry(indexName, index.getIndexClass());
globals.getNamedIndexListWrapper().clearIndexNameEntry(indexName, index.getIndexClass());
try {
globals.getConfig().getConnector().tableOperations().delete(globals.getConfig()
@@ -642,7 +645,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
throw ExceptionFactory.classForElementCannotBeNull();
}
globals.getKeyMetadataWrapper().clearKeyMetadataEntry(key, elementClass);
globals.getIndexedKeysListWrapper().clearKeyMetadataEntry(key, elementClass);
String table = null;
if (elementClass.equals(Vertex.class)) {
@@ -673,7 +676,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
throw ExceptionFactory.classForElementCannotBeNull();
}
globals.getKeyMetadataWrapper().writeKeyMetadataEntry(key, elementClass);
globals.getIndexedKeysListWrapper().writeKeyMetadataEntry(key, elementClass);
globals.checkedFlush();
// Re Index Graph
@@ -705,7 +708,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
@Override
public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) {
return globals.getKeyMetadataWrapper().getIndexedKeys(elementClass);
return globals.getIndexedKeysListWrapper().getIndexedKeys(elementClass);
}
/**

View File

@@ -21,7 +21,7 @@ import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Index;
import com.tinkerpop.blueprints.IndexableGraph;
import edu.jhuapl.tinkerpop.tables.NamedIndexTableWrapper;
import edu.jhuapl.tinkerpop.tables.namedindex.NamedIndexTableWrapper;
/**
* Accumulo-based implementation for {@link IndexableGraph}.

View File

@@ -22,14 +22,14 @@ import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Vertex;
import edu.jhuapl.tinkerpop.cache.ElementCaches;
import edu.jhuapl.tinkerpop.tables.EdgeIndexTableWrapper;
import edu.jhuapl.tinkerpop.tables.EdgeTableWrapper;
import edu.jhuapl.tinkerpop.tables.ElementTableWrapper;
import edu.jhuapl.tinkerpop.tables.IndexNameTableWrapper;
import edu.jhuapl.tinkerpop.tables.IndexTableWrapper;
import edu.jhuapl.tinkerpop.tables.IndexedKeysTableWrapper;
import edu.jhuapl.tinkerpop.tables.VertexIndexTableWrapper;
import edu.jhuapl.tinkerpop.tables.VertexTableWrapper;
import edu.jhuapl.tinkerpop.tables.BaseIndexValuesTableWrapper;
import edu.jhuapl.tinkerpop.tables.core.EdgeTableWrapper;
import edu.jhuapl.tinkerpop.tables.core.ElementTableWrapper;
import edu.jhuapl.tinkerpop.tables.core.VertexTableWrapper;
import edu.jhuapl.tinkerpop.tables.keyindex.EdgeKeyIndexTableWrapper;
import edu.jhuapl.tinkerpop.tables.keyindex.IndexedKeysListTableWrapper;
import edu.jhuapl.tinkerpop.tables.keyindex.VertexKeyIndexTableWrapper;
import edu.jhuapl.tinkerpop.tables.namedindex.NamedIndexListTableWrapper;
/**
* Internal class gathering together instances of
@@ -78,20 +78,20 @@ public class GlobalInstances {
return new EdgeTableWrapper(this);
}
public VertexIndexTableWrapper getVertexIndexWrapper() {
return new VertexIndexTableWrapper(this);
public VertexKeyIndexTableWrapper getVertexKeyIndexWrapper() {
return new VertexKeyIndexTableWrapper(this);
}
public EdgeIndexTableWrapper getEdgeIndexWrapper() {
return new EdgeIndexTableWrapper(this);
public EdgeKeyIndexTableWrapper getEdgeKeyIndexWrapper() {
return new EdgeKeyIndexTableWrapper(this);
}
public IndexedKeysTableWrapper getKeyMetadataWrapper() {
return new IndexedKeysTableWrapper(this);
public IndexedKeysListTableWrapper getIndexedKeysListWrapper() {
return new IndexedKeysListTableWrapper(this);
}
public IndexNameTableWrapper getIndexMetadataWrapper() {
return new IndexNameTableWrapper(this);
public NamedIndexListTableWrapper getNamedIndexListWrapper() {
return new NamedIndexListTableWrapper(this);
}
public <T extends Element> ElementTableWrapper getElementWrapper(Class<T> clazz) {
@@ -104,11 +104,11 @@ public class GlobalInstances {
}
}
public <T extends Element> IndexTableWrapper getKeyIndexWrapper(Class<T> clazz) {
public <T extends Element> BaseIndexValuesTableWrapper getIndexValuesWrapper(Class<T> clazz) {
if (Vertex.class.equals(clazz)) {
return getVertexIndexWrapper();
return getVertexKeyIndexWrapper();
} else if (Edge.class.equals(clazz)) {
return getEdgeIndexWrapper();
return getEdgeKeyIndexWrapper();
} else {
throw new AccumuloGraphException("Unrecognized class: "+clazz);
}

View File

@@ -22,20 +22,29 @@ import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Value;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
/**
* Entry parser for index metadata. This includes index
* names for named indexes, and property keys for
* key indexes.
* Entry parser for index metadata. The format
* is the same for both {@link IndexableGraph}
* and {@link KeyIndexableGraph} functionality.
* For the former, this parser returns names of
* indexes. For the latter, the parser returns
* indexed keys.
*/
public class IndexMetadataParser implements EntryParser<List<String>> {
public class IndexedItemsListParser implements EntryParser<List<String>> {
private final Class<? extends Element> elementClass;
public IndexMetadataParser(Class<? extends Element> elementClass) {
public IndexedItemsListParser(Class<? extends Element> elementClass) {
this.elementClass = elementClass;
}
public Class<? extends Element> getElementClass() {
return elementClass;
}
@Override
public List<String> parse(Iterable<Entry<Key,Value>> entries) {
List<String> keys = new ArrayList<String>();

View File

@@ -48,18 +48,27 @@ import edu.jhuapl.tinkerpop.parser.ElementIndexParser;
import edu.jhuapl.tinkerpop.parser.VertexIndexParser;
/**
* Wrapper around index tables.
* Wrapper around index tables containing properties
* and values.
*/
public abstract class IndexTableWrapper extends BaseTableWrapper {
public abstract class BaseIndexValuesTableWrapper extends BaseTableWrapper {
protected final Class<? extends Element> elementType;
protected IndexTableWrapper(GlobalInstances globals,
protected BaseIndexValuesTableWrapper(GlobalInstances globals,
Class<? extends Element> elementType, String tableName) {
super(globals, tableName);
this.elementType = elementType;
}
/**
* Return class of this index.
* @return
*/
public Class<? extends Element> getElementType() {
return elementType;
}
/**
* Add the property to this index, if autoindexing is enabled
* and/or the given key has indexing enabled.

View File

@@ -25,9 +25,9 @@ import edu.jhuapl.tinkerpop.mutator.index.IndexMetadataMutator;
* about which property keys are indexed for different
* graph types.
*/
public abstract class MetadataTableWrapper extends BaseTableWrapper {
public abstract class BaseIndexedItemsListTableWrapper extends BaseTableWrapper {
protected MetadataTableWrapper(GlobalInstances globals,
protected BaseIndexedItemsListTableWrapper(GlobalInstances globals,
String tableName) {
super(globals, tableName);
}

View File

@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.core;
import java.util.ArrayList;
import java.util.Iterator;

View File

@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.core;
import java.util.HashSet;
import java.util.Iterator;
@@ -39,6 +39,7 @@ import edu.jhuapl.tinkerpop.mutator.property.ClearPropertyMutator;
import edu.jhuapl.tinkerpop.mutator.property.WritePropertyMutator;
import edu.jhuapl.tinkerpop.mutator.Mutators;
import edu.jhuapl.tinkerpop.parser.PropertyParser;
import edu.jhuapl.tinkerpop.tables.BaseTableWrapper;
/**
* Wrapper around tables with operations

View File

@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.core;
import java.util.ArrayList;
import java.util.List;

View File

@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.keyindex;
import java.util.Arrays;
import java.util.Map.Entry;
@@ -25,18 +25,20 @@ import org.apache.accumulo.core.util.PeekingIterator;
import org.apache.hadoop.io.Text;
import com.tinkerpop.blueprints.Edge;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloEdge;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.ScannerIterable;
import edu.jhuapl.tinkerpop.parser.EdgeIndexParser;
import edu.jhuapl.tinkerpop.tables.BaseIndexValuesTableWrapper;
/**
* Wrapper around {@link Edge} index table.
*/
public class EdgeIndexTableWrapper extends IndexTableWrapper {
public class EdgeKeyIndexTableWrapper extends BaseIndexValuesTableWrapper {
public EdgeIndexTableWrapper(GlobalInstances globals) {
public EdgeKeyIndexTableWrapper(GlobalInstances globals) {
super(globals, Edge.class, globals.getConfig()
.getEdgeKeyIndexTableName());
}

View File

@@ -12,25 +12,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.keyindex;
import java.util.HashSet;
import java.util.Set;
import org.apache.accumulo.core.client.Scanner;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.util.ExceptionFactory;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.parser.IndexMetadataParser;
import edu.jhuapl.tinkerpop.parser.IndexedItemsListParser;
import edu.jhuapl.tinkerpop.tables.BaseIndexedItemsListTableWrapper;
/**
* Wraps the metadata tables which stores information
* about which property keys are indexed for different
* graph types.
*/
public class IndexedKeysTableWrapper extends MetadataTableWrapper {
public class IndexedKeysListTableWrapper extends BaseIndexedItemsListTableWrapper {
public IndexedKeysTableWrapper(GlobalInstances globals) {
public IndexedKeysListTableWrapper(GlobalInstances globals) {
super(globals, globals.getConfig().getIndexedKeysTableName());
}
@@ -47,7 +50,7 @@ public class IndexedKeysTableWrapper extends MetadataTableWrapper {
throw ExceptionFactory.classForElementCannotBeNull();
}
IndexMetadataParser parser = new IndexMetadataParser(elementClass);
IndexedItemsListParser parser = new IndexedItemsListParser(elementClass);
Scanner s = getScanner();
Set<String> keys = new HashSet<String>(parser.parse(s));

View File

@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.keyindex;
import java.util.Arrays;
import java.util.Map.Entry;
@@ -31,13 +31,14 @@ import edu.jhuapl.tinkerpop.AccumuloVertex;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.ScannerIterable;
import edu.jhuapl.tinkerpop.parser.VertexIndexParser;
import edu.jhuapl.tinkerpop.tables.BaseIndexValuesTableWrapper;
/**
* Wrapper around {@link Vertex} index table.
*/
public class VertexIndexTableWrapper extends IndexTableWrapper {
public class VertexKeyIndexTableWrapper extends BaseIndexValuesTableWrapper {
public VertexIndexTableWrapper(GlobalInstances globals) {
public VertexKeyIndexTableWrapper(GlobalInstances globals) {
super(globals, Vertex.class, globals.getConfig()
.getVertexKeyIndexTableName());
}

View File

@@ -12,27 +12,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.namedindex;
import com.tinkerpop.blueprints.Element;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.tables.BaseIndexedItemsListTableWrapper;
/**
* Wrapper around index metadata table.
* Wrapper around index metadata table. This lists
* names of indexes and their element types.
*/
public class IndexNameTableWrapper extends MetadataTableWrapper {
public class NamedIndexListTableWrapper extends BaseIndexedItemsListTableWrapper {
public IndexNameTableWrapper(GlobalInstances globals) {
public NamedIndexListTableWrapper(GlobalInstances globals) {
super(globals, globals.getConfig().getIndexNamesTableName());
}
public void writeIndexMetadataEntry(String indexName,
public void writeIndexNameEntry(String indexName,
Class<? extends Element> indexClass) {
writeEntry(indexName, indexClass);
}
public void clearIndexMetadataEntry(String indexName,
public void clearIndexNameEntry(String indexName,
Class<? extends Element> indexClass) {
clearEntry(indexName, indexClass);
}

View File

@@ -12,17 +12,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop.tables;
package edu.jhuapl.tinkerpop.tables.namedindex;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.IndexableGraph;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.tables.BaseIndexValuesTableWrapper;
/**
* Wrapper around a named index table (for {@link IndexableGraph}).
*/
public class NamedIndexTableWrapper extends IndexTableWrapper {
public class NamedIndexTableWrapper extends BaseIndexValuesTableWrapper {
public NamedIndexTableWrapper(GlobalInstances globals,
Class<? extends Element> elementType, String indexName) {