public class SessionFactory extends Object
Session instances for interacting with Neo4j.
In a typical scenario one instance of SessionFactory is created, shared across whole application.| Constructor and Description |
|---|
SessionFactory(Configuration configuration,
String... packages)
Constructs a new
SessionFactory by initialising the object-graph mapping meta-data from the given list of domain
object packages, and also sets the baseConfiguration to be used. |
SessionFactory(Driver driver,
boolean useStrictQuerying,
String... packages)
Create a session factory with given driver
Use this constructor when you need to provide fully customized driver.
|
SessionFactory(Driver driver,
String... packages) |
SessionFactory(String... packages)
Constructs a new
SessionFactory by initialising the object-graph mapping meta-data from the given list of domain
object packages and starts up the Neo4j database in embedded mode. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this session factory
Also closes any underlying resources, like driver etc.
|
void |
deregister(EventListener eventListener)
Removes the the specified listener from
this SessionFactory. |
LoadStrategy |
getLoadStrategy()
Returns current load strategy
|
boolean |
isUseStrictQuerying() |
MetaData |
metaData()
Retrieves the meta-data that was built up when this
SessionFactory was constructed. |
Session |
openSession()
Opens a new Neo4j mapping
Session using the Driver specified in the OGM baseConfiguration
The driver should be configured to connect to the database using the appropriate
DriverConfig |
void |
register(EventListener eventListener)
Registers the specified listener on all
Session events generated from
this SessionFactory. |
void |
register(IdStrategy strategy)
Register an instance of
IdStrategy
This instance will be used for generation of ids annotated with
@Id @GeneratedValue(strategy=SomeClass.class) |
void |
runAutoIndexManager(Configuration configuration)
Opens a session and runs the auto-index manager with the given configuration and the metadata configured in this
factory.
|
void |
setEntityInstantiator(EntityInstantiator entityInstantiator) |
void |
setLoadStrategy(LoadStrategy loadStrategy)
Sets the LoadStrategy
Will be used for all queries on subsequently created sessions.
|
<T> T |
unwrap(Class<T> clazz)
Method allows to unwrap either the OGM Driver ("Transport") by passing in one of
org.neo4j.ogm.drivers.bolt.driver.BoltDriver
org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
org.neo4j.ogm.drivers.http.driver.HttpDriver
It also allows access to the underlying Neo4j Java Driver ("Bolt driver") or the embedded database instance. |
public SessionFactory(String... packages)
SessionFactory by initialising the object-graph mapping meta-data from the given list of domain
object packages and starts up the Neo4j database in embedded mode. If the embedded driver is not available this method
will throw a Exception.
The package names passed to this constructor should not contain wildcards or trailing full stops, for example, "org.springframework.data.neo4j.example.domain" would be fine. The default behaviour is for sub-packages to be scanned and you can also specify fully-qualified class names if you want to cherry pick particular classes.
Indexes will also be checked or built if configured.packages - The packages to scan for domain objectspublic SessionFactory(Configuration configuration, String... packages)
SessionFactory by initialising the object-graph mapping meta-data from the given list of domain
object packages, and also sets the baseConfiguration to be used.
The package names passed to this constructor should not contain wildcards or trailing full stops, for example, "org.springframework.data.neo4j.example.domain" would be fine. The default behaviour is for sub-packages to be scanned and you can also specify fully-qualified class names if you want to cherry pick particular classes.
Indexes will also be checked or built unless auto index mode is set toNONE.configuration - The baseConfiguration to usepackages - The packages to scan for domain objects. They will be merged with the configuration.public SessionFactory(Driver driver, boolean useStrictQuerying, String... packages)
driver - driver to be used with this SessionFactoryuseStrictQuerying - Flag wether to use strict querying or not. Overwrites configuration settings (from the driver).packages - The packages to scan for domain objectspublic final void runAutoIndexManager(Configuration configuration)
configuration - only used to configure aspects of the auto-index manager, not for the session factory at this point.public MetaData metaData()
SessionFactory was constructed.MetaDatapublic Session openSession()
Session using the Driver specified in the OGM baseConfiguration
The driver should be configured to connect to the database using the appropriate
DriverConfigSessionpublic void register(EventListener eventListener)
Session events generated from
this SessionFactory.
Only Session instances created after this call are affected.eventListener - The event listener to register.public void deregister(EventListener eventListener)
this SessionFactory.
Only Session instances created after this call are affected.eventListener - The event listener to deregister.public LoadStrategy getLoadStrategy()
public void setLoadStrategy(LoadStrategy loadStrategy)
loadStrategy - load strategypublic boolean isUseStrictQuerying()
public void setEntityInstantiator(EntityInstantiator entityInstantiator)
public void close()
public void register(IdStrategy strategy)
IdStrategy
This instance will be used for generation of ids annotated with
@Id @GeneratedValue(strategy=SomeClass.class)strategy - IdStrategy to usepublic <T> T unwrap(Class<T> clazz)
org.neo4j.ogm.drivers.bolt.driver.BoltDriverorg.neo4j.ogm.drivers.embedded.driver.EmbeddedDriverorg.neo4j.ogm.drivers.http.driver.HttpDriverT - The type of the object to unwrapclazz - The class of the object to unwrapIllegalArgumentException - when an object of the given class cannot be unwrapped.Copyright © 2015–2020 Neo Technology, Inc.. All rights reserved.