Re: [Neo4j] Primary Like ID Across Class Types

2011-10-27 Thread Tatham Oddie
Hi Ramon,

We faced a similar problem on our current project using neo4j.

Our requirements were:
 * 64-bit integer
 * mostly-sequential
 * custom scopes so we could have URLs like /agencies/1/clients/1/addresses/1
 * web farm friendly
   * mostly decentralized
   * no node-specific configuration 
 * guaranteed uniqueness

Having solved all these problems, we released it as an open source library 
called SnowMaker.

We are working with .NET and Azure, but you might found our approach useful 
nonetheless.

I have blogged about it at http://l.tath.am/snowmaker

Of most interest to you will be the explanation towards the end and the 
sequence diagrams.

HTH!


-- Tatham


-Original Message-
From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On 
Behalf Of rbuckland
Sent: Thursday, 27 October 2011 10:37 PM
To: user@lists.neo4j.org
Subject: Re: [Neo4j] Primary Like ID Across Class Types

I have posted the relevant code online, interested to see what people think. 
like - man you just over-engineered that ! 

http://rbtech.blogspot.com/2011/10/neo4j-2nd-look-setting-primary-key-on.html


--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Primary-Like-ID-Across-Class-Types-tp3457270p3457359.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] REST api get list of all relationship properties (unique)

2011-10-27 Thread Jure Zakotnik
Hello Peter,

many thanks for the quick reply, this will help!

Regards Jure

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/REST-api-get-list-of-all-relationship-properties-unique-tp3458852p3458999.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] REST api get list of all relationship properties (unique)

2011-10-27 Thread Peter Neubauer
Jure,
if you know the Lucene query in Java, you could write a Groovy/Java
script directly accessing the IndexAPI and thus do your own Lucene
magic, see 
http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html#rest-api-send-an-arbitrary-groovy-script---lucene-sorting
for an example with custom sorting in Lucene via the REST API.

Does that help?

Cheers,

/peter neubauer

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

http://www.neo4j.org              - NOSQL for the Enterprise.
http://startupbootcamp.org/    - Öresund - Innovation happens HERE.



On Thu, Oct 27, 2011 at 7:33 PM, jure  wrote:
> Dear All,
>
> I would like to extract a list of unique properties used for all
> relationships using the REST API. I created a relationship index and indexed
> all properties. When I query for * using the REST API for the lucene query,
> I receive lots of relationships, so it's difficult to get a unique set of
> properties from the query. Is there a good way to achieve this?
>
> Thanks
> Jure
>
> --
> View this message in context: 
> http://neo4j-community-discussions.438527.n3.nabble.com/REST-api-get-list-of-all-relationship-properties-unique-tp3458852p3458852.html
> Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


[Neo4j] REST api get list of all relationship properties (unique)

2011-10-27 Thread jure
Dear All,

I would like to extract a list of unique properties used for all
relationships using the REST API. I created a relationship index and indexed
all properties. When I query for * using the REST API for the lucene query,
I receive lots of relationships, so it's difficult to get a unique set of
properties from the query. Is there a good way to achieve this?

Thanks
Jure 

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/REST-api-get-list-of-all-relationship-properties-unique-tp3458852p3458852.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Spring Data Graph / Neo4j – Problems with OO Inheritance & Polymorphism relation semantics

2011-10-27 Thread Jean-Pierre Bergamin
Hi Agelos

Regarding your 2nd point:

2)  2) The minor issue I have regards (the otherwise brilliant) @Query,
> due to its constraint of annotating (mainly) Iterable and NOT allowing Set,
> List etc (a runtime exception is thrown
> org.springframework.data.neo4j.conversion.QueryResultBuilder$1 cannot be
> cast to java.util.List).
>
> This wouldn’t be a huge problem, but the JSP/JSLT  tag DOESNOT
> iterate Iterable (!!!), nor you can directly call .iterator() from within
> JSP, making life hard on both ends.
>

>From the controller, just pass the iterator of the iterable to your JSP.
With Spring MVC, this would look like:

@RequestMapping(method = RequestMethod.GET)
public String list(Model uiModel) {
uiModel.addAttribute("kpis", kpiRepository.findAll().iterator());
return "secure/kpis/list";
}

In your JSP, you then can use this iterator as expected:









Best regards,
James
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] 1.5M02 failed to start on reboot

2011-10-27 Thread KanTube
Chris,

my servers are not in HA, i have two dev servers and one uat server all
running the community edition with one dev server running two services at
the same time.  the issue was on the uat server. 

i will send you the files you requested 

i deleted the data directory because i had an issue moving from 1.4 to
1.5.01 (completely separate from this issue) and noticed that if i deleted
the directory a new one would be generated and the server started.  so i
gave it a try again to see if the data files were the cause this time, no
magic here.

thanks 

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/1-5M02-failed-to-start-on-reboot-tp3455296p3458588.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Niels Hoogeveen

You know me and my obsession for densely connected nodes :-)

