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

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

Introduction

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

Prototype

protected SQLErrorCodesFactory() 

Source Link

Document

Create a new instance of the SQLErrorCodesFactory class.

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.
 *///ww w  . ja v a2s .co 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
    }
}