|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.DefaultConnectionManager
public class DefaultConnectionManager
The default implementation of a connection manager.
Each Db will get its own physical connection.
This kind of manager is useful for 2-tier applications directly connecting
to a database backend.
Although this manager implements a strict 1:1 mapping between dbs and connections
it can be easily extended to implememt a M:N mapping, see the MpxConnectionManager.
| Field Summary | |
|---|---|
protected ManagedConnection[] |
conList
managed connections |
protected Db[] |
dbList
Dbs logged in |
protected int |
freeConCount
number of entries in freeConList |
protected int[] |
freeConList
free list for conList (unused entries in conList) |
protected int |
freeDbCount
number of entries in freeDbList |
protected int[] |
freeDbList
free list for dbList (unused entries in dbList) |
protected int |
idOffset
offset for connection IDs |
protected int |
iniSize
initial size |
protected int |
maxConSize
maximum number of connections, 0 = unlimited |
protected int |
maxDbSize
maximum number of Dbs, 0 = unlimited |
protected String |
name
name of the connection manager |
| Constructor Summary | |
|---|---|
DefaultConnectionManager()
Creates a new connection manager with an initial size of 2, a maximum of 8 concurrent connections and an id offset of 1. |
|
DefaultConnectionManager(String name,
int iniSize,
int maxSize,
int idOffset)
Creates a new connection manager. |
|
| Method Summary | |
|---|---|
protected int |
addConnection(ManagedConnection con)
Adds a connection to the list. |
protected int |
addDb(Db db)
Adds a Db to the list. |
ManagedConnection |
attach(int id)
Attaches a Db to a connection.A Db must be attached before it can use any statements. |
void |
detach(int id)
Detaches a connection from a Db.A Db must be detached to release the connection for use of other Db instances. |
int |
getConnectionCount()
Gets the number of established connections |
int |
getDbCount()
Gets the number of valid db entries. |
int |
getMaxConnections()
Gets the maximum number of connections. |
int |
getMaxCountForClearWarnings()
Gets the current setting for clearWarnings() trigger |
int |
getMaxLogins()
Gets the maximum number of allowed logins. |
int |
login(Db db)
Logs in a Db connection.It is up to the manager how to verify whether the Db is allowed to open, a real connection is initiated or just an application level authorization is performed. |
Db |
logout(int id)
Logs out a Db connection. |
protected ManagedConnection |
removeConnection(int index)
Removes a connection from the list. |
protected Db |
removeDb(int index)
Removes a Db from the list. |
void |
setMaxCountForClearWarnings(int maxCountForClearWarnings)
Sets the countForClearWarnings trigger, 0 = app must eat the warnings! |
void |
shutdown()
Shuts down this connection manager. All connections are closed and the threads stopped. |
String |
toString()
Gets the name of the manager. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected String name
protected int iniSize
protected int idOffset
protected Db[] dbList
Dbs logged in
protected int maxDbSize
Dbs, 0 = unlimited
protected int[] freeDbList
protected int freeDbCount
protected ManagedConnection[] conList
protected int maxConSize
protected int[] freeConList
protected int freeConCount
| Constructor Detail |
|---|
public DefaultConnectionManager(String name,
int iniSize,
int maxSize,
int idOffset)
name - the name of the connection manageriniSize - the initial iniSize of the db tablemaxSize - the maximum number of connections, 0 = unlimited (dangerous!)idOffset - the offset for connection ids (> 0)public DefaultConnectionManager()
| Method Detail |
|---|
public String toString()
toString in class Objectpublic void setMaxCountForClearWarnings(int maxCountForClearWarnings)
maxCountForClearWarnings - the maxcountpublic int getMaxCountForClearWarnings()
protected int addDb(Db db)
db - the db to add
protected Db removeDb(int index)
index - the index of db in the dblist
public int getDbCount()
protected int addConnection(ManagedConnection con)
con - the connection to add
protected ManagedConnection removeConnection(int index)
index - the index of connection in the conlist
public int getConnectionCount()
public int getMaxLogins()
ConnectionManager
getMaxLogins in interface ConnectionManagerpublic int getMaxConnections()
ConnectionManager
getMaxConnections in interface ConnectionManager
public int login(Db db)
throws DbRuntimeException
ConnectionManagerDb connection.
login in interface ConnectionManagerdb - the db to login
DbRuntimeException - if login failed.
public Db logout(int id)
throws DbRuntimeException
ConnectionManagerDb connection.
The Db is not allowed to attach anymore. If the Db is still attached,
a rollback of any pending tx is done and an exception thrown.
logout in interface ConnectionManagerid - the connection ID of the db
DbRuntimeException - if logout failed.
public ManagedConnection attach(int id)
throws DbRuntimeException
ConnectionManagerDb to a connection.
attach in interface ConnectionManagerid - the connection ID of the db
DbRuntimeException - if attach failed.
public void detach(int id)
throws DbRuntimeException
ConnectionManagerDb.
detach in interface ConnectionManagerid - the connection ID of the db
DbRuntimeException - if detach failed.public void shutdown()
ConnectionManager
shutdown in interface ConnectionManager
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||