com.mysql.cj.jdbc.exceptions.CommunicationsException Java Examples
The following examples show how to use
com.mysql.cj.jdbc.exceptions.CommunicationsException.
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: MysqlConnectionTester.java From lams with GNU General Public License v2.0 | 6 votes |
public int statusOnException(Connection arg0, Throwable throwable) { if (throwable instanceof CommunicationsException || throwable instanceof CJCommunicationsException) { return CONNECTION_IS_INVALID; } if (throwable instanceof SQLException) { String sqlState = ((SQLException) throwable).getSQLState(); if (sqlState != null && sqlState.startsWith("08")) { return CONNECTION_IS_INVALID; } return CONNECTION_IS_OKAY; } // Runtime/Unchecked? return CONNECTION_IS_INVALID; }
Example #2
Source File: FailoverConnectionProxy.java From lams with GNU General Public License v2.0 | 6 votes |
@Override boolean shouldExceptionTriggerConnectionSwitch(Throwable t) { String sqlState = null; if (t instanceof CommunicationsException || t instanceof CJCommunicationsException) { return true; } else if (t instanceof SQLException) { sqlState = ((SQLException) t).getSQLState(); } else if (t instanceof CJException) { sqlState = ((CJException) t).getSQLState(); } if (sqlState != null) { if (sqlState.startsWith("08")) { // connection error return true; } } return false; }
Example #3
Source File: MysqlConnectionTester.java From FoxTelem with GNU General Public License v3.0 | 6 votes |
@Override public int statusOnException(Connection arg0, Throwable throwable) { if (throwable instanceof CommunicationsException || throwable instanceof CJCommunicationsException) { return CONNECTION_IS_INVALID; } if (throwable instanceof SQLException) { String sqlState = ((SQLException) throwable).getSQLState(); if (sqlState != null && sqlState.startsWith("08")) { return CONNECTION_IS_INVALID; } return CONNECTION_IS_OKAY; } // Runtime/Unchecked? return CONNECTION_IS_INVALID; }
Example #4
Source File: FailoverConnectionProxy.java From FoxTelem with GNU General Public License v3.0 | 6 votes |
@Override boolean shouldExceptionTriggerConnectionSwitch(Throwable t) { String sqlState = null; if (t instanceof CommunicationsException || t instanceof CJCommunicationsException) { return true; } else if (t instanceof SQLException) { sqlState = ((SQLException) t).getSQLState(); } else if (t instanceof CJException) { sqlState = ((CJException) t).getSQLState(); } if (sqlState != null) { if (sqlState.startsWith("08")) { // connection error return true; } } return false; }
Example #5
Source File: StandardLoadBalanceExceptionChecker.java From lams with GNU General Public License v2.0 | 5 votes |
public boolean shouldExceptionTriggerFailover(Throwable ex) { String sqlState = ex instanceof SQLException ? ((SQLException) ex).getSQLState() : null; if (sqlState != null) { if (sqlState.startsWith("08")) { // connection error return true; } if (this.sqlStateList != null) { // check against SQLState list for (Iterator<String> i = this.sqlStateList.iterator(); i.hasNext();) { if (sqlState.startsWith(i.next().toString())) { return true; } } } } // always handle CommunicationException if (ex instanceof CommunicationsException || ex instanceof CJCommunicationsException) { return true; } if (this.sqlExClassList != null) { // check against configured class lists for (Iterator<Class<?>> i = this.sqlExClassList.iterator(); i.hasNext();) { if (i.next().isInstance(ex)) { return true; } } } // no matches return false; }
Example #6
Source File: ModelDBUtils.java From modeldb with Apache License 2.0 | 5 votes |
public static boolean needToRetry(Exception ex) { Throwable communicationsException = findCommunicationsFailedCause(ex); if ((communicationsException.getCause() instanceof CommunicationsException) || (communicationsException.getCause() instanceof SocketException)) { LOGGER.warn(communicationsException.getMessage()); if (ModelDBHibernateUtil.checkDBConnection()) { ModelDBHibernateUtil.resetSessionFactory(); } return true; } return false; }
Example #7
Source File: ModelDBUtils.java From modeldb with Apache License 2.0 | 5 votes |
public static Throwable findCommunicationsFailedCause(Throwable throwable) { if (throwable == null) { return null; } Throwable rootCause = throwable; while (rootCause.getCause() != null && !(rootCause.getCause() instanceof CommunicationsException || rootCause.getCause() instanceof SocketException)) { rootCause = rootCause.getCause(); } return rootCause; }
Example #8
Source File: StandardLoadBalanceExceptionChecker.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
@Override public boolean shouldExceptionTriggerFailover(Throwable ex) { String sqlState = ex instanceof SQLException ? ((SQLException) ex).getSQLState() : null; if (sqlState != null) { if (sqlState.startsWith("08")) { // connection error return true; } if (this.sqlStateList != null) { // check against SQLState list for (Iterator<String> i = this.sqlStateList.iterator(); i.hasNext();) { if (sqlState.startsWith(i.next().toString())) { return true; } } } } // always handle CommunicationException if (ex instanceof CommunicationsException || ex instanceof CJCommunicationsException) { return true; } if (this.sqlExClassList != null) { // check against configured class lists for (Iterator<Class<?>> i = this.sqlExClassList.iterator(); i.hasNext();) { if (i.next().isInstance(ex)) { return true; } } } // no matches return false; }
Example #9
Source File: ExceptionsTest.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
public void testConstructors() { new CommunicationsException(TEST_MESSAGE, new Throwable()); new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() { }, new PacketReceivedTimeHolder() { }, new Exception()); new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable()); new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() { }, new Exception()); new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0); new MySQLQueryInterruptedException(); new MySQLQueryInterruptedException(TEST_MESSAGE); new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE); new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0); new MySQLStatementCancelledException(); new MySQLStatementCancelledException(TEST_MESSAGE); new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE); new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0); new MySQLTimeoutException(); new MySQLTimeoutException(TEST_MESSAGE); new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE); new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0); new MySQLTransactionRollbackException(); new MySQLTransactionRollbackException(TEST_MESSAGE); new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE); new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0); new NotUpdatable(TEST_MESSAGE); new OperationNotSupportedException(); new OperationNotSupportedException(TEST_MESSAGE); new PacketTooBigException(TEST_MESSAGE); new PacketTooBigException(0, 100); new SQLError(); }