org.vertexium.Graph.prepareEdge()方法的使用及代码示例

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

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

Graph.prepareEdge介绍

[英]Prepare an edge to be added to the graph. This method provides a way to build up an edge with it's properties to be inserted with a single operation.
[中]准备要添加到图形的边。此方法提供了一种通过单个操作插入边的属性来构建边的方法。

代码示例

代码示例来源: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: visallo/vertexium

@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.visallo/visallo-model-vertexium

private void createEdge(
    Vertex workspaceVertex,
    Vertex otherVertex,
    Authorizations authorizations
) {
  String workspaceVertexId = workspaceVertex.getId();
  String entityVertexId = otherVertex.getId();
  String edgeId = getWorkspaceToEntityEdgeId(workspaceVertexId, entityVertexId);
  EdgeBuilder edgeBuilder = getGraph().prepareEdge(
      edgeId,
      workspaceVertex,
      otherVertex,
      WORKSPACE_TO_ENTITY_RELATIONSHIP_IRI,
      VISIBILITY.getVisibility()
  );
  edgeBuilder.setIndexHint(IndexHint.DO_NOT_INDEX);
  edgeBuilder.save(authorizations);
}

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

public void addWorkspaceToUser(Vertex workspaceVertex, Vertex userVertex, Authorizations authorizations) {
  EdgeBuilder edgeBuilder = getGraph().prepareEdge(
      workspaceVertex,
      userVertex,
      WORKSPACE_TO_USER_RELATIONSHIP_IRI,
      VISIBILITY.getVisibility()
  );
  WorkspaceProperties.WORKSPACE_TO_USER_IS_CREATOR.setProperty(edgeBuilder, true, VISIBILITY.getVisibility());
  WorkspaceProperties.WORKSPACE_TO_USER_ACCESS.setProperty(
      edgeBuilder,
      WorkspaceAccess.WRITE.toString(),
      VISIBILITY.getVisibility()
  );
  edgeBuilder.save(authorizations);
}

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

@Override
public ImportContext createImportContext(
    ImportContext ctx,
    RdfTripleImportHelper rdfTripleImportHelper,
    Authorizations authorizations
) {
  ElementMutation m = rdfTripleImportHelper.getGraph().prepareEdge(
      getEdgeId(),
      getOutVertexId(),
      getInVertexId(),
      getEdgeLabel(),
      rdfTripleImportHelper.getVisibility(getEdgeVisibilitySource())
  );
  return new ImportContext(getEdgeId(), m);
}

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

@Test
public void testGraphQueryEdgeHasWithSecurity() {
  Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  Vertex v3 = graph.prepareVertex("v3", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("age", 25, VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("age", 25, VISIBILITY_B)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
      .has("age", Compare.EQUAL, 25)
      .edges();
  Assert.assertEquals(1, count(edges));
}

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

@Test
public void testGraphQueryEdgeHasWithSecurity() {
  Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  Vertex v3 = graph.prepareVertex("v3", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("age", 25, VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("age", 25, VISIBILITY_B)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
      .has("age", Compare.EQUAL, 25)
      .edges();
  Assert.assertEquals(1, count(edges));
}

代码示例来源: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 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.visallo/visallo-tools-ontology-ingest-common

private Edge save(IngestOptions ingestOptions, RelationshipBuilder relationshipBuilder) {
  Visibility relationshipVisibility = getVisibility(ingestOptions, relationshipBuilder.getVisibility());
  EdgeBuilderByVertexId edgeBuilder = graph.prepareEdge(
      relationshipBuilder.getId(),
      relationshipBuilder.getOutVertexId(),
      relationshipBuilder.getInVertexId(),
      relationshipBuilder.getIri(),
      getTimestamp(ingestOptions, relationshipBuilder.getTimestamp()),
      relationshipVisibility
  );
  addProperties(ingestOptions, relationshipVisibility, edgeBuilder, relationshipBuilder);
  LOGGER.trace("Saving edge: %s", edgeBuilder.getEdgeId());
  return edgeBuilder.save(getAuthorizations(ingestOptions));
}

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

@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.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: 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-test

@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-test

@Test
public void testDisableEdgeIndexing() {
  assumeTrue("disabling indexing not supported", disableEdgeIndexing(graph));
  Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("prop1", "value1", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
      .has("prop1", "value1")
      .edges();
  Assert.assertEquals(0, count(edges));
}

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

@Test
public void testDisableEdgeIndexing() {
  assumeTrue("disabling indexing not supported", disableEdgeIndexing(graph));
  Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
  graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A)
      .setProperty("prop1", "value1", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
      .has("prop1", "value1")
      .edges();
  Assert.assertEquals(0, count(edges));
}

代码示例来源: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: visallo/vertexium

@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.visallo/visallo-core-test

@Test
public void testExceptionDeletingSandboxedRelationshipsWithEdges() throws Exception {
  createSampleOntology();
  VisibilityJson json = VisibilityJson.updateVisibilitySourceAndAddWorkspaceId(new VisibilityJson(), "", workspaceId);
  Visibility visibility = getVisibilityTranslator().toVisibility(json).getVisibility();
  Vertex source = getGraph().prepareVertex(visibility).save(authorizations);
  Vertex target = getGraph().prepareVertex(visibility).save(authorizations);
  EdgeBuilder edgeBuilder = getGraph().prepareEdge(source, target, SANDBOX_RELATIONSHIP_IRI, visibility);
  edgeBuilder.setProperty(SANDBOX_PROPERTY_IRI, "a value", visibility);
  edgeBuilder.save(authorizations);
  thrown.expect(VisalloException.class);
  thrown.expectMessage("Unable to delete relationship that have edges using it");
  getOntologyRepository().deleteRelationship(SANDBOX_RELATIONSHIP_IRI, adminUser, workspaceId);
}

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

@Test
public void testExceptionDeletingSandboxedPropertiesWithEdges() throws Exception {
  createSampleOntology();
  VisibilityJson json = VisibilityJson.updateVisibilitySourceAndAddWorkspaceId(new VisibilityJson(), "", workspaceId);
  Visibility visibility = getVisibilityTranslator().toVisibility(json).getVisibility();
  Vertex source = getGraph().prepareVertex(visibility).save(authorizations);
  Vertex target = getGraph().prepareVertex(visibility).save(authorizations);
  EdgeBuilder edgeBuilder = getGraph().prepareEdge(source, target, SANDBOX_RELATIONSHIP_IRI, visibility);
  edgeBuilder.setProperty(SANDBOX_PROPERTY_IRI, "a value", visibility);
  edgeBuilder.save(authorizations);
  thrown.expect(VisalloException.class);
  thrown.expectMessage("Unable to delete property that have elements using it");
  getOntologyRepository().deleteProperty(SANDBOX_PROPERTY_IRI, adminUser, workspaceId);
}

相关文章

微信公众号

最新文章

更多