Search in sources :

Example 1 with ExecSQLAction

use of net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction in project tdq-studio-se by Talend.

the class SqlexplorerService method runInDQViewer.

/**
 * open the sql editor and run it.
 *
 * @param alias
 * @param databaseConnection
 * @param lEditorName
 * @param query
 */
private void runInDQViewer(Alias alias, DatabaseConnection databaseConnection, String lEditorName, String query) {
    String url = JavaSqlFactory.getURL(databaseConnection);
    String username = JavaSqlFactory.getUsername(databaseConnection);
    String password = JavaSqlFactory.getPassword(databaseConnection);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    SQLEditorInput input = new SQLEditorInput("SQL Editor (" + alias.getName() + "." + lEditorName + ").sql");
    User user = alias.getUser(username);
    if (PluginConstant.EMPTY_STRING.equals(username)) {
        // get the user both the dbtype and username are the same.
        if (!alias.getUrl().equals(url)) {
            user = new net.sourceforge.sqlexplorer.dbproduct.User(username, password);
            user.setAlias(alias);
            alias.addUser(user);
        }
    } else {
        if (user == null) {
            user = alias.getDefaultUser();
        }
    }
    alias.setDefaultUser(user);
    // create the hive connection
    if (databaseConnection != null) {
        user.setDatabaseConnection(databaseConnection);
        // if ManagedDriver class is not Loaded,check if it lack jars then update the realted jar.
        updateDriverIfClassNotLoad(databaseConnection);
    }
    input.setUser(user);
    // TDQ-9533 append a "limit X" in sql query for vertica database.
    if (EDatabaseTypeName.VERTICA.getProduct().equals(databaseConnection.getProductId())) {
        String maxPref = SQLExplorerPlugin.getDefault().getPreferenceStore().getString(IConstants.MAX_SQL_ROWS);
        int maxNum = maxPref == null ? 100 : Integer.parseInt(maxPref);
        query = query + " limit " + maxNum;
    }
    IWorkbenchPage page = SQLExplorerPlugin.getDefault().getActivePage();
    try {
        SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
        editorPart.setText(query);
        new ExecSQLAction(editorPart).run();
    } catch (PartInitException e) {
        log.error(e, e);
    }
}
Also used : SQLEditorInput(net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput) SQLEditor(net.sourceforge.sqlexplorer.plugin.editors.SQLEditor) User(net.sourceforge.sqlexplorer.dbproduct.User) ExecSQLAction(net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction) User(net.sourceforge.sqlexplorer.dbproduct.User) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with ExecSQLAction

use of net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction in project tdq-studio-se by Talend.

the class SQLTextEditor method createSourceViewer.

@Override
protected ISourceViewer createSourceViewer(final Composite parent, IVerticalRuler ruler, int style) {
    parent.setLayout(new FillLayout());
    final Composite myParent = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0;
    myParent.setLayout(layout);
    // create divider line
    Composite div1 = new Composite(myParent, SWT.NONE);
    GridData lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL;
    lgid.heightHint = 1;
    lgid.verticalIndent = 1;
    div1.setLayoutData(lgid);
    div1.setBackground(editor.getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
    // create text viewer
    GridData gid = new GridData();
    gid.grabExcessHorizontalSpace = gid.grabExcessVerticalSpace = true;
    gid.horizontalAlignment = gid.verticalAlignment = GridData.FILL;
    Dictionary dictionary = null;
    if (editor.getSession() != null && _enableContentAssist) {
        dictionary = editor.getSession().getUser().getMetaDataSession().getDictionary();
    }
    sqlTextViewer = new SQLTextViewer(myParent, style, store, dictionary, ruler);
    sqlTextViewer.getControl().setLayoutData(gid);
    // create bottom divider line
    Composite div2 = new Composite(myParent, SWT.NONE);
    lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL;
    lgid.heightHint = 1;
    lgid.verticalIndent = 0;
    div2.setLayoutData(lgid);
    div2.setBackground(editor.getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
    final SQLEditor thisEditor = editor;
    sqlTextViewer.getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {

        private ExecSQLAction _execSQLAction = new ExecSQLAction(thisEditor);

        @Override
        public void verifyKey(VerifyEvent event) {
            if (event.stateMask == SWT.CTRL && event.keyCode == 13) {
                event.doit = false;
                _execSQLAction.run();
            }
        }
    });
    sqlTextViewer.getTextWidget().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            SQLTextEditor.this.editor.getEditorSite().getPage().activate(SQLTextEditor.this.editor.getEditorSite().getPart());
        }
    });
    myParent.layout();
    IDocument dc = new Document();
    sqlTextViewer.setDocument(dc);
    mcl.install(sqlTextViewer);
    return sqlTextViewer;
}
Also used : Dictionary(net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary) Composite(org.eclipse.swt.widgets.Composite) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) ExecSQLAction(net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction) KeyAdapter(org.eclipse.swt.events.KeyAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) SQLTextViewer(net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) VerifyEvent(org.eclipse.swt.events.VerifyEvent) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ExecSQLAction (net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction)2 User (net.sourceforge.sqlexplorer.dbproduct.User)1 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)1 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)1 Dictionary (net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary)1 SQLTextViewer (net.sourceforge.sqlexplorer.sqleditor.SQLTextViewer)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 VerifyEvent (org.eclipse.swt.events.VerifyEvent)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 PartInitException (org.eclipse.ui.PartInitException)1