Package gnue :: Package common :: Package datasources :: Module GConnections :: Class GConnections
[show private | hide private]

Class GConnections


Class that loads connection definition files and maintains database connections.

If you pass GConnections an "eventHandler" instance, it will generate a Connections:Connect(name, base) when a new connection is created.
Method Summary
  __init__(self, location, loginHandler, loginOptions, eventhandler)
Create a new GConnections instance.
  addConnectionSpecification(self, name, parameters)
Add a session specific connection entry.
  closeAll(self)
This function closes all open connections.
  getAllConnectionParameters(self, includeAliases)
Return a dictionary of all connections from the connections.conf file.
  getAuthenticatedUser(self, connection)
Return the user name that has been used to log into the give connection.
  getConnection(self, connection_name, login)
Return an instance of the requested connection and optionally log into it.
  getConnectionNames(self, includeAliases)
Return a list of all connections from the connections.conf file.
  getConnectionParameter(self, connection_name, attribute, default)
Read a parameter from the connections.conf file.
  getConnectionParameters(self, connection_name)
Return the parameter dictionary for a given connection.
  hasConnectionParameters(self, connection_name)
Check if the given connection name exists in the connections.conf file.
  isConnectionActive(self, connection)
Return True if there is an open connection for the given connection name.
  loginToConnection(self, connection)
Log into a connection.
  setLoginHandler(self, loginHandler)
Set the login handler to use to ask the user for login data.

Method Details

__init__(self, location, loginHandler=None, loginOptions={}, eventhandler=None)
(Constructor)

Create a new GConnections instance.
Parameters:
location - Filename of the connections.conf file.
loginHandler - Instance of a GLoginHandler.LoginHandler descendant to ask the user for login data.
loginOptions - Default data for the login handler.
eventhandler - Event handler to notify about new connections.

addConnectionSpecification(self, name, parameters)

Add a session specific connection entry.

With this function, a temporary connection definition can be inserted without having to change the connections.conf file.
Parameters:
name - Connection name.
parameters - Connection parameters as a dictionary.

closeAll(self)

This function closes all open connections.

getAllConnectionParameters(self, includeAliases=1)

Return a dictionary of all connections from the connections.conf file.
Parameters:
includeAliases - Whether or not to include connection aliases.
Returns:
Dictionary where the keys are connection names and the values are dictionaries with all connection parameters.

getAuthenticatedUser(self, connection=None)

Return the user name that has been used to log into the give connection.

getConnection(self, connection_name, login=False)

Return an instance of the requested connection and optionally log into it.

If there's an already opened connection for the requested connectionname this instance will be returned.
Parameters:
connection_name - name of the connection to be returned
login - if TRUE, this function automatically tries to open the connection.
Returns:
connection instance
Raises:
GConnection.NotFoundError - if connection_name does not exist

getConnectionNames(self, includeAliases=True)

Return a list of all connections from the connections.conf file.
Parameters:
includeAliases - Whether or not to include connection aliases.
Returns:
List with all connection names.

getConnectionParameter(self, connection_name, attribute, default=None)

Read a parameter from the connections.conf file.

getConnectionParameters(self, connection_name)

Return the parameter dictionary for a given connection.
Returns:
Dictionary with parameter name and parameter value.

hasConnectionParameters(self, connection_name)

Check if the given connection name exists in the connections.conf file.

isConnectionActive(self, connection)

Return True if there is an open connection for the given connection name.
Parameters:
connection - Connection name.
Returns:
True if this connection is open, False otherwise.

loginToConnection(self, connection)

Log into a connection.

This is called automatically at the end of getConnection if the login parameter is set to True.
Parameters:
connection - Connection name.

setLoginHandler(self, loginHandler)

Set the login handler to use to ask the user for login data.


GNUe Home

Public API

Developer's Corner