java.sql.SQLTransientException Java Examples

The following examples show how to use java.sql.SQLTransientException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraPreparedStatement.java    From cassandra-jdbc-wrapper with Apache License 2.0 6 votes vote down vote up
CassandraPreparedStatement(CassandraConnection con,
    String cql,
    int rsType,
    int rsConcurrency,
    int rsHoldability
    ) throws SQLException
{
   super(con,cql,rsType,rsConcurrency,rsHoldability);       
   
   if (LOG.isTraceEnabled()) LOG.trace("CQL: " + this.cql);
   try
   {
	   stmt = this.connection.getSession().prepare(cql); 
	   this.statement = new BoundStatement(stmt);    	   
	   batchStatements = Lists.newArrayList();
	   count = cql.length() - cql.replace("?", "").length();   	   
   }
   catch (Exception e)
   {
       throw new SQLTransientException(e);
   }
}
 
Example #2
Source File: Helpers.java    From jqm with Apache License 2.0 6 votes vote down vote up
static boolean testDbFailure(Exception e)
{
    return (e instanceof SQLTransientException) || (e.getCause() instanceof SQLTransientException)
            || (e.getCause() != null && e.getCause().getCause() instanceof SQLTransientException)
            || (e.getCause() != null && e.getCause().getCause() != null
                    && e.getCause().getCause().getCause() instanceof SQLTransientException)
            || (e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause().getCause() != null
                    && e.getCause().getCause().getCause().getCause() instanceof SQLTransientException)
            || (e.getCause() != null && e.getCause() instanceof SQLException
                    && e.getMessage().equals("Failed to validate a newly established connection."))
            || (e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause() instanceof SocketException)
            || (e.getCause() != null && e.getCause().getMessage().equals("This connection has been closed"))
            || (e.getCause() != null && e.getCause() instanceof SQLNonTransientConnectionException)
            || (e.getCause() != null && e.getCause() instanceof SQLNonTransientException
                    && e.getCause().getMessage().equals("connection exception: closed"));
}
 
Example #3
Source File: Oracle.java    From morf with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.alfasoftware.morf.jdbc.DatabaseType#reclassifyException(java.lang.Exception)
 */
@Override
public Exception reclassifyException(Exception e) {
  // Reclassify OracleXA exceptions
  Optional<Integer> xaErrorCode = getErrorCodeFromOracleXAException(e);
  if (xaErrorCode.isPresent()) {
    // ORA-00060: Deadlock detected while waiting for resource
    // ORA-02049: Distributed transaction waiting for lock
    if (xaErrorCode.get() == 60 || xaErrorCode.get() == 2049) {
      return new SQLTransientException(e.getMessage(), null, xaErrorCode.get(), e);
    }
    return new SQLException(e.getMessage(), null, xaErrorCode.get(), e);
  }

  // Reclassify any SQLExceptions which should be SQLTransientExceptions but are not. Specifically this handles BatchUpdateExceptions
  if(e instanceof SQLException && !(e instanceof SQLTransientException)) {
    int errorCode = ((SQLException) e).getErrorCode();
    if(errorCode == 60 || errorCode == 2049) {
      return new SQLTransientException(e.getMessage(), ((SQLException) e).getSQLState(), errorCode, e);
    }
  }

  return e;
}
 
