[フレーム]
Skip to content

Domain entities

Domain entities can be wrapped around a node. The same approach can be used with relationships.

The source code of the examples is found at: Person.java

First off, store the node and make it accessible inside the package:

private final Node underlyingNode;
Person( GraphDatabaseService databaseService, Transaction transaction, Node personNode )
{
 this.databaseService = databaseService;
 this.transaction = transaction;
 this.underlyingNode = personNode;
}
protected Node getUnderlyingNode()
{
 return underlyingNode;
}

Delegate attributes to the node:

public String getName()
{
 return (String)underlyingNode.getProperty( NAME );
}

Make sure to override these methods:

@Override
public int hashCode()
{
 return underlyingNode.hashCode();
}
@Override
public boolean equals( Object o )
{
 return o instanceof Person &&
 underlyingNode.equals( ( (Person)o ).getUnderlyingNode() );
}
@Override
public String toString()
{
 return "Person[" + getName() + "]";
}

AltStyle によって変換されたページ (->オリジナル) /