import { shortcut } from '@core/core';
import { Vertical, TextEditor, TextValueCombo, Label, TextAreaEditor, Editor, EdirotIconCheckCombo, Left, TextButton, Layout } from 'ui';
import { CollapseXtype, EVENT_CHANGE } from 'src/modules/components/collapse/collapse';
import { FormItemXtype } from '../../components/form_item/form_item';
import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud/crud.typings';
import { connectionType } from '@constants/env';
import { CONNECT_CHARSET, CONNECTION_LAYOUT } from '@constants/constant';
import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service';
import { TextCheckerXtype } from '../../../../components/text_checker/text_checker';
export const FormJdbcXtype = 'dec.dcm.maintain.form.jdbc';
@shortcut(FormJdbcXtype)
export class FormJdbc extends BI.Widget {
    props = {
        formData: {} as Connection,
    }

    oldPassword = '';
    allDatabaseTypes = getAllDatabaseTypes();

    testStatus: any;
    advancedSet: any;
    formUser: any;
    formPassword: any;
    formPrincipal: any;
    formKeyPath: any;
    labelTips: any;

    form = {
        connectionName: null,
        driver: null,
        database: null,
        host: null,
        port: null,
        user: null,
        password: null,
        authType: null,
        principal: null,
        keyPath: null,
        originalCharsetName: null,
        schema: null,
        url: null,
        initialSize: null,
        maxActive: null,
        maxIdle: null,
        maxWait: null,
        validationQuery: null,
        testOnBorrow: null,
        testOnReturn: null,
        testWhileIdle: null,
        timeBetweenEvictionRunsMillis: null,
        numTestsPerEvictionRun: null,
        minIdle: null,
        minEvictableIdleTimeMillis: null,
    };

