neo4j/neo4j — pull request #1754 by nigelsmall (2013-12-21 15:43:50+00:00)
Title: PUT /label/{label}/nodes -- RESTful MERGE Operation

This enhancement adds a **PUT** handler for the **/label/{label}/nodes** server resource that introduces a MERGE-like facility for the REST interface. It takes a label and optional key-value pair as input and returns a new or existing node.

The bulk of the logic exists within `DatabaseActions.mergeNode` which attempts to find a match for the label/property, creating a new node if no match is found or returning the matching node otherwise. If multiple matches are found, an `OperationFailureException` is thrown.

The REST wrapper (in the `RestfulGraphDatabase` class) returns a single node representation (and so can be used in batches) along with a 200 or 201 status, depending on whether or not a new node was created. When multiple matches occur, a 409 status is returned with an error payload.

Note that the `mergeNode` method has two variants, one of which makes use of a mutable `AtomicBoolean` as a by-reference created/not-created indicator. This has been done as the method return value cannot express this information.