org.vertexium.Graph类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中org.vertexium.Graph类的一些代码示例,展示了Graph类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph类的具体详情如下:
包路径:org.vertexium.Graph
类名称:Graph

Graph介绍

暂无

代码示例

代码示例来源:origin: visallo/vertexium

@Test
public void testExtendedDataQueryAfterDeleteForEdge() {
  graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A);
  graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A);
  graph.prepareEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A)
      .addExtendedData("table1", "row1", "name", "value 1", VISIBILITY_A)
      .addExtendedData("table1", "row2", "name", "value 2", VISIBILITY_A)
      .save(AUTHORIZATIONS_A);
  graph.flush();
  List<ExtendedDataRow> searchResultsList = toList(graph.query(AUTHORIZATIONS_A).extendedDataRows());
  assertRowIdsAnyOrder(Lists.newArrayList("row1", "row2"), searchResultsList);
  graph.deleteEdge("e1", AUTHORIZATIONS_A);
  graph.flush();
  searchResultsList = toList(graph.query(AUTHORIZATIONS_A).extendedDataRows());
  assertRowIdsAnyOrder(Lists.newArrayList(), searchResultsList);
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testGetVertexWithBadAuthorizations() {
  graph.addVertex("v1", VISIBILITY_EMPTY, AUTHORIZATIONS_A);
  graph.flush();
  try {
    graph.getVertex("v1", AUTHORIZATIONS_BAD);
    throw new RuntimeException("Should throw " + SecurityVertexiumException.class.getSimpleName());
  } catch (SecurityVertexiumException ex) {
    // ok
  }
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testEdgeHashCodeAndEquals() {
  Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A);
  Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A);
  Edge e1 = graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("prop1", "value1", VISIBILITY_A)
      .save(AUTHORIZATIONS_A);
  Edge e2 = graph.prepareEdge("e2", v1, v2, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("prop1", "value1", VISIBILITY_A)
      .save(AUTHORIZATIONS_A);
  graph.flush();
  Edge e1Loaded = graph.getEdge("e1", AUTHORIZATIONS_A);
  assertEquals(e1Loaded.hashCode(), e1.hashCode());
  assertTrue(e1Loaded.equals(e1));
  assertNotEquals(e1Loaded.hashCode(), e2.hashCode());
  assertFalse(e1Loaded.equals(e2));
}

代码示例来源:origin: org.vertexium/vertexium-test

private void benchmarkFindVerticesById(Random random, int vertexCount, int findVerticesByIdCount) {
  double startTime = System.currentTimeMillis();
  for (int i = 0; i < findVerticesByIdCount; i++) {
    String vertexId = "v" + random.nextInt(vertexCount);
    graph.getVertex(vertexId, AUTHORIZATIONS_ALL);
  }
  graph.flush();
  double endTime = System.currentTimeMillis();
  LOGGER.info("find vertices by id in %.3fs", (endTime - startTime) / 1000);
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testDeleteVertex() {
  graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  graph.flush();
  Assert.assertEquals(1, count(graph.getVertices(AUTHORIZATIONS_A)));
  graph.deleteVertex("v1", AUTHORIZATIONS_A);
  graph.flush();
  Assert.assertEquals(0, count(graph.getVertices(AUTHORIZATIONS_A)));
}

代码示例来源:origin: org.visallo/visallo-common-rdf

protected Element getExistingElement(Graph graph, PropertyVisalloRdfTriple triple, Authorizations authorizations) {
    Element elem = triple.getElementType() == ElementType.VERTEX
        ? graph.getVertex(triple.getElementId(), authorizations)
        : graph.getEdge(triple.getElementId(), authorizations);
    if (elem == null) {
      graph.flush();
      elem = triple.getElementType() == ElementType.VERTEX
          ? graph.getVertex(triple.getElementId(), authorizations)
          : graph.getEdge(triple.getElementId(), authorizations);
    }
    checkNotNull(elem, "Could not find element with id " + triple.getElementId());
    return elem;
  }
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testStreamingPropertyValueReadAsString() {
  graph.prepareVertex("v1", VISIBILITY_EMPTY)
      .setProperty("spv", StreamingPropertyValue.create("Hello World"), VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_EMPTY);
  graph.flush();
  Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_EMPTY);
  assertEquals("Hello World", ((StreamingPropertyValue) v1.getPropertyValue("spv")).readToString());
  assertEquals("Wor", ((StreamingPropertyValue) v1.getPropertyValue("spv")).readToString(6, 3));
  assertEquals("", ((StreamingPropertyValue) v1.getPropertyValue("spv")).readToString("Hello World".length(), 1));
  assertEquals("Hello World", ((StreamingPropertyValue) v1.getPropertyValue("spv")).readToString(0, 100));
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testSoftDeletePropertyOnEdgeNotIndexed() {
  Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B);
  Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_A_AND_B);
  ElementBuilder<Edge> elementBuilder = graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_B)
      .setProperty("prop1", "value1", VISIBILITY_B);
  elementBuilder.setIndexHint(IndexHint.DO_NOT_INDEX);
  Edge e1 = elementBuilder.save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  ExistingElementMutation<Edge> m = e1.prepareMutation();
  m.softDeleteProperty("prop1", VISIBILITY_B);
  m.setIndexHint(IndexHint.DO_NOT_INDEX);
  m.save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  e1 = graph.getEdge("e1", AUTHORIZATIONS_A_AND_B);
  assertEquals(0, IterableUtils.count(e1.getProperties()));
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testExtendedDataDelete() {
  graph.prepareVertex("v1", VISIBILITY_A)
      .addExtendedData("table1", "row1", "name", "value", VISIBILITY_A)
      .save(AUTHORIZATIONS_A);
  graph.flush();
  graph.deleteVertex("v1", AUTHORIZATIONS_A);
  graph.flush();
  QueryResultsIterable<? extends VertexiumObject> searchResults = graph.query("value", AUTHORIZATIONS_A)
      .search();
  assertEquals(0, searchResults.getTotalHits());
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testAddEdgeWithoutIndexing() {
  assumeTrue("add edge without indexing not supported", !isDefaultSearchIndex());
  Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
  graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("prop1", "value1", VISIBILITY_A)
      .setIndexHint(IndexHint.DO_NOT_INDEX)
      .save(AUTHORIZATIONS_A);
  graph.flush();
  Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A_AND_B)
      .has("prop1", "value1")
      .edges();
  assertEdgeIds(edges);
}

