Java Code Examples for org.springframework.jdbc.support.SQLExceptionTranslator

The following examples show how to use org.springframework.jdbc.support.SQLExceptionTranslator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public SpringSessionSynchronization(
		SessionHolder sessionHolder, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, boolean newSession) {

	this.sessionHolder = sessionHolder;
	this.sessionFactory = sessionFactory;
	this.jdbcExceptionTranslator = jdbcExceptionTranslator;
	this.newSession = newSession;

	// Check whether the SessionFactory has a JTA TransactionManager.
	TransactionManager jtaTm =
			SessionFactoryUtils.getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
	if (jtaTm != null) {
		this.hibernateTransactionCompletion = true;
		// Fetch current JTA Transaction object
		// (just necessary for JTA transaction suspension, with an individual
		// Hibernate Session per currently active/suspended transaction).
		try {
			this.jtaTransaction = jtaTm.getTransaction();
		}
		catch (SystemException ex) {
			throw new DataAccessResourceFailureException("Could not access JTA transaction", ex);
		}
	}
}
 
Example 2
public SpringSessionSynchronization(
		SessionHolder sessionHolder, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, boolean newSession) {

	this.sessionHolder = sessionHolder;
	this.sessionFactory = sessionFactory;
	this.jdbcExceptionTranslator = jdbcExceptionTranslator;
	this.newSession = newSession;

	// Check whether the SessionFactory has a JTA TransactionManager.
	TransactionManager jtaTm =
			SessionFactoryUtils.getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
	if (jtaTm != null) {
		this.hibernateTransactionCompletion = true;
		// Fetch current JTA Transaction object
		// (just necessary for JTA transaction suspension, with an individual
		// Hibernate Session per currently active/suspended transaction).
		try {
			this.jtaTransaction = jtaTm.getTransaction();
		}
		catch (SystemException ex) {
			throw new DataAccessResourceFailureException("Could not access JTA transaction", ex);
		}
	}
}
 
Example 3
Source Project: spring-analysis-note   Source File: StoredProcedureTests.java    License: MIT License 5 votes vote down vote up
public StoredProcedureExceptionTranslator(DataSource ds) {
	setDataSource(ds);
	setSql(SQL);
	getJdbcTemplate().setExceptionTranslator(new SQLExceptionTranslator() {
		@Override
		public DataAccessException translate(String task, @Nullable String sql, SQLException ex) {
			return new CustomDataException(sql, ex);
		}
	});
	compile();
}
 
Example 4
Source Project: micronaut-sql   Source File: JooqExceptionTranslator.java    License: Apache License 2.0 5 votes vote down vote up
private SQLExceptionTranslator getTranslator(ExecuteContext context) {
    SQLDialect dialect = context.configuration().dialect();
    if (dialect != null && dialect.thirdParty() != null) {
        String dbName = dialect.thirdParty().springDbName();
        if (dbName != null) {
            return new SQLErrorCodeSQLExceptionTranslator(dbName);
        }
    }
    return new SQLStateSQLExceptionTranslator();
}
 
Example 5
Source Project: java-technology-stack   Source File: StoredProcedureTests.java    License: MIT License 5 votes vote down vote up
public StoredProcedureExceptionTranslator(DataSource ds) {
	setDataSource(ds);
	setSql(SQL);
	getJdbcTemplate().setExceptionTranslator(new SQLExceptionTranslator() {
		@Override
		public DataAccessException translate(String task, @Nullable String sql, SQLException ex) {
			return new CustomDataException(sql, ex);
		}
	});
	compile();
}
 
Example 6
Source Project: lams   Source File: HibernateAccessor.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtain a default SQLExceptionTranslator, lazily creating it if necessary.
 * <p>Creates a default
 * {@link org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator}
 * for the SessionFactory's underlying DataSource.
 */
