问题
I would like to use the ENRON GraphML dataset, loaded into Neo4j, as a database for my Grails 2.0 application. The use-case for the data is read-only. I have had no trouble loading the dataset and creating a database in a stand-alone application, and now would like to use the Grails plugin to manage access to the database.
Looking at the Neo4J plugin documentation on mapping domain classes, I see that it requires subreference nodes for each type of vertex. My data doesn't have that. I can see several ways of moving forward, and am unsure about which to pursue:
Dump the plugin, create a service, and manage reading the database myself. Pros: I can implement this easily. Cons: potential performance issues, bugs.
Write a program that creates the missing vertexes and edges expected by the plugin, and then load the database into the plugin. Pros: plugin will manage access. Cons: Might take a few iterations to figure out exactly what needs to be added to make it consistent with a plugin-created database.
Create an empty database via the plugin and perform a bunch of insertions by reading the data from a different database. Pros: plugin will manage access. Cons: might take a long time to bootstrap database; need to write code to traverse, serialize database; etc.
What's a good way to go? What am I overlooking?
回答1:
As being the author of the Grails Neo4j plugin I might be able to give a qualified answer here. The subreference structure currently used in the plugin is not always the best approach. I have some plans to replace this by indexing in a configurable way but there is no ETA right now. As you might require a more short term solution, I suggest to choose between 1) and 2) in case of a read-only database. One of the main advantages for using domain classes is the usage of scaffolding. As you're read only, this argument does not count here IMHO.
1) has another nice advantage: If you use e.g. cypher to query the graph the performance would be very good even when using a REST style database. In general if performance is important you should use cypher in favour of doing Grails criteria queries/ dynamic finders.
2) If you're going with that approach I can provide some support. Basically you need to create your domain classes and create a subreference node per domain class and connect all instances to this one. Advantage here: you could use e.g. dynamic finders or standard criteria queries. Creating the subreference nodes and the connections to the instances node could be easily done with one or two cypher statements.
来源:https://stackoverflow.com/questions/13148032/using-a-legacy-neo4j-database-with-grails