代码示例来源:origin: org.visallo/visallo-model-vertexium

@Override
public void clearCache(String workspaceId) {
  checkNotNull(workspaceId, "Workspace should not be null");
  LOGGER.info("clearing ontology cache for workspace %s", workspaceId);
  super.clearCache(workspaceId);
  graph.flush();
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testLargeFieldValuesThatAreMarkedWithExactMatch() {
  graph.defineProperty("field1").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define();
  StringBuilder largeText = new StringBuilder();
  for (int i = 0; i < 10000; i++) {
    largeText.append("test ");
  }
  graph.prepareVertex("v1", VISIBILITY_EMPTY)
      .addPropertyValue("", "field1", largeText.toString(), VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_EMPTY);
  graph.flush();
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testAddVertexWithoutIndexing() {
  assumeTrue("add vertex without indexing not supported", !isDefaultSearchIndex());
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("prop1", "value1", VISIBILITY_A)
      .setIndexHint(IndexHint.DO_NOT_INDEX)
      .save(AUTHORIZATIONS_A);
  graph.flush();
  Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B)
      .has("prop1", "value1")
      .vertices();
  assertVertexIds(vertices);
}

代码示例来源:origin: visallo/vertexium

@Test
public void testQueryReturningElasticsearchVertex() {
  graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_B);
  graph.addEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
  graph.flush();
  QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_B)
      .vertices(FetchHints.NONE);
  assertResultsCount(1, 1, vertices);
  Vertex vertex = toList(vertices).get(0);
  assertEquals("v2", vertex.getId());
}

代码示例来源:origin: org.vertexium/vertexium-core

@SuppressWarnings("unchecked")
private <T extends Element> Iterable<T> getIterableFromElementType(ElementType elementType, FetchHints fetchHints) throws VertexiumException {
  switch (elementType) {
    case VERTEX:
      return (Iterable<T>) getGraph().getVertices(fetchHints, getParameters().getAuthorizations());
    case EDGE:
      return (Iterable<T>) getGraph().getEdges(fetchHints, getParameters().getAuthorizations());
    default:
      throw new VertexiumException("Unexpected element type: " + elementType);
  }
}

代码示例来源:origin: visallo/vertexium

public Element getElement() {
  switch (elementType) {
    case VERTEX:
      return getGraph().getVertex(getElementId(), getGraph().getDefaultFetchHints(), getTime(), getAuthorizations());
    case EDGE:
      return getGraph().getEdge(getElementId(), getGraph().getDefaultFetchHints(), getTime(), getAuthorizations());
    default:
      throw new VertexiumException("Unhandled element type: " + elementType);
  }
}

代码示例来源:origin: visallo/vertexium

@Test
public void testMetadataMutationsOnEdge() {
  Metadata metadataPropB = Metadata.create();
  metadataPropB.add("meta1", "meta1", VISIBILITY_A);
  Edge edge = graph.prepareEdge("v1", "v2", LABEL_LABEL1, VISIBILITY_A)
      .setProperty("propBmeta", "propBmeta", metadataPropB, VISIBILITY_A)
      .save(AUTHORIZATIONS_ALL);
  graph.flush();
  ExistingElementMutation<Edge> m = edge.prepareMutation();
  m.setPropertyMetadata("propBmeta", "meta1", "meta2", VISIBILITY_A);
  edge = m.save(AUTHORIZATIONS_ALL);
  assertEquals("meta2", edge.getProperty("propBmeta").getMetadata().getEntry("meta1").getValue());
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch

private Element requeryWithAuthsAndMergedElement(Graph graph, Element element, Authorizations authorizations) {
  Element existingElement;
  if (element instanceof Vertex) {
    existingElement = graph.getVertex(element.getId(), authorizations);
  } else if (element instanceof Edge) {
    existingElement = graph.getEdge(element.getId(), authorizations);
  } else {
    throw new VertexiumException("Unexpected element type " + element.getClass().getName());
  }
  if (existingElement == null) {
    return element;
  }
  LOGGER.debug("Reindexing element " + element.getId());
  existingElement.mergeProperties(element);
  return existingElement;
}

代码示例来源:origin: org.visallo/visallo-core

private Authorizations getAuthorizations(String[] authorizations) {
    return graph.createAuthorizations(authorizations);
  }
}

代码示例来源:origin: org.vertexium/vertexium-core

/**
 * Get the attach vertex on either side of the edge.
 *
 * @param direction  The side of the edge to get the vertex from (IN or OUT).
 * @param fetchHints Hint on what should be fetched from the datastore.
 * @return The vertex.
 */
default Vertex getVertex(Direction direction, FetchHints fetchHints, Authorizations authorizations) {
  String vertexId = getVertexId(direction);
  return getGraph().getVertex(vertexId, fetchHints, authorizations);
}

相关文章