Skip to content

Commit 779d291

Browse files
committed
Further VertexDsl and GraphDsl improvements
* get property from vertex (optional) * get mandatory property from vertex (nullable) * get existing vertex type (optional) * renamed DSL types * refactored wrappers * updated readme / examples * scaladoc improvements
1 parent cd6a9dc commit 779d291

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+871
-1858
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ val g = new OrientGraphFactory("memory:orientDbScalaDslTest").getNoTx
8484
// add vertex
8585
g.dsl addVertex "Person" withProperty "name" -> "Frank"
8686
g.dsl addVertex "Customer" withProperty "name" -> "ACME" and "active" -> true
87+
g.dsl addVertex "Customer" withProperty "name" -> Some("ACME") and "active" -> None // only "name" is persisted
88+
g.dsl addVertex "Customer" withProperty "name" -> null // ugly, but no exception - don't work with null in Scala ;)
8789

8890
// find & filter
8991
g.dsl findVertices "City" single()
@@ -94,6 +96,12 @@ g.dsl findVertices "City" filter "name" -> "Zurich" list() take 3 // Iterable[Ve
9496
// edit existing
9597
val existing = g.dsl findVertices "Customer" single()
9698
existing foreach(_ withProperty "name" -> "ACME Software Solutions" and "year" -> 2017)
99+
100+
// get property
101+
val name: Option[String] = existing.flatMap(v => v.property[String]("name"))
102+
103+
// get mandatory property (nullable) - only use this with schema
104+
val name2: String = existing.map(v => v.mandatoryProperty[String]("name")).orNull
97105
```
98106

99107
Get Involved
Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

docs/api/2.11/ch/acmesoftware/orientDbScalaDsl/OrientGraphDsl.html renamed to docs/api/2.11/ch/acmesoftware/orientDbScalaDsl/GraphDsl.html

Lines changed: 64 additions & 47 deletions
Large diffs are not rendered by default.

docs/api/2.11/ch/acmesoftware/orientDbScalaDsl/VertexDsl.html

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,25 @@ <h4 class="signature">
333333
</a>
334334
</span>
335335
<div class="fullcomment"><dl class="attributes block"> <dt>Definition Classes</dt><dd>Any</dd></dl></div>
336+
</li><li name="ch.acmesoftware.orientDbScalaDsl.VertexDsl#mandatoryProperty" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
337+
<a id="mandatoryProperty[T](name:String):T"></a>
338+
<a id="mandatoryProperty[T](String):T"></a>
339+
<h4 class="signature">
340+
<span class="modifier_kind">
341+
<span class="modifier"></span>
342+
<span class="kind">def</span>
343+
</span>
344+
<span class="symbol">
345+
<span class="name">mandatoryProperty</span><span class="tparams">[<span name="T">T</span>]</span><span class="params">(<span name="name">name: <span class="extype" name="scala.Predef.String">String</span></span>)</span><span class="result">: <span class="extype" name="ch.acmesoftware.orientDbScalaDsl.VertexDsl.mandatoryProperty.T">T</span></span>
346+
</span>
347+
</h4><span class="permalink">
348+
<a href="../../../index.html#ch.acmesoftware.orientDbScalaDsl.VertexDsl@mandatoryProperty[T](name:String):T" title="Permalink" target="_top">
349+
<img src="../../../lib/permalink.png" alt="Permalink" />
350+
</a>
351+
</span>
352+
<p class="shortcomment cmt">Gets a mandatory property of a vertex</p><div class="fullcomment"><div class="comment cmt"><p>Gets a mandatory property of a vertex</p><p> Returns a property if it exists or not. This method can be used to retrieve properties baked in the schema, so
353+
it must be present. The result is not wrapped in an <code>Option[T]</code>, so if the property does not exist on the database
354+
result will be null.</p><h4>Example</h4><pre>existing.dsl.mandatoryProperty[<span class="std">String</span>](<span class="lit">"name"</span>) <span class="cmt">// String</span></pre></div><dl class="paramcmts block"><dt class="tparam">T</dt><dd class="cmt"><p>Property type</p></dd><dt class="param">name</dt><dd class="cmt"><p>The filed name of the property</p></dd></dl></div>
336355
</li><li name="scala.AnyRef#ne" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
337356
<a id="ne(x$1:AnyRef):Boolean"></a>
338357
<a id="ne(AnyRef):Boolean"></a>
@@ -384,6 +403,23 @@ <h4 class="signature">
384403
</a>
385404
</span>
386405
<div class="fullcomment"><dl class="attributes block"> <dt>Definition Classes</dt><dd>AnyRef</dd></dl></div>
406+
</li><li name="ch.acmesoftware.orientDbScalaDsl.VertexDsl#property" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
407+
<a id="property[T](name:String):Option[T]"></a>
408+
<a id="property[T](String):Option[T]"></a>
409+
<h4 class="signature">
410+
<span class="modifier_kind">
411+
<span class="modifier"></span>
412+
<span class="kind">def</span>
413+
</span>
414+
<span class="symbol">
415+
<span class="name">property</span><span class="tparams">[<span name="T">T</span>]</span><span class="params">(<span name="name">name: <span class="extype" name="scala.Predef.String">String</span></span>)</span><span class="result">: <span class="extype" name="scala.Option">Option</span>[<span class="extype" name="ch.acmesoftware.orientDbScalaDsl.VertexDsl.property.T">T</span>]</span>
416+
</span>
417+
</h4><span class="permalink">
418+
<a href="../../../index.html#ch.acmesoftware.orientDbScalaDsl.VertexDsl@property[T](name:String):Option[T]" title="Permalink" target="_top">
419+
<img src="../../../lib/permalink.png" alt="Permalink" />
420+
</a>
421+
</span>
422+
<p class="shortcomment cmt">Gets a property of a vertex</p><div class="fullcomment"><div class="comment cmt"><p>Gets a property of a vertex</p><h4>Example</h4><pre>existing.dsl.property[<span class="std">String</span>](<span class="lit">"name"</span>) <span class="cmt">// Option[String]</span></pre></div><dl class="paramcmts block"><dt class="tparam">T</dt><dd class="cmt"><p>Property type</p></dd><dt class="param">name</dt><dd class="cmt"><p>The filed name of the property</p></dd></dl></div>
387423
</li><li name="scala.AnyRef#synchronized" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
388424
<a id="synchronized[T0](x$1:=&gt;T0):T0"></a>
389425
<a id="synchronized[T0](⇒T0):T0"></a>
@@ -418,6 +454,23 @@ <h4 class="signature">
418454
</a>
419455
</span>
420456
<div class="fullcomment"><dl class="attributes block"> <dt>Definition Classes</dt><dd>AnyRef → Any</dd></dl></div>
457+
</li><li name="ch.acmesoftware.orientDbScalaDsl.VertexDsl#v" visbl="pub" data-isabs="false" fullComment="no" group="Ungrouped">
458+
<a id="v:com.tinkerpop.blueprints.Element"></a>
459+
<a id="v:Element"></a>
460+
<h4 class="signature">
461+
<span class="modifier_kind">
462+
<span class="modifier"></span>
463+
<span class="kind">val</span>
464+
</span>
465+
<span class="symbol">
466+
<span class="name">v</span><span class="result">: <span class="extype" name="com.tinkerpop.blueprints.Element">Element</span></span>
467+
</span>
468+
</h4><span class="permalink">
469+
<a href="../../../index.html#ch.acmesoftware.orientDbScalaDsl.VertexDsl@v:com.tinkerpop.blueprints.Element" title="Permalink" target="_top">
470+
<img src="../../../lib/permalink.png" alt="Permalink" />
471+
</a>
472+
</span>
473+
<p class="shortcomment cmt">The original Java instance to wrap</p>
421474
</li><li name="scala.AnyRef#wait" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
422475
<a id="wait():Unit"></a>
423476
<a id="wait():Unit"></a>
@@ -503,7 +556,10 @@ <h4 class="signature">
503556
<img src="../../../lib/permalink.png" alt="Permalink" />
504557
</a>
505558
</span>
506-
<p class="shortcomment cmt">Adds a property to existing vertex</p><div class="fullcomment"><div class="comment cmt"><p>Adds a property to existing vertex</p><h4>Example</h4><pre>existing.dsl withProperty <span class="lit">"name"</span> -&gt; <span class="lit">"ACME Software Solutions"</span> and <span class="lit">"year"</span> -&gt; <span class="num">2017</span></pre></div><dl class="paramcmts block"><dt class="param">prop</dt><dd class="cmt"><p>The property to set</p></dd></dl></div>
559+
<p class="shortcomment cmt">Adds a property to existing vertex</p><div class="fullcomment"><div class="comment cmt"><p>Adds a property to existing vertex</p><h4>Example</h4><pre>existing.dsl withProperty <span class="lit">"name"</span> -&gt; <span class="lit">"ACME Software Solutions"</span> and <span class="lit">"year"</span> -&gt; <span class="num">2017</span>
560+
existing.dsl withProperty <span class="lit">"name"</span> -&gt; <span class="std">Some</span>(<span class="lit">"foo"</span>) <span class="cmt">// will be persisted</span>
561+
existing.dsl withProperty <span class="lit">"name"</span> -&gt; <span class="std">None</span> <span class="cmt">// nothing will happen</span>
562+
existing.dsl withProperty <span class="lit">"name"</span> -&gt; <span class="kw">null</span> <span class="cmt">// nothing will happen</span></pre></div><dl class="paramcmts block"><dt class="param">prop</dt><dd class="cmt"><p>The property to set</p></dd></dl></div>
507563
</li></ol>
508564
</div>
509565

0 commit comments

Comments
 (0)