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