Example #4
Source File: AuthorityFactories.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the fallback to use if the authority factory is not available. Unless the problem may be temporary,
 * this method replaces the {@link EPSGFactory} instance by {@link EPSGFactoryFallback} in order to prevent
 * the same exception to be thrown and logged on every calls to {@link CRS#forCode(String)}.
 */
static GeodeticAuthorityFactory fallback(final UnavailableFactoryException e) throws UnavailableFactoryException {
    final boolean isTransient = (e.getCause() instanceof SQLTransientException);
    final AuthorityFactory unavailable = e.getUnavailableFactory();
    GeodeticAuthorityFactory factory;
    final boolean alreadyDone;
    synchronized (EPSG) {
        factory = EPSG[0];
        alreadyDone = (factory == EPSGFactoryFallback.INSTANCE);
        if (!alreadyDone) {                             // May have been set in another thread (race condition).
            if (unavailable != factory) {
                throw e;                                // Exception did not come from a factory that we control.
            }
            factory = EPSGFactoryFallback.INSTANCE;
            if (!isTransient) {
                ALL.reload();
                EPSG[0] = factory;
            }
        }
    }
    if (!alreadyDone) {
        log(e, true);
    }
    return factory;
}
 
Example #5
Source File: SQLTransientExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTransientException ex = new SQLTransientException("Exception 1", t1);
    SQLTransientException ex1 = new SQLTransientException("Exception 2");
    SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #6
Source File: SQLTransientExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTransientException ex = new SQLTransientException("Exception 1", t1);
    SQLTransientException ex1 = new SQLTransientException("Exception 2");
    SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #7
Source File: SQLTransientExceptionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTransientException ex = new SQLTransientException("Exception 1", t1);
    SQLTransientException ex1 = new SQLTransientException("Exception 2");
    SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #8
Source File: SQLTransientExceptionTests.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTransientException ex = new SQLTransientException("Exception 1", t1);
    SQLTransientException ex1 = new SQLTransientException("Exception 2");
    SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #9
Source File: CassandraPreparedStatement.java    From cassandra-jdbc-wrapper with Apache License 2.0 6 votes vote down vote up
private void doExecute() throws SQLException
{
    if (LOG.isTraceEnabled()) LOG.trace("CQL: " + cql);
    try
    {
        resetResults();
        if (this.connection.debugMode) System.out.println("CQL: "+ cql);     
        if(this.statement.getFetchSize()==0)
        		// force paging to avoid timeout and node harm...
        		this.statement.setFetchSize(100);
        this.statement.setConsistencyLevel(this.connection.defaultConsistencyLevel);
        for(int i=0; i<this.statement.preparedStatement().getVariables().size(); i++){
        	// Set parameters to null if unset
        	if(!this.statement.isSet(i)){
        		this.statement.setToNull(i);
        	}
        }
        currentResultSet = new CassandraResultSet(this, this.connection.getSession().execute(this.statement));
    }
    catch (Exception e)
    {
        throw new SQLTransientException(e);
    }
}
 
Example #10
Source File: SQLTransientExceptionTests.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTransientException ex = new SQLTransientException("Exception 1", t1);
    SQLTransientException ex1 = new SQLTransientException("Exception 2");
    SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #11
Source File: SQLTransientExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTransientException ex = new SQLTransientException("Exception 1", t1);
    SQLTransientException ex1 = new SQLTransientException("Exception 2");
    SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #12
Source File: SQLTransientExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message, and SQLState
 */
@Test
public void test3() {
    SQLTransientException ex = new SQLTransientException(reason, state);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #13
Source File: SQLTransientExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with null Throwable
 */
@Test
public void test8() {
    SQLTransientException ex = new SQLTransientException((Throwable)null);
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #14
Source File: LambdaTest2_SAM2.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void methodUV(UV uv) {
    System.out.println("methodUV(): SAM type interface UV object instantiated: " + uv);
    try{
        System.out.println("result returned: " + uv.foo(strs));
    }catch(EOFException e){
        System.out.println(e.getMessage());
    }catch(SQLTransientException ex){
        System.out.println(ex.getMessage());
    }
}
 
Example #15
Source File: SQLTransientExceptionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLTransientException ex = new SQLTransientException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example #16
Source File: LambdaTest2_SAM2.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void methodUV(UV uv) {
    System.out.println("methodUV(): SAM type interface UV object instantiated: " + uv);
    try{
        System.out.println("result returned: " + uv.foo(strs));
    }catch(EOFException e){
        System.out.println(e.getMessage());
    }catch(SQLTransientException ex){
        System.out.println(ex.getMessage());
    }
}
 
Example #17
Source File: SQLTransientExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message
 */
@Test
public void test2() {
    SQLTransientException ex = new SQLTransientException(reason);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #18
Source File: SQLTransientExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLTransientException ex = new SQLTransientException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example #19
Source File: SQLTransientExceptionTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message, and SQLState
 */
@Test
public void test3() {
    SQLTransientException ex = new SQLTransientException(reason, state);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #20
Source File: SQLTransientExceptionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with null Throwable
 */
@Test
public void test8() {
    SQLTransientException ex = new SQLTransientException((Throwable)null);
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #21
Source File: SQLTransientExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with Throwable
 */
@Test
public void test9() {
    SQLTransientException ex = new SQLTransientException(t);
    assertTrue(ex.getMessage().equals(cause)
            && ex.getSQLState() == null
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example #22
Source File: ConnectionRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests fix for Bug#16634180 - LOCK WAIT TIMEOUT EXCEEDED CAUSES SQLEXCEPTION, SHOULD CAUSE SQLTRANSIENTEXCEPTION
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug16634180() throws Exception {

    createTable("testBug16634180", "(pk integer primary key, val integer)", "InnoDB");
    this.stmt.executeUpdate("insert into testBug16634180 values(0,0)");

    Connection c1 = null;
    Connection c2 = null;

    try {
        c1 = getConnectionWithProps(new Properties());
        c1.setAutoCommit(false);
        Statement s1 = c1.createStatement();
        s1.executeUpdate("update testBug16634180 set val=val+1 where pk=0");

        c2 = getConnectionWithProps(new Properties());
        c2.setAutoCommit(false);
        Statement s2 = c2.createStatement();
        try {
            s2.executeUpdate("update testBug16634180 set val=val+1 where pk=0");
            fail("ER_LOCK_WAIT_TIMEOUT should be thrown.");
        } catch (SQLTransientException ex) {
            assertEquals(MysqlErrorNumbers.ER_LOCK_WAIT_TIMEOUT, ex.getErrorCode());
            assertEquals(SQLError.SQL_STATE_ROLLBACK_SERIALIZATION_FAILURE, ex.getSQLState());
            assertEquals("Lock wait timeout exceeded; try restarting transaction", ex.getMessage());
        }
    } finally {
        if (c1 != null) {
            c1.close();
        }
        if (c2 != null) {
            c2.close();
        }
    }
}
 
Example #23
Source File: CheckNoTimeoutException.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void methodUV(UV uv) {
    System.out.println("methodUV(): SAM type interface UV object instantiated: " + uv);
    try{
        System.out.println("result returned: " + uv.foo(strs));
    }catch(EOFException e){
        System.out.println(e.getMessage());
    }catch(SQLTransientException ex){
        System.out.println(ex.getMessage());
    }
}
 
Example #24
Source File: SQLTransientExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLTransientException ex =
            new SQLTransientException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example #25
Source File: SQLTransientExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLTransientException ex = new SQLTransientException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example #26
Source File: SQLExceptionSubclassTranslator.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
	if (ex instanceof SQLTransientException) {
		if (ex instanceof SQLTransientConnectionException) {
			return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTransactionRollbackException) {
			return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTimeoutException) {
			return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLNonTransientException) {
		if (ex instanceof SQLNonTransientConnectionException) {
			return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLDataException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLIntegrityConstraintViolationException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLInvalidAuthorizationSpecException) {
			return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLSyntaxErrorException) {
			return new BadSqlGrammarException(task, sql, ex);
		}
		else if (ex instanceof SQLFeatureNotSupportedException) {
			return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLRecoverableException) {
		return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
	}

	// Fallback to Spring's own SQL state translation...
	return null;
}
 
Example #27
Source File: SQLTransientExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message
 */
@Test
public void test2() {
    SQLTransientException ex = new SQLTransientException(reason);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #28
Source File: SQLTransientExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with no-arg constructor
 */
@Test
public void test1() {
    SQLTransientException ex = new SQLTransientException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #29
Source File: SQLTransientExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLTransientException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLTransientException ex = new SQLTransientException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example #30
Source File: LambdaTest2_SAM2.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void methodUVW(UVW uvw) {
    System.out.println("methodUVW(): SAM type interface UVW object instantiated: " + uvw);
    try{
        System.out.println("passing List<String>: " + uvw.foo(strs));
        System.out.println("passing List: " + uvw.foo(new ArrayList()));
    }catch(EOFException e){
        System.out.println(e.getMessage());
    }catch(SQLTransientException ex){
        System.out.println(ex.getMessage());
    }
}