本文整理汇总了Java中org.springframework.jdbc.support.SQLExceptionTranslator类的典型用法代码示例。如果您正苦于以下问题:Java SQLExceptionTranslator类的具体用法?Java SQLExceptionTranslator怎么用?Java SQLExceptionTranslator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SQLExceptionTranslator类属于org.springframework.jdbc.support包,在下文中一共展示了SQLExceptionTranslator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:SpringSessionSynchronization.java
示例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;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:HibernateAccessor.java
示例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;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HibernateTransactionManager.java
示例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();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:StoredProcedureTests.java
示例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();
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:8,代码来源:JooqExceptionTranslator.java
示例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();
}
}
开发者ID:DDTH,项目名称:ddth-dao,代码行数:13,代码来源:QndSQLExceptionTranslator.java
示例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;
}
开发者ID:ryanwli,项目名称:guzz,代码行数:13,代码来源:SpringWriteTemplate.java
示例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;
}
开发者ID:cero-t,项目名称:sqltemplate,代码行数:19,代码来源:StreamResultSetExtractor.java
示例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;
}
开发者ID:cero-t,项目名称:sqltemplate,代码行数:19,代码来源:ResultSetIterator.java
示例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);
}
开发者ID:cero-t,项目名称:sqltemplate,代码行数:14,代码来源:SqlTemplate.java
示例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);
}
开发者ID:cero-t,项目名称:sqltemplate,代码行数:14,代码来源:SqlTemplate.java
示例14: setExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
public void setExceptionTranslator(
SQLExceptionTranslator exceptionTranslator) {
delegate.setExceptionTranslator(exceptionTranslator);
}
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:5,代码来源:BatchJdbcTemplate.java
示例15: getExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
public SQLExceptionTranslator getExceptionTranslator() {
return delegate.getExceptionTranslator();
}
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:4,代码来源:BatchJdbcTemplate.java
示例16: getJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* Return the JDBC exception translator for this dialect, if any.
*/
public SQLExceptionTranslator getJdbcExceptionTranslator() {
return this.jdbcExceptionTranslator;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:DefaultJdoDialect.java
示例17: getJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* Return the JDBC exception translator for this instance, if any.
*/
public SQLExceptionTranslator getJdbcExceptionTranslator() {
return this.jdbcExceptionTranslator;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:HibernateAccessor.java
示例18: getJtaSynchronizedSession
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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();
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:72,代码来源:SessionFactoryUtils.java
示例19: registerJtaSynchronization
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* 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);
}
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:SessionFactoryUtils.java
示例20: getJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLExceptionTranslator; //导入依赖的package包/类
/**
* Return the JDBC exception translator for this transaction manager, if any.
*/
public SQLExceptionTranslator getJdbcExceptionTranslator() {
return this.jdbcExceptionTranslator;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:HibernateTransactionManager.java
注:本文中的org.springframework.jdbc.support.SQLExceptionTranslator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论