SPT RWT Application API

com.sptci.rwt
Class Connections

java.lang.Object
  extended by com.sptci.rwt.Connections
All Implemented Interfaces:
Serializable

public class Connections
extends Object
implements Serializable

A serializable wrapper used to represent saved JDBC connections for the application. This class will be serialised to the following file and initialised from the same file during application load:

<sptrwt.data.directory>/connections.xml

© Copyright 2007 Sans Pareil Technologies, Inc.

Version:
$Id: Connections.java 4123 2008-05-25 21:49:01Z rakesh $
Author:
Rakesh Vidyadharan 2007-09-24
See Also:
Serialized Form

Field Summary
private  TreeMap<String,DatabaseType> databases
          A map used to quickly look up DatabaseType instances by their DatabaseType.name.
static String DIRECTORY
          The system property used to configure the location of the root directory under which persistent state information for the application is stored.
static String ENCODING
          The encoding to use to serialise and deserialise instances of this class.
static String FILE_NAME
          The name of the file to which this class will be serialised.
private  String fileName
          The fully qualified file name to use to serialise this instance into.
protected static XStream xstream
          The XStream instance used to serialise and deserialise instances of this class.
 
Constructor Summary
protected Connections()
          Default constructor.
 
Method Summary
 void add(String name, ConnectionParameters parameters)
          Add the specified connection parameters value object to the application persistent state.
 void delete(String name)
          Remove the specified database from persistent state.
 void delete(String databaseType, String name)
          Remove the specified connection parameters from the application persistent state.
protected  void deserialise(String user)
          Deserialise the contents of FILE_NAME into this instance.
 Connection getConnection(String databaseType, String name)
          Return a Connection for the specified database type and saved with the specified unique name.
 ConnectionParameters getConnectionParameters(String databaseType, String name)
          Return a value object that represents all the connection information for the specified database type and saved with the specified unique name.
 DatabaseType getDatabaseType(String name)
          Returns the DatabaseType identified by the DatabaseType.name parameter specified.
 Collection<String> getDatabaseTypeNames()
          Returns the collection of DatabaseType.name values stored as key in databases.
 Collection<DatabaseType> getDatabaseTypes()
          Returns databases.
static Connections getInstance(String user)
          Create a new instance of the class for the specified user.
protected  void serialise()
          Serialise this instance to the FILE_NAME.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING

public static final String ENCODING
The encoding to use to serialise and deserialise instances of this class. "UTF-8"

See Also:
Constant Field Values

FILE_NAME

public static final String FILE_NAME
The name of the file to which this class will be serialised.

See Also:
Constant Field Values

DIRECTORY

public static final String DIRECTORY
The system property used to configure the location of the root directory under which persistent state information for the application is stored. "sptrwt.data.directory"

See Also:
Constant Field Values

xstream

protected static final XStream xstream
The XStream instance used to serialise and deserialise instances of this class.


databases

private final TreeMap<String,DatabaseType> databases
A map used to quickly look up DatabaseType instances by their DatabaseType.name.


fileName

private transient String fileName
The fully qualified file name to use to serialise this instance into.

Constructor Detail

Connections

protected Connections()
Default constructor. Cannot be instantiated.

Method Detail

getInstance

public static Connections getInstance(String user)
Create a new instance of the class for the specified user. Saved files are stored under a directory named after the user under DIRECTORY.

Returns:
The newly initialised instance of the class.
Throws:
RuntimeException - If errors are encountered while deserialising the persistent state of this instance.
See Also:
deserialise(java.lang.String)

getConnection

public Connection getConnection(String databaseType,
                                String name)
                         throws ConnectionException
Return a Connection for the specified database type and saved with the specified unique name.

Parameters:
databaseType - The name of the database engine.
name - The unique name used to identify the saved connection.
Returns:
The connection object or null if no saved information can be found for the specified parameters.
Throws:
ConnectionException - If errors are encountered while initiating the connection.
See Also:
getConnectionParameters(java.lang.String, java.lang.String), ConnectionFactory.open( ConnectionParameters )

getConnectionParameters

public ConnectionParameters getConnectionParameters(String databaseType,
                                                    String name)
Return a value object that represents all the connection information for the specified database type and saved with the specified unique name.

Parameters:
databaseType - The name of the database engine.
name - The unique name used to identify the saved connection.
Returns:
The appropriate value object or null if no matching saved connection is found.

add

public void add(String name,
                ConnectionParameters parameters)
Add the specified connection parameters value object to the application persistent state.

Parameters:
name - The unique name to use to identify the saved connection.
parameters - The parameters to be saved to FILE_NAME.
See Also:
serialise()

delete

public void delete(String databaseType,
                   String name)
Remove the specified connection parameters from the application persistent state.

Parameters:
databaseType - The database type under which the connection was saved.
name - The unique name to use to identify the saved connection.
See Also:
serialise()

delete

public void delete(String name)
Remove the specified database from persistent state. This removes all saved connections for that database engine.

Parameters:
name - The name of the database engine to remove from saved state.
See Also:
serialise()

deserialise

protected void deserialise(String user)
                    throws RuntimeException
Deserialise the contents of FILE_NAME into this instance.

Parameters:
user - The name of the user to use to construct the full filename.
Throws:
RuntimeException - If errors are encountered while deserialising the persistent state. No exceptions are thrown if the file does not exist.

serialise

protected void serialise()
                  throws RuntimeException
Serialise this instance to the FILE_NAME.

Throws:
RuntimeException - If errors are encountered while serialising the instance.

getDatabaseType

public DatabaseType getDatabaseType(String name)
Returns the DatabaseType identified by the DatabaseType.name parameter specified.

Parameters:
name - The name to use to fetch the database type.
Returns:
The database type associated with the name or null if no such database type exists.

getDatabaseTypes

public Collection<DatabaseType> getDatabaseTypes()
Returns databases.

Returns:
A read only view of the collection.

getDatabaseTypeNames

public Collection<String> getDatabaseTypeNames()
Returns the collection of DatabaseType.name values stored as key in databases.

Returns:
The collection of names.

SPT RWT Application API