protected synchronized SQLExceptionTranslator getDefaultJdbcExceptionTranslator() {
	if (this.defaultJdbcExceptionTranslator == null) {
		this.defaultJdbcExceptionTranslator = SessionFactoryUtils.newJdbcExceptionTranslator(getSessionFactory());
	}
	return this.defaultJdbcExceptionTranslator;
}
 
Example 7
/**
 * Obtain a default SQLExceptionTranslator, lazily creating it if necessary.
 * <p>Creates a default
 * {@link org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator}
 * for the SessionFactory's underlying DataSource.
 */
protected synchronized SQLExceptionTranslator getDefaultJdbcExceptionTranslator() {
	if (this.defaultJdbcExceptionTranslator == null) {
		if (getDataSource() != null) {
			this.defaultJdbcExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(getDataSource());
		}
		else {
			this.defaultJdbcExceptionTranslator = SessionFactoryUtils.newJdbcExceptionTranslator(getSessionFactory());
		}
	}
	return this.defaultJdbcExceptionTranslator;
}
 
Example 8
Source Project: spring4-understanding   Source File: HibernateAccessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a default SQLExceptionTranslator, lazily creating it if necessary.
 * <p>Creates a default
 * {@link org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator}
 * for the SessionFactory's underlying DataSource.
 */
protected synchronized SQLExceptionTranslator getDefaultJdbcExceptionTranslator() {
	if (this.defaultJdbcExceptionTranslator == null) {
		this.defaultJdbcExceptionTranslator = SessionFactoryUtils.newJdbcExceptionTranslator(getSessionFactory());
	}
	return this.defaultJdbcExceptionTranslator;
}
 
Example 9
/**
 * Obtain a default SQLExceptionTranslator, lazily creating it if necessary.
 * <p>Creates a default
 * {@link org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator}
 * for the SessionFactory's underlying DataSource.
 */
protected synchronized SQLExceptionTranslator getDefaultJdbcExceptionTranslator() {
	if (this.defaultJdbcExceptionTranslator == null) {
		if (getDataSource() != null) {
			this.defaultJdbcExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(getDataSource());
		}
		else {
			this.defaultJdbcExceptionTranslator = SessionFactoryUtils.newJdbcExceptionTranslator(getSessionFactory());
		}
	}
	return this.defaultJdbcExceptionTranslator;
}
 
Example 10
public StoredProcedureExceptionTranslator(DataSource ds) {
	setDataSource(ds);
	setSql(SQL);
	getJdbcTemplate().setExceptionTranslator(new SQLExceptionTranslator() {

		@Override
		public DataAccessException translate(String task, String sql,
				SQLException sqlex) {
			return new CustomDataException(sql, sqlex);
		}

	});
	compile();
}
 
Example 11
Source Project: gorm-hibernate5   Source File: GrailsHibernateTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SqlDialectInspection")
protected DataAccessException convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator) {
    String msg = ex.getMessage();
    String sql = ex.getSQL();
    SQLException sqlException = ex.getSQLException();
    return translator.translate("Hibernate operation: " + msg, sql, sqlException);
}
 
Example 12
Source Project: effectivejava   Source File: StoredProcedureTests.java    License: Apache License 2.0 5 votes vote down vote up
public StoredProcedureExceptionTranslator(DataSource ds) {
	setDataSource(ds);
	setSql(SQL);
	getJdbcTemplate().setExceptionTranslator(new SQLExceptionTranslator() {

		@Override
		public DataAccessException translate(String task, String sql,
				SQLException sqlex) {
			return new CustomDataException(sql, sqlex);
		}

	});
	compile();
}
 
Example 13
Source Project: tutorials   Source File: ExceptionTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public void exception(ExecuteContext context) {
    SQLDialect dialect = context.configuration().dialect();
    SQLExceptionTranslator translator = new SQLErrorCodeSQLExceptionTranslator(dialect.thirdParty().springDbName());

    context.exception(translator.translate("Access database using jOOQ", context.sql(), context.sqlException()));
}
 
