Пример #1
0
  /**
   * Called when a session started. Add commands to popup menu in object tree.
   *
   * @param session The session that is starting.
   * @return An implementation of PluginSessionCallback or null to indicate the plugin does not work
   *     with this session
   */
  public PluginSessionCallback sessionStarted(ISession session) {
    // Adds the view and procedure script actions if the session is DB2.
    addTreeNodeMenuActionsForDB2(session);

    // Register a custom ISQLExecutionListener implementation that simply prints all SQL being
    // executed to
    // the message panel.
    IMessageHandler messageHandler = session.getApplication().getMessageHandler();
    ExampleSqlExecutionListener sqlExecutionListener =
        new ExampleSqlExecutionListener(messageHandler);
    session.getSessionSheet().getSQLPaneAPI().addSQLExecutionListener(sqlExecutionListener);

    // We will override the default behavior of formatting exception messages that SQuirreL provides
    // for
    // this session with our own.  If this was a real plugin implementation, care would need to be
    // taken
    // that the custom formatter is only applied to database vendor sessions that this plugin was
    // written
    // for.  SQuirreL doesn't support registering multiple exception formatters for a single
    // session.  The
    // last one to register overrides all former registrations and results in a log warning message.
    session.setExceptionFormatter(new ExampleExceptionFormatter());

    return new PluginSessionCallbackAdaptor(this);
  }
Пример #2
0
  /**
   * Called when a session shutdown.
   *
   * @param session The session that is ending.
   */
  public void sessionEnding(ISession session) {
    super.sessionEnding(session);

    session.removePluginObject(this, IConstants.ISessionKeys.PREFS);
    _prefListeners.remove(session.getIdentifier());
    _sqlEntryFactoryProxy.sessionEnding(session);
  }
Пример #3
0
 /** Create the <TT>IDataSet</TT> to be displayed in this tab. */
 protected IDataSet createDataSet() throws DataSetException {
   final ISession session = getSession();
   try {
     final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
     return new ObjectArrayDataSet(md.getCatalogs());
   } catch (SQLException ex) {
     throw new DataSetException(ex);
   }
 }
Пример #4
0
 /**
  * Returns true if the ObjectTree tab is selected.
  *
  * @return Returns true if the ObjectTree tab is selected. false is returned otherwise.
  */
 private boolean objectTreeTabIsSelected() {
   boolean result = false;
   ISession session = _treePanel.getSession();
   if (session != null) {
     SessionPanel sessionPanel = session.getSessionSheet();
     if (sessionPanel != null) {
       result = sessionPanel.isObjectTreeTabSelected();
     }
   }
   return result;
 }
Пример #5
0
    public void load(ISession session, PreparedStatement stmt) {
      ResultSet rs = null;
      try {
        rs = stmt.executeQuery();
        StringBuffer buf = new StringBuffer(4096);
        while (rs.next()) {
          String line1 = rs.getString(1);
          String line2 = rs.getString(2);
          buf.append(line1.trim() + " ");
          buf.append(line2.trim() + " ");
        }
        String source = "";
        if (buf.length() == 0 && sourceType == TABLE_TYPE) {
          ISQLDatabaseMetaData md = session.getMetaData();
          // TODO: Need to define a better approach to getting dialects.
          // That is, we don't really want to ever prompt the user in this
          // case.  It's always Oracle.  Yet, we may have a new OracleDialect
          // at some point.
          HibernateDialect dialect = DialectFactory.getDialect("Oracle");

          // TODO: How to let the user customize this??
          CreateScriptPreferences prefs = new CreateScriptPreferences();

          ITableInfo[] tabs = new ITableInfo[] {(ITableInfo) getDatabaseObjectInfo()};
          List<ITableInfo> tables = Arrays.asList(tabs);
          // Handle table source
          List<String> sqls = dialect.getCreateTableSQL(tables, md, prefs, false);
          String sep = session.getQueryTokenizer().getSQLStatementSeparator();
          for (String sql : sqls) {
            buf.append(sql);
            buf.append(sep);
            buf.append("\n");
          }
          source = buf.toString();
        } else {
          if (s_log.isDebugEnabled()) {
            s_log.debug("View source before formatting: " + buf.toString());
          }
          source = formatter.reformat(buf.toString());
        }
        getTextArea().setText(source);
        getTextArea().setCaretPosition(0);
      } catch (SQLException ex) {
        s_log.error("Unexpected exception: " + ex.getMessage(), ex);
        session.showErrorMessage(ex);
      } finally {
        SQLUtilities.closeResultSet(rs);
      }
    }
