Example usage for org.springframework.jdbc.support SQLErrorCodesFactory getErrorCodes

List of usage examples for org.springframework.jdbc.support SQLErrorCodesFactory getErrorCodes

Introduction

In this page you can find the example usage for org.springframework.jdbc.support SQLErrorCodesFactory getErrorCodes.

Prototype

public SQLErrorCodes getErrorCodes(DataSource dataSource) 

Source Link

Document

Return SQLErrorCodes for the given DataSource , evaluating "databaseProductName" from the java.sql.DatabaseMetaData , or an empty error codes instance if no SQLErrorCodes were found.

Usage

From source file:nz.geek.caffe.spring.ase.AseExceptionMappingTest.java

/**
 * Test for SPR-11097. This test will pass since the error code 547 is
 * currently mapped in the patched config.
 *///from  w  w w . jav a  2  s .c  o  m
@Test
public void testForeignKeyConstraintViolationBatchWithPatch() {
    // override to ues our custom mappings for test

    final SQLErrorCodesFactory factory = new SQLErrorCodesFactory() {

        /**
         * @see org.springframework.jdbc.support.SQLErrorCodesFactory#loadResource(java.lang.String)
         */
        @Override
        protected Resource loadResource(String path) {
            return new ClassPathResource("/sql-error-codes-ase.xml", getClass().getClassLoader());
        }

    };

    this.jdbcTemplate.setExceptionTranslator(
            new SQLErrorCodeSQLExceptionTranslator(factory.getErrorCodes(this.datasource)));

    try {
        this.jdbcTemplate.batchUpdate(new String[] { "INSERT INTO TEST_CHILD VALUES (1, 'test', 2)" });
        Assert.fail("Insert should have failed");
    } catch (final DataIntegrityViolationException e) {
        // expected
    }
}