org.apache.jdo.impl.fostore
Class FOStoreConnectionFactory

java.lang.Object
  extended byorg.apache.jdo.impl.fostore.FOStoreConnectionFactory
All Implemented Interfaces:
java.io.Serializable

public class FOStoreConnectionFactory
extends java.lang.Object
implements java.io.Serializable

A connection factory for FOStore. Allows both same- and remote-address space connections. For the same address space-connections, the URL must not include the Host (Server) parameter. For remote address space connections, the URL's protocol is ignored.

This class is public so that clients can create instances of it with new.

Author:
Dave Bristor
See Also:
Serialized Form

Nested Class Summary
(package private) static interface FOStoreConnectionFactory.CFAccessor
          CFAccessor implementation instances allow copying values to/from a FOStoreConnectionFactory and a Properties.
 
Field Summary
protected static java.util.HashMap CFpropsAccessors
          This table maps from names to CFAccessors.
private  boolean configurable
          True until setConfigured has been invoked.
private  java.util.HashMap connectionMap
          Connections are pooled.
private  boolean create
           
private  FOStoreConnectionId defaultConnectionId
           
private  java.lang.String driverName
           
(package private) static org.apache.commons.logging.Log logger
          Logger
private  int loginTimeout
           
private  java.io.PrintWriter logWriter
           
private static org.apache.jdo.util.I18NHelper msg
          I18N support.
private  java.lang.String password
           
private  FOStorePMF pmf
           
private static int poolSize
          For now, set the pool size to 1.
private  FOStoreURLStreamHandler streamHandler
          Connections are created by the FOStoreURLStreamHandler.
private  java.lang.String url
           
private  FOStoreConnectionId userConnectionId
           
private  java.lang.String userName
           
 
Constructor Summary
FOStoreConnectionFactory()
          First time a FOStoreConnectionFactory is created, initialize accessors which are used to store/save instances via JNDI.
 
Method Summary
private  void assertConfigurable()
           
(package private)  void closeConnection(FOStoreClientConnection connection)
          Returns a connection to the pool
 void closeDatabase()
          Close the database.
private  FOStoreClientConnection createConnection(FOStoreConnectionId id)
          This method requires permission to perform the following requests: Create new URL with the specified StreamHandler.
(package private)  org.apache.jdo.util.Pool createPool(FOStoreConnectionId id)
          Create a new pool of connections for this combination of url, user, and password.
 FOStoreClientConnection getConnection()
          Provides a connection to the database using the configured userName, password, and url.
 FOStoreClientConnection getConnection(java.lang.String user, java.lang.String password)
          Provides a connection to the database using the given userName and password.
 boolean getCreate()
          Returns whether to create the database.
 java.lang.String getDriverName()
          Provides name of driver used for connections
 int getLoginTimeout()
          Returns the number of seconds to wait for a new connection to be established to the data source
 java.io.PrintWriter getLogWriter()
          Returns the LogWriter to which messages should be sent
 int getMaxPool()
          Returns maximum number of connections in the connection pool
 int getMinPool()
          Returns minimum number of connections in the connection pool
 int getMsInterval()
          Returns the amount of time, in milliseconds, between the connection manager's attempts to get a pooled connection.
 int getMsWait()
          Returns the number of milliseconds to wait for an available connection from the connection pool before throwing an exception
 FOStorePMF getPMF()
          Provides PersistenceManagerFactory for connections
 java.lang.String getURL()
          Returns connection URL
 java.lang.String getUserName()
          Returns database user name
protected static void initPropsAccessors()
           
 boolean isConfigured()
          Returns true if this connection factory has been configured with a URL.
