提交 8813bbf4 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Replace references to JdbcSQLException with SQLException or JdbcException

上级 6716fb8b
......@@ -16,7 +16,7 @@ import org.h2.api.JavaObjectSerializer;
import org.h2.command.CommandInterface;
import org.h2.command.CommandRemote;
import org.h2.command.dml.SetTypes;
import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcException;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.message.TraceSystem;
......@@ -338,8 +338,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
DbException e = DbException.convert(re);
if (e.getErrorCode() == ErrorCode.DATABASE_ALREADY_OPEN_1) {
if (autoServerMode) {
String serverKey = ((JdbcSQLException) e.getSQLException()).
getSQL();
String serverKey = ((JdbcException) e.getSQLException()).getSQL();
if (serverKey != null) {
backup.setServerKey(serverKey);
// OPEN_NEW must be removed now, otherwise
......
......@@ -135,8 +135,8 @@ public class DbException extends RuntimeException {
*/
public DbException addSQL(String sql) {
SQLException e = getSQLException();
if (e instanceof JdbcSQLException) {
JdbcSQLException j = (JdbcSQLException) e;
if (e instanceof JdbcException) {
JdbcException j = (JdbcException) e;
if (j.getSQL() == null) {
j.setSQL(filterSQL(sql));
}
......
......@@ -13,7 +13,7 @@ import java.text.SimpleDateFormat;
import java.util.concurrent.atomic.AtomicReferenceArray;
import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcException;
import org.h2.store.fs.FileUtils;
import org.h2.util.IOUtils;
......@@ -260,8 +260,8 @@ public class TraceSystem implements TraceWriter {
}
printWriter.println(s);
if (t != null) {
if (levelFile == ERROR && t instanceof JdbcSQLException) {
JdbcSQLException se = (JdbcSQLException) t;
if (levelFile == ERROR && t instanceof JdbcException) {
JdbcException se = (JdbcException) t;
int code = se.getErrorCode();
if (ErrorCode.isCommon(code)) {
printWriter.println(t.toString());
......
......@@ -28,7 +28,7 @@ import org.h2.engine.SysProperties;
import org.h2.expression.Parameter;
import org.h2.expression.ParameterInterface;
import org.h2.expression.ParameterRemote;
import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcException;
import org.h2.message.DbException;
import org.h2.result.ResultColumn;
import org.h2.result.ResultInterface;
......@@ -235,8 +235,8 @@ public class TcpServerThread implements Runnable {
String trace = writer.toString();
String message;
String sql;
if (e instanceof JdbcSQLException) {
JdbcSQLException j = (JdbcSQLException) e;
if (e instanceof JdbcException) {
JdbcException j = (JdbcException) e;
message = j.getOriginalMessage();
sql = j.getSQL();
} else {
......
......@@ -42,7 +42,7 @@ import org.h2.bnf.context.DbSchema;
import org.h2.bnf.context.DbTableOrView;
import org.h2.engine.Constants;
import org.h2.engine.SysProperties;
import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcException;
import org.h2.message.DbException;
import org.h2.security.SHA256;
import org.h2.tools.Backup;
......@@ -935,8 +935,7 @@ public class WebApp {
* @return the formatted error message
*/
private String getLoginError(Exception e, boolean isH2) {
if (e instanceof JdbcSQLException &&
((JdbcSQLException) e).getErrorCode() == ErrorCode.CLASS_NOT_FOUND_1) {
if (e instanceof JdbcException && ((JdbcException) e).getErrorCode() == ErrorCode.CLASS_NOT_FOUND_1) {
return "${text.login.driverNotFound}<br />" + getStackTrace(0, e, isH2);
}
return getStackTrace(0, e, isH2);
......
......@@ -15,7 +15,6 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.api.ErrorCode;
import org.h2.jdbc.JdbcSQLException;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
......@@ -278,7 +277,7 @@ public class TestCompatibility extends TestDb {
try {
stat.execute("CREATE TABLE TEST(COL " + type + ")");
fail("Expect type " + type + " to not exist in PostgreSQL mode");
} catch (org.h2.jdbc.JdbcSQLException e) {
} catch (SQLException e) {
/* Expected! */
}
}
......@@ -675,7 +674,7 @@ public class TestCompatibility extends TestDb {
try {
getConnection("compatibility;MODE=Unknown").close();
deleteDb("compatibility");
} catch (JdbcSQLException ex) {
} catch (SQLException ex) {
assertEquals(ErrorCode.UNKNOWN_MODE_1, ex.getErrorCode());
return;
}
......
......@@ -46,7 +46,6 @@ import org.h2.api.Aggregate;
import org.h2.api.AggregateFunction;
import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
import org.h2.jdbc.JdbcSQLException;
import org.h2.message.DbException;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
......@@ -2023,12 +2022,12 @@ public class TestFunctions extends TestDb implements AggregateFunction {
conn.close();
}
private void testAnnotationProcessorsOutput() throws SQLException {
private void testAnnotationProcessorsOutput() {
try {
System.setProperty(TestAnnotationProcessor.MESSAGES_KEY, "WARNING,foo1|ERROR,foo2");
callCompiledFunction("test_annotation_processor_warn_and_error");
fail();
} catch (JdbcSQLException e) {
} catch (SQLException e) {
assertEquals(ErrorCode.SYNTAX_ERROR_1, e.getErrorCode());
assertContains(e.getMessage(), "foo1");
assertContains(e.getMessage(), "foo2");
......
......@@ -8,8 +8,8 @@ package org.h2.test.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.jdbc.JdbcSQLException;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
......@@ -235,7 +235,7 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
rs = prep.executeQuery();
fail("Temp view T1 was accessible after previous WITH statement finished "+
"- but should not have been.");
} catch (JdbcSQLException e) {
} catch (SQLException e) {
// ensure the T1 table has been removed even without auto commit
assertContains(e.getMessage(), "Table \"T1\" not found;");
}
......
......@@ -347,7 +347,7 @@ public class TestMergeUsing extends TestDb implements Trigger {
try {
testMergeUsing(setupSQL, statementUnderTest, gatherResultsSQL,
expectedResultsSQL, expectedRowUpdateCount);
} catch (RuntimeException | org.h2.jdbc.JdbcSQLException e) {
} catch (RuntimeException | SQLException e) {
if (!e.getMessage().contains(exceptionMessage)) {
e.printStackTrace();
}
......
......@@ -22,7 +22,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.h2.api.ErrorCode;
import org.h2.jdbc.JdbcSQLException;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
......@@ -372,9 +371,8 @@ public class TestMultiThread extends TestDb implements Runnable {
// ignore timeout exceptions, happens periodically when the
// machine is really busy and it's not the thing we are
// trying to test
if (!(ex.getCause() instanceof JdbcSQLException)
|| ((JdbcSQLException) ex.getCause())
.getErrorCode() != ErrorCode.LOCK_TIMEOUT_1) {
if (!(ex.getCause() instanceof SQLException)
|| ((SQLException) ex.getCause()).getErrorCode() != ErrorCode.LOCK_TIMEOUT_1) {
throw ex;
}
}
......
......@@ -5,7 +5,6 @@
*/
package org.h2.test.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -14,7 +13,6 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.h2.jdbc.JdbcSQLException;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
......@@ -124,7 +122,7 @@ public class TestSetCollation extends TestDb {
try {
getConnection(DB_NAME);
fail();
} catch (JdbcSQLException e) {
} catch (SQLException e) {
// expected
} finally {
config.collation = null;
......
......@@ -10,8 +10,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
import org.h2.jdbc.JdbcSQLException;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
......@@ -71,7 +71,7 @@ public class TestSynonymForTable extends TestDb {
stat.execute("CREATE OR REPLACE SYNONYM testsynonym FOR s1.backingtable");
stat.execute("DROP SCHEMA s1 CASCADE");
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).execute("SELECT id FROM testsynonym");
conn.close();
}
......@@ -82,7 +82,7 @@ public class TestSynonymForTable extends TestDb {
stat.execute("DROP TABLE backingtable");
// Backing table does not exist anymore.
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).execute("SELECT id FROM testsynonym");
// Synonym should be dropped as well
ResultSet synonyms = conn.createStatement().executeQuery(
......@@ -92,7 +92,7 @@ public class TestSynonymForTable extends TestDb {
// Reopening should work with dropped synonym
Connection conn2 = getConnection("synonym");
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
assertThrows(ErrorCode.OBJECT_CLOSED, stat).execute("SELECT id FROM testsynonym");
conn2.close();
}
......@@ -104,13 +104,13 @@ public class TestSynonymForTable extends TestDb {
stat.execute("DROP SYNONYM testsynonym");
// Synonym does not exist anymore.
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).execute("SELECT id FROM testsynonym");
// Dropping with "if exists" should succeed even if the synonym does not exist anymore.
stat.execute("DROP SYNONYM IF EXISTS testsynonym");
// Without "if exists" the command should fail if the synonym does not exist.
assertThrows(JdbcSQLException.class, stat).execute("DROP SYNONYM testsynonym");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).execute("DROP SYNONYM testsynonym");
conn.close();
}
......@@ -132,7 +132,8 @@ public class TestSynonymForTable extends TestDb {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS backingtable(id INT PRIMARY KEY)");
assertThrows(JdbcSQLException.class, stat).execute("CREATE OR REPLACE SYNONYM backingtable FOR backingtable");
assertThrows(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, stat)
.execute("CREATE OR REPLACE SYNONYM backingtable FOR backingtable");
conn.close();
}
......@@ -194,7 +195,8 @@ public class TestSynonymForTable extends TestDb {
Connection conn = getConnection("synonym");
Statement stat = conn.createStatement();
assertThrows(JdbcSQLException.class, stat).execute("CREATE SYNONYM someSynonym FOR nonexistingTable");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat)
.execute("CREATE SYNONYM someSynonym FOR nonexistingTable");
conn.close();
}
......@@ -203,7 +205,8 @@ public class TestSynonymForTable extends TestDb {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS backingtable(id INT PRIMARY KEY)");
assertThrows(JdbcSQLException.class, stat).execute("CREATE SYNONYM backingtable FOR backingtable");
assertThrows(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, stat)
.execute("CREATE SYNONYM backingtable FOR backingtable");
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论