Search in sources :

Example 16 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class SystemDBOperator method checkDbConnection.

/**
	 * 测试数据库服务器连接,不适用于Internal DB
	 * @return false 连接失败, true 连接成功;
	 */
public boolean checkDbConnection() {
    Connection conn = null;
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
        data.setDatabaseName("");
    } catch (CloneNotSupportedException e) {
        logger.warn("", e);
        return false;
    }
    try {
        String url = Utils.replaceParams(dbConfig.getDbURL(), data);
        String driver = dbConfig.getDriver();
        Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
        conn = getConnection(driver, url, prop);
    } catch (ClassNotFoundException e) {
        logger.error(Messages.getString("database.SystemDBOperator.logger1"), e);
        return false;
    } catch (SQLException e) {
        logger.error(Messages.getString("database.SystemDBOperator.logger2"), e);
        return false;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                logger.warn("", e);
            }
        }
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) Connection(java.sql.Connection) Properties(java.util.Properties)

Example 17 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class ExportDatabaseBean method equals.

@Override
public boolean equals(Object o) {
    if (o instanceof ExportDatabaseBean) {
        ExportDatabaseBean bean = (ExportDatabaseBean) o;
        MetaData b = bean.getDbBean();
        MetaData a = this.getDbBean();
        String dbname = a.getDatabaseName();
        String host = b.getServerName();
        String port = a.getPort();
        String instance = a.getInstance();
        String localPath = a.getDataPath();
        if (b.getDatabaseName().equals(dbname) && b.getServerName().equals(host) && b.getDataPath().equals(localPath) && b.getPort().equals(port) && b.getInstance().equals(instance)) {
            return true;
        }
    }
    return super.equals(o);
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData)

Example 18 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class TmDbManagerDialog method resetInputValue.

/**
	 * 当选择数据库类型节点时,重置所有输入 ;
	 */
private void resetInputValue() {
    MetaData metaData = dbMetaDataMap.get(getCurrDbType());
    currServer.setId("");
    currServer.setDbType(metaData.getDbType());
    currServer.setItlDBLocation("");
    if (metaData.dataPathSupported()) {
        currServer.setItlDBLocation(metaData.getDataPath());
    }
    currServer.setHost("");
    if (metaData.serverNameSupported()) {
        currServer.setHost(metaData.getServerName());
    }
    currServer.setInstance("");
    if (metaData.instanceSupported()) {
        currServer.setInstance(metaData.getInstance());
    }
    currServer.setPort("");
    if (metaData.portSupported()) {
        currServer.setPort(metaData.getPort());
    }
    currServer.setUserName("");
    if (metaData.userNameSupported()) {
        currServer.setUserName(metaData.getUserName());
    }
    currServer.setPassword("");
    if (metaData.passwordSupported()) {
        currServer.setPassword(metaData.getPassword());
    }
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData)

Example 19 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class TmDbManagerDialog method validator.

/**
	 * 输入验证器 ;
	 */
private IStatus validator() {
    String instance = currServer.getInstance();
    String host = currServer.getHost();
    String port = currServer.getPort();
    String location = currServer.getItlDBLocation();
    String username = currServer.getUserName();
    MetaData dbMetaData = dbMetaDataMap.get(currServer.getDbType());
    if (dbMetaData.dataPathSupported()) {
        File f = new File(location);
        if (location == null || location.trim().length() == 0) {
            if (dbMetaData.getDbType().equals(Constants.DBTYPE_INTERNALDB)) {
                return ValidationStatus.error(Messages.getString("dialog.TmDbManagerDialog.msg5"));
            } else if (dbMetaData.getDbType().equals(Constants.DBTYPE_SQLITE)) {
                return ValidationStatus.error(Messages.getString("dialog.TmDbManagerDialog.msg11"));
            }
        } else if (!f.exists()) {
            return ValidationStatus.error(Messages.getString("dialog.TmDbManagerDialog.msg12"));
        }
    }
    if (dbMetaData.serverNameSupported()) {
        if (host == null || host.trim().length() == 0) {
            return ValidationStatus.error(Messages.getString("dialog.TmDbManagerDialog.msg6"));
        }
    }
    if (dbMetaData.portSupported()) {
        if (port == null || port.trim().length() == 0) {
            return ValidationStatus.error(Messages.getString("dialog.TmDbManagerDialog.msg7"));
        }
    }
    if (dbMetaData.userNameSupported()) {
        if (username == null || username.trim().length() == 0) {
            return ValidationStatus.error(Messages.getString("dialog.TmDbManagerDialog.msg8"));
        }
    }
    if (dbMetaData.instanceSupported()) {
        if (instance == null || instance.trim().length() == 0) {
            return ValidationStatus.error(Messages.getString("dialog.TmDbManagerDialog.msg9"));
        }
    }
    return ValidationStatus.ok();
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData) File(java.io.File)

Example 20 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class TmDbManagerDialog method initUI.

/**
	 * 根据当前操作不同的数据库类型,初始化界面 ;
	 */
private void initUI(boolean isAdd) {
    MetaData curDbMetaData = dbMetaDataMap.get(getCurrDbType());
    if (!isAdd) {
        Control[] childrens = locationText.getParent().getChildren();
        for (Control c : childrens) {
            if (!(c instanceof Composite)) {
                if (c instanceof Text || c instanceof Button) {
                    c.setEnabled(false);
                }
            } else {
                Composite com = (Composite) c;
                Control[] ch = com.getChildren();
                for (Control chl : ch) {
                    if (c instanceof Text || c instanceof Button) {
                        chl.setEnabled(false);
                    }
                }
            }
        }
    } else {
        if (curDbMetaData.dataPathSupported()) {
            locationText.setEnabled(true);
            borwserBtn.setEnabled(true);
        } else {
            locationText.setEnabled(false);
            borwserBtn.setEnabled(false);
        }
        if (curDbMetaData.serverNameSupported()) {
            hostText.setEnabled(true);
        } else {
            hostText.setEnabled(false);
        }
        if (curDbMetaData.instanceSupported()) {
            instanceText.setEnabled(true);
        } else {
            instanceText.setEnabled(false);
        }
        if (curDbMetaData.portSupported()) {
            portText.setEnabled(true);
        } else {
            portText.setEnabled(false);
        }
        if (curDbMetaData.userNameSupported()) {
            usernameText.setEnabled(true);
        } else {
            usernameText.setEnabled(false);
        }
        if (curDbMetaData.passwordSupported()) {
            passwordText.setEnabled(true);
        } else {
            passwordText.setEnabled(false);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Button(org.eclipse.swt.widgets.Button) MetaData(net.heartsome.cat.common.bean.MetaData) Text(org.eclipse.swt.widgets.Text)

Aggregations

MetaData (net.heartsome.cat.common.bean.MetaData)40 SQLException (java.sql.SQLException)21 ArrayList (java.util.ArrayList)14 Properties (java.util.Properties)13 Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)11 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)8 DBOperator (net.heartsome.cat.database.DBOperator)8 Statement (java.sql.Statement)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Entry (java.util.Map.Entry)5 Point (org.eclipse.swt.graphics.Point)5 MenuItem (org.eclipse.swt.widgets.MenuItem)5 List (java.util.List)4 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)4 File (java.io.File)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2