DBDataViewerIntegration

Integrating the DataView Module into the NetBeans Database Explorer

This page describes how we plan to integrate the DataView module into the Database Explorer. Please provide review comments at the end of this page

Contents


TODO

We also need a full UI spec, so that the logic can be consistent with the UI we want.

Integration algorithm (high-level)

Currently the DataView module has a class DataViewOutputPanel takes a DBConnectionDefinition and a query string.

    public DataViewOutputPanel(DBConnectionDefinition dbConn, String qs) throws Exception {

There instead needs to be an API that returns a list of panels, one for each result set:

  public class DBDataViewer {
    public static List<JPanel> createDataViews(DBConnectionDefinition dbConn, String queryString) {
      ...
    }
  }


The Database Explorer code that executes a query and displays a result can be found in SQLExecuteHelper.execute() in that db.core module, in the package
org.netbeans.modules.db.sql.execute

This class does the following:

  • Takes a string that represents all the SQL from the editor, and splits it into multiple statements. The private class
    SQLSplitter
    is responsible for this and is basically our very limited SQL parser
  • Iterates through each statement and executes it
  • Returns a single instance of SQLExecutionResult, which is used to populate the model for the results pane. This represents the results from the _last_ statement executed.
The
SQLExecuteHelper.execute()
method is called by a task thread in the class {SQLEditorSupport} in the db.core module in the package org.netbeans.modules.db.sql.loader. This thread executes the SQL and uses the results to populate the model for the results pane. We need to change what this task thread does to execute the SQL. Rather than asking
SQLExecuteHelper
to execute all of the statements and return an object representing the results from the last statement, it instead should do the following:
  • Make the top-level results panel a tabbed panel
  • We make the
    SQLSplitter
    a public class, and use it to split the SQL statements
  • For each statement, create a new instance of ResultsPanel.

So the code would look something like this:

DBConnectionDefinition conDef = new DBConnectionDefinition(dbConn.getName(), dbConn.getDriverClass(), dbConn.getDatabaseURL(), dbConn.getUser(), dbConn.getUser());

List<StatementInfo> statements = getStatements(script, startOffset, endOffset); // Uses SQLSplitter to split the statements

for (StatementInfo stmt : statements) {
  if (isUpdate(stmt) {
    // execute update and send results to output window
  } else {
    ResultsPanel panel = new ResultsPanel(conDef, stmt.getSQL());
    addResultPanel(panel); // add this panel as a tab to the top-level panel
  }
}


Questions/Comments

  • When the user executes the editor or a single statement, all previous results tabs are removed and we start fresh
  • If the user executes a single statement, a single results tab is displayed
  • Is it better to delegate non-result statements to the DataView module? I don't know if that makes sense, we could continue to handle non-result statements (DDL, DML) using our existing code.

Review Comments

Please add a section for each comment, so that we can track discussion.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo