Search in sources :

Example 6 with DatabaseConfig

use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.

the class DbConnectionController method extractConfigForUI.

public DatabaseConfig extractConfigForUI() {
    String name = nameField.getText();
    String host = hostField.getText();
    String port = portField.getText();
    String userName = userNameField.getText();
    String password = passwordField.getText();
    String encoding = encodingChoice.getValue();
    String dbType = dbTypeChoice.getValue();
    String schema = schemaField.getText();
    DatabaseConfig config = new DatabaseConfig();
    config.setName(name);
    config.setDbType(dbType);
    config.setHost(host);
    config.setPort(port);
    config.setUsername(userName);
    config.setPassword(password);
    config.setSchema(schema);
    config.setEncoding(encoding);
    if (StringUtils.isAnyEmpty(name, host, port, userName, encoding, dbType, schema)) {
        AlertUtil.showWarnAlert("密码以外其他字段必填");
        return null;
    }
    return config;
}
Also used : DatabaseConfig(com.zzg.mybatis.generator.model.DatabaseConfig)

Example 7 with DatabaseConfig

use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.

the class DbConnectionController method saveConnection.

final void saveConnection() {
    DatabaseConfig config = extractConfigForUI();
    if (config == null) {
        return;
    }
    try {
        ConfigHelper.saveDatabaseConfig(this.isUpdate, primayKey, config);
        this.tabPaneController.getDialogStage().close();
        mainUIController.loadLeftDBTree();
    } catch (Exception e) {
        _LOG.error(e.getMessage(), e);
        AlertUtil.showErrorAlert(e.getMessage());
    }
}
Also used : DatabaseConfig(com.zzg.mybatis.generator.model.DatabaseConfig)

Example 8 with DatabaseConfig

use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.

the class OverSshController method checkInput.

@FXML
public void checkInput() {
    DatabaseConfig databaseConfig = extractConfigFromUi();
    if (authTypeChoice.getValue().equals("Password") && (StringUtils.isBlank(databaseConfig.getSshHost()) || StringUtils.isBlank(databaseConfig.getSshPort()) || StringUtils.isBlank(databaseConfig.getSshUser()) || StringUtils.isBlank(databaseConfig.getSshPassword())) || authTypeChoice.getValue().equals("PubKey") && (StringUtils.isBlank(databaseConfig.getSshHost()) || StringUtils.isBlank(databaseConfig.getSshPort()) || StringUtils.isBlank(databaseConfig.getSshUser()) || StringUtils.isBlank(databaseConfig.getPrivateKey()))) {
        note.setText("当前SSH配置输入不完整,OVER SSH不生效");
        note.setTextFill(Paint.valueOf("#ff666f"));
    } else {
        note.setText("当前SSH配置生效");
        note.setTextFill(Paint.valueOf("#5da355"));
    }
}
Also used : DatabaseConfig(com.zzg.mybatis.generator.model.DatabaseConfig) FXML(javafx.fxml.FXML)

Example 9 with DatabaseConfig

use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.

the class OverSshController method extractConfigFromUi.

public DatabaseConfig extractConfigFromUi() {
    String name = nameField.getText();
    String host = hostField.getText();
    String port = portField.getText();
    String userName = userNameField.getText();
    String password = passwordField.getText();
    String encoding = encodingChoice.getValue();
    String dbType = dbTypeChoice.getValue();
    String schema = schemaField.getText();
    String authType = authTypeChoice.getValue();
    DatabaseConfig config = new DatabaseConfig();
    config.setName(name);
    config.setDbType(dbType);
    config.setHost(host);
    config.setPort(port);
    config.setUsername(userName);
    config.setPassword(password);
    config.setSchema(schema);
    config.setEncoding(encoding);
    config.setSshHost(this.sshHostField.getText());
    config.setSshPort(this.sshdPortField.getText());
    config.setLport(this.lportField.getText());
    config.setRport(this.rportField.getText());
    config.setSshUser(this.sshUserField.getText());
    config.setSshPassword(this.sshPasswordField.getText());
    if ("PubKey".equals(authType)) {
        config.setPrivateKey(this.privateKey.getAbsolutePath());
        config.setPrivateKeyPassword(this.sshPubkeyPasswordField.getText());
    }
    return config;
}
Also used : DatabaseConfig(com.zzg.mybatis.generator.model.DatabaseConfig)

Example 10 with DatabaseConfig

use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.

the class ConfigHelper method loadDatabaseConfig.

public static List<DatabaseConfig> loadDatabaseConfig() throws Exception {
    Connection conn = null;
    Statement stat = null;
    ResultSet rs = null;
    try {
        conn = ConnectionManager.getConnection();
        stat = conn.createStatement();
        rs = stat.executeQuery("SELECT * FROM dbs");
        List<DatabaseConfig> configs = new ArrayList<>();
        while (rs.next()) {
            int id = rs.getInt("id");
            String value = rs.getString("value");
            DatabaseConfig databaseConfig = JSON.parseObject(value, DatabaseConfig.class);
            databaseConfig.setId(id);
            configs.add(databaseConfig);
        }
        return configs;
    } finally {
        if (rs != null)
            rs.close();
        if (stat != null)
            stat.close();
        if (conn != null)
            conn.close();
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) DatabaseConfig(com.zzg.mybatis.generator.model.DatabaseConfig)

Aggregations

DatabaseConfig (com.zzg.mybatis.generator.model.DatabaseConfig)11 SQLRecoverableException (java.sql.SQLRecoverableException)3 FXML (javafx.fxml.FXML)3 ImageView (javafx.scene.image.ImageView)3 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 EOFException (java.io.EOFException)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Task (javafx.concurrent.Task)1 MenuItem (javafx.scene.control.MenuItem)1 TextFieldTreeCell (javafx.scene.control.cell.TextFieldTreeCell)1 ColumnOverride (org.mybatis.generator.config.ColumnOverride)1