0

I have a bunch of questions regarding Java 8 and SDN4. I created a model in Neo4j v3.0, played a bit with Cypher queries, and now moved to creating a Spring Boot application. As i started coding classes in Java, I've begun to rethink some of my model as well. Here's some questions in my mind (and I haven't found an example explaining this):

  1. Do you need to use Interfaces in Java, with SDN?For eg. I'd code a Product interface and then have my products implement it, but is that how it's done when working with labels?
  2. This is somewhat tied to my question on inheritance - I'd usually have a ProductFamily that my Product would inherit from. At the database level its modeled as (:Product)-[PartOf]->(:ProductFamily), but in the code these would not be super/sub class.
  3. Any examples of using Generics in a graph context?
  4. Is there a way to define constraints on what relationships a node can have and their direction in Java?

I understand there is probably not one right answer, but there's precious little on the web, so hope to get enlightened here!

Luanne
  • 19,145
  • 1
  • 39
  • 51
aaaaarrrgghhh
  • 397
  • 5
  • 16

1 Answers1

2
  1. If you had a Product interface annotated with @NodeEntity, then the you'll have the Product label in addition to the label on your implementing class, which I assume is what you want. If your interface isn't annotated, then your implementing classes will not inherit a label from it.

  2. Not sure what you mean- if you say you have a ProductFamily that Product inherits from, but in the code it would not be a super/sub class? Based on your graph model, if you want (:Product)-[PartOf]->(:ProductFamily) then you will have a Product class that maintains a reference to a ProductFamily class, and that reference annotated with @Relationship. If the Product class inherits from ProductFamily then persisting the Product will result in two labels- Product and ProductFamily because a Product IS-A ProductFamily.

  3. How do you see yourself using generics- the answer really depends on that. Some cases are supported, some are not (an example of something not supported right now is equivalent of template.createRelationBetween in SDN4)

  4. Yes, via the @Relationship annotation which accepts a type and direction. Note that this annotation only constrains your domain model, but you could very well flout this by creating relationships in another direction via a custom query.

Community
  • 1
  • 1
Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Thank you! Re (2) and (3), the idea is that I could work with ProductFamily based Collections as Generics even though i have Products returning in a query. And most properties are defined at `ProductFamily` class, with `Product` class having only properties specific to it. Eg. User queries for all `Product`s supporting a specific feature-i can then return `ProductFamily` if its a family-wide feature and some specific `Product`s when its not, but my collection is the same. Hope that makes sense! – aaaaarrrgghhh Jun 13 '16 at 03:54
  • Yes, possible, though you'll have two labels on the Product nodes (Product and ProductFamily) – Luanne Jun 13 '16 at 05:36