Search in sources :

Example 1 with ConnectionParameters

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

the class DBStructureComposite method openNewQueryEditor.

/**
     * qzhang Comment method "openNewQueryEditor".
     */
public void openNewQueryEditor() {
    final ConnectionParameters connParameters = builderDialog.getConnParameters();
    final RepositoryNode selectQuery = this.treeLabelProvider.getSelectedExtReposiotryNode();
    expandNodes = new ArrayList<RepositoryNode>();
    getNeedExpandedNodes(selectQuery);
    if (expandNodes.size() > 0) {
        treeViewer.setExpandedElements(expandNodes.toArray(new Object[0]));
    }
    if (treeViewer.getTree().getItemCount() > 0) {
        treeViewer.getTree().setSelection(treeViewer.getTree().getItem(0));
    }
    Action tempOpenNewEditorAction = new OpenNewEditorAction(treeViewer, builderDialog, connParameters, true);
    tempOpenNewEditorAction.run();
}
Also used : OpenQueryAction(org.talend.sqlbuilder.actions.OpenQueryAction) SelectionProviderAction(org.eclipse.ui.actions.SelectionProviderAction) MetadataRefreshAction(org.talend.sqlbuilder.actions.MetadataRefreshAction) GenerateSelectSQLAction(org.talend.sqlbuilder.actions.GenerateSelectSQLAction) DeleteQueryAction(org.talend.sqlbuilder.actions.DeleteQueryAction) OpenNewEditorAction(org.talend.sqlbuilder.actions.OpenNewEditorAction) Action(org.eclipse.jface.action.Action) ShowQueryPropertyAction(org.talend.sqlbuilder.actions.ShowQueryPropertyAction) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) OpenNewEditorAction(org.talend.sqlbuilder.actions.OpenNewEditorAction) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 2 with ConnectionParameters

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

the class AbstractElementPropertySectionController method initConnectionParameters.

protected void initConnectionParameters() {
    connParameters = null;
    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;
    }
    connParameters = new ConnectionParameters();
    //$NON-NLS-1$
    String type = getValueFromRepositoryName(elem, "TYPE", basePropertyParameter);
    if (type.equals("Oracle") || type.contains("OCLE")) {
        IElementParameter ele = elem.getElementParameter("CONNECTION_TYPE");
        if (ele != null) {
            type = (String) ele.getValue();
        } else {
            //$NON-NLS-1$
            type = "ORACLE_SID";
        }
    } else if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(type)) {
        // if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equals(
        // elem.getElementParameter("CONNECTION_MODE").getValue())) {
        setHiveRelatedParams(elem);
    // }
    } else if (EDatabaseTypeName.IMPALA.getProduct().equalsIgnoreCase(type)) {
        String distroKey = getValueFromRepositoryName(elem, "DISTRIBUTION");
        connParameters.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_IMPALA_DISTRIBUTION, distroKey);
        String distroVersion = getValueFromRepositoryName(elem, "IMPALA_VERSION");
        connParameters.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_IMPALA_VERSION, distroVersion);
    }
    // Get real hsqldb type
    if (type.equals(EDatabaseTypeName.HSQLDB.name()) && getValueFromRepositoryName(elem, "RUNNING_MODE").equals("HSQLDB_INPROGRESS_PERSISTENT")) {
        //$NON-NLS-1$
        type = EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName();
    }
    connParameters.setDbType(type);
    //$NON-NLS-1$
    String driverName = getValueFromRepositoryName(elem, "DB_VERSION", basePropertyParameter);
    String dbVersionName = EDatabaseVersion4Drivers.getDbVersionName(type, driverName);
    if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(type)) {
        if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equals(elem.getElementParameter("CONNECTION_MODE").getValue())) {
            connParameters.setDbVersion(EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue());
        } else {
            connParameters.setDbVersion(EDatabaseVersion4Drivers.HIVE.getVersionValue());
        }
    } else {
        connParameters.setDbVersion(dbVersionName);
    }
    connParameters.setNode(elem);
    String selectedComponentName = (String) elem.getPropertyValue(EParameterName.UNIQUE_NAME.getName());
    connParameters.setSelectedComponentName(selectedComponentName);
    connParameters.setFieldType(paramFieldType);
    if (elem instanceof Node && !((Node) elem).getMetadataList().isEmpty()) {
        connParameters.setMetadataTable(((Node) elem).getMetadataList().get(0));
    }
    connParameters.setSchemaRepository(EmfComponent.REPOSITORY.equals(elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName())));
    connParameters.setFromDBNode(true);
    //$NON-NLS-1$
    connParameters.setQuery("");
    List<? extends IElementParameter> list = elem.getElementParameters();
    boolean end = false;
    for (int i = 0; i < list.size() && !end; i++) {
        IElementParameter param = list.get(i);
        if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
            connParameters.setNodeReadOnly(param.isReadOnly());
            end = true;
        }
    }
    //$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) {
        Object compValue = compList.getValue();
        if (compValue != null && !compValue.equals("")) {
            //$NON-NLS-1$
            List<? extends INode> nodes = part.getProcess().getGraphicalNodes();
            for (INode node : nodes) {
                if (node.getUniqueName().equals(compValue) && (node instanceof Node)) {
                    connectionNode = node;
                    break;
                }
            }
            if (connectionNode == null) {
                nodes = part.getProcess().getGeneratingNodes();
                for (INode node : nodes) {
                    if (node.getUniqueName().equals(compValue) && (node instanceof INode)) {
                        connectionNode = node;
                        break;
                    }
                }
            }
            if (connectionNode != null) {
                setAllConnectionParameters(type, connectionNode);
            }
        }
    } else {
        setAllConnectionParameters(null, elem);
    }
    if (connectionNode != null) {
        setConnectionParameterNames(connectionNode, connParameters, basePropertyParameter);
    } else {
        setConnectionParameterNames(elem, connParameters, basePropertyParameter);
    }
}
Also used : INode(org.talend.core.model.process.INode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) Node(org.talend.designer.core.ui.editor.nodes.Node) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 3 with ConnectionParameters

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

