当前位置: 首页>>代码示例>>Java>>正文


Java SQLErrorCodeSQLExceptionTranslator类代码示例

本文整理汇总了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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:JdbcTemplateTests.java

示例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;
    }
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:20,代码来源:GrailsHibernateTemplate.java

示例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();
    }
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:19,代码来源:DefaultConcurrentRequestProcessor.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HibernateTransactionManager.java

示例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();
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:8,代码来源:JooqExceptionTranslator.java

示例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();
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:13,代码来源:QndSQLExceptionTranslator.java

示例8: JdbcTemplateStorageAccessor

import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
JdbcTemplateStorageAccessor(DataSource dataSource, String tableName) {
    super(dataSource, tableName);
    this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource);
}
 
开发者ID:lukas-krecan,项目名称:ShedLock,代码行数:5,代码来源:JdbcTemplateStorageAccessor.java

示例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);
  }
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:9,代码来源:MyBatisExceptionTranslator.java

示例10: sqlExceptionTranslator

import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; //导入依赖的package包/类
@Bean
public SQLExceptionTranslator sqlExceptionTranslator() {
    return new SQLErrorCodeSQLExceptionTranslator(jdbcConfiguration.dataSource());
}
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:5,代码来源:AppConfiguration.java

示例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();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:PersistenceManagerFactoryUtils.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SessionFactoryUtils.java


注:本文中的org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。