com.atlassian.jira.web.action.util
Class DatabaseConnectionBean

java.lang.Object
  extended by com.atlassian.jira.web.action.util.DatabaseConnectionBean
Direct Known Subclasses:
BugzillaConnectionBean, FogBugzConnectionBean, MantisConnectionBean

@NotThreadSafe
public class DatabaseConnectionBean
extends java.lang.Object

Bean for managing a JDBC connection - storing connection details, a Connection instance, and checking if a connection can be made. Most of this code is generic, and could be factored out if something other than Bugzilla needs it.

PLEASE NOTE: This is not Thread-Safe, and should only be used from the Web Actions!!!!!!!


Field Summary
protected  java.lang.String driverName
           
 
Constructor Summary
DatabaseConnectionBean(java.lang.String driverName, java.lang.String url, java.lang.String username, java.lang.String password, java.lang.String testSQL, java.lang.String testErrorMessage)
           
 
Method Summary
 void closeConnection()
           
 java.lang.String getCompleteURL()
           
 java.sql.Connection getConnection()
           
 java.lang.String getDriverName()
           
protected  I18nHelper getI18nBean()
           
 java.lang.String getPassword()
           
 java.lang.String getTestSQL()
           
 java.lang.String getUrl()
           
 java.lang.String getUsername()
           
 java.lang.String isValid()
          Checks that we can make a connection to the specified database and run a test query.
 boolean isValidDriverName()
           
 boolean isValidUrl()
           
<T> java.util.List<T>
queryDb(ResultSetTransformer<T> transformer)
          Queries the database with the SqlQuery and then adds and transforms each row of the result into an object which are then returned in a list
<T> java.util.List<T>
queryDbAppendCollection(ResultSetTransformer<T> transformer)
           
 void setDriverName(java.lang.String driverName)
           
 void setPassword(java.lang.String password)
           
 void setTestSQL(java.lang.String testSQL)
           
 void setUrl(java.lang.String url)
           
 void setUsername(java.lang.String username)
           
 void validateConnection(ErrorCollection errors)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

driverName

protected java.lang.String driverName
Constructor Detail

DatabaseConnectionBean

public DatabaseConnectionBean(java.lang.String driverName,
                              java.lang.String url,
                              java.lang.String username,
                              java.lang.String password,
                              java.lang.String testSQL,
                              java.lang.String testErrorMessage)
Method Detail

isValidDriverName

public boolean isValidDriverName()

isValidUrl

public boolean isValidUrl()

getCompleteURL

public java.lang.String getCompleteURL()
Returns:
the JDBC URL with username and password integrated

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns:
a Connection instance - always the same one unless JDBC details are changed.
Throws:
java.sql.SQLException - when things go HORRIBLY wrong

isValid

public java.lang.String isValid()
Checks that we can make a connection to the specified database and run a test query.

Returns:
An error message, or null if everything is OK

closeConnection

public void closeConnection()

getDriverName

public java.lang.String getDriverName()

setDriverName

public void setDriverName(java.lang.String driverName)

getUrl

public java.lang.String getUrl()

setUrl

public void setUrl(java.lang.String url)

getTestSQL

public java.lang.String getTestSQL()

setTestSQL

public void setTestSQL(java.lang.String testSQL)

getUsername

public java.lang.String getUsername()

setUsername

public void setUsername(java.lang.String username)

getPassword

public java.lang.String getPassword()

setPassword

public void setPassword(java.lang.String password)

queryDb

public <T> java.util.List<T> queryDb(ResultSetTransformer<T> transformer)
Queries the database with the SqlQuery and then adds and transforms each row of the result into an object which are then returned in a list

Parameters:
transformer - object transformer from resultset to domain object
Returns:
List of transformed objects

queryDbAppendCollection

public <T> java.util.List<T> queryDbAppendCollection(ResultSetTransformer<T> transformer)

validateConnection

public void validateConnection(ErrorCollection errors)

getI18nBean

protected I18nHelper getI18nBean()


Copyright © 2002-2010 Atlassian. All Rights Reserved.