| java.lang.Object com.methodhead.persistable.ConnectionSingleton
Method Summary | |
public static void | close(ResultSet rs) A convenience method to close the connection associated with the specified
result set. | public static Connection | getConnection(String name) Returns a connection from the connection pool named name An
exception is thrown if that pool hasn't been intitalized yet or if it is
not supplying connections (a likely cause of this is bad connection
parameters). | public static Connection | getConnection() Returns a connection from the default connection pool. | public static String | getDatabaseType(String name) Returns one of the DBTYPE_ constants indicating the type of
database the name pool is connected to. | public static String | getDatabaseType() Returns one of the DBTYPE_ constants indicating the type of
database the default pool is connected to. | public static boolean | init(String name, Properties dbProps) Initializes the connection pool associated with the name name
using the specified properties dbProps, returning true
if the singleton was successfully initialized, or false
otherwise. | public static boolean | init(Properties dbProps) Initalizes the singleton's default connection pool. | public static void | release(String name) Releases the pool with the specified name throwing an exception
if no such pool exists. | public static void | release() Releases the default pool. | public static void | runBatchUpdate(String name, Reader reader)
Executes a series of SQL statements read from the specified reader using the connection with the specified name. | public static void | runBatchUpdate(Reader reader) Executes a series SQL statement using a connection from the default pool. | public static ResultSet | runQuery(String name, String sql) Executes a SQL query using a connection from the pool named
name, returning a result set or null if an error
occured. | public static ResultSet | runQuery(String sql) Executes a SQL query using a connection from the default pool. | public static int | runUpdate(String name, String sql) Executes a SQL update using a connection from the pool named name. | public static int | runUpdate(String sql) Executes a SQL update using a connection from the default pool. |
DBTYPE_SQLSERVER | final public static String DBTYPE_SQLSERVER(Code) | | |
connections_ | protected static Map connections_(Code) | | |
close | public static void close(ResultSet rs)(Code) | | A convenience method to close the connection associated with the specified
result set. Any SQLException thrown while trying to close the
connection is logged and ignored. Nothing is done if rs is
null.
|
getConnection | public static Connection getConnection(String name) throws SQLException(Code) | | Returns a connection from the connection pool named name An
exception is thrown if that pool hasn't been intitalized yet or if it is
not supplying connections (a likely cause of this is bad connection
parameters). If name is null the default connection
pool is assumed. Important: be sure to close the
returned connection, as this is how the connection is returned to the
pool.
|
getDatabaseType | public static String getDatabaseType(String name)(Code) | | Returns one of the DBTYPE_ constants indicating the type of
database the name pool is connected to. The connection's meta
data is examined to determine the database type; if a type cannot be
determined, null is returned.
|
getDatabaseType | public static String getDatabaseType()(Code) | | Returns one of the DBTYPE_ constants indicating the type of
database the default pool is connected to. The connection's meta
data is examined to determine the database type; if a type cannot be
determined, null is returned.
|
init | public static boolean init(String name, Properties dbProps)(Code) | | Initializes the connection pool associated with the name name
using the specified properties dbProps, returning true
if the singleton was successfully initialized, or false
otherwise. If a pool already exists for the specified name,
false is returned (use
com.methodhead.persistable.ConnectionSingleton.release(java.lang.String)release() to release the pool). The following properties are expected
to be defined: driver (e.g, org.postgresql.Driver),
uri (e.g., jdbc:postgresql:yourdatabase),
user, and password. Leading and trailing whitespace is
trimmed from property values.
|
release | public static void release(String name) throws SQLException(Code) | | Releases the pool with the specified name throwing an exception
if no such pool exists.
|
runBatchUpdate | public static void runBatchUpdate(String name, Reader reader) throws IOException, SQLException(Code) | |
Executes a series of SQL statements read from the specified reader using the connection with the specified name.
The statements are expected in the following format:
-
Statements must be separated by a semicolon.
-
Statements may span several lines, but no statement should
begin on the same line another ends.
-
A double dash (--) indicates a comment; any text
after the dashes to the end of the line is ignored.
-
SQL keywords should not be mixed case, (e.g., INSERT or
insert, but not Insert).
-
SQL statements should not return results (i.e., no
SELECT statements, though SELECT INTO is ok).
Note: reader is not closed by this method.
|
runQuery | public static ResultSet runQuery(String name, String sql) throws SQLException(Code) | | Executes a SQL query using a connection from the pool named
name, returning a result set or null if an error
occured. If name is null, the default pool is
assumed. Important: be sure to close the connection
associated with the returned result set as this is how the connection is
returned to the pool (try something like
rs.getStatement().getConnection().close() or use
ConnectionSingleton.close()).
|
runUpdate | public static int runUpdate(String name, String sql) throws SQLException(Code) | | Executes a SQL update using a connection from the pool named name.
If name is null the default pool is assumed.
|
runUpdate | public static int runUpdate(String sql) throws SQLException(Code) | | Executes a SQL update using a connection from the default pool. @see
com.methodhead.persistable.ConnectionSingleton#runUpdate(java.lang.String,java.lang.String)
runUpdate()
|
|
|