Пример #6
0
  private void initSessionSheet(ISession session) {
    ActionCollection coll = getApplication().getActionCollection();
    session.addSeparatorToToolbar();
    session.addToToolbar(coll.get(FindAction.class));
    session.addToToolbar(coll.get(ReplaceAction.class));
    session.addToToolbar(coll.get(ConfigureAutoCorrectAction.class));

    SessionInternalFrame sif = session.getSessionInternalFrame();

    ISQLPanelAPI sqlPanelAPI = sif.getSQLPanelAPI();

    new ToolsPopupHandler(this).initToolsPopup(sif, coll);

    completeSqlPanelEntryAreaMenu(coll, sqlPanelAPI);
  }
Пример #7
0
  /**
   * Called when a session created but the UI hasn't been built for the session.
   *
   * @param session The session that is starting.
   */
  public void sessionCreated(ISession session) {
    SyntaxPreferences prefs = null;

    try {
      prefs = (SyntaxPreferences) _newSessionPrefs.clone();
    } catch (CloneNotSupportedException ex) {
      throw new InternalError("CloneNotSupportedException for SyntaxPreferences");
    }

    session.putPluginObject(this, IConstants.ISessionKeys.PREFS, prefs);

    SessionPreferencesListener lis = new SessionPreferencesListener(this, session);
    prefs.addPropertyChangeListener(lis);
    _prefListeners.put(session.getIdentifier(), lis);
  }
Пример #8
0
  public ExplainExecuterPanel(ISession session) {
    _session = session;
    _dialectType = DialectFactory.getDialectType(_session.getMetaData());
    _session
        .getProperties()
        .addPropertyChangeListener(
            new PropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent evt) {
                onPropertyChange(evt.getPropertyName());
              }
            });

    createGUI();
  }
Пример #9
0
 private void validateSQL() {
   final ISQLPanelAPI api = _session.getSQLPanelAPI(_plugin);
   final String sql = api.getSQLScriptToBeExecuted();
   if (sql != null && sql.trim().length() > 0) {
     final SessionProperties sessionProps = _session.getProperties();
     final WebServiceSessionProperties wssProps = _plugin.getWebServiceSessionProperties(_session);
     final char stmtSepChar = sessionProps.getSQLStatementSeparatorChar();
     final String solComment = sessionProps.getStartOfLineComment();
     final ValidationProps valProps =
         new ValidationProps(
             _prefs, wssProps, _session.getMessageHandler(), sql, stmtSepChar, solComment);
     new Executor(_session.getApplication(), valProps).execute();
   } else {
     _session.getMessageHandler().showErrorMessage("No SQL specified");
   }
 }
 public ObjectResultController(ISession session, HibernatePluginResources resource) {
   _session = session;
   _resource = resource;
   final SessionProperties props = session.getProperties();
   _objectResultTabbedPane =
       UIFactory.getInstance().createTabbedPane(props.getSQLExecutionTabPlacement());
 }
  public synchronized void toggleCurrentSQLResultTabSticky() {
    if (null != _stickyTab) {
      if (_stickyTab.equals(_tabbedExecutionsPanel.getSelectedComponent())) {
        // Sticky is turned off. Just remove sticky and return.
        _stickyTab = null;
        _tabbedExecutionsPanel.setIconAt(_tabbedExecutionsPanel.getSelectedIndex(), null);
        return;

      } else {
        // remove old sticky tab
        int indexOfStickyTab = getIndexOfTab(_stickyTab);
        if (-1 != indexOfStickyTab) {
          _tabbedExecutionsPanel.setIconAt(indexOfStickyTab, null);
        }
        _stickyTab = null;
      }
    }

    if (false == _tabbedExecutionsPanel.getSelectedComponent() instanceof IResultTab) {
      // i18n[SQLResultExecuterPanel.nonStickyPanel=Cannot make a cancel panel sticky]
      String msg = s_stringMgr.getString("SQLResultExecuterPanel.nonStickyPanel");
      JOptionPane.showMessageDialog(_session.getApplication().getMainFrame(), msg);
      return;
    }

    _stickyTab = (IResultTab) _tabbedExecutionsPanel.getSelectedComponent();
    int selectedIndex = _tabbedExecutionsPanel.getSelectedIndex();

    ImageIcon icon = getStickyIcon();

    _tabbedExecutionsPanel.setIconAt(selectedIndex, icon);
  }
  /**
   * Sesssion is ending. Remove all listeners that this component has setup. Close all torn off
   * result tab windows.
   */
  void sessionClosing() {
    if (_propsListener != null) {
      _session.getProperties().removePropertyChangeListener(_propsListener);
      _propsListener = null;
    }

    closeAllSQLResultFrames();
  }
  private void initAccelerator(Class<? extends Action> actionClass, JMenuItem mnuItem) {
    Action action = _session.getApplication().getActionCollection().get(actionClass);

    String accel = (String) action.getValue(Resources.ACCELERATOR_STRING);
    if (null != accel && 0 != accel.trim().length()) {
      mnuItem.setAccelerator(KeyStroke.getKeyStroke(accel));
    }
  }
  private void propertiesHaveChanged(String propName) {
    final SessionProperties props = _session.getProperties();

    if (propName == null || propName.equals(SessionProperties.IPropertyNames.AUTO_COMMIT)) {
      SetAutoCommitTask task = new SetAutoCommitTask();
      if (SwingUtilities.isEventDispatchThread()) {
        _session.getApplication().getThreadPool().addTask(task);
      } else {
        task.run();
      }
    }

    if (propName == null
        || propName.equals(SessionProperties.IPropertyNames.SQL_EXECUTION_TAB_PLACEMENT)) {
      _tabbedExecutionsPanel.setTabPlacement(props.getSQLExecutionTabPlacement());
    }
  }
