Spring Framework SQLStateSQLExceptionTranslator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework SQLStateSQLExceptionTranslator class.

This code example shows how to use the following methods:
        ctx.exception(translator().translate("jOOQ", ctx.sql(), ctx.sqlException())); 
    } 
 
    private SQLExceptionTranslator translator() { 
        return ds == null 
            ? new SQLStateSQLExceptionTranslator() 
            : new SQLErrorCodeSQLExceptionTranslator(ds); 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
        super(); 
        if (dataSource != null) { 
            this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource); 
        } 
        else { 
            this.exceptionTranslator = new SQLStateSQLExceptionTranslator(); 
        } 
    } 
 
    public void afterThrowing(Method method, Object[] args, Object target, DBIException ex) throws Throwable { 
        Throwable t = ex.getCause(); 
        String sql = ((Handle)target).toString(); // we really want the failing SQL statement here - is that possible?? 
        if (t instanceof SQLException) { 
            throw exceptionTranslator.translate("DBI", sql, (SQLException)t); 
        } 
        else 
            throw new DataRetrievalFailureException("DBI Exception:" + ex.getMessage(), t); 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
		// Check for PersistenceManagerFactory's DataSource. 
		if (connectionFactory instanceof DataSource) { 
			return new SQLErrorCodeSQLExceptionTranslator((DataSource) connectionFactory); 
		} 
		else { 
			return new SQLStateSQLExceptionTranslator(); 
		} 
	} 
 
	/** 
	 * Obtain a JDO PersistenceManager via the given factory. Is aware of a 
	 * corresponding PersistenceManager bound to the current thread, 
	 * for example when using JdoTransactionManager. Will create a new 
	 * PersistenceManager else, if "allowCreate" is {@code true}. 
	 * @param pmf PersistenceManagerFactory to create the PersistenceManager with 
	 * @param allowCreate if a non-transactional PersistenceManager should be created 
	 * when no transactional PersistenceManager can be found for the current thread 
	 * @return the PersistenceManager 
	 * @throws DataAccessResourceFailureException if the PersistenceManager couldn't be obtained 
	 * @throws IllegalStateException if no thread-bound PersistenceManager found and 
5
CodeRank
This code example shows how to use the following methods:
		if (this.exceptionTranslator == null) { 
			DataSource ds = getDataSource(); 
			if (ds != null) { 
				return new SQLErrorCodeSQLExceptionTranslator(ds); 
			} 
			return new SQLStateSQLExceptionTranslator(); 
		} 
		return this.exceptionTranslator; 
	} 
 
	/** 
	 * Set whether to lazily initialize the SQLExceptionTranslator for this accessor, 
	 * on first encounter of a SQLException. Default is "true"; can be switched to 
	 * "false" for initialization on startup. 
	 * <p>Early initialization only applies if <code>afterPropertiesSet</code> is called. 
	 * 
	 * @see #getExceptionTranslator 
	 * @see #afterPropertiesSet 
	 */ 
	public void setLazyInit(boolean lazyInit) { 
4
CodeRank
This code example shows how to use the following methods:
public class SpringExceptionTranslator implements com.mysema.query.sql.SQLExceptionTranslator { 
 
    private final SQLExceptionTranslator translator; 
     
    public SpringExceptionTranslator() { 
        this.translator = new SQLStateSQLExceptionTranslator(); 
    } 
     
    public SpringExceptionTranslator(SQLExceptionTranslator translator) { 
        this.translator = translator;         
    } 
     
    @Override 
    public RuntimeException translate(String sql, List<Object> bindings, SQLException e) { 
        return translator.translate(null, sql, e); 
    } 
 
    @Override 
    public RuntimeException translate(SQLException e) { 
        return translator.translate(null, null, e); 
4
CodeRank