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

public class DatabaseConnectionBean
extends 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 fully Thread-Safe, and should only be used from the Web Actions!!!!!!!


Field Summary
protected  String driverName
           
 
Constructor Summary
DatabaseConnectionBean(String driverName, String url, String username, String password, String testSQL, String testErrorMessage)
           
 
Method Summary
 void closeConnection()
           
 String getCompleteURL()
           
 Connection getConnection()
           
 String getDriverName()
           
protected  I18nBean getI18nBean()
           
 String getPassword()
           
 String getTestSQL()
           
 String getUrl()
           
 String getUsername()
           
 String isValid()
          Checks that we can make a connection to the specified database and run a test query.
 boolean isValidDriverName()
           
 boolean isValidUrl()
           
 List queryDb(ResultSetTransformer 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
 List queryDbAppendCollection(ResultSetTransformer transformer)
           
 void setDriverName(String driverName)
           
 void setPassword(String password)
           
 void setTestSQL(String testSQL)
           
 void setUrl(String url)
           
 void setUsername(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 String driverName
Constructor Detail

DatabaseConnectionBean

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

isValidDriverName

public boolean isValidDriverName()

isValidUrl

public boolean isValidUrl()

getCompleteURL

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

getConnection

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

isValid

public 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 String getDriverName()

setDriverName

public void setDriverName(String driverName)

getUrl

public String getUrl()

setUrl

public void setUrl(String url)

getTestSQL

public String getTestSQL()

setTestSQL

public void setTestSQL(String testSQL)

getUsername

public String getUsername()

setUsername

public void setUsername(String username)

getPassword

public String getPassword()

setPassword

public void setPassword(String password)

queryDb

public List queryDb(ResultSetTransformer 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 List queryDbAppendCollection(ResultSetTransformer transformer)

validateConnection

public void validateConnection(ErrorCollection errors)

getI18nBean

protected I18nBean getI18nBean()


Copyright © 2002-2008 Atlassian. All Rights Reserved.