提交 19ae457e authored 作者: Noel Grandin's avatar Noel Grandin

rather expose getJdbcSQLException than create new utility methods

上级 47fa5cab
...@@ -347,9 +347,9 @@ public class DbException extends RuntimeException { ...@@ -347,9 +347,9 @@ public class DbException extends RuntimeException {
* @param errorCode the error code * @param errorCode the error code
* @return the SQLException object * @return the SQLException object
*/ */
public static SQLException getSQLException(int errorCode) public static SQLException getJdbcSQLException(int errorCode)
{ {
return getJdbcSQLException(errorCode, null, new String[0]); return getJdbcSQLException(errorCode, null);
} }
/** /**
...@@ -359,22 +359,9 @@ public class DbException extends RuntimeException { ...@@ -359,22 +359,9 @@ public class DbException extends RuntimeException {
* @param p1 the first parameter of the message * @param p1 the first parameter of the message
* @return the SQLException object * @return the SQLException object
*/ */
public static SQLException getSQLException(int errorCode, String p1) public static SQLException getJdbcSQLException(int errorCode, String p1)
{ {
return getJdbcSQLException(errorCode, null, new String[] { p1 }); return getJdbcSQLException(errorCode, null, p1);
}
/**
* Create the SQL exception object for a specific error code.
*
* @param errorCode the error code
* @param cause the cause of the exception
* @param params the list of parameters of the message
* @return the exception
*/
public static SQLException getSQLException(int errorCode, Throwable cause, String... params)
{
return getJdbcSQLException(errorCode, cause, params);
} }
/** /**
...@@ -385,7 +372,7 @@ public class DbException extends RuntimeException { ...@@ -385,7 +372,7 @@ public class DbException extends RuntimeException {
* @param params the list of parameters of the message * @param params the list of parameters of the message
* @return the SQLException object * @return the SQLException object
*/ */
private static JdbcSQLException getJdbcSQLException(int errorCode, public static JdbcSQLException getJdbcSQLException(int errorCode,
Throwable cause, String... params) { Throwable cause, String... params) {
String sqlstate = ErrorCode.getState(errorCode); String sqlstate = ErrorCode.getState(errorCode);
String message = translate(sqlstate, params); String message = translate(sqlstate, params);
......
...@@ -43,7 +43,7 @@ public class FileLister { ...@@ -43,7 +43,7 @@ public class FileLister {
lock.lock(FileLockMethod.FILE); lock.lock(FileLockMethod.FILE);
lock.unlock(); lock.unlock();
} catch (DbException e) { } catch (DbException e) {
throw DbException.getSQLException( throw DbException.getJdbcSQLException(
ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1,
message); message);
} }
...@@ -52,7 +52,7 @@ public class FileLister { ...@@ -52,7 +52,7 @@ public class FileLister {
java.nio.channels.FileLock lock = f.tryLock(0, Long.MAX_VALUE, true); java.nio.channels.FileLock lock = f.tryLock(0, Long.MAX_VALUE, true);
lock.release(); lock.release();
} catch (Exception e) { } catch (Exception e) {
throw DbException.getSQLException( throw DbException.getJdbcSQLException(
ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, e, ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, e,
message); message);
} }
......
...@@ -226,7 +226,7 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -226,7 +226,7 @@ public class LobStorageBackend implements LobStorageInterface {
prep.setLong(1, block); prep.setLong(1, block);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
if (!rs.next()) { if (!rs.next()) {
throw DbException.getSQLException(ErrorCode.IO_EXCEPTION_1, throw DbException.getJdbcSQLException(ErrorCode.IO_EXCEPTION_1,
"Missing lob entry, block: " + block); "Missing lob entry, block: " + block);
} }
int compressed = rs.getInt(1); int compressed = rs.getInt(1);
...@@ -652,7 +652,7 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -652,7 +652,7 @@ public class LobStorageBackend implements LobStorageInterface {
prep.setLong(1, lobId); prep.setLong(1, lobId);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
if (!rs.next()) { if (!rs.next()) {
throw DbException.getSQLException(ErrorCode.IO_EXCEPTION_1, throw DbException.getJdbcSQLException(ErrorCode.IO_EXCEPTION_1,
"Missing lob entry: " + lobId); "Missing lob entry: " + lobId);
} }
byteCount = rs.getLong(1); byteCount = rs.getLong(1);
...@@ -667,7 +667,7 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -667,7 +667,7 @@ public class LobStorageBackend implements LobStorageInterface {
rs.next(); rs.next();
int lobMapCount = rs.getInt(1); int lobMapCount = rs.getInt(1);
if (lobMapCount == 0) { if (lobMapCount == 0) {
throw DbException.getSQLException(ErrorCode.IO_EXCEPTION_1, throw DbException.getJdbcSQLException(ErrorCode.IO_EXCEPTION_1,
"Missing lob entry: " + lobId); "Missing lob entry: " + lobId);
} }
reuse(sql, prep); reuse(sql, prep);
......
...@@ -586,7 +586,7 @@ public class Csv implements SimpleRowSource { ...@@ -586,7 +586,7 @@ public class Csv implements SimpleRowSource {
} }
private static SQLException convertException(String message, Exception e) { private static SQLException convertException(String message, Exception e) {
return DbException.getSQLException(ErrorCode.IO_EXCEPTION_1, e, message); return DbException.getJdbcSQLException(ErrorCode.IO_EXCEPTION_1, e, message);
} }
/** /**
......
...@@ -242,7 +242,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData, ...@@ -242,7 +242,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
@Override @Override
public void beforeFirst() throws SQLException { public void beforeFirst() throws SQLException {
if (autoClose) { if (autoClose) {
throw DbException.getSQLException(ErrorCode.RESULT_SET_NOT_SCROLLABLE); throw DbException.getJdbcSQLException(ErrorCode.RESULT_SET_NOT_SCROLLABLE);
} }
rowId = -1; rowId = -1;
if (source != null) { if (source != null) {
...@@ -278,7 +278,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData, ...@@ -278,7 +278,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
} }
} }
} }
throw DbException.getSQLException(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel); throw DbException.getJdbcSQLException(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
} }
/** /**
...@@ -2264,12 +2264,12 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData, ...@@ -2264,12 +2264,12 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
* INTERNAL * INTERNAL
*/ */
static SQLException getUnsupportedException() { static SQLException getUnsupportedException() {
return DbException.getSQLException(ErrorCode.FEATURE_NOT_SUPPORTED_1); return DbException.getJdbcSQLException(ErrorCode.FEATURE_NOT_SUPPORTED_1);
} }
private void checkClosed() throws SQLException { private void checkClosed() throws SQLException {
if (columns == null) { if (columns == null) {
throw DbException.getSQLException(ErrorCode.OBJECT_CLOSED); throw DbException.getJdbcSQLException(ErrorCode.OBJECT_CLOSED);
} }
} }
...@@ -2282,7 +2282,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData, ...@@ -2282,7 +2282,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
private Object get(int columnIndex) throws SQLException { private Object get(int columnIndex) throws SQLException {
if (currentRow == null) { if (currentRow == null) {
throw DbException.getSQLException(ErrorCode.NO_DATA_AVAILABLE); throw DbException.getJdbcSQLException(ErrorCode.NO_DATA_AVAILABLE);
} }
checkColumnIndex(columnIndex); checkColumnIndex(columnIndex);
columnIndex--; columnIndex--;
......
...@@ -64,7 +64,7 @@ public abstract class Tool { ...@@ -64,7 +64,7 @@ public abstract class Tool {
*/ */
protected SQLException throwUnsupportedOption(String option) protected SQLException throwUnsupportedOption(String option)
throws SQLException { throws SQLException {
throw DbException.getSQLException( throw DbException.getJdbcSQLException(
ErrorCode.FEATURE_NOT_SUPPORTED_1, option); ErrorCode.FEATURE_NOT_SUPPORTED_1, option);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论