提交 23959cee authored 作者: Thomas Mueller's avatar Thomas Mueller

Simplify SessionFactory a bit.

上级 b557fb3f
......@@ -24,15 +24,12 @@ import org.h2.util.StringUtils;
* It is also responsible for opening and creating new databases.
* This is a singleton class.
*/
public class Engine {
public class Engine implements SessionFactory {
private static final Engine INSTANCE = new Engine();
private static final HashMap<String, Database> DATABASES = New.hashMap();
private volatile long wrongPasswordDelay = SysProperties.DELAY_WRONG_PASSWORD_MIN;
private Engine() {
// don't allow others to instantiate
}
private final HashMap<String, Database> databases = New.hashMap();
private volatile long wrongPasswordDelay = SysProperties.DELAY_WRONG_PASSWORD_MIN;
public static Engine getInstance() {
return INSTANCE;
......@@ -45,7 +42,7 @@ public class Engine {
if (openNew || ci.isUnnamedInMemory()) {
database = null;
} else {
database = DATABASES.get(name);
database = databases.get(name);
}
User user = null;
boolean opened = false;
......@@ -64,7 +61,7 @@ public class Engine {
database.setMasterUser(user);
}
if (!ci.isUnnamedInMemory()) {
DATABASES.put(name, database);
databases.put(name, database);
}
}
synchronized (database) {
......@@ -108,7 +105,11 @@ public class Engine {
* @param ci the connection information
* @return the session
*/
public Session getSession(ConnectionInfo ci) {
public Session createSession(ConnectionInfo ci) {
return INSTANCE.createSessionAndValidate(ci);
}
private Session createSessionAndValidate(ConnectionInfo ci) {
try {
ConnectionInfo backup = null;
String lockMethodName = ci.getProperty("FILE_LOCK", null);
......@@ -213,7 +214,7 @@ public class Engine {
* @param name the database name
*/
public void close(String name) {
DATABASES.remove(name);
databases.remove(name);
}
/**
......
......@@ -42,7 +42,7 @@ import org.h2.value.ValueString;
* mode, this object resides on the server side and communicates with a
* SessionRemote object on the client side.
*/
public class Session extends SessionWithState implements SessionFactory {
public class Session extends SessionWithState {
/**
* This special log position means that the log entry has been written.
......@@ -118,10 +118,6 @@ public class Session extends SessionWithState implements SessionFactory {
this.currentSchemaName = Constants.SCHEMA_MAIN;
}
public SessionInterface createSession(ConnectionInfo ci) {
return Engine.getInstance().getSession(ci);
}
public boolean setCommitOrRollbackDisabled(boolean x) {
boolean old = commitOrRollbackDisabled;
commitOrRollbackDisabled = x;
......@@ -1178,7 +1174,7 @@ public class Session extends SessionWithState implements SessionFactory {
public SessionInterface reconnect(boolean write) {
readSessionState();
close();
Session newSession = Engine.getInstance().getSession(connectionInfo);
Session newSession = Engine.getInstance().createSession(connectionInfo);
newSession.sessionState = sessionState;
newSession.recreateSessionState();
if (write) {
......
......@@ -108,7 +108,7 @@ public class JdbcConnection extends TraceObject implements Connection {
}
checkJavaVersion();
// this will return an embedded or server connection
session = new SessionRemote().createSession(ci);
session = new SessionRemote(ci).createSession(ci);
trace = session.getTrace();
int id = getNextId(TraceObject.CONNECTION);
setTrace(trace, TraceObject.CONNECTION, id);
......
......@@ -121,8 +121,7 @@ public class TcpServerThread implements Runnable {
for (int i = 0; i < len; i++) {
ci.setProperty(transfer.readString(), transfer.readString());
}
Engine engine = Engine.getInstance();
session = engine.getSession(ci);
session = Engine.getInstance().createSession(ci);
transfer.setSession(session);
transfer.writeInt(SessionRemote.STATUS_OK);
transfer.writeInt(clientVersion);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论