Search in sources :

Example 36 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem 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 37 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem 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)

Example 38 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class ReadQueriesAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = !selection.isEmpty() && selection.size() == 1;
    if (canWork) {
        Object o = selection.getFirstElement();
        repositoryNode = (RepositoryNode) o;
        switch(repositoryNode.getType()) {
            case REPOSITORY_ELEMENT:
                if (repositoryNode.getObject().getRepositoryStatus() == ERepositoryStatus.DELETED) {
                    canWork = false;
                }
                if (repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CONNECTIONS && repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CON_QUERY) {
                    canWork = false;
                }
                // Studio does not support this action for impala, TBD-3827.
                if (canWork) {
                    if (isUnderDBConnection(repositoryNode)) {
                        DatabaseConnectionItem item = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
                        DatabaseConnection dbConn = (DatabaseConnection) item.getConnection();
                        String dbType = dbConn.getDatabaseType();
                        if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.HBASE.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.MAPRDB.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.IMPALA.getXmlName().equalsIgnoreCase(dbType)) {
                            canWork = false;
                            break;
                        }
                    }
                }
                break;
            default:
                canWork = false;
        }
        if (canWork && !isLastVersion(repositoryNode)) {
            canWork = false;
        }
    }
    setEnabled(canWork);
}
Also used : QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 39 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class UpgrateDatabaseTypeForSybaseConnection method execute.

@Override
public ExecutionResult execute(Item item) {
    try {
        if (item instanceof DatabaseConnectionItem) {
            DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
            Connection connection = dbItem.getConnection();
            if (connection instanceof DatabaseConnection) {
                DatabaseConnection dbconn = (DatabaseConnection) connection;
                if (dbconn.getProductId().equals(EDatabaseTypeName.SYBASEASE.getProduct())) {
                    dbconn.setDatabaseType(EDatabaseTypeName.SYBASEASE.getDisplayName());
                }
            }
            ProxyRepositoryFactory.getInstance().save(dbItem, true);
        }
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 40 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class AddTablesComposite method createTableList.

/**
     * DOC admin Comment method "createTableList".
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private Composite createTableList() {
    Composite div1 = new Composite(tabFolder, SWT.NONE);
    div1.setLayout(new GridLayout());
    GridData lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL_BOTH;
    lgid.heightHint = 1;
    lgid.verticalIndent = 1;
    div1.setLayoutData(lgid);
    div1.setBackground(ColorConstants.white);
    listTables = new org.eclipse.swt.widgets.List(div1, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    listTables.setLayoutData(new GridData(GridData.FILL_BOTH));
    DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(getRootNode());
    tables = ConnectionHelper.getTables((DatabaseConnection) item.getConnection());
    for (MetadataTable table : tables) {
        if (table.getSourceName() != null) {
            listTables.add(table.getSourceName());
        }
    }
    return div1;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)50 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)40 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 PersistenceException (org.talend.commons.exception.PersistenceException)16 Connection (org.talend.core.model.metadata.builder.connection.Connection)13 Item (org.talend.core.model.properties.Item)13 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 ArrayList (java.util.ArrayList)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 IElementParameter (org.talend.core.model.process.IElementParameter)10 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)9 Query (org.talend.core.model.metadata.builder.connection.Query)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 INode (org.talend.core.model.process.INode)7 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)6 ContextItem (org.talend.core.model.properties.ContextItem)6 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)6 Node (org.talend.designer.core.ui.editor.nodes.Node)6 List (java.util.List)5 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)5