Database Reference
In-Depth Information
The
GraphDatabaseService.createNode()
method creates the node in the
Neo4j database . This method returns the created node itself, which you can use to in-
spectitspropertiesortomanipulatethenodefurther.Intheprecedinglistings,you'reusing
the returned node instance to print the internal ID of the node as generated by the Neo4j
database
.
You've now seen the creation of a single
user
node, but because you're creating a social
network, you'll need a few more users. The following listing creates three more users.
Listing 3.3. Creating multiple nodes in a single transaction
try (Transaction tx = graphDb.beginTx()) {
Node user1 = graphDb.createNode();
logger.info("created user:"+user1.getId());
Node user2 = graphDb.createNode();
logger.info("created user:"+user2.getId());
Node user3 = graphDb.createNode();
logger.info("created user:"+user3.getId());
tx.success();
}
After the operations from
listing 3.3
, your graph will look exactly like
figure 3.7
, both in
the object model and on disk, using the Neo4j graph database storage.
The next step is to connect the created
user
nodes using relationships.
3.2.2. Creating relationships
Before you start implementing relationships to connect users as friends, remind yourself of
the model diagram in
figure 3.2
,
shown again here as
figure 3.8
.