net.sf.saffron.oj
Class OJConnectionRegistry

java.lang.Object
  |
  +--net.sf.saffron.oj.OJConnectionRegistry

public class OJConnectionRegistry
extends Object

Collection of saffron connections, and the expression by which they can be accessed.

You only need to register connections when you are compiling code for a later time.

If you create a wrapper around a connection, you will need to register the new connection as equivalent to the old one by calling setEquivalent(net.sf.saffron.core.SaffronConnection, net.sf.saffron.core.SaffronConnection).

The current implementation keeps connections around for ever. TODO: Use weak maps.

Since:
Nov 28, 2003
Version:
$Id: $
Author:
jhyde

Nested Class Summary
static class OJConnectionRegistry.ConnectionInfo
          Properties of a SaffronConnection.
static interface OJConnectionRegistry.ExpressionFunctor
          Yields an expression for a JDBC data source when given expressions for the Saffron connection and a JDBC connect string.
 
Field Summary
private  int counter
           
private  HashMap equivMap
           
static OJConnectionRegistry instance
           
private  HashMap map
           
private  HashMap tokenMap
           
 
Constructor Summary
private OJConnectionRegistry()
           
 
Method Summary
 SaffronConnection get(ParseTree expr)
          Retrieves a connection based upon an Openjava expression.
 OJConnectionRegistry.ConnectionInfo get(SaffronConnection connection)
          Retrieves information about a previously registered connection.
 OJConnectionRegistry.ConnectionInfo get(SaffronConnection connection, boolean create)
          Retrieves information about a previously registered connection, optionally registering a connection if it is not already registered.
 SaffronConnection get(String token)
          Retrives a connection based upon a token.
 void register(SaffronConnection connection, Expression expr, OJConnectionRegistry.ExpressionFunctor jdbcExprFunctor, Environment env)
          Registers a connection with an expression and environment
private  OJConnectionRegistry.ConnectionInfo registerInternal(SaffronConnection connection, Expression expr, OJConnectionRegistry.ExpressionFunctor jdbcExprFunctor, Environment env, String token)
           
 void setEquivalent(SaffronConnection connection, SaffronConnection equiv)
          Register that a connection is equivalent to another.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static final OJConnectionRegistry instance

map

private HashMap map

counter

private int counter

tokenMap

private HashMap tokenMap

equivMap

private HashMap equivMap
Constructor Detail

OJConnectionRegistry

private OJConnectionRegistry()
Method Detail

register

public void register(SaffronConnection connection,
                     Expression expr,
                     OJConnectionRegistry.ExpressionFunctor jdbcExprFunctor,
                     Environment env)
Registers a connection with an expression and environment

Parameters:
connection - SaffronConnection
expr - Java expression with which to access the connection in a generated program
jdbcExprFunctor - Functor which converts an expression for the SaffronConnection into an expression for the DataSource for a JDBC connection. If null, the default functor converts {expr} into (DataSource) {expr}.
Pre-condition:
connection != null, expr != null, env != null

registerInternal

private OJConnectionRegistry.ConnectionInfo registerInternal(SaffronConnection connection,
                                                             Expression expr,
                                                             OJConnectionRegistry.ExpressionFunctor jdbcExprFunctor,
                                                             Environment env,
                                                             String token)

get

public OJConnectionRegistry.ConnectionInfo get(SaffronConnection connection)
Retrieves information about a previously registered connection.

If no information is found about this connection, consults connections which it has been declared to be equivalent to using setEquivalent(net.sf.saffron.core.SaffronConnection, net.sf.saffron.core.SaffronConnection).


get

public OJConnectionRegistry.ConnectionInfo get(SaffronConnection connection,
                                               boolean create)
Retrieves information about a previously registered connection, optionally registering a connection if it is not already registered.

If the connection has not been registered, and create is true, creates an expression which references this registry. An example expression would be

OJConnectionRegistry.instance.get("45")
where "45" is a token value. Note that this expression will only be good within this JVM instance, and is therefore no good for generated code or code which will be run in another JVM.

Parameters:
connection - Connection to lookup
create - Whether to create a record if connection is not known.
Returns:
Information about the connection, null if the connection has not been registered and create is false

get

public SaffronConnection get(String token)
Retrives a connection based upon a token. If no connection has been registered with this token, throws an error.


get

public SaffronConnection get(ParseTree expr)
Retrieves a connection based upon an Openjava expression. If the expression looks like
OJConnectionRegistry.instance.get("45")
returns the same connection as get("45"), otherwise returns null.


setEquivalent

public void setEquivalent(SaffronConnection connection,
                          SaffronConnection equiv)
Register that a connection is equivalent to another.

Parameters:
connection - The new connection
equiv - The existing connection it is equivalent to

SourceForge.net_Logo