Пример #15
0
  private static Frame ctorHelper(
      ISession session, MssqlPlugin plugin, IDatabaseObjectInfo[] dbObjs) {
    if (session == null) throw new IllegalArgumentException("ISession == null");
    if (plugin == null) throw new IllegalArgumentException("MssqlPlugin == null");
    if (dbObjs == null) throw new IllegalArgumentException("IDatabaseObjectInfo[] is null");

    return session.getApplication().getMainFrame();
  }
 /**
  * Set the current session.
  *
  * @param session Current session.
  * @throws IllegalArgumentException Thrown if a <TT>null</TT> <TT>ISession</TT> passed.
  */
 public synchronized void setSession(ISession session) {
   if (session == null) {
     throw new IllegalArgumentException("Null ISession passed");
   }
   sessionClosing();
   _session = session;
   _propsListener = new MyPropertiesListener();
   _session.getProperties().addPropertyChangeListener(_propsListener);
 }
Пример #17
0
  @Override
  public void execute(ISQLEntryPanel parent, ExecutionScope executionScope) {
    String sql = parent.getSQLToBeExecuted();
    if (sql == null || sql.length() == 0) return;

    SQLExecuterTask executer =
        new SQLExecuterTask(_session, getExplainSql(sql), new SQLExecutionHandler());
    _session.getApplication().getThreadPool().addTask(executer);
  }
  private ImageIcon getStickyIcon() {
    ActionCollection actionCollection = _session.getApplication().getActionCollection();

    ImageIcon icon =
        (ImageIcon)
            actionCollection
                .get(ToggleCurrentSQLResultTabStickyAction.class)
                .getValue(Action.SMALL_ICON);
    return icon;
  }