Example 14
Source Project: spring-analysis-note   Source File: JdbcDaoSupport.java    License: MIT License 4 votes vote down vote up
/**
 * Return the SQLExceptionTranslator of this DAO's JdbcTemplate,
 * for translating SQLExceptions in custom JDBC access code.
 * @see org.springframework.jdbc.core.JdbcTemplate#getExceptionTranslator()
 */
protected final SQLExceptionTranslator getExceptionTranslator() {
	JdbcTemplate jdbcTemplate = getJdbcTemplate();
	Assert.state(jdbcTemplate != null, "No JdbcTemplate set");
	return jdbcTemplate.getExceptionTranslator();
}
 
Example 15
Source Project: micronaut-sql   Source File: JooqExceptionTranslator.java    License: Apache License 2.0 4 votes vote down vote up
private DataAccessException translate(ExecuteContext context,
        SQLExceptionTranslator translator, SQLException exception) {
    return translator.translate("jOOQ", context.sql(), exception);
}
 
Example 16
Source Project: java-technology-stack   Source File: JdbcDaoSupport.java    License: MIT License 4 votes vote down vote up
/**
 * Return the SQLExceptionTranslator of this DAO's JdbcTemplate,
 * for translating SQLExceptions in custom JDBC access code.
 * @see org.springframework.jdbc.core.JdbcTemplate#getExceptionTranslator()
 */
protected final SQLExceptionTranslator getExceptionTranslator() {
	JdbcTemplate jdbcTemplate = getJdbcTemplate();
	Assert.state(jdbcTemplate != null, "No JdbcTemplate set");
	return jdbcTemplate.getExceptionTranslator();
}
 
Example 17
Source Project: buffer-slayer   Source File: BatchJdbcTemplate.java    License: Apache License 2.0 4 votes vote down vote up
public void setExceptionTranslator(
    SQLExceptionTranslator exceptionTranslator) {
  delegate.setExceptionTranslator(exceptionTranslator);
}
 
Example 18
Source Project: buffer-slayer   Source File: BatchJdbcTemplate.java    License: Apache License 2.0 4 votes vote down vote up
public SQLExceptionTranslator getExceptionTranslator() {
  return delegate.getExceptionTranslator();
}
 
Example 19
Source Project: lams   Source File: DefaultJdoDialect.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the JDBC exception translator for this dialect, if any.
 */
public SQLExceptionTranslator getJdbcExceptionTranslator() {
	return this.jdbcExceptionTranslator;
}
 
Example 20
Source Project: lams   Source File: HibernateAccessor.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the JDBC exception translator for this instance, if any.
 */
public SQLExceptionTranslator getJdbcExceptionTranslator() {
	return this.jdbcExceptionTranslator;
}
 
Example 21
Source Project: lams   Source File: SessionFactoryUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieve a Session from the given SessionHolder, potentially from a
 * JTA transaction synchronization.
 * @param sessionHolder the SessionHolder to check
 * @param sessionFactory the SessionFactory to get the JTA TransactionManager from
 * @param jdbcExceptionTranslator SQLExcepionTranslator to use for flushing the
 * Session on transaction synchronization (may be {@code null})
 * @return the associated Session, if any
 * @throws DataAccessResourceFailureException if the Session couldn't be created
 */
