org.objectweb.cjdbc.driver
Class CjdbcUrl

java.lang.Object
  extended byorg.objectweb.cjdbc.driver.CjdbcUrl

public class CjdbcUrl
extends java.lang.Object

This class defines a C-JDBC url with parsed Metadata and so on. The connection policy is interpreted while reading the URL. We could rename it to ParsedURL.

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
private  AbstractControllerConnectPolicy controllerConnectPolicy
           
private  ControllerInfo[] controllerList
           
private  java.lang.String databaseName
           
static int DEBUG_LEVEL_DEBUG
          Most verbose level of debug
static int DEBUG_LEVEL_INFO
          Informational level of debug
static int DEBUG_LEVEL_OFF
          No debug messages
private  int debugLevel
           
private  java.util.HashMap parameters
           
private  java.lang.String url
           
 
Constructor Summary
CjdbcUrl(java.lang.String url)
          Creates a new CjdbcUrl object, parse it and instantiate the connection creation policy.
 
Method Summary
private  AbstractControllerConnectPolicy createConnectionPolicy()
          Create the corresponding controller connect policy according to what is found in the URL.
 AbstractControllerConnectPolicy getControllerConnectPolicy()
          Returns the controllerConnectPolicy value.
 ControllerInfo[] getControllerList()
          Returns the controllerList value.
 java.lang.String getDatabaseName()
          Returns the database name.
 java.util.HashMap getParameters()
          Returns the URL parameters/value in a HashMap (warning this is not a clone).
 java.lang.String getUrl()
          Returns the url value.
 boolean isDebugEnabled()
          Returns true if debugging is set to debug level 'debug'
 boolean isInfoEnabled()
          Returns true if debug level is 'info' or greater
static ControllerInfo parseController(java.lang.String controller)
          Checks the validity of the hostname, port number and controller name given in the URL and build the full URL used to lookup a controller.
private  void parseUrl()
          Checks for URL correctness and extract database name, controller list and parameters.
private  java.util.HashMap parseUrlParams(java.lang.String urlString)
          Parse the given URL and returns the parameters in a HashMap containing ParamaterName=>Value.
private  java.util.HashMap parseUrlParams(java.lang.String urlString, char beginMarker, java.lang.String parameterSeparator, java.lang.String equal)
          Parse the given URL looking for parameters starting after the beginMarker, using parameterSeparator as the separator between parameters and equal as the delimiter between a parameter and its value.
 void setUrl(java.lang.String url)
          Sets the url value.
private static java.lang.Character validDatabaseName(java.lang.String databaseName)
          Checks that the given name contains acceptable characters for a database name ([0-9][A-Z][a-z]["-_"]).
private static java.lang.Character validHostname(java.lang.String hostname)
          Checks that the given name contains acceptable characters for a hostname name ([0-9][A-Z][a-z][["-_."]).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

url

private java.lang.String url

databaseName

private java.lang.String databaseName

controllerList

private ControllerInfo[] controllerList

parameters

private java.util.HashMap parameters

controllerConnectPolicy

private AbstractControllerConnectPolicy controllerConnectPolicy

debugLevel

private int debugLevel

DEBUG_LEVEL_DEBUG

public static final int DEBUG_LEVEL_DEBUG
Most verbose level of debug

See Also:
Constant Field Values

DEBUG_LEVEL_INFO

public static final int DEBUG_LEVEL_INFO
Informational level of debug

See Also:
Constant Field Values

DEBUG_LEVEL_OFF

public static final int DEBUG_LEVEL_OFF
No debug messages

See Also:
Constant Field Values
Constructor Detail

CjdbcUrl

public CjdbcUrl(java.lang.String url)
         throws java.sql.SQLException
Creates a new CjdbcUrl object, parse it and instantiate the connection creation policy.

Parameters:
url - the URL to parse
Throws:
java.sql.SQLException - if an error occurs while parsing the url
Method Detail

isDebugEnabled

public boolean isDebugEnabled()
Returns true if debugging is set to debug level 'debug'

Returns:
true if debugging is enabled

isInfoEnabled

public boolean isInfoEnabled()
Returns true if debug level is 'info' or greater

Returns:
true if debug level is 'info' or greater

getControllerConnectPolicy

public AbstractControllerConnectPolicy getControllerConnectPolicy()
Returns the controllerConnectPolicy value.

Returns:
Returns the controllerConnectPolicy.

getControllerList

public ControllerInfo[] getControllerList()
Returns the controllerList value.

Returns:
Returns the controllerList.

getDatabaseName

public java.lang.String getDatabaseName()
Returns the database name.

Returns:
Returns the database name.

getParameters

public java.util.HashMap getParameters()
Returns the URL parameters/value in a HashMap (warning this is not a clone).

The HashMap is 'parameter name'=>'value'

Returns:
Returns the parameters and their value in a Hasmap.

getUrl

public java.lang.String getUrl()
Returns the url value.

Returns:
Returns the url.

setUrl

public void setUrl(java.lang.String url)
Sets the url value.

Parameters:
url - The url to set.

createConnectionPolicy

private AbstractControllerConnectPolicy createConnectionPolicy()
Create the corresponding controller connect policy according to what is found in the URL. If no policy was specified then a RandomConnectPolicy is returned.

Returns:
an AbstractControllerConnectPolicy

parseUrl

private void parseUrl()
               throws java.sql.SQLException
Checks for URL correctness and extract database name, controller list and parameters.

Throws:
java.sql.SQLException - if an error occurs.

parseUrlParams

private java.util.HashMap parseUrlParams(java.lang.String urlString)
                                  throws java.sql.SQLException
Parse the given URL and returns the parameters in a HashMap containing ParamaterName=>Value.

Parameters:
urlString - the URL to parse
Returns:
a Hashmap of param name=>value possibly empty
Throws:
java.sql.SQLException - if an error occurs

parseUrlParams

private java.util.HashMap parseUrlParams(java.lang.String urlString,
                                         char beginMarker,
                                         java.lang.String parameterSeparator,
                                         java.lang.String equal)
                                  throws java.sql.SQLException
Parse the given URL looking for parameters starting after the beginMarker, using parameterSeparator as the separator between parameters and equal as the delimiter between a parameter and its value.

Parameters:
urlString - the URL to parse
beginMarker - delimiter for beginning of parameters
parameterSeparator - delimiter between parameters
equal - delimiter between parameter and its value
Returns:
HashMap of ParameterName=>Value
Throws:
java.sql.SQLException - if an error occurs

parseController

public static ControllerInfo parseController(java.lang.String controller)
                                      throws java.sql.SQLException
Checks the validity of the hostname, port number and controller name given in the URL and build the full URL used to lookup a controller.

Parameters:
controller - information regarding a controller.
Returns:
a ControllerInfo object
Throws:
java.sql.SQLException - if an error occurs.

validHostname

private static java.lang.Character validHostname(java.lang.String hostname)
Checks that the given name contains acceptable characters for a hostname name ([0-9][A-Z][a-z][["-_."]).

Parameters:
hostname - name to check (caller must check that it is not null).
Returns:
null if the hostname is acceptable, else the character that causes the fault.

validDatabaseName

private static java.lang.Character validDatabaseName(java.lang.String databaseName)
Checks that the given name contains acceptable characters for a database name ([0-9][A-Z][a-z]["-_"]).

Parameters:
databaseName - name to check (caller must check that it is not null).
Returns:
null if the name is acceptable, else the character that causes the fault.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.