|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saffron.oj.OJConnectionRegistry
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.
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 |
public static final OJConnectionRegistry instance
private HashMap map
private int counter
private HashMap tokenMap
private HashMap equivMap
Constructor Detail |
private OJConnectionRegistry()
Method Detail |
public void register(SaffronConnection connection, Expression expr, OJConnectionRegistry.ExpressionFunctor jdbcExprFunctor, Environment env)
connection
- SaffronConnectionexpr
- Java expression with which to access the connection in a
generated programjdbcExprFunctor
- 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}
.private OJConnectionRegistry.ConnectionInfo registerInternal(SaffronConnection connection, Expression expr, OJConnectionRegistry.ExpressionFunctor jdbcExprFunctor, Environment env, String token)
public OJConnectionRegistry.ConnectionInfo get(SaffronConnection 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)
.
public OJConnectionRegistry.ConnectionInfo get(SaffronConnection connection, boolean create)
If the connection has not been registered, and create
is
true, creates an expression which references this registry. An example
expression would be
whereOJConnectionRegistry.instance.get("45")
"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.
connection
- Connection to lookupcreate
- Whether to create a record if connection is not known.
public SaffronConnection get(String token)
public SaffronConnection get(ParseTree expr)
returns the same connection asOJConnectionRegistry.instance.get("45")
get("45")
,
otherwise returns null
.
public void setEquivalent(SaffronConnection connection, SaffronConnection equiv)
connection
- The new connectionequiv
- The existing connection it is equivalent to
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |