Skip to content

Commit 8e3483e

Browse files
committed
Add JavaDoc
1 parent 3e61ca8 commit 8e3483e

File tree

1 file changed

+52
-16
lines changed

1 file changed

+52
-16
lines changed

src/main/java/com/nordstrom/common/jdbc/DatabaseUtils.java

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.sql.SQLException;
99
import java.util.Arrays;
1010
import java.util.Iterator;
11+
import java.util.Objects;
1112
import java.util.ServiceLoader;
1213
import java.util.regex.Matcher;
1314
import java.util.regex.Pattern;
@@ -50,7 +51,7 @@
5051
* sub-configurations or other dynamic data sources (e.g. - web service).</li>
5152
* </ul>
5253
* <b>Query Collection Example</b>
53-
* <br><br>
54+
* <p>
5455
* <pre>
5556
* public class OpctConfig extends {@code SettingsCore<OpctConfig.OpctValues>} {
5657
*
@@ -237,7 +238,7 @@ public static ResultPackage getResultPackage(QueryAPI query, Object... queryArgs
237238

238239
/**
239240
* Execute the specified query with the supplied arguments, returning a result of the indicated type.
240-
* <br><br>
241+
* <p>
241242
* <b>TYPES</b>: Specific result types produce the following behaviors: <ul>
242243
* <li>'null' - The query is executed as an update operation.</li>
243244
* <li>{@link ResultPackage} - An object containing the connection, statement, and result set is returned</li>
@@ -274,7 +275,7 @@ private static Object executeQuery(Class<?> resultType, QueryAPI query, Object..
274275

275276
/**
276277
* Execute the specified query with the supplied arguments, returning a result of the indicated type.
277-
* <br><br>
278+
* <p>
278279
* <b>TYPES</b>: Specific result types produce the following behaviors: <ul>
279280
* <li>'null' - The query is executed as an update operation.</li>
280281
* <li>{@link ResultPackage} - An object containing the connection, statement, and result set is returned</li>
@@ -306,13 +307,24 @@ public static Object executeQuery(Class<?> resultType, String connectionStr, Str
306307
}
307308

308309
/**
310+
* Execute the specified stored procedure with the specified arguments, returning a result of the indicated type.
311+
* <p>
312+
* <b>TYPES</b>: Specific result types produce the following behaviors: <ul>
313+
* <li>{@link ResultPackage} - An object containing the connection, statement, and result set is returned</li>
314+
* <li>{@link Integer} - If rows were returned, row 1 / column 1 is returned as an Integer; otherwise -1</li>
315+
* <li>{@link String} - If rows were returned, row 1 / column 1 is returned as an String; otherwise 'null'</li>
316+
* <li>For other types, {@link ResultSet#getObject(int, Class)} to return row 1 / column 1 as that type</li></ul>
309317
*
310-
* @param resultType
311-
* @param sproc
312-
* @param parms
313-
* @return
318+
* @param resultType desired result type (see TYPES above)
319+
* @param sproc stored procedure object to execute
320+
* @param params an array of objects containing the input parameter values
321+
* @return an object of the indicated type<br>
322+
* <b>NOTE</b>: If you specify {@link ResultPackage} as the result type, it's recommended that you close this object
323+
* when you're done with it to free up database and JDBC resources that were allocated for it.
314324
*/
315325
public static Object executeStoredProcedure(Class<?> resultType, SProcAPI sproc, Object... parms) {
326+
Objects.requireNonNull(resultType, "[resultType] argument must be non-null");
327+
316328
int typesCount = sproc.getArgCount();
317329
int parmsCount = parms.length;
318330

@@ -377,14 +389,25 @@ public static Object executeStoredProcedure(Class<?> resultType, SProcAPI sproc,
377389
}
378390

379391
/**
392+
* Execute the specified stored procedure with the supplied arguments, returning a result of the indicated type.
393+
* <p>
394+
* <b>TYPES</b>: Specific result types produce the following behaviors: <ul>
395+
* <li>{@link ResultPackage} - An object containing the connection, statement, and result set is returned</li>
396+
* <li>{@link Integer} - If rows were returned, row 1 / column 1 is returned as an Integer; otherwise -1</li>
397+
* <li>{@link String} - If rows were returned, row 1 / column 1 is returned as an String; otherwise 'null'</li>
398+
* <li>For other types, {@link ResultSet#getObject(int, Class)} to return row 1 / column 1 as that type</li></ul>
380399
*
381-
* @param resultType
382-
* @param connectionStr
383-
* @param sprocName
384-
* @param params
385-
* @return
400+
* @param resultType desired result type (see TYPES above)
401+
* @param connectionStr database connection string
402+
* @param sprocName name of the stored procedure to be executed
403+
* @param params an array of objects containing the input parameter values
404+
* @return an object of the indicated type<br>
405+
* <b>NOTE</b>: If you specify {@link ResultPackage} as the result type, it's recommended that you close this object
406+
* when you're done with it to free up database and JDBC resources that were allocated for it.
386407
*/
387408
public static Object executeStoredProcedure(Class<?> resultType, String connectionStr, String sprocName, Param... params) {
409+
Objects.requireNonNull(resultType, "[resultType] argument must be non-null");
410+
388411
StringBuilder sprocStr = new StringBuilder("{call ").append(sprocName).append("(");
389412

390413
String placeholder = "?";
@@ -410,11 +433,24 @@ public static Object executeStoredProcedure(Class<?> resultType, String connecti
410433
}
411434

412435
/**
436+
* Execute the specified prepared statement, returning a result of the indicated type.
437+
* <p>
438+
* <b>TYPES</b>: Specific result types produce the following behaviors: <ul>
439+
* <li>'null' - The prepared statement is a query to be executed as an update operation.</li>
440+
* <li>{@link ResultPackage} - An object containing the connection, statement, and result set is returned</li>
441+
* <li>{@link Integer} - If rows were returned, row 1 / column 1 is returned as an Integer; otherwise -1</li>
442+
* <li>{@link String} - If rows were returned, row 1 / column 1 is returned as an String; otherwise 'null'</li>
443+
* <li>For other types, {@link ResultSet#getObject(int, Class)} to return row 1 / column 1 as that type</li></ul>
444+
* <p>
445+
* <b>NOTE</b>: For all result types except {@link ResultPackage}, the specified connection and statement, as well
446+
* as the result set from executing the statement, are closed prior to returning the result.
413447
*
414-
* @param resultType
415-
* @param connection
416-
* @param statement
417-
* @return
448+
* @param resultType desired result type (see TYPES above)
449+
* @param connectionStr database connection string
450+
* @param statement prepared statement to be executed (query or store procedure)
451+
* @return for update operations, the number of rows affected; for query operations, an object of the indicated type<br>
452+
* <b>NOTE</b>: If you specify {@link ResultPackage} as the result type, it's recommended that you close this object
453+
* when you're done with it to free up database and JDBC resources that were allocated for it.
418454
*/
419455
private static Object executeStatement(Class<?> resultType, Connection connection, PreparedStatement statement) {
420456
Object result = null;

0 commit comments

Comments
 (0)