net.sf.btb
Class ConnectionManager

java.lang.Object
  extended by net.sf.btb.ConnectionManager

public class ConnectionManager
extends java.lang.Object

Manages database URLs for the bridges' properties file. It's possible to define more than one database URL in the file or to load connection attributes from another file.

You can change the path of the bridge.properties file by setting the system property attribute "bridge.properties.path" to the desired file path.

Author:
Jean-Philippe Gravel

Constructor Summary
ConnectionManager()
           
 
Method Summary
 java.sql.Connection createConnection()
          Creates a connection using the default connection string.
 java.sql.Connection createConnection(java.lang.String name)
          Creates a connection using the specified connection name.
 java.lang.String getDefault()
          Gets the default database.url name.
 java.lang.String getUrl()
          Gets the default database URL (the database.url.
 java.lang.String getUrl(java.lang.String name)
          Get the specified connection string.
 void loadAttributes()
          Loads the default attribute file as defined by the system property "bridge.properties.path".
 void loadAttributes(java.lang.String filePath)
          Load the specified attribute file.
 void saveAttributes()
          Saves the default attribute file as defined by ConnectionManager.FILE_PATH.
 void saveAttributes(java.lang.String filePath)
          Saves the changes to the attribute file specified.
 void setDefault(java.lang.String name)
          Sets the default database url name.
 void setUrl(java.lang.String url)
          Sets the default database URL.
 void setUrl(java.lang.String name, java.lang.String url)
          Sets the url value to the database.url.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager()
Method Detail

loadAttributes

public void loadAttributes()
                    throws java.io.IOException
Loads the default attribute file as defined by the system property "bridge.properties.path". If not defined, uses the default value "bridge.xml";

Throws:
java.io.IOException - if the file does not exist.

loadAttributes

public void loadAttributes(java.lang.String filePath)
                    throws java.io.IOException
Load the specified attribute file. Can read both XML and former attribute files. Note that a XML file must have the extension ".xml" to be recognized.

Parameters:
filePath - Path to the file to load.
Throws:
java.io.IOException - if the file does not exist.

saveAttributes

public void saveAttributes()
                    throws java.io.IOException
Saves the default attribute file as defined by ConnectionManager.FILE_PATH.

Throws:
java.io.IOException - if there is a problem during the save operation.

saveAttributes

public void saveAttributes(java.lang.String filePath)
                    throws java.io.IOException
Saves the changes to the attribute file specified. Note that a XML file must have the extension ".xml" to be recognized.

Parameters:
filePath - The path to the file to be saved.
Throws:
java.io.IOException - if there is a problem during the save operation.

createConnection

public java.sql.Connection createConnection()
                                     throws java.sql.SQLException
Creates a connection using the default connection string.

Returns:
a new connection.
Throws:
java.sql.SQLException - if there is a problem connecting to the database or if the connection string is invalid.

createConnection

public java.sql.Connection createConnection(java.lang.String name)
                                     throws java.sql.SQLException
Creates a connection using the specified connection name.

Parameters:
name - The name of the connection to create.
Returns:
a new connection.
Throws:
java.sql.SQLException - if there is a problem connecting to the database or if the connection string is invalid.

getUrl

public java.lang.String getUrl(java.lang.String name)
Get the specified connection string.

Parameters:
name - The name of the connection string to get.
Returns:
a String containing the connection information, including the protocol.

setUrl

public void setUrl(java.lang.String name,
                   java.lang.String url)
Sets the url value to the database.url.{name} attribute.

Parameters:
name - The name of the connection.url to set.
url - the url value.

getUrl

public java.lang.String getUrl()
Gets the default database URL (the database.url.{name} value).

Returns:
a String containing the database URL.

setUrl

public void setUrl(java.lang.String url)
Sets the default database URL.

Parameters:
url - The url to set to the default database.url attribute.

getDefault

public java.lang.String getDefault()
Gets the default database.url name.

Returns:
the database.url name.

setDefault

public void setDefault(java.lang.String name)
Sets the default database url name.

Parameters:
name - The name of the default database.url to use.


Copyright © 2009. All Rights Reserved.