本文整理汇总了Java中org.springframework.jdbc.support.SQLExceptionTranslator类的典型用法代码示例。如果您正苦于以下问题:Java SQLExceptionTranslator类的具体用法?Java SQLExceptionTranslator怎么用?Java SQLExceptionTranslator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SQLExceptionTranslator类属于org.springframework.jdbc.support包,在下文中一共展示了SQLExceptionTranslator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SpringSessionSynchronization
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
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);
}
}
}
示例2: getDefaultJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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;
}
示例3: getDefaultJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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;
}
示例4: StoredProcedureExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
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();
}
示例5: getTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
private SQLExceptionTranslator getTranslator(ExecuteContext context) {
SQLDialect dialect = context.configuration().dialect();
if (dialect != null && dialect.thirdParty() != null) {
return new SQLErrorCodeSQLExceptionTranslator(
dialect.thirdParty().springDbName());
}
return new SQLStateSQLExceptionTranslator();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:JooqExceptionTranslator.java
示例6: handle
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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 {
logger.error("Execution of SQL statement failed.", translated);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:JooqExceptionTranslator.java
示例7: getTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
private SQLExceptionTranslator getTranslator(ExecuteContext context) {
SQLDialect dialect = context.configuration().dialect();
if (dialect != null) {
return new SQLErrorCodeSQLExceptionTranslator(dialect.name());
}
return new SQLStateSQLExceptionTranslator();
}
示例8: main
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
DataSource ds = getDataSourceMysql();
SQLErrorCodesFactory sqlErrorCodesFactory = SQLErrorCodesFactory.getInstance();
SQLExceptionTranslator sqlExTrans = new SQLErrorCodeSQLExceptionTranslator(
sqlErrorCodesFactory.getErrorCodes(ds));
try {
qndMysqlPK(ds.getConnection());
} catch (SQLException e) {
System.out.println(sqlExTrans.translate(null, null, e));
e.printStackTrace();
}
}
示例9: getDefaultJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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 = TransactionManagerUtils.newJdbcExceptionTranslator();
}
return this.defaultJdbcExceptionTranslator;
}
示例10: StreamResultSetExtractor
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* Constructs an extractor.
*
* @param sql the SQL
* @param mapper the row mapper
* @param handleStream the handler function which extracts a result from the row stream
* @param excTranslator the translator of SQL to DataAccessException
*/
public StreamResultSetExtractor(
String sql,
RowMapper<T> mapper,
Function<? super Stream<T>, U> handleStream,
SQLExceptionTranslator excTranslator) {
this.sql = sql;
this.mapper = mapper;
this.handleStream = handleStream;
this.excTranslator = excTranslator;
}
示例11: ResultSetIterator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* Constructs an iterator.
*
* @param sql the SQL
* @param rs the result set to iterate over
* @param mapper the mapper which converts each row
* @param excTranslator the translator of {@link SQLException}s.
*/
ResultSetIterator(
String sql,
ResultSet rs,
RowMapper<T> mapper,
SQLExceptionTranslator excTranslator) {
this.sql = sql;
this.rs = rs;
this.mapper = mapper;
this.excTranslator = excTranslator;
}
示例12: queryStreamWithOrdinalParams
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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);
}
示例13: queryStreamWithNamedParams
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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);
}
示例14: setExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
public void setExceptionTranslator(
SQLExceptionTranslator exceptionTranslator) {
delegate.setExceptionTranslator(exceptionTranslator);
}
示例15: getExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
public SQLExceptionTranslator getExceptionTranslator() {
return delegate.getExceptionTranslator();
}