private boolean isRecordAlreadyExistsException ( SQLException e ) { // Search in UPPER case // MySQL 5.0.x - com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: // Duplicate entry '4f684b34c0a800030018c34f99165791-0' for key 1 // HSQLDB 8.x - java.sql.SQLException: Violation of unique constraint $$: duplicate value(s) for // column(s) $$: // JCR_VCAS_PK in statement [INSERT INTO JCR_VCAS (PROPERTY_ID, ORDER_NUM, CAS_ID) // VALUES(?,?,?)] String H2_PK_CONSTRAINT_DETECT_PATTERN = "(.*JdbcSQLException.*violation.*PRIMARY_KEY_.*)"; // PostgreSQL 8.2.x - org.postgresql.util.PSQLException: ERROR: duplicate key violates unique // constraint "jcr_vcas_pk" // Oracle 9i x64 (on Fedora 7) - java.sql.SQLException: ORA-00001: unique constraint // (EXOADMIN.JCR_VCAS_PK) violated // H2 - org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: // "PRIMARY_KEY_4 ON PUBLIC.JCR_VCAS_TEST(PROPERTY_ID, ORDER_NUM)"; // String err = e . toString ( ) ; if ( dialect . startsWith ( DBConstants . DB_DIALECT_MYSQL ) ) { // for MySQL will search return MYSQL_PK_CONSTRAINT_DETECT . matcher ( err ) . find ( ) ; } else if ( err . toLowerCase ( ) . toUpperCase ( ) . indexOf ( sqlConstraintPK . toLowerCase ( ) . toUpperCase ( ) ) >= 0 ) { // most of supported dbs prints PK name in exception return true ; } else if ( dialect . startsWith ( DBConstants . DB_DIALECT_DB2 ) ) { return DB2_PK_CONSTRAINT_DETECT . matcher ( err ) . find ( ) ; } else if ( dialect . startsWith ( DBConstants . DB_DIALECT_H2 ) ) { return H2_PK_CONSTRAINT_DETECT . matcher ( err ) . find ( ) ; } // NOTICE! As an additional check we may ask the database for property currently processed in // VCAS // and tell true if the property already exists only. return false ; }
Tell is it a RecordAlreadyExistsException .