private static Session getJtaSynchronizedSession(
		SessionHolder sessionHolder, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator) throws DataAccessResourceFailureException {

	// JTA synchronization is only possible with a javax.transaction.TransactionManager.
	// We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified
	// in Hibernate configuration, it will contain a TransactionManager reference.
	TransactionManager jtaTm = getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
	if (jtaTm != null) {
		// Check whether JTA transaction management is active ->
		// fetch pre-bound Session for the current JTA transaction, if any.
		// (just necessary for JTA transaction suspension, with an individual
		// Hibernate Session per currently active/suspended transaction)
		try {
			// Look for transaction-specific Session.
			Transaction jtaTx = jtaTm.getTransaction();
			if (jtaTx != null) {
				int jtaStatus = jtaTx.getStatus();
				if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
					Session session = sessionHolder.getValidatedSession(jtaTx);
					if (session == null && !sessionHolder.isSynchronizedWithTransaction()) {
						// No transaction-specific Session found: If not already marked as
						// synchronized with transaction, register the default thread-bound
						// Session as JTA-transactional. If there is no default Session,
						// we're a new inner JTA transaction with an outer one being suspended:
						// In that case, we'll return null to trigger opening of a new Session.
						session = sessionHolder.getValidatedSession();
						if (session != null) {
							logger.debug("Registering JTA transaction synchronization for existing Hibernate Session");
							sessionHolder.addSession(jtaTx, session);
							jtaTx.registerSynchronization(
									new SpringJtaSynchronizationAdapter(
											new SpringSessionSynchronization(sessionHolder, sessionFactory, jdbcExceptionTranslator, false),
											jtaTm));
							sessionHolder.setSynchronizedWithTransaction(true);
							// Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
							// with FlushMode.NEVER, which needs to allow flushing within the transaction.
							FlushMode flushMode = session.getFlushMode();
							if (flushMode.lessThan(FlushMode.COMMIT)) {
								session.setFlushMode(FlushMode.AUTO);
								sessionHolder.setPreviousFlushMode(flushMode);
							}
						}
					}
					return session;
				}
			}
			// No transaction active -> simply return default thread-bound Session, if any
			// (possibly from OpenSessionInViewFilter/Interceptor).
			return sessionHolder.getValidatedSession();
		}
		catch (Throwable ex) {
			throw new DataAccessResourceFailureException("Could not check JTA transaction", ex);
		}
	}
	else {
		// No JTA TransactionManager -> simply return default thread-bound Session, if any
		// (possibly from OpenSessionInViewFilter/Interceptor).
		return sessionHolder.getValidatedSession();
	}
}
 
Example 22
Source Project: lams   Source File: SessionFactoryUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Register a JTA synchronization for the given Session, if any.
 * @param sessionHolder the existing thread-bound SessionHolder, if any
 * @param session the Session to register
 * @param sessionFactory the SessionFactory that the Session was created with
 * @param jdbcExceptionTranslator SQLExcepionTranslator to use for flushing the
 * Session on transaction synchronization (may be {@code null})
 */
private static void registerJtaSynchronization(Session session, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, SessionHolder sessionHolder) {

	// JTA synchronization is only possible with a javax.transaction.TransactionManager.
	// We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified
	// in Hibernate configuration, it will contain a TransactionManager reference.
	TransactionManager jtaTm = getJtaTransactionManager(sessionFactory, session);
	if (jtaTm != null) {
		try {
			Transaction jtaTx = jtaTm.getTransaction();
			if (jtaTx != null) {
				int jtaStatus = jtaTx.getStatus();
				if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
					logger.debug("Registering JTA transaction synchronization for new Hibernate Session");
					SessionHolder holderToUse = sessionHolder;
					// Register JTA Transaction with existing SessionHolder.
					// Create a new SessionHolder if none existed before.
					if (holderToUse == null) {
						holderToUse = new SessionHolder(jtaTx, session);
					}
					else {
						holderToUse.addSession(jtaTx, session);
					}
					jtaTx.registerSynchronization(
							new SpringJtaSynchronizationAdapter(
									new SpringSessionSynchronization(holderToUse, sessionFactory, jdbcExceptionTranslator, true),
									jtaTm));
					holderToUse.setSynchronizedWithTransaction(true);
					if (holderToUse != sessionHolder) {
						TransactionSynchronizationManager.bindResource(sessionFactory, holderToUse);
					}
				}
			}
		}
		catch (Throwable ex) {
			throw new DataAccessResourceFailureException(
					"Could not register synchronization with JTA TransactionManager", ex);
		}
	}
}
 
