com.mirth.connect.server.userutil
Class DatabaseConnection

java.lang.Object
  extended by com.mirth.connect.server.userutil.DatabaseConnection

public class DatabaseConnection
extends java.lang.Object

Provides the ability to run SQL queries again the database connection object instantiated using DatabaseConnectionFactory.


Constructor Summary
DatabaseConnection(java.lang.String address)
          Instantiates a new database connection with the given server address.
DatabaseConnection(java.lang.String address, java.util.Properties info)
          Instantiates a new database connection with the given server address and connection arguments.
 
Method Summary
 void close()
          Closes the database connection.
 void commit()
          Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this DatabaseConnection object.
 javax.sql.rowset.CachedRowSet executeCachedQuery(java.lang.String expression)
          Executes a query on the database and returns a CachedRowSet.
 javax.sql.rowset.CachedRowSet executeCachedQuery(java.lang.String expression, java.util.List<java.lang.Object> parameters)
          Executes a prepared query on the database and returns a CachedRowSet.
 int executeUpdate(java.lang.String expression)
          Executes an INSERT/UPDATE on the database and returns the row count.
 int executeUpdate(java.lang.String expression, java.util.List<java.lang.Object> parameters)
          Executes a prepared INSERT/UPDATE statement on the database and returns the row count.
 javax.sql.rowset.CachedRowSet executeUpdateAndGetGeneratedKeys(java.lang.String expression)
          Executes an INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.
 javax.sql.rowset.CachedRowSet executeUpdateAndGetGeneratedKeys(java.lang.String expression, java.util.List<java.lang.Object> parameters)
          Executes a prepared INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.
 java.lang.String getAddress()
          Returns the server address.
 java.sql.Connection getConnection()
          Returns the database connection (java.sql.Connection) this class is using.
 void rollback()
          Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object.
 void setAutoCommit(boolean autoCommit)
          Sets this connection's auto-commit mode to the given state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseConnection

public DatabaseConnection(java.lang.String address)
                   throws java.sql.SQLException
Instantiates a new database connection with the given server address.

Parameters:
address - The server address to connect to.
Throws:
java.sql.SQLException

DatabaseConnection

public DatabaseConnection(java.lang.String address,
                          java.util.Properties info)
                   throws java.sql.SQLException
Instantiates a new database connection with the given server address and connection arguments.

Parameters:
address - The server address to connect to.
info - A Properties object containing all applicable connection arguments.
Throws:
java.sql.SQLException
Method Detail

getAddress

public java.lang.String getAddress()
Returns the server address.


executeCachedQuery

public javax.sql.rowset.CachedRowSet executeCachedQuery(java.lang.String expression)
                                                 throws java.sql.SQLException
Executes a query on the database and returns a CachedRowSet.

Parameters:
expression - The query expression to be executed.
Returns:
The result of the query, as a CachedRowSet.
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String expression)
                  throws java.sql.SQLException
Executes an INSERT/UPDATE on the database and returns the row count.

Parameters:
expression - The statement to be executed.
Returns:
A count of the number of updated rows.
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String expression,
                         java.util.List<java.lang.Object> parameters)
                  throws java.sql.SQLException
Executes a prepared INSERT/UPDATE statement on the database and returns the row count.

Parameters:
expression - The prepared statement to be executed.
parameters - The parameters for the prepared statement.
Returns:
A count of the number of updated rows.
Throws:
java.sql.SQLException

executeCachedQuery

public javax.sql.rowset.CachedRowSet executeCachedQuery(java.lang.String expression,
                                                        java.util.List<java.lang.Object> parameters)
                                                 throws java.sql.SQLException
Executes a prepared query on the database and returns a CachedRowSet.

Parameters:
expression - The prepared statement to be executed.
parameters - The parameters for the prepared statement.
Returns:
The result of the query, as a CachedRowSet.
Throws:
java.sql.SQLException

close

public void close()
Closes the database connection.


setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Sets this connection's auto-commit mode to the given state.

Parameters:
autoCommit - The value (true or false) to set the connection's auto-commit mode to.
Throws:
java.sql.SQLException

rollback

public void rollback()
              throws java.sql.SQLException
Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object.

Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this DatabaseConnection object.

Throws:
java.sql.SQLException

executeUpdateAndGetGeneratedKeys

public javax.sql.rowset.CachedRowSet executeUpdateAndGetGeneratedKeys(java.lang.String expression)
                                                               throws java.sql.SQLException
Executes an INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.

Parameters:
expression - The statement to be executed.
Returns:
A CachedRowSet containing any generated keys.
Throws:
java.sql.SQLException

executeUpdateAndGetGeneratedKeys

public javax.sql.rowset.CachedRowSet executeUpdateAndGetGeneratedKeys(java.lang.String expression,
                                                                      java.util.List<java.lang.Object> parameters)
                                                               throws java.sql.SQLException
Executes a prepared INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.

Parameters:
expression - The prepared statement to be executed.
parameters - The parameters for the prepared statement.
Returns:
A CachedRowSet containing any generated keys.
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
Returns the database connection (java.sql.Connection) this class is using.