From 412a4756db93fd787c47afb244c9adff0b77ec2a Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 15 Feb 2019 16:34:36 +0800 Subject: [PATCH] =?UTF-8?q?redis=E6=94=AF=E6=8C=81=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.xml | 2 +- plugin.xml | 3 +- .../fr/plugin/db/redis/core/DataWrapper.java | 69 ++++ .../plugin/db/redis/core/RedisTableData.java | 325 +++++++++--------- .../db/redis/core/RedisTableDataModel.java | 7 +- .../db/redis/core/visit/VisitorFactory.java | 1 - .../core/visit/impl/SingleArrayVisitor.java | 91 ----- .../fr/plugin/db/redis/ui/RedisQueryPane.java | 43 ++- .../db/redis/ui/RedisTableDataPane.java | 8 +- .../plugin/db/redis/locale/redis.properties | 4 +- .../db/redis/locale/redis_en_US.properties | 10 +- .../db/redis/locale/redis_zh_CN.properties | 10 +- 12 files changed, 309 insertions(+), 264 deletions(-) delete mode 100644 src/main/java/com/fr/plugin/db/redis/core/visit/impl/SingleArrayVisitor.java diff --git a/build.xml b/build.xml index 47680ed..80bc907 100644 --- a/build.xml +++ b/build.xml @@ -1,7 +1,7 @@ - + diff --git a/plugin.xml b/plugin.xml index bf1a703..b1c65ad 100755 --- a/plugin.xml +++ b/plugin.xml @@ -3,12 +3,13 @@ com.fr.solution.plugin.db.redis.v10 yes - 4.1 + 4.2 10.0 2018-11-29 richie [2018-11-30]解决远程设计时无法查询key列表的问题。
[2018-11-26]解决10.0版本中服务器数据集无法保存的问题。
[2018-09-12]适配10.0版本。
diff --git a/src/main/java/com/fr/plugin/db/redis/core/DataWrapper.java b/src/main/java/com/fr/plugin/db/redis/core/DataWrapper.java index 7d79bf6..a71c4e5 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/DataWrapper.java +++ b/src/main/java/com/fr/plugin/db/redis/core/DataWrapper.java @@ -1,6 +1,19 @@ package com.fr.plugin.db.redis.core; +import com.fr.general.GeneralUtils; +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.script.ScriptFactory; +import com.fr.stable.StringUtils; +import com.fr.workspace.WorkContext; + +import javax.script.ScriptEngine; +import javax.script.ScriptException; +import java.io.File; +import java.io.FileInputStream; +import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * Created by richie on 2017/6/5. @@ -31,4 +44,60 @@ public class DataWrapper { public List> getData() { return data; } + + public void transform(String script) throws ScriptException { + if (StringUtils.isBlank(script)) { + return; + } + String scriptText = null; + if (script.startsWith("file:///")) { + try { + FileInputStream in = new FileInputStream(new File(readAndRenderScriptFile(script))); + scriptText = IOUtils.inputStream2String(in); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } else { + scriptText = String.format("(function(){%s})()", script); + } + ScriptEngine scriptEngine = ScriptFactory.newScriptEngine(); + scriptEngine.put("$content", data); + scriptEngine.put("$column", columnNames); + Object r = scriptEngine.eval(scriptText); + if (r instanceof Map) { + Map map = (Map)r; + if (map.containsKey("column") && map.containsKey("content")) { + Object vector = map.get("column"); + List names = new ArrayList(); + for (Object name : ((Map)vector).values()) { + names.add(GeneralUtils.objectToString(name)); + } + columnNames = names.toArray(new String[0]); + Object content = map.get("content"); + if (content instanceof Map) { + List> list = new ArrayList>(); + for (Object element : ((Map)content).values()) { + list.add(object2List(element)); + } + data = list; + } + } + } + } + + private List object2List(Object obj) { + List list = new ArrayList(); + if (obj instanceof Map) { + for (Object element : ((Map)obj).values()) { + list.add((T)element); + } + } else { + list.add((T)obj); + } + return list; + } + + private String readAndRenderScriptFile(String filePath) { + return filePath.replaceFirst("\\$ENV_HOME", WorkContext.getCurrent().getPath()); + } } diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java b/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java index b1a81c6..4fd6a10 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java @@ -1,155 +1,172 @@ -package com.fr.plugin.db.redis.core; - -import com.fr.base.Parameter; -import com.fr.base.TableData; -import com.fr.base.TemplateUtils; -import com.fr.config.holder.Conf; -import com.fr.config.holder.factory.Holders; -import com.fr.config.holder.factory.XmlHolders; -import com.fr.data.AbstractParameterTableData; -import com.fr.data.core.DataCoreXmlUtils; -import com.fr.data.impl.Connection; -import com.fr.data.impl.NameDatabaseConnection; -import com.fr.file.DatasourceManager; -import com.fr.general.data.DataModel; -import com.fr.general.xml.GeneralXMLTools; -import com.fr.intelli.record.Focus; -import com.fr.intelli.record.Original; -import com.fr.plugin.db.redis.core.order.OrderValue; -import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue; -import com.fr.record.analyzer.EnableMetrics; -import com.fr.script.Calculator; -import com.fr.stable.ArrayUtils; -import com.fr.stable.ParameterProvider; -import com.fr.stable.StringUtils; -import com.fr.stable.xml.XMLPrintWriter; -import com.fr.stable.xml.XMLableReader; - -import java.util.HashMap; -import java.util.Map; - - -@EnableMetrics -public class RedisTableData extends AbstractParameterTableData { - - private static final long serialVersionUID = 7017455818551800001L; - private Conf database = Holders.obj(null, Connection.class); - private Conf dbIndex = XmlHolders.obj(new NumberOrderValue(0), OrderValue.class, OrderValue.XML_TAG); - private Conf query = Holders.simple(StringUtils.EMPTY); - - public void setDatabase(Connection c) { - this.database.set(c); - } - - public Connection getDatabase() { - return database.get(); - } - - public OrderValue getOrderValue() { - return dbIndex.get(); - } - - public void setOrderValue(OrderValue dbIndex) { - this.dbIndex.set(dbIndex); - } - - public String getQuery() { - return query.get(); - } - - public void setQuery(String query) { - this.query.set(query); - } - - public void setParameters(ParameterProvider[] providers) { - super.setDefaultParameters(providers); - } - - @Override - public DataModel createDataModel(Calculator calculator) { - return createDataModel(calculator, TableData.RESULT_ALL); - } - - @Override - @Focus(id = RedisConstants.PLUGIN_ID, text = "Plugin-Redis_DB", source = Original.PLUGIN) - public DataModel createDataModel(Calculator calculator, int rowCount) { - Parameter[] ps = Parameter.providers2Parameter(getParameters(calculator)); - Connection connection = database.get(); - if (connection instanceof NameDatabaseConnection) { - String name = ((NameDatabaseConnection) connection).getName(); - RedisDatabaseConnection rc = DatasourceManager.getProviderInstance().getConnection(name, RedisDatabaseConnection.class); - if (rc != null) { - OrderValue orderValue = dbIndex.get(); - return new RedisTableDataModel(calculator, ps, rc, - orderValue == null ? 0 : orderValue.toIndex(calculator, ps), - calculateQuery(query.get(), ps), - rowCount); - } - } - return null; - } - - private String calculateQuery(String query, Parameter[] ps) { - if (ArrayUtils.isEmpty(ps)) { - return query; - } - Map map = new HashMap(); - for (Parameter p : ps) { - map.put(p.getName(), p.getValue()); - } - try { - return TemplateUtils.renderParameter4Tpl(query, map); - } catch (Exception e) { - return query; - } - } - - public void readXML(XMLableReader reader) { - super.readXML(reader); - - if (reader.isChildNode()) { - String tmpName = reader.getTagName(); - String tmpVal; - - if (OrderValue.XML_TAG.equals(tmpName)) { - OrderValue orderValue = (OrderValue) GeneralXMLTools.readXMLable(reader); - if (orderValue != null) { - setOrderValue(orderValue); - } - } else if (com.fr.data.impl.Connection.XML_TAG.equals(tmpName)) { - if (reader.getAttrAsString("class", null) != null) { - com.fr.data.impl.Connection con = DataCoreXmlUtils.readXMLConnection(reader); - this.setDatabase(con); - } - } else if ("Query".equals(tmpName)) { - tmpVal = reader.getElementValue(); - if (isNotNullValue(tmpVal)) { - this.setQuery(tmpVal); - } - } - } - } - - @Override - public void writeXML(XMLPrintWriter writer) { - super.writeXML(writer); - GeneralXMLTools.writeXMLable(writer, dbIndex.get(), OrderValue.XML_TAG); - if (this.database.get() != null) { - DataCoreXmlUtils.writeXMLConnection(writer, this.database.get()); - } - writer.startTAG("Query").textNode(getQuery()).end(); - } - - private boolean isNotNullValue(String value) { - return value != null && !"null".equals(value); - } - - @Override - public Object clone() throws CloneNotSupportedException { - RedisTableData cloned = (RedisTableData) super.clone(); - cloned.database = (Conf) database.clone(); - cloned.query = (Conf) query.clone(); - cloned.dbIndex = (Conf) dbIndex.clone(); - return cloned; - } +package com.fr.plugin.db.redis.core; + +import com.fr.base.Parameter; +import com.fr.base.TableData; +import com.fr.base.TemplateUtils; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; +import com.fr.config.holder.factory.XmlHolders; +import com.fr.data.AbstractParameterTableData; +import com.fr.data.core.DataCoreXmlUtils; +import com.fr.data.impl.Connection; +import com.fr.data.impl.NameDatabaseConnection; +import com.fr.file.DatasourceManager; +import com.fr.general.data.DataModel; +import com.fr.general.xml.GeneralXMLTools; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.plugin.db.redis.core.order.OrderValue; +import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue; +import com.fr.record.analyzer.EnableMetrics; +import com.fr.script.Calculator; +import com.fr.stable.ArrayUtils; +import com.fr.stable.ParameterProvider; +import com.fr.stable.StringUtils; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; + +import java.util.HashMap; +import java.util.Map; + + +@EnableMetrics +public class RedisTableData extends AbstractParameterTableData { + + private static final long serialVersionUID = 7017455818551800001L; + private Conf database = Holders.obj(null, Connection.class); + private Conf dbIndex = XmlHolders.obj(new NumberOrderValue(0), OrderValue.class, OrderValue.XML_TAG); + private Conf query = Holders.simple(StringUtils.EMPTY); + private Conf script = Holders.simple(StringUtils.EMPTY); + + public void setDatabase(Connection c) { + this.database.set(c); + } + + public Connection getDatabase() { + return database.get(); + } + + public OrderValue getOrderValue() { + return dbIndex.get(); + } + + public void setOrderValue(OrderValue dbIndex) { + this.dbIndex.set(dbIndex); + } + + public String getQuery() { + return query.get(); + } + + public void setQuery(String query) { + this.query.set(query); + } + + public String getScript() { + return script.get(); + } + + public void setScript(String script) { + this.script.set(script); + } + + public void setParameters(ParameterProvider[] providers) { + super.setDefaultParameters(providers); + } + + @Override + public DataModel createDataModel(Calculator calculator) { + return createDataModel(calculator, TableData.RESULT_ALL); + } + + @Override + @Focus(id = RedisConstants.PLUGIN_ID, text = "Plugin-Redis_DB", source = Original.PLUGIN) + public DataModel createDataModel(Calculator calculator, int rowCount) { + Parameter[] ps = Parameter.providers2Parameter(getParameters(calculator)); + Connection connection = database.get(); + if (connection instanceof NameDatabaseConnection) { + String name = ((NameDatabaseConnection) connection).getName(); + RedisDatabaseConnection rc = DatasourceManager.getProviderInstance().getConnection(name, RedisDatabaseConnection.class); + if (rc != null) { + OrderValue orderValue = dbIndex.get(); + return new RedisTableDataModel(calculator, ps, rc, + orderValue == null ? 0 : orderValue.toIndex(calculator, ps), + calculateQuery(query.get(), ps), + calculateQuery(script.get(), ps), + rowCount); + } + } + return null; + } + + private String calculateQuery(String query, Parameter[] ps) { + if (ArrayUtils.isEmpty(ps)) { + return query; + } + Map map = new HashMap(); + for (Parameter p : ps) { + map.put(p.getName(), p.getValue()); + } + try { + return TemplateUtils.renderParameter4Tpl(query, map); + } catch (Exception e) { + return query; + } + } + + public void readXML(XMLableReader reader) { + super.readXML(reader); + + if (reader.isChildNode()) { + String tmpName = reader.getTagName(); + String tmpVal; + + if (OrderValue.XML_TAG.equals(tmpName)) { + OrderValue orderValue = (OrderValue) GeneralXMLTools.readXMLable(reader); + if (orderValue != null) { + setOrderValue(orderValue); + } + } else if (com.fr.data.impl.Connection.XML_TAG.equals(tmpName)) { + if (reader.getAttrAsString("class", null) != null) { + com.fr.data.impl.Connection con = DataCoreXmlUtils.readXMLConnection(reader); + this.setDatabase(con); + } + } else if ("Query".equals(tmpName)) { + tmpVal = reader.getElementValue(); + if (isNotNullValue(tmpVal)) { + this.setQuery(tmpVal); + } + } else if ("Script".equals(tmpName)) { + tmpVal = reader.getElementValue(); + if (isNotNullValue(tmpVal)) { + this.setScript(tmpVal); + } + } + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + super.writeXML(writer); + GeneralXMLTools.writeXMLable(writer, dbIndex.get(), OrderValue.XML_TAG); + if (this.database.get() != null) { + DataCoreXmlUtils.writeXMLConnection(writer, this.database.get()); + } + writer.startTAG("Query").textNode(getQuery()).end(); + writer.startTAG("Script").textNode(getScript()).end(); + } + + private boolean isNotNullValue(String value) { + return value != null && !"null".equals(value); + } + + @Override + public Object clone() throws CloneNotSupportedException { + RedisTableData cloned = (RedisTableData) super.clone(); + cloned.database = (Conf) database.clone(); + cloned.query = (Conf) query.clone(); + cloned.script = (Conf) script.clone(); + cloned.dbIndex = (Conf) dbIndex.clone(); + return cloned; + } } \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java b/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java index f5fd901..b49b49d 100755 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java @@ -20,16 +20,16 @@ public class RedisTableDataModel extends AbstractDataModel { private List> data; - public RedisTableDataModel(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, int rowCount) { + public RedisTableDataModel(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) { PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(RedisConstants.PLUGIN_ID); if (pluginLicense.isAvailable()) { - initRedisData(calculator, ps, mc, dbIndex, query, rowCount); + initRedisData(calculator, ps, mc, dbIndex, query, script, rowCount); } else { throw new RuntimeException("Redis Plugin License Expired!"); } } - private synchronized void initRedisData(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, int rowCount) { + private synchronized void initRedisData(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) { if (StringUtils.isEmpty(query)) { return; } @@ -40,6 +40,7 @@ public class RedisTableDataModel extends AbstractDataModel { } try { DataWrapper wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redisClient, query, rowCount); + wrapper.transform(script); data = wrapper.getData(); columnNames = wrapper.getColumnNames(); } catch (Exception e) { diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java b/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java index 41a6bce..911b9fd 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java @@ -27,7 +27,6 @@ public class VisitorFactory { visitors.add(new ZRangeVisitor()); visitors.add(new MGetVisitor()); visitors.add(new KeysVisitor()); - visitors.add(new SingleArrayVisitor()); } public static DataWrapper getKeyValueResult(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/SingleArrayVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/SingleArrayVisitor.java deleted file mode 100644 index c001ad1..0000000 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/SingleArrayVisitor.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.fr.plugin.db.redis.core.visit.impl; - -import com.fr.base.Parameter; -import com.fr.general.FRLogger; -import com.fr.plugin.db.redis.conf.ShellConfigManager; -import com.fr.plugin.db.redis.core.DataWrapper; -import com.fr.plugin.db.redis.core.visit.AbstractVisitor; -import com.fr.script.Calculator; -import com.fr.stable.ArrayUtils; -import com.fr.stable.StringUtils; -import redis.clients.jedis.Jedis; - -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -/** - * Created by richie on 2017/6/5. - */ -public class SingleArrayVisitor extends AbstractVisitor { - @Override - public List> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { - String[] arr = query.trim().split(TOKEN_SPACE); - if (ArrayUtils.getLength(arr) < 1) { - throw new IllegalArgumentException("Illegal query:" + query); - } - String shell = ShellConfigManager.getProviderInstance().getShellText(); - if (StringUtils.isNotEmpty(shell)) { - for (Parameter parameter : ps) { - shell += " " + parameter.getName() + " " + parameter.getValue(); - } - Process process = Runtime.getRuntime().exec(shell); - String statusText = getShellResult(process); - if (isSuccess(statusText)) { - return calculateData(client, arr[1]); - } - } - return null; - } - - @Override - public String keyWord() { - return "singlemaparray"; - } - - - private boolean isSuccess(String statusText) { - return "success".equals(statusText); - } - - // TODO:richie 只要实现这个方法就可以了,还要处理列名的时候,需要修改下面 buildData方法 - private List> calculateData(Jedis client, String key) { - String result = client.get(key); - return null; - } - - @Override - public DataWrapper buildData(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { - return super.buildData(calculator, ps, client, query, rowCount); - } - - private String getShellResult(Process process) { - String result = null; - try { - ByteArrayOutputStream resultOutStream = new ByteArrayOutputStream(); - InputStream errorInStream = new BufferedInputStream(process.getErrorStream()); - InputStream processInStream = new BufferedInputStream(process.getInputStream()); - int num = 0; - byte[] bs = new byte[1024]; - while ((num = errorInStream.read(bs)) != -1) { - resultOutStream.write(bs, 0, num); - } - while ((num = processInStream.read(bs)) != -1) { - resultOutStream.write(bs, 0, num); - } - result = new String(resultOutStream.toByteArray()); - errorInStream.close(); - processInStream.close(); - resultOutStream.close(); - } catch (IOException e) { - FRLogger.getLogger().error(e.getMessage(), e); - } finally { - if (process != null) { - process.destroy(); - } - } - return result; - } -} diff --git a/src/main/java/com/fr/plugin/db/redis/ui/RedisQueryPane.java b/src/main/java/com/fr/plugin/db/redis/ui/RedisQueryPane.java index 0e57229..f5447e0 100755 --- a/src/main/java/com/fr/plugin/db/redis/ui/RedisQueryPane.java +++ b/src/main/java/com/fr/plugin/db/redis/ui/RedisQueryPane.java @@ -7,18 +7,19 @@ import com.fr.design.dialog.BasicPane; import com.fr.design.editor.ValueEditorPane; import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextarea.DescriptionTextArea; +import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants; import com.fr.design.gui.syntax.ui.rtextarea.RTextScrollPane; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.FRLogger; -import com.fr.general.Inter; import com.fr.general.SiteCenter; import com.fr.log.FineLoggerFactory; import com.fr.plugin.db.redis.core.order.OrderValue; import com.fr.plugin.db.redis.ui.value.IndexValuePaneFactory; +import ij.gui.MultiLineLabel; import java.awt.*; import java.awt.event.ActionEvent; @@ -31,12 +32,15 @@ public class RedisQueryPane extends BasicPane { private SQLEditPane sqlTextPane; private ValueEditorPane dbIndexEditor; + private RSyntaxTextArea scriptTextPane; public RedisQueryPane() { setLayout(new BorderLayout()); sqlTextPane = new SQLEditPane(); + scriptTextPane = new RSyntaxTextArea(); + dbIndexEditor = IndexValuePaneFactory.createValueEditorPane(); ActionLabel helpLabel = new ActionLabel(Toolkit.i18nText("Plugin-Redis_Help")); @@ -51,25 +55,40 @@ public class RedisQueryPane extends BasicPane { } }); + DescriptionTextArea descriptionArea = new DescriptionTextArea(); + descriptionArea.setWrapStyleWord(true); + descriptionArea.setLineWrap(true); + + descriptionArea.setText(Toolkit.i18nText("Plugin-Redis_Script_Text_Description")); + Component[][] coms = new Component[][]{ {new UILabel(Toolkit.i18nText("Plugin-Redis_DB_Index") + ":"), dbIndexEditor}, - {GUICoreUtils.createBorderLayoutPane(new UILabel(Toolkit.i18nText("Plugin-Redis_Query_Condition") + ":"), BorderLayout.NORTH), createConditionTextPane(sqlTextPane)} + {GUICoreUtils.createBorderLayoutPane(new UILabel(Toolkit.i18nText("Plugin-Redis_Query_Condition") + ":"), BorderLayout.NORTH), createConditionTextPane(sqlTextPane, SyntaxConstants.SYNTAX_STYLE_SQL, 50)}, + {GUICoreUtils.createBorderLayoutPane( + new UILabel(Toolkit.i18nText("Plugin-Redis_Script_Text") + ":"), BorderLayout.NORTH), + GUICoreUtils.createBorderLayoutPane( + createConditionTextPane(scriptTextPane, SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, 200), BorderLayout.CENTER, + descriptionArea, BorderLayout.SOUTH + ), + + }, }; double p = TableLayout.PREFERRED; double f = TableLayout.FILL; - double[] rowSize = {p, p}; + double[] rowSize = {p, p, p}; double[] columnSize = {p, f}; add(TableLayoutHelper.createTableLayoutPane(coms, rowSize, columnSize)); } - private RTextScrollPane createConditionTextPane(SQLEditPane sqlTextPane) { - sqlTextPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL); - RTextScrollPane sqlTextScrollPane = new RTextScrollPane(sqlTextPane); + private RTextScrollPane createConditionTextPane(RSyntaxTextArea editorPane, String type, int height) { + editorPane.setSyntaxEditingStyle(type); + RTextScrollPane sqlTextScrollPane = new RTextScrollPane(editorPane); sqlTextScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); - sqlTextScrollPane.setPreferredSize(new Dimension(680, 300)); + sqlTextScrollPane.setPreferredSize(new Dimension(680, height)); + sqlTextScrollPane.setLineNumbersEnabled(false); return sqlTextScrollPane; } @@ -93,4 +112,12 @@ public class RedisQueryPane extends BasicPane { public void setOrderValue(OrderValue orderValue) { dbIndexEditor.populate(orderValue); } + + public String getScript() { + return scriptTextPane.getText(); + } + + public void setScript(String script) { + scriptTextPane.setText(script); + } } \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/ui/RedisTableDataPane.java b/src/main/java/com/fr/plugin/db/redis/ui/RedisTableDataPane.java index 4490af6..0efb4d8 100755 --- a/src/main/java/com/fr/plugin/db/redis/ui/RedisTableDataPane.java +++ b/src/main/java/com/fr/plugin/db/redis/ui/RedisTableDataPane.java @@ -100,7 +100,7 @@ public class RedisTableDataPane extends AbstractTableDataPane { } private void refresh() { - String[] paramTexts = new String[]{queryPane.getQuery()}; + String[] paramTexts = new String[]{queryPane.getQuery(), queryPane.getScript()}; ParameterProvider[] parameters = ParameterHelper.analyze4Parameters(paramTexts, false); @@ -111,7 +111,7 @@ public class RedisTableDataPane extends AbstractTableDataPane { private void checkParameter() { - String[] paramTexts = new String[]{queryPane.getQuery()}; + String[] paramTexts = new String[]{queryPane.getQuery(), queryPane.getScript()}; ParameterProvider[] parameters = ParameterHelper.analyze4Parameters(paramTexts, false); parameters = ArrayUtils.addAll(parameters, queryPane.getOrderValue().analyze4Parameters()); @@ -149,6 +149,8 @@ public class RedisTableDataPane extends AbstractTableDataPane { queryPane.setQuery(tableData.getQuery()); + queryPane.setScript(tableData.getScript()); + queryPane.setOrderValue(tableData.getOrderValue()); } @@ -169,6 +171,8 @@ public class RedisTableDataPane extends AbstractTableDataPane { tableData.setQuery(queryPane.getQuery()); + tableData.setScript(queryPane.getScript()); + tableData.setOrderValue(queryPane.getOrderValue()); return tableData; diff --git a/src/main/resources/com/fr/plugin/db/redis/locale/redis.properties b/src/main/resources/com/fr/plugin/db/redis/locale/redis.properties index 4bbe711..1cb8a8f 100755 --- a/src/main/resources/com/fr/plugin/db/redis/locale/redis.properties +++ b/src/main/resources/com/fr/plugin/db/redis/locale/redis.properties @@ -13,4 +13,6 @@ Plugin-Redis_Refresh=Refresh Plugin-Redis_Formula=Formula Plugin-Redis_Query=Query Plugin-Redis_Connection_Successfully=Connection Successfully -Plugin-Redis_Connection_Failed=Connection Failed \ No newline at end of file +Plugin-Redis_Connection_Failed=Connection Failed +Plugin-Redis_Script_Text=Transform Script +Plugin-Redis_Script_Text_Description=Script Description diff --git a/src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties b/src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties index 43a37b9..eb350d7 100755 --- a/src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties +++ b/src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties @@ -7,4 +7,12 @@ Plugin-Redis_DB=RedisDB Plugin-Redis_Help=Help Doc Plugin-Redis_Keys_Pattern=Keys Pattern Plugin-Redis_Keys_Pattern_Search=Search -Plugin-Redis_DB_Index=DB Index \ No newline at end of file +Plugin-Redis_DB_Index=DB Index +Plugin-Redis_Preview=Preview +Plugin-Redis_Refresh=Refresh +Plugin-Redis_Formula=Formula +Plugin-Redis_Query=Query +Plugin-Redis_Connection_Successfully=Connection Successfully +Plugin-Redis_Connection_Failed=Connection Failed +Plugin-Redis_Script_Text=Transform Script +Plugin-Redis_Script_Text_Description=Script Description diff --git a/src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties b/src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties index dfcd6dd..8f4ca08 100755 --- a/src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties +++ b/src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties @@ -8,4 +8,12 @@ Plugin-Redis_Help=\u5E2E\u52A9\u6587\u6863 Plugin-Redis_Keys_Pattern=\u952E\u503C\u7684\u6B63\u5219\u8868\u8FBE\u5F0F Plugin-Redis_Keys_Pattern_Search=\u641C\u7D22 Plugin-Redis_DB_Index=\u6570\u636E\u5E93\u7F16\u53F7 -Plugin-Redis_Preview=\u9884\u89C8 \ No newline at end of file +Plugin-Redis_Preview=\u9884\u89C8 +Plugin-Redis_Refresh=\u5237\u65B0 +Plugin-Redis_Formula=\u516C\u5F0F +Plugin-Redis_Query=\u67E5\u8BE2 +Plugin-Redis_Connection_Successfully=\u8FDE\u63A5\u6210\u529F +Plugin-Redis_Connection_Failed=\u8FDE\u63A5\u5931\u8D25 +Plugin-Redis_Script_Text=\u8F6C\u6362\u811A\u672C +Plugin-Redis_Script_Text_Description=\u53EF\u4EE5\u4F7F\u7528JavaScript\u811A\u672C\u6765\u8F6C\u6362\u67E5\u8BE2\u7ED3\u679C\u3002\n\u6CE8\u610F1\uFF1A\u5185\u7F6E\u53C2\u6570$content\u548C$column\uFF0C\u5206\u522B\u8868\u793A\u539F\u59CB\u7684\u6570\u636E\u96C6\u5185\u5BB9\uFF08\u4E8C\u7EF4\u6570\u7EC4\uFF09\u548C\u6570\u636E\u96C6\u7684\u5217\u540D\uFF08\u4E00\u7EF4\u6570\u7EC4\uFF09\u3002\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u4E8C\u7EF4\u6570\u7EC4\uFF0C\u8868\u793A\u4EC5\u4FEE\u6539\u6570\u636E\u96C6\u5185\u5BB9\uFF0C\u4E0D\u4FEE\u6539\u6570\u636E\u96C6\u7684\u5217\u540D\uFF1B\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u5982\u4E0B\u683C\u5F0F\u7684\u5BF9\u8C61:\ +{content:[][],column:[]}\uFF0C\u8868\u793A\u540C\u65F6\u4FEE\u6539\u4E86\u6570\u636E\u96C6\u7684\u5185\u5BB9\u548C\u5217\u540D\u3002\n\u6CE8\u610F2\uFF1A\u5982\u679C\u5E0C\u671B\u5F15\u7528\u5916\u90E8JS\uFF0C\u53EF\u4EE5\u5728\u811A\u672C\u6846\u4E2D\u5199\u5165file:///$ENV_HOME/transform.js\uFF0C\u5176\u4E2D$ENV_HOME\u8868\u793A\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u3002 \ No newline at end of file