private  void setConfigured()
          Set the url, user, and password into the ConnectionIds for this connection factory.
 void setCreate(boolean create)
          Sets whether to create the database.
 void setCreate(java.lang.String create)
          Sets whether to create the database.
 void setDriverName(java.lang.String driverName)
          Sets name of the driver for connections
 void setFromProperties(java.util.Properties p)
          Configures a FOStoreConnectionFactory from the given Properties.
 void setLoginTimeout(int loginTimeout)
          Sets the number of seconds to wait for a new connection to be established to the data source
 void setLogWriter(java.io.PrintWriter logWriter)
          Sets the LogWriter to which messages should be sent
 void setMaxPool(int maxPool)
          Sets maximum number of connections in the connection pool
 void setMinPool(int minPool)
          Sets minimum number of connections in the connection pool
 void setMsInterval(int msInterval)
          Sets the amount of time, in milliseconds, between the connection manager's attempts to get a pooled connection.
 void setMsWait(int msWait)
          Sets the number of milliseconds to wait for an available connection from the connection pool before throwing an exception
 void setPassword(java.lang.String password)
          Sets database user password
 void setPMF(FOStorePMF pmf)
          Sets PersistenceManagerFactory for connections
(package private)  void setProperties(java.util.Properties p)
          Sets properties as per the property values in the connection factory.
 void setURL(java.lang.String url)
          Sets connection URL
 void setUserName(java.lang.String userName)
          Sets database user
private static int toInt(java.lang.String s)
          It should *never* be the case that our translation process encounters a NumberFormatException.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

url

private java.lang.String url

userName

private java.lang.String userName

password

private java.lang.String password

driverName

private java.lang.String driverName

create

private boolean create

pmf

private FOStorePMF pmf

loginTimeout

private int loginTimeout

logWriter

private transient java.io.PrintWriter logWriter

streamHandler

private final FOStoreURLStreamHandler streamHandler
Connections are created by the FOStoreURLStreamHandler.


connectionMap

private final java.util.HashMap connectionMap
Connections are pooled. Each unique combination of url, user, password has its own pool. The hashmap associates a FOStoreConnectionId with its pool of connections.


poolSize

private static final int poolSize
For now, set the pool size to 1.

See Also:
Constant Field Values

defaultConnectionId

private FOStoreConnectionId defaultConnectionId

userConnectionId

private FOStoreConnectionId userConnectionId

configurable

private boolean configurable
True until setConfigured has been invoked. Allows properties to be set if true.


CFpropsAccessors

protected static java.util.HashMap CFpropsAccessors
This table maps from names to CFAccessors. The names are the same as the persistence manager factory's property names, but with org.apache.jdo.FOStoreConnectionFactory.option prepended.


msg

private static final org.apache.jdo.util.I18NHelper msg
I18N support.


logger

static final org.apache.commons.logging.Log logger
Logger

Constructor Detail

FOStoreConnectionFactory

public FOStoreConnectionFactory()
First time a FOStoreConnectionFactory is created, initialize accessors which are used to store/save instances via JNDI.

Method Detail

setConfigured

private void setConfigured()
Set the url, user, and password into the ConnectionIds for this connection factory.


assertConfigurable

private void assertConfigurable()

getConnection

public FOStoreClientConnection getConnection(java.lang.String user,
                                             java.lang.String password)
Provides a connection to the database using the given userName and password. The first time a connection is made, the factory can no longer be configured.

Returns:
A FOStoreClientConnection

createPool

org.apache.jdo.util.Pool createPool(FOStoreConnectionId id)
Create a new pool of connections for this combination of url, user, and password. This might be either the default or for a specific user.


getConnection

public FOStoreClientConnection getConnection()
Provides a connection to the database using the configured userName, password, and url. The first time a connection is made, the factory can no longer be configured.

Returns:
A FOStoreClientConnection

createConnection

private FOStoreClientConnection createConnection(FOStoreConnectionId id)
This method requires permission to perform the following requests: Create new URL with the specified StreamHandler. Delete old database id create flag is set to true.


closeConnection

void closeConnection(FOStoreClientConnection connection)
Returns a connection to the pool

Parameters:
connection - Connection to be returned to the pool.

closeDatabase

public void closeDatabase()
Close the database. This really means close all connections that have been opened. Closing the last connection on a database actually closes the database, whether local or remote.


setDriverName

public void setDriverName(java.lang.String driverName)
Sets name of the driver for connections

