/** * Resolves a given tree and attribute name into one or more {@link IndexInfo} objects * * @param indexdb the index database * @param treeName the name of the feature tree * @param attributeName the name of the indexed attribute. If {@code null}, this function will * return the index infos associated with the given tree name * @return the resolved {@link IndexInfo} objects */ public static List<IndexInfo> resolveIndexInfo(IndexDatabase indexdb, String treeName, @Nullable String attributeName) { if (attributeName == null) { return indexdb.getIndexInfos(treeName); } else { Optional<IndexInfo> indexInfoOpt = indexdb.getIndexInfo(treeName, attributeName); if (indexInfoOpt.isPresent()) { return Lists.newArrayList(indexInfoOpt.get()); } } return Lists.newArrayList(); }
/** * @param oldCanonical the layer's canonical tree id * @param treeName the layer's tree path * @param attributeName the index attribute name * @param repo * @return */ private Optional<Index> resolveIndex(final ObjectId oldCanonical, final String treeName, final String attributeName, final IndexDatabase db) { IndexInfo info = db.getIndexInfo(treeName, attributeName).orNull(); Optional<Index> index = Optional.empty(); if (info != null) { index = resolveIndex(oldCanonical, info, db); } return index; }
/** * Performs the operation. * * @return the newly constructed {@link IndexInfo} */ @Override protected IndexInfo _call() { IndexDatabase indexDatabase = indexDatabase(); checkArgument(treeName != null, "tree name not provided"); checkArgument(attributeName != null, "indexing attribute name not provided"); checkArgument(indexType != null, "index type not provided"); checkArgument(!indexDatabase.getIndexInfo(treeName, attributeName).isPresent(), "An index has already been created on that tree and attribute."); Map<String, Object> metadata = this.metadata; IndexInfo index = indexDatabase.createIndexInfo(treeName, attributeName, indexType, metadata); return index; } }
/** * Resolves a given tree and attribute name into one or more {@link IndexInfo} objects * * @param indexdb the index database * @param treeName the name of the feature tree * @param attributeName the name of the indexed attribute. If {@code null}, this function will * return the index infos associated with the given tree name * @return the resolved {@link IndexInfo} objects */ public static List<IndexInfo> resolveIndexInfo(IndexDatabase indexdb, String treeName, @Nullable String attributeName) { if (attributeName == null) { return indexdb.getIndexInfos(treeName); } else { Optional<IndexInfo> indexInfoOpt = indexdb.getIndexInfo(treeName, attributeName); if (indexInfoOpt.isPresent()) { return Lists.newArrayList(indexInfoOpt.get()); } } return Lists.newArrayList(); }
/** * Performs the operation. * * @return the newly constructed {@link IndexInfo} */ @Override protected IndexInfo _call() { IndexDatabase indexDatabase = indexDatabase(); checkArgument(treeName != null, "tree name not provided"); checkArgument(attributeName != null, "indexing attribute name not provided"); checkArgument(indexType != null, "index type not provided"); checkState(!indexDatabase.getIndexInfo(treeName, attributeName).isPresent(), "An index has already been created on that tree and attribute."); Map<String, Object> metadata = this.metadata; IndexInfo index = indexDatabase.createIndexInfo(treeName, attributeName, indexType, metadata); return index; } }
@Test public void testGetIndexNotPresent() { String treeName = "tree"; String attributeName = "attribute"; Optional<IndexInfo> indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertFalse(indexOpt.isPresent()); indexDb.createIndexInfo("otherTree", "someAttribute", IndexType.QUADTREE, null); indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertFalse(indexOpt.isPresent()); }
@Test public void testGetIndexNotPresent() { String treeName = "tree"; String attributeName = "attribute"; Optional<IndexInfo> indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertFalse(indexOpt.isPresent()); indexDb.createIndexInfo("otherTree", "someAttribute", IndexType.QUADTREE, null); indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertFalse(indexOpt.isPresent()); }
@Then("^the response should contain the index ID for tree \"([^\"]*)\"$") public void the_response_contains_indexID(String tree) throws Throwable { GeoGIG gig = localRepo.geogigCLI.getGeogig(); ObjectId canonicalTreeId = gig.command(ResolveTreeish.class).setTreeish("HEAD:" + tree).call().get(); Optional<IndexInfo> indexInfo = gig.getRepository().indexDatabase().getIndexInfo(tree,"pp"); Optional<ObjectId> indexedTree = gig.getRepository().indexDatabase().resolveIndexedTree(indexInfo.get(),canonicalTreeId); if (!indexedTree.isPresent()) { fail(); } String indexId = indexedTree.get().toString(); String actual = localRepo.stdOut.toString().replaceAll(LINE_SEPARATOR, "") .replaceAll("\\\\", "/"); assertTrue("'" + actual + "' does not contain ID '" + indexId.substring(0,8), actual.contains(indexId.toString().substring(0,8))); }
@Then("^the response should contain the index ID for tree \"([^\"]*)\"$") public void the_response_contains_indexID(String tree) throws Throwable { GeoGIG gig = localRepo.geogigCLI.getGeogig(); ObjectId canonicalTreeId = gig.command(ResolveTreeish.class).setTreeish("HEAD:" + tree).call().get(); Optional<IndexInfo> indexInfo = gig.getRepository().indexDatabase().getIndexInfo(tree,"pp"); Optional<ObjectId> indexedTree = gig.getRepository().indexDatabase().resolveIndexedTree(indexInfo.get(),canonicalTreeId); if (!indexedTree.isPresent()) { fail(); } String indexId = indexedTree.get().toString(); String actual = localRepo.stdOut.toString().replaceAll(LINE_SEPARATOR, "") .replaceAll("\\\\", "/"); assertTrue("'" + actual + "' does not contain ID '" + indexId.substring(0,8), actual.contains(indexId.toString().substring(0,8))); }
@Then("^the response should contain the index ID for tree \"([^\"]*)\"$") public void the_response_contains_indexID(String tree) throws Throwable { GeoGIG gig = localRepo.geogigCLI.getGeogig(); ObjectId canonicalTreeId = gig.command(ResolveTreeish.class).setTreeish("HEAD:" + tree) .call().get(); Optional<IndexInfo> indexInfo = gig.getRepository().indexDatabase().getIndexInfo(tree, "pp"); Optional<ObjectId> indexedTree = gig.getRepository().indexDatabase() .resolveIndexedTree(indexInfo.get(), canonicalTreeId); if (!indexedTree.isPresent()) { fail(); } String indexId = indexedTree.get().toString(); String actual = localRepo.stdOut.toString().replaceAll(LINE_SEPARATOR, "") .replaceAll("\\\\", "/"); assertTrue("'" + actual + "' does not contain ID '" + indexId.substring(0, 8), actual.contains(indexId.toString().substring(0, 8))); }
@Then("^the response should contain index info ID for tree \"([^\"]*)\"$") public void the_response_contains_indexInfoID(String tree) throws Throwable { Repository repo = localRepo.geogigCLI.getGeogig().getRepository(); Optional<IndexInfo> indexInfo = repo.indexDatabase().getIndexInfo(tree, "pp"); ObjectId oid = null; if (indexInfo.isPresent()) { oid = indexInfo.get().getId(); } String actual = localRepo.stdOut.toString().replaceAll(LINE_SEPARATOR, "") .replaceAll("\\\\", "/"); if (oid == null) { fail(); } else { assertTrue("'" + actual + "' does not contain ID for '" + oid.toString(), actual.contains(oid.toString())); } }
@Then("^the response should contain index info ID for tree \"([^\"]*)\"$") public void the_response_contains_indexInfoID(String tree) throws Throwable { Repository repo = localRepo.geogigCLI.getGeogig().getRepository(); Optional<IndexInfo> indexInfo = repo.indexDatabase().getIndexInfo(tree,"pp"); ObjectId oid = null; if (indexInfo.isPresent()) { oid = indexInfo.get().getId(); } String actual = localRepo.stdOut.toString().replaceAll(LINE_SEPARATOR, "") .replaceAll("\\\\", "/"); if (oid == null) { fail(); } else { assertTrue("'" + actual + "' does not contain ID for '" + oid.toString(), actual.contains(oid.toString())); } }
@Then("^the response should contain index info ID for tree \"([^\"]*)\"$") public void the_response_contains_indexInfoID(String tree) throws Throwable { Repository repo = localRepo.geogigCLI.getGeogig().getRepository(); Optional<IndexInfo> indexInfo = repo.indexDatabase().getIndexInfo(tree,"pp"); ObjectId oid = null; if (indexInfo.isPresent()) { oid = indexInfo.get().getId(); } String actual = localRepo.stdOut.toString().replaceAll(LINE_SEPARATOR, "") .replaceAll("\\\\", "/"); if (oid == null) { fail(); } else { assertTrue("'" + actual + "' does not contain ID for '" + oid.toString(), actual.contains(oid.toString())); } }
@Test public void testDropIndex() { createIndex(); Optional<IndexInfo> indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom"); assertTrue(indexInfo.isPresent()); IndexInfo oldIndexInfo = indexInfo.get(); Optional<ObjectId> indexedTreeId = indexdb.resolveIndexedTree(oldIndexInfo, worldPointsTree.getId()); assertTrue(indexedTreeId.isPresent()); IndexInfo droppedIndex = geogig.command(DropIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .call(); assertEquals(oldIndexInfo, droppedIndex); indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom"); assertFalse(indexInfo.isPresent()); indexedTreeId = indexdb.resolveIndexedTree(droppedIndex, worldPointsTree.getId()); assertFalse(indexedTreeId.isPresent()); }
@Test public void testDropIndex() { createIndex(); Optional<IndexInfo> indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom"); assertTrue(indexInfo.isPresent()); IndexInfo oldIndexInfo = indexInfo.get(); Optional<ObjectId> indexedTreeId = indexdb.resolveIndexedTree(oldIndexInfo, worldPointsTree.getId()); assertTrue(indexedTreeId.isPresent()); IndexInfo droppedIndex = geogig.command(DropIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .call(); assertEquals(oldIndexInfo, droppedIndex); indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom"); assertFalse(indexInfo.isPresent()); indexedTreeId = indexdb.resolveIndexedTree(droppedIndex, worldPointsTree.getId()); assertFalse(indexedTreeId.isPresent()); }
protected void testCopyIndexesTo(IndexDatabase target) { IndexInfo index1 = createIndex("Layer1", this.indexDb); this.indexDb.copyIndexesTo(target); Optional<IndexInfo> indexInfo = target.getIndexInfo(index1.getTreeName(), index1.getAttributeName()); assertNotNull(indexInfo); assertTrue(indexInfo.isPresent()); assertEquals(index1, indexInfo.get()); Set<IndexTreeMapping> expectedMappings = toSet(this.indexDb.resolveIndexedTrees(index1)); Set<IndexTreeMapping> actualMappings = toSet(target.resolveIndexedTrees(index1)); assertEquals(expectedMappings.size(), actualMappings.size()); assertEquals(expectedMappings, actualMappings); Set<ObjectId> expectedIndexTrees = verifyAllReachableTrees(this.indexDb, expectedMappings); Set<ObjectId> actualIndexTrees = verifyAllReachableTrees(target, actualMappings); assertEquals(expectedIndexTrees.size(), actualIndexTrees.size()); assertEquals(expectedIndexTrees, actualIndexTrees); }
@Test public void testGetIndex() { Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put("meta1", 5L); metadata.put("meta2", "someValue"); String treeName = "tree"; String attributeName = "attribute"; indexDb.createIndexInfo(treeName, attributeName, IndexType.QUADTREE, metadata); indexDb.createIndexInfo("otherTree", "someAttribute", IndexType.QUADTREE, null); Optional<IndexInfo> indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertTrue(indexOpt.isPresent()); IndexInfo index = indexOpt.get(); assertEquals(treeName, index.getTreeName()); assertEquals(attributeName, index.getAttributeName()); assertEquals(IndexType.QUADTREE, index.getIndexType()); assertEquals(metadata, index.getMetadata()); assertEquals(IndexInfo.getIndexId(treeName, attributeName), index.getId()); }
@Test public void testGetIndex() { Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put("meta1", 5L); metadata.put("meta2", "someValue"); String treeName = "tree"; String attributeName = "attribute"; indexDb.createIndexInfo(treeName, attributeName, IndexType.QUADTREE, metadata); indexDb.createIndexInfo("otherTree", "someAttribute", IndexType.QUADTREE, null); Optional<IndexInfo> indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertTrue(indexOpt.isPresent()); IndexInfo index = indexOpt.get(); assertEquals(treeName, index.getTreeName()); assertEquals(attributeName, index.getAttributeName()); assertEquals(IndexType.QUADTREE, index.getIndexType()); assertEquals(metadata, index.getMetadata()); assertEquals(IndexInfo.getIndexId(treeName, attributeName), index.getId()); }
@Test public void testNullMetadata() { String treeName = "tree"; String attributeName = "attribute"; IndexInfo index = indexDb.createIndexInfo(treeName, attributeName, IndexType.QUADTREE, null); assertEquals(treeName, index.getTreeName()); assertEquals(attributeName, index.getAttributeName()); assertEquals(IndexType.QUADTREE, index.getIndexType()); assertTrue(index.getMetadata().isEmpty()); assertEquals(IndexInfo.getIndexId(treeName, attributeName), index.getId()); Optional<IndexInfo> indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertTrue(indexOpt.isPresent()); index = indexOpt.get(); assertEquals(treeName, index.getTreeName()); assertEquals(attributeName, index.getAttributeName()); assertEquals(IndexType.QUADTREE, index.getIndexType()); assertTrue(index.getMetadata().isEmpty()); assertEquals(IndexInfo.getIndexId(treeName, attributeName), index.getId()); }
@Test public void testNullMetadata() { String treeName = "tree"; String attributeName = "attribute"; IndexInfo index = indexDb.createIndexInfo(treeName, attributeName, IndexType.QUADTREE, null); assertEquals(treeName, index.getTreeName()); assertEquals(attributeName, index.getAttributeName()); assertEquals(IndexType.QUADTREE, index.getIndexType()); assertTrue(index.getMetadata().isEmpty()); assertEquals(IndexInfo.getIndexId(treeName, attributeName), index.getId()); Optional<IndexInfo> indexOpt = indexDb.getIndexInfo(treeName, attributeName); assertTrue(indexOpt.isPresent()); index = indexOpt.get(); assertEquals(treeName, index.getTreeName()); assertEquals(attributeName, index.getAttributeName()); assertEquals(IndexType.QUADTREE, index.getIndexType()); assertTrue(index.getMetadata().isEmpty()); assertEquals(IndexInfo.getIndexId(treeName, attributeName), index.getId()); }