EADS-3597 - use NB way of showing connections instead EADS-3585
authorchrislovsund@netbeans.org
Thu, 23 May 2013 14:23:18 +0200
branchEADS-3585
changeset 408518fc1b75b79
parent 407 315a62f4569b
child 409 c511bf62239a
EADS-3597 - use NB way of showing connections instead
added new executor to lookup of DataObject, to access connection.
added JComboBox with projects connections (instead of add in to execute DropDownButton
changed PlsqlExecuteAction to use new executor
todo: debug is no longer working
Options/src/org/netbeans/modules/plsqlsupport/options/OptionsUtilities.java
PLSQL/Debugging/src/org/netbeans/modules/plsql/debug/PlsqlDebugAction.java
PLSQL/Debugging/src/org/netbeans/modules/plsql/debug/layer.xml
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/Bundle.properties
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/ConnectionAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CurrentDatabaseToolbarInfo.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/DescribeAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlCommitAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlMultipleExecuteAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlRollbackAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/DeployFilesAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/layer.xml
PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlDataObject.java
PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlEditor.java
PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/PlsqlFileValidatorService.java
PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/validation/PlsqlFileValidatorServiceImpl.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionExecutor.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionHolder.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionNewExecutor.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseTransaction.java
     1.1 --- a/Options/src/org/netbeans/modules/plsqlsupport/options/OptionsUtilities.java	Wed May 22 16:22:11 2013 +0530
     1.2 +++ b/Options/src/org/netbeans/modules/plsqlsupport/options/OptionsUtilities.java	Thu May 23 14:23:18 2013 +0200
     1.3 @@ -64,6 +64,10 @@
     1.4     private OptionsUtilities() {
     1.5     } //singleton
     1.6  
     1.7 +   /**
     1.8 +    * 
     1.9 +    * @return true if the option to auto deploy all database connections have been selected.
    1.10 +    */
    1.11     public static boolean isDeployNoPromptEnabled() {
    1.12        return !NbPreferences.forModule(GeneralPanel.class).getBoolean(AUTO_DEPLOY_ALL_DATABASES_KEY, true);
    1.13     }
     2.1 --- a/PLSQL/Debugging/src/org/netbeans/modules/plsql/debug/PlsqlDebugAction.java	Wed May 22 16:22:11 2013 +0530
     2.2 +++ b/PLSQL/Debugging/src/org/netbeans/modules/plsql/debug/PlsqlDebugAction.java	Thu May 23 14:23:18 2013 +0200
     2.3 @@ -102,7 +102,9 @@
     2.4     @ActionReference(path = "Shortcuts", name = "DS-D"),
     2.5     @ActionReference(path = "Shortcuts", name = "OS-D"),
     2.6     @ActionReference(path = "Editors/text/x-plsql/Popup", name = "org-netbeans-modules-plsql-debug-PlsqlDebugAction",
     2.7 -   position = 1020, separatorAfter = 1050)
     2.8 +           position = 1020, separatorAfter = 1050),
     2.9 +   @ActionReference(path = "Editors/text/x-plsql/Toolbars/Default", name = "org-netbeans-modules-plsql-debug-PlsqlDebugAction",
    2.10 +           position = 250)
    2.11  })
    2.12  public final class PlsqlDebugAction extends CookieAction {
    2.13  
     3.1 --- a/PLSQL/Debugging/src/org/netbeans/modules/plsql/debug/layer.xml	Wed May 22 16:22:11 2013 +0530
     3.2 +++ b/PLSQL/Debugging/src/org/netbeans/modules/plsql/debug/layer.xml	Thu May 23 14:23:18 2013 +0200
     3.3 @@ -16,14 +16,6 @@
     3.4                    <attr name="position" intvalue="1005"/>
     3.5                 </file>
     3.6              </folder>
     3.7 -            <folder name="Toolbars">
     3.8 -               <folder name="Default">
     3.9 -                  <file name="org-netbeans-modules-plsql-debug-PlsqlDebugAction.instance">
    3.10 -                     <attr bundlevalue="org.netbeans.modules.plsql.debug.Bundle#CTL_PlsqlDebugAction" name="displayName"/>
    3.11 -                     <attr name="position" intvalue="19600"/>
    3.12 -                  </file>
    3.13 -               </folder>
    3.14 -            </folder>
    3.15           </folder>
    3.16        </folder>
    3.17     </folder>
     4.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/Bundle.properties	Wed May 22 16:22:11 2013 +0530
     4.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/Bundle.properties	Thu May 23 14:23:18 2013 +0200
     4.3 @@ -26,3 +26,9 @@
     4.4  PromptDialog.fieldSubstitutionValue.text=
     4.5  SelectMethodDialog.jLabel1.text=Available Methods
     4.6  SelectMethodDialog.btnOk.text=OK
     4.7 +
     4.8 +# ConnectionAction
     4.9 +LBL_ConnectionAction=C&onnection:
    4.10 +LBL_DatabaseConnection=Database Connection
    4.11 +SelectConnectionPanel.dbconnLabel.text=&Database Connection:
    4.12 +ConnectionAction.ToolbarPresenter.LoadingConnections=<html><i>Loading Connections...</i></html>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/ConnectionAction.java	Thu May 23 14:23:18 2013 +0200
     5.3 @@ -0,0 +1,395 @@
     5.4 +/*
     5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 + *
     5.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     5.8 + *
     5.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    5.10 + * Other names may be trademarks of their respective owners.
    5.11 + *
    5.12 + * The contents of this file are subject to the terms of either the GNU
    5.13 + * General Public License Version 2 only ("GPL") or the Common
    5.14 + * Development and Distribution License("CDDL") (collectively, the
    5.15 + * "License"). You may not use this file except in compliance with the
    5.16 + * License. You can obtain a copy of the License at
    5.17 + * http://www.netbeans.org/cddl-gplv2.html
    5.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.19 + * specific language governing permissions and limitations under the
    5.20 + * License.  When distributing the software, include this License Header
    5.21 + * Notice in each file and include the License file at
    5.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    5.23 + * particular file as subject to the "Classpath" exception as provided
    5.24 + * by Oracle in the GPL Version 2 section of the License file that
    5.25 + * accompanied this code. If applicable, add the following below the
    5.26 + * License Header, with the fields enclosed by brackets [] replaced by
    5.27 + * your own identifying information:
    5.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    5.29 + *
    5.30 + * If you wish your version of this file to be governed by only the CDDL
    5.31 + * or only the GPL Version 2, indicate your decision by adding
    5.32 + * "[Contributor] elects to include this software in this distribution
    5.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    5.34 + * single choice of license, a recipient has the option to distribute
    5.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    5.36 + * to extend the choice of license to its licensees as provided above.
    5.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    5.38 + * Version 2 license, then the option applies only if the new code is
    5.39 + * made subject to such option by the copyright holder.
    5.40 + *
    5.41 + * Contributor(s):
    5.42 + *
    5.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
    5.44 + */
    5.45 +package org.netbeans.modules.plsql.execution;
    5.46 +
    5.47 +import java.awt.BorderLayout;
    5.48 +import java.awt.Component;
    5.49 +import java.awt.Container;
    5.50 +import java.awt.DefaultFocusTraversalPolicy;
    5.51 +import java.awt.Dimension;
    5.52 +import java.awt.event.ActionEvent;
    5.53 +import java.awt.event.ItemEvent;
    5.54 +import java.awt.event.ItemListener;
    5.55 +import java.beans.PropertyChangeEvent;
    5.56 +import java.beans.PropertyChangeListener;
    5.57 +import java.util.ArrayList;
    5.58 +import java.util.Collections;
    5.59 +import java.util.Comparator;
    5.60 +import java.util.List;
    5.61 +import javax.swing.AbstractAction;
    5.62 +import javax.swing.AbstractListModel;
    5.63 +import javax.swing.Action;
    5.64 +import javax.swing.ComboBoxModel;
    5.65 +import javax.swing.DefaultComboBoxModel;
    5.66 +import javax.swing.DefaultListCellRenderer;
    5.67 +import javax.swing.JComboBox;
    5.68 +import javax.swing.JEditorPane;
    5.69 +import javax.swing.JLabel;
    5.70 +import javax.swing.JList;
    5.71 +import javax.swing.JPanel;
    5.72 +import javax.swing.SwingUtilities;
    5.73 +import javax.swing.border.EmptyBorder;
    5.74 +import org.netbeans.api.db.explorer.DatabaseConnection;
    5.75 +import org.netbeans.modules.db.api.sql.execute.SQLExecution;
    5.76 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    5.77 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionNewExecutor;
    5.78 +import org.openide.awt.ActionID;
    5.79 +import org.openide.awt.ActionReference;
    5.80 +import org.openide.awt.ActionReferences;
    5.81 +import org.openide.awt.ActionRegistration;
    5.82 +import org.openide.awt.Mnemonics;
    5.83 +import org.openide.cookies.EditorCookie;
    5.84 +import org.openide.loaders.DataObject;
    5.85 +import org.openide.util.ContextAwareAction;
    5.86 +import org.openide.util.HelpCtx;
    5.87 +import org.openide.util.Lookup;
    5.88 +import org.openide.util.Mutex;
    5.89 +import org.openide.util.NbBundle;
    5.90 +import org.openide.util.RequestProcessor;
    5.91 +import org.openide.util.Utilities;
    5.92 +import org.openide.util.actions.Presenter;
    5.93 +
    5.94 +@ActionID(id = "org.netbeans.modules.plsql.execution.ConnectionAction", category = "PLSQL")
    5.95 +@ActionRegistration(displayName = "#LBL_ConnectionAction", lazy = false)
    5.96 +@ActionReferences({
    5.97 +    @ActionReference(path = "Editors/text/x-plsql/Toolbars/Default",
    5.98 +            name = "org-netbeans-modules-plsql-execution-ConnectionAction", position = 100)
    5.99 +})
   5.100 +public final class ConnectionAction extends AbstractAction implements ContextAwareAction, Presenter.Toolbar {
   5.101 +
   5.102 +    private final Lookup actionContext;
   5.103 +    private ToolbarPresenter toolbarPresenter;
   5.104 +    private DataObject dataObject;
   5.105 +    private static final String NO_CONNECTION = "no database connection";
   5.106 +
   5.107 +    public ConnectionAction() {
   5.108 +        this(Utilities.actionsGlobalContext());
   5.109 +    }
   5.110 +
   5.111 +    public ConnectionAction(Lookup context) {
   5.112 +        putValue(SHORT_DESCRIPTION, getName());
   5.113 +        this.actionContext = context;
   5.114 +        dataObject = context.lookup(DataObject.class);
   5.115 +    }
   5.116 +
   5.117 +    @Override
   5.118 +    public Action createContextAwareInstance(Lookup context) {
   5.119 +        return new ConnectionAction(context);
   5.120 +    }
   5.121 +
   5.122 +    private String getName() {
   5.123 +        return NbBundle.getMessage(ConnectionAction.class, "LBL_ConnectionAction");
   5.124 +    }
   5.125 +
   5.126 +    public HelpCtx getHelpCtx() {
   5.127 +        return HelpCtx.DEFAULT_HELP;
   5.128 +    }
   5.129 +
   5.130 +//    private String getDatabaseConnectionText() {
   5.131 +//        if (dataObject != null) {
   5.132 +//            DatabaseConnectionManager dbConnectionManager = DatabaseConnectionManager.getInstance(dataObject);
   5.133 +//            if (dbConnectionManager != null) {
   5.134 +//                return dbConnectionManager.formatDatabaseConnectionInfo();
   5.135 +//            }
   5.136 +//        }
   5.137 +//        return NO_CONNECTION;
   5.138 +//    }
   5.139 +    @Override
   5.140 +    public Component getToolbarPresenter() {
   5.141 +
   5.142 +        toolbarPresenter = new ToolbarPresenter(actionContext, DatabaseConnectionManager.getInstance(dataObject));
   5.143 +        toolbarPresenter.setSQLExecution(dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class));
   5.144 +        return toolbarPresenter;
   5.145 +
   5.146 +    }
   5.147 +
   5.148 +    @Override
   5.149 +    public void actionPerformed(ActionEvent e) {
   5.150 +        //do nothing...
   5.151 +    }
   5.152 +
   5.153 +    private static final class ToolbarPresenter extends JPanel {
   5.154 +
   5.155 +        private final Lookup actionContext;
   5.156 +        private DatabaseConnectionManager connectionManager;
   5.157 +        private DatabaseConnectionNewExecutor waitingSQLExecution = null;
   5.158 +        private JComboBox combo;
   5.159 +        private JLabel comboLabel;
   5.160 +        private DatabaseConnectionModel model;
   5.161 +        private boolean waiting;
   5.162 +        private static final RequestProcessor RP = new RequestProcessor(ToolbarPresenter.class);
   5.163 +
   5.164 +        public ToolbarPresenter(final Lookup actionContext, DatabaseConnectionManager manager) {
   5.165 +            this.connectionManager = manager;
   5.166 +            initComponents();
   5.167 +            waiting = true;
   5.168 +            RP.post(new Runnable() {
   5.169 +                @Override
   5.170 +                public void run() {
   5.171 +                    model = new DatabaseConnectionModel(connectionManager);
   5.172 +                    if (waitingSQLExecution != null) {
   5.173 +                        model.setSQLExecution(waitingSQLExecution);
   5.174 +                        waitingSQLExecution = null;
   5.175 +                    }
   5.176 +                    SwingUtilities.invokeLater(new Runnable() {
   5.177 +                        @Override
   5.178 +                        public void run() {
   5.179 +                            waiting = false;
   5.180 +                            combo.setModel(model);
   5.181 +                            setEnabled(true);
   5.182 +                        }
   5.183 +                    });
   5.184 +                }
   5.185 +            });
   5.186 +            this.actionContext = actionContext;
   5.187 +        }
   5.188 +
   5.189 +        @Override
   5.190 +        public Dimension getMinimumSize() {
   5.191 +            Dimension dim = super.getMinimumSize();
   5.192 +            int minWidth = comboLabel.getWidth() * 2;
   5.193 +            return new Dimension(minWidth, dim.height);
   5.194 +        }
   5.195 +
   5.196 +        public void setSQLExecution(DatabaseConnectionNewExecutor executor) {
   5.197 +            if (model != null) {
   5.198 +                model.setSQLExecution(executor);
   5.199 +            } else {
   5.200 +                waitingSQLExecution = executor;
   5.201 +            }
   5.202 +        }
   5.203 +
   5.204 +        private void initComponents() {
   5.205 +            setLayout(new BorderLayout(4, 0));
   5.206 +            setBorder(new EmptyBorder(0, 2, 0, 8));
   5.207 +            setOpaque(false);
   5.208 +            setFocusTraversalPolicyProvider(true);
   5.209 +            setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
   5.210 +                @Override
   5.211 +                public Component getDefaultComponent(Container aContainer) {
   5.212 +                    if (!SwingUtilities.isEventDispatchThread()) {
   5.213 +                        return null;
   5.214 +                    }
   5.215 +                    final EditorCookie ec = actionContext.lookup(
   5.216 +                            EditorCookie.class);
   5.217 +                    if (ec != null) {
   5.218 +                        JEditorPane[] panes = ec.getOpenedPanes();
   5.219 +                        if (panes != null) {
   5.220 +                            for (JEditorPane pane : panes) {
   5.221 +                                if (pane.isShowing()) {
   5.222 +                                    return pane;
   5.223 +                                }
   5.224 +                            }
   5.225 +                        }
   5.226 +                    }
   5.227 +
   5.228 +                    return null;
   5.229 +                }
   5.230 +            });
   5.231 +
   5.232 +            combo = new JComboBox();
   5.233 +            combo.addItemListener(new ItemListener() {
   5.234 +                @Override
   5.235 +                public void itemStateChanged(ItemEvent e) {
   5.236 +                    DatabaseConnection dbconn = (DatabaseConnection) combo.getSelectedItem();
   5.237 +                    combo.setToolTipText(dbconn != null ? dbconn.getDisplayName() : null);
   5.238 +                }
   5.239 +            });
   5.240 +            combo.setOpaque(false);
   5.241 +            combo.setModel(new DefaultComboBoxModel(
   5.242 +                    new String[]{NbBundle.getMessage(ToolbarPresenter.class, "ConnectionAction.ToolbarPresenter.LoadingConnections")}));
   5.243 +            setEnabled(false);
   5.244 +            combo.setRenderer(new DatabaseConnectionRenderer());
   5.245 +            String accessibleName = NbBundle.getMessage(ConnectionAction.class, "LBL_DatabaseConnection");
   5.246 +            combo.getAccessibleContext().setAccessibleName(accessibleName);
   5.247 +            combo.getAccessibleContext().setAccessibleDescription(accessibleName);
   5.248 +            combo.setPreferredSize(new Dimension(200, combo.getPreferredSize().height));
   5.249 +
   5.250 +            add(combo, BorderLayout.CENTER);
   5.251 +
   5.252 +            comboLabel = new JLabel();
   5.253 +            Mnemonics.setLocalizedText(comboLabel, NbBundle.getMessage(ConnectionAction.class, "LBL_ConnectionAction"));
   5.254 +            comboLabel.setOpaque(false);
   5.255 +            comboLabel.setLabelFor(combo);
   5.256 +            add(comboLabel, BorderLayout.WEST);
   5.257 +        }
   5.258 +
   5.259 +        @Override
   5.260 +        public void setEnabled(boolean enabled) {
   5.261 +            combo.setEnabled(enabled && !waiting);
   5.262 +            super.setEnabled(enabled && !waiting);
   5.263 +        }
   5.264 +    }
   5.265 +
   5.266 +    private static final class DatabaseConnectionModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
   5.267 +
   5.268 +//        private ConnectionListener listener;
   5.269 +        private List<DatabaseConnection> connectionList; // must be ArrayList
   5.270 +        private DatabaseConnectionNewExecutor executor;
   5.271 +        private DatabaseConnectionManager connectionProvider;
   5.272 +
   5.273 +        @SuppressWarnings("LeakingThisInConstructor")
   5.274 +        public DatabaseConnectionModel(DatabaseConnectionManager connectionProvider) {
   5.275 +            this.connectionProvider = connectionProvider;
   5.276 +//            listener = WeakListeners.create(ConnectionListener.class, this, ConnectionManager.getDefault());
   5.277 +//            ConnectionManager.getDefault().addConnectionListener(listener);
   5.278 +//                                connectionProvider.addPropertyChangeListener(listener);
   5.279 +
   5.280 +            connectionList = new ArrayList<DatabaseConnection>();
   5.281 +            connectionList.addAll(connectionProvider.getDatabaseConnections());
   5.282 +//            connectionList.addAll(Arrays.asList(ConnectionManager.getDefault().getConnections()));
   5.283 +            sortConnections();
   5.284 +        }
   5.285 +
   5.286 +        @Override
   5.287 +        public Object getElementAt(int index) {
   5.288 +            return connectionList.get(index);
   5.289 +        }
   5.290 +
   5.291 +        @Override
   5.292 +        public int getSize() {
   5.293 +            return connectionList.size();
   5.294 +        }
   5.295 +
   5.296 +        @Override
   5.297 +        public void setSelectedItem(Object object) {
   5.298 +            if (executor != null) {
   5.299 +                executor.updateConnection((DatabaseConnection) object);
   5.300 +            }
   5.301 +        }
   5.302 +
   5.303 +        @Override
   5.304 +        public Object getSelectedItem() {
   5.305 +            return executor != null ? executor.getConnection() : null;
   5.306 +        }
   5.307 +
   5.308 +        public void setSQLExecution(DatabaseConnectionNewExecutor executor) {
   5.309 +            // XXX: should add listeners 
   5.310 +//            if (this.executor != null) {
   5.311 +//                this.executor.removePropertyChangeListener(this);
   5.312 +//            }
   5.313 +            this.executor = executor;
   5.314 +//            if (this.executor != null) {
   5.315 +//                this.executor.addPropertyChangeListener(this);
   5.316 +//            }
   5.317 +            fireContentsChanged(this, 0, 0); // because the selected item might have changed
   5.318 +        }
   5.319 +
   5.320 +        @Override
   5.321 +        public void propertyChange(PropertyChangeEvent evt) {
   5.322 +            String propertyName = evt.getPropertyName();
   5.323 +            if (propertyName == null || propertyName.equals(SQLExecution.PROP_DATABASE_CONNECTION)) {
   5.324 +                Mutex.EVENT.readAccess(new Runnable() {
   5.325 +                    @Override
   5.326 +                    public void run() {
   5.327 +                        fireContentsChanged(this, 0, 0); // because the selected item might have changed
   5.328 +                    }
   5.329 +                });
   5.330 +            }
   5.331 +        }
   5.332 +
   5.333 +//        @Override
   5.334 +//        public void connectionsChanged() {
   5.335 +//            Mutex.EVENT.readAccess(new Runnable() {
   5.336 +//                @Override
   5.337 +//                public void run() {
   5.338 +//                    connectionList.clear();
   5.339 +//
   5.340 +////                    connectionList.addAll(Arrays.asList(ConnectionManager.getDefault().getConnections()));
   5.341 +//                    connectionList.addAll(connectionProvider.getDatabaseConnections());
   5.342 +//                    sortConnections();
   5.343 +//
   5.344 +//                    DatabaseConnection selectedItem = (DatabaseConnection) getSelectedItem();
   5.345 +//                    if (selectedItem != null && !connectionList.contains(selectedItem)) {
   5.346 +//                        setSelectedItem(null);
   5.347 +//                    }
   5.348 +//                    fireContentsChanged(this, 0, connectionList.size());
   5.349 +//                }
   5.350 +//            });
   5.351 +//        }
   5.352 +        void sortConnections() {
   5.353 +            Collections.sort(connectionList, new Comparator<DatabaseConnection>() {
   5.354 +                @Override
   5.355 +                public int compare(DatabaseConnection o1, DatabaseConnection o2) {
   5.356 +                    return o1.getDisplayName().compareTo(o2.getDisplayName());
   5.357 +                }
   5.358 +            });
   5.359 +        }
   5.360 +    }
   5.361 +
   5.362 +    private static final class DatabaseConnectionRenderer extends DefaultListCellRenderer {
   5.363 +
   5.364 +        @Override
   5.365 +        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   5.366 +            Object displayName;
   5.367 +            String tooltipText = null;
   5.368 +
   5.369 +            if (value instanceof DatabaseConnection) {
   5.370 +                DatabaseConnection connection = (DatabaseConnection) value;
   5.371 +                //XXX: should have url instead, see execution action dropdownbutton
   5.372 +                String url = connection.getDatabaseURL();
   5.373 +                String schema = connection.getUser();
   5.374 +                int pos = url.indexOf("@") + 1;
   5.375 +                if (pos > 0) {
   5.376 +                    url = url.substring(pos);
   5.377 +                }
   5.378 +                url = schema + "@" + url;
   5.379 +                String alias = connection.getDisplayName();
   5.380 +                if (alias != null && !alias.equals(connection.getName())) {
   5.381 +                    url = alias + " [" + url + "]";
   5.382 +                }
   5.383 +//            JMenuItem item = new JMenuItem(url);
   5.384 +//            if (connectionProvider.isDefaultDatabase(c)) {
   5.385 +//                item.setFont(item.getFont().deriveFont(Font.BOLD));
   5.386 +//            }
   5.387 +                displayName = connection.getDisplayName();
   5.388 +                tooltipText = url;
   5.389 +            } else {
   5.390 +                displayName = value;
   5.391 +            }
   5.392 +            JLabel component = (JLabel) super.getListCellRendererComponent(list, displayName, index, isSelected, cellHasFocus);
   5.393 +            component.setToolTipText(tooltipText);
   5.394 +
   5.395 +            return component;
   5.396 +        }
   5.397 +    }
   5.398 +}
     6.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/CurrentDatabaseToolbarInfo.java	Wed May 22 16:22:11 2013 +0530
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,106 +0,0 @@
     6.4 -/*
     6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     6.6 - *
     6.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     6.8 - *
     6.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    6.10 - * Other names may be trademarks of their respective owners.
    6.11 - *
    6.12 - * The contents of this file are subject to the terms of either the GNU
    6.13 - * General Public License Version 2 only ("GPL") or the Common
    6.14 - * Development and Distribution License("CDDL") (collectively, the
    6.15 - * "License"). You may not use this file except in compliance with the
    6.16 - * License. You can obtain a copy of the License at
    6.17 - * http://www.netbeans.org/cddl-gplv2.html
    6.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    6.19 - * specific language governing permissions and limitations under the
    6.20 - * License.  When distributing the software, include this License Header
    6.21 - * Notice in each file and include the License file at
    6.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    6.23 - * particular file as subject to the "Classpath" exception as provided
    6.24 - * by Oracle in the GPL Version 2 section of the License file that
    6.25 - * accompanied this code. If applicable, add the following below the
    6.26 - * License Header, with the fields enclosed by brackets [] replaced by
    6.27 - * your own identifying information:
    6.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    6.29 - *
    6.30 - * If you wish your version of this file to be governed by only the CDDL
    6.31 - * or only the GPL Version 2, indicate your decision by adding
    6.32 - * "[Contributor] elects to include this software in this distribution
    6.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    6.34 - * single choice of license, a recipient has the option to distribute
    6.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    6.36 - * to extend the choice of license to its licensees as provided above.
    6.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    6.38 - * Version 2 license, then the option applies only if the new code is
    6.39 - * made subject to such option by the copyright holder.
    6.40 - *
    6.41 - * Contributor(s):
    6.42 - *
    6.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
    6.44 - */
    6.45 -package org.netbeans.modules.plsql.execution;
    6.46 -
    6.47 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    6.48 -import java.awt.Component;
    6.49 -import java.awt.event.ActionEvent;
    6.50 -import javax.swing.AbstractAction;
    6.51 -import javax.swing.Action;
    6.52 -import javax.swing.JLabel;
    6.53 -import org.netbeans.api.db.explorer.DatabaseConnection;
    6.54 -import org.openide.loaders.DataObject;
    6.55 -import org.openide.util.ContextAwareAction;
    6.56 -import org.openide.util.HelpCtx;
    6.57 -import org.openide.util.Lookup;
    6.58 -import org.openide.util.NbBundle;
    6.59 -import org.openide.util.Utilities;
    6.60 -import org.openide.util.actions.Presenter;
    6.61 -
    6.62 -public final class CurrentDatabaseToolbarInfo extends AbstractAction implements ContextAwareAction, Presenter.Toolbar {
    6.63 -   private JLabel label;
    6.64 -   private DataObject dataObject;
    6.65 -   private static final String NO_CONNECTION = "no database connection";
    6.66 -
    6.67 -   public CurrentDatabaseToolbarInfo() {
    6.68 -      this(Utilities.actionsGlobalContext());
    6.69 -   }
    6.70 -
    6.71 -   public CurrentDatabaseToolbarInfo(Lookup context) {
    6.72 -      putValue(SHORT_DESCRIPTION, getName());
    6.73 -      dataObject = context.lookup(DataObject.class);
    6.74 -   }
    6.75 -
    6.76 -   public Action createContextAwareInstance(Lookup context) {
    6.77 -      return new CurrentDatabaseToolbarInfo(context);
    6.78 -   }
    6.79 -
    6.80 -   private String getName() {
    6.81 -      return NbBundle.getMessage(CurrentDatabaseToolbarInfo.class, "CTL_CurrentDatabaseToolbarInfo");
    6.82 -   }
    6.83 -
    6.84 -
    6.85 -   public HelpCtx getHelpCtx() {
    6.86 -      return HelpCtx.DEFAULT_HELP;
    6.87 -   }
    6.88 -
    6.89 -   private String getDatabaseConnectionText() {
    6.90 -      if(dataObject!=null) {
    6.91 -         DatabaseConnectionManager dbConnectionManager = DatabaseConnectionManager.getInstance(dataObject);
    6.92 -         if(dbConnectionManager!=null) {
    6.93 -            return dbConnectionManager.formatDatabaseConnectionInfo();
    6.94 -         }
    6.95 -      }
    6.96 -      return NO_CONNECTION;
    6.97 -   }
    6.98 -
    6.99 -   @Override
   6.100 -   public Component getToolbarPresenter() {
   6.101 -      label = new JLabel(getDatabaseConnectionText());
   6.102 -      return label;
   6.103 -   }
   6.104 -
   6.105 -   @Override
   6.106 -   public void actionPerformed(ActionEvent e) {
   6.107 -     //do nothing...
   6.108 -   }
   6.109 -}
     7.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/DescribeAction.java	Wed May 22 16:22:11 2013 +0530
     7.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/DescribeAction.java	Thu May 23 14:23:18 2013 +0200
     7.3 @@ -83,7 +83,7 @@
     7.4      @Override
     7.5      protected void performAction(Node[] activatedNodes) {
     7.6          DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
     7.7 -        EditorCookie ec = dataObject.getCookie(EditorCookie.class);
     7.8 +        EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
     7.9          final Document doc = ec.getDocument();
    7.10          final DatabaseConnectionManager connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
    7.11          final DatabaseConnection connection = connectionProvider.getPooledDatabaseConnection(true);
     8.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlCommitAction.java	Wed May 22 16:22:11 2013 +0530
     8.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlCommitAction.java	Thu May 23 14:23:18 2013 +0200
     8.3 @@ -52,11 +52,8 @@
     8.4  import javax.swing.Action;
     8.5  import javax.swing.ImageIcon;
     8.6  import javax.swing.JButton;
     8.7 -import org.netbeans.api.db.explorer.DatabaseConnection;
     8.8  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
     8.9 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionHolder;
    8.10 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    8.11 -import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
    8.12 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionNewExecutor;
    8.13  import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
    8.14  import org.openide.awt.ActionID;
    8.15  import org.openide.awt.ActionRegistration;
    8.16 @@ -73,11 +70,11 @@
    8.17  
    8.18      private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    8.19      private final DataObject dataObject;
    8.20 -    private DatabaseConnectionManager connectionProvider;
    8.21 -    private DatabaseConnectionHolder connectionHolder;
    8.22 -    private DatabaseConnection connection;
    8.23 +//    private DatabaseConnectionManager connectionProvider;
    8.24 +    private DatabaseConnectionNewExecutor connectionSession;
    8.25 +//    private DatabaseConnection connection;
    8.26      private JButton button;
    8.27 -    private final DatabaseTransaction transaction;
    8.28 +//    private final DatabaseTransaction transaction;
    8.29      private final PropertyChangeListener changeListener = new EnableCommit();
    8.30  
    8.31      public PlsqlCommitAction() {
    8.32 @@ -89,7 +86,9 @@
    8.33          putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/database_commit.png")));
    8.34  
    8.35          dataObject = context.lookup(DataObject.class);
    8.36 -        transaction = DatabaseTransaction.getInstance(dataObject);
    8.37 +        if (dataObject != null) {
    8.38 +            connectionSession = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
    8.39 +        }
    8.40      }
    8.41  
    8.42      @Override
    8.43 @@ -119,21 +118,23 @@
    8.44  
    8.45      private void prepareConnection() {
    8.46          if (dataObject != null) {
    8.47 -            connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
    8.48 +//            connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
    8.49 +            connectionSession = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
    8.50          }
    8.51 -        connection = dataObject.getLookup().lookup(DatabaseConnection.class);
    8.52 +//        connection = dataObject.getLookup().lookup(DatabaseConnection.class);
    8.53      }
    8.54  
    8.55      @Override
    8.56      public void actionPerformed(ActionEvent event) {
    8.57  
    8.58          prepareConnection();
    8.59 -        if (connectionProvider == null || connection == null) {
    8.60 -            return;
    8.61 -        }
    8.62 +//        if (connectionProvider == null || connection == null) {
    8.63 +//            return;
    8.64 +//        }
    8.65  
    8.66          saveIfModified(dataObject);
    8.67 -        transaction.commitTransaction(connection, connectionProvider);
    8.68 +        connectionSession.commitTransaction();
    8.69 +//        transaction.commitTransaction(connection, connectionProvider);
    8.70      }
    8.71  
    8.72      @Override
    8.73 @@ -146,7 +147,7 @@
    8.74          button.setAction(this);
    8.75          button.setEnabled(false);
    8.76          button.setDisabledIcon(new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/database_commit_disable.png")));
    8.77 -        transaction.addPropertyChangeListener(changeListener);
    8.78 +        connectionSession.addTransactionListener(changeListener);
    8.79          return button;
    8.80      }
    8.81  
    8.82 @@ -165,10 +166,8 @@
    8.83  
    8.84          @Override
    8.85          public void propertyChange(PropertyChangeEvent event) {
    8.86 -            if (!OptionsUtilities.isCommandWindowAutoCommitEnabled() && transaction.isOpen()) {
    8.87 -                button.setEnabled(true);
    8.88 -            } else {
    8.89 -                button.setEnabled(false);
    8.90 +            if (!OptionsUtilities.isCommandWindowAutoCommitEnabled()) {
    8.91 +                button.setEnabled((Boolean) event.getNewValue());
    8.92              }
    8.93          }
    8.94      }
     9.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java	Wed May 22 16:22:11 2013 +0530
     9.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java	Thu May 23 14:23:18 2013 +0200
     9.3 @@ -41,40 +41,25 @@
     9.4   */
     9.5  package org.netbeans.modules.plsql.execution;
     9.6  
     9.7 -import java.awt.Component;
     9.8 -import java.awt.Font;
     9.9 -import java.awt.event.ActionEvent;
    9.10 -import java.awt.event.ActionListener;
    9.11 -import java.awt.event.ItemEvent;
    9.12 -import java.awt.event.ItemListener;
    9.13 -import java.awt.image.BufferedImage;
    9.14 -import java.beans.PropertyChangeEvent;
    9.15 -import java.beans.PropertyChangeListener;
    9.16  import java.io.IOException;
    9.17  import java.util.ArrayList;
    9.18  import java.util.List;
    9.19  import java.util.Locale;
    9.20 -import java.util.logging.Logger;
    9.21  import javax.swing.*;
    9.22 -import javax.swing.event.PopupMenuEvent;
    9.23 -import javax.swing.event.PopupMenuListener;
    9.24  import javax.swing.text.Document;
    9.25 -import org.netbeans.api.db.explorer.DatabaseConnection;
    9.26  import org.netbeans.api.progress.ProgressHandle;
    9.27  import org.netbeans.api.progress.ProgressHandleFactory;
    9.28 -import org.netbeans.modules.plsql.filetype.PlsqlDataObject;
    9.29  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
    9.30 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionHolder;
    9.31  import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    9.32 -import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
    9.33 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionNewExecutor;
    9.34  import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
    9.35  import org.openide.awt.*;
    9.36  import org.openide.cookies.EditorCookie;
    9.37  import org.openide.cookies.SaveCookie;
    9.38 -import org.openide.filesystems.FileObject;
    9.39  import org.openide.loaders.DataObject;
    9.40 +import org.openide.nodes.Node;
    9.41  import org.openide.util.*;
    9.42 -import org.openide.util.actions.Presenter;
    9.43 +import org.openide.util.actions.CookieAction;
    9.44  
    9.45  @ActionID(id = "org.netbeans.modules.plsql.execution.PlsqlExecuteAction", category = "PLSQL")
    9.46  @ActionRegistration(displayName = "#CTL_PlsqlExecute", lazy = false)
    9.47 @@ -84,42 +69,42 @@
    9.48      @ActionReference(path = "Editors/text/x-plsql/Popup", name = "org-netbeans-modules-plsql-execution-PlsqlExecuteAction",
    9.49              position = 405, separatorBefore = 404),
    9.50      @ActionReference(path = "Editors/text/x-plsql/Toolbars/Default", name = "org-netbeans-modules-plsql-execution-PlsqlExecuteAction",
    9.51 -            position = 19500, separatorBefore = 19400)
    9.52 +            position = 200)
    9.53  })
    9.54 -public class PlsqlExecuteAction extends AbstractAction implements ContextAwareAction, Presenter.Toolbar {
    9.55 +public class PlsqlExecuteAction extends CookieAction {
    9.56  
    9.57 -    private static final Logger LOG = Logger.getLogger(PlsqlExecuteAction.class.getName());
    9.58 +//    private static final Logger LOG = Logger.getLogger(PlsqlExecuteAction.class.getName());
    9.59      private static final String ICON_PATH = "org/netbeans/modules/plsql/execution/execute.png";
    9.60      private static final RequestProcessor RP = new RequestProcessor(PlsqlExecuteAction.class.getName(), 4);
    9.61      private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    9.62 -    private static final String DATABASE_CONNECTION_KEY = "databaseConnection";
    9.63 +//    private static final String DATABASE_CONNECTION_KEY = "databaseConnection";
    9.64      private static final String TEST_BLOCK_NAME_PREFIX = "TestBlock:";
    9.65 -    private final DataObject dataObject;
    9.66 -    private PlsqlDataObject plsqlDataobject;
    9.67 +    private DataObject dataObject;
    9.68 +//    private PlsqlDataObject plsqlDataobject;
    9.69      private DatabaseConnectionManager connectionProvider;
    9.70 -    private DatabaseConnection connection;
    9.71 -    private PopupMenuPopulator popupMenuPopulator = null;
    9.72 -    private JPopupMenu popup;
    9.73 -    private JButton button;
    9.74 -    private ActionListener buttonListener = new ButtonListener();
    9.75 +    private DatabaseConnectionNewExecutor connectionSession;
    9.76 +//    private PopupMenuPopulator popupMenuPopulator = null;
    9.77 +//    private JPopupMenu popup;
    9.78 +//    private JButton button;
    9.79 +//    private ActionListener buttonListener = new ButtonListener();
    9.80      private boolean autoCommit = true;
    9.81 -    private final DatabaseTransaction transaction;
    9.82  
    9.83      public PlsqlExecuteAction() {
    9.84 -        this(Utilities.actionsGlobalContext());
    9.85 -    }
    9.86 +        super();
    9.87 +//        this(Utilities.actionsGlobalContext());
    9.88 +//    }
    9.89  
    9.90 -    public PlsqlExecuteAction(Lookup context) {
    9.91 -        putValue(NAME, NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_PlsqlExecute"));
    9.92 +//    public PlsqlExecuteAction(Lookup context) {
    9.93 +//        putValue(NAME, NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_PlsqlExecute"));
    9.94          putValue(SHORT_DESCRIPTION, NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_PlsqlExecuteDescription"));
    9.95 -        putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(ICON_PATH)));
    9.96 +//        putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(ICON_PATH)));
    9.97  
    9.98 -        dataObject = context.lookup(DataObject.class);
    9.99 +//        dataObject = context.lookup(DataObject.class);
   9.100  
   9.101 -        if (validator.isValidTDB(dataObject)) {
   9.102 -            autoCommit = OptionsUtilities.isCommandWindowAutoCommitEnabled();
   9.103 -        }
   9.104 -        transaction = DatabaseTransaction.getInstance(dataObject);
   9.105 +//        if (validator.isValidTDB(dataObject)) {
   9.106 +//            autoCommit = OptionsUtilities.isCommandWindowAutoCommitEnabled();
   9.107 +//        }
   9.108 +//        connectionSession = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
   9.109      }
   9.110  
   9.111      @Override
   9.112 @@ -140,24 +125,59 @@
   9.113      }
   9.114  
   9.115      @Override
   9.116 -    public Action createContextAwareInstance(Lookup context) {
   9.117 -        return new PlsqlExecuteAction(context);
   9.118 +    protected int mode() {
   9.119 +        return CookieAction.MODE_EXACTLY_ONE;
   9.120      }
   9.121  
   9.122 +    @Override
   9.123 +    protected boolean asynchronous() {
   9.124 +        return false;
   9.125 +    }
   9.126 +
   9.127 +    @Override
   9.128 +    protected Class<?>[] cookieClasses() {
   9.129 +        return new Class[]{DataObject.class};
   9.130 +    }
   9.131 +
   9.132 +    @Override
   9.133 +    public String getName() {
   9.134 +        return NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_PlsqlExecute");
   9.135 +    }
   9.136 +
   9.137 +    @Override
   9.138 +    protected String iconResource() {
   9.139 +        return ICON_PATH;
   9.140 +    }
   9.141 +
   9.142 +    @Override
   9.143 +    public HelpCtx getHelpCtx() {
   9.144 +        return HelpCtx.DEFAULT_HELP;
   9.145 +    }
   9.146 +
   9.147 +//    @Override
   9.148 +//    public Action createContextAwareInstance(Lookup context) {
   9.149 +//        return new PlsqlExecuteAction(context);
   9.150 +//    }
   9.151      private void prepareConnection() {
   9.152          if (dataObject != null) {
   9.153              connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
   9.154 -            if (connectionProvider != null) {
   9.155 -                if (popupMenuPopulator == null) {
   9.156 -                    popupMenuPopulator = new PopupMenuPopulator();
   9.157 -                    connectionProvider.addPropertyChangeListener(popupMenuPopulator);
   9.158 -                }
   9.159 -            }
   9.160 +//            if (connectionProvider != null) {
   9.161 +//                if (popupMenuPopulator == null) {
   9.162 +//                    popupMenuPopulator = new PopupMenuPopulator();
   9.163 +//                    connectionProvider.addPropertyChangeListener(popupMenuPopulator);
   9.164 +//                }
   9.165 +//            }
   9.166          }
   9.167      }
   9.168  
   9.169      @Override
   9.170 -    public void actionPerformed(ActionEvent event) {
   9.171 +    protected void performAction(Node[] activatedNodes) {
   9.172 +        dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
   9.173 +        if (validator.isValidTDB(dataObject)) {
   9.174 +            autoCommit = OptionsUtilities.isCommandWindowAutoCommitEnabled();
   9.175 +        }
   9.176 +        connectionSession = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
   9.177 +
   9.178          if (connectionProvider == null) {
   9.179              prepareConnection();
   9.180          }
   9.181 @@ -165,138 +185,24 @@
   9.182              return;
   9.183          }
   9.184  
   9.185 -        final DatabaseConnection dc;
   9.186          // If autocommit OFF - take the connection from data object.
   9.187 -        if (!autoCommit) {
   9.188 -            dc = dataObject.getLookup().lookup(DatabaseConnection.class);
   9.189 -        } else {
   9.190 -            dc = connectionProvider.getTemplateConnection();
   9.191 -        }
   9.192 -        if (setConnection(dc)) {
   9.193 -            saveAndExecute();
   9.194 -        }
   9.195 -    }
   9.196 -
   9.197 -    @Override
   9.198 -    public Component getToolbarPresenter() {
   9.199 -        if (!isEnabled()) {
   9.200 -            return null;
   9.201 -        }
   9.202 -
   9.203 -        popup = new JPopupMenu();
   9.204 -        if (connectionProvider == null) {
   9.205 -            prepareConnection();
   9.206 -        }
   9.207 -
   9.208 -        if (connectionProvider != null) {
   9.209 -            populatePopupMenu();
   9.210 -        }
   9.211 -
   9.212 -        button = DropDownButtonFactory.createDropDownButton(
   9.213 -                new ImageIcon(new BufferedImage(32, 32, BufferedImage.TYPE_BYTE_GRAY)), popup);
   9.214 -        button.setAction(this);
   9.215 -        button.addItemListener(new ItemListener() {
   9.216 -            @Override
   9.217 -            public void itemStateChanged(ItemEvent e) {
   9.218 -                if (e.getStateChange() == ItemEvent.SELECTED) {
   9.219 -                    popup.show(button, 0, button.getHeight());
   9.220 -                }
   9.221 -            }
   9.222 -        });
   9.223 -
   9.224 -        popup.addPopupMenuListener(new PopupMenuListener() {
   9.225 -            @Override
   9.226 -            public void popupMenuCanceled(PopupMenuEvent e) {
   9.227 -                button.setSelected(false);
   9.228 -            }
   9.229 -
   9.230 -            @Override
   9.231 -            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
   9.232 -                button.setSelected(false);
   9.233 -            }
   9.234 -
   9.235 -            @Override
   9.236 -            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
   9.237 -            }
   9.238 -        });
   9.239 -
   9.240 -        return button;
   9.241 -    }
   9.242 -
   9.243 -    private void populatePopupMenu() {
   9.244 -        popup.removeAll();
   9.245 -        for (DatabaseConnection c : connectionProvider.getDatabaseConnections()) {
   9.246 -            String url = c.getDatabaseURL();
   9.247 -            String schema = c.getUser();
   9.248 -            int pos = url.indexOf("@") + 1;
   9.249 -            if (pos > 0) {
   9.250 -                url = url.substring(pos);
   9.251 -            }
   9.252 -            url = schema + "@" + url;
   9.253 -            String alias = c.getDisplayName();
   9.254 -            if (alias != null && !alias.equals(c.getName())) {
   9.255 -                url = alias + " [" + url + "]";
   9.256 -            }
   9.257 -            JMenuItem item = new JMenuItem(url);
   9.258 -            if (connectionProvider.isDefaultDatabase(c)) {
   9.259 -                item.setFont(item.getFont().deriveFont(Font.BOLD));
   9.260 -            }
   9.261 -            item.putClientProperty(DATABASE_CONNECTION_KEY, c);
   9.262 -            item.addActionListener(buttonListener);
   9.263 -            popup.add(item);
   9.264 -        }
   9.265 -    }
   9.266 -
   9.267 -    private boolean setConnection(DatabaseConnection newConnection) {
   9.268 -        if (connectionHasChanged(newConnection)) {
   9.269 -//            connection = dataObject.getLookup().lookup(DatabaseConnection.class);
   9.270 -            if (transaction != null && transaction.isOpen()) {
   9.271 -                if (!OptionsUtilities.isDeployNoPromptEnabled()) {
   9.272 -                    String msg = "Commit open transactions for " + connection.getDisplayName() + "?";
   9.273 -                    String title = "Commit open transaction?";
   9.274 -                    int dialogAnswer = JOptionPane.showOptionDialog(null, msg, title, JOptionPane.YES_NO_CANCEL_OPTION,
   9.275 -                            JOptionPane.QUESTION_MESSAGE, null, null, null);
   9.276 -
   9.277 -                    if (dialogAnswer == JOptionPane.YES_OPTION) {
   9.278 -                        transaction.commitTransaction(connection, connectionProvider);
   9.279 -                    } else if (dialogAnswer == JOptionPane.NO_OPTION) {
   9.280 -                        transaction.rollbackTransaction(connection, connectionProvider);
   9.281 -                    } else {
   9.282 -                        return false;
   9.283 -                    }
   9.284 -                }
   9.285 +        if (autoCommit) {
   9.286 +            if (!connectionSession.updateConnection(connectionProvider.getTemplateConnection())) {
   9.287 +                return;
   9.288              }
   9.289          }
   9.290 -        if (!connectionProvider.isDefaultDatabase(newConnection) && !OptionsUtilities.isDeployNoPromptEnabled()) {
   9.291 -            String msg = "You are now connecting to a secondary database.";
   9.292 -            String title = "Connecting to a Secondary Database!";
   9.293 -            final int dialogAnswer = JOptionPane.showOptionDialog(null, msg, title, JOptionPane.YES_NO_OPTION,
   9.294 -                    JOptionPane.QUESTION_MESSAGE, null, null, null);
   9.295 -            if (dialogAnswer != JOptionPane.YES_OPTION) {
   9.296 -                return false;
   9.297 -            }
   9.298 -        }
   9.299 -        connection = newConnection;
   9.300 -        return true;
   9.301 -    }
   9.302 -
   9.303 -    public void saveAndExecute() {
   9.304 -        if (connectionProvider == null) {
   9.305 -            prepareConnection();
   9.306 -        }
   9.307 +        saveIfModified(dataObject);
   9.308  
   9.309          EditorCookie edCookie = dataObject.getLookup().lookup(EditorCookie.class);
   9.310          Document document = edCookie.getDocument();
   9.311 -        saveIfModified(dataObject);
   9.312 -
   9.313 -        DataObject obj = FileExecutionUtil.getDataObject(document);
   9.314 -        FileObject file = obj.getPrimaryFile();
   9.315 -        if (file == null) {
   9.316 -            return;
   9.317 -        }
   9.318 +//        DataObject obj = FileExecutionUtil.getDataObject(document);
   9.319 +//        FileObject file = obj.getPrimaryFile();
   9.320 +//        if (file == null) {
   9.321 +//            return;
   9.322 +//        }
   9.323          //to reconnect if the connection is gone. 
   9.324 -        if (connection.getJDBCConnection() == null) {
   9.325 -            connectionProvider.connect(connection);
   9.326 +        if (connectionSession.getConnection().getJDBCConnection() == null) {
   9.327 +            connectionProvider.connect(connectionSession.getConnection());
   9.328          }
   9.329  
   9.330          PlsqlExecutableBlocksMaker blockMaker = new PlsqlExecutableBlocksMaker(document);
   9.331 @@ -342,14 +248,12 @@
   9.332                      }
   9.333                  }
   9.334              }
   9.335 +            if (blocks.size() > 0 && (dataObject.getNodeDelegate().getDisplayName() == null || !dataObject.getNodeDelegate().getDisplayName().contains(TEST_BLOCK_NAME_PREFIX))) {
   9.336 +                String str = blocks.get(0).getPlsqlString().replaceAll("\n", " ");
   9.337 +                dataObject.getNodeDelegate().setDisplayName(str.length() > 30 ? str.substring(0, 30) + "..." : str);
   9.338 +            }
   9.339          }
   9.340 -        String extension = file.getExt();
   9.341 -        if (blocks.size() > 0 && "tdb".equalsIgnoreCase(extension) && (dataObject.getNodeDelegate().getDisplayName() == null || !dataObject.getNodeDelegate().getDisplayName().contains(TEST_BLOCK_NAME_PREFIX))) {
   9.342 -            String str = blocks.get(0).getPlsqlString().replaceAll("\n", " ");
   9.343 -            dataObject.getNodeDelegate().setDisplayName(str.length() > 30 ? str.substring(0, 30) + "..." : str);
   9.344 -        }
   9.345 -        RP.post(new ExecutionHandler(connectionProvider, connection, blocks, document));
   9.346 -
   9.347 +        RP.post(new ExecutionHandler(new PlsqlFileExecutor(connectionProvider, connectionSession), blocks, document));
   9.348      }
   9.349  
   9.350      private void saveIfModified(DataObject dataObj) {
   9.351 @@ -363,22 +267,14 @@
   9.352          }
   9.353      }
   9.354  
   9.355 -    private boolean connectionHasChanged(DatabaseConnection newConnection) {
   9.356 -        return connection != null && !connection.getName().equals(newConnection.getName());
   9.357 -    }
   9.358 -
   9.359      private class ExecutionHandler implements Runnable, Cancellable {
   9.360  
   9.361 -        private DatabaseConnectionManager connectionProvider;
   9.362 -        private DatabaseConnection connection;
   9.363 -        private List<PlsqlExecutableObject> blocks;
   9.364 -        private Document document;
   9.365 -        private PlsqlFileExecutor executor;
   9.366 +        private final PlsqlFileExecutor executor;
   9.367 +        private final List<PlsqlExecutableObject> blocks;
   9.368 +        private final Document document;
   9.369  
   9.370 -        public ExecutionHandler(DatabaseConnectionManager connectionProvider, DatabaseConnection connection,
   9.371 -                List<PlsqlExecutableObject> blocks, Document doc) {
   9.372 -            this.connectionProvider = connectionProvider;
   9.373 -            this.connection = connection;
   9.374 +        public ExecutionHandler(PlsqlFileExecutor executor, List<PlsqlExecutableObject> blocks, Document doc) {
   9.375 +            this.executor = executor;
   9.376              this.blocks = blocks;
   9.377              this.document = doc;
   9.378          }
   9.379 @@ -388,28 +284,22 @@
   9.380              ProgressHandle handle = ProgressHandleFactory.createHandle("Executing database file...", this);
   9.381              try {
   9.382                  handle.start();
   9.383 -                if (connection == connectionProvider.getTemplateConnection()) {
   9.384 -                    connection = connectionProvider.getPooledDatabaseConnection(false, true);
   9.385 -                    if (connection == null) {
   9.386 -                        return;
   9.387 -                    }
   9.388 -                }
   9.389 -                final DataObject obj = FileExecutionUtil.getDataObject(document);
   9.390 -                FileObject file = obj.getPrimaryFile();
   9.391 -                if (file == null) {
   9.392 -                    return;
   9.393 -                }
   9.394 +                // XXX commented out, not sure why it is needed.
   9.395 +//                if (connectionSession.getConnection() == connectionProvider.getTemplateConnection()) {
   9.396 +//                    connectionSession = connectionProvider.getPooledDatabaseConnection(false, true);
   9.397 +//                    if (connectionSession == null) {
   9.398 +//                        return;
   9.399 +//                    }
   9.400 +//                }
   9.401 +//                final DataObject obj = FileExecutionUtil.getDataObject(document);
   9.402 +//                FileObject file = obj.getPrimaryFile();
   9.403 +//                if (file == null) {
   9.404 +//                    return;
   9.405 +//                }
   9.406  
   9.407 -                executor = new PlsqlFileExecutor(connectionProvider, connection);
   9.408                  executor.executePLSQL(blocks, document, false, autoCommit);
   9.409  
   9.410              } finally {
   9.411 -                if (autoCommit) {
   9.412 -                    connectionProvider.releaseDatabaseConnection(connection);
   9.413 -                } else {
   9.414 -                    //set connection to the lookup when autocommit is OFF
   9.415 -                    modifyConnection();
   9.416 -                }
   9.417                  handle.finish();
   9.418              }
   9.419          }
   9.420 @@ -421,38 +311,35 @@
   9.421              }
   9.422              return true;
   9.423          }
   9.424 -
   9.425 -        private void modifyConnection() {
   9.426 -            DatabaseConnectionHolder connectionHolder = dataObject.getLookup().lookup(DatabaseConnectionHolder.class);
   9.427 -            connectionHolder.setDatabaseConnection(connection);
   9.428 -            // will remove below if new impl is better.
   9.429 -            plsqlDataobject = (PlsqlDataObject) dataObject;
   9.430 -            plsqlDataobject.modifyLookupDatabaseConnection(connection);
   9.431 -        }
   9.432 +//        private void modifyConnection() {
   9.433 +////            DatabaseConnectionNewExecutor connectionHolder = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
   9.434 +//            connectionSession.updateConnection(connectionSession);
   9.435 +//            // will remove below if new impl is better.
   9.436 +//            plsqlDataobject = (PlsqlDataObject) dataObject;
   9.437 +//            plsqlDataobject.modifyLookupDatabaseConnection(connectionSession);
   9.438 +//        }
   9.439      }
   9.440 -
   9.441 -    private class ButtonListener implements ActionListener {
   9.442 -
   9.443 -        @Override
   9.444 -        public void actionPerformed(ActionEvent e) {
   9.445 -
   9.446 -            JMenuItem item = (JMenuItem) e.getSource();
   9.447 -            DatabaseConnection newConnection = (DatabaseConnection) item.getClientProperty(DATABASE_CONNECTION_KEY);
   9.448 -            if (setConnection(newConnection)) {
   9.449 -                connectionProvider.setModuleInOracle(connection);
   9.450 -                saveAndExecute();
   9.451 -            }
   9.452 -        }
   9.453 -    };
   9.454 -
   9.455 -    private class PopupMenuPopulator implements PropertyChangeListener {
   9.456 -
   9.457 -        @Override
   9.458 -        public void propertyChange(PropertyChangeEvent event) {
   9.459 -            if (popup != null) {
   9.460 -                prepareConnection();
   9.461 -                populatePopupMenu();
   9.462 -            }
   9.463 -        }
   9.464 -    }
   9.465 +//    private class ButtonListener implements ActionListener {
   9.466 +//
   9.467 +//        @Override
   9.468 +//        public void actionPerformed(ActionEvent e) {
   9.469 +//
   9.470 +//            JMenuItem item = (JMenuItem) e.getSource();
   9.471 +//            DatabaseConnection newConnection = (DatabaseConnection) item.getClientProperty(DATABASE_CONNECTION_KEY);
   9.472 +//            if (connectionSession.updateConnection(newConnection)) {
   9.473 +//                connectionProvider.setModuleInOracle(connectionSession.getConnection());
   9.474 +//                saveAndExecute();
   9.475 +//            }
   9.476 +//        }
   9.477 +//    };
   9.478 +//    private class PopupMenuPopulator implements PropertyChangeListener {
   9.479 +//
   9.480 +//        @Override
   9.481 +//        public void propertyChange(PropertyChangeEvent event) {
   9.482 +//            if (popup != null) {
   9.483 +//                prepareConnection();
   9.484 +//                populatePopupMenu();
   9.485 +//            }
   9.486 +//        }
   9.487 +//    }
   9.488  }
   9.489 \ No newline at end of file
    10.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java	Wed May 22 16:22:11 2013 +0530
    10.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java	Thu May 23 14:23:18 2013 +0200
    10.3 @@ -82,8 +82,8 @@
    10.4  import org.netbeans.modules.plsql.utilities.PlsqlFileUtil;
    10.5  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
    10.6  import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    10.7 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionNewExecutor;
    10.8  import org.netbeans.modules.plsqlsupport.db.DatabaseContentManager;
    10.9 -import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
   10.10  import org.netbeans.modules.plsqlsupport.db.ui.SQLCommandWindow;
   10.11  import org.openide.DialogDisplayer;
   10.12  import org.openide.NotifyDescriptor;
   10.13 @@ -106,26 +106,32 @@
   10.14      private static final RequestProcessor RP = new RequestProcessor("SQLExecution", 4, true);
   10.15      private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
   10.16      private boolean cancel = false;
   10.17 -    private final DatabaseConnection connection;
   10.18 +    private final DatabaseConnectionNewExecutor connectionSession;
   10.19      private Connection debugConnection;
   10.20      private DatabaseContentManager cache;
   10.21      private PlsqlEditor plsqlEditor;
   10.22      private final InputOutput preparedIO;
   10.23      private final DatabaseConnectionManager connectionProvider;
   10.24 -    private Savepoint firstSavepoint = null;
   10.25 -    private final String connectionDisplayName;
   10.26 +//    private Savepoint firstSavepoint = null;
   10.27 +//    private DatabaseConnection connection;
   10.28 +
   10.29 +    public PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, DatabaseConnectionNewExecutor connection) {
   10.30 +        this.connectionSession = connection;
   10.31 +        this.preparedIO = null;
   10.32 +        this.connectionProvider = connectionProvider;
   10.33 +        this.cache = DatabaseContentManager.getInstance(connection.getConnection());
   10.34 +    }
   10.35  
   10.36      public PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, DatabaseConnection connection) {
   10.37 -        this.connectionDisplayName = "Using DB: " + connection.getDisplayName() + " [" + connection.getName() + "]";
   10.38 -        this.connection = connection;
   10.39 +        this.connectionSession = null;
   10.40 +//        this.connection = connection;
   10.41          this.preparedIO = null;
   10.42          this.connectionProvider = connectionProvider;
   10.43          this.cache = DatabaseContentManager.getInstance(connection);
   10.44      }
   10.45  
   10.46      public PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, Connection debugConnection, InputOutput io) {
   10.47 -        this.connection = null;
   10.48 -        this.connectionDisplayName = null;
   10.49 +        this.connectionSession = null;
   10.50          this.debugConnection = debugConnection;
   10.51          this.preparedIO = io;
   10.52          this.connectionProvider = connectionProvider;
   10.53 @@ -339,10 +345,11 @@
   10.54          }
   10.55      }
   10.56  
   10.57 -    private InputOutput initializeIO(String fileName, String displayName, DataObject dataObj) {
   10.58 +    private InputOutput initializeIO(String fileName, String displayName, DataObject dataObj, PlsqlExecutableObject executableObject) {
   10.59          if (this.preparedIO != null) {
   10.60              return this.preparedIO;
   10.61          }
   10.62 +        displayName = getIOTabName(executableObject, fileName, displayName);
   10.63          String startMsg = "Deploying " + FileExecutionUtil.getActivatedFileName(dataObj);
   10.64          if (validator.isValidTDB(dataObj)) {
   10.65              startMsg = "Executing " + fileName;
   10.66 @@ -366,7 +373,7 @@
   10.67                  io.getErr().flush();
   10.68              }
   10.69              io.select();
   10.70 -            io.getOut().println(connectionDisplayName);
   10.71 +            io.getOut().println(connectionSession.getDisplayName());
   10.72              io.getOut().println(startMsg);
   10.73              io.getOut().println("-------------------------------------------------------------");
   10.74          } catch (IOException ex) {
   10.75 @@ -403,7 +410,7 @@
   10.76          cancel = false;
   10.77          InputOutput io = null;
   10.78          boolean deploymentOk = true;
   10.79 -        if (debugConnection == null && connection.getJDBCConnection() == null) {
   10.80 +        if (debugConnection == null && connectionSession.getConnection().getJDBCConnection() == null) {
   10.81              JOptionPane.showMessageDialog(null, "Connect to the Database");
   10.82              return null;
   10.83          }
   10.84 @@ -424,7 +431,7 @@
   10.85          Connection con;
   10.86          Statement stm = null;
   10.87          String firstWord = null;
   10.88 -        DatabaseTransaction transaction = DatabaseTransaction.getInstance((DataObject) object);
   10.89 +//        DatabaseTransaction transaction = DatabaseTransaction.getInstance((DataObject) object);
   10.90  
   10.91          //quick & dirty fix to avoid having output tabs for the SQL Execution window (unless there's an exception)
   10.92          //first check to see if this is a simple select statement and if so treat it separately.
   10.93 @@ -447,16 +454,16 @@
   10.94                          if (!ignoreDefines) {
   10.95                              plsqlText = replaceAliases(plsqlText, definesMap, define, io);
   10.96                          }
   10.97 -                        executeSelect(plsqlText, connection, doc, null);
   10.98 +                        executeSelect(plsqlText, connectionSession.getConnection(), doc, null);
   10.99                          return null;
  10.100                      } else if (firstWord.equalsIgnoreCase("DESC") || firstWord.equalsIgnoreCase("DESCRIBE")) {
  10.101 -                        describeObject(connection, doc, tokenizer, io);
  10.102 +                        describeObject(connectionSession.getConnection(), doc, tokenizer, io);
  10.103                          return null;
  10.104                      }
  10.105  
  10.106                  } catch (SQLException sqlEx) {
  10.107                      try {
  10.108 -                        io = initializeIO(fileName, getIOTabName(executableObjs.get(0), fileName, dataObj.getNodeDelegate().getDisplayName()), dataObj);
  10.109 +                        io = initializeIO(fileName, dataObj.getNodeDelegate().getDisplayName(), dataObj, executableObjs.get(0));
  10.110                          int errLine = getLineNumberFromMsg(sqlEx.getMessage());
  10.111                          int outLine = executionObject.getStartLineNo() + errLine - 1;
  10.112                          String msg = getmodifiedErorrMsg(sqlEx.getMessage(), outLine);
  10.113 @@ -480,11 +487,11 @@
  10.114          try {
  10.115  
  10.116  
  10.117 -            io = initializeIO(fileName, getIOTabName(executableObjs.get(0), fileName, dataObj.getNodeDelegate().getDisplayName()), dataObj);
  10.118 -            con = debugConnection != null ? debugConnection : connection.getJDBCConnection();
  10.119 +            io = initializeIO(fileName, dataObj.getNodeDelegate().getDisplayName(), dataObj, executableObjs.get(0));
  10.120 +            con = debugConnection != null ? debugConnection : connectionSession.getJDBCConnection();
  10.121              con.setAutoCommit(false);
  10.122              enableDbmsOut(con);
  10.123 -            firstSavepoint = con.setSavepoint();
  10.124 +//            firstSavepoint = con.setSavepoint();
  10.125              //savepointsCreated.put(new Integer(firstSavepoint.getSavepointId()),firstSavepoint);
  10.126  
  10.127              stm = con.createStatement();
  10.128 @@ -494,8 +501,8 @@
  10.129              for (PlsqlExecutableObject exeObj : executableObjs) {
  10.130                  if (cancel) {
  10.131                      io.getErr().println("!!!Execution cancelled. Performing rollback");
  10.132 -                    // con.rollback();
  10.133 -                    con.rollback(firstSavepoint);
  10.134 +                    con.rollback();
  10.135 +//                    con.rollback(firstSavepoint);
  10.136                      return io;
  10.137                  }
  10.138                  int lineNumber = exeObj.getStartLineNo();
  10.139 @@ -548,7 +555,7 @@
  10.140                                  plsqlEditor.closeResultSetTabs();
  10.141                                  firstSelectStatement = false;
  10.142                              }
  10.143 -                            moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
  10.144 +                            moreRowsToBeFetched = executeSelect(plsqlText, connectionSession.getConnection(), doc, null);
  10.145                              continue;
  10.146                          } else {
  10.147                              io.select();
  10.148 @@ -654,8 +661,8 @@
  10.149                          io.getOut().println("!!!Error detected. Performing Rollback");
  10.150                          deploymentOk = false;
  10.151                          try {
  10.152 -                            // con.rollback();
  10.153 -                            con.rollback(firstSavepoint);
  10.154 +                            con.rollback();
  10.155 +//                            con.rollback(firstSavepoint);
  10.156                          } catch (SQLException ex) {
  10.157                          }
  10.158                          break;
  10.159 @@ -705,12 +712,12 @@
  10.160                              if (plsqlEditor != null) {
  10.161                                  plsqlEditor.closeResultSetTabs();
  10.162                              }
  10.163 -                            moreRowsToBeFetched = executeSelect(plsqlText, connection, doc, null);
  10.164 +                            moreRowsToBeFetched = executeSelect(plsqlText, connectionSession.getConnection(), doc, null);
  10.165                              continue;
  10.166                          } else {
  10.167                              io.select();
  10.168                              if (firstWord.equalsIgnoreCase("DESC") || firstWord.equalsIgnoreCase("DESCRIBE")) {
  10.169 -                                describeObject(connection, doc, tokenizer, io);
  10.170 +                                describeObject(connectionSession.getConnection(), doc, tokenizer, io);
  10.171                                  continue;
  10.172                              } else if (firstWord.equalsIgnoreCase("PROMPT")) {
  10.173                                  if (plsqlText.length() > 7) {
  10.174 @@ -799,7 +806,8 @@
  10.175                          if (!autoCommit) {
  10.176                              try {
  10.177                                  io.getOut().println("!!!Error detected. Performing rollback");
  10.178 -                                con.rollback(firstSavepoint);
  10.179 +                                con.rollback();
  10.180 +//                                con.rollback(firstSavepoint);
  10.181                              } catch (SQLException ex) {
  10.182                              }
  10.183                          }
  10.184 @@ -985,10 +993,10 @@
  10.185              }
  10.186  
  10.187              if (validator.isValidTDB(dataObj) && !autoCommit) {
  10.188 -                if (!deploymentOk && !connectionProvider.hasDataToCommit(connection)) {
  10.189 +                if (!deploymentOk && !connectionSession.hasOpenTransaction()) {
  10.190                      con.commit();
  10.191 -                } else if (deploymentOk && connectionProvider.hasDataToCommit(connection)) {
  10.192 -                    transaction.open();
  10.193 +//                } else if (deploymentOk && connectionSession.hasOpenTransaction()) {
  10.194 +//                    connectionSession.openTransaction();
  10.195                  }
  10.196              } else {
  10.197                  con.commit();
  10.198 @@ -1004,7 +1012,7 @@
  10.199                  if (preparedIO == null) {
  10.200                      io.getOut().println("-------------------------------------------------------------");
  10.201                      io.getOut().println(endMsg + " (Total times: " + totalTime + "s)");
  10.202 -                    io.getOut().println(connectionDisplayName);
  10.203 +                    io.getOut().println(connectionSession.getDisplayName());
  10.204                      io.getOut().println(new Timestamp(endTime).toString());
  10.205                  }
  10.206              }
  10.207 @@ -1027,6 +1035,11 @@
  10.208                  io.getErr().close();
  10.209                  // IOPosition.currentPosition(io).scrollTo();
  10.210              }
  10.211 +            if (autoCommit) {
  10.212 +                connectionProvider.releaseDatabaseConnection(connectionSession.getConnection());
  10.213 +            } else {
  10.214 +                connectionSession.hasOpenTransaction();
  10.215 +            }
  10.216          }
  10.217          return deploymentOk ? null : io;
  10.218      }
  10.219 @@ -1042,7 +1055,7 @@
  10.220  
  10.221      private List<PlsqlErrorObject> getPackageerrors(String packageName, String packageType) {
  10.222          List<PlsqlErrorObject> errorObjects = new ArrayList<PlsqlErrorObject>();
  10.223 -        Connection con = debugConnection != null ? debugConnection : connection.getJDBCConnection();
  10.224 +        Connection con = debugConnection != null ? debugConnection : connectionSession.getConnection().getJDBCConnection();
  10.225          if (con != null) {
  10.226              Statement stm = null;
  10.227              try {
  10.228 @@ -1308,7 +1321,7 @@
  10.229                                  }
  10.230                                  components.add(component);
  10.231                                  toolTips.add("<html>" + result.getStatementInfo().getSQL().replaceAll("\n", "<br>"));
  10.232 -                                if ("IFSAPP".equals(connection.getSchema())) {
  10.233 +                                if ("IFSAPP".equals(connectionSession.getConnection().getSchema())) {
  10.234                                      fixDataTablePopupMenu(result.getDataView());
  10.235                                  }
  10.236                              }
    11.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlMultipleExecuteAction.java	Wed May 22 16:22:11 2013 +0530
    11.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlMultipleExecuteAction.java	Thu May 23 14:23:18 2013 +0200
    11.3 @@ -287,8 +287,8 @@
    11.4                              String fileName = obj.getPrimaryFile().getNameExt();
    11.5                              if (fileName.toLowerCase(Locale.ENGLISH).endsWith(executionOrder.get(typeIndex))) {
    11.6                                  //Load the editor cookier and allow parsing
    11.7 -                                EditorCookie ec = obj.getCookie(EditorCookie.class);
    11.8 -                                Document doc = null;
    11.9 +                                EditorCookie ec = obj.getLookup().lookup(EditorCookie.class);
   11.10 +                                Document doc;
   11.11                                  try {
   11.12                                      doc = ec.openDocument();
   11.13                                  } catch (UserQuestionException uqe) {
   11.14 @@ -337,7 +337,7 @@
   11.15          private void saveIfModified(DataObject dataObj) {
   11.16              if (dataObj instanceof DataObject) {
   11.17                  try {
   11.18 -                    SaveCookie saveCookie = dataObj.getCookie(SaveCookie.class);
   11.19 +                    SaveCookie saveCookie = dataObj.getLookup().lookup(SaveCookie.class);
   11.20                      if (saveCookie != null) {
   11.21                          saveCookie.save();
   11.22                      }
    12.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlRollbackAction.java	Wed May 22 16:22:11 2013 +0530
    12.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlRollbackAction.java	Thu May 23 14:23:18 2013 +0200
    12.3 @@ -52,10 +52,8 @@
    12.4  import javax.swing.Action;
    12.5  import javax.swing.ImageIcon;
    12.6  import javax.swing.JButton;
    12.7 -import org.netbeans.api.db.explorer.DatabaseConnection;
    12.8  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
    12.9 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
   12.10 -import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
   12.11 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionNewExecutor;
   12.12  import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
   12.13  import org.openide.awt.ActionID;
   12.14  import org.openide.awt.ActionRegistration;
   12.15 @@ -72,10 +70,11 @@
   12.16  
   12.17      private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
   12.18      private final DataObject dataObject;
   12.19 -    private final DatabaseTransaction transaction;
   12.20 -    private DatabaseConnectionManager connectionProvider;
   12.21 +//    private final DatabaseTransaction transaction;
   12.22 +    private DatabaseConnectionNewExecutor connectionSession;
   12.23 +//    private DatabaseConnectionManager connectionProvider;
   12.24      private JButton button;
   12.25 -    private DatabaseConnection connection;
   12.26 +//    private DatabaseConnection connection;
   12.27      private final PropertyChangeListener propertyChangeListener = new EnableRollback();
   12.28  
   12.29      public PlsqlRollbackAction() {
   12.30 @@ -88,7 +87,9 @@
   12.31          putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/database_rollback.png")));
   12.32  
   12.33          dataObject = context.lookup(DataObject.class);
   12.34 -        transaction = DatabaseTransaction.getInstance(dataObject);
   12.35 +        if (dataObject != null) {
   12.36 +            connectionSession = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
   12.37 +        }
   12.38      }
   12.39  
   12.40      @Override
   12.41 @@ -119,21 +120,22 @@
   12.42  
   12.43      private void prepareConnection() {
   12.44          if (dataObject != null) {
   12.45 -            connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
   12.46 +            connectionSession = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
   12.47          }
   12.48 -        connection = dataObject.getLookup().lookup(DatabaseConnection.class);
   12.49 +//        connection = dataObject.getLookup().lookup(DatabaseConnection.class);
   12.50      }
   12.51  
   12.52      @Override
   12.53      public void actionPerformed(ActionEvent event) {
   12.54  
   12.55          prepareConnection();
   12.56 -        if (connectionProvider == null || connection == null) {
   12.57 -            return;
   12.58 -        }
   12.59 +//        if (connectionProvider == null || connection == null) {
   12.60 +//            return;
   12.61 +//        }
   12.62  
   12.63          saveIfModified(dataObject);
   12.64 -        transaction.rollbackTransaction(connection, connectionProvider);
   12.65 +        connectionSession.rollbackTransaction();
   12.66 +//        transaction.rollbackTransaction(connection);
   12.67      }
   12.68  
   12.69      @Override
   12.70 @@ -146,7 +148,7 @@
   12.71          button.setAction(this);
   12.72          button.setEnabled(false);
   12.73          button.setDisabledIcon(new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/database_rollback_disable.png")));
   12.74 -        transaction.addPropertyChangeListener(propertyChangeListener);
   12.75 +        connectionSession.addTransactionListener(propertyChangeListener);
   12.76          return button;
   12.77      }
   12.78  
   12.79 @@ -165,10 +167,8 @@
   12.80  
   12.81          @Override
   12.82          public void propertyChange(PropertyChangeEvent event) {
   12.83 -            if (!OptionsUtilities.isCommandWindowAutoCommitEnabled() && transaction.isOpen()) {
   12.84 -                button.setEnabled(true);
   12.85 -            } else {
   12.86 -                button.setEnabled(false);
   12.87 +            if (!OptionsUtilities.isCommandWindowAutoCommitEnabled()) {
   12.88 +                button.setEnabled((Boolean) event.getNewValue());
   12.89              }
   12.90          }
   12.91      }
    13.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/DeployFilesAction.java	Wed May 22 16:22:11 2013 +0530
    13.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/DeployFilesAction.java	Thu May 23 14:23:18 2013 +0200
    13.3 @@ -217,7 +217,7 @@
    13.4                          if (obj != null) {
    13.5                              if (fileName.toLowerCase(Locale.ENGLISH).endsWith(executionOrder.get(typeIndex))) {
    13.6                                  //Load the editor cookier and allow parsing
    13.7 -                                EditorCookie ec = obj.getCookie(EditorCookie.class);
    13.8 +                                EditorCookie ec = obj.getLookup().lookup(EditorCookie.class);
    13.9                                  Task task = ec.prepareDocument();
   13.10                                  task.waitFinished();
   13.11                                  Document doc = ec.getDocument();
    14.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/layer.xml	Wed May 22 16:22:11 2013 +0530
    14.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/layer.xml	Thu May 23 14:23:18 2013 +0200
    14.3 @@ -57,36 +57,36 @@
    14.4                              <attr name="position" intvalue="19600"/>
    14.5                          </file>
    14.6                          <file name="org-netbeans-modules-plsql-execution-PlsqlCommitAction.instance">
    14.7 -                            <attr name="position" intvalue="19650"/>
    14.8 +                            <attr name="position" intvalue="300"/>
    14.9                          </file>
   14.10                          <file name="org-netbeans-modules-plsql-execution-PlsqlRollbackAction.instance">
   14.11 -                            <attr name="position" intvalue="19750"/>
   14.12 +                            <attr name="position" intvalue="400"/>
   14.13                          </file>
   14.14                          <file name="Separator2.instance">
   14.15                              <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
   14.16 -                            <attr name="position" intvalue="19850"/>
   14.17 +                            <attr name="position" intvalue="500"/>
   14.18                          </file>
   14.19                    <!--End Commit and Rollback-->
   14.20                          <file name="org-netbeans-modules-plsql-execution-PlsqlExplainPlanAction.instance">
   14.21 -                            <attr name="position" intvalue="19900"/>
   14.22 +                            <attr name="position" intvalue="600"/>
   14.23                          </file>
   14.24                          <file name="org-netbeans-modules-plsql-execution-PlsqlExecutionHistoryAction.instance">
   14.25 -                            <attr name="position" intvalue="20000"/>
   14.26 +                            <attr name="position" intvalue="700"/>
   14.27                          </file>
   14.28                          <file name="Separator2.instance">
   14.29                              <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
   14.30 -                            <attr name="position" intvalue="20100"/>
   14.31 +                            <attr name="position" intvalue="800"/>
   14.32                          </file>
   14.33                          <file name="org-netbeans-modules-plsql-execution-PlsqlSaveCommandAction.instance">
   14.34 -                            <attr name="position" intvalue="20200"/>
   14.35 +                            <attr name="position" intvalue="900"/>
   14.36                          </file>
   14.37                          <file name="Separator3.instance">
   14.38                              <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
   14.39 -                            <attr name="position" intvalue="20300"/>
   14.40 +                            <attr name="position" intvalue="1000"/>
   14.41                          </file>
   14.42 -                        <file name="org-netbeans-modules-plsql-execution-CurrentDatabaseToolbarInfo.instance">
   14.43 +<!--                        <file name="org-netbeans-modules-plsql-execution-CurrentDatabaseToolbarInfo.instance">
   14.44                              <attr name="position" intvalue="20350"/>
   14.45 -                        </file>
   14.46 +                        </file>-->
   14.47  
   14.48                      </folder> <!-- Default -->
   14.49  
    15.1 --- a/PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlDataObject.java	Wed May 22 16:22:11 2013 +0530
    15.2 +++ b/PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlDataObject.java	Thu May 23 14:23:18 2013 +0200
    15.3 @@ -41,31 +41,27 @@
    15.4   */
    15.5  package org.netbeans.modules.plsql.filetype;
    15.6  
    15.7 -import org.netbeans.modules.plsqlsupport.options.PLSQLAnnotationsPanel;
    15.8 +import java.io.IOException;
    15.9 +import java.util.ArrayList;
   15.10 +import java.util.List;
   15.11 +import java.util.prefs.PreferenceChangeListener;
   15.12 +import org.netbeans.api.db.explorer.DatabaseConnection;
   15.13 +import org.netbeans.api.project.FileOwnerQuery;
   15.14 +import org.netbeans.api.project.Project;
   15.15 +import org.netbeans.modules.plsql.annotation.PlsqlAnnotationManager;
   15.16 +import org.netbeans.modules.plsql.lexer.PlsqlBlockFactory;
   15.17 +import org.netbeans.modules.plsql.utilities.PlsqlFileLocatorService;
   15.18 +import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
   15.19  import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
   15.20 -import java.io.IOException;
   15.21 -import java.util.prefs.PreferenceChangeEvent;
   15.22 -import org.netbeans.api.project.Project;
   15.23 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionNewExecutor;
   15.24  import org.openide.filesystems.FileObject;
   15.25  import org.openide.loaders.DataObjectExistsException;
   15.26  import org.openide.loaders.MultiDataObject;
   15.27  import org.openide.nodes.CookieSet;
   15.28  import org.openide.nodes.Node;
   15.29 -import org.netbeans.api.project.FileOwnerQuery;
   15.30 -import org.netbeans.modules.plsql.lexer.PlsqlBlockFactory;
   15.31 -import org.netbeans.modules.plsql.annotation.PlsqlAnnotationManager;
   15.32 -import org.netbeans.modules.plsql.utilities.PlsqlFileLocatorService;
   15.33 -import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
   15.34 -import java.util.ArrayList;
   15.35 -import java.util.List;
   15.36 -import java.util.prefs.PreferenceChangeListener;
   15.37  import org.openide.util.Lookup;
   15.38 -import org.openide.util.NbPreferences;
   15.39  import org.openide.util.lookup.Lookups;
   15.40  import org.openide.util.lookup.ProxyLookup;
   15.41 -import org.netbeans.api.db.explorer.DatabaseConnection;
   15.42 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionHolder;
   15.43 -import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
   15.44  
   15.45  public class PlsqlDataObject extends MultiDataObject {
   15.46  
   15.47 @@ -75,9 +71,8 @@
   15.48     private PreferenceChangeListener listener;
   15.49     private PlsqlBlockFactory blockFactory = null;
   15.50     private PlsqlAnnotationManager annotationManager = null;
   15.51 -   private boolean isAnnotationsEnabled = false;
   15.52     private final PlsqlEditorSupport editorSupport;
   15.53 -   private DatabaseConnectionHolder connectionHolder;
   15.54 +   private DatabaseConnectionNewExecutor executor;
   15.55     private DatabaseConnection databaseConnection;
   15.56     private StatementExecutionHistory statementExecutionHistory;
   15.57  
   15.58 @@ -102,16 +97,12 @@
   15.59           }
   15.60  
   15.61           blockFactory.addObserver(annotationManager);
   15.62 -
   15.63 -         //Add preference change listener to IFS Options panel
   15.64 -         //addPreferenceListener();
   15.65 -         //This will handle by the PlsqlAnnotationManager
   15.66 -      }
   15.67 +     }
   15.68        // TODO: if file not in project?!?
   15.69        if (project != null) {
   15.70           databaseConnection = DatabaseConnectionManager.getInstance(project).getTemplateConnection();
   15.71        }
   15.72 -      connectionHolder = new DatabaseConnectionHolder(databaseConnection);
   15.73 +      executor = DatabaseConnectionNewExecutor.create(databaseConnection, fileObject);
   15.74        createLookup();
   15.75     }
   15.76  
   15.77 @@ -141,37 +132,11 @@
   15.78        return getCookieSet();
   15.79     }
   15.80  
   15.81 -   private void addPreferenceListener() {
   15.82 -      listener = new PreferenceChangeListener() {
   15.83 -         @Override
   15.84 -         public void preferenceChange(PreferenceChangeEvent evt) {
   15.85 -            if (evt.getKey().equals(OptionsUtilities.PLSQL_ANNOTATIONS_ENABLED_KEY)) {
   15.86 -               manageAnnotations();
   15.87 -            }
   15.88 -         }
   15.89 -      };
   15.90 -      NbPreferences.forModule(PLSQLAnnotationsPanel.class).addPreferenceChangeListener(listener);
   15.91 -   }
   15.92 -
   15.93 -   private void manageAnnotations() {
   15.94 -      if (OptionsUtilities.isPlSqlAnnotationsEnabled() && !isAnnotationsEnabled) {
   15.95 -         blockFactory.addObserver(annotationManager);
   15.96 -         isAnnotationsEnabled = true;
   15.97 -         modifyLookupAnnotationManager(annotationManager);
   15.98 -         annotationManager.initAnnotations(this);
   15.99 -      } else if (!OptionsUtilities.isPlSqlAnnotationsEnabled() && isAnnotationsEnabled) {
  15.100 -         blockFactory.deleteObserver(annotationManager);
  15.101 -         annotationManager.clearAnnotations();
  15.102 -         isAnnotationsEnabled = false;
  15.103 -         modifyLookupAnnotationManager(annotationManager);
  15.104 -      }
  15.105 -   }
  15.106 -
  15.107     private void createLookup() {
  15.108        List<Object> objects = new ArrayList<Object>();
  15.109        objects.add(blockFactory);
  15.110        objects.add(statementExecutionHistory);
  15.111 -      objects.add(connectionHolder);
  15.112 +      objects.add(executor);
  15.113  
  15.114        if (annotationManager != null) {
  15.115           objects.add(annotationManager);
    16.1 --- a/PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlEditor.java	Wed May 22 16:22:11 2013 +0530
    16.2 +++ b/PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlEditor.java	Thu May 23 14:23:18 2013 +0200
    16.3 @@ -41,9 +41,6 @@
    16.4   */
    16.5  package org.netbeans.modules.plsql.filetype;
    16.6  
    16.7 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    16.8 -import org.netbeans.api.db.explorer.DatabaseConnection;
    16.9 -import org.netbeans.modules.plsql.annotation.PlsqlAnnotationManager;
   16.10  import java.awt.Component;
   16.11  import java.beans.PropertyChangeEvent;
   16.12  import java.beans.PropertyChangeListener;
   16.13 @@ -52,70 +49,61 @@
   16.14  import java.io.ObjectOutput;
   16.15  import java.util.Iterator;
   16.16  import java.util.List;
   16.17 +import java.util.logging.Level;
   16.18 +import java.util.logging.Logger;
   16.19  import javax.swing.JComponent;
   16.20 -import javax.swing.JOptionPane;
   16.21  import javax.swing.JPanel;
   16.22  import javax.swing.JSplitPane;
   16.23  import javax.swing.JTabbedPane;
   16.24  import javax.swing.text.BadLocationException;
   16.25  import javax.swing.text.Document;
   16.26 +import org.netbeans.modules.plsql.annotation.PlsqlAnnotationManager;
   16.27 +import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
   16.28 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionNewExecutor;
   16.29  import org.openide.awt.TabbedPaneFactory;
   16.30  import org.openide.cookies.EditorCookie;
   16.31  import org.openide.filesystems.FileUtil;
   16.32  import org.openide.loaders.DataObject;
   16.33  import org.openide.text.CloneableEditor;
   16.34  import org.openide.text.DataEditorSupport;
   16.35 +import org.openide.util.Lookup;
   16.36  import org.openide.util.NbBundle;
   16.37  import org.openide.windows.TopComponent;
   16.38  
   16.39 -
   16.40  public class PlsqlEditor extends CloneableEditor {
   16.41  
   16.42 +   private static final Logger LOG = Logger.getLogger(PlsqlEditor.class.getName());
   16.43 +   private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
   16.44     private JSplitPane splitter;
   16.45     private JTabbedPane resultComponent;
   16.46  
   16.47     public PlsqlEditor() {
   16.48     }
   16.49  
   16.50 -   /** Creates new editor */
   16.51 +   /**
   16.52 +    * Creates new editor
   16.53 +    */
   16.54     public PlsqlEditor(PlsqlEditorSupport support) {
   16.55        super(support);
   16.56     }
   16.57  
   16.58     @Override
   16.59 -    protected boolean closeLast() {
   16.60 -        PlsqlDataObject dataObject = (PlsqlDataObject) ((DataEditorSupport) cloneableEditorSupport()).getDataObject();
   16.61 -       if (dataObject.isTemporary()) {
   16.62 -           DatabaseConnection connection = dataObject.getLookup().lookup(DatabaseConnection.class);
   16.63 -           if (connection.getJDBCConnection() != null) {
   16.64 +   protected boolean closeLast() {
   16.65 +      final DataObject dataObject = ((DataEditorSupport) cloneableEditorSupport()).getDataObject();
   16.66 +      if (validator.isValidTDB(dataObject)) {
   16.67 +         DatabaseConnectionNewExecutor executor = dataObject.getLookup().lookup(DatabaseConnectionNewExecutor.class);
   16.68 +         if (executor.closeOpenTransaction()) {
   16.69 +            FileUtil.toFile(dataObject.getPrimaryFile()).delete();
   16.70 +         } else {
   16.71 +            return false;
   16.72 +         }
   16.73 +      }
   16.74  
   16.75 -               DatabaseConnectionManager connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
   16.76 -               if(connectionProvider.testConnection(connection)){
   16.77 -                   if (DatabaseConnectionManager.getInstance(dataObject).hasDataToCommit(connection)) {
   16.78 -                       String msg = "There are pending transactions in the database. Do you want to commit?";
   16.79 -                       String title = dataObject.getNodeDelegate().getDisplayName();
   16.80 -                       int result = JOptionPane.showOptionDialog(null, msg, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
   16.81 -                       if (result == JOptionPane.YES_OPTION) {
   16.82 -                           //commit
   16.83 -                           connectionProvider.commitRollbackTransactions(connection, true);
   16.84 -                       } else if (result == JOptionPane.NO_OPTION) {
   16.85 -                           //rollback
   16.86 -                           connectionProvider.commitRollbackTransactions(connection, false);
   16.87 -                       } else {
   16.88 -                           return false;
   16.89 -                       }
   16.90 -                   }
   16.91 -               } 
   16.92 -           }
   16.93 -           FileUtil.toFile(dataObject.getPrimaryFile()).delete();
   16.94 -       }
   16.95 -
   16.96 -
   16.97 -       if (!super.closeLast()) {
   16.98 -           return false;
   16.99 -       }
  16.100 -       return true;
  16.101 -    }
  16.102 +      if (!super.closeLast()) {
  16.103 +         return false;
  16.104 +      }
  16.105 +      return true;
  16.106 +   }
  16.107  
  16.108     public void closeResultSetTabs() {
  16.109        if (resultComponent != null) {
  16.110 @@ -123,7 +111,10 @@
  16.111        }
  16.112     }
  16.113  
  16.114 -   /** Overrides superclass method to change the editor background color*/
  16.115 +   /**
  16.116 +    * Overrides superclass method to change the editor background color
  16.117 +    */
  16.118 +   @Override
  16.119     protected void componentShowing() {
  16.120        super.componentShowing();
  16.121  
  16.122 @@ -193,7 +184,7 @@
  16.123        }
  16.124  
  16.125        resultComponent.addPropertyChangeListener(new PropertyChangeListener() {
  16.126 -
  16.127 +         @Override
  16.128           public void propertyChange(PropertyChangeEvent evt) {
  16.129              if (TabbedPaneFactory.PROP_CLOSE.equals(evt.getPropertyName())) {
  16.130                 int selected = resultComponent.getSelectedIndex();
  16.131 @@ -269,32 +260,33 @@
  16.132     @Override
  16.133     public void writeExternal(ObjectOutput out) throws IOException {
  16.134        super.writeExternal(out);
  16.135 -      PlsqlDataObject dataObject = (PlsqlDataObject) ((DataEditorSupport) cloneableEditorSupport()).getDataObject();
  16.136 -      if (dataObject.isTemporary()) {
  16.137 +      DataObject dataObject = ((DataEditorSupport) cloneableEditorSupport()).getDataObject();
  16.138 +      if (validator.isValidTDB(dataObject)) {
  16.139           out.writeObject(getDisplayName());
  16.140        }
  16.141     }
  16.142  
  16.143     @Override
  16.144 -    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  16.145 -        super.readExternal(in);
  16.146 -        PlsqlDataObject dataObject = (PlsqlDataObject) ((DataEditorSupport) cloneableEditorSupport()).getDataObject();
  16.147 -        if (dataObject.isTemporary()) {
  16.148 -            String displayName = (String) in.readObject();
  16.149 -            if (displayName.equalsIgnoreCase(NbBundle.getMessage(PlsqlEditor.class, "LBL_SQLExecutionWindow"))) {
  16.150 -                try {
  16.151 -                    EditorCookie edCookie = dataObject.getLookup().lookup(EditorCookie.class);
  16.152 -                    Document document = edCookie.openDocument();
  16.153 -                    String name = document.getLength() > 30 ? document.getText(0, 30) + "..." : document.getText(0, document.getLength());
  16.154 -                    name.replaceAll("\n", " ");
  16.155 -                    if (name.length() > 0) {
  16.156 -                        displayName = name;
  16.157 -                    }
  16.158 -                } catch (BadLocationException ex) {
  16.159 -                }
  16.160 +   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  16.161 +      super.readExternal(in);
  16.162 +      DataObject dataObject = ((DataEditorSupport) cloneableEditorSupport()).getDataObject();
  16.163 +      if (validator.isValidTDB(dataObject)) {
  16.164 +         String displayName = (String) in.readObject();
  16.165 +         if (displayName.equalsIgnoreCase(NbBundle.getMessage(PlsqlEditor.class, "LBL_SQLExecutionWindow"))) {
  16.166 +            try {
  16.167 +               EditorCookie edCookie = dataObject.getLookup().lookup(EditorCookie.class);
  16.168 +               Document document = edCookie.openDocument();
  16.169 +               String name = document.getLength() > 30 ? document.getText(0, 30) + "..." : document.getText(0, document.getLength());
  16.170 +               name.replaceAll("\n", " ");
  16.171 +               if (name.length() > 0) {
  16.172 +                  displayName = name;
  16.173 +               }
  16.174 +            } catch (BadLocationException ex) {
  16.175 +               LOG.log(Level.FINEST, displayName, ex);
  16.176              }
  16.177 -            setDisplayName(displayName);
  16.178 -            dataObject.getNodeDelegate().setDisplayName(displayName);
  16.179 -        }
  16.180 -    }
  16.181 +         }
  16.182 +         setDisplayName(displayName);
  16.183 +         dataObject.getNodeDelegate().setDisplayName(displayName);
  16.184 +      }
  16.185 +   }
  16.186  }
    17.1 --- a/PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/PlsqlFileValidatorService.java	Wed May 22 16:22:11 2013 +0530
    17.2 +++ b/PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/PlsqlFileValidatorService.java	Thu May 23 14:23:18 2013 +0200
    17.3 @@ -98,10 +98,11 @@
    17.4      public boolean isValidPackageBody(String fileExt);
    17.5  
    17.6      /**
    17.7 -     * Check if DataObject is valid .tdb file. If null object sent false is returned.
    17.8 +     * Check if DataObject is valid .tdb file and exist on disk. If null object sent false is returned.
    17.9 +     * The .tdb file is the serialization of a PLSQL command window.
   17.10       *
   17.11       * @param dataObject
   17.12 -     * @return
   17.13 +     * @return true if DataObject is valid .tdb file and exist on disk.
   17.14       */
   17.15      public boolean isValidTDB(DataObject dataObject);
   17.16  
    18.1 --- a/PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/validation/PlsqlFileValidatorServiceImpl.java	Wed May 22 16:22:11 2013 +0530
    18.2 +++ b/PLSQL/Utilities/src/org/netbeans/modules/plsql/utilities/validation/PlsqlFileValidatorServiceImpl.java	Thu May 23 14:23:18 2013 +0200
    18.3 @@ -134,7 +134,7 @@
    18.4           return false;
    18.5        }
    18.6        FileObject fileObject = dataObject.getPrimaryFile();
    18.7 -      return fileObject.getPath().toLowerCase(Locale.ENGLISH).endsWith(".tdb");
    18.8 +      return fileObject.getPath().toLowerCase(Locale.ENGLISH).endsWith(".tdb") && fileObject.isValid();
    18.9     }
   18.10  
   18.11     @Override
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionExecutor.java	Thu May 23 14:23:18 2013 +0200
    19.3 @@ -0,0 +1,13 @@
    19.4 +/*
    19.5 + * To change this template, choose Tools | Templates
    19.6 + * and open the template in the editor.
    19.7 + */
    19.8 +package org.netbeans.modules.plsqlsupport.db;
    19.9 +
   19.10 +/**
   19.11 + *
   19.12 + * @author chrlse
   19.13 + */
   19.14 +interface DatabaseConnectionExecutor {
   19.15 +    
   19.16 +}
    20.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionHolder.java	Wed May 22 16:22:11 2013 +0530
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,41 +0,0 @@
    20.4 -/*
    20.5 - * To change this template, choose Tools | Templates
    20.6 - * and open the template in the editor.
    20.7 - */
    20.8 -package org.netbeans.modules.plsqlsupport.db;
    20.9 -
   20.10 -import org.netbeans.api.db.explorer.DatabaseConnection;
   20.11 -
   20.12 -/**
   20.13 - *
   20.14 - * @author chrlse
   20.15 - */
   20.16 -public class DatabaseConnectionHolder {
   20.17 -
   20.18 -    private DatabaseConnection databaseConnection;
   20.19 -    private DatabaseTransaction transaction;
   20.20 -
   20.21 -    public DatabaseConnectionHolder() {
   20.22 -    }
   20.23 -
   20.24 -    public DatabaseConnectionHolder(DatabaseConnection databaseConnection) {
   20.25 -        this.databaseConnection = databaseConnection;
   20.26 -    }
   20.27 -
   20.28 -    public DatabaseConnection getDatabaseConnection() {
   20.29 -        return databaseConnection;
   20.30 -    }
   20.31 -
   20.32 -    public void setDatabaseConnection(DatabaseConnection databaseConnection) {
   20.33 -        this.databaseConnection = databaseConnection;
   20.34 -    }
   20.35 -
   20.36 -    public DatabaseTransaction getTransaction() {
   20.37 -        return transaction;
   20.38 -    }
   20.39 -
   20.40 -    public void setTransaction(DatabaseTransaction transaction) {
   20.41 -        this.transaction = transaction;
   20.42 -    }
   20.43 -    
   20.44 -}
    21.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java	Wed May 22 16:22:11 2013 +0530
    21.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java	Thu May 23 14:23:18 2013 +0200
    21.3 @@ -41,7 +41,6 @@
    21.4   */
    21.5  package org.netbeans.modules.plsqlsupport.db;
    21.6  
    21.7 -import org.netbeans.modules.plsqlsupport.db.ui.DatabaseConnectionPanel;
    21.8  import java.beans.ExceptionListener;
    21.9  import java.beans.PropertyChangeListener;
   21.10  import java.beans.PropertyChangeSupport;
   21.11 @@ -71,6 +70,7 @@
   21.12  import org.netbeans.api.db.explorer.DatabaseException;
   21.13  import org.netbeans.api.project.FileOwnerQuery;
   21.14  import org.netbeans.api.project.Project;
   21.15 +import org.netbeans.modules.plsqlsupport.db.ui.DatabaseConnectionPanel;
   21.16  import org.openide.filesystems.FileObject;
   21.17  import org.openide.filesystems.FileUtil;
   21.18  import org.openide.loaders.DataObject;
   21.19 @@ -187,6 +187,11 @@
   21.20          return result;
   21.21      }
   21.22  
   21.23 +    /**
   21.24 +     *
   21.25 +     * @param connection
   21.26 +     * @return true if given connection is the template connection (main).
   21.27 +     */
   21.28      public boolean isDefaultDatabase(DatabaseConnection connection) {
   21.29          return databaseConnectionsAreEqual(connection, templateConnection);
   21.30      }
   21.31 @@ -239,53 +244,6 @@
   21.32          }
   21.33      }
   21.34  
   21.35 -    public void commitRollbackTransactions(DatabaseConnection connection, boolean commit) {
   21.36 -        try {
   21.37 -            if (connection.getJDBCConnection() == null) {
   21.38 -                return;
   21.39 -            }
   21.40 -            Connection con = connection.getJDBCConnection();
   21.41 -
   21.42 -            if (commit) {
   21.43 -                con.commit();
   21.44 -            } else {
   21.45 -                con.rollback();
   21.46 -            }
   21.47 -        } catch (SQLException ex) {
   21.48 -            Exceptions.printStackTrace(ex);
   21.49 -        }
   21.50 -    }
   21.51 -
   21.52 -    /**
   21.53 -     *
   21.54 -     * @return True if there in on going transactions for a command window.
   21.55 -     */
   21.56 -    public boolean hasDataToCommit(DatabaseConnection connection) {
   21.57 -        ResultSet rs = null;
   21.58 -        PreparedStatement stmt = null;
   21.59 -        String commitData = null;
   21.60 -        if (connection == null || connection.getJDBCConnection() == null) {
   21.61 -            return false;
   21.62 -        }
   21.63 -
   21.64 -        try {
   21.65 -            String sqlSelect = " SELECT taddr FROM   v$session WHERE  AUDsid=userenv('SESSIONID')";
   21.66 -            stmt = connection.getJDBCConnection().prepareStatement(sqlSelect);
   21.67 -            rs = stmt.executeQuery();
   21.68 -            if (rs.next()) {
   21.69 -                commitData = rs.getString(1);
   21.70 -            }
   21.71 -            if (commitData != null) {
   21.72 -                return true;
   21.73 -            } else {
   21.74 -                return false;
   21.75 -            }
   21.76 -        } catch (SQLException ex) {
   21.77 -            Exceptions.printStackTrace(ex);
   21.78 -        }
   21.79 -        return false;
   21.80 -    }
   21.81 -
   21.82      private void clearConnectionPool() {
   21.83          synchronized (connectionPool) {
   21.84              while (!connectionPool.isEmpty()) {
   21.85 @@ -315,6 +273,10 @@
   21.86          }
   21.87      }
   21.88  
   21.89 +    /**
   21.90 +     *
   21.91 +     * @return the Template Connection (main connection).
   21.92 +     */
   21.93      public DatabaseConnection getTemplateConnection() {
   21.94          if (templateConnection != null) {
   21.95              return templateConnection;
   21.96 @@ -465,7 +427,7 @@
   21.97       * using Oracle's 'Dbms_Application_Info.Set_Module' procedure. This will be useful 
   21.98       * for tracing current connections in the DB created by NetBeans by querying 'v$sessions'
   21.99       */
  21.100 -    public void setModuleInOracle(final DatabaseConnection connection) {
  21.101 +    public static void setModuleInOracle(final DatabaseConnection connection) {
  21.102          try {
  21.103              ResultSet rs = null;
  21.104              CallableStatement stmt = null;
  21.105 @@ -635,7 +597,7 @@
  21.106          changeSupport.removePropertyChangeListener(listener);
  21.107      }
  21.108  
  21.109 -    public boolean testConnection(DatabaseConnection connection) {
  21.110 +    public static boolean testConnection(DatabaseConnection connection) {
  21.111          Connection con = connection.getJDBCConnection();
  21.112          if (con == null) {
  21.113              return false;
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionNewExecutor.java	Thu May 23 14:23:18 2013 +0200
    22.3 @@ -0,0 +1,112 @@
    22.4 +/*
    22.5 + * To change this template, choose Tools | Templates
    22.6 + * and open the template in the editor.
    22.7 + */
    22.8 +package org.netbeans.modules.plsqlsupport.db;
    22.9 +
   22.10 +import java.beans.PropertyChangeListener;
   22.11 +import java.sql.Connection;
   22.12 +import javax.swing.JOptionPane;
   22.13 +import org.netbeans.api.db.explorer.DatabaseConnection;
   22.14 +import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
   22.15 +import org.openide.filesystems.FileObject;
   22.16 +import org.openide.windows.IOProvider;
   22.17 +
   22.18 +/**
   22.19 + * reference usage holder
   22.20 + *
   22.21 + * @author chrlse
   22.22 + */
   22.23 +public class DatabaseConnectionNewExecutor implements DatabaseConnectionExecutor {
   22.24 +
   22.25 +    public static DatabaseConnectionNewExecutor create(DatabaseConnection connection, FileObject fileObject) {
   22.26 +        return new DatabaseConnectionNewExecutor(connection, new DatabaseTransaction(connection, IOProvider.getDefault().getIO(fileObject.getNameExt(), false)));
   22.27 +    }
   22.28 +    private DatabaseConnection connection;
   22.29 +    private DatabaseTransaction transaction;
   22.30 +
   22.31 +    private DatabaseConnectionNewExecutor(DatabaseConnection connection, DatabaseTransaction transaction) {
   22.32 +        this.connection = connection;
   22.33 +        this.transaction = transaction;
   22.34 +    }
   22.35 +
   22.36 +    public DatabaseConnection getConnection() {
   22.37 +        return connection;
   22.38 +    }
   22.39 +
   22.40 +    /**
   22.41 +     *
   22.42 +     * @param newConnection the new {@link DatabaseConnection} to be used.
   22.43 +     * @return true if the given connection is the same as the old. true if given is a new different connection. false
   22.44 +     * if open transaction exist on old connection and user selects cancel.
   22.45 +     */
   22.46 +    public boolean updateConnection(DatabaseConnection newConnection) {
   22.47 +        if (!connectionHasChanged(newConnection)) {
   22.48 +            return true;
   22.49 +        }
   22.50 +        if (closeOpenTransaction()) {
   22.51 +            connection = newConnection;
   22.52 +            DatabaseConnectionManager.setModuleInOracle(connection);
   22.53 +            transaction.setConnection(connection);
   22.54 +            return true;
   22.55 +        }
   22.56 +        return false;
   22.57 +    }
   22.58 +
   22.59 +    private boolean connectionHasChanged(DatabaseConnection newConnection) {
   22.60 +        return connection != null && !connection.getName().equals(newConnection.getName());
   22.61 +    }
   22.62 +
   22.63 +    DatabaseTransaction getTransaction() {
   22.64 +        return transaction;
   22.65 +    }
   22.66 +
   22.67 +    public String getDisplayName() {
   22.68 +        return "Using DB: " + connection.getDisplayName() + " [" + connection.getName() + "]";
   22.69 +    }
   22.70 +
   22.71 +    public boolean hasOpenTransaction() {
   22.72 +        return transaction.hasOpenTransaction();
   22.73 +    }
   22.74 +
   22.75 +//    public void openTransaction() {
   22.76 +//        transaction.open();
   22.77 +//    }
   22.78 +    public Connection getJDBCConnection() {
   22.79 +        return connection.getJDBCConnection();
   22.80 +    }
   22.81 +
   22.82 +    public void addTransactionListener(PropertyChangeListener changeListener) {
   22.83 +        transaction.addPropertyChangeListener(changeListener);
   22.84 +    }
   22.85 +
   22.86 +    public void commitTransaction() {
   22.87 +        transaction.commitTransaction();
   22.88 +    }
   22.89 +
   22.90 +    public void rollbackTransaction() {
   22.91 +        transaction.rollbackTransaction();
   22.92 +    }
   22.93 +
   22.94 +    /**
   22.95 +     * Close transaction if open, either by commit or rollback based on feedback from user.
   22.96 +     *
   22.97 +     * @return
   22.98 +     */
   22.99 +    public boolean closeOpenTransaction() {
  22.100 +        if (!OptionsUtilities.isDeployNoPromptEnabled() && transaction.hasOpenTransaction()) {
  22.101 +            String msg = "Commit open transactions for " + connection.getDisplayName() + "?";
  22.102 +            String title = "Commit open transaction?";
  22.103 +            int dialogAnswer = JOptionPane.showOptionDialog(null, msg, title, JOptionPane.YES_NO_CANCEL_OPTION,
  22.104 +                    JOptionPane.QUESTION_MESSAGE, null, null, null);
  22.105 +            if (dialogAnswer == JOptionPane.YES_OPTION) {
  22.106 +                transaction.commitTransaction();
  22.107 +            } else if (dialogAnswer == JOptionPane.NO_OPTION) {
  22.108 +                transaction.rollbackTransaction();
  22.109 +            } else {
  22.110 +                return false;
  22.111 +            }
  22.112 +        }
  22.113 +        return true;
  22.114 +    }
  22.115 +}
    23.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseTransaction.java	Wed May 22 16:22:11 2013 +0530
    23.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseTransaction.java	Thu May 23 14:23:18 2013 +0200
    23.3 @@ -43,14 +43,15 @@
    23.4  
    23.5  import java.beans.PropertyChangeListener;
    23.6  import java.beans.PropertyChangeSupport;
    23.7 -import java.util.ArrayList;
    23.8 -import java.util.List;
    23.9 +import java.sql.CallableStatement;
   23.10 +import java.sql.Connection;
   23.11 +import java.sql.SQLException;
   23.12 +import java.util.logging.Level;
   23.13 +import java.util.logging.Logger;
   23.14  import org.netbeans.api.db.explorer.DatabaseConnection;
   23.15  import org.netbeans.api.progress.ProgressHandle;
   23.16  import org.netbeans.api.progress.ProgressHandleFactory;
   23.17 -import org.openide.loaders.DataObject;
   23.18  import org.openide.util.Exceptions;
   23.19 -import org.openide.windows.IOProvider;
   23.20  import org.openide.windows.InputOutput;
   23.21  
   23.22  /**
   23.23 @@ -60,66 +61,52 @@
   23.24   */
   23.25  public class DatabaseTransaction {
   23.26  
   23.27 -    private final static List<DatabaseTransaction> instance = new ArrayList<DatabaseTransaction>();
   23.28 -    private boolean open;
   23.29 -    private final DataObject dataObject;
   23.30 -    public static final String PROP_commit = "PlsqlCommit";
   23.31 +    private static final Logger LOG = Logger.getLogger(DatabaseTransaction.class.getName());
   23.32 +    public static final String PROP_TRANSACTION = "TransactionOpen";
   23.33      private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
   23.34 +    private DatabaseConnection connection;
   23.35      private final InputOutput io;
   23.36 +    private boolean open = false;
   23.37  
   23.38 -    public DatabaseTransaction(DataObject dataObject, InputOutput io) {
   23.39 -        open = false;
   23.40 -        this.dataObject = dataObject;
   23.41 +    public DatabaseTransaction(DatabaseConnection connection, InputOutput io) {
   23.42 +        this.connection = connection;
   23.43          this.io = io;
   23.44      }
   23.45  
   23.46 -    public static DatabaseTransaction getInstance(DataObject object) {
   23.47 -        if (object == null) {
   23.48 -            return null;
   23.49 -        }
   23.50 -        InputOutput io = IOProvider.getDefault().getIO(object.getPrimaryFile().getNameExt(), false);
   23.51 -
   23.52 -        if (instance.isEmpty()) {
   23.53 -            instance.add(new DatabaseTransaction(object, io));
   23.54 -            return instance.get(0);
   23.55 -        } else {
   23.56 -            for (int i = 0; i < instance.size(); i++) {
   23.57 -                DatabaseTransaction plsqlCommit = instance.get(i);
   23.58 -                if (plsqlCommit.dataObject.equals(object)) {
   23.59 -                    return plsqlCommit;
   23.60 -                }
   23.61 -            }
   23.62 -            DatabaseTransaction transaction = new DatabaseTransaction(object, io);
   23.63 -            instance.add(transaction);
   23.64 -            return transaction;
   23.65 -        }
   23.66 +    void setConnection(DatabaseConnection connection) {
   23.67 +        this.connection = connection;
   23.68 +        close();
   23.69      }
   23.70  
   23.71 -    public void open() {
   23.72 -        setOpen(true);
   23.73 -    }
   23.74 -
   23.75 -    public void close() {
   23.76 +//    public void open() {
   23.77 +//        setOpen(true);
   23.78 +//    }
   23.79 +//
   23.80 +    private void close() {
   23.81          setOpen(false);
   23.82      }
   23.83  
   23.84      private void setOpen(boolean newOpen) {
   23.85          boolean oldOpen = open;
   23.86          open = newOpen;
   23.87 -        changeSupport.firePropertyChange(PROP_commit, oldOpen, open);
   23.88 +        changeSupport.firePropertyChange(PROP_TRANSACTION, oldOpen, open);
   23.89      }
   23.90  
   23.91      public boolean isOpen() {
   23.92          return open;
   23.93      }
   23.94  
   23.95 -    public void commitTransaction(DatabaseConnection connection, DatabaseConnectionManager connectionProvider) {
   23.96 +    /**
   23.97 +     *
   23.98 +     *
   23.99 +     */
  23.100 +    public void commitTransaction() {
  23.101          ProgressHandle handle = ProgressHandleFactory.createHandle("Commit database file...");
  23.102          handle.start();
  23.103  
  23.104          try {
  23.105 -            if (connection.getJDBCConnection() != null && connectionProvider.hasDataToCommit(connection)) {
  23.106 -                connectionProvider.commitRollbackTransactions(connection, true);
  23.107 +            if (hasOpenTransaction()) {
  23.108 +                commitRollbackTransactions(true);
  23.109              }
  23.110              close();
  23.111              if (!io.isClosed()) {
  23.112 @@ -133,13 +120,17 @@
  23.113          }
  23.114      }
  23.115  
  23.116 -    public void rollbackTransaction(DatabaseConnection connection, DatabaseConnectionManager connectionProvider) {
  23.117 +    /**
  23.118 +     *
  23.119 +     *
  23.120 +     */
  23.121 +    public void rollbackTransaction() {
  23.122          ProgressHandle handle = ProgressHandleFactory.createHandle("Rollback database file...");
  23.123          handle.start();
  23.124  
  23.125          try {
  23.126 -            if (connection.getJDBCConnection() != null && connectionProvider.hasDataToCommit(connection)) {
  23.127 -                connectionProvider.commitRollbackTransactions(connection, false);
  23.128 +            if (hasOpenTransaction()) {
  23.129 +                commitRollbackTransactions(false);
  23.130              }
  23.131              close();
  23.132              if (!io.isClosed()) {
  23.133 @@ -173,4 +164,65 @@
  23.134          }
  23.135          changeSupport.addPropertyChangeListener(propertyName, listener);
  23.136      }
  23.137 +
  23.138 +    /**
  23.139 +     *
  23.140 +     *
  23.141 +     * @return True if there in on going transactions for a command window.
  23.142 +     */
  23.143 +    public boolean hasOpenTransaction() {
  23.144 +        boolean isOpen = false;
  23.145 +        String commitData = null;
  23.146 +        if (connection.getJDBCConnection() == null) {
  23.147 +            setOpen(isOpen);
  23.148 +            return isOpen;
  23.149 +        }
  23.150 +
  23.151 +        try {
  23.152 +            String sqlProc = "{call ? := DBMS_TRANSACTION.local_transaction_id}";
  23.153 +            CallableStatement stmt = connection.getJDBCConnection().prepareCall(sqlProc);
  23.154 +            stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
  23.155 +            stmt.executeUpdate();
  23.156 +            String transactionId = stmt.getString(1);
  23.157 +//            System.out.println("transaction:" + transactionId);
  23.158 +//            String sqlSelect = " SELECT taddr FROM   v$session WHERE  AUDsid=userenv('SESSIONID')";
  23.159 +//            ResultSet rs = connection.getJDBCConnection().prepareStatement(sqlSelect).executeQuery();
  23.160 +//            if (rs.next()) {
  23.161 +//                commitData = rs.getString(1);
  23.162 +//            }
  23.163 +            io.getOut().println(("transactionId=" + transactionId));
  23.164 +            if (transactionId != null) {
  23.165 +                io.getOut().println(("transactionId=" + transactionId));
  23.166 +                isOpen = true;
  23.167 +            } else {
  23.168 +                isOpen = false;
  23.169 +            }
  23.170 +        } catch (SQLException ex) {
  23.171 +            LOG.log(Level.WARNING, "", ex);
  23.172 +            isOpen = false;
  23.173 +        }
  23.174 +        setOpen(isOpen);
  23.175 +        return isOpen;
  23.176 +    }
  23.177 +
  23.178 +    /**
  23.179 +     *
  23.180 +     * @param commit the value of commit
  23.181 +     */
  23.182 +    private void commitRollbackTransactions(boolean commit) {
  23.183 +        try {
  23.184 +            if (connection.getJDBCConnection() == null) {
  23.185 +                return;
  23.186 +            }
  23.187 +            Connection con = connection.getJDBCConnection();
  23.188 +
  23.189 +            if (commit) {
  23.190 +                con.commit();
  23.191 +            } else {
  23.192 +                con.rollback();
  23.193 +            }
  23.194 +        } catch (SQLException ex) {
  23.195 +            Exceptions.printStackTrace(ex);
  23.196 +        }
  23.197 +    }
  23.198  }