    render() {
        const { connectionName, connectionData } = this.options.formData;
        const { driver, user, password, originalCharsetName, schema, url, connectionPoolAttr, database, authType, principal, keyPath } = connectionData as ConnectionJDBC;
        const { initialSize, maxActive, maxIdle, maxWait, validationQuery, testOnBorrow, testOnReturn, testWhileIdle, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minIdle, minEvictableIdleTimeMillis } = connectionPoolAttr as ConnectionPoolJDBC;
        const databaseType = getJdbcDatabaseType(database, driver);
        this.oldPassword = password;
        const { host, port, databaseName } = resolveUrlInfo(url);
        const { hgap, vgap } = CONNECTION_LAYOUT;
        
        return {
            type: Vertical,
            hgap,
            vgap,
            items: [
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Name'),
                    forms: [{
                        type: TextCheckerXtype,
                        width: 300,
                        value: connectionName,
                        allowBlank: true,
                        ref: (_ref: any) => {
                            this.form.connectionName = _ref;
                        },
                        watermark: BI.i18nText('Dec-Dcm_Data_Connections'),
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
                    forms: [{
                        type: EdirotIconCheckCombo,
                        width: 300,
                        value: driver,
                        ref: (_ref: any) => {
                            this.form.driver = _ref;
                        },
                        items: this.getDrivers(),
                        listeners: [{
                            eventName: BI.EditorIconCheckCombo.EVENT_CHANGE,
                            action: () => {
                                const value = this.form.driver.getValue();
                                const connectionData = this.options.formData.connectionData as ConnectionJDBC;
                                const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
                                const url = connectionType.urls ? connectionType.urls[value] : connectionType.url;
                                this.form.url.setValue(url);
                                const urlInfo = resolveUrlInfo(url);
                                this.form.host.setValue(urlInfo.host);
                                this.form.database.setValue(urlInfo.databaseName);
                                this.form.port.setValue(urlInfo.port);
                            },
                        }],
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
                    forms: [{
                        type: TextEditor,
                        width: 300,
                        allowBlank: true,
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
                        value: databaseName,
                        ref: (_ref: any) => {
                            this.form.database = _ref;
                        },
                        listeners: [{
                            eventName: BI.Editor.EVENT_CHANGE,
                            action: () => {
                                this.onHostPortChange(databaseType);
                            },
                        }],
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
                    forms: [{
                        type: TextEditor,
                        width: 300,
                        allowBlank: true,
                        value: host,
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
                        ref: (_ref: any) => {
                            this.form.host = _ref;
                        },
                        listeners: [{
                            eventName: BI.Editor.EVENT_CHANGE,
                            action: () => {
                                this.onHostPortChange(databaseType);
                            },
                        }],
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
                    forms: [{
                        type: TextCheckerXtype,
                        width: 300,
                        allowBlank: true,
                        value: port,
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
                        validationChecker: [{
                            errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                            checker: (value: string) => this.checkInteger(value),
                            autoFix: true,
                        }],
                        ref: (_ref: any) => {
                            this.form.port = _ref;
                        },
                        listeners: [{
                            eventName: BI.Editor.EVENT_CHANGE,
                            action: () => {
                                this.onHostPortChange(databaseType);
                            },
                        }],
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_AuthType'),
                    invisible: !databaseType.kerberos,
                    forms: [{
                        type: TextValueCombo,
                        width: 300,
                        value: authType,
                        ref: (_ref: any) => {
                            this.form.authType = _ref;
                        },
                        items: [
                            {
                                text: BI.i18nText('Dec-Dcm_Connection_Form_UserName_Password'),
                                value: '',
                            },
                            {
                                text: 'Kerberos',
                                value: 'kerberos',
                            },
                        ],
                        listeners: [
                            {
                                eventName: BI.Combo.EVENT_CHANGE,
                                action: () => {
                                    const type = this.form.authType.getValue()[0];
                                    this.formPrincipal.setVisible(!!type);
                                    this.formKeyPath.setVisible(!!type);
                                    this.formUser.setVisible(!type);
                                    this.formPassword.setVisible(!type);
                                    this.labelTips.setVisible(!!type);
                                },
                            },
                        ],
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
                    invisible: !!authType,
                    ref: (_ref: any) => {
                        this.formUser = _ref;
                    },
                    forms: [{
                        type: TextEditor,
                        width: 300,
                        allowBlank: true,
                        value: user,
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
                        ref: (_ref: any) => {
                            this.form.user = _ref;
                        },
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
                    invisible: !!authType,
                    ref: (_ref: any) => {
                        this.formPassword = _ref;
                    },
                    forms: [{
                        type: Editor,
                        cls: 'bi-border bi-border-radius',
                        width: 300,
                        height: 20,
                        allowBlank: true,
                        value: password,
                        inputType: 'password',
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
                        ref: (_ref: any) => {
                            this.form.password = _ref;
                        },
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Principal'),
                    invisible: !authType,
                    ref: (_ref: any) => {
                        this.formPrincipal = _ref;
                    },
                    forms: [{
                        type: TextEditor,
                        width: 300,
                        allowBlank: true,
                        value: principal,
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_Principal'),
                        ref: (_ref: any) => {
                            this.form.principal = _ref;
                        },
                    }],
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
                    invisible: !authType,
                    ref: (_ref: any) => {
                        this.formKeyPath = _ref;
                    },
                    forms: [{
                        type: Editor,
                        cls: 'bi-border',
                        width: 300,
                        height: 20,
                        allowBlank: true,
                        value: keyPath,
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
                        ref: (_ref: any) => {
                            this.form.keyPath = _ref;
                        },
                    }],
                },
                {
                    type: Label,
                    cls: 'bi-tips',
                    textAlign: 'left',
                    invisible: true,
                    text: BI.i18nText('Dec-Dcm_Connection_JDBC_Warning'),
                    ref: (_ref: any) => {
                        this.labelTips = _ref;
                    },
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
                    forms: [{
                        type: TextValueCombo,
                        width: 300,
                        value: originalCharsetName ? originalCharsetName : '',
                        items: CONNECT_CHARSET,
                        ref: (_ref: any) => {
                            this.form.originalCharsetName = _ref;
                        },
                    }],
                },
                {
                    type: FormItemXtype,
                    invisible: !databaseType.hasSchema,
                    height: 64,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'),
                    forms: [{
                        type: Vertical,
                        items: [{
                            type: Left,
                            items: [{
                                type: TextButton,
                                cls: 'bi-high-light',
                                text: BI.i18nText('Dec-Dcm_Connection_Click_Connect_Database'),
                                handler: () => {
                                    this.fireEvent('EVENT_TEST_CONNECTION');
                                },
                            }, {
                                type: Label,
                                cls: 'bi-tips',
                                lgap: 3,
                                text: BI.i18nText('Dec-Dcm_Connection_Read_Mode_List'),
                            }],
                        }, {
                            type: TextValueCombo,
                            width: 300,
                            vgap: 15,
                            disabled: true,
                            value: schema,
                            items: schema ? [{ text: schema, value:schema }] : [],
                            ref: (_ref: any) => {
                                this.form.schema = _ref;
                            },
                        }],
                    }],
                },
                {
                    type: Layout,
                    cls: 'bi-border-top',
                    bgap: 8,
                },
                {
                    type: FormItemXtype,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
                    forms: [{
                        type: TextEditor,
                        width: 300,
                        allowBlank: true,
                        value: url,
                        watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
                        ref: (_ref: any) => {
                            this.form.url = _ref;
                        },
                        listeners: [{
                            eventName: 'EVENT_CHANGE',
                            action: () => {
                                const urlInfo = resolveUrlInfo(this.form.url.getValue());
                                this.form.host.setValue(urlInfo.host);
                                this.form.database.setValue(urlInfo.databaseName);
                                this.form.port.setValue(urlInfo.port);
                            },
                        }],
                    }],
                },
                {
                    type: CollapseXtype,
                    bgap: -15,
                    width: 70,
                    name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'),
                    listeners: [
                        {
                            eventName: EVENT_CHANGE,
                            action: (isCollapse: boolean) => {
                                this.advancedSet.setVisible(!isCollapse);
                            },
                        },
                    ],
                },
                {
                    type: Vertical,
                    vgap,
                    tgap: -15,
                    invisible: true,
                    ref: (_ref: any) => {
                        this.advancedSet = _ref;
                    },
                    items: [
                        {
                            type: FormItemXtype,
                            tgap: 15,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
                            forms: [{
                                type: TextCheckerXtype,
                                width: 300,
                                allowBlank: false,
                                value: initialSize,
                                validationChecker: [{
                                    errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                                    checker: (value: string) => this.checkInteger(value),
                                    autoFix: true,
                                }],
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
                                ref: (_ref: any) => {
                                    this.form.initialSize = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
                            forms: [{
                                type: TextCheckerXtype,
                                width: 300,
                                allowBlank: false,
                                value: maxActive,
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
                                validationChecker: [{
                                    errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                                    checker: (value: string) => this.checkInteger(value),
                                    autoFix: true,
                                }],
                                ref: (_ref: any) => {
                                    this.form.maxActive = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'),
                            forms: [{
                                type: TextCheckerXtype,
                                width: 300,
                                allowBlank: false,
                                value: maxIdle,
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Idle'),
                                validationChecker: [{
                                    errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                                    checker: (value: string) => this.checkInteger(value),
                                    autoFix: true,
                                }],
                                ref: (_ref: any) => {
                                    this.form.maxIdle = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
                            forms: [{
                                type: TextCheckerXtype,
                                width: 300,
                                allowBlank: false,
                                value: minIdle,
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
                                validationChecker: [{
                                    errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                                    checker: (value: string) => this.checkInteger(value),
                                    autoFix: true,
                                }],
                                ref: (_ref: any) => {
                                    this.form.minIdle = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
                            forms: [
                                {
                                    type: TextCheckerXtype,
                                    width: 300,
                                    allowBlank: false,
                                    value: maxWait,
                                    watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
                                    validationChecker: [{
                                        errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                                        checker: (value: string) => this.checkInteger(value),
                                        autoFix: true,
                                    }],
                                    ref: (_ref: any) => {
                                        this.form.maxWait = _ref;
                                    },
                                },
                                {
                                    type: Label,
                                    lgap: 5,
                                    height: CONNECTION_LAYOUT.labelHeight,
                                    text: BI.i18nText('Dec-Dcm_Millisecond'),
                                },
                            ],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
                            forms: [{
                                type: TextAreaEditor,
                                cls: 'bi-border',
                                allowBlank: true,
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
                                value: validationQuery,
                                width: 300,
                                height: 100,
                                ref: (_ref: any) => {
                                    this.form.validationQuery = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
                            forms: [{
                                type: TextValueCombo,
                                width: 300,
                                allowBlank: true,
                                value: testOnBorrow,
                                items: this.getBooleanItem(),
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
                                ref: (_ref: any) => {
                                    this.form.testOnBorrow = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
                            forms: [{
                                type: TextValueCombo,
                                width: 300,
                                allowBlank: true,
                                value: testOnReturn,
                                items: this.getBooleanItem(),
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
                                ref: (_ref: any) => {
                                    this.form.testOnReturn = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
                            forms: [{
                                type: TextValueCombo,
                                width: 300,
                                allowBlank: true,
                                value: testWhileIdle,
                                items: this.getBooleanItem(),
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
                                ref: (_ref: any) => {
                                    this.form.testWhileIdle = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
                            forms: [
                                {
                                    type: TextCheckerXtype,
                                    width: 300,
                                    allowBlank: false,
                                    value: timeBetweenEvictionRunsMillis,
                                    watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
                                    validationChecker: [{
                                        errorText: BI.i18nText('Dec-Dcm_Connection_Check_Number'),
                                        checker: (value: string) => this.checkNumber(value),
                                        autoFix: true,
                                    }],
                                    ref: (_ref: any) => {
                                        this.form.timeBetweenEvictionRunsMillis = _ref;
                                    },
                                },
                                {
                                    type: Label,
                                    lgap: 5,
                                    height: CONNECTION_LAYOUT.labelHeight,
                                    text: BI.i18nText('Dec-Dcm_Millisecond'),
                                },
                            ],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
                            forms: [{
                                type: TextCheckerXtype,
                                width: 300,
                                allowBlank: false,
                                value: numTestsPerEvictionRun,
                                watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
                                validationChecker: [{
                                    errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                                    checker: (value: string) => this.checkInteger(value),
                                    autoFix: true,
                                }],
                                ref: (_ref: any) => {
                                    this.form.numTestsPerEvictionRun = _ref;
                                },
                            }],
                        },
                        {
                            type: FormItemXtype,
                            name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
                            forms: [
                                {
                                    type: TextCheckerXtype,
                                    width: 300,
                                    allowBlank: false,
                                    value: minEvictableIdleTimeMillis,
                                    watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
                                    validationChecker: [{
                                        errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
                                        checker: (value: string) => this.checkInteger(value),
                                        autoFix: true,
                                    }],
                                    ref: (_ref: any) => {
                                        this.form.minEvictableIdleTimeMillis = _ref;
                                    },
                                },
                                {
                                    type: Label,
                                    lgap: 5,
                                    height: CONNECTION_LAYOUT.labelHeight,
                                    text: BI.i18nText('BI-Basic_Seconds'),
                                },
                            ],
                        },
                    ],
                },
            ],
        };
    }

    public setError(value: string) {
        this.form.connectionName.setError(value);
    }

    private checkInteger(value: string) {
        return /^[\d]+$/.test(value);
    }

    private checkNumber(value: string) {
        return /^[(\-|\+)?\d]+$/.test(value);
    }

    private getDrivers() {
        const connectionData = this.options.formData.connectionData as ConnectionJDBC;
        const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
        const drivers = connectionType.drivers ?
            connectionType.drivers.map(item => {
                return {
                    text: item,
                    value: item,
                };
            }) :
            [{
                text: connectionType.driver,
                value: connectionType.driver,
            }];

        if (!drivers.some(item => item.text === connectionData.driver)) {
            return [
                {
                    text: connectionData.driver,
                    value: connectionData.driver,
                },
                ...drivers,
            ];
        }
        
        return drivers;
    }

    private getBooleanItem() {
        return [
            {
                text: BI.i18nText('Dec-Dcm_Yes'),
                value: true,
            },
            {
                text: BI.i18nText('Dec-Dcm_No'),
                value: false,
            },
        ];
    }

    private onHostPortChange(databaseType) {
        const { urls, url } = databaseType;
        const driver = this.form.driver.getValue();
        const selectUrl = BI.get(urls, driver) || url;
        const host = this.form.host.getValue();
        const port = this.form.port.getValue();
        const database = this.form.database.getValue();
        this.form.url.setValue(splitUrl(host, port, database, selectUrl));
    }

    public setSchemas(schemas: string[]) {
        this.form.schema.setEnable(true);
        if (schemas.length > 0) {
            const value = this.form.schema.getValue()[0];
            this.form.schema.populate(schemas.map(item => {
                return {
                    text: item,
                    value: item,
                };
            }));
            this.form.schema.setValue(value && schemas.some(item => item === value) ? value : schemas[0]);
        }
    }

    public getSubmitValue():Connection {
        const connectionData = this.options.formData.connectionData as ConnectionJDBC;
        const connectionPoolAttr = connectionData.connectionPoolAttr;
        const originalCharsetName = this.form.originalCharsetName.getValue()[0] || '';
        // TODO 获取表单数据这里待优化
        
        return {
            connectionType: connectionType.JDBC,
            connectionId: this.form.connectionName.getValue(),
            connectionName: this.form.connectionName.getValue(),
            connectionData: {
                database: connectionData.database,
                connectionName: this.form.connectionName.getValue(),
                driver: this.form.driver.getValue(),
                url: this.form.url.getValue(),
                user: this.form.user.getValue(),
                password: this.oldPassword === this.form.password.getValue() ? this.oldPassword : BI.encode(this.form.password.getValue()),
                queryType: '',
                newCharsetName: originalCharsetName ? 'gbk' : '', // 后台要求,originalCharsetName不为空时,newCharsetName为gbk
                originalCharsetName,
                schema: this.form.schema.getValue()[0],
                host: this.form.host.getValue(),
                authType: this.form.authType.getValue()[0] || '',
                creator: Dec ? Dec.personal.username : '',
                principal: this.form.principal.getValue(),
                keyPath: this.form.keyPath.getValue(),
                connectionPoolAttr: {
                    initialSize: this.form.initialSize.getValue(),
                    maxActive: this.form.maxActive.getValue(),
                    maxIdle: this.form.maxIdle.getValue(),
                    minIdle: this.form.minIdle.getValue(),
                    maxWait: this.form.maxWait.getValue(),
                    validationQuery: this.form.validationQuery.getValue(),
                    testOnBorrow: BI.size(this.form.testOnBorrow.getValue()) > 0 ? this.form.testOnBorrow.getValue()[0] : connectionPoolAttr.testOnBorrow,
                    testOnReturn: BI.size(this.form.testOnReturn.getValue()) > 0 ? this.form.testOnReturn.getValue()[0] : connectionPoolAttr.testOnReturn,
                    testWhileIdle: BI.size(this.form.testOnReturn.getValue()) > 0 ? this.form.testWhileIdle.getValue()[0] : connectionPoolAttr.testWhileIdle,
                    timeBetweenEvictionRunsMillis: this.form.timeBetweenEvictionRunsMillis.getValue(),
                    numTestsPerEvictionRun: this.form.numTestsPerEvictionRun.getValue(),
                    minEvictableIdleTimeMillis: this.form.minEvictableIdleTimeMillis.getValue(),
                },
            },
        };
    }
}