title: Threadsafe domain model getOrCreate in SDN?
body: <p>Working with SDN 2.1.0.BUILD-SNAPSHOT</p>
  
  <p>Is there a Domain-level, threadsafe way of executing a getOrCreate?</p>
  
  <p>I have </p>
  
  <pre><code>@NodeEntity
  public class ResourceEntity  extends Entity {
  
  @Fetch
  @Indexed(unique=true)
  String url;
  
  @Fetch
  String platform;
  }
  </code></pre>
  
  <p>What I want is to be able to access a neo4j REST database, and either add a new ResourceEntity, or retrieve one already there, if there's already one with a specified url field...</p>
  
  <p>What I can't find is a way of doing that atomically. And it needs to work atomically, as there will be multiple threads calling this code.</p>
  
  <pre><code>neo4jTemplate.save(resourceEntity);
  </code></pre>
  
  <p>throws (as it should) a org.springframework.dao.DataIntegrityViolationException if I attempt to insert a ResourceEntity with a duplicate key, but what <em>isn't</em> exposed on Neo4jTemplate at domain level is getOrCreate, which is what I want. How do I achieve that in SDN without having to do something untidy like</p>
  
  <pre><code>Map&lt;String, Object&gt; properties = new HashMap&lt;String, Object&gt;();
  properties.put("url", url);
  properties.put("__type__", "com.mydomain.analysis.thingie.dao.ResourceEntity");
  
  Node node = neo4jTemplate.getOrCreateNode("ResourceEntity", "url", "url", properties);
  </code></pre>
  
  <p>...and then pull the new ResourceEntity back from a repository or something similar... nasty!(i haven't tested that but I think that would work) -- but it's VERY ugly!</p>