Пример #19
0
  private void addTreeNodeMenuActionsForDB2(ISession session) {
    try {
      if (DialectFactory.isDB2(session.getMetaData())) {
        // Plugin knows only how to script Views and Stored Procedures on DB2.
        // So if it's not a DB2 Session we tell SQuirreL the Plugin should not be used.

        // Add context menu items to the object tree's view and procedure nodes.
        IObjectTreeAPI otApi = session.getSessionInternalFrame().getObjectTreeAPI();
        otApi.addToPopup(
            DatabaseObjectType.VIEW,
            new ScriptDB2ViewAction(session.getApplication(), _resources, session));
        otApi.addToPopup(
            DatabaseObjectType.PROCEDURE,
            new ScriptDB2ProcedureAction(session.getApplication(), _resources, session));
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Пример #20
0
  private void createGUI() {
    setLayout(new BorderLayout());

    _tabbedExecutionsPanel =
        UIFactory.getInstance()
            .createTabbedPane(_session.getProperties().getSQLExecutionTabPlacement());

    initTabPopup();

    add(_tabbedExecutionsPanel, BorderLayout.CENTER);
  }
  private void createGUI() {
    final SessionProperties props = _session.getProperties();
    _tabbedExecutionsPanel =
        UIFactory.getInstance().createTabbedPane(props.getSQLExecutionTabPlacement(), true);

    createTabPopup();

    setLayout(new BorderLayout());

    add(_tabbedExecutionsPanel, BorderLayout.CENTER);
  }
  private void checkResultTabLimit() {
    SessionProperties props = _session.getProperties();

    while (props.getLimitSQLResultTabs()
        && props.getSqlResultTabLimit() < _tabbedExecutionsPanel.getTabCount()) {
      if (_tabbedExecutionsPanel.getComponentAt(0) instanceof CancelPanel) {
        break;
      }
      closeTabAt(0);
    }
  }
  /** @see ISQLEntryPanelFactory#createSQLEntryPanel() */
  public ISQLEntryPanel createSQLEntryPanel(ISession session) throws IllegalArgumentException {
    if (session == null) {
      throw new IllegalArgumentException("Null ISession passed");
    }

    JeditPreferences prefs =
        (JeditPreferences) session.getPluginObject(_plugin, JeditConstants.ISessionKeys.PREFS);
    if (prefs.getUseJeditTextControl()) {
      JeditSQLEntryPanel pnl =
          (JeditSQLEntryPanel)
              session.getPluginObject(_plugin, JeditConstants.ISessionKeys.JEDIT_SQL_ENTRY_CONTROL);
      if (pnl == null) {
        pnl = new JeditSQLEntryPanel(session, _plugin, prefs);
        //				final JEditTextArea ta = pnl.getTypedComponent();
        session.putPluginObject(_plugin, JeditConstants.ISessionKeys.JEDIT_SQL_ENTRY_CONTROL, pnl);
      }
      return pnl;
    }
    session.removePluginObject(_plugin, JeditConstants.ISessionKeys.JEDIT_SQL_ENTRY_CONTROL);
    return _originalFactory.createSQLEntryPanel(session);
  }
Пример #24
0
  private void btCreateTableActionPerformed(java.awt.event.ActionEvent evt) {
    ISQLConnection con = _session.getSQLConnection();
    String query = getQuery();
    Statement stmt = null;
    try {
      stmt = con.createStatement();
      stmt.execute(query);
      _session.getSessionInternalFrame().getObjectTreeAPI().refreshTree();
      jd.setVisible(false);
      jd.dispose();
      JOptionPane.showMessageDialog(
          null,
          // i18n[mysql.msgTableCreated=Table {0} created]
          s_stringMgr.getString("mysql.msgTableCreated", tfTableName.getText()));
    } catch (SQLException ex) {
      _session.showErrorMessage(ex);

    } finally {
      SQLUtilities.closeStatement(stmt);
    }
  }
  public void execute(ISQLEntryPanel sqlPanel) {
    removeErrorPanels();

    String sql = sqlPanel.getSQLToBeExecuted();
    if (sql != null && sql.length() > 0) {
      executeSQL(sql);
    } else {
      // i18n[SQLResultExecuterPanel.nosqlselected=No SQL selected for execution.]
      String msg = s_stringMgr.getString("SQLResultExecuterPanel.nosqlselected");
      _session.showErrorMessage(msg);
    }
  }
Пример #26
0
    public void propertyChange(PropertyChangeEvent evt) {
      String propName = evt.getPropertyName();

      if (false == SyntaxPreferences.IPropertyNames.USE_RSYNTAX_CONTROL.equals(propName)) {

        // Not the Textcontrol itself changed but some other of the Syntax Preferences, for example
        // a
        // color.
        // So we tell the current control to update the preferences.
        Object pluginObject =
            _session.getPluginObject(_plugin, IConstants.ISessionKeys.SQL_ENTRY_CONTROL);

        if (pluginObject instanceof RSyntaxSQLEntryPanel) {
          ((RSyntaxSQLEntryPanel) pluginObject).updateFromPreferences();
        }
      } else {
        /*
        We don't support switching the entry control during a session
        because serveral things, that are attached to the entry control
        from outside this plugin would need to reinitialze too.
        For example code completion and edit extras.

        synchronized (_session)
        {
        	ISQLEntryPanelFactory factory = _plugin.getSQLEntryAreaFactory();
        	ISQLEntryPanel pnl = factory.createSQLEntryPanel(_session);
        	_session.getSQLPanelAPI(_plugin).installSQLEntryPanel(pnl);
        }
        */

        String msg =
            // i18n[syntax.switchingNotSupported=Switching the editor of a runninig session is not
            // supported.\nYou may switch the entry area in the New Session Properties dialog]
            s_stringMgr.getString("syntax.switchingNotSupported");

        JOptionPane.showMessageDialog(_session.getApplication().getMainFrame(), msg);

        throw new SyntaxPrefChangeNotSupportedException();
      }
    }
Пример #27
0
 public void actionPerformed(ActionEvent evt) {
   if (_session != null) {
     try {
       // new InQuotesCommand(_session.getSQLPanelAPI(_plugin)).execute();
       new InQuotesCommand(FrameWorkAcessor.getSQLPanelAPI(_session, _plugin)).execute();
     } catch (Throwable ex) {
       // i18n[editextras.errorQuoteSql=Error processing Quote SQL command: {0}]
       final String msg = s_stringMgr.getString("editextras.errorQuoteSql", ex);
       _session.showErrorMessage(msg);
       s_log.error(msg, ex);
     }
   }
 }
Пример #28
0
  public void actionPerformed(ActionEvent evt) {
    if (_session != null) {
      ObjectTreeNode[] selectedNodes =
          _session.getSessionSheet().getObjectTreePanel().getSelectedNodes();

      Positioner positioner = new Positioner();
      GraphController toAddTo = null;

      for (int i = 0; i < selectedNodes.length; i++) {
        if (selectedNodes[i].getDatabaseObjectType() == DatabaseObjectType.TABLE) ;
        {
          if (null == toAddTo) {
            GraphController[] controllers = _plugin.getGraphControllers(_session);
            if (0 == controllers.length) {
              toAddTo = _plugin.createNewGraphControllerForSession(_session, false);
            } else {
              GraphSelectionDialogController dlg =
                  new GraphSelectionDialogController(
                      controllers, _session.getApplication().getMainFrame());
              dlg.doModal();

              if (false == dlg.isOK()) {
                return;
              }
              if (null == dlg.getSelectedController()) {
                toAddTo = _plugin.createNewGraphControllerForSession(_session, false);
              } else {
                toAddTo = dlg.getSelectedController();
              }
            }
          }

          toAddTo.addTable(selectedNodes[i], positioner);
        }
      }
    }
  }
  /**
   * Create the child nodes for the passed parent node and return them. Note that this method should
   * <B>not</B> actually add the child nodes to the parent node as this is taken care of in the
   * caller.
   *
   * @param session Current session.
   * @param node Node to be expanded.
   * @return A list of <TT>ObjectTreeNode</TT> objects representing the child nodes for the passed
   *     node.
   */
  public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode)
      throws SQLException {
    final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
    final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
    final ISQLConnection conn = session.getSQLConnection();
    final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
    final String catalogName = parentDbinfo.getCatalogName();
    final String schemaName = parentDbinfo.getSchemaName();
    final ObjFilterMatcher filterMatcher = new ObjFilterMatcher(session.getProperties());

    String sql = SQL;
    if (isOS400) {
      sql = OS_400_SQL;
    }

    final PreparedStatement pstmt = conn.prepareStatement(sql);
    ResultSet rs = null;
    try {
      pstmt.setString(1, schemaName);
      pstmt.setString(2, filterMatcher.getSqlLikeMatchString());
      rs = pstmt.executeQuery();
      while (rs.next()) {
        IDatabaseObjectInfo si =
            new DatabaseObjectInfo(
                catalogName, schemaName, rs.getString(1), DatabaseObjectType.SEQUENCE, md);

        if (filterMatcher.matches(si.getSimpleName())) {
          childNodes.add(new ObjectTreeNode(session, si));
        }
      }
    } finally {
      SQLUtilities.closeResultSet(rs);
      SQLUtilities.closeStatement(pstmt);
    }
    return childNodes;
  }
Пример #30
0
  private void secureAddTab(ExplainTab tab) {
    SessionProperties props = _session.getProperties();

    if (s_log.isDebugEnabled()) {
      s_log.debug("secureAddTab - TabCount: " + _tabbedExecutionsPanel.getTabCount());
      s_log.debug("secureAddTab - Limited?: " + props.getLimitSQLResultTabs());
      s_log.debug("secureAddTab - TabLimit: " + props.getSqlResultTabLimit());
    }

    if (props.getLimitSQLResultTabs()
        && props.getSqlResultTabLimit() <= _tabbedExecutionsPanel.getTabCount()) {
      closeTabAt(0);
    }
    _tabbedExecutionsPanel.addTab(tab.getTitle(), null, tab, tab.getToolTip());
    _tabbedExecutionsPanel.setSelectedComponent(tab);
  }