Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can embed objects both in node entities and in relationship entities, leveraging the Spring type conversion system <a href="http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/validation.html" rel="nofollow">Spring type conversion system</a>. Provide a pair of string-to-object and object-to-string converters and declare them in the Spring configuration file. The following is a simple scheme that I successfully used in an SDN based application. Objects extend the <em>Embedded</em> common interface to conveniently declare a single converter and are converted to/from JSON string format (this is only to get a better readability when exploring graph node properties, you can choose whatever string format you prefer).</p> <ol> <li><p>String to object converter:</p> <pre><code>final class StringToEmbeddedConverterFactory implements ConverterFactory&lt;String, Embedded&gt; { @Override public &lt;T extends Embedded&gt; Converter&lt;String, T&gt; getConverter(Class&lt;T&gt; type) { return new StringToEmbeddedConverter(type); } private final class StringToEmbeddedConverter&lt;S extends String, E extends Embedded&gt; implements Converter&lt;S, E&gt; { private Class&lt;E&gt; embeddedType; public StringToEmbeddedConverter(Class&lt;E&gt; embeddedType) { this.embeddedType = embeddedType; } @Override public E convert(S source) { if (source != null) { return (E) new Gson().fromJson(source, embeddedType); } else { return null; } } } } </code></pre></li> <li><p>Object to string converter:</p> <pre><code> final class EmbeddedToStringConverterFactory implements ConverterFactory&lt;Embedded, String&gt; { @Override public &lt;T extends String&gt; Converter&lt;Embedded, T&gt; getConverter(Class&lt;T&gt; type) { return new EmbeddedToStringConverter(type); } private final class EmbeddedToStringConverter&lt;E extends Embedded, S extends String&gt; implements Converter&lt;E, S&gt; { private Class&lt;S&gt; stringType; public EmbeddedToStringConverter(Class&lt;S&gt; stringType) { this.stringType = stringType; } @Override public S convert(E source) { if (source != null) { return (S) new Gson().toJson(source); } else { return null; } } } } </code></pre></li> <li><p>Spring configuration.</p></li> </ol> <p>Put the following lines in the Spring configurations file to declare the converter factories:</p> <pre><code>&lt;!-- language: lang-xml --&gt; &lt;bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"&gt; &lt;property name="converters"&gt; &lt;list&gt; &lt;bean class="com.example.EmbeddedToStringConverterFactory"/&gt; &lt;bean class="com.example.StringToEmbeddedConverterFactory"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload