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

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

Introduction

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

Prototype

@Deprecated
public static void closeSession(Session session) 

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  w w. j a v  a  2  s . com
    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);
        }
    }
}