Search in sources :

Example 6 with ConnectionParameters

use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.

the class GenerateSelectSQLAction method run.

/**
     * run.
     */
@Override
public void run() {
    if (selectedNodes.isEmpty()) {
        return;
    }
    try {
        // String query = null;
        // ErDiagramDialog erDiagramDialog = new ErDiagramDialog(dialog.getShell(), Messages
        // .getString("GenerateSelectSQLAction.textCenerateSelectStatement")); //$NON-NLS-1$
        // erDiagramDialog.setNodes(selectedNodes);
        // erDiagramDialog.setSqlText(null);
        // if (Window.OK == erDiagramDialog.open()) {
        // query = erDiagramDialog.getSql();
        // }
        // if (query == null) {
        // return;
        // }
        List<String> repositoryNames = repositoryNodeManager.getALLReposotoryNodeNames();
        ConnectionParameters connParam = new ConnectionParameters();
        //$NON-NLS-1$
        connParam.setQuery("");
        connParam.setNeedTakePrompt(false);
        connParam.setShowDesignerPage(true);
        //$NON-NLS-1$
        connParam.setEditorTitle(TextUtil.getNewQueryLabel());
        dialog.openEditor(SQLBuilderRepositoryNodeManager.getRoot((RepositoryNode) selectedNodes.get(0)), repositoryNames, connParam, isDefaultEditor, selectedNodes);
    } catch (Throwable e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("GenerateSelectSQLAction.logMessageGenerateSql"), e);
    }
}
Also used : ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 7 with ConnectionParameters

use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.

the class DbTableController method checkConnection.

/**
     * nma Comment method "checkConnection".
     * 
     * @param metadataConnection, IContextManager
     */
