Yep, you are right. I wasn't sure in the beginning how Neo would handle this. I also thought that the identity of the relationship type would matter (e.g. in traversal commands where you want to follow all relationships of a given type), but obviously only the name is important. Btw., after loading such a relation again from the repository, the resulting relationship type implementation is something completely different (some internal class).
Ciao, Peter > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Viktor Klang > Sent: Montag, 5. Mai 2008 19:23 > To: Neo user discussions > Subject: Re: [Neo] Does RelationshipType enum need to be unique? > > Hi! > > > Why keep it in a final static map? > > why not just: > > public final class RelUtil > { > public final static RelationshipType createRelType(final String name) > { > return new RelationshipType() > { > public String name() > { > return name; > } > }; > } > } > > I mean, if they are dynamic, and new are created, it's probably safe to > assume that old will disappear, so having a static cache seems overflow, > and > object-creation in Java is cheap compared to long-lived objects... > > > My two Roubles, > > (Over in Mother Russia this week) > > Cheers, > -V > > On Mon, May 5, 2008 at 11:20 AM, Peter Haensgen <[EMAIL PROTECTED]> > wrote: > > > Hi, > > > > the "enum" approach has the disadvantage that the available relationship > > types are static, e.g. they must be known at compile time. In some > cases, > > this may not be sufficient. > > Therefore I have built a "DynamicRelationType", which simply looks like > > this: > > > > public class DynamicRelationshipType implements RelationshipType > > { > > private static Map<String, RelationshipType> types = new > > HashMap<String, RelationshipType>(); > > > > private String name; > > > > private DynamicRelationshipType(String name) > > { > > this.name = name; > > } > > > > public String name() > > { > > return name; > > } > > > > public static synchronized RelationshipType > getRelationshipType(String > > name) > > { > > RelationshipType type = types.get(name); > > if (type == null) > > { > > type = new DynamicRelationshipType(name); > > types.put(name, type); > > } > > > > return type; > > } > > } > > > > > > In the application code, you would use like this: > > > > Node rn = neo.getReferenceNode(); > > Node n = neo.createNode(); > > > > RelationshipType t1 = > > DynamicRelationshipType.getRelationshipType("MyType"); > > rn.createRelationshipTo(n, t1); > > > > > > Works fine for me! > > > > FYI, > > Peter > > > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] [mailto:user- > [EMAIL PROTECTED] > > > On Behalf Of Philip Jägenstedt > > > Sent: Sonntag, 4. Mai 2008 00:08 > > > To: Neo user discussions > > > Subject: [Neo] Does RelationshipType enum need to be unique? > > > > > > This question may reveal some ignorance on my side, but I'm going > ahead > > > anyway. > > > > > > Is there anything which makes it a bad idea to have several different > > > enums implementing RelationshipType and using these for different > > > relationships in neo? The reason in my case is that some relationship > > > types are native to the model (the MusicBrainz model) and ought to > > > reside in org.musicbrainz.RelationTypes or similar, while other > > > relationships are specific to my application and not really related to > > > the model. > > > > > > The reason I ask is that I don't really understand what an enum is in > > > Java. If I have > > > > > > enum MyRelationshipTypes implements RelationshipType > > > { > > > CONTAINED_IN, KNOWS > > > } > > > > > > and then rename it to > > > > > > enum MomsRelationshipTypes implements RelationshipType > > > { > > > CONTAINED_IN, KNOWS > > > } > > > > > > will neo treat these as the same or new relationships? > > > > > > Philip > > > _______________________________________________ > > > Neo mailing list > > > User@lists.neo4j.org > > > https://lists.neo4j.org/mailman/listinfo/user > > _______________________________________________ > > Neo mailing list > > User@lists.neo4j.org > > https://lists.neo4j.org/mailman/listinfo/user > > > > > > -- > Viktor Klang > Rogue Software Architect > _______________________________________________ > Neo mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user _______________________________________________ Neo mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user