Open sammerry opened 6 years ago
I may have misunderstood the line above. Im trying to either honor the existing id
field on my case class or overwrite the id when null with a different field. For example.
@label("Test")
case class Testing(foo: String, bar:String)
in Neo4JElementIdProvider
fieldName = "bar"
and expecting to find an id from bar in the database.
Sorry, I do not understand what you are trying to accomplish...
fieldName
represents the name of the field that will be used as the Vertex/Edge identifier. You need to return a field name in the case you are not using the Neo4J Node/Relation native identifier. As an example:
@Override
public String fieldName() {
return "foo";
}
You cannot use more than one field name as identifier, all vertices will have the same field name as identifier. The same applies to edges.
generate
must be implemented in all providers that do not use server side id generation. See DatabaseSequenceElementIdProvider
as an example.
Rather than generating an ID for a Vertex or allowing the database to generate an ID for me. I'd like to use a pre defined UUID as the Vertex ID. I was thinking the Neo4JElementIdProvider
might be the correct place to define it but the generate method doesn't have access to any fields on the Vertex.
The library does not support user provided IDs at the moment, so far it supports the ID generation in the provider or the native one in the database.
User provided IDs can be implemented by the creation of the corresponding provider and the modification of the Graph features based on provider (see Vertex features) and (Edge features).
I do not have time at the moment to implement it, feel free to submit a PR if you are able to implement it.
If i add a method in the Neo4JElementIdProvider
with a signature like T generate(Virtex virtex)
it would allow generating an id based on the virtex id or custom id hashing based on field values. Can add it in this weekend if that sounds good to you.
I do not like that solution, I see the following problems:
Neo4JElementIdProvider
interface is not specific to Vertex
, it must do the same for Edge
.The solution that will work on all scenarios is allow the library to accept user defined identifiers on Vertex/Edge creation so you can do something like:
// create vertex with user defined identifier
Vertex vertex = graph.addVertex(T.id, customIdentifierValue);
I will be working on some new features soon (next month) and I will be able to implement this solution...
Writing a custom
Neo4JElementIdProvider
to set a standard ID from a value in my case class. Ifid
is null it will never use the new field. I think the logic on this line should be one of the followingif (idFieldName != null)
orif (id == null && idFieldName != null)
Since the
Neo4JElementIdProvider
expects null from itsgenerate
andfieldName
methods it behaves oddly.https://github.com/SteelBridgeLabs/neo4j-gremlin-bolt/blob/master/src/main/java/com/steelbridgelabs/oss/neo4j/structure/Neo4JVertex.java#L942