org.apache.tinkerpop.gremlin.structure.Property Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.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: TestLocalDateArray.java From sqlg with MIT License | 6 votes |
@Test public void testPeriodArray() { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsIntegerArrayValues()); Period[] periods = new Period[]{Period.of(2016, 5, 5), Period.of(2015, 4, 4)}; this.sqlgGraph.addVertex(T.label, "A", "periods", periods); this.sqlgGraph.tx().commit(); //Create a new sqlgGraph try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { List<? extends Property<Period[]>> properties = sqlgGraph1.traversal().V().hasLabel("A").<Period[]>properties("periods").toList(); Assert.assertEquals(1, properties.size()); Assert.assertTrue(properties.get(0).isPresent()); Period[] periodsFromDb = properties.get(0).value(); Assert.assertArrayEquals(periods, periodsFromDb); } }
Example #2
Source File: AbstractUntypedCompatibilityTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldReadWriteProperty() throws Exception { final String resourceName = "property"; assumeCompatibility(resourceName); final Property resource = findModelEntryObject(resourceName); final HashMap fromStatic = read(getCompatibility().readFromResource(resourceName), HashMap.class); final HashMap recycled = read(write(resource, Path.class), HashMap.class); assertNotSame(fromStatic, recycled); assertEquals(2, fromStatic.size()); assertEquals(resource.key(), fromStatic.get("key")); assertEquals(resource.value(), fromStatic.get("value")); assertEquals(2, recycled.size()); assertEquals(resource.key(), recycled.get("key")); assertEquals(resource.value(), recycled.get("value")); }
Example #3
Source File: Attachable.java From tinkerpop with Apache License 2.0 | 6 votes |
public static <V> Function<Attachable<V>, V> create(final Host hostVertexOrGraph) { return (Attachable<V> attachable) -> { final Object base = attachable.get(); if (base instanceof Vertex) { return hostVertexOrGraph instanceof Graph ? (V) Method.createVertex((Attachable<Vertex>) attachable, (Graph) hostVertexOrGraph) : (V) Method.createVertex((Attachable<Vertex>) attachable, (Vertex) hostVertexOrGraph); } else if (base instanceof Edge) { return hostVertexOrGraph instanceof Graph ? (V) Method.createEdge((Attachable<Edge>) attachable, (Graph) hostVertexOrGraph) : (V) Method.createEdge((Attachable<Edge>) attachable, (Vertex) hostVertexOrGraph); } else if (base instanceof VertexProperty) { return hostVertexOrGraph instanceof Graph ? (V) Method.createVertexProperty((Attachable<VertexProperty>) attachable, (Graph) hostVertexOrGraph) : (V) Method.createVertexProperty((Attachable<VertexProperty>) attachable, (Vertex) hostVertexOrGraph); } else if (base instanceof Property) { return hostVertexOrGraph instanceof Graph ? (V) Method.createProperty((Attachable<Property>) attachable, (Graph) hostVertexOrGraph) : (V) Method.createProperty((Attachable<Property>) attachable, (Vertex) hostVertexOrGraph); } else throw Attachable.Exceptions.providedAttachableMustContainAGraphObject(attachable); }; }
Example #4
Source File: HasContainer.java From tinkerpop with Apache License 2.0 | 6 votes |
public final boolean test(final Element element) { // it is OK to evaluate equality of ids via toString(), given that the test suite enforces the value of // id().toString() to be a first class representation of the identifier. a string test is only executed // if the predicate value is a String. this allows stuff like: g.V().has(id,lt(10)) to work properly if (this.key.equals(T.id.getAccessor())) return testingIdString ? testIdAsString(element) : testId(element); if (this.key.equals(T.label.getAccessor())) return testLabel(element); final Iterator<? extends Property> itty = element.properties(this.key); while (itty.hasNext()) { if (testValue(itty.next())) return true; } return false; }
Example #5
Source File: TestLocalDateArray.java From sqlg with MIT License | 6 votes |
@Test public void testZonedDateTimeArray2() { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalDateTimeArrayValues()); ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai"); ZonedDateTime zonedDateTimeAGT = ZonedDateTime.of(LocalDateTime.now(), zoneIdShanghai); ZoneId zoneIdHarare = ZoneId.of("Africa/Harare"); ZonedDateTime zonedDateTimeAGTHarare = ZonedDateTime.of(LocalDateTime.now(), zoneIdHarare); ZonedDateTime[] zonedDateTimes = new ZonedDateTime[]{zonedDateTimeAGT, zonedDateTimeAGTHarare}; this.sqlgGraph.addVertex(T.label, "A", "zonedDateTimes", zonedDateTimes); this.sqlgGraph.tx().commit(); //Create a new sqlgGraph //noinspection Duplicates try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { List<? extends Property<ZonedDateTime[]>> properties = sqlgGraph1.traversal().V().hasLabel("A").<ZonedDateTime[]>properties("zonedDateTimes").toList(); Assert.assertEquals(1, properties.size()); Assert.assertTrue(properties.get(0).isPresent()); ZonedDateTime[] value = properties.get(0).<ZonedDateTime[]>value(); Assert.assertArrayEquals(zonedDateTimes, value); } }
Example #6
Source File: PolymorphicTypeResolver.java From Ferma with Apache License 2.0 | 6 votes |
@Override public <P extends Element, T extends Element> GraphTraversal<P, T> hasNotType(final GraphTraversal<P, T> traverser, final Class<?> type) { final Set<? extends String> allAllowedValues = this.reflectionCache.getSubTypeNames(type.getName()); return traverser.filter(new Predicate<Traverser<T>>() { @Override public boolean test(final Traverser<T> toCheck) { final Property<String> property = toCheck.get().property(typeResolutionKey); if( !property.isPresent() ) return true; final String resolvedType = property.value(); if( allAllowedValues.contains(resolvedType) ) return false; else return true; } }); }
Example #7
Source File: BitsyEdge.java From bitsy with Apache License 2.0 | 6 votes |
@Override // THERE ARE TWO MORE COPIES OF THIS CODE IN ELEMENT AND VERTEX public <T> Iterator<Property<T>> properties(String... propertyKeys) { ArrayList<Property<T>> ans = new ArrayList<Property<T>>(); if (propertyKeys.length == 0) { if (this.properties == null) return Collections.emptyIterator(); propertyKeys = this.properties.getPropertyKeys(); } for (String key : propertyKeys) { Property<T> prop = property(key); if (prop.isPresent()) ans.add(prop); } return ans.iterator(); }
Example #8
Source File: TestLocalDate.java From sqlg with MIT License | 6 votes |
@Test public void testLocalDateTimeUpdate() { LocalDateTime now = LocalDateTime.now(); Vertex v = this.sqlgGraph.addVertex(T.label, "A", "dateTime", now); this.sqlgGraph.tx().commit(); v.property("dateTime", now.plusHours(1)); this.sqlgGraph.tx().commit(); //Create a new sqlgGraph try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { List<? extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("dateTime").toList(); Assert.assertEquals(1, properties.size()); Assert.assertTrue(properties.get(0).isPresent()); Assert.assertEquals(now.plusHours(1), properties.get(0).value()); } }
Example #9
Source File: Neo4JEdge.java From neo4j-gremlin-bolt with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public <V> Property<V> property(String name, V value) { ElementHelper.validateProperty(name, value); // validate bolt support Neo4JBoltSupport.checkPropertyValue(value); // transaction should be ready for io operations graph.tx().readWrite(); // property value for key Neo4JEdgeProperty<V> propertyValue = new Neo4JEdgeProperty<>(this, name, value); // update map properties.put(name, propertyValue); // set edge as dirty session.dirtyEdge(this); // update flag dirty = true; // return property return propertyValue; }
Example #10
Source File: Neo4JEdgeWhileGettingPropertiesTest.java From neo4j-gremlin-bolt with Apache License 2.0 | 6 votes |
@Test public void givenTwoKeysShouldShouldGetPropertyValues() { // arrange Mockito.when(graph.tx()).thenAnswer(invocation -> transaction); Mockito.when(relationship.get(Mockito.eq("id"))).thenAnswer(invocation -> Values.value(1L)); Mockito.when(relationship.type()).thenAnswer(invocation -> "label"); Mockito.when(relationship.keys()).thenAnswer(invocation -> Collections.singleton("key1")); Mockito.when(relationship.get(Mockito.eq("key1"))).thenAnswer(invocation -> Values.value("value1")); Mockito.when(provider.fieldName()).thenAnswer(invocation -> "id"); ArgumentCaptor<Long> argument = ArgumentCaptor.forClass(Long.class); Mockito.when(provider.processIdentifier(argument.capture())).thenAnswer(invocation -> argument.getValue()); Neo4JEdge edge = new Neo4JEdge(graph, session, provider, outVertex, relationship, inVertex); edge.property("p1", 1L); edge.property("p2", 1L); // act Iterator<Property<Long>> result = edge.properties("key1", "p2"); // assert Assert.assertNotNull("Failed to get properties", result); Assert.assertTrue("Property is not present", result.hasNext()); result.next(); Assert.assertTrue("Property is not present", result.hasNext()); result.next(); Assert.assertFalse("Too many properties in edge", result.hasNext()); }
Example #11
Source File: Neo4JEdgeWhileGettingPropertyValueTest.java From neo4j-gremlin-bolt with Apache License 2.0 | 6 votes |
@Test public void givenEdgeWithPropertyValueShouldShouldGetPropertyValue() { // arrange Mockito.when(graph.tx()).thenAnswer(invocation -> transaction); Mockito.when(relationship.get(Mockito.eq("id"))).thenAnswer(invocation -> Values.value(1L)); Mockito.when(relationship.type()).thenAnswer(invocation -> "label"); Mockito.when(relationship.keys()).thenAnswer(invocation -> Collections.singleton("key1")); Mockito.when(relationship.get(Mockito.eq("key1"))).thenAnswer(invocation -> Values.value("value1")); Mockito.when(provider.fieldName()).thenAnswer(invocation -> "id"); ArgumentCaptor<Long> argument = ArgumentCaptor.forClass(Long.class); Mockito.when(provider.processIdentifier(argument.capture())).thenAnswer(invocation -> argument.getValue()); Neo4JEdge edge = new Neo4JEdge(graph, session, provider, outVertex, relationship, inVertex); edge.property("p1", 1L); // act Property<?> result = edge.property("p1"); // assert Assert.assertNotNull("Failed to get property value", result); Assert.assertTrue("Property value is not present", result.isPresent()); Assert.assertEquals("Invalid property key", result.key(), "p1"); Assert.assertEquals("Invalid property value", result.value(), 1L); Assert.assertEquals("Invalid property element", result.element(), edge); }
Example #12
Source File: TestLocalDateArray.java From sqlg with MIT License | 6 votes |
@Test public void testZonedDateTimeArray() { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsZonedDateTimeArrayValues()); ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai"); ZonedDateTime zonedDateTimeAGT = ZonedDateTime.of(LocalDateTime.now(), zoneIdShanghai); ZoneId zoneIdHarare = ZoneId.of("Africa/Harare"); ZonedDateTime zonedDateTimeAGTHarare = ZonedDateTime.of(LocalDateTime.now(), zoneIdHarare); ZonedDateTime[] zonedDateTimes = {zonedDateTimeAGT, zonedDateTimeAGTHarare}; this.sqlgGraph.addVertex(T.label, "A", "zonedDateTimes", zonedDateTimes); this.sqlgGraph.tx().commit(); //Create a new sqlgGraph //noinspection Duplicates try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { List<? extends Property<ZonedDateTime[]>> properties = sqlgGraph1.traversal().V().hasLabel("A").<ZonedDateTime[]>properties("zonedDateTimes").toList(); Assert.assertEquals(1, properties.size()); Assert.assertTrue(properties.get(0).isPresent()); ZonedDateTime[] value = properties.get(0).<ZonedDateTime[]>value(); Assert.assertArrayEquals(zonedDateTimes, value); } }
Example #13
Source File: ComputerResultStep.java From tinkerpop with Apache License 2.0 | 5 votes |
public Iterator<Traverser.Admin<S>> attach(final Iterator<Traverser.Admin<S>> iterator, final Graph graph) { return IteratorUtils.map(iterator, traverser -> { traverser.setSideEffects(this.getTraversal().getSideEffects()); // necessary to ensure no NPE if (this.attachElements && (traverser.get() instanceof Attachable) && !(traverser.get() instanceof Property)) traverser.set((S) ((Attachable<Element>) traverser.get()).attach(Attachable.Method.get(graph))); return traverser; }); }
Example #14
Source File: ArangoDBVertexProperty.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
@Override public void remove() { logger.info("remove {}", this._id()); if (paired) { // Delete properties properties().forEachRemaining(Property::remove); } super.remove(); }
Example #15
Source File: TestHelper.java From tinkerpop with Apache License 2.0 | 5 votes |
public static void validatePropertyEquality(final Property originalProperty, final Property otherProperty) { assertEquals(originalProperty, otherProperty); assertEquals(otherProperty, originalProperty); if (originalProperty.isPresent()) { assertEquals(originalProperty.key(), otherProperty.key()); assertEquals(originalProperty.value(), otherProperty.value()); assertEquals(originalProperty.element(), otherProperty.element()); } }
Example #16
Source File: ValueTraversalTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldWorkOnVertexPropertyWithMissingKey() { final ValueTraversal<VertexProperty, Integer> t = new ValueTraversal<>("age"); final VertexProperty vp = mock(VertexProperty.class); when(vp.property("age")).thenReturn(Property.empty()); t.addStart(new B_O_Traverser<>(vp, 1).asAdmin()); assertNull(t.next()); }
Example #17
Source File: ElementHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldValidatePropertyAndNotAllowNullKey() { try { ElementHelper.validateProperty(null, "test"); fail("Should fail as property key cannot be null"); } catch (IllegalArgumentException iae) { assertEquals(Property.Exceptions.propertyKeyCanNotBeNull().getMessage(), iae.getMessage()); } }
Example #18
Source File: GraphSONSerializersV1d0.java From tinkerpop with Apache License 2.0 | 5 votes |
private void writeProperties(final Edge edge, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException { final Iterator<Property<Object>> elementProperties = normalize ? IteratorUtils.list(edge.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : edge.properties(); if (elementProperties.hasNext()) { jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES); if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName()); while (elementProperties.hasNext()) { final Property<Object> elementProperty = elementProperties.next(); GraphSONUtil.writeWithType(elementProperty.key(), elementProperty.value(), jsonGenerator, serializerProvider, typeSerializer); } jsonGenerator.writeEndObject(); } }
Example #19
Source File: BitsyElement.java From bitsy with Apache License 2.0 | 5 votes |
@Override public <T> Property<T> property(String key, T value) { if (value == null) { throw new IllegalArgumentException("A null property can not be stored. You can call removeProperty() instead"); } markForUpdate(); if (key == null) { throw new IllegalArgumentException("Expecting non-null key in setProperty"); } else if (key.length() == 0) { throw new IllegalArgumentException("Expecting non-empty key in setProperty"); } else if (key.equals("id")) { throw new IllegalArgumentException("Can not set the 'id' property on an element"); } else if (key.equals("label")) { throw new IllegalArgumentException("Can not set the 'label' property on an element"); } else if (key.charAt(0) == '~') { throw new IllegalArgumentException("Can not set a property beginning with ~ on an element"); } if (this.properties == null) { this.properties = new Dictionary1(key, value); } else { this.properties = properties.setProperty(key, value); } assert (properties != null); return new BitsyProperty<T>(this, key, value); }
Example #20
Source File: Properties.java From gremlin-ogm with Apache License 2.0 | 5 votes |
/** * Convert the key value array into a list of {@link Property}s. */ public static List<Property> list(Object... objects) { List<Property> properties = new ArrayList<>(); for (int i = 0; i < objects.length; i = i + 2) { String key = (String) objects[i]; Object value = objects[i + 1]; properties.add(new DetachedProperty<>(key, value)); } return properties; }
Example #21
Source File: ShortestDistanceMapReduce.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Override public void map(final Vertex vertex, final MapEmitter<Object, Long> emitter) { final Property distance = vertex.property(ShortestDistanceVertexProgram.DISTANCE); if (distance.isPresent()) { emitter.emit(vertex.id(), (Long) distance.value()); } }
Example #22
Source File: BlazeGraph.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * Binding set to property (for Edge and VertexProperty elements). */ private final <V> Function<BindingSet, Property<V>> property(final BlazeReifiedElement e) { return bs -> { log.debug(() -> bs); final URI key = (URI) bs.getValue("key"); final Literal val = (Literal) bs.getValue("val"); final BlazeProperty<V> prop = new BlazeProperty<>(BlazeGraph.this, e, key, val); return prop; }; }
Example #23
Source File: ElementHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldDetermineAbsentPropertyNotEqualToPresent() { Property<?> p1 = mock(Property.class); Property<?> p2 = mock(Property.class); when(p1.isPresent()).thenReturn(false); when(p2.isPresent()).thenReturn(true); assertFalse(ElementHelper.areEqual(p1, p2)); }
Example #24
Source File: ElementHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldDetermineAbsentPropertiesEqual() { Property<?> p1 = mock(Property.class); Property<?> p2 = mock(Property.class); when(p1.isPresent()).thenReturn(false); when(p2.isPresent()).thenReturn(false); assertTrue(ElementHelper.areEqual(p1, p2)); }
Example #25
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldReferencePropertyOfEdgeWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v); final String label = e.label(); final Object inId = v.id(); final Object outId = v.id(); e.property("to-change", "no!"); final MutationListener listener = new AbstractMutationListener() { @Override public void edgePropertyChanged(final Edge element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(ReferenceEdge.class)); assertEquals(label, element.label()); assertEquals(inId, element.inVertex().id()); assertEquals(outId, element.outVertex().id()); assertEquals("no!", oldValue.value()); assertEquals("to-change", 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.E(e).property("to-change","yay!").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.E(e).properties())); assertThat(triggered.get(), is(true)); }
Example #26
Source File: GraphTypeManager.java From windup with Eclipse Public License 1.0 | 5 votes |
private void addTokenProperty(Element el, String propertyName, String propertyValue) { Property<String> val = el.property(propertyName); if (!val.isPresent()) el.property(propertyName, propertyValue); else el.property(propertyName, val.value() + "|" + propertyValue); }
Example #27
Source File: DedupGlobalStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Map<Object, Traverser.Admin<S>> nextBarrier() throws NoSuchElementException { final Map<Object, Traverser.Admin<S>> map = null != this.barrier ? this.barrier : new HashMap<>(); while (this.starts.hasNext()) { final Traverser.Admin<S> traverser = this.starts.next(); final Object object; if (null != this.dedupLabels) { object = new ArrayList<>(this.dedupLabels.size()); for (final String label : this.dedupLabels) { ((List) object).add(TraversalUtil.applyNullable((S) this.getSafeScopeValue(Pop.last, label, traverser), this.dedupTraversal)); } } else { object = TraversalUtil.applyNullable(traverser, this.dedupTraversal); } if (!map.containsKey(object)) { traverser.setBulk(1L); // DetachedProperty and DetachedVertexProperty both have a transient for the Host element. that causes // trouble for olap which ends up requiring the Host later. can't change the transient without some // consequences: (1) we break gryo formatting and io tests start failing (2) storing the element with // the property has the potential to bloat detached Element instances as it basically stores that data // twice. Not sure if it's smart to change that at least in 3.4.x and not without some considerable // thought as to what might be major changes. To work around the problem we will detach properties as // references so that the parent element goes with it. Also, given TINKERPOP-2318 property comparisons // have changed in such a way that allows this to work properly if (traverser.get() instanceof Property) traverser.set(ReferenceFactory.detach(traverser.get())); else traverser.set(DetachedFactory.detach(traverser.get(), true)); map.put(object, traverser); } } this.barrier = null; this.barrierIterator = null; if (map.isEmpty()) throw FastNoSuchElementException.instance(); else return map; }
Example #28
Source File: FollowedBy.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override protected <V> Property<V> specificProperty(String key) { // note: use the statically defined strings to take advantage of `==` (pointer comparison) over `.equals` (String content comparison) for performance if (WEIGHT.equals(key) && weight != null) { return new TinkerProperty(this, key, weight); } else { return Property.empty(); } }
Example #29
Source File: BlazeReifiedElement.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * Safer default implementation that closes the iterator from properties(). */ @Override default <V> BlazeProperty<V> property(final String key) { try (CloseableIterator<? extends Property<V>> it = this.<V>properties(key)) { return it.hasNext() ? (BlazeProperty<V>) it.next() : EmptyBlazeProperty.instance(); } }
Example #30
Source File: AbstractTypedCompatibilityTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldReadWriteProperty() throws Exception { final String resourceName = "property"; assumeCompatibility(resourceName); final Property resource = findModelEntryObject(resourceName); final Property fromStatic = read(getCompatibility().readFromResource(resourceName), Property.class); final Property recycled = (Property) read(write(fromStatic, Property.class), getCompatibility().resolve(Property.class)); assertNotSame(fromStatic, recycled); assertProperty(resource, fromStatic); assertProperty(resource, recycled); }