Database Reference
In-Depth Information
Spring Data Neo4j
This section covers basic operations and usage of Spring Data Neo4j (SDN) with the goal of reviewing the specific
code examples before implementing it within an application. The next section will walk you through a sample
application with specific graph goals and models.
As for the other language drivers and libraries available for Neo4j, one goal of SDN is to provide a degree of
abstraction over the Neo4j REST API. In addition, the SDN provides many additional utility classes and methods that
might otherwise be required to be coded at some other stage in the development of your application.
Spring Data neo4j is maintained by the undeniably awesome and helpful Michael hunger and supported by a
number of great Spring Data neo4j developers. If you would like to get involved with SDn, go to https://github.com/
spring-projects/spring-data-neo4j .
Note
Each of the following brief sections covers concepts that tie either directly or indirectly to features and
functionality found within the Neo4j Server and REST API. If you choose to go through each language chapter, notice
how each library covers those features and functionality in similar ways but takes advantage of the language-specific
capabilities to ensure that the API is flexible and performant.
The code examples shown in this section are deliberately brief, being provided to familiarize you with
basic operations. For example, many of the examples make use of the neo4joperations class to perform operations.
notwithstanding, Spring Data neo4j is an extremely rich library and provides additional classes and methods to handle
basic operations. To give you a sense of their scope, I expand on a selection of capabilities in the sample application.
Important
Managing Nodes and Relationships
Chapters 1 and 2 covered the elements of a graph database, which includes the most basic of graph concepts: the
node. Managing nodes and their properties and relationships will probably account for the bulk of your application's
graph-related code.
In SDN, there are a few ways to manage creation and retrieval of nodes and relationships. This section covers
some basic methods, and the sample application provides some additional ways.
Creating a Node
The maintenance of nodes is set in motion with the creation process, as shown in Listing 11-4. Creating a node
begins with setting up a connection to the database. As is the case with most Spring projects that use a database, the
configuration of the database properties can be set in a configuration file via XML. The sample application uses a file
named applicationContext.xml , which resides in the /WEB-INF directory. The next section of this chapter will cover
the configuration.
In addition, we will add the @Autowired annotation on the Neo4jOperations class. This instantiates the
Neo4jOperations bean for use inside each method in the class. The sample SDN project extends a parent Service class
in order to reuse the Neo4jOperations bean. Next, the properties are put into a Map, and then the Node can be saved
to the database using the createNode method and adding its Map parameter.
 
 
Search WWH ::




Custom Search