提交 576b3c8f authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Incapsulated setSchema/getSchema logic in SessionInterface

上级 56d4c7e9
...@@ -1221,10 +1221,17 @@ public class Session extends SessionWithState { ...@@ -1221,10 +1221,17 @@ public class Session extends SessionWithState {
this.currentSchemaName = schema.getName(); this.currentSchemaName = schema.getName();
} }
@Override
public String getCurrentSchemaName() { public String getCurrentSchemaName() {
return currentSchemaName; return currentSchemaName;
} }
@Override
public void setCurrentSchemaName(String schemaName) {
Schema schema = database.getSchema(schemaName);
setCurrentSchema(schema);
}
/** /**
* Create an internal connection. This connection is used when initializing * Create an internal connection. This connection is used when initializing
* triggers, and when calling user defined functions. * triggers, and when calling user defined functions.
......
...@@ -7,8 +7,8 @@ package org.h2.engine; ...@@ -7,8 +7,8 @@ package org.h2.engine;
import java.io.Closeable; import java.io.Closeable;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.store.DataHandler; import org.h2.store.DataHandler;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -140,4 +140,18 @@ public interface SessionInterface extends Closeable { ...@@ -140,4 +140,18 @@ public interface SessionInterface extends Closeable {
* @return true if this session is remote * @return true if this session is remote
*/ */
boolean isRemote(); boolean isRemote();
/**
* Set current schema as in {@link JdbcConnection#setSchema(String)}.
*
* @param schema the schema name
*/
void setCurrentSchemaName(String schema);
/**
* Get current schema as in {@link JdbcConnection#getSchema()}.
*
* @return the current schema name
*/
String getCurrentSchemaName();
} }
...@@ -858,4 +858,14 @@ public class SessionRemote extends SessionWithState implements DataHandler { ...@@ -858,4 +858,14 @@ public class SessionRemote extends SessionWithState implements DataHandler {
public boolean isRemote() { public boolean isRemote() {
return true; return true;
} }
@Override
public String getCurrentSchemaName() {
throw DbException.getUnsupportedException("getSchema && remote session");
}
@Override
public void setCurrentSchemaName(String schema) {
throw DbException.getUnsupportedException("setSchema && remote session");
}
} }
...@@ -1903,12 +1903,7 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne ...@@ -1903,12 +1903,7 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne
debugCodeCall("setSchema", schema); debugCodeCall("setSchema", schema);
} }
checkClosed(); checkClosed();
if (session.isRemote()) { session.setCurrentSchemaName(schema);
throw DbException.getUnsupportedException("setSchema && remote session");
}
Database database = (Database) session.getDataHandler();
Schema s = database.getSchema(schema);
((Session) session).setCurrentSchema(s);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -1926,10 +1921,7 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne ...@@ -1926,10 +1921,7 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne
debugCodeCall("getSchema"); debugCodeCall("getSchema");
} }
checkClosed(); checkClosed();
if (session.isRemote()) { return session.getCurrentSchemaName();
throw DbException.getUnsupportedException("getSchema && remote session");
}
return ((Session) session).getCurrentSchemaName();
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论