コミットメタ情報

リビジョン6ef5fa929ebd112d85168476cdd11a598b442adc (tree)
日時2013-12-13 22:01:40
作者argius <argius.net@gmai...>
コミッターargius

ログメッセージ

[#31450] add ScriptContext field into Environment for scripting

変更サマリ

差分

--- a/src/net/argius/stew/CommandProcessor.java
+++ b/src/net/argius/stew/CommandProcessor.java
@@ -127,13 +127,23 @@ final class CommandProcessor {
127127 }
128128 // script
129129 if (commandName.equals("-s")) {
130- final File file = Path.resolve(env.getCurrentDirectory(), p.at(1));
130+ if (!p.has(1)) {
131+ throw new UsageException(res.get("usage.-s"));
132+ }
133+ final String p1 = p.at(1);
134+ if (p1.equals(".")) {
135+ env.initializeScriptContext();
136+ outputMessage("i.script-context-initialized");
137+ return true;
138+ }
139+ final File file = Path.resolve(env.getCurrentDirectory(), p1);
131140 if (!file.isFile()) {
132141 throw new UsageException(res.get("usage.-s"));
133142 }
134143 log.debug("-s %s", file.getAbsolutePath());
135144 ScriptEngineManager factory = new ScriptEngineManager();
136145 ScriptEngine engine = factory.getEngineByName("JavaScript");
146+ engine.setContext(env.getScriptContext());
137147 engine.put("connection", env.getCurrentConnection());
138148 engine.put("conn", env.getCurrentConnection());
139149 engine.put("patameter", p);
--- a/src/net/argius/stew/Environment.java
+++ b/src/net/argius/stew/Environment.java
@@ -5,6 +5,8 @@ import static net.argius.stew.Bootstrap.getSystemFile;
55 import java.io.*;
66 import java.sql.*;
77
8+import javax.script.*;
9+
810 import net.argius.stew.ui.*;
911
1012 /**
@@ -26,6 +28,7 @@ public final class Environment {
2628 private File currentDirectory;
2729 private long connectorTimestamp;
2830 private AliasMap aliasMap;
31+ private ScriptContext scriptContext;
2932
3033 private Environment(ConnectorMap connectorMap, File currentDirectory) {
3134 this.connectorMap = connectorMap;
@@ -49,6 +52,7 @@ public final class Environment {
4952 this(new ConnectorMap(), getInitialCurrentDirectory()); // init directories
5053 initializeQueryTimeout();
5154 loadConnectorMap();
55+ initializeScriptContext();
5256 }
5357
5458 /**
@@ -56,7 +60,7 @@ public final class Environment {
5660 * @param src
5761 */
5862 public Environment(Environment src) {
59- // never copy coconnector,conn,op,aliasMap into this
63+ // never copy coconnector,conn,op,aliasMap,scriptContext into this
6064 this(new ConnectorMap(src.connectorMap), src.currentDirectory);
6165 this.timeoutSeconds = src.timeoutSeconds;
6266 }
@@ -181,6 +185,10 @@ public final class Environment {
181185 }
182186 }
183187
188+ void initializeScriptContext() {
189+ this.scriptContext = new SimpleScriptContext();
190+ }
191+
184192 /**
185193 * Loads and refreshes connector map.
186194 */
@@ -266,4 +274,8 @@ public final class Environment {
266274 return aliasMap;
267275 }
268276
277+ public ScriptContext getScriptContext() {
278+ return scriptContext;
279+ }
280+
269281 }
--- a/src/net/argius/stew/messages.u8p
+++ b/src/net/argius/stew/messages.u8p
@@ -14,6 +14,7 @@ i.now=({0,date,yyyy-MM-dd}T{0,time,HH:mm:ss}{0,time,ZZZZ})
1414 i.proceeded=Proceeded {0} records.
1515 i.response-time=[ response time: {0,number,#.###} seconds ]
1616 i.rollbacked=Rollbacked.
17+i.script-context-initialized=Script Context was initialized.
1718 i.selected=Selected {0} records.
1819 i.updated=Updated {0} records.
1920 w.auto-commit-not-available=Warning: Auto-commit mode is not available.
--- a/src/net/argius/stew/messages_ja.u8p
+++ b/src/net/argius/stew/messages_ja.u8p
@@ -13,6 +13,7 @@ i.noalias=エイリアスは未定義です。
1313 i.proceeded={0} 件 処理されました。
1414 i.response-time=[ 応答時間: {0,number,#.###} 秒 ]
1515 i.rollbacked=ロールバックされました。
16+i.script-context-initialized=Script Context は初期化されました。
1617 i.selected={0} 件 ヒットしました。
1718 i.updated={0} 件 更新されました。
1819 w.auto-commit-not-available=警告: 自動コミットモードが無効です。
旧リポジトリブラウザで表示