org.unitils.database
Class SQLUnitils

java.lang.Object
  extended by org.unitils.database.SQLUnitils

public class SQLUnitils
extends Object

Utilities for executing statements and queries.

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
SQLUnitils()
           
 
Method Summary
static int executeUpdate(String sql, DataSource dataSource)
          Executes the given update statement.
static int executeUpdateQuietly(String sql, DataSource dataSource)
          Executes the given statement ignoring all exceptions.
static long getItemAsLong(String sql, DataSource dataSource)
          Returns the long extracted from the result of the given query.
static String getItemAsString(String sql, DataSource dataSource)
          Returns the value extracted from the result of the given query.
static Set<String> getItemsAsStringSet(String sql, DataSource dataSource)
          Returns the items extracted from the result of the given query.
static boolean isEmpty(String tableName, DataSource dataSource)
          Utility method to check whether the given table is empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLUnitils

public SQLUnitils()
Method Detail

executeUpdate

public static int executeUpdate(String sql,
                                DataSource dataSource)
Executes the given update statement.

Parameters:
sql - The sql string for retrieving the items
dataSource - The data source, not null
Returns:
The nr of updates

executeUpdateQuietly

public static int executeUpdateQuietly(String sql,
                                       DataSource dataSource)
Executes the given statement ignoring all exceptions.

Parameters:
sql - The sql string for retrieving the items
dataSource - The data source, not null
Returns:
The nr of updates, -1 if not succesful

getItemAsLong

public static long getItemAsLong(String sql,
                                 DataSource dataSource)
Returns the long extracted from the result of the given query. If no value is found, a UnitilsException is thrown.

Parameters:
sql - The sql string for retrieving the items
dataSource - The data source, not null
Returns:
The long item value

getItemAsString

public static String getItemAsString(String sql,
                                     DataSource dataSource)
Returns the value extracted from the result of the given query. If no value is found, a UnitilsException is thrown.

Parameters:
sql - The sql string for retrieving the items
dataSource - The data source, not null
Returns:
The string item value

getItemsAsStringSet

public static Set<String> getItemsAsStringSet(String sql,
                                              DataSource dataSource)
Returns the items extracted from the result of the given query.

Parameters:
sql - The sql string for retrieving the items
dataSource - The data source, not null
Returns:
The items, not null

isEmpty

public static boolean isEmpty(String tableName,
                              DataSource dataSource)
Utility method to check whether the given table is empty.

Parameters:
tableName - The table, not null
dataSource - The data source, not null
Returns:
True if empty


Copyright © 2011. All Rights Reserved.