Package org.neo4j.ogm.session
Class SessionFactory
java.lang.Object
org.neo4j.ogm.session.SessionFactory
This is the main initialization point of OGM. Used to create
Session
instances for interacting with Neo4j.
In a typical scenario one instance of SessionFactory is created, shared across whole application.- Author:
- Vince Bickers, Luanne Misquitta, Mark Angrish, Frantisek Hartman, Michael J. Simons
-
Constructor Summary
ConstructorsConstructorDescriptionSessionFactory
(String... packages) Constructs a newSessionFactory
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.SessionFactory
(org.neo4j.ogm.config.Configuration configuration, String... packages) Constructs a newSessionFactory
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
(org.neo4j.ogm.driver.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
(org.neo4j.ogm.driver.Driver driver, String... packages) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this session factory Also closes any underlying resources, like driver etc.void
deregister
(EventListener eventListener) Removes the specified listener fromthis SessionFactory
.Returns current load strategyboolean
metaData()
Retrieves the meta-data that was built up when thisSessionFactory
was constructed.Opens a new Neo4j mappingSession
using the Driver specified in the OGM baseConfiguration The driver should be configured to connect to the database using the appropriate DriverConfigvoid
register
(IdStrategy strategy) Register an instance ofIdStrategy
This instance will be used for generation of ids annotated with@Id @GeneratedValue(strategy=SomeClass.class)
void
register
(EventListener eventListener) Registers the specified listener on allSession
events generated fromthis SessionFactory
.final void
runAutoIndexManager
(org.neo4j.ogm.config.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.void
setTransactionManagerFactory
(BiFunction<org.neo4j.ogm.driver.Driver, Session, org.neo4j.ogm.transaction.TransactionManager> transactionManagerFactory) Use this method to plug in custom transaction managers.<T> T
Method allows to unwrap either the OGM Driver ("Transport") by passing in one oforg.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.
-
Constructor Details
-
SessionFactory
Constructs a newSessionFactory
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 aException
.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.- Parameters:
packages
- The packages to scan for domain objects
-
SessionFactory
Constructs a newSessionFactory
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
.- Parameters:
configuration
- The baseConfiguration to usepackages
- The packages to scan for domain objects. They will be merged with the configuration.
-
SessionFactory
-
SessionFactory
public SessionFactory(org.neo4j.ogm.driver.Driver driver, boolean useStrictQuerying, String... packages) Create a session factory with given driver Use this constructor when you need to provide fully customized driver. Indexes will not be automatically created.- Parameters:
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 objects
-
-
Method Details
-
runAutoIndexManager
public final void runAutoIndexManager(org.neo4j.ogm.config.Configuration configuration) Opens a session and runs the auto-index manager with the given configuration and the metadata configured in this factory. This method can be run multiple times.- Parameters:
configuration
- only used to configure aspects of the auto-index manager, not for the session factory at this point.
-
metaData
Retrieves the meta-data that was built up when thisSessionFactory
was constructed.- Returns:
- The underlying
MetaData
-
openSession
Opens a new Neo4j mappingSession
using the Driver specified in the OGM baseConfiguration The driver should be configured to connect to the database using the appropriate DriverConfig- Returns:
- A new
Session
-
register
Registers the specified listener on allSession
events generated fromthis SessionFactory
. Only Session instances created after this call are affected.- Parameters:
eventListener
- The event listener to register.
-
deregister
Removes the specified listener fromthis SessionFactory
. Only Session instances created after this call are affected.- Parameters:
eventListener
- The event listener to deregister.
-
getLoadStrategy
Returns current load strategy- Returns:
- load strategy
-
setLoadStrategy
Sets the LoadStrategy Will be used for all queries on subsequently created sessions. This also can be set on individual Session instances.- Parameters:
loadStrategy
- load strategy
-
isUseStrictQuerying
public boolean isUseStrictQuerying()- Returns:
- True if this instance uses strict querying or not.
-
setEntityInstantiator
-
setTransactionManagerFactory
public void setTransactionManagerFactory(BiFunction<org.neo4j.ogm.driver.Driver, Session, org.neo4j.ogm.transaction.TransactionManager> transactionManagerFactory) Use this method to plug in custom transaction managers. We offerAbstractTransactionManager
as a base for your implementation that behaves according to what OGM expects. Support for custom transaction managers will be done only on a best effort base.- Parameters:
transactionManagerFactory
- A factory for transaction managers. Must not be null
-
close
public void close()Closes this session factory Also closes any underlying resources, like driver etc. -
register
Register an instance ofIdStrategy
This instance will be used for generation of ids annotated with@Id @GeneratedValue(strategy=SomeClass.class)
- Parameters:
strategy
-IdStrategy
to use
-
unwrap
Method allows to unwrap either the OGM Driver ("Transport") by passing in one oforg.neo4j.ogm.drivers.bolt.driver.BoltDriver
org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
org.neo4j.ogm.drivers.http.driver.HttpDriver
- Type Parameters:
T
- The type of the object to unwrap- Parameters:
clazz
- The class of the object to unwrap- Returns:
- The unwrapped, underlying object
- Throws:
IllegalArgumentException
- when an object of the given class cannot be unwrapped.
-