本文整理了Java中org.springframework.jdbc.core.JdbcTemplate.getExceptionTranslator()
方法的一些代码示例,展示了JdbcTemplate.getExceptionTranslator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JdbcTemplate.getExceptionTranslator()
方法的具体详情如下:
包路径:org.springframework.jdbc.core.JdbcTemplate
类名称:JdbcTemplate
方法名:getExceptionTranslator
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* 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();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Translate the given {@link SQLException} into a generic {@link DataAccessException}.
* @param task readable text describing the task being attempted
* @param sql the SQL query or update that caused the problem (may be {@code null})
* @param ex the offending {@code SQLException}
* @return a DataAccessException wrapping the {@code SQLException} (never {@code null})
* @since 5.0
* @see #getExceptionTranslator()
*/
protected DataAccessException translateException(String task, @Nullable String sql, SQLException ex) {
DataAccessException dae = getExceptionTranslator().translate(task, sql, ex);
return (dae != null ? dae : new UncategorizedSQLException(task, sql, ex));
}
代码示例来源:origin: io.bufferslayer/buffer-spring-jdbc
public SQLExceptionTranslator getExceptionTranslator() {
return delegate.getExceptionTranslator();
}
代码示例来源:origin: io.bufferslayer/bufferslayer-spring-jdbc
public SQLExceptionTranslator getExceptionTranslator() {
return delegate.getExceptionTranslator();
}
代码示例来源:origin: io.leopard/leopard-jdbc
/**
* 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() {
return getJdbcTemplate().getExceptionTranslator();
}
代码示例来源:origin: org.springframework/org.springframework.jdbc
/**
* 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() {
return getJdbcTemplate().getExceptionTranslator();
}
代码示例来源:origin: cero-t/sqltemplate
/**
* Executes a quey for stream with ordinal parameters.
*/
private <T, U> U queryStreamWithOrdinalParams(
String sql,
PreparedStatementSetter pss,
RowMapper<T> mapper,
Function<? super Stream<T>, U> handleStream) {
SQLExceptionTranslator excTranslator = jdbcTemplate.getExceptionTranslator();
ResultSetExtractor<U> extractor
= new StreamResultSetExtractor(sql, mapper, handleStream, excTranslator);
return jdbcTemplate.query(sql, pss, extractor);
}
代码示例来源:origin: apache/servicemix-bundles
/**
* 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();
}
代码示例来源:origin: cero-t/sqltemplate
/**
* Executes a query for stream with named parameters.
*/
private <T, U> U queryStreamWithNamedParams(
String sql,
SqlParameterSource sps,
RowMapper<T> mapper,
Function<? super Stream<T>, U> handleStream) {
SQLExceptionTranslator excTranslator = jdbcTemplate.getExceptionTranslator();
ResultSetExtractor<U> extractor
= new StreamResultSetExtractor(sql, mapper, handleStream, excTranslator);
return namedJdbcTemplate.query(sql, sps, extractor);
}
代码示例来源:origin: dCache/dcache
DirectoryStreamImpl(FsInode dir, JdbcTemplate jdbc)
{
_jdbc = jdbc;
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs;
try {
connection = DataSourceUtils.getConnection(_jdbc.getDataSource());
ps = connection.prepareStatement(QUERY);
ps.setFetchSize(50);
ps.setLong(1, dir.ino());
ps.setLong(2, dir.ino());
ps.setLong(3, dir.ino());
rs = ps.executeQuery();
} catch (SQLException ex) {
JdbcUtils.closeStatement(ps);
DataSourceUtils.releaseConnection(connection, _jdbc.getDataSource());
throw _jdbc.getExceptionTranslator().translate("StatementExecution", QUERY, ex);
}
_connection = connection;
_resultSet = rs;
_statement = ps;
}
代码示例来源:origin: spring-cloud/spring-cloud-dataflow
/**
* Execute list of {@code SqlCommand} by suppressing errors if those are given
* with a command.
*
* @param connection the connection
* @param commands the sql commands
*/
public void execute(Connection connection, List<SqlCommand> commands) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(connection, true));
SQLExceptionTranslator origExceptionTranslator = jdbcTemplate.getExceptionTranslator();
for (SqlCommand command : commands) {
if(!ObjectUtils.isEmpty(command.getSuppressedErrorCodes())) {
jdbcTemplate.setExceptionTranslator(new SuppressSQLErrorCodesTranslator(command.getSuppressedErrorCodes()));
}
try {
logger.debug("Executing command {}", command.getCommand());
jdbcTemplate.execute(command.getCommand());
} catch (SuppressDataAccessException e) {
logger.debug("Suppressing error {}", e);
}
// restore original translator in case next command
// doesn't define suppressing codes.
jdbcTemplate.setExceptionTranslator(origExceptionTranslator);
}
}
}
代码示例来源:origin: spring-cloud/spring-cloud-skipper
/**
* Execute list of {@code SqlCommand} by suppressing errors if those are given
* with a command.
*
* @param connection the connection
* @param commands the sql commands
*/
public void execute(Connection connection, List<SqlCommand> commands) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(connection, true));
SQLExceptionTranslator origExceptionTranslator = jdbcTemplate.getExceptionTranslator();
for (SqlCommand command : commands) {
if (!ObjectUtils.isEmpty(command.getSuppressedErrorCodes())) {
jdbcTemplate.setExceptionTranslator(new SuppressSQLErrorCodesTranslator(command.getSuppressedErrorCodes()));
}
try {
logger.debug("executing command {}", command.getCommand());
jdbcTemplate.execute(command.getCommand());
}
catch (SuppressDataAccessException e) {
logger.debug("Suppressing error {}", e);
}
// restore original translator in case next command
// doesn't define suppressing codes.
jdbcTemplate.setExceptionTranslator(origExceptionTranslator);
}
}
}
代码示例来源:origin: kaif-open/kaif
default PGobject pgJson(final String rawJson) {
final PGobject jsonObject = new PGobject();
jsonObject.setType("json");
try {
jsonObject.setValue(rawJson);
return jsonObject;
} catch (final SQLException e) {
// see NamedParameterJdbcTemplate for source code
throw ((JdbcTemplate) jdbc()).getExceptionTranslator()
.translate("not valid json: " + rawJson, null, e);
}
}
代码示例来源:origin: kaif-open/kaif
default <T> Stream<T> convertArray(Array array,
CheckedSqlBiFunction<ResultSet, Integer, T> extract) {
try {
Stream.Builder<T> builder = Stream.builder();
try (ResultSet arrayRs = array.getResultSet()) {
while (arrayRs.next()) {
// index 1 is array index number, so extract should use 2
builder.add(extract.apply(arrayRs, 2));
}
}
return builder.build();
} catch (SQLException e) {
// see NamedParameterJdbcTemplate for source code
throw ((JdbcTemplate) jdbc()).getExceptionTranslator()
.translate("could not convert array: " + array, null, e);
}
}
代码示例来源:origin: cero-t/sqltemplate
String sql = getTemplate(fileName, entity);
RowMapper<T> mapper = mapperBuilder.mapper(clazz);
SQLExceptionTranslator excTranslator = jdbcTemplate.getExceptionTranslator();
if (TypeUtils.isSimpleValueType(entity.getClass())) {
PreparedStatementSetter pss = paramBuilder.byArgs(entity);
代码示例来源:origin: org.springframework/org.springframework.jdbc
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
Connection con = DataSourceUtils.getConnection(getDataSource());
try {
Connection conToUse = con;
if (this.nativeJdbcExtractor != null) {
// Extract native JDBC Connection, castable to OracleConnection or the like.
conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
}
else {
// Create close-suppressing Connection proxy, also preparing returned Statements.
conToUse = createConnectionProxy(con);
}
return action.doInConnection(conToUse);
}
catch (SQLException ex) {
// Release Connection early, to avoid potential connection pool deadlock
// in the case when the exception translator hasn't been initialized yet.
DataSourceUtils.releaseConnection(con, getDataSource());
con = null;
throw getExceptionTranslator().translate("ConnectionCallback", getSql(action), ex);
}
finally {
DataSourceUtils.releaseConnection(con, getDataSource());
}
}
代码示例来源:origin: org.springframework/org.springframework.jdbc
DataSourceUtils.releaseConnection(con, getDataSource());
con = null;
throw getExceptionTranslator().translate("CallableStatementCallback", sql, ex);
代码示例来源:origin: org.springframework/org.springframework.jdbc
DataSourceUtils.releaseConnection(con, getDataSource());
con = null;
throw getExceptionTranslator().translate("PreparedStatementCallback", sql, ex);
代码示例来源:origin: org.springframework/org.springframework.jdbc
DataSourceUtils.releaseConnection(con, getDataSource());
con = null;
throw getExceptionTranslator().translate("StatementCallback", getSql(action), ex);
内容来源于网络,如有侵权,请联系作者删除!