@ -7,6 +7,7 @@ import com.fr.data.driver.DriverLoader;
import com.fr.data.driver.config.DriverLoaderConfig ;
import com.fr.data.impl.JDBCDatabaseConnection ;
import com.fr.data.solution.entity.DriverClasses ;
import com.fr.datasource.connection.impl.DefaultDatabaseType ;
import com.fr.design.constants.LayoutConstants ;
import com.fr.design.gui.core.ReactiveCardPane ;
import com.fr.design.gui.ibutton.UIButton ;
@ -22,6 +23,7 @@ import com.fr.design.utils.BrowseUtils;
import com.fr.file.filter.ChooseFileFilter ;
import com.fr.general.CloudCenter ;
import com.fr.general.ComparatorUtils ;
import com.fr.general.GeneralUtils ;
import com.fr.log.FineLoggerFactory ;
import com.fr.stable.ArrayUtils ;
import com.fr.stable.EncodeConstants ;
@ -62,6 +64,16 @@ public class JDBCDefPane extends JPanel {
public static final String DRIVER_TYPE = "driver_type" ;
public static final String USER_NAME = "user_name" ;
private static final String OTHER_DB = "Others" ;
public static final String ORACLE = "Oracle" ;
public static final String DB2 = "DB2" ;
public static final String SQL_SERVER = "SQL Server" ;
public static final String MYSQL = "MySQL" ;
public static final String SYBASE = "Sybase" ;
public static final String ACCESS = "Access" ;
public static final String DERBY = "Derby" ;
public static final String POSTGRE = "Postgre" ;
public static final String SQLITE = "SQLite" ;
public static final String INCEPTOR = "Inceptor" ;
private static final Pattern ORACLE_URL = Pattern . compile ( "^jdbc:oracle:thin:@[/]*([-0-9a-zA-Z_\\.\\\\]+)(:([0-9]+|port))?([:/](.*))?.*" , Pattern . CASE_INSENSITIVE ) ;
private static final Pattern GENERAL_URL = Pattern . compile ( "^jdbc:(mysql|sqlserver|db2|derby|postgresql|inceptor|inceptor2|hive2)://([-0-9a-zA-Z_\\.\\\\]+)(:([0-9]+|port))?((/|;DatabaseName=)(.*))?.*" , Pattern . CASE_INSENSITIVE ) ;
private static final Pattern PORT = Pattern . compile ( "^0$|^[1-9][\\d]*[\\d]*$" ) ;
@ -69,9 +81,22 @@ public class JDBCDefPane extends JPanel {
// 编码转换.
private String originalCharSet = null ;
private static Map < String , DriverURLName [ ] > jdbcMap = new HashMap < String , DriverURLName [ ] > ( ) ;
// 用于映射connection的database字段
private static Map < String , String > dbTypeMap = new HashMap < > ( ) ;
private JPanel linkPanel ;
static {
dbTypeMap . put ( ORACLE , DefaultDatabaseType . ORACLE . getType ( ) ) ;
dbTypeMap . put ( DB2 , DefaultDatabaseType . IBM_DB2 . getType ( ) ) ;
dbTypeMap . put ( SQL_SERVER , DefaultDatabaseType . MICROSOFT_SQL_SERVER . getType ( ) ) ;
dbTypeMap . put ( MYSQL , DefaultDatabaseType . MYSQL . getType ( ) ) ;
dbTypeMap . put ( SYBASE , DefaultDatabaseType . SAP_ASE . getType ( ) ) ;
dbTypeMap . put ( ACCESS , DefaultDatabaseType . OTHER . getType ( ) ) ;
dbTypeMap . put ( DERBY , DefaultDatabaseType . DERBY . getType ( ) ) ;
dbTypeMap . put ( POSTGRE , DefaultDatabaseType . POSTGRESQL . getType ( ) ) ;
dbTypeMap . put ( SQLITE , DefaultDatabaseType . SQLITE . getType ( ) ) ;
dbTypeMap . put ( INCEPTOR , DefaultDatabaseType . TRANSWARP_INCEPTOR . getType ( ) ) ;
jdbcMap . put ( OTHER_DB , new DriverURLName [ ] { new DriverURLName ( "sun.jdbc.odbc.JdbcOdbcDriver" , "jdbc:odbc:" ) ,
new DriverURLName ( "org.hsqldb.jdbcDriver" , "jdbc:hsqldb:file:[PATH_TO_DB_FILES]" ) , new DriverURLName ( "com.inet.tds.TdsDriver" , "jdbc:inetdae7:localhost:1433/" ) ,
new DriverURLName ( "COM.cloudscape.JDBCDriver" , "jdbc:cloudscape:/cloudscape/" ) ,
@ -106,7 +131,7 @@ public class JDBCDefPane extends JPanel {
private ReactiveCardPane centerPanel ;
private ReactiveCardPane driverSelectRow ;
// 请不要改动dbtype,只应该最后添加
private final String [ ] dbtype = { "Oracle" , "DB2" , "SQL Server" , "MySQL" , "Sybase" , "Access" , "Derby" , "Postgre" , "SQLite" , "Inceptor" , OTHER_DB } ;
private final String [ ] dbtype = { ORACLE , DB2 , SQL_SERVER , MYSQL , SYBASE , ACCESS , DERBY , POSTGRE , SQLITE , INCEPTOR , OTHER_DB } ;
private JDBCDatabaseConnection jdbcDatabase ;
@ -153,6 +178,7 @@ public class JDBCDefPane extends JPanel {
if ( needRefresh ) {
jdbcDatabase . setDatabase ( StringUtils . EMPTY ) ;
}
jdbcDatabase . setDatabase ( dbTypeMap . getOrDefault ( GeneralUtils . objectToString ( dbtypeComboBox . getSelectedItem ( ) ) , DefaultDatabaseType . OTHER . getType ( ) ) ) ;
changePane ( dbtypeComboBox . getSelectedItem ( ) ) ;
JDBCConnectionDef . getInstance ( ) . setConnection ( ( String ) dbtypeComboBox . getSelectedItem ( ) , jdbcDatabase ) ;
DatabaseConnectionPane . JDBC . getAdvancedAttrPane ( ) . populate ( jdbcDatabase ) ;