the class OpenQueryAction method run.

@Override
public void run() {
    RepositoryNode node = (RepositoryNode) getStructuredSelection().getFirstElement();
    if (node == null) {
        return;
    }
    if (node.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.QUERY) {
        List<String> repositoryName = repositoryNodeManager.getALLReposotoryNodeNames();
        ConnectionParameters connectionParameters = new ConnectionParameters();
        IRepositoryViewObject repViewObject = node.getObject();
        if (repViewObject instanceof QueryRepositoryObject) {
            QueryRepositoryObject queryRepObj = (QueryRepositoryObject) repViewObject;
            Query query = queryRepObj.getQuery();
            connectionParameters.setQueryObject(query);
            dialog.setConnParameters(connectionParameters);
        }
        connectionParameters.setQuery(dialog.getConnParameters().getQuery());
        connectionParameters.setShowDesignerPage(false);
        dialog.openEditor(node, repositoryName, connectionParameters, false);
    }
}
Also used : QueryRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject) Query(org.talend.core.model.metadata.builder.connection.Query) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 4 with ConnectionParameters

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

the class ReadQueriesAction method doRun.

@Override
protected void doRun() {
    IStructuredSelection selection = (IStructuredSelection) getSelection();
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (repositoryNode == null && selection != null) {
        repositoryNode = (RepositoryNode) selection.getFirstElement();
    }
    DatabaseConnectionItem dbConnectionItem = null;
    ConnectionParameters connParameters = new ConnectionParameters();
    if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
        dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
        connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
        connParameters.setRepositoryId(repositoryNode.getObject().getId());
        //$NON-NLS-1$
        connParameters.setQuery("");
    } else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
        QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
        dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
        connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
        connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
        connParameters.setQueryObject(queryRepositoryObject.getQuery());
        connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
        // first open Sql Builder,set true
        connParameters.setFirstOpenSqlBuilder(true);
    }
    Display display = Display.getCurrent();
    if (display == null) {
        display = Display.getDefault();
    }
    Shell parentShell = new Shell(display);
    TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
    Connection connection = dbConnectionItem.getConnection();
    String selectedContext = null;
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null && connection.isContextMode()) {
            ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
            setsDialog.open();
            selectedContext = setsDialog.getSelectedContext();
        }
    }
    SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
    dial.setReadOnly(true);
    if (connection instanceof DatabaseConnection) {
        IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
        connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
        UIUtils.checkConnection(parentShell, imetadataConnection);
    }
    connParameters.setNodeReadOnly(true);
    connParameters.setFromRepository(true);
    dial.setConnParameters(connParameters);
    dial.open();
    refresh(repositoryNode);
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) Shell(org.eclipse.swt.widgets.Shell) ContextSetsSelectionDialog(org.talend.metadata.managment.ui.wizard.metadata.ContextSetsSelectionDialog) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) SQLBuilderDialog(org.talend.sqlbuilder.ui.SQLBuilderDialog) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Display(org.eclipse.swt.widgets.Display)

