Java Code Examples for org.apache.tinkerpop.gremlin.structure.VertexProperty#property()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.VertexProperty#property() .
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 File: Attachable.java From tinkerpop with Apache License 2.0 | 6 votes |
public static Property createProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) { final Property baseProperty = attachableProperty.get(); final Element baseElement = baseProperty.element(); if (baseElement instanceof Vertex) { return Method.createVertexProperty((Attachable) attachableProperty, hostGraph); } else if (baseElement instanceof Edge) { final Iterator<Edge> edgeIterator = hostGraph.edges(baseElement.id()); if (edgeIterator.hasNext()) return edgeIterator.next().property(baseProperty.key(), baseProperty.value()); throw new IllegalStateException("Could not find edge to create the attachable property on"); } else { // vertex property final Iterator<Vertex> vertexIterator = hostGraph.vertices(((VertexProperty) baseElement).element().id()); if (vertexIterator.hasNext()) { final Vertex vertex = vertexIterator.next(); final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertex.properties(((VertexProperty) baseElement).key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty<Object> vp = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vp, baseElement)) return vp.property(baseProperty.key(), baseProperty.value()); } } throw new IllegalStateException("Could not find vertex property to create the attachable property on"); } }
Example 2
Source File: Attachable.java From tinkerpop with Apache License 2.0 | 6 votes |
public static Property createProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) { final Property baseProperty = attachableProperty.get(); final Element baseElement = baseProperty.element(); if (baseElement instanceof Vertex) { return Method.createVertexProperty((Attachable) attachableProperty, hostVertex); } else if (baseElement instanceof Edge) { final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT); if (edgeIterator.hasNext()) return edgeIterator.next().property(baseProperty.key(), baseProperty.value()); throw new IllegalStateException("Could not find edge to create the property on"); } else { // vertex property final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(((VertexProperty) baseElement).key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty<Object> vp = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vp, baseElement)) return vp.property(baseProperty.key(), baseProperty.value()); } throw new IllegalStateException("Could not find vertex property to create the attachable property on"); } }
Example 3
Source File: TestSearch.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * Make sure we can find all five kinds of properties: * <p> * <pre> * Edge -> Property * Vertex -> VertexProperty(single/set) * Vertex -> VertexProperty(list) * VertexProperty(single/set) -> Property * VertexProperty(list) -> Property * </pre> * </p> */ public void testAllFiveKinds() { final BlazeVertex a = graph.addVertex(T.id, "a"); final BlazeVertex b = graph.addVertex(T.id, "b"); final BlazeEdge e = graph.addEdge(a, b, Edge.DEFAULT_LABEL, T.id, "e"); final Property<String> ep = e.property("ep", "foo 1"); final VertexProperty<String> vps = a.property(Cardinality.single, "vps", "foo 2"); final VertexProperty<String> vpl = a.property(Cardinality.list, "vpl", "foo 3"); final Property<String> vpsp = vps.property("vpsp", "foo 4"); final Property<String> vplp = vpl.property("vplp", "foo 5"); graph.commit(); final Map<String,Property<String>> expected = new HashMap<String,Property<String>>() {{ put("foo 1", ep); put("foo 2", vps); put("foo 3", vpl); put("foo 4", vpsp); put("foo 5", vplp); }}; log.debug(() -> "\n"+graph.dumpStore()); final List<Property<String>> results = graph.<String>search("foo", Match.ANY).collect(); log.debug(() -> results.stream()); assertEquals(5, results.size()); results.stream().forEach(p -> { assertEquals(expected.get(p.value()), p); }); }
Example 4
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldDetachPropertyOfVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final VertexProperty vp = v.property("xxx","blah"); final String label = vp.label(); final Object value = vp.value(); vp.property("to-change", "dah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(DetachedVertexProperty.class)); assertEquals(label, element.label()); assertEquals(value, element.value()); assertEquals("dah", oldValue.value()); assertEquals("to-change", oldValue.key()); assertEquals("bah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).properties("xxx").property("to-change","bah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertEquals(1, IteratorUtils.count(g.V(v).properties().properties())); assertThat(triggered.get(), is(true)); }
Example 5
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldDetachPropertyOfVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final VertexProperty vp = v.property("xxx","blah"); final String label = vp.label(); final Object value = vp.value(); vp.property("to-change", "dah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(DetachedVertexProperty.class)); assertEquals(label, element.label()); assertEquals(value, element.value()); assertThat(oldValue, instanceOf(KeyedProperty.class)); assertEquals("new", oldValue.key()); assertEquals("yay!", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).properties("xxx").property("new","yay!").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertEquals(2, IteratorUtils.count(g.V(v).properties().properties())); assertThat(triggered.get(), is(true)); }
Example 6
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldReferencePropertyOfVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final VertexProperty vp = v.property("xxx","blah"); final String label = vp.label(); final Object value = vp.value(); vp.property("to-change", "dah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(ReferenceVertexProperty.class)); assertEquals(label, element.label()); assertEquals(value, element.value()); assertEquals("dah", oldValue.value()); assertEquals("to-change", oldValue.key()); assertEquals("bah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).properties("xxx").property("to-change","bah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertEquals(1, IteratorUtils.count(g.V(v).properties().properties())); assertThat(triggered.get(), is(true)); }
Example 7
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldReferencePropertyOfVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final VertexProperty vp = v.property("xxx","blah"); final String label = vp.label(); final Object value = vp.value(); vp.property("to-change", "dah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(ReferenceVertexProperty.class)); assertEquals(label, element.label()); assertEquals(value, element.value()); assertThat(oldValue, instanceOf(KeyedProperty.class)); assertEquals("new", oldValue.key()); assertEquals("yay!", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).properties("xxx").property("new","yay!").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertEquals(2, IteratorUtils.count(g.V(v).properties().properties())); assertThat(triggered.get(), is(true)); }
Example 8
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldUseActualPropertyOfVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final VertexProperty vp = v.property("xxx","blah"); final String label = vp.label(); final Object value = vp.value(); vp.property("to-change", "dah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) { assertEquals(vp, element); assertEquals(label, element.label()); assertEquals(value, element.value()); assertEquals("dah", oldValue.value()); assertEquals("to-change", oldValue.key()); assertEquals("bah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).properties("xxx").property("to-change","bah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertEquals(1, IteratorUtils.count(g.V(v).properties().properties())); assertThat(triggered.get(), is(true)); }
Example 9
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldUseActualPropertyOfVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final VertexProperty vp = v.property("xxx","blah"); final String label = vp.label(); final Object value = vp.value(); vp.property("to-change", "dah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) { assertEquals(vp, element); assertEquals(label, element.label()); assertEquals(value, element.value()); assertThat(oldValue, instanceOf(KeyedProperty.class)); assertEquals("new", oldValue.key()); assertEquals("yay!", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).properties("xxx").property("new","yay!").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertEquals(2, IteratorUtils.count(g.V(v).properties().properties())); assertThat(triggered.get(), is(true)); }
Example 10
Source File: NativeNeo4jStructureCheck.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldNotGenerateNodesAndRelationships() { graph.tx().readWrite(); tryCommit(graph, graph -> validateCounts(0, 0, 0, 0)); Vertex vertex = graph.addVertex(T.label, "person"); tryCommit(graph, graph -> validateCounts(1, 0, 1, 0)); vertex.property("name", "marko"); assertEquals("marko", vertex.value("name")); tryCommit(graph, graph -> validateCounts(1, 0, 1, 0)); vertex.property("name", "okram"); tryCommit(graph, g -> { validateCounts(1, 0, 1, 0); assertEquals("okram", vertex.value("name")); }); VertexProperty vertexProperty = vertex.property("name"); tryCommit(graph, graph -> { assertTrue(vertexProperty.isPresent()); assertEquals("name", vertexProperty.key()); assertEquals("okram", vertexProperty.value()); validateCounts(1, 0, 1, 0); }); try { vertexProperty.property("acl", "private"); } catch (UnsupportedOperationException e) { assertEquals(VertexProperty.Exceptions.metaPropertiesNotSupported().getMessage(), e.getMessage()); } }