Package org.h2.jdbc

Examples of org.h2.jdbc.JdbcSQLException


            String sqlstate = transfer.readString();
            String message = transfer.readString();
            String sql = transfer.readString();
            int errorCode = transfer.readInt();
            String stackTrace = transfer.readString();
            JdbcSQLException s = new JdbcSQLException(message, sql, sqlstate, errorCode, null, stackTrace);
            if (errorCode == ErrorCode.CONNECTION_BROKEN_1) {
                // allow re-connect
                IOException e = new IOException(s.toString());
                e.initCause(s);
                throw e;
            }
            throw DbException.convert(s);
        } else if (status == STATUS_CLOSED) {
View Full Code Here


    @Override
    public DataAccessException translateExceptionIfPossible(RuntimeException re) {       
        DataAccessException e = null;
        // first make sure the root exception is actually an org.h2.jdbc.JdbcSQLException
        if (ExceptionUtils.getRootCause(re) instanceof JdbcSQLException) {
            JdbcSQLException rootException = (JdbcSQLException)ExceptionUtils.getRootCause(re);
                       
            // now translate the H2 specific error codes into Rave's common application Exceptions
            // add more error codes to the switch statement that should be specifically trapped                        
            switch(rootException.getErrorCode()) {
                case ErrorCode.DUPLICATE_KEY_1: {
                    e = new DuplicateItemException("DUPLICATE_ITEM", rootException);
                    break;
                }

                default: {
                    e = new TranslatedH2Exception(rootException.getErrorCode(), "ERROR", "Unknown Database Error");
                    break;
                }
            }
        } else {           
            // we got a RuntimeException that wasn't an org.h2.jdbc.JdbcSQLException
View Full Code Here

    /**
     * Test of translateExceptionIfPossible method, of class H2OpenJpaDialect.
     */
    @Test
    public void testTranslateExceptionIfPossible_uniqueContstraintViolation() {                
        JdbcSQLException jdbcEx = new JdbcSQLException("message", "sql statement", "state", ErrorCode.DUPLICATE_KEY_1, null, "stacktrace");
        RuntimeException re = new RuntimeException("dummy runtime exception", jdbcEx);    
                      
        assertThat(dialect.translateExceptionIfPossible(re), is(DuplicateItemException.class));
    }
View Full Code Here

        assertThat(dialect.translateExceptionIfPossible(re), is(DuplicateItemException.class));
    }
   
    @Test
    public void testTranslateExceptionIfPossible_unknownJdbcSQLExceptionError() {                
        JdbcSQLException jdbcEx = new JdbcSQLException("message", "sql statement", "state", ErrorCode.CANNOT_DROP_CURRENT_USER, null, "stacktrace");
        RuntimeException re = new RuntimeException("dummy runtime exception", jdbcEx);    
       
        TranslatedH2Exception translatedException = (TranslatedH2Exception) dialect.translateExceptionIfPossible(re);            
        assertThat(translatedException.getErrorCode(), is(ErrorCode.CANNOT_DROP_CURRENT_USER));       
    }
View Full Code Here

            e.printStackTrace(new PrintWriter(writer));
            String trace = writer.toString();
            String message;
            String sql;
            if (e instanceof JdbcSQLException) {
                JdbcSQLException j = (JdbcSQLException) e;
                message = j.getOriginalMessage();
                sql = j.getSQL();
            } else {
                message = e.getMessage();
                sql = null;
            }
            transfer.writeInt(SessionRemote.STATUS_ERROR).writeString(e.getSQLState()).writeString(message)
View Full Code Here

                return;
            }
            printWriter.println(s);
            if (t != null) {
                if (levelFile == ERROR && t instanceof JdbcSQLException) {
                    JdbcSQLException se = (JdbcSQLException) t;
                    int code = se.getErrorCode();
                    if (ErrorCode.isCommon(code)) {
                        printWriter.println(t.toString());
                    } else {
                        t.printStackTrace(printWriter);
                    }
View Full Code Here

    /**
     * Test of translateExceptionIfPossible method, of class H2OpenJpaDialect.
     */
    @Test
    public void testTranslateExceptionIfPossible_uniqueContstraintViolation() {                
        JdbcSQLException jdbcEx = new JdbcSQLException("message", "sql statement", "state", ErrorCode.DUPLICATE_KEY_1, null, "stacktrace");
        RuntimeException re = new RuntimeException("dummy runtime exception", jdbcEx);

        assertTrue(dialect.translateExceptionIfPossible(re) instanceof DuplicateItemException);
    }
View Full Code Here

        assertTrue(dialect.translateExceptionIfPossible(re) instanceof DuplicateItemException);
    }
   
    @Test
    public void testTranslateExceptionIfPossible_unknownJdbcSQLExceptionError() {                
        JdbcSQLException jdbcEx = new JdbcSQLException("message", "sql statement", "state", ErrorCode.CANNOT_DROP_CURRENT_USER, null, "stacktrace");
        RuntimeException re = new RuntimeException("dummy runtime exception", jdbcEx);    
       
        TranslatedH2Exception translatedException = (TranslatedH2Exception) dialect.translateExceptionIfPossible(re);            
        assertThat(translatedException.getErrorCode(), is(ErrorCode.CANNOT_DROP_CURRENT_USER));       
    }
View Full Code Here

     * @return the SQLException object
     */
    public static JdbcSQLException getSQLException(int errorCode, String[] params, Throwable cause) {
        String sqlstate = ErrorCode.getState(errorCode);
        String message = translate(sqlstate, params);
        return new JdbcSQLException(message, null, sqlstate, errorCode, cause, null);
    }
View Full Code Here

     * @param sql the SQL statement
     * @return the error object
     */
    public static SQLException addSQL(SQLException e, String sql) {
        if (e instanceof JdbcSQLException) {
            JdbcSQLException j = (JdbcSQLException) e;
            if (j.getSQL() == null) {
                j.setSQL(sql);
            }
            return j;
        }
        return new JdbcSQLException(e.getMessage(), sql, e.getSQLState(), e.getErrorCode(), e, null);
    }
View Full Code Here

TOP

Related Classes of org.h2.jdbc.JdbcSQLException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.