@ -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 < String , Integer > 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 " ) ;
}
}