use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.
the class Neo4jJsonCodecTest method testPathWriting.
@Test
public void testPathWriting() throws IOException {
//Given
Path path = mock(Path.class);
PropertyContainer propertyContainer = mock(PropertyContainer.class);
when(propertyContainer.getAllProperties()).thenThrow(RuntimeException.class);
when(path.iterator()).thenReturn(Arrays.asList(propertyContainer).listIterator());
//When
try {
jsonCodec.writeValue(jsonGenerator, path);
} catch (Exception ignored) {
}
//Then
verify(jsonGenerator, times(1)).writeEndArray();
}
use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.
the class PropertyContainerProxyTest method shouldListAllProperties.
@Test
public void shouldListAllProperties() {
// Given
Map<String, Object> properties = new HashMap<>();
properties.put("boolean", true);
properties.put("short_string", "abc");
properties.put("string", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW" + "XYZabcdefghijklmnopqrstuvwxyz");
properties.put("long", Long.MAX_VALUE);
properties.put("short_array", new long[] { 1, 2, 3, 4 });
properties.put("array", new long[] { Long.MAX_VALUE - 1, Long.MAX_VALUE - 2, Long.MAX_VALUE - 3, Long.MAX_VALUE - 4, Long.MAX_VALUE - 5, Long.MAX_VALUE - 6, Long.MAX_VALUE - 7, Long.MAX_VALUE - 8, Long.MAX_VALUE - 9, Long.MAX_VALUE - 10, Long.MAX_VALUE - 11 });
long containerId;
try (Transaction tx = db.beginTx()) {
containerId = createPropertyContainer();
PropertyContainer container = lookupPropertyContainer(containerId);
for (Map.Entry<String, Object> entry : properties.entrySet()) {
container.setProperty(entry.getKey(), entry.getValue());
}
tx.success();
}
// When
Map<String, Object> listedProperties;
try (Transaction tx = db.beginTx()) {
listedProperties = lookupPropertyContainer(containerId).getAllProperties();
tx.success();
}
// Then
assertEquals(properties.size(), listedProperties.size());
for (String key : properties.keySet()) {
assertObjectOrArrayEquals(properties.get(key), listedProperties.get(key));
}
}
use of org.neo4j.graphdb.PropertyContainer in project neo4j-apoc-procedures by neo4j-contrib.
the class Atomic method concat.
/**
* concat a property's value
*/
@Procedure(mode = Mode.WRITE)
@Description("apoc.atomic.concat(node/relatonship,propertyName,string) Concats the property's value with the 'string' value")
public Stream<AtomicResults> concat(@Name("container") Object container, @Name("propertyName") String property, @Name("string") String string, @Name(value = "times", defaultValue = "5") Long times) {
checkIsPropertyContainer(container);
PropertyContainer propertyContainer;
final String[] newValue = new String[1];
final String[] oldValue = new String[1];
propertyContainer = (PropertyContainer) container;
final ExecutionContext executionContext = new ExecutionContext(db, propertyContainer, property);
retry(executionContext, (context) -> {
oldValue[0] = propertyContainer.getProperty(property).toString();
newValue[0] = oldValue[0].toString().concat(string);
propertyContainer.setProperty(property, newValue[0]);
return context.propertyContainer.getProperty(property);
}, times);
return Stream.of(new AtomicResults(propertyContainer, property, oldValue[0], newValue[0]));
}
use of org.neo4j.graphdb.PropertyContainer in project neo4j-apoc-procedures by neo4j-contrib.
the class Atomic method add.
/**
* increment a property's value
*/
@Procedure(mode = Mode.WRITE)
@Description("apoc.atomic.add(node/relatonship,propertyName,number) Sums the property's value with the 'number' value ")
public Stream<AtomicResults> add(@Name("container") Object container, @Name("propertyName") String property, @Name("number") Number number, @Name(value = "times", defaultValue = "5") Long times) {
checkIsPropertyContainer(container);
PropertyContainer propertyContainer;
final Number[] newValue = new Number[1];
final Number[] oldValue = new Number[1];
propertyContainer = (PropertyContainer) container;
final ExecutionContext executionContext = new ExecutionContext(db, propertyContainer, property);
retry(executionContext, (context) -> {
oldValue[0] = (Number) propertyContainer.getProperty(property);
newValue[0] = AtomicUtils.sum((Number) propertyContainer.getProperty(property), number);
propertyContainer.setProperty(property, newValue[0]);
return context.propertyContainer.getProperty(property);
}, times);
return Stream.of(new AtomicResults(propertyContainer, property, oldValue[0], newValue[0]));
}
use of org.neo4j.graphdb.PropertyContainer in project graphdb by neo4j-attic.
the class Dijkstra method getPath.
/**
* @return One of the shortest paths found or null.
*/
public List<PropertyContainer> getPath() {
if (startNode == null || endNode == null) {
throw new RuntimeException("Start or end node undefined.");
}
calculate();
if (foundPathsMiddleNodes == null || foundPathsMiddleNodes.size() == 0) {
return null;
}
Node middleNode = foundPathsMiddleNodes.iterator().next();
LinkedList<PropertyContainer> path = new LinkedList<PropertyContainer>();
path.addAll(Util.constructSinglePathToNode(middleNode, predecessors1, true, false));
path.addAll(Util.constructSinglePathToNode(middleNode, predecessors2, false, true));
return path;
}
Aggregations