Example 23
/**
 * Return the JDBC exception translator for this transaction manager, if any.
 */
public SQLExceptionTranslator getJdbcExceptionTranslator() {
	return this.jdbcExceptionTranslator;
}
 
Example 24
Source Project: spring4-understanding   Source File: DefaultJdoDialect.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Return the JDBC exception translator for this dialect, if any.
 */
public SQLExceptionTranslator getJdbcExceptionTranslator() {
	return this.jdbcExceptionTranslator;
}
 
Example 25
Source Project: spring4-understanding   Source File: HibernateAccessor.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Return the JDBC exception translator for this instance, if any.
 */
public SQLExceptionTranslator getJdbcExceptionTranslator() {
	return this.jdbcExceptionTranslator;
}
 
Example 26
Source Project: spring4-understanding   Source File: SessionFactoryUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve a Session from the given SessionHolder, potentially from a
 * JTA transaction synchronization.
 * @param sessionHolder the SessionHolder to check
 * @param sessionFactory the SessionFactory to get the JTA TransactionManager from
 * @param jdbcExceptionTranslator SQLExcepionTranslator to use for flushing the
 * Session on transaction synchronization (may be {@code null})
 * @return the associated Session, if any
 * @throws DataAccessResourceFailureException if the Session couldn't be created
 */
private static Session getJtaSynchronizedSession(
		SessionHolder sessionHolder, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator) throws DataAccessResourceFailureException {

	// JTA synchronization is only possible with a javax.transaction.TransactionManager.
	// We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified
	// in Hibernate configuration, it will contain a TransactionManager reference.
	TransactionManager jtaTm = getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
	if (jtaTm != null) {
		// Check whether JTA transaction management is active ->
		// fetch pre-bound Session for the current JTA transaction, if any.
		// (just necessary for JTA transaction suspension, with an individual
		// Hibernate Session per currently active/suspended transaction)
		try {
			// Look for transaction-specific Session.
			Transaction jtaTx = jtaTm.getTransaction();
			if (jtaTx != null) {
				int jtaStatus = jtaTx.getStatus();
				if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
					Session session = sessionHolder.getValidatedSession(jtaTx);
					if (session == null && !sessionHolder.isSynchronizedWithTransaction()) {
						// No transaction-specific Session found: If not already marked as
						// synchronized with transaction, register the default thread-bound
						// Session as JTA-transactional. If there is no default Session,
						// we're a new inner JTA transaction with an outer one being suspended:
						// In that case, we'll return null to trigger opening of a new Session.
						session = sessionHolder.getValidatedSession();
						if (session != null) {
							logger.debug("Registering JTA transaction synchronization for existing Hibernate Session");
							sessionHolder.addSession(jtaTx, session);
							jtaTx.registerSynchronization(
									new SpringJtaSynchronizationAdapter(
											new SpringSessionSynchronization(sessionHolder, sessionFactory, jdbcExceptionTranslator, false),
											jtaTm));
							sessionHolder.setSynchronizedWithTransaction(true);
							// Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
							// with FlushMode.NEVER, which needs to allow flushing within the transaction.
							FlushMode flushMode = session.getFlushMode();
							if (flushMode.lessThan(FlushMode.COMMIT)) {
								session.setFlushMode(FlushMode.AUTO);
								sessionHolder.setPreviousFlushMode(flushMode);
							}
						}
					}
					return session;
				}
			}
			// No transaction active -> simply return default thread-bound Session, if any
			// (possibly from OpenSessionInViewFilter/Interceptor).
			return sessionHolder.getValidatedSession();
		}
		catch (Throwable ex) {
			throw new DataAccessResourceFailureException("Could not check JTA transaction", ex);
		}
	}
	else {
		// No JTA TransactionManager -> simply return default thread-bound Session, if any
		// (possibly from OpenSessionInViewFilter/Interceptor).
		return sessionHolder.getValidatedSession();
	}
}
 
