use of java.sql.SQLWarning in project spring-framework by spring-projects.
the class JdbcTemplateTests method testFatalWarning.
/**
* Mock objects allow us to produce warnings at will
*/
@Test
public void testFatalWarning() throws Exception {
String sql = "SELECT forename from custmr";
SQLWarning warnings = new SQLWarning("My warning");
given(this.resultSet.next()).willReturn(false);
given(this.preparedStatement.getWarnings()).willReturn(warnings);
given(this.connection.createStatement()).willReturn(this.preparedStatement);
JdbcTemplate t = new JdbcTemplate(this.dataSource);
t.setIgnoreWarnings(false);
ResultSetExtractor<Byte> extractor = rs -> rs.getByte(1);
assertThatExceptionOfType(SQLWarningException.class).isThrownBy(() -> t.query(sql, extractor)).withCause(warnings);
verify(this.resultSet).close();
verify(this.preparedStatement).close();
verify(this.connection).close();
}
use of java.sql.SQLWarning in project druid by alibaba.
the class ResultSetProxyImpl method getWarnings.
@Override
public SQLWarning getWarnings() throws SQLException {
FilterChainImpl chain = createChain();
SQLWarning value = chain.resultSet_getWarnings(this);
recycleFilterChain(chain);
return value;
}
use of java.sql.SQLWarning in project druid by alibaba.
the class ConnectionProxyImpl method getWarnings.
@Override
public SQLWarning getWarnings() throws SQLException {
FilterChainImpl chain = createChain();
SQLWarning value = chain.connection_getWarnings(this);
recycleFilterChain(chain);
return value;
}
use of java.sql.SQLWarning in project Payara by payara.
the class TransactionalAnnotationTest method testSpecRollbackOnDontRollbackOnSample.
public void testSpecRollbackOnDontRollbackOnSample() throws Exception {
TransactionalInterceptorRequired transactionalInterceptorREQUIRED = new TransactionalInterceptorRequired();
javax.transaction.TransactionManager transactionManager = new TransactionManager();
transactionalInterceptorREQUIRED.setTestTransactionManager(transactionManager);
javax.interceptor.InvocationContext ctx = new InvocationContext(BeanSpecExampleOfRollbackDontRollback.class.getMethod("throwSQLException"), null, BeanSpecExampleOfRollbackDontRollback.class) {
@Override
public Object getTarget() {
return new BeanSpecExampleOfRollbackDontRollback();
}
@Override
public Object proceed() throws Exception {
throw new SQLException("test SQLException");
}
};
transactionManager.begin();
try {
transactionalInterceptorREQUIRED.transactional(ctx);
} catch (SQLException sqlex) {
}
try {
transactionManager.commit();
fail("should have thrown RollbackException due to mark for rollback");
} catch (RollbackException rbe) {
}
// Now with a child of SQLException
ctx = new InvocationContext(BeanSpecExampleOfRollbackDontRollback.class.getMethod("throwSQLException"), null, BeanSpecExampleOfRollbackDontRollback.class) {
@Override
public Object getTarget() {
return new BeanSpecExampleOfRollbackDontRollback();
}
@Override
public Object proceed() throws Exception {
throw new SQLExceptionExtension();
}
};
transactionManager.begin();
try {
transactionalInterceptorREQUIRED.transactional(ctx);
} catch (SQLExceptionExtension sqlex) {
}
try {
transactionManager.commit();
fail("should have thrown RollbackException due to mark for rollback");
} catch (RollbackException rbe) {
}
// now with a child of SQLException but one that is specified as dontRollback
ctx = new InvocationContext(BeanSpecExampleOfRollbackDontRollback.class.getMethod("throwSQLWarning"), null, BeanSpecExampleOfRollbackDontRollback.class) {
@Override
public Object proceed() throws Exception {
throw new SQLWarning("test SQLWarning");
}
@Override
public Object getTarget() {
return new BeanSpecExampleOfRollbackDontRollback();
}
};
transactionManager.begin();
try {
transactionalInterceptorREQUIRED.transactional(ctx);
} catch (SQLWarning sqlex) {
}
try {
transactionManager.commit();
} catch (Exception rbe) {
fail("should not thrown Exception");
}
// now with a child of SQLWarning but one that is specified as rollback
// ie testing this
// @Transactional(
// rollbackOn = {SQLException.class, SQLWarningExtension.class},
// dontRollbackOn = {SQLWarning.class})
// where dontRollbackOn=SQLWarning overrides rollbackOn=SQLException,
// but rollbackOn=SQLWarningExtension overrides dontRollbackOn=SQLWarning
// ie...
// SQLException isAssignableFrom SQLWarning
// SQLWarning isAssignableFrom SQLWarningExtensionExtension
// SQLWarningExtensionExtension isAssignableFrom SQLWarningExtension
ctx = new InvocationContext(BeanSpecExampleOfRollbackDontRollbackExtension.class.getMethod("throwSQLWarning"), null, BeanSpecExampleOfRollbackDontRollbackExtension.class) {
@Override
public Object proceed() throws Exception {
throw new SQLWarningExtension();
}
@Override
public Object getTarget() {
return new BeanSpecExampleOfRollbackDontRollbackExtension();
}
};
transactionManager.begin();
try {
transactionalInterceptorREQUIRED.transactional(ctx);
} catch (SQLWarningExtension sqlex) {
}
try {
transactionManager.commit();
fail("should have thrown RollbackException due to mark for rollback");
} catch (RollbackException rbe) {
}
// same as above test but with extension just to show continued inheritance...
ctx = new InvocationContext(BeanSpecExampleOfRollbackDontRollbackExtension.class.getMethod("throwSQLWarning"), null, BeanSpecExampleOfRollbackDontRollbackExtension.class) {
@Override
public Object proceed() throws Exception {
throw new SQLWarningExtensionExtension();
}
@Override
public Object getTarget() {
return new BeanSpecExampleOfRollbackDontRollbackExtension();
}
};
transactionManager.begin();
try {
transactionalInterceptorREQUIRED.transactional(ctx);
} catch (SQLWarningExtensionExtension sqlex) {
}
try {
transactionManager.commit();
fail("should have thrown RollbackException due to mark for rollback");
} catch (RollbackException rbe) {
}
}
use of java.sql.SQLWarning in project dbeaver by dbeaver.
the class SQLServerToolWithStatus method getExecuteStatistics.
@Override
public List<ToolStatus> getExecuteStatistics(OBJECT_TYPE object, SETTINGS settings, DBEPersistAction action, DBCSession session, DBCStatement dbStat) throws DBCException {
List<ToolStatus> statusList = new ArrayList<>();
try {
int warnNum = 0;
SQLWarning warning = ((JDBCStatement) dbStat).getWarnings();
while (warning != null) {
statusList.add(new ToolStatus(object, warning.getMessage()));
warnNum++;
warning = warning.getNextWarning();
}
if (warnNum == 0) {
statusList.add(new ToolStatus(object, "Done"));
}
} catch (SQLException e) {
// ignore
}
return statusList;
}
Aggregations