EADS-3669: Use Dbms_Application_Info.Set_Module(module_, action_), minor improvments
authorRifki Razick <riralk@netbeans.org>
Wed, 24 Apr 2013 10:58:09 +0530
changeset 383107088021957
parent 382 dea0e289301c
child 385 6df018124382
EADS-3669: Use Dbms_Application_Info.Set_Module(module_, action_), minor improvments
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java
     1.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java	Wed Apr 24 08:49:17 2013 +0530
     1.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java	Wed Apr 24 10:58:09 2013 +0530
     1.3 @@ -58,6 +58,7 @@
     1.4  import java.util.HashMap;
     1.5  import java.util.List;
     1.6  import java.util.Map;
     1.7 +import java.util.MissingResourceException;
     1.8  import java.util.Properties;
     1.9  import java.util.Stack;
    1.10  import java.util.logging.Level;
    1.11 @@ -74,6 +75,7 @@
    1.12  import org.openide.filesystems.FileUtil;
    1.13  import org.openide.loaders.DataObject;
    1.14  import org.openide.util.Exceptions;
    1.15 +import org.openide.util.NbBundle;
    1.16  import org.openide.util.RequestProcessor;
    1.17  import org.openide.util.RequestProcessor.Task;
    1.18  
    1.19 @@ -175,8 +177,7 @@
    1.20  
    1.21      /**
    1.22       *
    1.23 -     * @return The database URL of the primary database connection, empty String
    1.24 -     * if none is found.
    1.25 +     * @return The database URL of the primary database connection, empty String if none is found.
    1.26       */
    1.27      public String getPrimaryConnectionURL() {
    1.28          String result = "";
    1.29 @@ -312,7 +313,7 @@
    1.30              setModuleInOracle(connection);
    1.31              return connection;
    1.32          }
    1.33 -    }                                
    1.34 +    }
    1.35  
    1.36      public DatabaseConnection getTemplateConnection() {
    1.37          if (templateConnection != null) {
    1.38 @@ -458,29 +459,40 @@
    1.39          this.debugConnection = null;
    1.40          changeSupport.firePropertyChange(PROP_DATABASE_CONNECTIONS, oldConnections, newConnections);
    1.41      }
    1.42 -    
    1.43 -    public void setModuleInOracle(final DatabaseConnection connection){
    1.44 +
    1.45 +    /*
    1.46 +     * This method attempts to set the module/program that is connecting to the database
    1.47 +     * using Oracle's 'Dbms_Application_Info.Set_Module' procedure. This will be useful 
    1.48 +     * for tracing current connections in the DB created by NetBeans by querying 'v$sessions'
    1.49 +     */
    1.50 +    public void setModuleInOracle(final DatabaseConnection connection) {
    1.51          try {
    1.52              ResultSet rs = null;
    1.53 -            CallableStatement stmt=null;
    1.54 +            CallableStatement stmt = null;
    1.55              if (connection == null || connection.getJDBCConnection() == null) {
    1.56                  return;
    1.57              }
    1.58 +            String appName = "";
    1.59 +            try {
    1.60 +                appName = NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project");
    1.61 +            } catch (MissingResourceException x) {
    1.62 +                appName = "NetBeans"; // NOI18N
    1.63 +            }
    1.64              String sqlProc = "{call Dbms_Application_Info.Set_Module(?,?)}";
    1.65 -                stmt = connection.getJDBCConnection().prepareCall(sqlProc);
    1.66 -                stmt.setString(1, "NetBeans");
    1.67 -                stmt.setString(2, "Main Program");
    1.68 -                stmt.executeUpdate();
    1.69 +            stmt = connection.getJDBCConnection().prepareCall(sqlProc);
    1.70 +            stmt.setString(1, appName);
    1.71 +            stmt.setString(2, "Main Program");
    1.72 +            stmt.executeUpdate();
    1.73          } catch (SQLException ex) {
    1.74 -           // Exceptions.printStackTrace(ex);
    1.75 -             logger.log(Level.WARNING, "Error when adding Module in v$Session");
    1.76 +            // Exceptions.printStackTrace(ex);
    1.77 +            logger.log(Level.WARNING, "Error when adding Module in v$Session");
    1.78          }
    1.79      }
    1.80  
    1.81      public synchronized void connect(final DatabaseConnection connection) {
    1.82          if (connection == null) {
    1.83              return;
    1.84 -        }        
    1.85 +        }
    1.86          boolean onlineBeforeConnect = isOnline();
    1.87          boolean failed = false;
    1.88          try {
    1.89 @@ -490,9 +502,9 @@
    1.90                      setOnline(true);
    1.91                      usagesEnabled = isFindUsagesEnabled();
    1.92                  }
    1.93 -                if (failedConnections.contains(connection.getName())) { 
    1.94 +                if (failedConnections.contains(connection.getName())) {
    1.95                      failedConnections.remove(connection.getName());
    1.96 -                }                  
    1.97 +                }
    1.98                  return;
    1.99              } else {
   1.100                  if (!failedConnections.contains(connection.getName())) {
   1.101 @@ -508,11 +520,10 @@
   1.102                      } else {
   1.103                          try {
   1.104                              SwingUtilities.invokeAndWait(new Runnable() {
   1.105 -
   1.106                                  @Override
   1.107                                  public void run() {
   1.108                                      ConnectionManager.getDefault().showConnectionDialog(connection);
   1.109 -                                    setModuleInOracle(connection);                                    
   1.110 +                                    setModuleInOracle(connection);
   1.111                                  }
   1.112                              });
   1.113                          } catch (InterruptedException e) {
   1.114 @@ -525,7 +536,6 @@
   1.115                  if ((connection.getJDBCConnection() == null || connection.getJDBCConnection().isClosed())) {
   1.116                      if (SwingUtilities.isEventDispatchThread()) {
   1.117                          Task request = RP.post(new Runnable() {
   1.118 -
   1.119                              @Override
   1.120                              public void run() {
   1.121                                  try {
   1.122 @@ -556,8 +566,8 @@
   1.123          failed = failed || !testConnection(connection);
   1.124          if (failed) {
   1.125              if (!failedConnections.contains(connection.getName())) {
   1.126 -               JOptionPane.showMessageDialog(null, "Can't connect to the database.");
   1.127 -               failedConnections.add(connection.getName());
   1.128 +                JOptionPane.showMessageDialog(null, "Can't connect to the database.");
   1.129 +                failedConnections.add(connection.getName());
   1.130              }
   1.131          }
   1.132          if (databaseConnectionsAreEqual(connection, templateConnection)) {
   1.133 @@ -567,9 +577,9 @@
   1.134              }
   1.135          }
   1.136          if (!failed) {
   1.137 -           if (failedConnections.contains(connection.getName())) { 
   1.138 -               failedConnections.remove(connection.getName());
   1.139 -           }
   1.140 +            if (failedConnections.contains(connection.getName())) {
   1.141 +                failedConnections.remove(connection.getName());
   1.142 +            }
   1.143          }
   1.144      }
   1.145  
   1.146 @@ -644,6 +654,7 @@
   1.147  
   1.148      /**
   1.149       * Set Reverse Engineering DatabaseConnection
   1.150 +     *
   1.151       * @param newConnection
   1.152       */
   1.153      public void setReverseConnection(DatabaseConnection newConnection) {
   1.154 @@ -654,6 +665,7 @@
   1.155  
   1.156      /**
   1.157       * Returns Reverse Engineering DatabaseConnection
   1.158 +     *
   1.159       * @return
   1.160       */
   1.161      public DatabaseConnection getReverseConnection() {
   1.162 @@ -662,6 +674,7 @@
   1.163  
   1.164      /**
   1.165       * Returns true is Reverse Engineering DatabaseConnection has been set.
   1.166 +     *
   1.167       * @return
   1.168       */
   1.169      public boolean hasReverseConnection() {
   1.170 @@ -670,6 +683,7 @@
   1.171  
   1.172      /**
   1.173       * Returns true is Reverse Engineering DatabaseConnection is online.
   1.174 +     *
   1.175       * @return
   1.176       */
   1.177      public boolean isReverseOnline() {