org.rhq.plugins.database
Class DatabaseQueryUtility

java.lang.Object
  extended by org.rhq.plugins.database.DatabaseQueryUtility

public class DatabaseQueryUtility
extends Object

Various database (JDBC) query functions.

Author:
Greg Hinkle

Method Summary
static void close(Statement statement, ResultSet resultSet)
          Closes statements and result sets.
static int executeUpdate(DatabaseComponent databaseComponent, String query, Object... parameters)
          Executes a database update.
static String[] getColumns(ResultSetMetaData rsmd)
          Returns an array of strings as upper-case column names.
static List<Map<String,Object>> getGridValues(DatabaseComponent databaseComponent, String query, Object... parameters)
          Returns a list of values, one per row, containing a map of column names to values of that row.
static Map<String,Double> getNumericQueryValueMap(DatabaseComponent databaseComponent, String query, Object... parameters)
          Returns a mapping of rows as key-value pairs where the key is the first column (a string) and the second column is a value numeric.
static Map<String,Double> getNumericQueryValues(DatabaseComponent databaseComponent, String query, Object... parameters)
          Executes a query, returning the results as a map where the keys are the column names and values are the value of that column.
static Double getSingleNumericQueryValue(DatabaseComponent databaseComponent, String query, Object... parameters)
          Returns the result of a query as a single Double value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

executeUpdate

public static int executeUpdate(DatabaseComponent databaseComponent,
                                String query,
                                Object... parameters)
                         throws SQLException
Executes a database update.

Parameters:
databaseComponent -
query -
parameters -
Returns:
Throws:
SQLException

getSingleNumericQueryValue

public static Double getSingleNumericQueryValue(DatabaseComponent databaseComponent,
                                                String query,
                                                Object... parameters)
Returns the result of a query as a single Double value. Returns Double.NaN if the query fails.


getNumericQueryValues

public static Map<String,Double> getNumericQueryValues(DatabaseComponent databaseComponent,
                                                       String query,
                                                       Object... parameters)
Executes a query, returning the results as a map where the keys are the column names and values are the value of that column. Note depending on the database, the column names may be uppercase (Oracle) or lowercase.

Parameters:
databaseComponent -
query - SQL query string
parameters - optional bind parameters
Returns:
a map of query results

getGridValues

public static List<Map<String,Object>> getGridValues(DatabaseComponent databaseComponent,
                                                     String query,
                                                     Object... parameters)
                                              throws SQLException
Returns a list of values, one per row, containing a map of column names to values of that row. Note depending on the database, the column names may be uppercase (Oracle) or lowercase.

Parameters:
databaseComponent - database to query
query - SQL query
parameters - parameters to bind to the query
Throws:
SQLException - if query fails

getNumericQueryValueMap

public static Map<String,Double> getNumericQueryValueMap(DatabaseComponent databaseComponent,
                                                         String query,
                                                         Object... parameters)
Returns a mapping of rows as key-value pairs where the key is the first column (a string) and the second column is a value numeric.

Parameters:
databaseComponent - the component to execute on
query - the sql query to run
parameters - any parameters to bind first
Returns:
a Map of the keys against the value

getColumns

public static String[] getColumns(ResultSetMetaData rsmd)
                           throws SQLException
Returns an array of strings as upper-case column names.

Throws:
SQLException

close

public static void close(Statement statement,
                         ResultSet resultSet)
Closes statements and result sets.



Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.