Example 27
Source Project: spring4-understanding   Source File: SessionFactoryUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Register a JTA synchronization for the given Session, if any.
 * @param sessionHolder the existing thread-bound SessionHolder, if any
 * @param session the Session to register
 * @param sessionFactory the SessionFactory that the Session was created with
 * @param jdbcExceptionTranslator SQLExcepionTranslator to use for flushing the
 * Session on transaction synchronization (may be {@code null})
 */
private static void registerJtaSynchronization(Session session, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, SessionHolder sessionHolder) {

	// JTA synchronization is only possible with a javax.transaction.TransactionManager.
	// We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified
	// in Hibernate configuration, it will contain a TransactionManager reference.
	TransactionManager jtaTm = getJtaTransactionManager(sessionFactory, session);
	if (jtaTm != null) {
		try {
			Transaction jtaTx = jtaTm.getTransaction();
			if (jtaTx != null) {
				int jtaStatus = jtaTx.getStatus();
				if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
					logger.debug("Registering JTA transaction synchronization for new Hibernate Session");
					SessionHolder holderToUse = sessionHolder;
					// Register JTA Transaction with existing SessionHolder.
					// Create a new SessionHolder if none existed before.
					if (holderToUse == null) {
						holderToUse = new SessionHolder(jtaTx, session);
					}
					else {
						holderToUse.addSession(jtaTx, session);
					}
					jtaTx.registerSynchronization(
							new SpringJtaSynchronizationAdapter(
									new SpringSessionSynchronization(holderToUse, sessionFactory, jdbcExceptionTranslator, true),
									jtaTm));
					holderToUse.setSynchronizedWithTransaction(true);
					if (holderToUse != sessionHolder) {
						TransactionSynchronizationManager.bindResource(sessionFactory, holderToUse);
					}
				}
			}
		}
		catch (Throwable ex) {
			throw new DataAccessResourceFailureException(
					"Could not register synchronization with JTA TransactionManager", ex);
		}
	}
}
 
Example 28
/**
 * Return the JDBC exception translator for this transaction manager, if any.
 */
public SQLExceptionTranslator getJdbcExceptionTranslator() {
	return this.jdbcExceptionTranslator;
}
 
Example 29
Source Project: micronaut-sql   Source File: JooqExceptionTranslator.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Handle a single exception in the chain. SQLExceptions might be nested multiple
 * levels deep. The outermost exception is usually the least interesting one ("Call
 * getNextException to see the cause."). Therefore the innermost exception is
 * propagated and all other exceptions are logged.
 *
 * @param context The execute context
 * @param translator The exception translator
 * @param exception The exception
 */
private void handle(ExecuteContext context, SQLExceptionTranslator translator,
        SQLException exception) {
    DataAccessException translated = translate(context, translator, exception);
    if (exception.getNextException() == null) {
        context.exception(translated);
    } else {
        LOG.error("Execution of SQL statement failed.", translated);
    }
}
 
Example 30
/**
 * Create an appropriate SQLExceptionTranslator for the given PersistenceManagerFactory.
 * <p>If a DataSource is found, creates a SQLErrorCodeSQLExceptionTranslator for the
 * DataSource; else, falls back to a SQLStateSQLExceptionTranslator.
 * @param connectionFactory the connection factory of the PersistenceManagerFactory
 * (may be {@code null})
 * @return the SQLExceptionTranslator (never {@code null})
 * @see javax.jdo.PersistenceManagerFactory#getConnectionFactory()
 * @see org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
 * @see org.springframework.jdbc.support.SQLStateSQLExceptionTranslator
 */
static SQLExceptionTranslator newJdbcExceptionTranslator(Object connectionFactory) {
	// Check for PersistenceManagerFactory's DataSource.
	if (connectionFactory instanceof DataSource) {
		return new SQLErrorCodeSQLExceptionTranslator((DataSource) connectionFactory);
	}
	else {
		return new SQLStateSQLExceptionTranslator();
	}
}