protected boolean checkConnection(IMetadataConnection metadataConnection, IContextManager contextManager) {
    try {
        String DBType = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDbType(), contextManager);
        String userName = ContextParameterUtils.parseScriptContextCode(metadataConnection.getUsername(), contextManager);
        String password = ContextParameterUtils.parseScriptContextCode(metadataConnection.getPassword(), contextManager);
        String schema = ContextParameterUtils.parseScriptContextCode(metadataConnection.getSchema(), contextManager);
        String driveClass = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDriverClass(), contextManager);
        String driverJarPath = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDriverJarPath(), contextManager);
        String dbVersion = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDbVersionString(), contextManager);
        String additionalParams = ContextParameterUtils.parseScriptContextCode(metadataConnection.getAdditionalParams(), contextManager);
        // specially used for URL
        String server = ContextParameterUtils.parseScriptContextCode(metadataConnection.getServerName(), contextManager);
        String port = ContextParameterUtils.parseScriptContextCode(metadataConnection.getPort(), contextManager);
        String sidOrDatabase = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDatabase(), contextManager);
        String filePath = ContextParameterUtils.parseScriptContextCode(metadataConnection.getFileFieldName(), contextManager);
        String datasource = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDataSourceName(), contextManager);
        String dbRootPath = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDbRootPath(), contextManager);
        String additionParam = ContextParameterUtils.parseScriptContextCode(metadataConnection.getAdditionalParams(), contextManager);
        String newURL = DatabaseConnStrUtil.getURLString(DBType, dbVersion, server, userName, password, port, sidOrDatabase, filePath.toLowerCase(), datasource, dbRootPath, additionParam);
        ConnectionStatus testConnection = ExtractMetaDataFromDataBase.testConnection(DBType, newURL, userName, password, schema, driveClass, driverJarPath, dbVersion, additionalParams);
        ConnectionParameters connParameters2 = new ConnectionParameters();
        if (connParameters == null) {
            connParameters = connParameters2;
        }
        connParameters.setConnectionComment(testConnection.getMessageException());
        if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connParameters.getDbType())) {
            return true;
        }
        return testConnection.getResult();
    } catch (Exception e) {
        //$NON-NLS-1$ //$NON-NLS-2$
        log.error(Messages.getString("CommonWizard.exception") + "\n" + e.toString());
    }
    return false;
}
Also used : ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) ConnectionStatus(org.talend.core.repository.model.connection.ConnectionStatus) SQLException(java.sql.SQLException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 8 with ConnectionParameters

use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.

the class SqlMemoController method refreshConnectionCommand.

private Command refreshConnectionCommand() {
    // open sql builder in repository mode, just use query object, no need for connection information
    ConnectionParameters connParameters = new ConnectionParameters();
    String queryId = (String) elem.getPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
    Query query = MetadataToolHelper.getQueryFromRepository(queryId);
    DatabaseConnectionItem item = findRepositoryItem(queryId);
    if (item != null) {
        connParameters.setRepositoryName(item.getProperty().getLabel());
        connParameters.setRepositoryId(item.getProperty().getId());
    }
    connParameters.setQueryObject(query);
    connParameters.setQuery(query.getValue());
    TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
    String processName = null;
    if (elem instanceof IProcess) {
        processName = ((IProcess) elem).getName();
    } else if (elem instanceof INode) {
        processName = ((INode) elem).getProcess().getName();
    } else if (elem instanceof IConnection) {
        processName = ((IConnection) elem).getSource().getProcess().getName();
    }
    connParameters.setNodeReadOnly(false);
    connParameters.setFromRepository(true);
    ISQLBuilderService sqlBuilderService = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
    Dialog sqlBuilder = sqlBuilderService.openSQLBuilderDialog(composite.getShell(), processName, connParameters);
    String sql = null;
    if (Window.OK == sqlBuilder.open()) {
        sql = connParameters.getQuery();
    }
    if (sql != null && !queryText.isDisposed()) {
        queryText.setText(sql);
        String propertyName = (String) openSQLEditorButton.getData(PARAMETER_NAME);
        return new PropertyChangeCommand(elem, propertyName, sql);
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Query(org.talend.core.model.metadata.builder.connection.Query) ModelSelectionDialog(org.talend.commons.ui.swt.dialogs.ModelSelectionDialog) Dialog(org.eclipse.jface.dialogs.Dialog) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IConnection(org.talend.core.model.process.IConnection) IProcess(org.talend.core.model.process.IProcess) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 9 with ConnectionParameters

use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.

the class AbstractElementPropertySectionController method initConnectionParametersWithContext.

protected void initConnectionParametersWithContext(IElement element, IContext context) {
    IElementParameter basePropertyParameter = null;
    for (IElementParameter param : elem.getElementParameters()) {
        if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
            if (param.getRepositoryValue().startsWith("DATABASE")) {
                basePropertyParameter = param;
                break;
            }
        }
    }
    // jobsetting view load the db info from current selected category
    IElementParameter updateBasePropertyParameter = updateBasePropertyParameter();
    if (updateBasePropertyParameter != null && !updateBasePropertyParameter.equals(basePropertyParameter)) {
        basePropertyParameter = updateBasePropertyParameter;
    }
    // qli modified to fix the bug "7364".
    if (connParameters == null) {
        connParameters = new ConnectionParameters();
    }
    String dbType = connParameters.getDbType();
    //$NON-NLS-1$
    Object value = elem.getPropertyValue("USE_EXISTING_CONNECTION");
    IElementParameter compList = elem.getElementParameterFromField(EParameterFieldType.COMPONENT_LIST);
    if (value != null && (value instanceof Boolean) && ((Boolean) value) && compList != null) {
        if (connectionNode == null) {
            Object compValue = compList.getValue();
            if (compValue != null && !compValue.equals("")) {
                //$NON-NLS-1$
                List<? extends INode> nodes = part.getProcess().getGeneratingNodes();
                for (INode node : nodes) {
                    if (node.getUniqueName().equals(compValue) && (node instanceof INode)) {
                        connectionNode = node;
                        break;
                    }
                }
            }
        }
        if (connectionNode != null) {
            element = connectionNode;
        }
    }
    String dbName = getParameterValueWithContext(element, EConnectionParameterName.SID.getName(), context, basePropertyParameter);
    if (EDatabaseTypeName.EXASOL.getDisplayName().equals(dbType)) {
        if (dbName.contains("\\\"")) {
            dbName = dbName.replace("\\\"", "");
        }
        dbName = TextUtil.removeQuots(dbName);
    } else if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(connParameters.getDbType())) {
        //$NON-NLS-1$
        dbName = "";
    }
    connParameters.setDbName(dbName);
    connParameters.setPassword(getParameterValueWithContext(element, EConnectionParameterName.PASSWORD.getName(), context, basePropertyParameter));
    connParameters.setPort(getParameterValueWithContext(element, EConnectionParameterName.PORT.getName(), context, basePropertyParameter));
    connParameters.setSchema(getParameterValueWithContext(element, EConnectionParameterName.SCHEMA.getName(), context, basePropertyParameter));
    connParameters.setHost(getParameterValueWithContext(element, EConnectionParameterName.SERVER_NAME.getName(), context, basePropertyParameter));
    connParameters.setUserName(getParameterValueWithContext(element, EConnectionParameterName.USERNAME.getName(), context, basePropertyParameter));
    String dir = getParameterValueWithContext(element, EConnectionParameterName.DIRECTORY.getName(), context, basePropertyParameter);
    if (dbType.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName())) {
        dir = getParameterValueWithContext(element, EConnectionParameterName.DBPATH.getName(), context, basePropertyParameter);
    }
    if (connParameters.getSchema() == null || connParameters.getSchema().equals("")) {
        if (EDatabaseTypeName.IBMDB2.getDisplayName().equals(dbType) || EDatabaseTypeName.IBMDB2ZOS.getDisplayName().equals(dbType)) {
            connParameters.setSchema(getParameterValueWithContext(element, EParameterName.SCHEMA_DB_DB2.getDisplayName(), context, basePropertyParameter));
        }
    }
    connParameters.setDirectory(dir);
    connParameters.setHttps(Boolean.parseBoolean(getParameterValueWithContext(element, EConnectionParameterName.HTTPS.getName(), context, basePropertyParameter)));
    String url = TalendTextUtils.removeQuotesIfExist(getParameterValueWithContext(element, EConnectionParameterName.URL.getName(), context, basePropertyParameter));
    if (StringUtils.isEmpty(url)) {
        // to get the Oracle RAC url.
        if (EDatabaseTypeName.ORACLE_CUSTOM.getDisplayName().equals(dbType)) {
            url = TalendTextUtils.removeQuotesIfExist(getParameterValueWithContext(element, "RAC_" + EConnectionParameterName.URL.getName(), context, basePropertyParameter));
        }
    }
    connParameters.setUrl(url);
    String driverClass = TalendTextUtils.removeQuotesIfExist(getParameterValueWithContext(element, EConnectionParameterName.DRIVER_CLASS.getName(), context, basePropertyParameter));
    if (element != null) {
        String dbVersion = getValueFromRepositoryName(element, "DB_VERSION");
        if (EDatabaseVersion4Drivers.VERTICA_6.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_5_1.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_6_1_X.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_7.getVersionValue().equals(dbVersion)) {
            driverClass = EDatabase4DriverClassName.VERTICA2.getDriverClass();
        }
    }
    connParameters.setDriverClass(driverClass);
    connParameters.setDriverJar(TalendTextUtils.removeQuotesIfExist(getParameterValueWithContext(element, EConnectionParameterName.DRIVER_JAR.getName(), context, basePropertyParameter)));
    // for jdbc connection from reposiotry
    final String dbTypeByClassName = ExtractMetaDataUtils.getInstance().getDbTypeByClassName(connParameters.getDriverClass());
    if (connParameters.getDbType() == null || EDatabaseTypeName.MYSQL.getDisplayName().equals(connParameters.getDbType()) && !EDatabaseTypeName.MYSQL.getProduct().equals(dbTypeByClassName)) {
        if (dbTypeByClassName != null && !"".equals(dbTypeByClassName)) {
            connParameters.setDbType(dbTypeByClassName);
        }
    }
    if (connParameters.getDbType().equals(EDatabaseTypeName.SQLITE.getXmlName()) || connParameters.getDbType().equals(EDatabaseTypeName.ACCESS.getXmlName()) || connParameters.getDbType().equals(EDatabaseTypeName.FIREBIRD.getXmlName())) {
        connParameters.setFilename(getParameterValueWithContext(element, EConnectionParameterName.FILE.getName(), context, basePropertyParameter));
    }
    connParameters.setJdbcProperties(getParameterValueWithContext(element, EConnectionParameterName.PROPERTIES_STRING.getName(), context, basePropertyParameter));
    connParameters.setDatasource(getParameterValueWithContext(element, EConnectionParameterName.DATASOURCE.getName(), context, basePropertyParameter));
}
Also used : INode(org.talend.core.model.process.INode) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

ConnectionParameters (org.talend.core.sqlbuilder.util.ConnectionParameters)9 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 INode (org.talend.core.model.process.INode)3 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 Query (org.talend.core.model.metadata.builder.connection.Query)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 ContextItem (org.talend.core.model.properties.ContextItem)2 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)2 ContextSetsSelectionDialog (org.talend.metadata.managment.ui.wizard.metadata.ContextSetsSelectionDialog)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 SQLBuilderDialog (org.talend.sqlbuilder.ui.SQLBuilderDialog)2 SQLException (java.sql.SQLException)1