本文整理汇总了Java中org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator类的典型用法代码示例。如果您正苦于以下问题:Java SQLErrorCodeSQLExceptionTranslator类的具体用法?Java SQLErrorCodeSQLExceptionTranslator怎么用?Java SQLErrorCodeSQLExceptionTranslator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SQLErrorCodeSQLExceptionTranslator类属于org.springframework.jdbc.support包,在下文中一共展示了SQLErrorCodeSQLExceptionTranslator类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
/**
* If beanProperty is true, initialize via exception translator bean property;
* if false, use afterPropertiesSet().
*/
private void doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(boolean beanProperty)
throws SQLException {
SQLException sqlException = new SQLException("foo", "07xxx");
this.dataSource = mock(DataSource.class);
given(this.dataSource.getConnection()).willThrow(sqlException);
this.template = new JdbcTemplate();
this.template.setDataSource(this.dataSource);
this.template.setLazyInit(false);
if (beanProperty) {
// This will get a connection.
this.template.setExceptionTranslator(new SQLErrorCodeSQLExceptionTranslator(this.dataSource));
}
else {
// This will cause creation of default SQL translator.
this.template.afterPropertiesSet();
}
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
this.thrown.expect(CannotGetJdbcConnectionException.class);
this.thrown.expect(exceptionCause(sameInstance(sqlException)));
this.template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch);
}
示例2: GrailsHibernateTemplate
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
public GrailsHibernateTemplate(SessionFactory sessionFactory) {
Assert.notNull(sessionFactory, "Property 'sessionFactory' is required");
this.sessionFactory = sessionFactory;
ConnectionProvider connectionProvider = ((SessionFactoryImplementor) sessionFactory).getServiceRegistry().getService(ConnectionProvider.class);
if(connectionProvider instanceof DatasourceConnectionProviderImpl) {
this.dataSource = ((DatasourceConnectionProviderImpl) connectionProvider).getDataSource();
if(dataSource instanceof TransactionAwareDataSourceProxy) {
this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
}
jdbcExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource);
}
else {
// must be in unit test mode, setup default translator
SQLErrorCodeSQLExceptionTranslator sqlErrorCodeSQLExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator();
sqlErrorCodeSQLExceptionTranslator.setDatabaseProductName("H2");
jdbcExceptionTranslator = sqlErrorCodeSQLExceptionTranslator;
}
}
示例3: executeWith
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
protected Object executeWith(Connection connection, SqlMapClientCallback action) {
SqlMapSession session = getSqlMapClient().openSession();
try {
try {
session.setUserConnection(connection);
} catch (SQLException e) {
throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", e);
}
try {
return action.doInSqlMapClient(session);
} catch (SQLException ex) {
throw new SQLErrorCodeSQLExceptionTranslator().translate("SqlMapClient operation",
null, ex);
}
} finally {
session.close();
}
}
示例4: getDefaultJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的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;
}
示例5: getTranslator
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的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: getTranslator
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
private SQLExceptionTranslator getTranslator(ExecuteContext context) {
SQLDialect dialect = context.configuration().dialect();
if (dialect != null) {
return new SQLErrorCodeSQLExceptionTranslator(dialect.name());
}
return new SQLStateSQLExceptionTranslator();
}
示例7: main
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的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();
}
}
示例8: JdbcTemplateStorageAccessor
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
JdbcTemplateStorageAccessor(DataSource dataSource, String tableName) {
super(dataSource, tableName);
this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource);
}
示例9: initExceptionTranslator
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
/**
* Initializes the internal translator reference.
*/
private synchronized void initExceptionTranslator() {
if (this.exceptionTranslator == null) {
this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(this.dataSource);
}
}
示例10: sqlExceptionTranslator
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
@Bean
public SQLExceptionTranslator sqlExceptionTranslator() {
return new SQLErrorCodeSQLExceptionTranslator(jdbcConfiguration.dataSource());
}
示例11: newJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
/**
* 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();
}
}
示例12: newJdbcExceptionTranslator
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
/**
* Create an appropriate SQLExceptionTranslator for the given SessionFactory.
* If a DataSource is found, a SQLErrorCodeSQLExceptionTranslator for the DataSource
* is created; else, a SQLStateSQLExceptionTranslator as fallback.
* @param sessionFactory the SessionFactory to create the translator for
* @return the SQLExceptionTranslator
* @see #getDataSource
* @see org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
* @see org.springframework.jdbc.support.SQLStateSQLExceptionTranslator
*/
public static SQLExceptionTranslator newJdbcExceptionTranslator(SessionFactory sessionFactory) {
DataSource ds = getDataSource(sessionFactory);
if (ds != null) {
return new SQLErrorCodeSQLExceptionTranslator(ds);
}
return new SQLStateSQLExceptionTranslator();
}