> Date: Thu, 27 Oct 2011 17:37:07 +
> From: peter.neuba...@neotechnology.com
> To: user@lists.neo4j.org
> Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> 
> Good catch Niels, thanks - my brain is in jet lag mode :-\
> On Oct 27, 2011 7:26 PM, "Niels Hoogeveen" 
> wrote:
> 
> >
> > I see I made a bit of a mistake with this one. The gist of the solution
> > remains, but I made a mistake dealing with the directions of relationship.
> > It should be something like this.
> > public boolean areConnected(Node n1,Node n2, RelationshipType
> > relType,Direction dir) {
> >
> >  Direction dir2 = null;
> >  if(dir.equals(Direction.INCOMING))
> >   dir2 = Direction.OUTGOING;
> >  else if(dir.equals(Direction.OUTGOING))
> >   dir2 = Direction.INCOMING;
> >  else dir2 = Direction.BOTH;
> >
> >  Iterator rels1 = n1.getRelationships(relType,
> > dir).iterator();
> >  Iterator rels2 = n2.getRelationships(relType,
> > dir2).iterator();
> >
> >  while(rels1.hasNext && rels2.hasNext){
> >   Relationship rel1 = rels1.next();
> >   Relationship rel2 = rels2.next();
> >
> >   if (rel1.getEndNode().equals(n2)
> > return true;
> >   else if (rel2.getEndNode().equals(n1))
> > return true;
> >  }
> >  return false;
> > }
> > > From: pd_aficion...@hotmail.com
> > > To: user@lists.neo4j.org
> > > Date: Thu, 27 Oct 2011 19:05:16 +0200
> > > Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> > >
> > >
> > > There is one caveat to this method, you'd have to know which node is
> > most densely connected.
> > >
> > > Suppose one of the nodes has 100,000 relationships (incoming and
> > outgoing) and the other node has only a few relationships, then you'd want
> > to iterate over the relationships of the second node.
> > >
> > > A solution could be to iterate over both sets of relationships at the
> > same time:
> > >
> > > public boolean areConnected(Node n1,Node n2, RelationshipType
> > relType,Direction dir) {
> > >
> > >   Iterator rels1 = n1.getRelationships(relType,
> > dir).iterator();
> > >   Iterator rels2 = n2.getRelationships(relType,
> > dir).iterator();
> > >
> > >   while(rels1.hasNext && rels2.hasNext){
> > >  Relationship rel1 = rels1.next();
> > >  Relationship rel2 = rels2.next();
> > >
> > > if (rel1.getEndNode().equals(n2)
> > >   return true;
> > > else if (rel2.getEndNode().equals(n1))
> > >   return true;
> > >   }
> > >   return false;
> > > }
> > > > Date: Thu, 27 Oct 2011 18:39:01 +0200
> > > > From: bplsi...@gmail.com
> > > > To: user@lists.neo4j.org
> > > > Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> > > >
> > > > Easy: just one.
> > > >
> > > > For now, I've written this, but I'm still not sure it is the simplest
> > > > way to write it
> > > >
> > > >  public boolean areConnected(Node n1,Node n2,Relationship
> > > > rel,Direction dir) throws Exception {
> > > >  Iterable relationships =
> > n1.getRelationships(dir);
> > > >
> > > >  for (Relationship r : relationships) {
> > > >  //I am only working with Dynamic Relationships
> > > >  if (r.getType().equals(rel.getType())) {
> > > >  if (dir == Direction.OUTGOING) { if
> > > > (r.getEndNode().equals(n2)) { return true; } }
> > > >  else { if (r.getStartNode().equals(n2)) { return
> > true; } }
> > > >  }
> > > >  }
> > > >  return false;
> > > >  }
> > > >
> > > > Bruno
> > > >
> > > > Le 27/10/2011 18:31, Peter Neubauer a écrit :
> > > > > Bruno,
> > > > > There is no such function low level, but toy can use a Shortest path
> > algo to
> > > > > check this. What is the maximum length for a path between the nodes?
> > > > > On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva"<
> > bplsi...@gmail.com>
> > > > > wrote:
> > > > >
> > > > >> Hello there!
> > > > >> First of all, thanks for the help in all my previous questions, all
> > the
> > > > >> answers have been helping me to use Neo4j with success.
> > > > >>
> > > > >> I have a very simple question, but I haven't found the answer yet...
> > > > >>
> > > > >> I'd like to have a function, which signature would be more or less
> > like
> > > > >> this:
> > > > >>
> > > > >> public areTheyConnected(Node *n1*,Node *n2*,Relationship
> > *rel*,Direction
> > > > >> *dir*)
> > > > >>
> > > > >> which returns true iff there is an edge of type *rel*, between *n1*
> > and
> > > > >> *n2*, in the *dir* direction (the direction has n1 as reference).
> > > > >>
> > > > >> Example:
> > > > >>
> > > > >> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows
> > Tom"
> > > > >>
> > > > >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING)
> > returns
> > > > >> true; (Bob knows Tom)
> > > > >> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
> > > > >> returns true; (Jack knows Tom)
> > > > >>
> > > > >> a

Re: [Neo4j] 1.5M02 failed to start on reboot

2011-10-27 Thread Chris Gioran
Hi,

Are the three servers members of an HA cluster? If yes, can you
provide details of your setup (the conf/ directory contents would do
nicely)?
Could you provide us with the messages.log files of the servers?
Contact me off list if you have concerns about sharing it publicly.
If you could provide the corrupt database, that would be very nice.
Same off-list contact suggestion as above applies.
Finally, what prompted you to delete the data directory?

cheers,
CG

On Wed, Oct 26, 2011 at 8:58 PM, KanTube  wrote:
> I encountered a odd error.  I installed several windows updates (it was
> Tuesday :) ) and then proceeded to reboot my servers (three in total).  on
> one server the Neo4j service did not restart.  I then deleted the data
> directory and the service started correctly.  I then moved the data from
> another server to this server and it started correctly again.  Seems like
> original data file became corrupted during the shutdown.  I have the data
> files if you think this is something you want to investigate (it is a very
> small data set)
>
> setup win7 x64 (vm running in Fusion)
> Neo4j 1.5M02
>
>
>
> --
> View this message in context: 
> http://neo4j-community-discussions.438527.n3.nabble.com/1-5M02-failed-to-start-on-reboot-tp3455296p3455296.html
> Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Peter Neubauer
Good catch Niels, thanks - my brain is in jet lag mode :-\
On Oct 27, 2011 7:26 PM, "Niels Hoogeveen" 
wrote:

>
> I see I made a bit of a mistake with this one. The gist of the solution
> remains, but I made a mistake dealing with the directions of relationship.
> It should be something like this.
> public boolean areConnected(Node n1,Node n2, RelationshipType
> relType,Direction dir) {
>
>  Direction dir2 = null;
>  if(dir.equals(Direction.INCOMING))
>   dir2 = Direction.OUTGOING;
>  else if(dir.equals(Direction.OUTGOING))
>   dir2 = Direction.INCOMING;
>  else dir2 = Direction.BOTH;
>
>  Iterator rels1 = n1.getRelationships(relType,
> dir).iterator();
>  Iterator rels2 = n2.getRelationships(relType,
> dir2).iterator();
>
>  while(rels1.hasNext && rels2.hasNext){
>   Relationship rel1 = rels1.next();
>   Relationship rel2 = rels2.next();
>
>   if (rel1.getEndNode().equals(n2)
> return true;
>   else if (rel2.getEndNode().equals(n1))
> return true;
>  }
>  return false;
> }
> > From: pd_aficion...@hotmail.com
> > To: user@lists.neo4j.org
> > Date: Thu, 27 Oct 2011 19:05:16 +0200
> > Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> >
> >
> > There is one caveat to this method, you'd have to know which node is
> most densely connected.
> >
> > Suppose one of the nodes has 100,000 relationships (incoming and
> outgoing) and the other node has only a few relationships, then you'd want
> to iterate over the relationships of the second node.
> >
> > A solution could be to iterate over both sets of relationships at the
> same time:
> >
> > public boolean areConnected(Node n1,Node n2, RelationshipType
> relType,Direction dir) {
> >
> >   Iterator rels1 = n1.getRelationships(relType,
> dir).iterator();
> >   Iterator rels2 = n2.getRelationships(relType,
> dir).iterator();
> >
> >   while(rels1.hasNext && rels2.hasNext){
> >  Relationship rel1 = rels1.next();
> >  Relationship rel2 = rels2.next();
> >
> > if (rel1.getEndNode().equals(n2)
> >   return true;
> > else if (rel2.getEndNode().equals(n1))
> >   return true;
> >   }
> >   return false;
> > }
> > > Date: Thu, 27 Oct 2011 18:39:01 +0200
> > > From: bplsi...@gmail.com
> > > To: user@lists.neo4j.org
> > > Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> > >
> > > Easy: just one.
> > >
> > > For now, I've written this, but I'm still not sure it is the simplest
> > > way to write it
> > >
> > >  public boolean areConnected(Node n1,Node n2,Relationship
> > > rel,Direction dir) throws Exception {
> > >  Iterable relationships =
> n1.getRelationships(dir);
> > >
> > >  for (Relationship r : relationships) {
> > >  //I am only working with Dynamic Relationships
> > >  if (r.getType().equals(rel.getType())) {
> > >  if (dir == Direction.OUTGOING) { if
> > > (r.getEndNode().equals(n2)) { return true; } }
> > >  else { if (r.getStartNode().equals(n2)) { return
> true; } }
> > >  }
> > >  }
> > >  return false;
> > >  }
> > >
> > > Bruno
> > >
> > > Le 27/10/2011 18:31, Peter Neubauer a écrit :
> > > > Bruno,
> > > > There is no such function low level, but toy can use a Shortest path
> algo to
> > > > check this. What is the maximum length for a path between the nodes?
> > > > On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva"<
> bplsi...@gmail.com>
> > > > wrote:
> > > >
> > > >> Hello there!
> > > >> First of all, thanks for the help in all my previous questions, all
> the
> > > >> answers have been helping me to use Neo4j with success.
> > > >>
> > > >> I have a very simple question, but I haven't found the answer yet...
> > > >>
> > > >> I'd like to have a function, which signature would be more or less
> like
> > > >> this:
> > > >>
> > > >> public areTheyConnected(Node *n1*,Node *n2*,Relationship
> *rel*,Direction
> > > >> *dir*)
> > > >>
> > > >> which returns true iff there is an edge of type *rel*, between *n1*
> and
> > > >> *n2*, in the *dir* direction (the direction has n1 as reference).
> > > >>
> > > >> Example:
> > > >>
> > > >> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows
> Tom"
> > > >>
> > > >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING)
> returns
> > > >> true; (Bob knows Tom)
> > > >> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
> > > >> returns true; (Jack knows Tom)
> > > >>
> > > >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING)
> returns
> > > >> false; (Tom doesn't know Bob)
> > > >>
> > > >> Is there an easy method (constant time, or close) for that?
> > > >>
> > > >> Thank you very much,
> > > >> Bruno
> > > >> ___
> > > >> Neo4j mailing list
> > > >> User@lists.neo4j.org
> > > >> https://lists.neo4j.org/mailman/listinfo/user
> > > >>
> > > > ___
> > > > Neo4j mailing list
> > > > User@lists.n

Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Niels Hoogeveen

I see I made a bit of a mistake with this one. The gist of the solution 
remains, but I made a mistake dealing with the directions of relationship.
It should be something like this.
public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction 
dir) {
 
 Direction dir2 = null;
 if(dir.equals(Direction.INCOMING))
   dir2 = Direction.OUTGOING;
 else if(dir.equals(Direction.OUTGOING))
   dir2 = Direction.INCOMING;
 else dir2 = Direction.BOTH;

 Iterator rels1 = n1.getRelationships(relType, dir).iterator();
 Iterator rels2 = n2.getRelationships(relType, dir2).iterator();
 
 while(rels1.hasNext && rels2.hasNext){
   Relationship rel1 = rels1.next();
   Relationship rel2 = rels2.next();
 
   if (rel1.getEndNode().equals(n2)
 return true;
   else if (rel2.getEndNode().equals(n1))
 return true;
 }
 return false;
}
> From: pd_aficion...@hotmail.com
> To: user@lists.neo4j.org
> Date: Thu, 27 Oct 2011 19:05:16 +0200
> Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> 
> 
> There is one caveat to this method, you'd have to know which node is most 
> densely connected. 
> 
> Suppose one of the nodes has 100,000 relationships (incoming and outgoing) 
> and the other node has only a few relationships, then you'd want to iterate 
> over the relationships of the second node.
> 
> A solution could be to iterate over both sets of relationships at the same 
> time:
> 
> public boolean areConnected(Node n1,Node n2, RelationshipType 
> relType,Direction dir) {
> 
>   Iterator rels1 = n1.getRelationships(relType, 
> dir).iterator();
>   Iterator rels2 = n2.getRelationships(relType, 
> dir).iterator();
> 
>   while(rels1.hasNext && rels2.hasNext){
>  Relationship rel1 = rels1.next();
>  Relationship rel2 = rels2.next();
> 
> if (rel1.getEndNode().equals(n2)
>   return true;
> else if (rel2.getEndNode().equals(n1))
>   return true;
>   }
>   return false;
> }
> > Date: Thu, 27 Oct 2011 18:39:01 +0200
> > From: bplsi...@gmail.com
> > To: user@lists.neo4j.org
> > Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> > 
> > Easy: just one.
> > 
> > For now, I've written this, but I'm still not sure it is the simplest 
> > way to write it
> > 
> >  public boolean areConnected(Node n1,Node n2,Relationship 
> > rel,Direction dir) throws Exception {
> >  Iterable relationships = n1.getRelationships(dir);
> > 
> >  for (Relationship r : relationships) {
> >  //I am only working with Dynamic Relationships
> >  if (r.getType().equals(rel.getType())) {
> >  if (dir == Direction.OUTGOING) { if 
> > (r.getEndNode().equals(n2)) { return true; } }
> >  else { if (r.getStartNode().equals(n2)) { return true; } }
> >  }
> >  }
> >  return false;
> >  }
> > 
> > Bruno
> > 
> > Le 27/10/2011 18:31, Peter Neubauer a écrit :
> > > Bruno,
> > > There is no such function low level, but toy can use a Shortest path algo 
> > > to
> > > check this. What is the maximum length for a path between the nodes?
> > > On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva"
> > > wrote:
> > >
> > >> Hello there!
> > >> First of all, thanks for the help in all my previous questions, all the
> > >> answers have been helping me to use Neo4j with success.
> > >>
> > >> I have a very simple question, but I haven't found the answer yet...
> > >>
> > >> I'd like to have a function, which signature would be more or less like
> > >> this:
> > >>
> > >> public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction
> > >> *dir*)
> > >>
> > >> which returns true iff there is an edge of type *rel*, between *n1* and
> > >> *n2*, in the *dir* direction (the direction has n1 as reference).
> > >>
> > >> Example:
> > >>
> > >> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows Tom"
> > >>
> > >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns
> > >> true; (Bob knows Tom)
> > >> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
> > >> returns true; (Jack knows Tom)
> > >>
> > >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns
> > >> false; (Tom doesn't know Bob)
> > >>
> > >> Is there an easy method (constant time, or close) for that?
> > >>
> > >> Thank you very much,
> > >> Bruno
> > >> ___
> > >> Neo4j mailing list
> > >> User@lists.neo4j.org
> > >> https://lists.neo4j.org/mailman/listinfo/user
> > >>
> > > ___
> > > Neo4j mailing list
> > > User@lists.neo4j.org
> > > https://lists.neo4j.org/mailman/listinfo/user
> > 
> > ___
> > Neo4j mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> 
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lis

Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Niels Hoogeveen

I gave a different approach in another post, but I am actually not sure if I 
understand the problem correctly.

You give a signature: public boolean areConnected(Node n1,Node n2,Relationship 
rel,Direction dir)

If you simply want to check if the given Relationship connects n1 and n2 with 
the given direction you don't have to iterate at all. It would simply be 
something like:

if(dir.equals(Direction.OUTGOING)){
  return (rel.getEndNode().equals(n1) && rel.getEndNode().equals(n2))
}else{
 return (rel.getEndNode().equals(n2) && rel.getEndNode().equals(n1))
}

If instead the third argument of the method should be RelationshipType it's 
best to iterate over the relationships of both nodes.

Niels
> Date: Thu, 27 Oct 2011 18:39:01 +0200
> From: bplsi...@gmail.com
> To: user@lists.neo4j.org
> Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> 
> Easy: just one.
> 
> For now, I've written this, but I'm still not sure it is the simplest 
> way to write it
> 
>  public boolean areConnected(Node n1,Node n2,Relationship 
> rel,Direction dir) throws Exception {
>  Iterable relationships = n1.getRelationships(dir);
> 
>  for (Relationship r : relationships) {
>  //I am only working with Dynamic Relationships
>  if (r.getType().equals(rel.getType())) {
>  if (dir == Direction.OUTGOING) { if 
> (r.getEndNode().equals(n2)) { return true; } }
>  else { if (r.getStartNode().equals(n2)) { return true; } }
>  }
>  }
>  return false;
>  }
> 
> Bruno
> 
> Le 27/10/2011 18:31, Peter Neubauer a écrit :
> > Bruno,
> > There is no such function low level, but toy can use a Shortest path algo to
> > check this. What is the maximum length for a path between the nodes?
> > On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva"
> > wrote:
> >
> >> Hello there!
> >> First of all, thanks for the help in all my previous questions, all the
> >> answers have been helping me to use Neo4j with success.
> >>
> >> I have a very simple question, but I haven't found the answer yet...
> >>
> >> I'd like to have a function, which signature would be more or less like
> >> this:
> >>
> >> public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction
> >> *dir*)
> >>
> >> which returns true iff there is an edge of type *rel*, between *n1* and
> >> *n2*, in the *dir* direction (the direction has n1 as reference).
> >>
> >> Example:
> >>
> >> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows Tom"
> >>
> >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns
> >> true; (Bob knows Tom)
> >> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
> >> returns true; (Jack knows Tom)
> >>
> >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns
> >> false; (Tom doesn't know Bob)
> >>
> >> Is there an easy method (constant time, or close) for that?
> >>
> >> Thank you very much,
> >> Bruno
> >> ___
> >> Neo4j mailing list
> >> User@lists.neo4j.org
> >> https://lists.neo4j.org/mailman/listinfo/user
> >>
> > ___
> > Neo4j mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> 
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
  
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Niels Hoogeveen

There is one caveat to this method, you'd have to know which node is most 
densely connected. 

Suppose one of the nodes has 100,000 relationships (incoming and outgoing) and 
the other node has only a few relationships, then you'd want to iterate over 
the relationships of the second node.

A solution could be to iterate over both sets of relationships at the same time:

public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction 
dir) {

  Iterator rels1 = n1.getRelationships(relType, dir).iterator();
  Iterator rels2 = n2.getRelationships(relType, dir).iterator();

  while(rels1.hasNext && rels2.hasNext){
 Relationship rel1 = rels1.next();
 Relationship rel2 = rels2.next();

if (rel1.getEndNode().equals(n2)
  return true;
else if (rel2.getEndNode().equals(n1))
  return true;
  }
  return false;
}
> Date: Thu, 27 Oct 2011 18:39:01 +0200
> From: bplsi...@gmail.com
> To: user@lists.neo4j.org
> Subject: Re: [Neo4j] Function to check whether two nodes are connected?
> 
> Easy: just one.
> 
> For now, I've written this, but I'm still not sure it is the simplest 
> way to write it
> 
>  public boolean areConnected(Node n1,Node n2,Relationship 
> rel,Direction dir) throws Exception {
>  Iterable relationships = n1.getRelationships(dir);
> 
>  for (Relationship r : relationships) {
>  //I am only working with Dynamic Relationships
>  if (r.getType().equals(rel.getType())) {
>  if (dir == Direction.OUTGOING) { if 
> (r.getEndNode().equals(n2)) { return true; } }
>  else { if (r.getStartNode().equals(n2)) { return true; } }
>  }
>  }
>  return false;
>  }
> 
> Bruno
> 
> Le 27/10/2011 18:31, Peter Neubauer a écrit :
> > Bruno,
> > There is no such function low level, but toy can use a Shortest path algo to
> > check this. What is the maximum length for a path between the nodes?
> > On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva"
> > wrote:
> >
> >> Hello there!
> >> First of all, thanks for the help in all my previous questions, all the
> >> answers have been helping me to use Neo4j with success.
> >>
> >> I have a very simple question, but I haven't found the answer yet...
> >>
> >> I'd like to have a function, which signature would be more or less like
> >> this:
> >>
> >> public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction
> >> *dir*)
> >>
> >> which returns true iff there is an edge of type *rel*, between *n1* and
> >> *n2*, in the *dir* direction (the direction has n1 as reference).
> >>
> >> Example:
> >>
> >> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows Tom"
> >>
> >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns
> >> true; (Bob knows Tom)
> >> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
> >> returns true; (Jack knows Tom)
> >>
> >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns
> >> false; (Tom doesn't know Bob)
> >>
> >> Is there an easy method (constant time, or close) for that?
> >>
> >> Thank you very much,
> >> Bruno
> >> ___
> >> Neo4j mailing list
> >> User@lists.neo4j.org
> >> https://lists.neo4j.org/mailman/listinfo/user
> >>
> > ___
> > Neo4j mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> 
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
  
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Peter Neubauer
Bruno,
Yes thus looks good. We should put thus into a utility function to start
with. Could you please raise an issue on Github?
On Oct 27, 2011 6:39 PM, "Bruno Paiva Lima da Silva" 
wrote:

> Easy: just one.
>
> For now, I've written this, but I'm still not sure it is the simplest
> way to write it
>
> public boolean areConnected(Node n1,Node n2,Relationship
> rel,Direction dir) throws Exception {
> Iterable relationships = n1.getRelationships(dir);
>
> for (Relationship r : relationships) {
> //I am only working with Dynamic Relationships
> if (r.getType().equals(rel.getType())) {
> if (dir == Direction.OUTGOING) { if
> (r.getEndNode().equals(n2)) { return true; } }
> else { if (r.getStartNode().equals(n2)) { return true; } }
> }
> }
> return false;
> }
>
> Bruno
>
> Le 27/10/2011 18:31, Peter Neubauer a écrit :
> > Bruno,
> > There is no such function low level, but toy can use a Shortest path algo
> to
> > check this. What is the maximum length for a path between the nodes?
> > On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva"
> > wrote:
> >
> >> Hello there!
> >> First of all, thanks for the help in all my previous questions, all the
> >> answers have been helping me to use Neo4j with success.
> >>
> >> I have a very simple question, but I haven't found the answer yet...
> >>
> >> I'd like to have a function, which signature would be more or less like
> >> this:
> >>
> >> public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction
> >> *dir*)
> >>
> >> which returns true iff there is an edge of type *rel*, between *n1* and
> >> *n2*, in the *dir* direction (the direction has n1 as reference).
> >>
> >> Example:
> >>
> >> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows Tom"
> >>
> >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns
> >> true; (Bob knows Tom)
> >> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
> >> returns true; (Jack knows Tom)
> >>
> >> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns
> >> false; (Tom doesn't know Bob)
> >>
> >> Is there an easy method (constant time, or close) for that?
> >>
> >> Thank you very much,
> >> Bruno
> >> ___
> >> Neo4j mailing list
> >> User@lists.neo4j.org
> >> https://lists.neo4j.org/mailman/listinfo/user
> >>
> > ___
> > Neo4j mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
>
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Bruno Paiva Lima da Silva
Easy: just one.

For now, I've written this, but I'm still not sure it is the simplest 
way to write it

 public boolean areConnected(Node n1,Node n2,Relationship 
rel,Direction dir) throws Exception {
 Iterable relationships = n1.getRelationships(dir);

 for (Relationship r : relationships) {
 //I am only working with Dynamic Relationships
 if (r.getType().equals(rel.getType())) {
 if (dir == Direction.OUTGOING) { if 
(r.getEndNode().equals(n2)) { return true; } }
 else { if (r.getStartNode().equals(n2)) { return true; } }
 }
 }
 return false;
 }

Bruno

Le 27/10/2011 18:31, Peter Neubauer a écrit :
> Bruno,
> There is no such function low level, but toy can use a Shortest path algo to
> check this. What is the maximum length for a path between the nodes?
> On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva"
> wrote:
>
>> Hello there!
>> First of all, thanks for the help in all my previous questions, all the
>> answers have been helping me to use Neo4j with success.
>>
>> I have a very simple question, but I haven't found the answer yet...
>>
>> I'd like to have a function, which signature would be more or less like
>> this:
>>
>> public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction
>> *dir*)
>>
>> which returns true iff there is an edge of type *rel*, between *n1* and
>> *n2*, in the *dir* direction (the direction has n1 as reference).
>>
>> Example:
>>
>> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows Tom"
>>
>> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns
>> true; (Bob knows Tom)
>> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
>> returns true; (Jack knows Tom)
>>
>> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns
>> false; (Tom doesn't know Bob)
>>
>> Is there an easy method (constant time, or close) for that?
>>
>> Thank you very much,
>> Bruno
>> ___
>> Neo4j mailing list
>> User@lists.neo4j.org
>> https://lists.neo4j.org/mailman/listinfo/user
>>
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Transaction and REST API

2011-10-27 Thread Peter Neubauer
Yes,
+ 1 on contributions of useful rest plugins. I would like to see them listed
in the manual, and keep the docs somewhere central. Suggestions?
On Oct 27, 2011 12:35 PM, "Kristen Eisenberg" 
wrote:

> Hi Ido,
>
> > How will you go about implement such change using REST interface?
>
> With the current default REST interface, you can't. But you can write an
> extension (either in the managed framework, or if you're brave/desperate in
> the unmanaged framework through JAX-RS) which can do this.
>
> I imagine you might give such a resource the name:
>
> .../products
>
> When you POST a new product representation to the /products resource, under
> the covers it creates both a new node that represents your product and
> inserts the relationship into the DB too.
>
> > Another example in the same area is suppose I want to change 2 links, say
> > change a category from been sub-category to another sub-category and
> let's
> > say it involve delete one link and create another.
>
> Same deal, although the discovery is a little trickier here. If you were to
> do this in a sane way, I'd suggest filling in a form, which contains the URI
> of the relationship to be deleted, plus the information needed to create a
> new relationship. POST that form to a resource representing the graph and
> you're done.
>
> > I'm trying to see if there is a generic way to implement such things of
> > changing multiple resources in generic manager in REST or is it simply to
> > application (or service) specific.
>
> I think they're mostly going to be application specific. That's why we have
> the two ways of extending the server (warning: the JAX-RS way really is a
> sharp tool, be careful). But if the community notices useful patterns
> emerging, then we could think about rolling them up into a general
> extensions package (rather like the very useful graph algos package).
>
> So a plea to the community: if you extend the server in any cool and useful
> way, let the group know and we'll perhaps get a rest-contrib project
> running.
>
> Happy new year everybody!
>
>
> Kristen Eisenberg
> Billige Flüge
> Marketing GmbH
> Emanuelstr. 3,
> 10317 Berlin
> Deutschland
> Telefon: +49 (33)
> 5310967
> Email:
> utebachmeier at
> gmail.com
> Site:
> http://flug.airego.de
> - Billige Flüge vergleichen
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Peter Neubauer
Bruno,
There is no such function low level, but toy can use a Shortest path algo to
check this. What is the maximum length for a path between the nodes?
On Oct 27, 2011 6:14 PM, "Bruno Paiva Lima da Silva" 
wrote:

> Hello there!
> First of all, thanks for the help in all my previous questions, all the
> answers have been helping me to use Neo4j with success.
>
> I have a very simple question, but I haven't found the answer yet...
>
> I'd like to have a function, which signature would be more or less like
> this:
>
> public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction
> *dir*)
>
> which returns true iff there is an edge of type *rel*, between *n1* and
> *n2*, in the *dir* direction (the direction has n1 as reference).
>
> Example:
>
> In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows Tom"
>
> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns
> true; (Bob knows Tom)
> areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also
> returns true; (Jack knows Tom)
>
> areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns
> false; (Tom doesn't know Bob)
>
> Is there an easy method (constant time, or close) for that?
>
> Thank you very much,
> Bruno
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


[Neo4j] Function to check whether two nodes are connected?

2011-10-27 Thread Bruno Paiva Lima da Silva
Hello there!
First of all, thanks for the help in all my previous questions, all the 
answers have been helping me to use Neo4j with success.

I have a very simple question, but I haven't found the answer yet...

I'd like to have a function, which signature would be more or less like 
this:

public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction 
*dir*)

which returns true iff there is an edge of type *rel*, between *n1* and 
*n2*, in the *dir* direction (the direction has n1 as reference).

Example:

In my graph, I have: "Bob knows Tom, Tom knows Peter, Jack knows Tom"

areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns 
true; (Bob knows Tom)
areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also 
returns true; (Jack knows Tom)

areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns 
false; (Tom doesn't know Bob)

Is there an easy method (constant time, or close) for that?

Thank you very much,
Bruno
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] neo4j-advanced-1.5.M02 can`t run in Windows 7 64 bit

2011-10-27 Thread Rick Bullotta
The error messages indicates that the database is already open.  Is Neoclipse 
open or another instance of the server running?  Or some code that is opening 
the database in embedded mode?

-Original Message-
From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On 
Behalf Of rbuckland
Sent: Thursday, October 27, 2011 7:55 AM
To: user@lists.neo4j.org
Subject: Re: [Neo4j] neo4j-advanced-1.5.M02 can`t run in Windows 7 64 bit

What JDK are you using ? 
Where is the path
E:\document\neo4j\Neo4j\neo4j-advanced-1.5.M02\data\graph.db\neostore ?
Is that a network path as the error message looks a bit suspicious.

I do have Windows 7 64bit so can try it later.

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/neo4j-advanced-1-5-M02-can-t-run-in-Windows-7-64-bit-tp3440480p3457394.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] neo4j-advanced-1.5.M02 can`t run in Windows 7 64 bit

2011-10-27 Thread rbuckland
What JDK are you using ? 
Where is the path
E:\document\neo4j\Neo4j\neo4j-advanced-1.5.M02\data\graph.db\neostore ?
Is that a network path as the error message looks a bit suspicious.

I do have Windows 7 64bit so can try it later.

--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/neo4j-advanced-1-5-M02-can-t-run-in-Windows-7-64-bit-tp3440480p3457394.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Primary Like ID Across Class Types

2011-10-27 Thread rbuckland
I have posted the relevant code online, interested to see what people think. 
like - man you just over-engineered that ! 

http://rbtech.blogspot.com/2011/10/neo4j-2nd-look-setting-primary-key-on.html


--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Primary-Like-ID-Across-Class-Types-tp3457270p3457359.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


[Neo4j] Primary Like ID Across Class Types

2011-10-27 Thread rbuckland
Hi, 

I noted in playing with spring-data-neo4j that the Node's under neo4j Don't
have an ID key like typically we would in an RDBMS scenario.

My use case, in short is the application I will be building out will have, a
really simple Web Interface with REST type URLs. So .. for example, I will
be able to do

http://myservice.co.uk/superwebapp/mySpecialThing/detailedView/55

The 55 there will result in a query to Neo4J to locate the "MySpecialThing"
object with ID of type 55 and display it.

So to ensure I have a "per concrete domain POJO, a set ID", I created a
simple ID manager setup.

The thought (for the alpha version) is, that on invoking "getId()" for the
object, an aspect wrapper around it looks to see if it has an id (if it's
null) and if not, it goes and creates an ID from a singleton bean manager,
which in turn loads from neo4j Or looks into a cache, for an
IdObject(ClassName) which has getNextId() on it.

It's not beautiful but practical. The unit tests work all good.

I considered using a UUID as the ID, but I know you do get to use the
simpler "numbers" practically more. I did not want to use NodeId as these
are repository wide. 

Any thoughts ? 

My one thought is that the getId() Aspect probably should be on persist() or
somewhere deeper. Such that the id is actually created on storage. (conjures
up needs to check the Id for clashes etc .. ewww).

you will find the post over at 

http://rbtech.blogspot.com with the suitable code.



--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Primary-Like-ID-Across-Class-Types-tp3457270p3457270.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


[Neo4j] Transaction and REST API

2011-10-27 Thread Kristen Eisenberg
Hi Ido,

> How will you go about implement such change using REST interface?

With the current default REST interface, you can't. But you can write an 
extension (either in the managed framework, or if you're brave/desperate in the 
unmanaged framework through JAX-RS) which can do this. 

I imagine you might give such a resource the name:

.../products

When you POST a new product representation to the /products resource, under the 
covers it creates both a new node that represents your product and inserts the 
relationship into the DB too.

> Another example in the same area is suppose I want to change 2 links, say
> change a category from been sub-category to another sub-category and let's
> say it involve delete one link and create another.

Same deal, although the discovery is a little trickier here. If you were to do 
this in a sane way, I'd suggest filling in a form, which contains the URI of 
the relationship to be deleted, plus the information needed to create a new 
relationship. POST that form to a resource representing the graph and you're 
done.

> I'm trying to see if there is a generic way to implement such things of
> changing multiple resources in generic manager in REST or is it simply to
> application (or service) specific.

I think they're mostly going to be application specific. That's why we have the 
two ways of extending the server (warning: the JAX-RS way really is a sharp 
tool, be careful). But if the community notices useful patterns emerging, then 
we could think about rolling them up into a general extensions package (rather 
like the very useful graph algos package).

So a plea to the community: if you extend the server in any cool and useful 
way, let the group know and we'll perhaps get a rest-contrib project running.

Happy new year everybody!


Kristen Eisenberg
Billige Flüge
Marketing GmbH
Emanuelstr. 3,
10317 Berlin
Deutschland
Telefon: +49 (33)
5310967
Email:
utebachmeier at
gmail.com
Site:
http://flug.airego.de
- Billige Flüge vergleichen
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Spring Data Graph / Neo4j – Problems with OO Inheritance & Polymorphism relation semantics

2011-10-27 Thread Agelos Pikoulas
Thank you Michael -  wish you 'll have a great conference & we're all
looking forward for the online materials :-)

On Wed, Oct 26, 2011 at 8:14 PM, Michael Hunger <
michael.hun...@neotechnology.com> wrote:

> Angelos, I'm currently at SpringOne and quite swamped, I get back to you as
> soon as possible.
>
> Michael
>
> Am 26.10.2011 um 04:30 schrieb Agelos Pikoulas:
>
> > On my previous email please excuse my confusing Person, the example
> should
> > clearly be like this :
> >
> > *
> > *
> >
> > *@NodeEntity public class Content {}*
> > * *
> >
> > *@NodeEntity public class ExtContent extends Content {}*
> >
> > *@NodeEntity
> > public class Person  {
> >
> >@RelatedToVia(elementClass = Person.class, type = "LIKES", direction =
> > Direction.OUTGOING)
> >private Set likedPersons;
> >public Set getLikedPersons() {return likedPersons;}
> >
> >@RelatedToVia(elementClass = Content.class, type = "LIKES", direction
> =
> > Direction.OUTGOING)
> >private Set likedContent;
> >public Set getLikedContent() { return likedContent; }
> > }
> >
> > *I am attaching the code, if someone can github it cause my eclipse
> plugin
> > refuses to do so :-(*
> > *
> > On Wed, Oct 26, 2011 at 12:54 AM, Agelos Pikoulas <
> agelos.pikou...@gmail.com
> >> wrote:
> >
> >> Hi to all graphistas,
> >>
> >>
> >> I have two issues, a major and a minor :
> >>
> >> 1)  1) Starting with SDG 1.0/1.1, I have been developing a MetaModel
> >> (and a generator & hopefully later a MetaMetaModel:) and I have been
> facing
> >> walls in regards to @NodeEntity / NodeBacked classes inheritance and
> their
> >> related @RelatedXXX feature set.
> >>
> >> To the specifics, when a @NodeEntity class extends another, there is
> >> limited support to how these can consistently be related to other nodes
> >> (and retrieved) based not just on the RelationShip name, but also on
> their
> >> class (and inheritance/subclass tree).
> >>
> >>
> >> To better describe things, look at this simplistic example :
> >>
> >> I have
> >>
> >>@NodeEntity public class Content {}
> >>
> >>@NodeEntity public class ExtContent extends Content {}
> >>
> >> and
> >>
> >>
> >> @NodeEntity public class Person  {
> >>
> >>public Set getLikedPersons() {return
> >> likedPersons;}
> >>
> >>@RelatedToVia(elementClass = Person.class, type =
> "LIKES",
> >> direction = Direction.OUTGOING)
> >>
> >>private Set likedPersons;
> >>
> >>
> >>
> >>public Iterable getLikedContent() { return
> >> likedContent; }
> >>
> >>@Query ("start n=node({self})  match (n)
> >> -[:LIKES]-(content) return content")
> >>
> >>@RelatedToVia(elementClass = Content.class, type =
> >> "LIKES", direction = Direction.OUTGOING)
> >>
> >>private Iterable likedContent;
> >>
> >> }
> >>
> >>
> >> As you can see, I want Person object/nodes to 'LIKES' other Person
> objects,
> >> or Content objects (and below in the inheritance tree, such as
> ExtContent) :
> >>
> >>
> >> @Test
> >>public void oo_testing() {
> >>
> >>Person p1 = new Person().persist();
> >>Person p2 = new Person().persist();
> >>Content c1 = new Content().persist();
> >>ExtContent c2 = new ExtContent().persist();
> >>
> >>p1.relateTo(c1, "LIKES");
> >>p1.relateTo(c2, "LIKES");
> >>p1.relateTo(p2, "LIKES");
> >>
> >>for (Content cc : p1.getLikedContent())
> >>logger.warn("Class : " + cc.getClass().getName() + ",
>  __type__
> >> : " + cc.getPersistentState().getProperty("__type__"));
> >>
> >>assertEquals("LikedContent objects are 2", 2,
> >> p1.getLikedContent().size()); // fails, cause it returns all of 'LIKES'
> >> related nodes
> >>
> >>}
> >>
> >>
> >> In version 1.1.RELEASE, retrieving any of the collections fails at
> rutime
> >> (can't recall the Exception, but it was the sort of "wrong class
> found").
> >>
> >>
> >> In version 2.0.0.M1 & today's 2.0.0.BUILD-SNAPSHOT, getLikedPersons() &
> >> getLikedContent() both contain
> >>
> >> ALL nodes that are related via 'LIKES' relationship, irrespective of
> class.
> >>
> >>
> >>
> >> So, this is what p1.getLikedContent() contains :
> >>
> >>
> >> Class : sdnTests.domain.Content,  __type__ : sdnTests.domain.Person
> >> Class : sdnTests.domain.Content,  __type__ : sdnTests.domain.Content
> >> Class : sdnTests.domain.ExtContent,  __type__ :
> sdnTests.domain.ExtContent
> >>
> >>
> >> One would expect that since elementClass defines the class of nodes to
> >> fill the collection with, this it would be obeyed.
> >>
> >> To a better extend, Iterable likedContent should contain all
> >> object/nodes of type Content AND Content subclasses (eg ExtContent),
> >>
> >> since do we have this type information.
> >>
> >>
> >> The same lacking of OO/polymorphism exists with repositories,
> >>
> >> as discussed here
> >> http://lists.neo4j.org/pipermail/user/2011-October/012654.html