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

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

Introduction

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

Prototype

public static DataAccessException convertOgmAccessException(RuntimeException ex) 

Source Link

Document

Convert the given runtime exception to an appropriate exception from the org.springframework.dao hierarchy.

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 av a  2s. 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);
        }
    }
}