Java Code Examples for org.apache.tinkerpop.gremlin.structure.Vertex#property()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Vertex#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: TestBatchNormalUpdatePrimitiveArrays.java From sqlg with MIT License | 6 votes |
@Test public void testBatchUpdateArrayFloat() throws InterruptedException { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsFloatArrayValues()); this.sqlgGraph.tx().normalBatchModeOn(); Vertex god = this.sqlgGraph.addVertex(T.label, "GOD", "array", new Float[]{1.1f, 2.2f}); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); god = this.sqlgGraph.traversal().V(god.id()).next(); god.property("array", new Float[]{6.6f, 7.7f}); this.sqlgGraph.tx().commit(); testBatchUpdateArrayFloat_assert(this.sqlgGraph, god); if (this.sqlgGraph1 != null) { Thread.sleep(SLEEP_TIME); testBatchUpdateArrayFloat_assert(this.sqlgGraph1, god); } }
Example 2
Source File: TestBatchNormalUpdatePrimitiveArrays.java From sqlg with MIT License | 6 votes |
@Test public void testfloatArrayUpdateNull() throws InterruptedException { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsFloatArrayValues()); this.sqlgGraph.tx().normalBatchModeOn(); float[] floatArray = new float[]{1F, 2F}; Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "floatArray1", floatArray); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "floatArray2", floatArray); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "floatArray3", floatArray); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); float[] floatArrayAgain = new float[]{3F, 4F}; a1.property("floatArray1", floatArrayAgain); a2.property("floatArray2", floatArrayAgain); a3.property("floatArray3", floatArrayAgain); this.sqlgGraph.tx().commit(); testfloatArrayUpdateNull_assert(this.sqlgGraph, a1, a2, a3, floatArrayAgain); if (this.sqlgGraph1 != null) { sleep(SLEEP_TIME); testfloatArrayUpdateNull_assert(this.sqlgGraph1, a1, a2, a3, floatArrayAgain); } }
Example 3
Source File: TestGlobalUniqueIndex.java From sqlg with MIT License | 6 votes |
@SuppressWarnings("OptionalGetWithoutIsPresent") @Test public void testUpdateUniqueProperty() { Map<String, PropertyType> properties = new HashMap<String, PropertyType>() {{ put("name", PropertyType.STRING); }}; VertexLabel personVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("Person", properties); this.sqlgGraph.getTopology().ensureGlobalUniqueIndexExist(new HashSet<PropertyColumn>() {{ add(personVertexLabel.getProperty("name").get()); }}); this.sqlgGraph.tx().commit(); Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person"); v1.property("name", "Joseph"); Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "Joe"); this.sqlgGraph.tx().commit(); v2 = this.sqlgGraph.traversal().V(v2.id()).next(); try { v2.property("name", "Joseph"); fail("Should not be able to call a person a pre-existing name."); } catch (Exception e) { //good } }
Example 4
Source File: TestBatchNormalUpdateDateTimeArrays.java From sqlg with MIT License | 6 votes |
@Test public void testUpdateLocalTimeArray() { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalTimeArrayValues()); this.sqlgGraph.tx().normalBatchModeOn(); LocalTime[] localTimeArray = new LocalTime[]{LocalTime.now(), LocalTime.now()}; Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "localTimeArray1", localTimeArray); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "localTimeArray2", localTimeArray); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "localTimeArray3", localTimeArray); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); LocalTime[] localTimeArrayAgain = new LocalTime[]{LocalTime.now().plusHours(1), LocalTime.now().plusHours(2)}; a1.property("localTimeArray1", localTimeArrayAgain); a2.property("localTimeArray2", localTimeArrayAgain); a3.property("localTimeArray3", localTimeArrayAgain); this.sqlgGraph.tx().commit(); testUpdateLocalTimeArray_assert(this.sqlgGraph, a1, a2, a3, localTimeArrayAgain); }
Example 5
Source File: CountVertexProgram.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
@Override public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { switch (memory.getIteration()) { case 0: messenger.sendMessage(messageScopeOut, 1L); break; case 1: if (messenger.receiveMessages().hasNext()) { vertex.property(EDGE_COUNT, getMessageCount(messenger)); } break; default: throw GraknAnalyticsException.unreachableStatement("Exceeded expected maximum number of iterations"); } }
Example 6
Source File: TestRemovedVertex.java From sqlg with MIT License | 5 votes |
@Test(expected = IllegalStateException.class) public void testExceptionOnRemovedVertex() { Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "john"); v1.remove(); v1.property("name", "peter"); Assert.fail("should have thrown exception"); }
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 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 8
Source File: TestBatchNormalUpdate.java From sqlg with MIT License | 5 votes |
@Test public void testUpdateWithCommaInValues() { this.sqlgGraph.tx().normalBatchModeOn(); Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name1", "a1", "name2", "a11", "name3", "a111"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name1", "a2", "name2", "a22", "name3", "a222"); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name1", "a3", "name2", "a33", "name3", "a333"); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); a1.property("name1", "a1,a2"); a2.property("name1", "a1,a2"); this.sqlgGraph.tx().commit(); }
Example 9
Source File: TransactionImpl.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
/** * Set a new type shard checkpoint for a given label */ private void setShardCheckpoint(Label label, long checkpoint) { Concept schemaConcept = getSchemaConcept(label); if (schemaConcept != null) { Vertex janusVertex = ConceptVertex.from(schemaConcept).vertex().element(); janusVertex.property(Schema.VertexProperty.TYPE_SHARD_CHECKPOINT.name(), checkpoint); } else { throw new RuntimeException("Label '" + label.getValue() + "' does not exist"); } }
Example 10
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 shouldTriggerAddVertexPropertyPropertyRemoved() { 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 vSome = graph.addVertex("some", "thing"); vSome.property(VertexProperty.Cardinality.single, "that", "thing", "is", "good"); final GraphTraversalSource gts = create(eventStrategy); final Vertex vAny = gts.V().addV().property("any", "thing").next(); gts.V(vAny).properties("any").property("is", "bad").next(); gts.V(vAny).properties("any").properties("is").drop().iterate(); tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("any", "thing")))); assertEquals(1, listener1.addVertexEventRecorded()); assertEquals(1, listener2.addVertexEventRecorded()); assertEquals(1, listener2.vertexPropertyPropertyChangedEventRecorded()); assertEquals(1, listener1.vertexPropertyPropertyChangedEventRecorded()); assertEquals(1, listener2.vertexPropertyPropertyRemovedEventRecorded()); assertEquals(1, listener1.vertexPropertyPropertyRemovedEventRecorded()); }
Example 11
Source File: MapInPropertiesHandler.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Getter */ private static Map<String, Object> handleGetter(Vertex vertex, Method method, Object[] args, MapInProperties ann) { if (args != null && args.length != 0) throw new WindupException("Method must take zero arguments"); Map<String, Object> map = new HashMap<>(); String prefix = preparePrefix(ann); Set<String> keys = vertex.keys(); for (String key : keys) { if (!key.startsWith(prefix)) continue; // Skip the type property if (key.equals(WindupFrame.TYPE_PROP)) continue; final Property<Object> val = vertex.property(key); if (!ann.propertyType().isAssignableFrom(val.value().getClass())) { log.warning("@InProperties is meant for Map<String," + ann.propertyType().getName() + ">, but the value was: " + val.getClass()); } map.put(key.substring(prefix.length()), val.value()); } return map; }
Example 12
Source File: GraphOMRSClassificationMapper.java From egeria with Apache License 2.0 | 5 votes |
private void removeProperty(Vertex vertex, String qualifiedPropName) { // no value has been specified - remove the property from the vertex VertexProperty vp = vertex.property(getPropertyKeyClassification(qualifiedPropName)); if (vp != null) { vp.remove(); } }
Example 13
Source File: TinkerGraphTransformationRepairSwitchMonitored.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
@Override public void activate(final Collection<TinkerGraphSwitchMonitoredMatch> matches) throws Exception { for (final TinkerGraphSwitchMonitoredMatch match : matches) { final Vertex sw = match.getSw(); final Vertex sensor = driver.getGraph().addVertex(SENSOR); sensor.property(ModelConstants.ID, driver.generateNewVertexId()); sw.addEdge(MONITORED_BY, sensor); } }
Example 14
Source File: Vre.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
private void saveProperties(Map<String, String> keywordTypes, Vertex vreVertex) { vreVertex.property(VRE_NAME_PROPERTY_NAME, vreName); try { if (!keywordTypes.isEmpty()) { vreVertex.property(KEYWORD_TYPES_PROPERTY_NAME, new ObjectMapper().writeValueAsString(keywordTypes)); } } catch (JsonProcessingException e) { LOG.error("Failed to serialize keyword types to JSON {}", keywordTypes); } }
Example 15
Source File: PageRankMapReduce.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Override public void map(final Vertex vertex, final MapEmitter<Object, Double> emitter) { final Property pageRank = vertex.property(PageRankVertexProgram.PAGE_RANK); if (pageRank.isPresent()) { emitter.emit(vertex.id(), (Double) pageRank.value()); } }
Example 16
Source File: MarvelGraphFactory.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
@Override public void run() { final long start = System.currentTimeMillis(); final Vertex vertex = graph.addVertex(); vertex.property(CHARACTER, character); // only sets weapon on character vertex on initial creation. vertex.property(WEAPON, WEAPONS.get(RANDOM.nextInt(WEAPONS.size()))); REGISTRY.counter(COUNTER_GET + CHARACTER).inc(); final long end = System.currentTimeMillis(); final long time = end - start; REGISTRY.timer(TIMER_CREATE + CHARACTER).update(time, TimeUnit.MILLISECONDS); }
Example 17
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
@Test public void testDualMapping() { if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) return; PropertyKey name = makeKey("name", String.class); TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX); mixed.name(); finishSchema(); tx.addVertex("name", "Long John Don"); tx.addVertex("name", "Long Little Lewis"); tx.addVertex("name", "Middle Sister Mabel"); clopen(); evaluateQuery(tx.query().has("name", Cmp.EQUAL, "Long John Don"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 2, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long Don"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.CONTAINS_PREFIX, "Lon"), ElementCategory.VERTEX, 2, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.CONTAINS_REGEX, "Lit*le"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.REGEX, "Long.*"), ElementCategory.VERTEX, 2, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mixed"); for (Vertex u : tx.getVertices()) { String n = u.<String>value("name"); if (n.endsWith("Don")) { u.remove(); } else if (n.endsWith("Lewis")) { u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob"); } else if (n.endsWith("Mabel")) { u.property("name").remove(); } } clopen(); evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 0, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.CONTAINS, "Big"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.PREFIX, "Big"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mixed"); evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 0, new boolean[]{true, true}, "mixed"); }
Example 18
Source File: ObjectVertexTest.java From act-platform with ISC License | 4 votes |
@Test public void testReturnEmptyPropertyIfKeyNonExistent() { Vertex vertex = createVertex(); VertexProperty property = vertex.property("something"); assertEquals(VertexProperty.empty(), property); }
Example 19
Source File: TestBasicOperations.java From tinkerpop3 with GNU General Public License v2.0 | 4 votes |
public void testRollback() throws Exception { final Vertex v1 = graph.addVertex("name", "marko"); final Edge e1 = v1.addEdge("l", v1, "name", "xxx"); graph.commit(); assertEquals(v1.id(), graph.vertices(v1.id()).next().id()); assertEquals(e1.id(), graph.edges(e1.id()).next().id()); assertEquals("marko", v1.<String>value("name")); assertEquals("xxx", e1.<String>value("name")); assertEquals("marko", v1.<String>value("name")); assertEquals("marko", graph.vertices(v1.id()).next().<String>value("name")); v1.property(VertexProperty.Cardinality.single, "name", "stephen"); assertEquals("stephen", v1.<String>value("name")); assertEquals("stephen", graph.vertices(v1.id()).next().<String>value("name")); graph.rollback(); assertEquals("marko", v1.<String>value("name")); assertEquals("marko", graph.vertices(v1.id()).next().<String>value("name")); }
Example 20
Source File: Util.java From jaeger-analytics-java with Apache License 2.0 | 4 votes |
public static void printVertex(Vertex vertex) { String operation = vertex.property(Keys.OPERATION_NAME) != null ? String.valueOf(vertex.property(Keys.OPERATION_NAME).value()) : "null"; String traceId = vertex.property(Keys.TRACE_ID) != null ? String.valueOf(vertex.property(Keys.TRACE_ID).value()) : "null"; String spanId = vertex.property(Keys.SPAN_ID) != null ? String.valueOf(vertex.property(Keys.SPAN_ID).value()) : "null"; System.out.printf("%s[%s:%s], tags = %s\n", operation, traceId, spanId, vertex.keys()); }