IndexStore { protected IndexImpl createViewIndex(Graph graph) { if (graph.getView().isMainView()) { throw new IllegalArgumentException("Can't create a view index for the main view"); } IndexImpl viewIndex = new IndexImpl<T>(columnStore); ColumnImpl[] columns = columnStore.toArray(); viewIndex.addAllColumns(columns); viewIndexes.put(graph.getView(), viewIndex); indexView(graph); return viewIndex; } IndexStore(ColumnStore<T> columnStore); Object set(Column column, Object oldValue, Object value, T element); void clear(T element); void index(T element); void indexView(Graph graph); void indexInView(T element, GraphView view); void clearInView(T element, GraphView view); void clear(GraphView view); void clear();  }
@Test public void testCreateViewIndex() { GraphStore graphStore = generateBasicGraphStoreWithColumns(); IndexStore<Node> indexStore = graphStore.nodeTable.store.indexStore; GraphView view = graphStore.viewStore.createView(); Graph graph = graphStore.viewStore.getGraph(view); IndexImpl index = indexStore.createViewIndex(graph); Assert.assertSame(indexStore.getIndex(graph), index); for (ColumnImpl col : graphStore.nodeTable.store.toArray()) { if (col.isIndexed()) { Assert.assertTrue(index.hasColumn(col)); } } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testCreateViewIndexMainView() { GraphStore graphStore = new GraphStore(); graphStore.nodeTable.store.indexStore.createViewIndex(graphStore); }
@Test public void testIndexWithView() { GraphStore graphStore = generateBasicGraphStoreWithColumns(); GraphView view = graphStore.viewStore.createView(); Graph graph = graphStore.viewStore.getGraph(view); IndexStore<Node> indexStore = graphStore.nodeTable.store.indexStore; IndexImpl index = indexStore.createViewIndex(graphStore.viewStore.getGraph(view)); Column column = graphStore.nodeTable.store.getColumn("foo"); Node n1 = graphStore.factory.newNode("1"); n1.setAttribute(column, "bar"); graphStore.addNode(n1); graph.addNode(n1); Assert.assertEquals(index.countElements(column), 1); Assert.assertEquals(index.countValues(column), 1); Assert.assertEquals(index.count(column, "bar"), 1); }
@Test public void testClearElementWithView() { GraphStore graphStore = generateBasicGraphStoreWithColumns(); GraphView view = graphStore.viewStore.createView(); Graph graph = graphStore.viewStore.getGraph(view); Column column = graphStore.nodeTable.store.getColumn("foo"); Node n1 = graphStore.factory.newNode("1"); n1.setAttribute(column, "bar"); graphStore.addNode(n1); graph.addNode(n1); IndexStore<Node> indexStore = graphStore.nodeTable.store.indexStore; IndexImpl index = indexStore.createViewIndex(graphStore.viewStore.getGraph(view)); n1.clearAttributes(); Assert.assertEquals(index.countElements(column), 0); Assert.assertEquals(index.countValues(column), 0); Assert.assertEquals(index.count(column, "bar"), 0); }