public interface Session
Session
serves as the main point of integration for the Neo4j OGM.
All the publicly-available capabilities of the framework are defined by this interface.
Instances of Session are not thread safe.
In a typical application scenario there should be a Session instance per thread.
A broader scope may be chosen, but the access to the Session must be synchronized externally.
load(java.lang.Class, java.io.Serializable)
load single instance of class by id.loadAll(java.lang.Class, java.util.Collection)
load multiple instances of same class by ids.
Note that if an entity with id is not found it is simply omitted from the results.loadAll(java.lang.Class, org.neo4j.ogm.cypher.Filter)
queries multiple instances of class by
filterRelationshipEntity
).
When loading entities the depth parameter is reflected by the query (also see LoadStrategy
).
When saving entities the depth parameter defines a horizon from root entity for checking for modified entities.
clear()
to clear current session before
reload.SessionFactory
Modifier and Type | Method and Description |
---|---|
Transaction |
beginTransaction()
Begin a new READ_WRITE transaction.
|
Transaction |
beginTransaction(Transaction.Type type)
Begin a new transaction, passing in the required type (READ_ONLY, READ_WRITE).
|
Transaction |
beginTransaction(Transaction.Type type,
Iterable<String> bookmarks)
Begin a new transaction, passing in the required type and bookmarks
If an existing transaction already exists, users must
decide whether to commit or rollback.
|
void |
clear()
Clears the Session
|
long |
count(Class<?> clazz,
Iterable<Filter> filters)
Counts all the node entities of the specified type which match the filters supplied
|
long |
countEntitiesOfType(Class<?> entity)
Counts all the node entities of the specified type.
|
<T> Object |
delete(Class<T> type,
Iterable<Filter> filters,
boolean listResults)
Delete all entities of type matching filter
|
<T> void |
delete(T object)
Delete entity (or entities)
|
<T> void |
deleteAll(Class<T> type)
Delete all entities of type
|
boolean |
detachNodeEntity(Long id)
Detach this node entity represented by the supplied Graph ID from the session.
|
boolean |
detachRelationshipEntity(Long id)
Detach this relationship entity represented by the supplied Graph ID from the session.
|
boolean |
dispose(EventListener eventListener)
Remove an event listener from this session.
|
<T> T |
doInTransaction(GraphCallback<T> graphCallback)
Deprecated.
|
boolean |
eventsEnabled()
Determines if events are enabled for this session.
|
String |
getLastBookmark()
Retrieves the last bookmark used in this session when used in a Neo4j Causal Cluster.
|
LoadStrategy |
getLoadStrategy()
Returns current load strategy
|
Transaction |
getTransaction()
Get the existing transaction if available
|
<T,ID extends Serializable> |
load(Class<T> type,
ID id)
Load single entity instance of type, with default depth = 1
|
<T,ID extends Serializable> |
load(Class<T> type,
ID id,
int depth)
Load single entity instance of type, with depth
|
<T> Collection<T> |
loadAll(Class<T> type)
Load all entities of type, with default depth = 1.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids)
Load entities of type by their ids, with default depth = 1.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids,
int depth)
Load entities of type by their ids.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids,
Pagination pagination)
Load entities of type by their ids, with default depth = 1.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids,
Pagination pagination,
int depth)
Load entities of type by their ids.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids,
SortOrder sortOrder)
Load entities of type by their ids, with default depth = 1.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids,
SortOrder sortOrder,
int depth)
Load entities of type by their ids.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids,
SortOrder sortOrder,
Pagination pagination)
Load entities of type by their ids, with default depth = 1.
|
<T,ID extends Serializable> |
loadAll(Class<T> type,
Collection<ID> ids,
SortOrder sortOrder,
Pagination pagination,
int depth)
Load entities of type by their ids.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter)
Load all entities of type, filtered by filter, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter,
int depth)
Load all entities of type, filtered by filter.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter,
Pagination pagination)
Load all entities of type, filtered by filter, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter,
Pagination pagination,
int depth)
Load all entities of type, filtered by filter.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters)
Load all entities of type, filtered by filters, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters,
int depth)
Load all entities of type, filtered by filters.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter,
SortOrder sortOrder)
Load all entities of type, filtered by filter, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter,
SortOrder sortOrder,
int depth)
Load all entities of type, filtered by filter.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter,
SortOrder sortOrder,
Pagination pagination)
Load all entities of type, filtered by filter, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filter filter,
SortOrder sortOrder,
Pagination pagination,
int depth)
Load all entities of type, filtered by filter.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters,
Pagination pagination)
Load all entities of type, filtered by filters, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters,
Pagination pagination,
int depth)
Load all entities of type, filtered by filters.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters,
SortOrder sortOrder)
Load all entities of type, filtered by filters, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters,
SortOrder sortOrder,
int depth)
Load all entities of type, filtered by filters.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters,
SortOrder sortOrder,
Pagination pagination)
Load all entities of type, filtered by filters, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Filters filters,
SortOrder sortOrder,
Pagination pagination,
int depth)
Load all entities of type, filtered by filters.
|
<T> Collection<T> |
loadAll(Class<T> type,
int depth)
Load all entities of type, with depth
|
<T> Collection<T> |
loadAll(Class<T> type,
Pagination pagination)
Load all entities of type, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
Pagination pagination,
int depth)
Load all entities of type.
|
<T> Collection<T> |
loadAll(Class<T> type,
SortOrder sortOrder)
Load all entities of type, with default depth = 1
|
<T> Collection<T> |
loadAll(Class<T> type,
SortOrder sortOrder,
int depth)
Load all entities of type.
|
<T> Collection<T> |
loadAll(Class<T> type,
SortOrder sortOrder,
Pagination pagination)
Load all entities of type, with default depth = 1.
|
<T> Collection<T> |
loadAll(Class<T> type,
SortOrder sortOrder,
Pagination pagination,
int depth)
Load all entities of type.
|
<T> Collection<T> |
loadAll(Collection<T> objects)
Load entities by themselves - uses id of the entity to load it again, with default depth = 1.
|
<T> Collection<T> |
loadAll(Collection<T> objects,
int depth)
Load entities by themselves - uses id of the entity to load it again.
|
<T> Collection<T> |
loadAll(Collection<T> objects,
Pagination pagination)
Load entities by themselves - uses id of the entity to load it again, with default depth = 1.
|
<T> Collection<T> |
loadAll(Collection<T> objects,
Pagination pagination,
int depth)
Load entities by themselves - uses id of the entity to load it again.
|
<T> Collection<T> |
loadAll(Collection<T> objects,
SortOrder sortOrder)
Load entities by themselves - uses id of the entity to load it again, with default depth = 1.
|
<T> Collection<T> |
loadAll(Collection<T> objects,
SortOrder sortOrder,
int depth)
Load entities by themselves - uses id of the entity to load it again.
|
<T> Collection<T> |
loadAll(Collection<T> objects,
SortOrder sortOrder,
Pagination pagination)
Load entities by themselves - uses id of the entity to load it again, with default depth = 1.
|
<T> Collection<T> |
loadAll(Collection<T> objects,
SortOrder sortOrder,
Pagination pagination,
int depth)
Load entities by themselves - uses id of the entity to load it again.
|
void |
notifyListeners(Event event)
Notifies listeners of this session of the supplied
Event . |
void |
purgeDatabase()
Delete all nodes in the database.
|
<T> Iterable<T> |
query(Class<T> objectType,
String cypher,
Map<String,?> parameters)
a cypher statement this method will return a collection of domain objects that is hydrated to
the default level or a collection of scalars (depending on the parametrized type).
|
Result |
query(String cypher,
Map<String,?> parameters)
a cypher statement this method will return a Result object containing a collection of Map's which represent Neo4j
objects as properties, along with query statistics if applicable.
|
Result |
query(String cypher,
Map<String,?> parameters,
boolean readOnly)
a cypher statement this method will return a Result object containing a collection of Map's which represent Neo4j
objects as properties, along with query statistics if applicable.
|
<T> T |
queryForObject(Class<T> objectType,
String cypher,
Map<String,?> parameters)
a cypher statement this method will return a domain object that is hydrated to the
default level or a scalar (depending on the parametrized type).
|
EventListener |
register(EventListener eventListener)
Register an event listener with this session.
|
Long |
resolveGraphIdFor(Object possibleEntity)
Resolve the graph id for a possible entity.
|
<T> void |
save(T object)
Save entity(or entities) into the database, up to specified depth
The entities are either created or updated.
|
<T> void |
save(T object,
int depth)
Save entity(or entities) into the database, up to specified depth
The objects are either created or updated.
|
void |
setLoadStrategy(LoadStrategy loadStrategy)
Sets the LoadStrategy
Will be used for all subsequent queries.
|
void |
withBookmark(String bookmark)
Sets the bookmark to use on this session.
|
<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids)
type
- type of entitiesids
- ids of entities to load<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids, int depth)
type
- type of entitiesids
- ids of entities to loaddepth
- depth<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids, SortOrder sortOrder)
type
- type of entitiesids
- ids of entities to loadsortOrder
- sort order<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids, SortOrder sortOrder, int depth)
type
- type of entitiesids
- ids of entities to loadsortOrder
- sort orderdepth
- depth<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids, Pagination pagination)
type
- type of entitiesids
- ids of entities to loadpagination
- pagination<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids, Pagination pagination, int depth)
type
- type of entitiesids
- ids of entities to loadpagination
- paginationdepth
- depth<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids, SortOrder sortOrder, Pagination pagination)
type
- type of entitiesids
- ids of entities to loadsortOrder
- sort orderpagination
- pagination<T,ID extends Serializable> Collection<T> loadAll(Class<T> type, Collection<ID> ids, SortOrder sortOrder, Pagination pagination, int depth)
type
- type of entitiesids
- ids of entities to loadsortOrder
- sort orderpagination
- paginationdepth
- depth<T> Collection<T> loadAll(Collection<T> objects)
objects
- objects<T> Collection<T> loadAll(Collection<T> objects, int depth)
objects
- objects<T> Collection<T> loadAll(Collection<T> objects, SortOrder sortOrder)
objects
- objectssortOrder
- sort order<T> Collection<T> loadAll(Collection<T> objects, SortOrder sortOrder, int depth)
objects
- objectssortOrder
- sort orderdepth
- depth<T> Collection<T> loadAll(Collection<T> objects, Pagination pagination)
objects
- objectspagination
- pagination<T> Collection<T> loadAll(Collection<T> objects, Pagination pagination, int depth)
objects
- objectspagination
- paginationdepth
- depth<T> Collection<T> loadAll(Collection<T> objects, SortOrder sortOrder, Pagination pagination)
objects
- objectssortOrder
- sort orderpagination
- pagination<T> Collection<T> loadAll(Collection<T> objects, SortOrder sortOrder, Pagination pagination, int depth)
objects
- objectssortOrder
- sort orderpagination
- paginationdepth
- depth<T> Collection<T> loadAll(Class<T> type)
type
- type of entities<T> Collection<T> loadAll(Class<T> type, int depth)
type
- type of entitiesdepth
- depth<T> Collection<T> loadAll(Class<T> type, SortOrder sortOrder)
type
- type of entitiessortOrder
- sort order<T> Collection<T> loadAll(Class<T> type, SortOrder sortOrder, int depth)
type
- type of entitiessortOrder
- sort orderdepth
- depth<T> Collection<T> loadAll(Class<T> type, Pagination pagination)
type
- type of entitiespagination
- pagination<T> Collection<T> loadAll(Class<T> type, Pagination pagination, int depth)
type
- type of entitiespagination
- paginationdepth
- depth<T> Collection<T> loadAll(Class<T> type, SortOrder sortOrder, Pagination pagination)
type
- type of entitiessortOrder
- sort orderpagination
- pagination<T> Collection<T> loadAll(Class<T> type, SortOrder sortOrder, Pagination pagination, int depth)
type
- type of entitiessortOrder
- sort orderpagination
- paginationdepth
- depth<T> Collection<T> loadAll(Class<T> type, Filter filter)
type
- type of entitiesfilter
- filter<T> Collection<T> loadAll(Class<T> type, Filter filter, int depth)
type
- type of entitiesfilter
- filterdepth
- depth<T> Collection<T> loadAll(Class<T> type, Filter filter, SortOrder sortOrder)
type
- type of entitiesfilter
- filtersortOrder
- sort order<T> Collection<T> loadAll(Class<T> type, Filter filter, SortOrder sortOrder, int depth)
type
- type of entitiesfilter
- filtersortOrder
- sort order<T> Collection<T> loadAll(Class<T> type, Filter filter, Pagination pagination)
type
- type of entitiesfilter
- filterpagination
- pagination<T> Collection<T> loadAll(Class<T> type, Filter filter, Pagination pagination, int depth)
type
- type of entitiesfilter
- filterpagination
- paginationdepth
- depth<T> Collection<T> loadAll(Class<T> type, Filter filter, SortOrder sortOrder, Pagination pagination)
type
- type of entitiesfilter
- filtersortOrder
- sort orderpagination
- pagination<T> Collection<T> loadAll(Class<T> type, Filter filter, SortOrder sortOrder, Pagination pagination, int depth)
type
- type of entitiesfilter
- filtersortOrder
- sort orderpagination
- paginationdepth
- depth<T> Collection<T> loadAll(Class<T> type, Filters filters)
type
- type of entitiesfilters
- filters<T> Collection<T> loadAll(Class<T> type, Filters filters, int depth)
type
- type of entitiesfilters
- filtersdepth
- depth<T> Collection<T> loadAll(Class<T> type, Filters filters, SortOrder sortOrder)
type
- type of entitiesfilters
- filterssortOrder
- sort order<T> Collection<T> loadAll(Class<T> type, Filters filters, SortOrder sortOrder, int depth)
type
- type of entitiesfilters
- filterssortOrder
- sort orderdepth
- depth<T> Collection<T> loadAll(Class<T> type, Filters filters, Pagination pagination)
type
- type of entitiesfilters
- filterspagination
- pagination<T> Collection<T> loadAll(Class<T> type, Filters filters, Pagination pagination, int depth)
type
- type of entitiesfilters
- filterspagination
- paginationdepth
- depth<T> Collection<T> loadAll(Class<T> type, Filters filters, SortOrder sortOrder, Pagination pagination)
type
- type of entitiesfilters
- filterssortOrder
- sort orderpagination
- pagination<T> Collection<T> loadAll(Class<T> type, Filters filters, SortOrder sortOrder, Pagination pagination, int depth)
type
- type of entitiesfilters
- filterssortOrder
- sort orderpagination
- paginationdepth
- depth<T,ID extends Serializable> T load(Class<T> type, ID id)
<T,ID extends Serializable> T load(Class<T> type, ID id, int depth)
<T> void save(T object)
GraphId
and Id
When new objects are saved the instances are modified - the graph id is set to respective field.object
- object to save, may be single entity, array of entities or Iterable
<T> void save(T object, int depth)
GraphId
and Id
.
When new objects are saved the instances are modified - the graph id is set to respective field.object
- object to save, may be single entity, array of entities or Iterable
<T> void delete(T object)
object
- object to delete, may be single entity, array of entities or Iterable
<T> void deleteAll(Class<T> type)
type
- type of the entities to delete<T> Object delete(Class<T> type, Iterable<Filter> filters, boolean listResults)
type
- type of the entities to deletefilters
- filters to match entities to deletelistResults
- true if ids of deleted entities should be returned, false to return count onlyvoid purgeDatabase()
void clear()
Transaction getTransaction()
Transaction beginTransaction()
Transaction beginTransaction(Transaction.Type type)
type
- the Transaction.Type
required for this transactionTransaction beginTransaction(Transaction.Type type, Iterable<String> bookmarks)
type
- the Transaction.Type
required for this transactionbookmarks
- bookmarks that are passed to driver@Deprecated <T> T doInTransaction(GraphCallback<T> graphCallback)
GraphCallback
in the scope of this Session
, giving fine-grained control over
behaviour.T
- The type of object returned from applying this callbackgraphCallback
- The GraphCallback
to executeGraphCallback
NullPointerException
- if invoked with null
<T> T queryForObject(Class<T> objectType, String cypher, Map<String,?> parameters)
T
- A domain object or scalar.objectType
- The type that should be returned from the query.cypher
- The parametrizable cypher to execute.parameters
- Any scalar parameters to attach to the cypher.RuntimeException
- If more than one object is found.<T> Iterable<T> query(Class<T> objectType, String cypher, Map<String,?> parameters)
T
- A domain object or scalar.objectType
- The type that should be returned from the query.cypher
- The parametrizable cypher to execute.parameters
- Any parameters to attach to the cypher.Result query(String cypher, Map<String,?> parameters)
cypher
- The parametrisable cypher to execute.parameters
- Any parameters to attach to the cypher.Result
containing an Iterable
map representing query results and QueryStatistics
if applicable.Result query(String cypher, Map<String,?> parameters, boolean readOnly)
long countEntitiesOfType(Class<?> entity)
entity
- The Class
denoting the type of entity to countlong count(Class<?> clazz, Iterable<Filter> filters)
Long resolveGraphIdFor(Object possibleEntity)
possibleEntity
- the possible entityGraphId
or null if either the object is not an entity or the id is null.boolean detachNodeEntity(Long id)
id
- the node id to detach.true
if detached successfully.boolean detachRelationshipEntity(Long id)
id
- the relationship id to detach.true
if detached successfully.EventListener register(EventListener eventListener)
eventListener
- The listener to register.boolean dispose(EventListener eventListener)
eventListener
- The listener to deregistertrue
if successfully regisistered.void notifyListeners(Event event)
Event
.event
- The event to inform listeners with.boolean eventsEnabled()
true
if this session allows events.String getLastBookmark()
void withBookmark(String bookmark)
bookmark
- The last used bookmark String that this session should start from.LoadStrategy getLoadStrategy()
void setLoadStrategy(LoadStrategy loadStrategy)
Copyright © 2018 Neo Technology, Inc.. All rights reserved.