Example 5 with ConnectionParameters

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

the class EditQueriesAction method doRun.

@Override
protected void doRun() {
    IStructuredSelection selection = (IStructuredSelection) getSelection();
    if (repositoryNode == null && selection != null) {
        repositoryNode = (RepositoryNode) selection.getFirstElement();
    }
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IRepositoryViewObject nodeObject = repositoryNode.getObject();
    boolean locked = false;
    if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
        if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
            locked = true;
        }
    }
    // Avoid to delete node which is locked.
    if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
        final String title = "Impossible to edit queries";
        String nodeName = nodeObject.getRepositoryObjectType().getLabel();
        final String message = "item is already locked by another user.";
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialog dialog = new MessageDialog(new Shell(), title, null, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
                dialog.open();
            }
        });
        return;
    }
    DatabaseConnectionItem dbConnectionItem = null;
    boolean readOnly = false;
    ConnectionParameters connParameters = new ConnectionParameters();
    if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
        dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
        connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
        connParameters.setRepositoryId(repositoryNode.getObject().getId());
        //$NON-NLS-1$
        connParameters.setQuery("");
    } else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
        QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
        readOnly = SubItemHelper.isDeleted(queryRepositoryObject.getAbstractMetadataObject());
        dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
        connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
        connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
        connParameters.setQueryObject(queryRepositoryObject.getQuery());
        connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
        // first open Sql Builder,set true
        connParameters.setFirstOpenSqlBuilder(true);
    } else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
        dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
        connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
        connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
        connParameters.setMetadataTable((MetadataTableRepositoryObject) repositoryNode.getObject());
        //$NON-NLS-1$
        connParameters.setQuery("");
    }
    IRepositoryView viewPart = getViewPart();
    Display display = null;
    if (viewPart != null) {
        display = viewPart.getViewer().getControl().getDisplay();
    } else {
        display = Display.getCurrent();
        if (display == null) {
            display = Display.getDefault();
        }
    }
    Shell parentShell = new Shell(display);
    TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
    Connection connection = dbConnectionItem.getConnection();
    String selectedContext = null;
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null && connection.isContextMode()) {
            ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
            setsDialog.open();
            selectedContext = setsDialog.getSelectedContext();
        }
    }
    SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
    dial.setReadOnly(readOnly);
    if (connection instanceof DatabaseConnection) {
        IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
        connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
        UIUtils.checkConnection(parentShell, imetadataConnection);
    }
    connParameters.setNodeReadOnly(readOnly);
    connParameters.setFromRepository(true);
    dial.setConnParameters(connParameters);
    dial.open();
    IRepositoryView view = getViewPart();
    if (view != null) {
        view.refreshView();
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Shell(org.eclipse.swt.widgets.Shell) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) ContextSetsSelectionDialog(org.talend.metadata.managment.ui.wizard.metadata.ContextSetsSelectionDialog) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) SQLBuilderDialog(org.talend.sqlbuilder.ui.SQLBuilderDialog) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Display(org.eclipse.swt.widgets.Display)

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