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 86e7633be0..6c8e194617 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,6 +1,7 @@ package com.fr.design.data.datapane.connect; import com.fr.base.GraphHelper; +import com.fr.data.core.db.dialect.DialectFactory; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.pool.DBCPConnectionPoolAttr; import com.fr.design.dialog.BasicDialog; @@ -31,6 +32,7 @@ import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -43,7 +45,6 @@ public class DBCPAttrPane extends BasicPane { private static final int ORACLE_DEFAULT_FETCHSIZE = 128; private static final int DB2_DEFAULT_FETCHSIZE = 50; private static final int POSTGRE_DEFAULT_FETCHSIZE = 10000; - private static final int EMPTY_FETCHSIZE = -2; // carl:DBCP的一些属性 private IntegerEditor DBCP_INITIAL_SIZE = new IntegerEditor(); private IntegerEditor DBCP_MIN_IDLE = new IntegerEditor(); @@ -114,12 +115,25 @@ 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) { - if (jdbcDatabase.getFetchSize() == EMPTY_FETCHSIZE) { - this.FETCHSIZE.setText(StringUtils.EMPTY); + + /* + * 填充FetchSize输入框逻辑: + * + * 1. 如果JDBCDatabaseConnection里的fetchSize是有效值(>0),则显示该有效值 + * 2. 如果JDBCDatabaseConnection里的fetchSize是无效值(<=0): + * 2.1 如果我们对这种数据库有默认值(如oracle、db2、pgsql),就显示对应数据库的默认值,因为要避免性能问题,这几种数据库不支持关闭fetchSize + * 2.2 如果我们对这种数据库无默认值,就显示-1 + */ + + int fetchSize = jdbcDatabase.getFetchSize(); + String databaseName = JDBCConnectionDef.getInstance().getDatabaseName(); + if (DialectFactory.isValidFetchSize(fetchSize)) { + this.FETCHSIZE.setText(String.valueOf(fetchSize)); + } else { + if (DEFAULT_FETCHSIZE_MAP.containsKey(databaseName)) { + this.FETCHSIZE.setText(String.valueOf(DEFAULT_FETCHSIZE_MAP.get(databaseName))); } else { - this.FETCHSIZE.setText(jdbcDatabase.getFetchSize() == -1 ? String.valueOf(fetchSize) : String.valueOf(jdbcDatabase.getFetchSize())); + this.FETCHSIZE.setText(String.valueOf(-1)); } } } @@ -137,12 +151,34 @@ 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) { - if (StringUtils.isEmpty(this.FETCHSIZE.getText())) { - jdbcDatabase.setFetchSize(EMPTY_FETCHSIZE); + + /* + * FetchSize设置逻辑: + * + * 1. 如果客户界面上的fetchSize框留空: + * 1.1 如果我们对这种数据库有默认值(如oracle、db2、pgsql),就存对应数据库的默认值,否则会有性能问题,这几种数据库我们是不支持关闭fetchSize的 + * 1.2 如果我们对这种数据库没有默认值,就置为-1 + * 2. 如果客户界面上的fetchSize框非空: + * 2.1 如果fetchSize是个有效值(>0),就使用该值 + * 2.2 如果fetchSize是个无效值(<=0),就置为-1 + * + * -1带来的结果,就是我们Dialect不会putExecutor,最终不会执行java.sql.Statement.setFetchSize + */ + String fetchSizeText = this.FETCHSIZE.getText(); + String databaseName = JDBCConnectionDef.getInstance().getDatabaseName(); + + if (StringUtils.isEmpty(fetchSizeText)) { + if (DEFAULT_FETCHSIZE_MAP.containsKey(databaseName)) { + Optional.ofNullable(DEFAULT_FETCHSIZE_MAP.get(databaseName)).ifPresent(jdbcDatabase::setFetchSize); + } else { + jdbcDatabase.setFetchSize(-1); + } + } else { + int fetchSizeSet = Integer.parseInt(fetchSizeText); + if (DialectFactory.isValidFetchSize(fetchSizeSet)) { + jdbcDatabase.setFetchSize(fetchSizeSet); } else { - jdbcDatabase.setFetchSize(Integer.parseInt(this.FETCHSIZE.getText())); + jdbcDatabase.setFetchSize(-1); } } }