org.apache.tinkerpop.gremlin.structure.Vertex Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Vertex.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: sqlg Author: pietermartin File: TestBatchNormalUpdatePrimitiveArrays.java License: MIT License | 6 votes |
@Test public void testShortArrayUpdateNull() throws InterruptedException { this.sqlgGraph.tx().normalBatchModeOn(); Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsShortArrayValues()); Short[] shortArray = new Short[]{1, 2}; Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "shortArray1", shortArray); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "shortArray2", shortArray); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "shortArray3", shortArray); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); Short[] shortArrayAgain = new Short[]{3, 4}; a1.property("shortArray1", shortArrayAgain); a2.property("shortArray2", shortArrayAgain); a3.property("shortArray3", shortArrayAgain); this.sqlgGraph.tx().commit(); testShortArrayUpdateNull_assert(this.sqlgGraph, a1, a2, a3, shortArrayAgain); if (this.sqlgGraph1 != null) { sleep(SLEEP_TIME); testShortArrayUpdateNull_assert(this.sqlgGraph1, a1, a2, a3, shortArrayAgain); } }
Example #2
Source Project: sqlg Author: pietermartin File: TestEdgeCache.java License: MIT License | 6 votes |
@Test public void testMultipleEdgesFromSameVertex() { Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "mike"); Vertex v2 = this.sqlgGraph.addVertex(T.label, "Car", "name", "bmw"); Vertex v3 = this.sqlgGraph.addVertex(T.label, "Car", "name", "bmw"); Vertex v4 = this.sqlgGraph.addVertex(T.label, "Bike", "name", "ktm"); v1.addEdge("bts_aaaaaa", v2); v1.addEdge("bts_btsalmtos", v4); v1.addEdge("bts_btsalm", v3); this.sqlgGraph.tx().commit(); this.sqlgGraph.close(); try (SqlgGraph sqlgGraph = SqlgGraph.open(configuration)) { v1 = sqlgGraph.traversal().V(v1.id()).next(); assertEquals(1, sqlgGraph.traversal().V(v1.id()).out("bts_btsalm").count().next().intValue()); assertEquals(1, sqlgGraph.traversal().V(v1.id()).out("bts_btsalmtos").count().next().intValue()); } }
Example #3
Source Project: tinkerpop Author: apache File: TinkerGraphTest.java License: Apache License 2.0 | 6 votes |
@Test public void shouldRemoveAVertexFromAnIndex() { final TinkerGraph g = TinkerGraph.open(); g.createIndex("name", Vertex.class); g.addVertex("name", "marko", "age", 29); g.addVertex("name", "stephen", "age", 35); final Vertex v = g.addVertex("name", "stephen", "age", 35); // a tricky way to evaluate if indices are actually being used is to pass a fake BiPredicate to has() // to get into the Pipeline and evaluate what's going through it. in this case, we know that at index // is used because only "stephen" ages should pass through the pipeline due to the inclusion of the // key index lookup on "name". If there's an age of something other than 35 in the pipeline being evaluated // then something is wrong. assertEquals(new Long(2), g.traversal().V().has("age", P.test((t, u) -> { assertEquals(35, t); return true; }, 35)).has("name", "stephen").count().next()); v.remove(); assertEquals(new Long(1), g.traversal().V().has("age", P.test((t, u) -> { assertEquals(35, t); return true; }, 35)).has("name", "stephen").count().next()); }
Example #4
Source Project: neo4j-gremlin-bolt Author: SteelBridgeLabs File: Neo4JSession.java License: Apache License 2.0 | 6 votes |
Neo4JVertex addVertex(Object... keyValues) { Objects.requireNonNull(keyValues, "keyValues cannot be null"); // verify parameters are key/value pairs ElementHelper.legalPropertyKeyValueArray(keyValues); // id cannot be present if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); // create vertex Neo4JVertex vertex = new Neo4JVertex(graph, this, vertexIdProvider, edgeIdProvider, Arrays.asList(ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL).split(Neo4JVertex.LabelDelimiter))); // add vertex to transient set (before processing properties to avoid having a transient vertex in update queue) transientVertices.add(vertex); // attach properties ElementHelper.attachProperties(vertex, keyValues); // check vertex has id Object id = vertex.id(); if (id != null) transientVertexIndex.put(id, vertex); // return vertex return vertex; }
Example #5
Source Project: timbuctoo Author: HuygensING File: LocalProperty.java License: GNU General Public License v3.0 | 6 votes |
@Override public Vertex save(Graph graph, String clientPropertyName) { Vertex propertyVertex = super.save(graph, clientPropertyName); propertyVertex.property(DATABASE_PROPERTY_NAME, propName); if (converter instanceof HasOptions) { try { propertyVertex.property(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(((HasOptions) converter).getOptions())); } catch (JsonProcessingException e) { LOG.error("Failed to write options to database for property {}", propName); } } return propertyVertex; }
Example #6
Source Project: sqlg Author: pietermartin File: TestBatchNormalUpdatePrimitiveArrays.java License: MIT License | 6 votes |
@Test public void testintArrayUpdateNull() throws InterruptedException { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsIntegerArrayValues()); this.sqlgGraph.tx().normalBatchModeOn(); int[] intArray = new int[]{1, 2}; Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "intArray1", intArray); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "intArray2", intArray); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "intArray3", intArray); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); int[] intArrayAgain = new int[]{3, 4}; a1.property("intArray1", intArrayAgain); a2.property("intArray2", intArrayAgain); a3.property("intArray3", intArrayAgain); this.sqlgGraph.tx().commit(); testintArrayUpdateNull_assert(this.sqlgGraph, a1, a2, a3, intArrayAgain); if (this.sqlgGraph1 != null) { sleep(SLEEP_TIME); testintArrayUpdateNull_assert(this.sqlgGraph1, a1, a2, a3, intArrayAgain); } }
Example #7
Source Project: tinkerpop Author: apache File: AddEdgeTest.java License: Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) public void g_V_aggregateXxX_asXaX_selectXxX_unfold_addEXexistsWithX_toXaX_propertyXtime_nowX() { final Traversal<Vertex, Edge> traversal = get_g_V_aggregateXxX_asXaX_selectXxX_unfold_addEXexistsWithX_toXaX_propertyXtime_nowX(); printTraversalForm(traversal); int count = 0; while (traversal.hasNext()) { final Edge edge = traversal.next(); assertEquals("existsWith", edge.label()); assertEquals("now", g.E(edge).values("time").next()); assertEquals(1, g.E(edge).properties().count().next().intValue()); count++; } assertEquals(36, count); assertEquals(42, IteratorUtils.count(g.E())); for (final Vertex vertex : IteratorUtils.list(g.V())) { assertEquals(6, g.V(vertex).out("existsWith").count().next().intValue()); assertEquals(6, g.V(vertex).in("existsWith").count().next().intValue()); } assertEquals(6, IteratorUtils.count(g.V())); }
Example #8
Source Project: timbuctoo Author: HuygensING File: RelationTypeDescription.java License: GNU General Public License v3.0 | 6 votes |
public RelationTypeDescription(Vertex vertex) { setId(vertex.<String>property("tim_id").value()); setType(vertex.<String>property("types").value()); setRegularName(vertex.<String>property("relationtype_regularName").value()); setInverseName(vertex.<String>property("relationtype_inverseName").value()); setSourceTypeName(vertex.<String>property("relationtype_sourceTypeName").value()); setTargetTypeName(vertex.<String>property("relationtype_targetTypeName").value()); vertex.<String>property("created").ifPresent(this::setCreated); vertex.<String>property("modified").ifPresent(this::setModified); setRev(vertex.<Integer>property("rev").value()); setReflexive(vertex.<Boolean>property("relationtype_reflexive").value()); setDerived(vertex.<Boolean>property("relationtype_derived").value()); setSymmetric(vertex.<Boolean>property("relationtype_symmetric").value()); }
Example #9
Source Project: timbuctoo Author: HuygensING File: TinkerPopOperations.java License: GNU General Public License v3.0 | 6 votes |
private void saveRelationType(RelationType relationType) { final String rdfUri = TIMBUCTOO_NAMESPACE + relationType.getOutName(); final String[] rdfAlternatives = {TIMBUCTOO_NAMESPACE + relationType.getInverseName()}; final Vertex vertex = graph.addVertex( T.label, "relationtype", "rev", 1, "types", jsnA(jsn("relationtype")).toString(), "isLatest", true, "tim_id", relationType.getTimId().toString(), "relationtype_regularName", relationType.getOutName(), "relationtype_inverseName", relationType.getInverseName(), "relationtype_sourceTypeName", relationType.getSourceTypeName(), "relationtype_targetTypeName", relationType.getTargetTypeName(), "relationtype_reflexive", relationType.isReflexive(), "relationtype_symmetric", relationType.isSymmetric(), "relationtype_derived", relationType.isDerived(), "rdfUri", rdfUri, "rdfAlternatives", rdfAlternatives ); systemPropertyModifier.setCreated(vertex, "timbuctoo", "timbuctoo"); }
Example #10
Source Project: hugegraph Author: hugegraph File: VertexAPI.java License: Apache License 2.0 | 6 votes |
@DELETE @Timed @Path("{id}") @Consumes(APPLICATION_JSON) @RolesAllowed({"admin", "$owner=$graph $action=vertex_delete"}) public void delete(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String idValue) { LOG.debug("Graph [{}] remove vertex by id '{}'", graph, idValue); Id id = checkAndParseVertexId(idValue); HugeGraph g = graph(manager, graph); // TODO: add removeVertex(id) to improve commit(g, () -> { Iterator<Vertex> iter = g.vertices(id); try { E.checkArgument(iter.hasNext(), "No such vertex with id: '%s'", idValue); iter.next().remove(); } finally { CloseableIterator.closeIterator(iter); } }); }
Example #11
Source Project: hgraphdb Author: rayokota File: VertexModel.java License: Apache License 2.0 | 6 votes |
public Iterator<Vertex> verticesInRange(String label, String key, Object inclusiveFrom, Object exclusiveTo) { ElementHelper.validateProperty(key, inclusiveFrom); ElementHelper.validateProperty(key, exclusiveTo); IndexMetadata index = graph.getIndex(OperationType.READ, ElementType.VERTEX, label, key); if (index != null) { LOGGER.debug("Using vertex index for ({}, {})", label, key); return graph.getVertexIndexModel().verticesInRange(label, index.isUnique(), key, inclusiveFrom, exclusiveTo); } final VertexReader parser = new VertexReader(graph); byte[] fromVal = ValueUtils.serializePropertyValue(graph, ElementType.VERTEX, label, key, inclusiveFrom); byte[] toVal = ValueUtils.serializePropertyValue(graph, ElementType.VERTEX, label, key, exclusiveTo); final byte[] keyBytes = Bytes.toBytes(key); Scan scan = getPropertyScan(label, keyBytes, fromVal, toVal); ResultScanner scanner = null; try { scanner = table.getScanner(scan); return HBaseGraphUtils.mapWithCloseAtEnd(scanner, parser::parse); } catch (IOException e) { throw new HBaseGraphException(e); } }
Example #12
Source Project: tinkerpop Author: apache File: StarGraphTest.java License: Apache License 2.0 | 6 votes |
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) public void shouldAttachWithCreateMethod() { final Random random = TestHelper.RANDOM; StarGraph starGraph = StarGraph.open(); Vertex starVertex = starGraph.addVertex(T.label, "person", "name", "stephen", "name", "spmallete"); starVertex.property("acl", true, "timestamp", random.nextLong(), "creator", "marko"); for (int i = 0; i < 100; i++) { starVertex.addEdge("knows", starGraph.addVertex("person", "name", new UUID(random.nextLong(), random.nextLong()), "since", random.nextLong())); starGraph.addVertex(T.label, "project").addEdge("developedBy", starVertex, "public", random.nextBoolean()); } final Vertex createdVertex = starGraph.getStarVertex().attach(Attachable.Method.create(graph)); starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(edge -> ((Attachable<Edge>) edge).attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex))); TestHelper.validateEquality(starVertex, createdVertex); }
Example #13
Source Project: sqlg Author: pietermartin File: SqlgAddVertexStartStep.java License: MIT License | 6 votes |
@Override protected Traverser.Admin<Vertex> processNextStart() { if (this.first) { this.first = false; final SqlgTraverserGenerator generator = SqlgTraverserGenerator.instance(); final Vertex vertex = this.getTraversal().getGraph().get().addVertex( this.parameters.getKeyValues( generator.generate(false, (Step)this, 1L, false, false) )); if (this.callbackRegistry != null && !this.callbackRegistry.getCallbacks().isEmpty()) { final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get(); final Event.VertexAddedEvent vae = new Event.VertexAddedEvent(eventStrategy.detach(vertex)); this.callbackRegistry.getCallbacks().forEach(c -> c.accept(vae)); } return generator.generate(vertex, (Step)this, 1L, false, false); } else throw FastNoSuchElementException.instance(); }
Example #14
Source Project: timbuctoo Author: HuygensING File: EdgeListFacetDescriptionTest.java License: GNU General Public License v3.0 | 6 votes |
@Test public void filterAddsNoFilterIfTheFacetValuesIsEmpty() { List<FacetValue> facetValues = Lists.newArrayList( new ListFacetValue(FACET_NAME, Lists.newArrayList())); SearchRequestV2_1 searchRequest = new SearchRequestV2_1(); searchRequest.setFacetValues(facetValues); GraphTraversal<Vertex, Vertex> traversal = newGraph() .withVertex(v -> v.withTimId("1")) .withVertex(v -> v.withTimId("2")) .build().traversal().V(); instance.filter(traversal, facetValues); assertThat(traversal.toList(), containsInAnyOrder(VertexMatcher.likeVertex().withTimId("1"), VertexMatcher.likeVertex().withTimId("2"))); }
Example #15
Source Project: grakn Author: graknlabs File: LabelFragment.java License: GNU Affero General Public License v3.0 | 5 votes |
@Override public GraphTraversal<Vertex, ? extends Element> applyTraversalInner( GraphTraversal<Vertex, ? extends Element> traversal, ConceptManager conceptManager, Collection<Variable> vars) { Set<Integer> labelIds = labels().stream().map(label -> conceptManager.convertToId(label).getValue()).collect(toSet()); if (labelIds.size() == 1) { int labelId = Iterables.getOnlyElement(labelIds); return traversal.has(LABEL_ID.name(), labelId); } else { return traversal.has(LABEL_ID.name(), P.within(labelIds)); } }
Example #16
Source Project: windup Author: windup File: QuickfixService.java License: Eclipse Public License 1.0 | 5 votes |
/** * Tries to find a link with the specified description and href. If it cannot, then it will return a new one. */ @SuppressWarnings("unchecked") public QuickfixModel getOrCreate(String name, QuickfixType type) { Iterable<Vertex> results = (Iterable<Vertex>)getQuery().getRawTraversal().has(QuickfixModel.PROPERTY_TYPE, type).has(QuickfixModel.PROPERTY_DESCRIPTION, name).toList(); if (!results.iterator().hasNext()) { QuickfixModel model = create(); model.setQuickfixType(type); model.setName(name); return model; } return frame(results.iterator().next()); }
Example #17
Source Project: tinkerpop Author: apache File: ReferenceVertexPropertyTest.java License: Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldNotBeEqualsPropertiesAsIdIsDifferent() { final Vertex v = graph.addVertex(); final VertexProperty vp1 = v.property(VertexProperty.Cardinality.single, "test", "this"); final ReferenceVertexProperty mp1 = ReferenceFactory.detach(vp1); final VertexProperty vp2 = v.property(VertexProperty.Cardinality.single, "testing", "this"); final ReferenceVertexProperty mp2 = ReferenceFactory.detach(vp2); assertFalse(mp1.equals(mp2)); }
Example #18
Source Project: sqlg Author: pietermartin File: TestLoadSchema.java License: MIT License | 5 votes |
@Test public void testLoadingLocalTime() { Vertex v = this.sqlgGraph.addVertex(T.label, "Person", "createOn", LocalTime.now()); this.sqlgGraph.tx().commit(); this.sqlgGraph.close(); //noinspection Duplicates try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { Vertex vv = sqlgGraph1.traversal().V(v.id()).next(); Assert.assertTrue(vv.property("createOn").isPresent()); Map<String, PropertyType> propertyTypeMap = sqlgGraph1.getTopology().getAllTables().get(SchemaTable.of( sqlgGraph1.getSqlDialect().getPublicSchema(), "V_Person").toString()); Assert.assertTrue(propertyTypeMap.containsKey("createOn")); sqlgGraph1.tx().rollback(); } }
Example #19
Source Project: sqlg Author: pietermartin File: TestLocalDate.java License: MIT License | 5 votes |
@Test public void testDuration2() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "duration", Duration.ofSeconds(1, 1)); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "duration", Duration.ofSeconds(1, 1)); a1.addEdge("test", a2, "duration", Duration.ofSeconds(2, 2)); this.sqlgGraph.tx().commit(); Assert.assertEquals(Duration.ofSeconds(1, 1), this.sqlgGraph.traversal().V(a1.id()).next().value("duration")); Assert.assertEquals(Duration.ofSeconds(1, 1), this.sqlgGraph.traversal().V(a2.id()).next().value("duration")); Assert.assertEquals(Duration.ofSeconds(2, 2), this.sqlgGraph.traversal().V(a1.id()).outE().next().value("duration")); Assert.assertEquals(Duration.ofSeconds(1, 1), this.sqlgGraph.traversal().V(a1.id()).out().next().value("duration")); }
Example #20
Source Project: janusgraph_tutorial Author: marcelocf File: LoadData.java License: Apache License 2.0 | 5 votes |
private Vertex[] generateStatusUpdates(Vertex user, int count){ Vertex[] updates = new Vertex[count]; for(int i=0; i < count; i++) { updates[i] = addStatusUpdatew(user, getContent()); } return updates; }
Example #21
Source Project: tinkerpop Author: apache File: IoVertexTest.java License: Apache License 2.0 | 5 votes |
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldReadWriteVertexMultiPropsNoEdges() throws Exception { final Vertex v1 = graph.addVertex("name", "marko", "name", "mark", "acl", "rw"); v1.property(VertexProperty.Cardinality.single, "propsSquared", 123, "x", "a", "y", "b"); final Vertex v2 = graph.addVertex(); v1.addEdge("friends", v2, "weight", 0.5d); try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { final GraphWriter writer = writerMaker.apply(graph); writer.writeVertex(os, v1); final AtomicBoolean called = new AtomicBoolean(false); final GraphReader reader = readerMaker.apply(graph); try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) { reader.readVertex(bais, attachable -> { final Vertex detachedVertex = attachable.get(); assertEquals(v1.id(), assertViaDirectEquality ? detachedVertex.id() : graph.vertices(detachedVertex.id().toString()).next().id()); assertEquals(v1.label(), detachedVertex.label()); assertEquals(4, IteratorUtils.count(detachedVertex.properties())); assertEquals("a", detachedVertex.property("propsSquared").value("x")); assertEquals("b", detachedVertex.property("propsSquared").value("y")); assertEquals(2, IteratorUtils.count(detachedVertex.properties("name"))); assertTrue(IteratorUtils.stream(detachedVertex.properties("name")).allMatch(p -> p.key().equals("name") && (p.value().equals("marko") || p.value().equals("mark")))); assertEquals(v1.value("acl"), detachedVertex.value("acl").toString()); called.set(true); return mock(Vertex.class); }); } assertTrue(called.get()); } }
Example #22
Source Project: timbuctoo Author: HuygensING File: D3GraphTest.java License: GNU General Public License v3.0 | 5 votes |
@Test public void addNodeAddsNodeForVertexWhenNodesDoesNotContainTheVertexAsANode() throws IOException { D3Graph underTest = new D3Graph(); Vertex mockVertex1 = mockVertex("1", "document", "document_title", "title1"); Vertex mockVertex2 = mockVertex("2", "document", "document_title", "title2"); underTest.addNode(mockVertex1, null); underTest.addNode(mockVertex2, null); assertThat(underTest.getNodes(), contains( new Node(mockVertex1, null), new Node(mockVertex2, null) )); }
Example #23
Source Project: sqlg Author: pietermartin File: TestTopology.java License: MIT License | 5 votes |
@Test public void testAddColumns(){ //Create Schema Topology topology = sqlgGraph.getTopology(); topology.ensureSchemaExist("TEST"); Map<String, Object> columns = new HashMap<>(); columns.put("Test1", ""); columns.put("Test2", ""); //Add a vertex and remove to create columns Vertex v = sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns); v.remove(); sqlgGraph.tx().commit(); columns = new HashMap<>(); columns.put("Test1", "T1"); columns.put("Test2", "T2"); //Add the data sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns); sqlgGraph.tx().commit(); //Simulating second load //Remove the whole table label Optional<VertexLabel> tableVertexLabel = sqlgGraph.getTopology().getVertexLabel("TEST", "TEST_Table"); tableVertexLabel.ifPresent(vertexLabel -> vertexLabel.remove(false)); columns = new HashMap<>(); columns.put("Test1", ""); columns.put("Test2", ""); columns.put("Test3", ""); //Add a vertex with more columns than previously had v = sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns); v.remove(); sqlgGraph.tx().commit(); }
Example #24
Source Project: tinkergraph-gremlin Author: ShiftLeftSecurity File: TinkerIoRegistryV1d0.java License: Apache License 2.0 | 5 votes |
@Override public void serializeWithType(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.CLASS, TinkerGraph.class.getName()); jsonGenerator.writeFieldName(GraphSONTokens.VERTICES); jsonGenerator.writeStartArray(); jsonGenerator.writeString(ArrayList.class.getName()); jsonGenerator.writeStartArray(); final Iterator<Vertex> vertices = graph.vertices(); while (vertices.hasNext()) { GraphSONUtil.writeWithType(vertices.next(), jsonGenerator, serializerProvider, typeSerializer); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndArray(); jsonGenerator.writeFieldName(GraphSONTokens.EDGES); jsonGenerator.writeStartArray(); jsonGenerator.writeString(ArrayList.class.getName()); jsonGenerator.writeStartArray(); final Iterator<Edge> edges = graph.edges(); while (edges.hasNext()) { GraphSONUtil.writeWithType(edges.next(), jsonGenerator, serializerProvider, typeSerializer); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); }
Example #25
Source Project: sqlg Author: pietermartin File: TestGraphStepOrderBy.java License: MIT License | 5 votes |
@Test public void testOrderByInSchemas() { Vertex a = this.sqlgGraph.addVertex(T.label, "A.A", "name", "a"); Vertex b = this.sqlgGraph.addVertex(T.label, "A.A", "name", "b"); Vertex c = this.sqlgGraph.addVertex(T.label, "A.A", "name", "c"); this.sqlgGraph.tx().commit(); List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A.A").order().by("name", Order.decr).toList(); Assert.assertEquals(c, vertices.get(0)); Assert.assertEquals(b, vertices.get(1)); Assert.assertEquals(a, vertices.get(2)); }
Example #26
Source Project: tinkerpop Author: apache File: VertexTest.java License: Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_hasLabelXpersonX_V_hasLabelXsoftwareX_name() { final Traversal<Vertex, String> traversal = get_g_V_hasLabelXpersonX_V_hasLabelXsoftwareX_name(); printTraversalForm(traversal); checkResults(Arrays.asList("lop", "lop", "lop", "lop", "ripple", "ripple", "ripple", "ripple"), traversal); }
Example #27
Source Project: windup Author: windup File: CleanFromMultipleSourceFiles.java License: Eclipse Public License 1.0 | 5 votes |
private String groupByProjectModelFunction(final GraphContext context, final Vertex vertex) { JavaSourceFileModel javaModel = context.getFramed().frameElement(vertex, JavaSourceFileModel.class); // String that identifies 3 properties - projectModel + packageName + className that must be the same for vertices ProjectModel projectModel = javaModel.getProjectModel(); String projectModelID = projectModel == null ? "" : projectModel.getId().toString(); String packageName = javaModel.getPackageName() == null ? "" : javaModel.getPackageName(); return projectModelID + "_" + packageName + "_" + javaModel.getFileName(); }
Example #28
Source Project: tinkerpop Author: apache File: EventStrategyProcessTest.java License: Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldTriggerAddEdge() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final Vertex v = graph.addVertex(); v.addEdge("self", v); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).as("v").addE("self").to("v").next(); tryCommit(graph, g -> assertEquals(2, IteratorUtils.count(gts.E()))); assertEquals(0, listener1.addVertexEventRecorded()); assertEquals(0, listener2.addVertexEventRecorded()); assertEquals(1, listener1.addEdgeEventRecorded()); assertEquals(1, listener2.addEdgeEventRecorded()); }
Example #29
Source Project: sqlg Author: pietermartin File: TestLocalVertexStepOptional.java License: MIT License | 5 votes |
@Test public void testUnoptimizableChooseStep() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B"); a1.addEdge("ab", b1); a1.addEdge("ab", b2); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>)this.sqlgGraph.traversal() .V(a1) .local( __.<Vertex, Vertex>choose( v -> v.label().equals("A"), __.out(), __.in() ) ); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgLocalStepBarrier); SqlgLocalStepBarrier<?, ?> localStep = (SqlgLocalStepBarrier) traversal.getSteps().get(1); List<SqlgVertexStep> sqlgVertexStepCompileds = TraversalHelper.getStepsOfAssignableClassRecursively(SqlgVertexStep.class, localStep.getLocalChildren().get(0)); Assert.assertEquals(2, sqlgVertexStepCompileds.size()); SqlgVertexStep sqlgVertexStepCompiled = sqlgVertexStepCompileds.get(0); assertStep(sqlgVertexStepCompiled, false, false, false, true); sqlgVertexStepCompiled = sqlgVertexStepCompileds.get(1); assertStep(sqlgVertexStepCompiled, false, false, false, true); Assert.assertEquals(2, vertices.size()); }
Example #30
Source Project: tinkerpop Author: apache File: AndTest.java License: Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_hasXname_markoX_and_hasXname_markoX_and_hasXname_markoX() { final Traversal<Vertex, Vertex> traversal = get_g_V_hasXname_markoX_and_hasXname_markoX_and_hasXname_markoX(); printTraversalForm(traversal); checkResults(Collections.singletonList(convertToVertex(graph, "marko")), traversal); }