1.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java Thu Apr 25 17:11:04 2013 +0200
1.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java Thu Apr 25 17:12:47 2013 +0200
1.3 @@ -437,6 +437,7 @@
1.4 JMenuItem item = (JMenuItem) e.getSource();
1.5 DatabaseConnection newConnection = (DatabaseConnection) item.getClientProperty(DATABASE_CONNECTION_KEY);
1.6 if (setConnection(newConnection)) {
1.7 + connectionProvider.setModuleInOracle(connection);
1.8 saveAndExecute();
1.9 }
1.10 }
2.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java Thu Apr 25 17:11:04 2013 +0200
2.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java Thu Apr 25 17:12:47 2013 +0200
2.3 @@ -47,6 +47,7 @@
2.4 import java.beans.PropertyChangeSupport;
2.5 import java.io.File;
2.6 import java.lang.reflect.InvocationTargetException;
2.7 +import java.sql.CallableStatement;
2.8 import java.sql.Connection;
2.9 import java.sql.Driver;
2.10 import java.sql.PreparedStatement;
2.11 @@ -57,6 +58,7 @@
2.12 import java.util.HashMap;
2.13 import java.util.List;
2.14 import java.util.Map;
2.15 +import java.util.MissingResourceException;
2.16 import java.util.Properties;
2.17 import java.util.Stack;
2.18 import java.util.logging.Level;
2.19 @@ -73,6 +75,7 @@
2.20 import org.openide.filesystems.FileUtil;
2.21 import org.openide.loaders.DataObject;
2.22 import org.openide.util.Exceptions;
2.23 +import org.openide.util.NbBundle;
2.24 import org.openide.util.RequestProcessor;
2.25 import org.openide.util.RequestProcessor.Task;
2.26
2.27 @@ -174,8 +177,7 @@
2.28
2.29 /**
2.30 *
2.31 - * @return The database URL of the primary database connection, empty String
2.32 - * if none is found.
2.33 + * @return The database URL of the primary database connection, empty String if none is found.
2.34 */
2.35 public String getPrimaryConnectionURL() {
2.36 String result = "";
2.37 @@ -307,7 +309,9 @@
2.38 }
2.39 }
2.40 logger.log(Level.FINEST, "Creating new connection. Total number of connections created={0}", ++connectionCount);
2.41 - return DatabaseConnection.create(templateConnection.getJDBCDriver(), templateConnection.getDatabaseURL(), templateConnection.getUser(), templateConnection.getSchema(), templateConnection.getPassword(), true, templateConnection.getDisplayName());
2.42 + connection = DatabaseConnection.create(templateConnection.getJDBCDriver(), templateConnection.getDatabaseURL(), templateConnection.getUser(), templateConnection.getSchema(), templateConnection.getPassword(), true, templateConnection.getDisplayName());
2.43 + setModuleInOracle(connection);
2.44 + return connection;
2.45 }
2.46 }
2.47
2.48 @@ -456,6 +460,35 @@
2.49 changeSupport.firePropertyChange(PROP_DATABASE_CONNECTIONS, oldConnections, newConnections);
2.50 }
2.51
2.52 + /*
2.53 + * This method attempts to set the module/program that is connecting to the database
2.54 + * using Oracle's 'Dbms_Application_Info.Set_Module' procedure. This will be useful
2.55 + * for tracing current connections in the DB created by NetBeans by querying 'v$sessions'
2.56 + */
2.57 + public void setModuleInOracle(final DatabaseConnection connection) {
2.58 + try {
2.59 + ResultSet rs = null;
2.60 + CallableStatement stmt = null;
2.61 + if (connection == null || connection.getJDBCConnection() == null) {
2.62 + return;
2.63 + }
2.64 + String appName = "";
2.65 + try {
2.66 + appName = NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project");
2.67 + } catch (MissingResourceException x) {
2.68 + appName = "NetBeans"; // NOI18N
2.69 + }
2.70 + String sqlProc = "{call Dbms_Application_Info.Set_Module(?,?)}";
2.71 + stmt = connection.getJDBCConnection().prepareCall(sqlProc);
2.72 + stmt.setString(1, appName);
2.73 + stmt.setString(2, "Main Program");
2.74 + stmt.executeUpdate();
2.75 + } catch (SQLException ex) {
2.76 + // Exceptions.printStackTrace(ex);
2.77 + logger.log(Level.WARNING, "Error when adding Module in v$Session");
2.78 + }
2.79 + }
2.80 +
2.81 public synchronized void connect(final DatabaseConnection connection) {
2.82 if (connection == null) {
2.83 return;
2.84 @@ -469,15 +502,16 @@
2.85 setOnline(true);
2.86 usagesEnabled = isFindUsagesEnabled();
2.87 }
2.88 - if (failedConnections.contains(connection.getName())) {
2.89 + if (failedConnections.contains(connection.getName())) {
2.90 failedConnections.remove(connection.getName());
2.91 - }
2.92 + }
2.93 return;
2.94 } else {
2.95 if (!failedConnections.contains(connection.getName())) {
2.96 if (SwingUtilities.isEventDispatchThread()) {
2.97 try {
2.98 ConnectionManager.getDefault().showConnectionDialog(connection);
2.99 + setModuleInOracle(connection);
2.100 } catch (NullPointerException e) {
2.101 failed = true;
2.102 } catch (IllegalStateException e) {
2.103 @@ -486,10 +520,10 @@
2.104 } else {
2.105 try {
2.106 SwingUtilities.invokeAndWait(new Runnable() {
2.107 -
2.108 @Override
2.109 public void run() {
2.110 ConnectionManager.getDefault().showConnectionDialog(connection);
2.111 + setModuleInOracle(connection);
2.112 }
2.113 });
2.114 } catch (InterruptedException e) {
2.115 @@ -502,11 +536,11 @@
2.116 if ((connection.getJDBCConnection() == null || connection.getJDBCConnection().isClosed())) {
2.117 if (SwingUtilities.isEventDispatchThread()) {
2.118 Task request = RP.post(new Runnable() {
2.119 -
2.120 @Override
2.121 public void run() {
2.122 try {
2.123 ConnectionManager.getDefault().connect(connection);
2.124 + setModuleInOracle(connection);
2.125 } catch (DatabaseException ex) {
2.126 }
2.127 }
2.128 @@ -519,6 +553,7 @@
2.129 } else {
2.130 try {
2.131 ConnectionManager.getDefault().connect(connection);
2.132 + setModuleInOracle(connection);
2.133 } catch (DatabaseException ex) {
2.134 failed = true;
2.135 }
2.136 @@ -531,8 +566,8 @@
2.137 failed = failed || !testConnection(connection);
2.138 if (failed) {
2.139 if (!failedConnections.contains(connection.getName())) {
2.140 - JOptionPane.showMessageDialog(null, "Can't connect to the database.");
2.141 - failedConnections.add(connection.getName());
2.142 + JOptionPane.showMessageDialog(null, "Can't connect to the database.");
2.143 + failedConnections.add(connection.getName());
2.144 }
2.145 }
2.146 if (databaseConnectionsAreEqual(connection, templateConnection)) {
2.147 @@ -542,9 +577,9 @@
2.148 }
2.149 }
2.150 if (!failed) {
2.151 - if (failedConnections.contains(connection.getName())) {
2.152 - failedConnections.remove(connection.getName());
2.153 - }
2.154 + if (failedConnections.contains(connection.getName())) {
2.155 + failedConnections.remove(connection.getName());
2.156 + }
2.157 }
2.158 }
2.159
2.160 @@ -619,6 +654,7 @@
2.161
2.162 /**
2.163 * Set Reverse Engineering DatabaseConnection
2.164 + *
2.165 * @param newConnection
2.166 */
2.167 public void setReverseConnection(DatabaseConnection newConnection) {
2.168 @@ -629,6 +665,7 @@
2.169
2.170 /**
2.171 * Returns Reverse Engineering DatabaseConnection
2.172 + *
2.173 * @return
2.174 */
2.175 public DatabaseConnection getReverseConnection() {
2.176 @@ -637,6 +674,7 @@
2.177
2.178 /**
2.179 * Returns true is Reverse Engineering DatabaseConnection has been set.
2.180 + *
2.181 * @return
2.182 */
2.183 public boolean hasReverseConnection() {
2.184 @@ -645,6 +683,7 @@
2.185
2.186 /**
2.187 * Returns true is Reverse Engineering DatabaseConnection is online.
2.188 + *
2.189 * @return
2.190 */
2.191 public boolean isReverseOnline() {