/**
* Validate that the ordering of the returned Exceptions is correct
* using Traditional while loop
*/
@Test
public void test12() {
sqlRecoverableException ex = new sqlRecoverableException("Exception 1",t1);
sqlRecoverableException ex1 = new sqlRecoverableException("Exception 2");
sqlRecoverableException ex2 = new sqlRecoverableException("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();
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using Traditional while loop
*/
@Test
public void test12() {
sqlRecoverableException ex = new sqlRecoverableException("Exception 1",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();
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using Traditional while loop
*/
@Test
public void test12() {
sqlRecoverableException ex = new sqlRecoverableException("Exception 1",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();
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using Traditional while loop
*/
@Test
public void test12() {
sqlRecoverableException ex = new sqlRecoverableException("Exception 1",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();
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using Traditional while loop
*/
@Test
public void test12() {
sqlRecoverableException ex = new sqlRecoverableException("Exception 1",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();
}
}
项目:cassandra-jdbc-wrapper
文件:PooledCassandraConnection.java
void statementErrorOccurred(CassandraPreparedStatement preparedStatement,sqlException sqlException)
{
StatementEvent event = new StatementEvent(this,preparedStatement,sqlException);
for (StatementEventListener listener : statementEventListeners)
{
listener.statementErrorOccurred(event);
}
String cql = preparedStatement.getCql();
Set<CassandraPreparedStatement> usedStatements = usedPreparedStatements.get(cql);
if (!(event.getsqlException() instanceof sqlRecoverableException))
{
preparedStatement.close();
usedStatements.remove(preparedStatement);
}
}
/**
* @test java.sql.sqlRecoverableException(Throwable)
*/
public void test_Constructor_LThrowable() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
cause);
assertNotNull(sqlRecoverableException);
assertEquals(
"The reason of sqlRecoverableException should be equals to cause.toString()","java.lang.Exception: MYTHROWABLE",sqlRecoverableException
.getMessage());
assertNull("The sqlState of sqlRecoverableException should be null",sqlRecoverableException.getsqlState());
assertEquals("The error code of sqlRecoverableException should be 0",sqlRecoverableException.getErrorCode(),0);
assertEquals(
"The cause of sqlRecoverableException set and get should be equivalent",cause,sqlRecoverableException.getCause());
}
/**
* @test java.sql.sqlRecoverableException(String,Throwable)
*/
public void test_Constructor_LStringLThrowable() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING",cause);
assertNotNull(sqlRecoverableException);
assertEquals(
"The reason of sqlRecoverableException set and get should be equivalent","MYTESTSTRING",sqlRecoverableException.getMessage());
assertNull("The sqlState of sqlRecoverableException should be null",String,Throwable)
*/
public void test_Constructor_LStringLStringLThrowable() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1","MYTESTSTRING2",cause);
assertNotNull(sqlRecoverableException);
assertEquals(
"The sqlState of sqlRecoverableException set and get should be equivalent",sqlRecoverableException.getsqlState());
assertEquals(
"The reason of sqlRecoverableException set and get should be equivalent","MYTESTSTRING1",sqlRecoverableException.getMessage());
assertEquals("The error code of sqlRecoverableException should be 0",Throwable)
*/
public void test_Constructor_LStringLStringLThrowable_1() {
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1",null);
assertNotNull(sqlRecoverableException);
assertEquals(
"The sqlState of sqlRecoverableException set and get should be equivalent",0);
assertNull("The cause of sqlRecoverableException should be null",Throwable)
*/
public void test_Constructor_LStringLStringLThrowable_2() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING",null,cause);
assertNotNull(sqlRecoverableException);
assertNull("The sqlState of sqlRecoverableException should be null",Throwable)
*/
public void test_Constructor_LStringLStringLThrowable_4() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,sqlRecoverableException.getsqlState());
assertNull("The reason of sqlRecoverableException should be null",Throwable)
*/
public void test_Constructor_LStringLStringLThrowable_6() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,int,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1",1,sqlRecoverableException.getMessage());
assertEquals("The error code of sqlRecoverableException should be 1",1);
assertEquals(
"The cause of sqlRecoverableException set and get should be equivalent",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_1() {
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1",1);
assertNull("The cause of sqlRecoverableException should be null",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_2() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_3() {
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_4() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1",-1,sqlRecoverableException.getMessage());
assertEquals("The error code of sqlRecoverableException should be -1",-1);
assertEquals(
"The cause of sqlRecoverableException set and get should be equivalent",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_5() {
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING1",-1);
assertNull("The cause of sqlRecoverableException should be null",sqlRecoverableException.getCause());
}
/**
* @test java.sql.sqlRecoverableException(String,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_6() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_7() {
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING",null);
assertNotNull(sqlRecoverableException);
assertNotNull(sqlRecoverableException);
assertNull("The sqlState of sqlRecoverableException should be null",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_8() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_10() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
"MYTESTSTRING",Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_12() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_14() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_15() {
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_16() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_18() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_20() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,Throwable)
*/
public void test_Constructor_LStringLStringILThrowable_22() {
Throwable cause = new Exception("MYTHROWABLE");
sqlRecoverableException sqlRecoverableException = new sqlRecoverableException(
null,sqlRecoverableException.getCause());
}
@Override
public boolean isTransient(Exception e) {
if (e instanceof sqlTransientException || e instanceof sqlRecoverableException) {
return true;
}
if (e instanceof sqlNonTransientException) {
return false;
}
if (e instanceof sqlException) {
sqlException se = (sqlException) e;
if (issqlStateConnectionException(se) || issqlStateRollbackException(se)) {
return true;
}
if (issqlStateDuplicateValueInUniqueIndex(se) && treatDuplicatesAsTransient) {
return true;
}
}
return false;
}
private static ASsqlStatement getStatement (String queryString) throws sqlException
{
CharStream charstream = new ANTlrstringStream(queryString);
ASsqlLexer lexer = new ASsqlLexer(charstream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ASsqlParser parser = new ASsqlParser(tokens);
ASsqlStatement statement = null;
try
{
statement = parser.query();
}
catch (RecognitionException ex)
{
throw new sqlRecoverableException(ex);
}
// The lexer and parser queue up any errors they may have encountered
// along the way,if necessary,we turn them into exceptions here.
lexer.throwFirstRecognitionError();
parser.throwFirstRecognitionError();
return statement;
}
@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,ex);
}
else if (ex instanceof sqlTimeoutException) {
return new QueryTimeoutException(buildMessage(task,ex);
}
}
else if (ex instanceof sqlNonTransientException) {
if (ex instanceof sqlNonTransientConnectionException) {
return new DataAccessResourceFailureException(buildMessage(task,ex);
}
else if (ex instanceof sqlDataException) {
return new DataIntegrityViolationException(buildMessage(task,ex);
}
else if (ex instanceof sqlIntegrityConstraintViolationException) {
return new DataIntegrityViolationException(buildMessage(task,ex);
}
else if (ex instanceof sqlInvalidAuthorizationSpecException) {
return new PermissionDeniedDataAccessException(buildMessage(task,ex);
}
else if (ex instanceof sqlSyntaxErrorException) {
return new BadsqlGrammarException(task,ex);
}
else if (ex instanceof sqlFeatureNotSupportedException) {
return new InvalidDataAccessApiUsageException(buildMessage(task,ex);
}
}
else if (ex instanceof sqlRecoverableException) {
return new RecoverableDataAccessException(buildMessage(task,ex);
}
// Fallback to Spring's own sql state translation...
return null;
}
/**
* Create sqlRecoverableException with message,sqlState,and error code
*/
@Test
public void test4() {
sqlRecoverableException ex =
new sqlRecoverableException(reason,state,errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getsqlState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create sqlRecoverableException with message,and Throwable
*/
@Test
public void test5() {
sqlRecoverableException ex =
new sqlRecoverableException(reason,t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getsqlState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create sqlRecoverableException with message,and Throwable
*/
@Test
public void test6() {
sqlRecoverableException ex = new sqlRecoverableException(reason,t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getsqlState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。