Skip to content

Commit

Permalink
Risoluzione Issue apache#4, apache#5, apache#6
Browse files Browse the repository at this point in the history
  • Loading branch information
VanniMaceria committed Oct 14, 2024
1 parent 1121337 commit c490e81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/main/java/org/apache/commons/dbutils/QueryRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import javax.sql.DataSource;

import org.apache.commons.dbutils.constants.SQLExceptionCostants;

/**
* Executes SQL queries with pluggable strategies for handling
* {@code ResultSet}s. This class is thread safe.
Expand Down Expand Up @@ -131,15 +133,15 @@ public QueryRunner(final StatementConfiguration stmtConfig) {
*/
public int[] batch(final Connection conn, final String sql, final Object[][] params) throws SQLException {
if (conn == null) {
throw new SQLException("Null connection");
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
}

if (sql == null) {
throw new SQLException("Null SQL statement");
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
}

if (params == null) {
throw new SQLException("Null parameters. If parameters aren't need, pass an empty array.");
throw new SQLException(SQLExceptionCostants.NULL_PARAMS_ERROR);
}

PreparedStatement stmt = null;
Expand Down Expand Up @@ -206,11 +208,11 @@ public int[] batch(final String sql, final Object[][] params) throws SQLExceptio
*/
public int execute(final Connection conn, final String sql, final Object... params) throws SQLException {
if (conn == null) {
throw new SQLException("Null connection");
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
}

if (sql == null) {
throw new SQLException("Null SQL statement");
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
}

CallableStatement stmt = null;
Expand Down Expand Up @@ -257,15 +259,15 @@ public int execute(final Connection conn, final String sql, final Object... para
*/
public <T> List<T> execute(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object... params) throws SQLException {
if (conn == null) {
throw new SQLException("Null connection");
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
}

if (sql == null) {
throw new SQLException("Null SQL statement");
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
}

if (rsh == null) {
throw new SQLException("Null ResultSetHandler");
throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR);
}

CallableStatement stmt = null;
Expand Down Expand Up @@ -381,15 +383,15 @@ public <T> T insert(final Connection conn, final String sql, final ResultSetHand
*/
public <T> T insert(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object... params) throws SQLException {
if (conn == null) {
throw new SQLException("Null connection");
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
}

if (sql == null) {
throw new SQLException("Null SQL statement");
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
}

if (rsh == null) {
throw new SQLException("Null ResultSetHandler");
throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR);
}

Statement stmt = null;
Expand Down Expand Up @@ -469,15 +471,15 @@ public <T> T insert(final String sql, final ResultSetHandler<T> rsh, final Objec
*/
public <T> T insertBatch(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object[][] params) throws SQLException {
if (conn == null) {
throw new SQLException("Null connection");
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
}

if (sql == null) {
throw new SQLException("Null SQL statement");
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
}

if (params == null) {
throw new SQLException("Null parameters. If parameters aren't need, pass an empty array.");
throw new SQLException(SQLExceptionCostants.NULL_PARAMS_ERROR);
}

PreparedStatement stmt = null;
Expand Down Expand Up @@ -583,15 +585,15 @@ public <T> T query(final Connection conn, final String sql, final ResultSetHandl
*/
public <T> T query(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object... params) throws SQLException {
if (conn == null) {
throw new SQLException("Null connection");
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
}

if (sql == null) {
throw new SQLException("Null SQL statement");
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
}

if (rsh == null) {
throw new SQLException("Null ResultSetHandler");
throw new SQLException(SQLExceptionCostants.NULL_RESULT_SET_ERROR);
}

Statement stmt = null;
Expand Down Expand Up @@ -759,11 +761,11 @@ public int update(final Connection conn, final String sql, final Object param) t
*/
public int update(final Connection conn, final String sql, final Object... params) throws SQLException {
if (conn == null) {
throw new SQLException("Null connection");
throw new SQLException(SQLExceptionCostants.NULL_CONNECTION_ERROR);
}

if (sql == null) {
throw new SQLException("Null SQL statement");
throw new SQLException(SQLExceptionCostants.NULL_STATEMENT_ERROR);
}

Statement stmt = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.apache.commons.dbutils.constants;

public class SQLExceptionCostants {
public static final String NULL_CONNECTION_ERROR = "Null connection error";
public static final String NULL_PARAMS_ERROR = "Null parameters error";
public static final String NULL_STATEMENT_ERROR = "Null SQL statement";
public static final String NULL_RESULT_SET_ERROR = "Null result set error";
}

0 comments on commit c490e81

Please sign in to comment.