From 859d2667a378654002106f922b742530b3ccd874 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Mon, 5 Jul 2021 10:51:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-52847=20=E3=80=9010.0.18=E3=80=91?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81fetchsize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datapane/connect/DBCPAttrPane.java | 138 +++++++++++++++++- .../connect/DatabaseConnectionPane.java | 5 +- .../datapane/connect/JDBCConnectionDef.java | 43 ++++++ .../data/datapane/connect/JDBCDefPane.java | 2 + 4 files changed, 177 insertions(+), 11 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCConnectionDef.java diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java index 01af97293..58a021812 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java @@ -1,8 +1,9 @@ package com.fr.design.data.datapane.connect; +import com.fr.base.GraphHelper; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.pool.DBCPConnectionPoolAttr; -import com.fr.design.constants.UIConstants; +import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; import com.fr.design.editor.editor.IntegerEditor; import com.fr.design.gui.icombobox.UIComboBox; @@ -12,14 +13,35 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; -import java.awt.BorderLayout; -import java.awt.Component; -import javax.swing.BorderFactory; +import com.fr.general.ComparatorUtils; +import com.fr.stable.StringUtils; + import javax.swing.JPanel; +import javax.swing.JTextField; import javax.swing.SwingConstants; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Window; +import java.awt.event.InputMethodEvent; +import java.awt.event.InputMethodListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class DBCPAttrPane extends BasicPane { public static final int TIME_MULTIPLE = 1000; + private static final Pattern FETCHSIZE_PATTERN = Pattern.compile("^0$|^[1-9][\\d]*[\\d]*$");; + private static final Pattern CHAR_NEED_ESCAPE = Pattern.compile("[?|$^*\\\\\\[\\](){}.+]"); + private static final int MAX_FETCHSIZE = 1000000; + private static final Map DEFAULT_FETCHSIZE_MAP = new HashMap<>(); + private static final int ORACLE_DEFAULT_FETCHSIZE = 128; + private static final int DB2_DEFAULT_FETCHSIZE = 50; + private static final int POSTGRE_DEFAULT_FETCHSIZE = 10000; // carl:DBCP的一些属性 private IntegerEditor DBCP_INITIAL_SIZE = new IntegerEditor(); private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor(); @@ -36,11 +58,24 @@ public class DBCPAttrPane extends BasicPane { private IntegerEditor DBCP_NUMTESTSPEREVICTIONRUN = new IntegerEditor(); private IntegerEditor DBCP_MINEVICTABLEIDLETIMEMILLIS = new IntegerEditor(); + private UITextField FETCHSIZE = new UITextField(); + + private JPanel defaultPane; + private JPanel northFlowPane; + private JPanel southFlowPane; + + static { + DEFAULT_FETCHSIZE_MAP.put("Oracle", ORACLE_DEFAULT_FETCHSIZE); + DEFAULT_FETCHSIZE_MAP.put("DB2", DB2_DEFAULT_FETCHSIZE); + DEFAULT_FETCHSIZE_MAP.put("Postgre", POSTGRE_DEFAULT_FETCHSIZE); + } + public DBCPAttrPane() { - JPanel defaultPane = this; + defaultPane = this; // JPanel northFlowPane - JPanel northFlowPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); + northFlowPane = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr")); + northFlowPane.setPreferredSize(new Dimension(630, 320)); defaultPane.add(northFlowPane, BorderLayout.NORTH); DBCP_VALIDATION_QUERY.setColumns(15); @@ -67,7 +102,6 @@ public class DBCPAttrPane extends BasicPane { DBCP_MINEVICTABLEIDLETIMEMILLIS}}; JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 4); - contextPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, UIConstants.LINE_COLOR)); northFlowPane.add(contextPane); } @@ -89,6 +123,10 @@ public class DBCPAttrPane extends BasicPane { this.DBCP_MINEVICTABLEIDLETIMEMILLIS.setValue(dbcpAttr.getMinEvictableIdleTimeMillis() / TIME_MULTIPLE); this.DBCP_NUMTESTSPEREVICTIONRUN.setValue(dbcpAttr.getNumTestsPerEvictionRun()); this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.setValue(dbcpAttr.getTimeBetweenEvictionRunsMillis()); + Integer fetchSize = DEFAULT_FETCHSIZE_MAP.get(JDBCConnectionDef.getInstance().getDatabaseName()); + if (fetchSize != null) { + this.FETCHSIZE.setText(jdbcDatabase.getFetchSize() == -1 ? String.valueOf(fetchSize) : String.valueOf(jdbcDatabase.getFetchSize())); + } } public void update(JDBCDatabaseConnection jdbcDatabase) { @@ -109,10 +147,94 @@ public class DBCPAttrPane extends BasicPane { dbcpAttr.setMinEvictableIdleTimeMillis(((Number) this.DBCP_MINEVICTABLEIDLETIMEMILLIS.getValue()).intValue() * TIME_MULTIPLE); dbcpAttr.setNumTestsPerEvictionRun(((Number) this.DBCP_NUMTESTSPEREVICTIONRUN.getValue()).intValue()); dbcpAttr.setTimeBetweenEvictionRunsMillis(((Number) this.DBCP_TIMEBETWEENEVICTIONRUNSMILLS.getValue()).intValue()); + Integer fetchSize = DEFAULT_FETCHSIZE_MAP.get(JDBCConnectionDef.getInstance().getDatabaseName()); + if (fetchSize != null) { + jdbcDatabase.setFetchSize(Integer.parseInt(this.FETCHSIZE.getText())); + } + } + + @Override + public BasicDialog showWindow(Window window) { + String databaseName = JDBCConnectionDef.getInstance().getDatabaseName(); + if (showOtherConfig(databaseName)) { + southFlowPane = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Report_Other")); + southFlowPane.setPreferredSize(new Dimension(630, 200)); + double f = TableLayout.FILL; + double[] rowSize = {f}; + double otherColumnSize = GraphHelper.getWidth(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Evictionruns_millis")) + 6; + double[] columnSize = {otherColumnSize, otherColumnSize}; + FETCHSIZE.addKeyListener(fetchSizeKeyListener); + FETCHSIZE.addInputMethodListener(fetchSizeInputMethodListener); + FETCHSIZE.setHorizontalAlignment(JTextField.RIGHT); + Component[][] comps = { + {new UILabel("Fetchsize:", SwingConstants.RIGHT), FETCHSIZE} + }; + JPanel otherConfigPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 4); + southFlowPane.add(otherConfigPane); + + defaultPane.removeAll(); + defaultPane.add(northFlowPane, BorderLayout.NORTH); + defaultPane.add(southFlowPane, BorderLayout.SOUTH); + } else { + if (southFlowPane != null) { + defaultPane.remove(southFlowPane); + } + } + return this.showWindow(window, null); + } + + private boolean showOtherConfig(Object dbType) { + return ComparatorUtils.equals(dbType, "Oracle") || ComparatorUtils.equals(dbType, "DB2") || ComparatorUtils.equals(dbType, "Postgre"); + } + + KeyListener fetchSizeKeyListener = new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + String fetchSize = FETCHSIZE.getText(); + if (!isFetchSizeValid(fetchSize)) { + FETCHSIZE.setText(fetchSize.replaceAll(getCharNeedReplace(e.getKeyChar()), "")); + if (!isFetchSizeValid(FETCHSIZE.getText())) { + FETCHSIZE.setText(StringUtils.EMPTY); + } + } else if (FETCHSIZE.getText().length() > String.valueOf(MAX_FETCHSIZE).length() || Long.parseLong(FETCHSIZE.getText()) > MAX_FETCHSIZE) { + FETCHSIZE.setText(String.valueOf(MAX_FETCHSIZE)); + } + } + }; + + InputMethodListener fetchSizeInputMethodListener = new InputMethodListener() { + @Override + public void inputMethodTextChanged(InputMethodEvent event) { + if (null == event.getText()) { + return; + } + char ch = event.getText().current(); + if (!(ch >= '0' && ch <= '9')) { + event.consume(); + } + } + + @Override + public void caretPositionChanged(InputMethodEvent event) { + + } + }; + + private boolean isFetchSizeValid(String fetchSize) { + return FETCHSIZE_PATTERN.matcher(fetchSize).find(); + } + + private String getCharNeedReplace(char c) { + String charNeedReplace = c + ""; + Matcher matcher = CHAR_NEED_ESCAPE.matcher(charNeedReplace); + if (matcher.find()) { + charNeedReplace = "\\" + charNeedReplace; + } + return charNeedReplace; } @Override protected String title4PopupWindow() { - return Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr"); + return Toolkit.i18nText("Fine-Design_Basic_Advanced_Setup"); } } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java index f3a97ffb1..e55aaa2dd 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java @@ -12,7 +12,6 @@ import com.fr.data.solution.entity.DriverPage; import com.fr.data.solution.processor.ClassNotFoundExceptionSolutionProcessor; import com.fr.data.solution.processor.SolutionProcessor; import com.fr.design.beans.BasicBeanPane; -import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.ActionLabel; @@ -338,7 +337,7 @@ public abstract class DatabaseConnectionPane Date: Mon, 5 Jul 2021 17:41:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-52847=20=E3=80=9010.0.18=E3=80=91?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81fetchsize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/data/datapane/connect/JDBCConnectionDef.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCConnectionDef.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCConnectionDef.java index 1410decee..6d15b23e9 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCConnectionDef.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCConnectionDef.java @@ -24,6 +24,10 @@ public class JDBCConnectionDef { return instance; } + private JDBCConnectionDef() { + + } + public String getDatabaseName() { return databaseName; }