will check for open session when deciding if a transaction is open or not. instead of just looking in the executed code to see if some DML commands are used.
authorchrislovsund@netbeans.org
Fri, 17 May 2013 15:22:34 +0200
changeset 402cb020c7e10a6
parent 401 b82d3dc958ae
child 403 22fdc507e8c3
will check for open session when deciding if a transaction is open or not. instead of just looking in the executed code to see if some DML commands are used.
some refactoring done, more needed.
EADS-3602 - Transaction buttons does not get enabled when executing code that should leave transaction open/pending
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/PlsqlRollbackAction.java
PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlTransaction.java
PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlDataObject.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionHolder.java
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseTransaction.java
     1.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlCommitAction.java	Fri May 17 12:53:09 2013 +0530
     1.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlCommitAction.java	Fri May 17 15:22:34 2013 +0200
     1.3 @@ -54,7 +54,9 @@
     1.4  import javax.swing.JButton;
     1.5  import org.netbeans.api.db.explorer.DatabaseConnection;
     1.6  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
     1.7 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionHolder;
     1.8  import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
     1.9 +import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
    1.10  import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
    1.11  import org.openide.awt.ActionID;
    1.12  import org.openide.awt.ActionRegistration;
    1.13 @@ -72,9 +74,10 @@
    1.14      private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    1.15      private final DataObject dataObject;
    1.16      private DatabaseConnectionManager connectionProvider;
    1.17 +    private DatabaseConnectionHolder connectionHolder;
    1.18      private DatabaseConnection connection;
    1.19      private JButton button;
    1.20 -    private final PlsqlTransaction transaction;
    1.21 +    private final DatabaseTransaction transaction;
    1.22      private final PropertyChangeListener changeListener = new EnableCommit();
    1.23  
    1.24      public PlsqlCommitAction() {
    1.25 @@ -86,7 +89,7 @@
    1.26          putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/database_commit.png")));
    1.27  
    1.28          dataObject = context.lookup(DataObject.class);
    1.29 -        transaction = PlsqlTransaction.getInstance(dataObject);
    1.30 +        transaction = DatabaseTransaction.getInstance(dataObject);
    1.31      }
    1.32  
    1.33      @Override
    1.34 @@ -129,10 +132,6 @@
    1.35              return;
    1.36          }
    1.37  
    1.38 -        if (!connectionProvider.hasDataToCommit(connection)) {
    1.39 -            return;
    1.40 -        }
    1.41 -
    1.42          saveIfModified(dataObject);
    1.43          transaction.commitTransaction(connection, connectionProvider);
    1.44      }
     2.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java	Fri May 17 12:53:09 2013 +0530
     2.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java	Fri May 17 15:22:34 2013 +0200
     2.3 @@ -64,7 +64,9 @@
     2.4  import org.netbeans.api.progress.ProgressHandleFactory;
     2.5  import org.netbeans.modules.plsql.filetype.PlsqlDataObject;
     2.6  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
     2.7 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionHolder;
     2.8  import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
     2.9 +import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
    2.10  import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
    2.11  import org.openide.awt.*;
    2.12  import org.openide.cookies.EditorCookie;
    2.13 @@ -101,7 +103,7 @@
    2.14      private JButton button;
    2.15      private ActionListener buttonListener = new ButtonListener();
    2.16      private boolean autoCommit = true;
    2.17 -    private final PlsqlTransaction transaction;
    2.18 +    private final DatabaseTransaction transaction;
    2.19  
    2.20      public PlsqlExecuteAction() {
    2.21          this(Utilities.actionsGlobalContext());
    2.22 @@ -117,7 +119,7 @@
    2.23          if (validator.isValidTDB(dataObject)) {
    2.24              autoCommit = OptionsUtilities.isCommandWindowAutoCommitEnabled();
    2.25          }
    2.26 -        transaction = PlsqlTransaction.getInstance(dataObject);
    2.27 +        transaction = DatabaseTransaction.getInstance(dataObject);
    2.28      }
    2.29  
    2.30      @Override
    2.31 @@ -421,6 +423,9 @@
    2.32          }
    2.33  
    2.34          private void modifyConnection() {
    2.35 +            DatabaseConnectionHolder connectionHolder = dataObject.getLookup().lookup(DatabaseConnectionHolder.class);
    2.36 +            connectionHolder.setDatabaseConnection(connection);
    2.37 +            // will remove below if new impl is better.
    2.38              plsqlDataobject = (PlsqlDataObject) dataObject;
    2.39              plsqlDataobject.modifyLookupDatabaseConnection(connection);
    2.40          }
    2.41 @@ -428,9 +433,6 @@
    2.42  
    2.43      private class ButtonListener implements ActionListener {
    2.44  
    2.45 -        public ButtonListener() {
    2.46 -        }
    2.47 -
    2.48          @Override
    2.49          public void actionPerformed(ActionEvent e) {
    2.50  
    2.51 @@ -445,9 +447,6 @@
    2.52  
    2.53      private class PopupMenuPopulator implements PropertyChangeListener {
    2.54  
    2.55 -        public PopupMenuPopulator() {
    2.56 -        }
    2.57 -
    2.58          @Override
    2.59          public void propertyChange(PropertyChangeEvent event) {
    2.60              if (popup != null) {
     3.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java	Fri May 17 12:53:09 2013 +0530
     3.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlFileExecutor.java	Fri May 17 15:22:34 2013 +0200
     3.3 @@ -53,8 +53,8 @@
     3.4  import java.lang.reflect.Method;
     3.5  import java.math.BigDecimal;
     3.6  import java.sql.*;
     3.7 +import java.util.*;
     3.8  import java.util.Date;
     3.9 -import java.util.*;
    3.10  import javax.swing.JButton;
    3.11  import javax.swing.JMenuItem;
    3.12  import javax.swing.JOptionPane;
    3.13 @@ -83,6 +83,7 @@
    3.14  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
    3.15  import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    3.16  import org.netbeans.modules.plsqlsupport.db.DatabaseContentManager;
    3.17 +import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
    3.18  import org.netbeans.modules.plsqlsupport.db.ui.SQLCommandWindow;
    3.19  import org.openide.DialogDisplayer;
    3.20  import org.openide.NotifyDescriptor;
    3.21 @@ -102,6 +103,7 @@
    3.22  
    3.23  public class PlsqlFileExecutor {
    3.24  
    3.25 +    private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    3.26      private boolean cancel = false;
    3.27      private final RequestProcessor rp = new RequestProcessor("SQLExecution", 1, true);
    3.28      // execution results. Not synchronized since accessed only from rp of throughput 1.
    3.29 @@ -344,7 +346,7 @@
    3.30              return this.preparedIO;
    3.31          }
    3.32          String startMsg = "Deploying " + FileExecutionUtil.getActivatedFileName(dataObj);
    3.33 -        if (fileName.endsWith(".tdb")) {
    3.34 +        if (validator.isValidTDB(dataObj)) {
    3.35              startMsg = "Executing " + fileName;
    3.36          }
    3.37          InputOutput io = null;
    3.38 @@ -378,12 +380,7 @@
    3.39      //store in object history if this is an SQL Command window (*.tdb)
    3.40      private void addToHistory(Document doc) {
    3.41          DataObject obj = FileExecutionUtil.getDataObject(doc);
    3.42 -        FileObject file = obj.getPrimaryFile();
    3.43 -        if (file == null) {
    3.44 -            return;
    3.45 -        }
    3.46 -        String extension = file.getExt();
    3.47 -        if ("tdb".equalsIgnoreCase(extension)) {
    3.48 +        if (validator.isValidTDB(obj)) {
    3.49              StatementExecutionHistory history = obj.getLookup().lookup(StatementExecutionHistory.class);
    3.50              try {
    3.51                  history.addEntry(doc.getText(0, doc.getLength()));
    3.52 @@ -395,7 +392,6 @@
    3.53      }
    3.54  
    3.55      public InputOutput executePLSQL(List<PlsqlExecutableObject> executableObjs, Document doc, boolean hidden, boolean autoCommit) {
    3.56 -        final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    3.57          Project project = null;
    3.58          Object object = doc.getProperty(Document.StreamDescriptionProperty);
    3.59          if (object instanceof DataObject) {
    3.60 @@ -424,13 +420,13 @@
    3.61          String fileName = dataObj.getPrimaryFile().getNameExt();
    3.62          boolean moreRowsToBeFetched = false;
    3.63          //Check whether this is the excution window file
    3.64 -        if (fileName.endsWith(".tdb")) {
    3.65 +        if (validator.isValidTDB(dataObj)) {
    3.66              endMsg = "Finished executing command ";
    3.67          }
    3.68          Connection con;
    3.69          Statement stm = null;
    3.70          String firstWord = null;
    3.71 -        PlsqlTransaction commit = PlsqlTransaction.getInstance((DataObject) object);
    3.72 +        DatabaseTransaction transaction = DatabaseTransaction.getInstance((DataObject) object);
    3.73  
    3.74          //quick & dirty fix to avoid having output tabs for the SQL Execution window (unless there's an exception)
    3.75          //first check to see if this is a simple select statement and if so treat it separately.
    3.76 @@ -990,17 +986,12 @@
    3.77                  }
    3.78              }
    3.79  
    3.80 -            if (fileName.endsWith(".tdb") && !autoCommit) {
    3.81 -                if (!deploymentOk && !(firstWord != null
    3.82 -                        && (firstWord.equalsIgnoreCase("INSERT") || firstWord.equalsIgnoreCase("UPDATE") || firstWord.equalsIgnoreCase("DELETE")))) {
    3.83 +            if (validator.isValidTDB(dataObj) && !autoCommit) {
    3.84 +                if (!deploymentOk && !connectionProvider.hasDataToCommit(connection)) {
    3.85                      con.commit();
    3.86 -                } else {
    3.87 -                    if (deploymentOk && (firstWord != null
    3.88 -                            && (firstWord.equalsIgnoreCase("INSERT") || firstWord.equalsIgnoreCase("UPDATE") || firstWord.equalsIgnoreCase("DELETE")))) {
    3.89 -                        commit.open();
    3.90 -                    }
    3.91 +                } else if (deploymentOk && connectionProvider.hasDataToCommit(connection)) {
    3.92 +                    transaction.open();
    3.93                  }
    3.94 -
    3.95              } else {
    3.96                  con.commit();
    3.97              }
    3.98 @@ -1188,13 +1179,10 @@
    3.99                  } else if (tokenTxt.toUpperCase(Locale.ENGLISH).startsWith("SET ")) {
   3.100                      StringTokenizer tokenizer = new StringTokenizer(tokenTxt);
   3.101                      tokenizer.nextToken();
   3.102 -                    String alias;
   3.103 -                    boolean isNext = tokenizer.hasMoreTokens();
   3.104                      tokenizer.nextToken();
   3.105 -                    isNext = tokenizer.hasMoreTokens();
   3.106                      //alias
   3.107 -                    if (isNext) {
   3.108 -                        alias = tokenizer.nextToken();
   3.109 +                    if (tokenizer.hasMoreTokens()) {
   3.110 +                        tokenizer.nextToken();
   3.111                      } else {
   3.112                          break;
   3.113                      }
     4.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlRollbackAction.java	Fri May 17 12:53:09 2013 +0530
     4.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlRollbackAction.java	Fri May 17 15:22:34 2013 +0200
     4.3 @@ -55,6 +55,7 @@
     4.4  import org.netbeans.api.db.explorer.DatabaseConnection;
     4.5  import org.netbeans.modules.plsql.utilities.PlsqlFileValidatorService;
     4.6  import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
     4.7 +import org.netbeans.modules.plsqlsupport.db.DatabaseTransaction;
     4.8  import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
     4.9  import org.openide.awt.ActionID;
    4.10  import org.openide.awt.ActionRegistration;
    4.11 @@ -71,7 +72,7 @@
    4.12  
    4.13      private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
    4.14      private final DataObject dataObject;
    4.15 -    private final PlsqlTransaction transaction;
    4.16 +    private final DatabaseTransaction transaction;
    4.17      private DatabaseConnectionManager connectionProvider;
    4.18      private JButton button;
    4.19      private DatabaseConnection connection;
    4.20 @@ -87,7 +88,7 @@
    4.21          putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/database_rollback.png")));
    4.22  
    4.23          dataObject = context.lookup(DataObject.class);
    4.24 -        transaction = PlsqlTransaction.getInstance(dataObject);
    4.25 +        transaction = DatabaseTransaction.getInstance(dataObject);
    4.26      }
    4.27  
    4.28      @Override
    4.29 @@ -131,10 +132,6 @@
    4.30              return;
    4.31          }
    4.32  
    4.33 -        if (!connectionProvider.hasDataToCommit(connection)) {
    4.34 -            return;
    4.35 -        }
    4.36 -
    4.37          saveIfModified(dataObject);
    4.38          transaction.rollbackTransaction(connection, connectionProvider);
    4.39      }
     5.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlTransaction.java	Fri May 17 12:53:09 2013 +0530
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,181 +0,0 @@
     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.beans.PropertyChangeListener;
    5.48 -import java.beans.PropertyChangeSupport;
    5.49 -import java.util.ArrayList;
    5.50 -import java.util.List;
    5.51 -import org.netbeans.api.db.explorer.DatabaseConnection;
    5.52 -import org.openide.loaders.DataObject;
    5.53 -import org.openide.windows.InputOutput;
    5.54 -import org.netbeans.api.progress.ProgressHandle;
    5.55 -import org.netbeans.api.progress.ProgressHandleFactory;
    5.56 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
    5.57 -import org.openide.util.Exceptions;
    5.58 -import org.openide.windows.IOProvider;
    5.59 -
    5.60 -/**
    5.61 - *
    5.62 - * @author SubSLK
    5.63 - * @author chrlse
    5.64 - */
    5.65 -public class PlsqlTransaction {
    5.66 -
    5.67 -    private final static List<PlsqlTransaction> instance = new ArrayList<PlsqlTransaction>();
    5.68 -    private boolean open;
    5.69 -    private final DataObject dataObject;
    5.70 -    public static final String PROP_commit = "PlsqlCommit";
    5.71 -    private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    5.72 -    private final InputOutput io;
    5.73 -
    5.74 -    public PlsqlTransaction(DataObject dataObject, InputOutput io) {
    5.75 -        open = false;
    5.76 -        this.dataObject = dataObject;
    5.77 -        this.io = io;
    5.78 -    }
    5.79 -
    5.80 -    public static PlsqlTransaction getInstance(DataObject object) {
    5.81 -        if (object == null) {
    5.82 -            return null;
    5.83 -        }
    5.84 -        InputOutput io = IOProvider.getDefault().getIO(object.getPrimaryFile().getNameExt(), false);
    5.85 -
    5.86 -        if (instance.isEmpty()) {
    5.87 -            instance.add(new PlsqlTransaction(object, io));
    5.88 -            return instance.get(0);
    5.89 -        } else {
    5.90 -            for (int i = 0; i < instance.size(); i++) {
    5.91 -                PlsqlTransaction plsqlCommit = instance.get(i);
    5.92 -                if (plsqlCommit.dataObject.equals(object)) {
    5.93 -                    return plsqlCommit;
    5.94 -                }
    5.95 -            }
    5.96 -            PlsqlTransaction plsqlCommit = new PlsqlTransaction(object, io);
    5.97 -            instance.add(plsqlCommit);
    5.98 -            return plsqlCommit;
    5.99 -        }
   5.100 -    }
   5.101 -
   5.102 -    void open() {
   5.103 -        setOpen(true);
   5.104 -    }
   5.105 -
   5.106 -    void close() {
   5.107 -        setOpen(false);
   5.108 -    }
   5.109 -
   5.110 -    private void setOpen(boolean newOpen) {
   5.111 -        boolean oldOpen = open;
   5.112 -        open = newOpen;
   5.113 -        changeSupport.firePropertyChange(PROP_commit, oldOpen, open);
   5.114 -    }
   5.115 -
   5.116 -    public boolean isOpen() {
   5.117 -        return open;
   5.118 -    }
   5.119 -
   5.120 -    public void commitTransaction(DatabaseConnection connection, DatabaseConnectionManager connectionProvider) {
   5.121 -
   5.122 -        ProgressHandle handle = ProgressHandleFactory.createHandle("Commit database file...");
   5.123 -        handle.start();
   5.124 -
   5.125 -        try {
   5.126 -            if (!io.isClosed()) {
   5.127 -                io.getOut().println((new StringBuilder()).append("> Commit Statement successfully"));
   5.128 -            }
   5.129 -
   5.130 -            if (connection.getJDBCConnection() != null) {
   5.131 -                connectionProvider.commitRollbackTransactions(connection, true);
   5.132 -                close();
   5.133 -            }
   5.134 -
   5.135 -        } catch (Exception ex) {
   5.136 -            io.getOut().println((new StringBuilder()).append(">!!! Error Commit Statement"));
   5.137 -            Exceptions.printStackTrace(ex);
   5.138 -        } finally {
   5.139 -            handle.finish();
   5.140 -        }
   5.141 -    }
   5.142 -
   5.143 -    public void rollbackTransaction(DatabaseConnection connection, DatabaseConnectionManager connectionProvider) {
   5.144 -        ProgressHandle handle = ProgressHandleFactory.createHandle("Rollback database file...");
   5.145 -        handle.start();
   5.146 -
   5.147 -        try {
   5.148 -            if (!io.isClosed()) {
   5.149 -                io.getOut().println((new StringBuilder()).append("> Rollback Statement successfully"));
   5.150 -            }
   5.151 -
   5.152 -            if (connection.getJDBCConnection() != null) {
   5.153 -                connectionProvider.commitRollbackTransactions(connection, false);
   5.154 -                close();
   5.155 -            }
   5.156 -
   5.157 -        } catch (Exception ex) {
   5.158 -            io.getOut().println((new StringBuilder()).append(">!!! Error Rollback Statement"));
   5.159 -            Exceptions.printStackTrace(ex);
   5.160 -        } finally {
   5.161 -            handle.finish();
   5.162 -        }
   5.163 -    }
   5.164 -
   5.165 -    public void addPropertyChangeListener(PropertyChangeListener listener) {
   5.166 -        PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
   5.167 -        for (int i = 0; i < listeners.length; i++) {
   5.168 -            if (listeners[i] == listener) {
   5.169 -                return;
   5.170 -            }
   5.171 -        }
   5.172 -        changeSupport.addPropertyChangeListener(listener);
   5.173 -    }
   5.174 -
   5.175 -    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
   5.176 -        PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
   5.177 -        for (int i = 0; i < listeners.length; i++) {
   5.178 -            if (listeners[i] == listener) {
   5.179 -                return;
   5.180 -            }
   5.181 -        }
   5.182 -        changeSupport.addPropertyChangeListener(propertyName, listener);
   5.183 -    }
   5.184 -}
     6.1 --- a/PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlDataObject.java	Fri May 17 12:53:09 2013 +0530
     6.2 +++ b/PLSQL/FileType/src/org/netbeans/modules/plsql/filetype/PlsqlDataObject.java	Fri May 17 15:22:34 2013 +0200
     6.3 @@ -64,6 +64,7 @@
     6.4  import org.openide.util.lookup.Lookups;
     6.5  import org.openide.util.lookup.ProxyLookup;
     6.6  import org.netbeans.api.db.explorer.DatabaseConnection;
     6.7 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionHolder;
     6.8  import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
     6.9  
    6.10  public class PlsqlDataObject extends MultiDataObject {
    6.11 @@ -76,6 +77,7 @@
    6.12     private PlsqlAnnotationManager annotationManager = null;
    6.13     private boolean isAnnotationsEnabled = false;
    6.14     private final PlsqlEditorSupport editorSupport;
    6.15 +   private DatabaseConnectionHolder connectionHolder;
    6.16     private DatabaseConnection databaseConnection;
    6.17     private StatementExecutionHistory statementExecutionHistory;
    6.18  
    6.19 @@ -109,6 +111,7 @@
    6.20        if (project != null) {
    6.21           databaseConnection = DatabaseConnectionManager.getInstance(project).getTemplateConnection();
    6.22        }
    6.23 +      connectionHolder = new DatabaseConnectionHolder(databaseConnection);
    6.24        createLookup();
    6.25     }
    6.26  
    6.27 @@ -131,6 +134,7 @@
    6.28  
    6.29     /**
    6.30      * Return cookie set, to be used in editor support
    6.31 +    *
    6.32      * @return
    6.33      */
    6.34     CookieSet getCookieSet0() {
    6.35 @@ -139,7 +143,6 @@
    6.36  
    6.37     private void addPreferenceListener() {
    6.38        listener = new PreferenceChangeListener() {
    6.39 -
    6.40           @Override
    6.41           public void preferenceChange(PreferenceChangeEvent evt) {
    6.42              if (evt.getKey().equals(OptionsUtilities.PLSQL_ANNOTATIONS_ENABLED_KEY)) {
    6.43 @@ -168,10 +171,11 @@
    6.44        List<Object> objects = new ArrayList<Object>();
    6.45        objects.add(blockFactory);
    6.46        objects.add(statementExecutionHistory);
    6.47 +      objects.add(connectionHolder);
    6.48  
    6.49 -       if (annotationManager != null) {
    6.50 -           objects.add(annotationManager);
    6.51 -       }
    6.52 +      if (annotationManager != null) {
    6.53 +         objects.add(annotationManager);
    6.54 +      }
    6.55  
    6.56        if (databaseConnection != null) {
    6.57           objects.add(databaseConnection);
    6.58 @@ -180,8 +184,8 @@
    6.59        lookup = new ProxyLookup(new Lookup[]{getCookieSet().getLookup(), fixed});
    6.60     }
    6.61  
    6.62 -   public void modifyLookupDatabaseConnection(DatabaseConnection Connection) {
    6.63 -      databaseConnection = Connection;
    6.64 +   public void modifyLookupDatabaseConnection(DatabaseConnection connection) {
    6.65 +      databaseConnection = connection;
    6.66        createLookup();
    6.67     }
    6.68  
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionHolder.java	Fri May 17 15:22:34 2013 +0200
     7.3 @@ -0,0 +1,41 @@
     7.4 +/*
     7.5 + * To change this template, choose Tools | Templates
     7.6 + * and open the template in the editor.
     7.7 + */
     7.8 +package org.netbeans.modules.plsqlsupport.db;
     7.9 +
    7.10 +import org.netbeans.api.db.explorer.DatabaseConnection;
    7.11 +
    7.12 +/**
    7.13 + *
    7.14 + * @author chrlse
    7.15 + */
    7.16 +public class DatabaseConnectionHolder {
    7.17 +
    7.18 +    private DatabaseConnection databaseConnection;
    7.19 +    private DatabaseTransaction transaction;
    7.20 +
    7.21 +    public DatabaseConnectionHolder() {
    7.22 +    }
    7.23 +
    7.24 +    public DatabaseConnectionHolder(DatabaseConnection databaseConnection) {
    7.25 +        this.databaseConnection = databaseConnection;
    7.26 +    }
    7.27 +
    7.28 +    public DatabaseConnection getDatabaseConnection() {
    7.29 +        return databaseConnection;
    7.30 +    }
    7.31 +
    7.32 +    public void setDatabaseConnection(DatabaseConnection databaseConnection) {
    7.33 +        this.databaseConnection = databaseConnection;
    7.34 +    }
    7.35 +
    7.36 +    public DatabaseTransaction getTransaction() {
    7.37 +        return transaction;
    7.38 +    }
    7.39 +
    7.40 +    public void setTransaction(DatabaseTransaction transaction) {
    7.41 +        this.transaction = transaction;
    7.42 +    }
    7.43 +    
    7.44 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseTransaction.java	Fri May 17 15:22:34 2013 +0200
     8.3 @@ -0,0 +1,176 @@
     8.4 +/*
     8.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 + *
     8.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     8.8 + *
     8.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    8.10 + * Other names may be trademarks of their respective owners.
    8.11 + *
    8.12 + * The contents of this file are subject to the terms of either the GNU
    8.13 + * General Public License Version 2 only ("GPL") or the Common
    8.14 + * Development and Distribution License("CDDL") (collectively, the
    8.15 + * "License"). You may not use this file except in compliance with the
    8.16 + * License. You can obtain a copy of the License at
    8.17 + * http://www.netbeans.org/cddl-gplv2.html
    8.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    8.19 + * specific language governing permissions and limitations under the
    8.20 + * License.  When distributing the software, include this License Header
    8.21 + * Notice in each file and include the License file at
    8.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    8.23 + * particular file as subject to the "Classpath" exception as provided
    8.24 + * by Oracle in the GPL Version 2 section of the License file that
    8.25 + * accompanied this code. If applicable, add the following below the
    8.26 + * License Header, with the fields enclosed by brackets [] replaced by
    8.27 + * your own identifying information:
    8.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    8.29 + *
    8.30 + * If you wish your version of this file to be governed by only the CDDL
    8.31 + * or only the GPL Version 2, indicate your decision by adding
    8.32 + * "[Contributor] elects to include this software in this distribution
    8.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    8.34 + * single choice of license, a recipient has the option to distribute
    8.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    8.36 + * to extend the choice of license to its licensees as provided above.
    8.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    8.38 + * Version 2 license, then the option applies only if the new code is
    8.39 + * made subject to such option by the copyright holder.
    8.40 + *
    8.41 + * Contributor(s):
    8.42 + *
    8.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
    8.44 + */
    8.45 +package org.netbeans.modules.plsqlsupport.db;
    8.46 +
    8.47 +import java.beans.PropertyChangeListener;
    8.48 +import java.beans.PropertyChangeSupport;
    8.49 +import java.util.ArrayList;
    8.50 +import java.util.List;
    8.51 +import org.netbeans.api.db.explorer.DatabaseConnection;
    8.52 +import org.netbeans.api.progress.ProgressHandle;
    8.53 +import org.netbeans.api.progress.ProgressHandleFactory;
    8.54 +import org.openide.loaders.DataObject;
    8.55 +import org.openide.util.Exceptions;
    8.56 +import org.openide.windows.IOProvider;
    8.57 +import org.openide.windows.InputOutput;
    8.58 +
    8.59 +/**
    8.60 + *
    8.61 + * @author SubSLK
    8.62 + * @author chrlse
    8.63 + */
    8.64 +public class DatabaseTransaction {
    8.65 +
    8.66 +    private final static List<DatabaseTransaction> instance = new ArrayList<DatabaseTransaction>();
    8.67 +    private boolean open;
    8.68 +    private final DataObject dataObject;
    8.69 +    public static final String PROP_commit = "PlsqlCommit";
    8.70 +    private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    8.71 +    private final InputOutput io;
    8.72 +
    8.73 +    public DatabaseTransaction(DataObject dataObject, InputOutput io) {
    8.74 +        open = false;
    8.75 +        this.dataObject = dataObject;
    8.76 +        this.io = io;
    8.77 +    }
    8.78 +
    8.79 +    public static DatabaseTransaction getInstance(DataObject object) {
    8.80 +        if (object == null) {
    8.81 +            return null;
    8.82 +        }
    8.83 +        InputOutput io = IOProvider.getDefault().getIO(object.getPrimaryFile().getNameExt(), false);
    8.84 +
    8.85 +        if (instance.isEmpty()) {
    8.86 +            instance.add(new DatabaseTransaction(object, io));
    8.87 +            return instance.get(0);
    8.88 +        } else {
    8.89 +            for (int i = 0; i < instance.size(); i++) {
    8.90 +                DatabaseTransaction plsqlCommit = instance.get(i);
    8.91 +                if (plsqlCommit.dataObject.equals(object)) {
    8.92 +                    return plsqlCommit;
    8.93 +                }
    8.94 +            }
    8.95 +            DatabaseTransaction transaction = new DatabaseTransaction(object, io);
    8.96 +            instance.add(transaction);
    8.97 +            return transaction;
    8.98 +        }
    8.99 +    }
   8.100 +
   8.101 +    public void open() {
   8.102 +        setOpen(true);
   8.103 +    }
   8.104 +
   8.105 +    public void close() {
   8.106 +        setOpen(false);
   8.107 +    }
   8.108 +
   8.109 +    private void setOpen(boolean newOpen) {
   8.110 +        boolean oldOpen = open;
   8.111 +        open = newOpen;
   8.112 +        changeSupport.firePropertyChange(PROP_commit, oldOpen, open);
   8.113 +    }
   8.114 +
   8.115 +    public boolean isOpen() {
   8.116 +        return open;
   8.117 +    }
   8.118 +
   8.119 +    public void commitTransaction(DatabaseConnection connection, DatabaseConnectionManager connectionProvider) {
   8.120 +        ProgressHandle handle = ProgressHandleFactory.createHandle("Commit database file...");
   8.121 +        handle.start();
   8.122 +
   8.123 +        try {
   8.124 +            if (connection.getJDBCConnection() != null && connectionProvider.hasDataToCommit(connection)) {
   8.125 +                connectionProvider.commitRollbackTransactions(connection, true);
   8.126 +            }
   8.127 +            close();
   8.128 +            if (!io.isClosed()) {
   8.129 +                io.getOut().println((new StringBuilder()).append("> Commit Statement successfully"));
   8.130 +            }
   8.131 +        } catch (Exception ex) {
   8.132 +            io.getOut().println((new StringBuilder()).append(">!!! Error Commit Statement"));
   8.133 +            Exceptions.printStackTrace(ex);
   8.134 +        } finally {
   8.135 +            handle.finish();
   8.136 +        }
   8.137 +    }
   8.138 +
   8.139 +    public void rollbackTransaction(DatabaseConnection connection, DatabaseConnectionManager connectionProvider) {
   8.140 +        ProgressHandle handle = ProgressHandleFactory.createHandle("Rollback database file...");
   8.141 +        handle.start();
   8.142 +
   8.143 +        try {
   8.144 +            if (connection.getJDBCConnection() != null && connectionProvider.hasDataToCommit(connection)) {
   8.145 +                connectionProvider.commitRollbackTransactions(connection, false);
   8.146 +            }
   8.147 +            close();
   8.148 +            if (!io.isClosed()) {
   8.149 +                io.getOut().println((new StringBuilder()).append("> Rollback Statement successfully"));
   8.150 +            }
   8.151 +
   8.152 +        } catch (Exception ex) {
   8.153 +            io.getOut().println((new StringBuilder()).append(">!!! Error Rollback Statement"));
   8.154 +            Exceptions.printStackTrace(ex);
   8.155 +        } finally {
   8.156 +            handle.finish();
   8.157 +        }
   8.158 +    }
   8.159 +
   8.160 +    public void addPropertyChangeListener(PropertyChangeListener listener) {
   8.161 +        PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
   8.162 +        for (int i = 0; i < listeners.length; i++) {
   8.163 +            if (listeners[i] == listener) {
   8.164 +                return;
   8.165 +            }
   8.166 +        }
   8.167 +        changeSupport.addPropertyChangeListener(listener);
   8.168 +    }
   8.169 +
   8.170 +    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
   8.171 +        PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
   8.172 +        for (int i = 0; i < listeners.length; i++) {
   8.173 +            if (listeners[i] == listener) {
   8.174 +                return;
   8.175 +            }
   8.176 +        }
   8.177 +        changeSupport.addPropertyChangeListener(propertyName, listener);
   8.178 +    }
   8.179 +}