Database Reference
In-Depth Information
ResultSetMapper
A common need in many data-driven applications is to take results from a query and map them back to domain
objects. To map database results back to the domain objects, you will use a specifically designed class called
ResultSetMapper
. ResultSetMapper contains four public methods and one private method:
mapLabelNodeToClass
—This method takes a
Map
from a query result, a
Class
type and an
ObjectMapper
to convert a single
Label
node into a domain object.
•
mapResultSetToObject
—This method takes a
ResultSet
and
Class
type and returns a List of
domain objects based on the Class type.
•
mapResultSetToListMappedClass
—This method takes a
ResultSet
and
Class
type and
returns a List of mapped objects based on the
Class
type. Mapped objects typically consist of
a mix of properties that will be used for the view, such as a list of status updates.
•
mapResultSetToMappedClass
—This method takes a
Map
and
Class
type and returns a single
mapped object based on the
Class
type. Again, a mapped object typically consists of a mix of
properties that will be used for the view, such as a list of status updates.
•
query
—this private method is used to convert a
ResultSet
into an
Iterator
of
Map
objects.
•
■
Struts 2 and the front-end code, such as Mustache, help run the sample application, but I will limit
extended coverage of those concepts to the Social Graph section. In the Social Graph section, I will focus on the
non-obvious but important aspects of those concepts. As you go through the rest of the application, controllers as
well as the front-end code will use similar syntax, so they will be referenced but not listed in the chapter as repetitive
coverage of that syntax would distract from the discrete, specific java and Neo4j examples.
Head's-Up
Social Graph Model
This section explores the social graph model and a few of the operations that typically accompany it. In particular, this
section looks at the following:
•
Sign-up and Login
•
Updating a user
•
Creating a relationship type through a user by following other users
•
Managing user content, such as displaying, adding, updating, and removing status updates
■
The sample graph database used for these examples comes loaded with social data, so you can immediately
begin working with representative data in each of the graph models. In the case of the social graph—and for other graph
models, as well—you will login with the user
ajordan
. Going forward, please login with
ajordan
to see each of the
working examples.
Note