org.deegree.commons.jdbc
Class ConnectionManager

java.lang.Object
  extended by org.deegree.commons.config.AbstractBasicResourceManager
      extended by org.deegree.commons.jdbc.ConnectionManager
All Implemented Interfaces:
ResourceManager, ResourceProvider

public class ConnectionManager
extends AbstractBasicResourceManager
implements ResourceProvider

Entry point for accessing JDBC connections in deegree that are defined in JDBC configuration files.

Configuration of JDBC connections used in deegree is based on simple string identifiers: each configured JDBC connection has a unique identifier. This class allows the retrieval of connections based on their identifier.

Version:
$Revision: $, $Date: $
Author:
Markus Schneider, last edited by: $Author: schneider $

Nested Class Summary
static class ConnectionManager.Type
           
 
Field Summary
 
Fields inherited from class org.deegree.commons.config.AbstractBasicResourceManager
dir, idToState, workspace
 
Constructor Summary
ConnectionManager()
           
 
Method Summary
 ResourceState activate(String id)
          Activates the resource with the given identifier.
static void addConnection(JDBCConnection jaxbConn, String connId)
          Adds a connection pool from the given pool definition.
static void addConnection(String connId, String url, String user, String password, int poolMinSize, int poolMaxSize)
          Adds a connection pool as specified in the parameters.
static void addConnection(URL jdbcConfigUrl, String connId, DeegreeWorkspace workspace)
          Adds the connection pool defined in the given file.
 ResourceState deactivate(String id)
          Deactivates the resource with the given identifier.
 ResourceState deleteResource(String id)
          Removes the specified resource and deletes the corresponding configuration file.
static void destroy(String connid)
           
 Connection get(String id)
          Returns a connection from the connection pool with the given id.
 String getConfigNamespace()
          Returns the namespace for configuration documents that this provider handles.
 URL getConfigSchema()
          Returns the URL for retrieving the configuration document schema.
static Connection getConnection(String id)
          Returns a connection from the connection pool with the given id.
static Set<String> getConnectionIds()
           
 Class<? extends ResourceManager>[] getDependencies()
           
 ResourceManagerMetadata getMetadata()
           
protected  ResourceProvider getProvider(File file)
           
 ConnectionManager.Type getType(String id)
           
 void init(File jdbcDir, DeegreeWorkspace workspace)
          Initializes the ConnectionManager by loading all JDBC pool configurations from the given directory.
static void invalidate(String id, Connection conn)
          Invalidates a broken Connection to avoid its re-use.
protected  void remove(String id)
           
 void shutdown()
          Is called upon workspace shutdown.
 void startup(DeegreeWorkspace workspace)
          Is called upon workspace startup.
 
Methods inherited from class org.deegree.commons.config.AbstractBasicResourceManager
createResource, getState, getStates, init
 
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

init

public void init(File jdbcDir,
                 DeegreeWorkspace workspace)
Initializes the ConnectionManager by loading all JDBC pool configurations from the given directory.

Parameters:
jdbcDir -

destroy

public static void destroy(String connid)

getType

public ConnectionManager.Type getType(String id)
Parameters:
id -
Returns:
the type of the connection, null if the connection is unknown or the connection type could not be determined

get

public Connection get(String id)
Returns a connection from the connection pool with the given id.

Parameters:
id - id of the connection pool
Returns:
connection from the corresponding connection pool, null, if not available

getConnection

public static Connection getConnection(String id)
                                throws SQLException
Returns a connection from the connection pool with the given id.

Parameters:
id - id of the connection pool
Returns:
connection from the corresponding connection pool
Throws:
SQLException - if the connection pool is unknown or a SQLException occurs creating the connection

invalidate

public static void invalidate(String id,
                              Connection conn)
                       throws Exception
Invalidates a broken Connection to avoid its re-use.

Parameters:
id - connection pool id, must not be null
conn - connection, must not be null
Throws:
Exception

addConnection

public static void addConnection(URL jdbcConfigUrl,
                                 String connId,
                                 DeegreeWorkspace workspace)
                          throws JAXBException
Adds the connection pool defined in the given file.

Parameters:
jdbcConfigUrl -
connId -
workspace - can be null
Throws:
JAXBException

addConnection

public static void addConnection(JDBCConnection jaxbConn,
                                 String connId)
Adds a connection pool from the given pool definition.

Parameters:
jaxbConn -
connId -

addConnection

public static void addConnection(String connId,
                                 String url,
                                 String user,
                                 String password,
                                 int poolMinSize,
                                 int poolMaxSize)
Adds a connection pool as specified in the parameters.

Parameters:
connId -
url -
user -
password -
poolMinSize -
poolMaxSize -

getConnectionIds

public static Set<String> getConnectionIds()
Returns:
all currently available connection ids

shutdown

public void shutdown()
Description copied from interface: ResourceManager
Is called upon workspace shutdown.

Specified by:
shutdown in interface ResourceManager

startup

public void startup(DeegreeWorkspace workspace)
Description copied from interface: ResourceManager
Is called upon workspace startup.

Specified by:
startup in interface ResourceManager

getDependencies

public Class<? extends ResourceManager>[] getDependencies()
Specified by:
getDependencies in interface ResourceManager
Returns:
an empty array if there are no dependencies

getMetadata

public ResourceManagerMetadata getMetadata()
Specified by:
getMetadata in interface ResourceManager
Returns:
a metadata object, may be null

getConfigNamespace

public String getConfigNamespace()
Description copied from interface: ResourceProvider
Returns the namespace for configuration documents that this provider handles.

Specified by:
getConfigNamespace in interface ResourceProvider
Returns:
the namespace for configuration documents, never null

getConfigSchema

public URL getConfigSchema()
Description copied from interface: ResourceProvider
Returns the URL for retrieving the configuration document schema.

Specified by:
getConfigSchema in interface ResourceProvider
Returns:
the URL for retrieving the configuration document schema, may be null

deleteResource

public ResourceState deleteResource(String id)
Description copied from interface: ResourceManager
Removes the specified resource and deletes the corresponding configuration file.

Specified by:
deleteResource in interface ResourceManager
Overrides:
deleteResource in class AbstractBasicResourceManager
Parameters:
id - resource identifier, must not be null
Returns:
resource state after deletion, usually null (if not, deletion failed)

remove

protected void remove(String id)
Specified by:
remove in class AbstractBasicResourceManager

activate

public ResourceState activate(String id)
Description copied from interface: ResourceManager
Activates the resource with the given identifier.

Specified by:
activate in interface ResourceManager
Parameters:
id - resource identifier, must not be null
Returns:
resource state after activation (may be unsuccessful), but never null

deactivate

public ResourceState deactivate(String id)
Description copied from interface: ResourceManager
Deactivates the resource with the given identifier.

Specified by:
deactivate in interface ResourceManager
Parameters:
id - resource identifier, must not be null
Returns:
resource state after deactivation (may be unsuccessful), but never null

getProvider

protected ResourceProvider getProvider(File file)
Specified by:
getProvider in class AbstractBasicResourceManager


Copyright © 2011. All Rights Reserved.