Parameters:
driverName - driver name

getPMF

public FOStorePMF getPMF()
Provides PersistenceManagerFactory for connections

Returns:
PMF

setPMF

public void setPMF(FOStorePMF pmf)
Sets PersistenceManagerFactory for connections

Parameters:
pmf - PersistenceManagerFactory

getDriverName

public java.lang.String getDriverName()
Provides name of driver used for connections

Returns:
driver name

setURL

public void setURL(java.lang.String url)
Sets connection URL

Parameters:
url - connection URL

getURL

public java.lang.String getURL()
Returns connection URL

Returns:
connection URL

setUserName

public void setUserName(java.lang.String userName)
Sets database user

Parameters:
userName - database user

getUserName

public java.lang.String getUserName()
Returns database user name

Returns:
current database user name

setPassword

public void setPassword(java.lang.String password)
Sets database user password

Parameters:
password - database user password

setMinPool

public void setMinPool(int minPool)
Sets minimum number of connections in the connection pool

Parameters:
minPool - minimum number of connections

getMinPool

public int getMinPool()
Returns minimum number of connections in the connection pool

Returns:
connection minPool

setMaxPool

public void setMaxPool(int maxPool)
Sets maximum number of connections in the connection pool

Parameters:
maxPool - maximum number of connections

getMaxPool

public int getMaxPool()
Returns maximum number of connections in the connection pool

Returns:
connection maxPool

setMsInterval

public void setMsInterval(int msInterval)
Sets the amount of time, in milliseconds, between the connection manager's attempts to get a pooled connection.

Parameters:
msInterval - the interval between attempts to get a database connection, in milliseconds.

getMsInterval

public int getMsInterval()
Returns the amount of time, in milliseconds, between the connection manager's attempts to get a pooled connection.

Returns:
the length of the interval between tries in milliseconds

setMsWait

public void setMsWait(int msWait)
Sets the number of milliseconds to wait for an available connection from the connection pool before throwing an exception

Parameters:
msWait - number in milliseconds

getMsWait

public int getMsWait()
Returns the number of milliseconds to wait for an available connection from the connection pool before throwing an exception

Returns:
number in milliseconds

setLogWriter

public void setLogWriter(java.io.PrintWriter logWriter)
Sets the LogWriter to which messages should be sent

Parameters:
logWriter - logWriter

getLogWriter

public java.io.PrintWriter getLogWriter()
Returns the LogWriter to which messages should be sent

Returns:
logWriter

setLoginTimeout

public void setLoginTimeout(int loginTimeout)
Sets the number of seconds to wait for a new connection to be established to the data source

Parameters:
loginTimeout - wait time in seconds

getLoginTimeout

public int getLoginTimeout()
Returns the number of seconds to wait for a new connection to be established to the data source

Returns:
wait time in seconds

setCreate

public void setCreate(boolean create)
Sets whether to create the database.

Parameters:
create - whether to create the database.

setCreate

public void setCreate(java.lang.String create)
Sets whether to create the database.

Parameters:
create - whether to create the database.

getCreate

public boolean getCreate()
Returns whether to create the database.

Returns:
whether to create the database

initPropsAccessors

protected static void initPropsAccessors()

toInt

private static int toInt(java.lang.String s)
It should *never* be the case that our translation process encounters a NumberFormatException. If so, tell the user in the JDO-approved manner.


setProperties

void setProperties(java.util.Properties p)
Sets properties as per the property values in the connection factory. For each CFAccessor in the given HashMap, gets the corresponding value from the FOStoreConnectionFactory and puts it in the given Properties object.


setFromProperties

public void setFromProperties(java.util.Properties p)
Configures a FOStoreConnectionFactory from the given Properties. For each Accessor in the given HashMap, gets the corresponding value from the Properties and sets that value in the PMF. This is public so that a test program can create a FOSToreConnectionFactory, and configure it from a Properties object.


isConfigured

public boolean isConfigured()
Returns true if this connection factory has been configured with a URL.


toString

public java.lang.String toString()