Example usage for org.springframework.data.neo4j.transaction SessionFactoryUtils getSession

List of usage examples for org.springframework.data.neo4j.transaction SessionFactoryUtils getSession

Introduction

In this page you can find the example usage for org.springframework.data.neo4j.transaction SessionFactoryUtils getSession.

Prototype

public static Session getSession(SessionFactory sessionFactory) throws IllegalStateException 

Source Link

Usage

From source file:org.springframework.data.neo4j.template.Neo4jTemplate.java

@Override
public <T> T execute(Neo4jCallback<T> action) throws DataAccessException {
    Assert.notNull(action, "Callback object must not be null");

    Session session = null;//from  w ww.j  a  v  a 2 s. c om
    boolean isNew = false;
    try {
        session = SessionFactoryUtils.getSession(getSessionFactory());
    } catch (IllegalStateException ex) {
        logger.debug("Could not retrieve pre-bound OGM session", ex);
    }
    if (session == null) {
        session = getSessionFactory().openSession();
        isNew = true;
    }

    try {
        return action.doInNeo4jOgm(session);
    } catch (RuntimeException ex) {
        throw SessionFactoryUtils.convertOgmAccessException(ex);
    } finally {
        if (isNew) {
            SessionFactoryUtils.closeSession(session);
        }
    }
}