Example usage for org.springframework.jdbc.support SQLErrorCodeSQLExceptionTranslator setDatabaseProductName

List of usage examples for org.springframework.jdbc.support SQLErrorCodeSQLExceptionTranslator setDatabaseProductName

Introduction

In this page you can find the example usage for org.springframework.jdbc.support SQLErrorCodeSQLExceptionTranslator setDatabaseProductName.

Prototype

public void setDatabaseProductName(String dbName) 

Source Link

Document

Set the database product name for this translator.

Usage

From source file:org.grails.orm.hibernate.GrailsHibernateTemplate.java

public GrailsHibernateTemplate(SessionFactory sessionFactory) {
    Assert.notNull(sessionFactory, "Property 'sessionFactory' is required");
    this.sessionFactory = sessionFactory;

    if (sessionFactory instanceof SessionFactoryProxy) {
        sessionFactory = ((SessionFactoryProxy) sessionFactory).getCurrentSessionFactory();
    }/*from w w w. j  a v  a2s .  c  o  m*/
    ConnectionProvider connectionProvider = ((SessionFactoryImpl) sessionFactory).getServiceRegistry()
            .getService(ConnectionProvider.class);
    if (connectionProvider instanceof DatasourceConnectionProviderImpl) {
        jdbcExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(
                ((DatasourceConnectionProviderImpl) connectionProvider).getDataSource());
    } else {
        // must be in unit test mode, setup default translator
        SQLErrorCodeSQLExceptionTranslator sqlErrorCodeSQLExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator();
        sqlErrorCodeSQLExceptionTranslator.setDatabaseProductName("H2");
        jdbcExceptionTranslator = sqlErrorCodeSQLExceptionTranslator;
    }
}