1.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/DescribeAction.java Mon May 27 14:06:08 2013 +0200
1.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/DescribeAction.java Mon May 27 17:47:13 2013 +0200
1.3 @@ -41,14 +41,14 @@
1.4 */
1.5 package org.netbeans.modules.plsql.execution;
1.6
1.7 -import org.netbeans.modules.plsqlsupport.db.PlsqlExecutableObjectType;
1.8 -import org.netbeans.modules.plsqlsupport.db.PlsqlExecutableObject;
1.9 import java.util.ArrayList;
1.10 import java.util.List;
1.11 import javax.swing.text.Document;
1.12 import org.netbeans.api.db.explorer.DatabaseConnection;
1.13 import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
1.14 import org.netbeans.modules.plsqlsupport.db.DatabaseContentManager;
1.15 +import org.netbeans.modules.plsqlsupport.db.PlsqlExecutableObject;
1.16 +import org.netbeans.modules.plsqlsupport.db.PlsqlExecutableObjectType;
1.17 import org.openide.awt.ActionID;
1.18 import org.openide.awt.ActionReference;
1.19 import org.openide.awt.ActionRegistration;
1.20 @@ -65,7 +65,7 @@
1.21 * @author YADHLK
1.22 */
1.23 @ActionID(id = "org.netbeans.modules.plsql.execution.DescribeAction", category = "PLSQL")
1.24 -@ActionRegistration(displayName = "#CTL_DescribeAction")
1.25 +@ActionRegistration(displayName = "#CTL_DescribeAction", lazy = true)
1.26 @ActionReference(path = "Editors/text/x-plsql/Popup", position = 440, separatorAfter = 450)
1.27 public class DescribeAction extends CookieAction {
1.28
2.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlCommitAction.java Mon May 27 14:06:08 2013 +0200
2.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlCommitAction.java Mon May 27 17:47:13 2013 +0200
2.3 @@ -70,11 +70,8 @@
2.4
2.5 private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
2.6 private final DataObject dataObject;
2.7 -// private DatabaseConnectionManager connectionProvider;
2.8 private DatabaseConnectionExecutor executor;
2.9 -// private DatabaseConnection connection;
2.10 private JButton button;
2.11 -// private final DatabaseTransaction transaction;
2.12 private final PropertyChangeListener changeListener = new EnableCommit();
2.13
2.14 public PlsqlCommitAction() {
2.15 @@ -118,23 +115,17 @@
2.16
2.17 private void prepareConnection() {
2.18 if (dataObject != null) {
2.19 -// connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
2.20 executor = dataObject.getLookup().lookup(DatabaseConnectionExecutor.class);
2.21 }
2.22 -// connection = dataObject.getLookup().lookup(DatabaseConnection.class);
2.23 }
2.24
2.25 @Override
2.26 public void actionPerformed(ActionEvent event) {
2.27
2.28 prepareConnection();
2.29 -// if (connectionProvider == null || connection == null) {
2.30 -// return;
2.31 -// }
2.32
2.33 saveIfModified(dataObject);
2.34 executor.commitTransaction();
2.35 -// transaction.commitTransaction(connection, connectionProvider);
2.36 }
2.37
2.38 @Override
3.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java Mon May 27 14:06:08 2013 +0200
3.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlExecuteAction.java Mon May 27 17:47:13 2013 +0200
3.3 @@ -72,37 +72,15 @@
3.4 })
3.5 public class PlsqlExecuteAction extends CookieAction {
3.6
3.7 -// private static final Logger LOG = Logger.getLogger(PlsqlExecuteAction.class.getName());
3.8 private static final String ICON_PATH = "org/netbeans/modules/plsql/execution/execute.png";
3.9 - private static final RequestProcessor RP = new RequestProcessor(PlsqlExecuteAction.class.getName(), 4);
3.10 private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
3.11 -// private static final String DATABASE_CONNECTION_KEY = "databaseConnection";
3.12 private static final String TEST_BLOCK_NAME_PREFIX = "TestBlock:";
3.13 private DataObject dataObject;
3.14 -// private PlsqlDataObject plsqlDataobject;
3.15 private DatabaseConnectionExecutor executor;
3.16 -// private PopupMenuPopulator popupMenuPopulator = null;
3.17 -// private JPopupMenu popup;
3.18 -// private JButton button;
3.19 -// private ActionListener buttonListener = new ButtonListener();
3.20 - private boolean autoCommit = true;
3.21
3.22 public PlsqlExecuteAction() {
3.23 super();
3.24 -// this(Utilities.actionsGlobalContext());
3.25 -// }
3.26 -
3.27 -// public PlsqlExecuteAction(Lookup context) {
3.28 -// putValue(NAME, NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_PlsqlExecute"));
3.29 putValue(SHORT_DESCRIPTION, NbBundle.getMessage(PlsqlExecuteAction.class, "CTL_PlsqlExecuteDescription"));
3.30 -// putValue(SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(ICON_PATH)));
3.31 -
3.32 -// dataObject = context.lookup(DataObject.class);
3.33 -
3.34 -// if (validator.isValidTDB(dataObject)) {
3.35 -// autoCommit = OptionsUtilities.isCommandWindowAutoCommitEnabled();
3.36 -// }
3.37 -// connectionSession = dataObject.getLookup().lookup(PlsqlExecutor.class);
3.38 }
3.39
3.40 @Override
3.41 @@ -157,24 +135,10 @@
3.42 dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
3.43 executor = dataObject.getLookup().lookup(DatabaseConnectionExecutor.class);
3.44
3.45 -// if (connectionProvider == null) {
3.46 -// if (dataObject != null) {
3.47 -// connectionProvider = DatabaseConnectionManager.getInstance(dataObject);
3.48 -// if (connectionProvider == null) {
3.49 -// return;
3.50 -// }
3.51 -// }
3.52 -// }
3.53 -
3.54 saveIfModified(dataObject);
3.55
3.56 EditorCookie edCookie = dataObject.getLookup().lookup(EditorCookie.class);
3.57 Document document = edCookie.getDocument();
3.58 -// DataObject obj = FileExecutionUtil.getDataObject(document);
3.59 -// FileObject file = obj.getPrimaryFile();
3.60 -// if (file == null) {
3.61 -// return;
3.62 -// }
3.63
3.64 PlsqlExecutableBlocksMaker blockMaker = new PlsqlExecutableBlocksMaker(document);
3.65 List<PlsqlExecutableObject> blocks = blockMaker.makeExceutableObjects();
3.66 @@ -237,27 +201,4 @@
3.67 Exceptions.printStackTrace(ex);
3.68 }
3.69 }
3.70 -// private class ButtonListener implements ActionListener {
3.71 -//
3.72 -// @Override
3.73 -// public void actionPerformed(ActionEvent e) {
3.74 -//
3.75 -// JMenuItem item = (JMenuItem) e.getSource();
3.76 -// DatabaseConnection newConnection = (DatabaseConnection) item.getClientProperty(DATABASE_CONNECTION_KEY);
3.77 -// if (connectionSession.updateConnection(newConnection)) {
3.78 -// connectionProvider.setModuleInOracle(connectionSession.getConnection());
3.79 -// saveAndExecute();
3.80 -// }
3.81 -// }
3.82 -// };
3.83 -// private class PopupMenuPopulator implements PropertyChangeListener {
3.84 -//
3.85 -// @Override
3.86 -// public void propertyChange(PropertyChangeEvent event) {
3.87 -// if (popup != null) {
3.88 -// prepareConnection();
3.89 -// populatePopupMenu();
3.90 -// }
3.91 -// }
3.92 -// }
3.93 }
3.94 \ No newline at end of file
4.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlOutputListener.java Mon May 27 14:06:08 2013 +0200
4.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlOutputListener.java Mon May 27 17:47:13 2013 +0200
4.3 @@ -41,9 +41,6 @@
4.4 */
4.5 package org.netbeans.modules.plsql.execution;
4.6
4.7 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
4.8 -import org.netbeans.modules.plsqlsupport.db.DatabaseContentManager;
4.9 -import org.netbeans.modules.plsql.hyperlink.PlsqlGoToDbImplAction;
4.10 import java.io.File;
4.11 import java.util.List;
4.12 import javax.swing.JEditorPane;
4.13 @@ -51,11 +48,13 @@
4.14 import javax.swing.text.BadLocationException;
4.15 import javax.swing.text.Document;
4.16 import org.netbeans.api.project.Project;
4.17 +import org.netbeans.modules.plsql.hyperlink.PlsqlGoToDbImplAction;
4.18 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
4.19 +import org.netbeans.modules.plsqlsupport.db.DatabaseContentManager;
4.20 import org.openide.cookies.EditorCookie;
4.21 import org.openide.cookies.OpenCookie;
4.22 import org.openide.filesystems.FileUtil;
4.23 import org.openide.loaders.*;
4.24 -import org.openide.nodes.Node;
4.25 import org.openide.util.Exceptions;
4.26 import org.openide.util.actions.SystemAction;
4.27 import org.openide.windows.OutputEvent;
4.28 @@ -93,10 +92,10 @@
4.29 File file = new File(originalFileName);
4.30 if (file.exists()) {
4.31 DataObject dObject = DataFolder.find(FileUtil.toFileObject(file));
4.32 - OpenCookie openCookie = dObject.getCookie(OpenCookie.class);
4.33 + OpenCookie openCookie = dObject.getLookup().lookup(OpenCookie.class);
4.34 openCookie.open();
4.35 - Node n = dObject.getNodeDelegate();
4.36 - EditorCookie ec = dObject.getCookie(EditorCookie.class);
4.37 + dObject.getNodeDelegate();
4.38 + EditorCookie ec = dObject.getLookup().lookup(EditorCookie.class);
4.39 if (ec != null) {
4.40 JEditorPane panes[] = ec.getOpenedPanes();
4.41 if (panes.length > 0) {
5.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlRollbackAction.java Mon May 27 14:06:08 2013 +0200
5.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/PlsqlRollbackAction.java Mon May 27 17:47:13 2013 +0200
5.3 @@ -70,11 +70,8 @@
5.4
5.5 private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
5.6 private final DataObject dataObject;
5.7 -// private final DatabaseTransaction transaction;
5.8 private DatabaseConnectionExecutor executor;
5.9 -// private DatabaseConnectionManager connectionProvider;
5.10 private JButton button;
5.11 -// private DatabaseConnection connection;
5.12 private final PropertyChangeListener propertyChangeListener = new EnableRollback();
5.13
5.14 public PlsqlRollbackAction() {
5.15 @@ -122,20 +119,15 @@
5.16 if (dataObject != null) {
5.17 executor = dataObject.getLookup().lookup(DatabaseConnectionExecutor.class);
5.18 }
5.19 -// connection = dataObject.getLookup().lookup(DatabaseConnection.class);
5.20 }
5.21
5.22 @Override
5.23 public void actionPerformed(ActionEvent event) {
5.24
5.25 prepareConnection();
5.26 -// if (connectionProvider == null || connection == null) {
5.27 -// return;
5.28 -// }
5.29
5.30 saveIfModified(dataObject);
5.31 executor.rollbackTransaction();
5.32 -// transaction.rollbackTransaction(connection);
5.33 }
5.34
5.35 @Override
6.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseConnectionExecutorFactory.java Mon May 27 14:06:08 2013 +0200
6.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseConnectionExecutorFactory.java Mon May 27 17:47:13 2013 +0200
6.3 @@ -22,7 +22,7 @@
6.4 @Override
6.5 public DatabaseConnectionExecutor create(DatabaseConnectionManager connectionProvider, DatabaseConnection connection, FileObject fileObject) {
6.6 DatabaseConnectionIO io = new DatabaseConnectionIO();
6.7 - DatabaseTransaction databaseTransaction = DatabaseTransaction.create(io, connection, fileObject);
6.8 + DatabaseTransaction databaseTransaction = DatabaseTransaction.Factory.create(io, connection, fileObject);
6.9 return new PlsqlExecutor(connectionProvider, io, connection, databaseTransaction);
6.10 }
6.11
7.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseConnectionIO.java Mon May 27 14:06:08 2013 +0200
7.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseConnectionIO.java Mon May 27 17:47:13 2013 +0200
7.3 @@ -42,7 +42,6 @@
7.4 } catch (IOException ex) {
7.5 Exceptions.printStackTrace(ex);
7.6 }
7.7 -// return io;
7.8 }
7.9
7.10 /*
7.11 @@ -68,6 +67,6 @@
7.12 }
7.13
7.14 InputOutput getIO() {
7.15 - return io;
7.16 + return io;
7.17 }
7.18 }
8.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseConnectionSession.java Mon May 27 14:06:08 2013 +0200
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,31 +0,0 @@
8.4 -/*
8.5 - * To change this template, choose Tools | Templates
8.6 - * and open the template in the editor.
8.7 - */
8.8 -package org.netbeans.modules.plsql.execution.impl;
8.9 -
8.10 -import org.netbeans.api.db.explorer.DatabaseConnection;
8.11 -import org.openide.windows.InputOutput;
8.12 -
8.13 -/**
8.14 - *
8.15 - * @author chrlse
8.16 - */
8.17 -class DatabaseConnectionSession {
8.18 - private DatabaseConnection connection;
8.19 - private InputOutput io;
8.20 -
8.21 - public DatabaseConnectionSession(DatabaseConnection connection, InputOutput io) {
8.22 - this.connection = connection;
8.23 - this.io = io;
8.24 - }
8.25 -
8.26 - public DatabaseConnection getConnection() {
8.27 - return connection;
8.28 - }
8.29 -
8.30 - public InputOutput getIo() {
8.31 - return io;
8.32 - }
8.33 -
8.34 -}
9.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseTransaction.java Mon May 27 14:06:08 2013 +0200
9.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseTransaction.java Mon May 27 17:47:13 2013 +0200
9.3 @@ -1,228 +1,55 @@
9.4 /*
9.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9.6 - *
9.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
9.8 - *
9.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9.10 - * Other names may be trademarks of their respective owners.
9.11 - *
9.12 - * The contents of this file are subject to the terms of either the GNU
9.13 - * General Public License Version 2 only ("GPL") or the Common
9.14 - * Development and Distribution License("CDDL") (collectively, the
9.15 - * "License"). You may not use this file except in compliance with the
9.16 - * License. You can obtain a copy of the License at
9.17 - * http://www.netbeans.org/cddl-gplv2.html
9.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
9.19 - * specific language governing permissions and limitations under the
9.20 - * License. When distributing the software, include this License Header
9.21 - * Notice in each file and include the License file at
9.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
9.23 - * particular file as subject to the "Classpath" exception as provided
9.24 - * by Oracle in the GPL Version 2 section of the License file that
9.25 - * accompanied this code. If applicable, add the following below the
9.26 - * License Header, with the fields enclosed by brackets [] replaced by
9.27 - * your own identifying information:
9.28 - * "Portions Copyrighted [year] [name of copyright owner]"
9.29 - *
9.30 - * If you wish your version of this file to be governed by only the CDDL
9.31 - * or only the GPL Version 2, indicate your decision by adding
9.32 - * "[Contributor] elects to include this software in this distribution
9.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
9.34 - * single choice of license, a recipient has the option to distribute
9.35 - * your version of this file under either the CDDL, the GPL Version 2 or
9.36 - * to extend the choice of license to its licensees as provided above.
9.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
9.38 - * Version 2 license, then the option applies only if the new code is
9.39 - * made subject to such option by the copyright holder.
9.40 - *
9.41 - * Contributor(s):
9.42 - *
9.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
9.44 + * To change this template, choose Tools | Templates
9.45 + * and open the template in the editor.
9.46 */
9.47 package org.netbeans.modules.plsql.execution.impl;
9.48
9.49 import java.beans.PropertyChangeListener;
9.50 -import java.beans.PropertyChangeSupport;
9.51 -import java.sql.CallableStatement;
9.52 -import java.sql.Connection;
9.53 -import java.sql.SQLException;
9.54 -import java.util.logging.Level;
9.55 -import java.util.logging.Logger;
9.56 import org.netbeans.api.db.explorer.DatabaseConnection;
9.57 -import org.netbeans.api.progress.ProgressHandle;
9.58 -import org.netbeans.api.progress.ProgressHandleFactory;
9.59 import org.openide.filesystems.FileObject;
9.60 -import org.openide.util.Exceptions;
9.61
9.62 /**
9.63 *
9.64 - * @author SubSLK
9.65 - * @author chrlse
9.66 + * @author ChrLSE
9.67 */
9.68 -class DatabaseTransaction {
9.69 +public interface DatabaseTransaction {
9.70
9.71 - private static final Logger LOG = Logger.getLogger(DatabaseTransaction.class.getName());
9.72 - public static final String PROP_TRANSACTION = "TransactionOpen";
9.73 -
9.74 - static DatabaseTransaction create(DatabaseConnectionIO io, DatabaseConnection connection, FileObject fileObject) {
9.75 - if (!fileObject.getExt().equalsIgnoreCase("tdb")) {
9.76 - return null;
9.77 - }
9.78 - return new DatabaseTransaction(io, connection);
9.79 - }
9.80 - private final PropertyChangeSupport changeSupport;
9.81 - private final DatabaseConnectionIO io;
9.82 - private DatabaseConnection connection;
9.83 - private boolean open = false;
9.84 - private String transactionId;
9.85 -
9.86 - DatabaseTransaction(DatabaseConnectionIO io, DatabaseConnection connection) {
9.87 - changeSupport = new PropertyChangeSupport(this);
9.88 - this.io = io;
9.89 - this.connection = connection;
9.90 - }
9.91 -
9.92 - void setConnection(DatabaseConnection connection) {
9.93 - this.connection = connection;
9.94 - close();
9.95 - }
9.96 -
9.97 -// public void open() {
9.98 -// setOpen(true);
9.99 -// }
9.100 -//
9.101 - private void close() {
9.102 - setOpen(false);
9.103 - }
9.104 -
9.105 - private void setOpen(boolean newOpen) {
9.106 - boolean oldOpen = open;
9.107 - open = newOpen;
9.108 - changeSupport.firePropertyChange(PROP_TRANSACTION, oldOpen, open);
9.109 - }
9.110 -
9.111 - public boolean isOpen() {
9.112 - return open;
9.113 - }
9.114 + void addPropertyChangeListener(PropertyChangeListener listener);
9.115
9.116 /**
9.117 *
9.118 *
9.119 */
9.120 - public void commitTransaction() {
9.121 - ProgressHandle handle = ProgressHandleFactory.createHandle("Commit database file...");
9.122 - handle.start();
9.123 -
9.124 - try {
9.125 - if (hasOpenTransaction()) {
9.126 - commitRollbackTransactions(true);
9.127 - }
9.128 - close();
9.129 - io.println((new StringBuilder()).append("> Commit of Transaction ID = [")
9.130 - .append(transactionId).append("] successful"));
9.131 - } catch (Exception ex) {
9.132 - io.println((new StringBuilder()).append(">!!! Error Commit Statement"));
9.133 - Exceptions.printStackTrace(ex);
9.134 - } finally {
9.135 - handle.finish();
9.136 - }
9.137 - }
9.138 + void commitTransaction();
9.139
9.140 /**
9.141 *
9.142 *
9.143 + * @return True if there are on going transaction for a connection.
9.144 */
9.145 - public void rollbackTransaction() {
9.146 - ProgressHandle handle = ProgressHandleFactory.createHandle("Rollback database file...");
9.147 - handle.start();
9.148 -
9.149 - try {
9.150 - if (hasOpenTransaction()) {
9.151 - commitRollbackTransactions(false);
9.152 - }
9.153 - close();
9.154 - io.println((new StringBuilder()).append("> Rollback of Transaction ID = [")
9.155 - .append(transactionId).append("] successful"));
9.156 -
9.157 - } catch (Exception ex) {
9.158 - io.println((new StringBuilder()).append(">!!! Error Rollback Statement"));
9.159 - Exceptions.printStackTrace(ex);
9.160 - } finally {
9.161 - handle.finish();
9.162 - }
9.163 - }
9.164 -
9.165 - public void addPropertyChangeListener(PropertyChangeListener listener) {
9.166 - PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
9.167 - for (int i = 0; i < listeners.length; i++) {
9.168 - if (listeners[i] == listener) {
9.169 - return;
9.170 - }
9.171 - }
9.172 - changeSupport.addPropertyChangeListener(listener);
9.173 - }
9.174 -
9.175 - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
9.176 - PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
9.177 - for (int i = 0; i < listeners.length; i++) {
9.178 - if (listeners[i] == listener) {
9.179 - return;
9.180 - }
9.181 - }
9.182 - changeSupport.addPropertyChangeListener(propertyName, listener);
9.183 - }
9.184 + boolean hasOpenTransaction();
9.185
9.186 /**
9.187 *
9.188 *
9.189 - * @return True if there in on going transactions for a command window.
9.190 */
9.191 - public boolean hasOpenTransaction() {
9.192 - boolean isOpen = false;
9.193 - if (connection.getJDBCConnection() == null) {
9.194 - setOpen(isOpen);
9.195 - return isOpen;
9.196 - }
9.197 -
9.198 - try {
9.199 - String sqlProc = "{call ? := DBMS_TRANSACTION.local_transaction_id}";
9.200 - CallableStatement stmt = connection.getJDBCConnection().prepareCall(sqlProc);
9.201 - stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
9.202 - stmt.executeUpdate();
9.203 - transactionId = stmt.getString(1);
9.204 -// io.getOut().println(("transactionId=" + transactionId));
9.205 - if (transactionId != null) {
9.206 - io.println(("Transaction open with ID = [" + transactionId + "]"));
9.207 - isOpen = true;
9.208 - } else {
9.209 - isOpen = false;
9.210 - }
9.211 - } catch (SQLException ex) {
9.212 - LOG.log(Level.WARNING, "", ex);
9.213 - isOpen = false;
9.214 - }
9.215 - setOpen(isOpen);
9.216 - return isOpen;
9.217 - }
9.218 + void rollbackTransaction();
9.219
9.220 /**
9.221 *
9.222 - * @param commit the value of commit
9.223 + * @return true if auto commit is enabled.
9.224 */
9.225 - private void commitRollbackTransactions(boolean commit) {
9.226 - try {
9.227 - if (connection.getJDBCConnection() == null) {
9.228 - return;
9.229 + boolean autoCommit();
9.230 +
9.231 + public void setConnection(DatabaseConnection connection);
9.232 +
9.233 + static class Factory {
9.234 +
9.235 + static DatabaseTransaction create(DatabaseConnectionIO io, DatabaseConnection connection, FileObject fileObject) {
9.236 + if (!fileObject.getExt().equalsIgnoreCase("tdb")) {
9.237 + return new DatabaseTransactionAutoCommit();
9.238 }
9.239 - Connection con = connection.getJDBCConnection();
9.240 -
9.241 - if (commit) {
9.242 - con.commit();
9.243 - } else {
9.244 - con.rollback();
9.245 - }
9.246 - } catch (SQLException ex) {
9.247 - Exceptions.printStackTrace(ex);
9.248 + return new DatabaseTransactionDefault(io, connection);
9.249 }
9.250 }
9.251 }
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseTransactionAutoCommit.java Mon May 27 17:47:13 2013 +0200
10.3 @@ -0,0 +1,42 @@
10.4 +/*
10.5 + * To change this template, choose Tools | Templates
10.6 + * and open the template in the editor.
10.7 + */
10.8 +package org.netbeans.modules.plsql.execution.impl;
10.9 +
10.10 +import java.beans.PropertyChangeListener;
10.11 +import org.netbeans.api.db.explorer.DatabaseConnection;
10.12 +
10.13 +/**
10.14 + * Implementation that always has auto commit enabled.
10.15 + *
10.16 + * @author ChrLSE
10.17 + */
10.18 +class DatabaseTransactionAutoCommit implements DatabaseTransaction {
10.19 +
10.20 + @Override
10.21 + public void addPropertyChangeListener(PropertyChangeListener listener) {
10.22 + }
10.23 +
10.24 + @Override
10.25 + public void commitTransaction() {
10.26 + }
10.27 +
10.28 + @Override
10.29 + public boolean hasOpenTransaction() {
10.30 + return false;
10.31 + }
10.32 +
10.33 + @Override
10.34 + public void rollbackTransaction() {
10.35 + }
10.36 +
10.37 + @Override
10.38 + public boolean autoCommit() {
10.39 + return true;
10.40 + }
10.41 +
10.42 + @Override
10.43 + public void setConnection(DatabaseConnection connection) {
10.44 + }
10.45 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/DatabaseTransactionDefault.java Mon May 27 17:47:13 2013 +0200
11.3 @@ -0,0 +1,226 @@
11.4 +/*
11.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
11.6 + *
11.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
11.8 + *
11.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
11.10 + * Other names may be trademarks of their respective owners.
11.11 + *
11.12 + * The contents of this file are subject to the terms of either the GNU
11.13 + * General Public License Version 2 only ("GPL") or the Common
11.14 + * Development and Distribution License("CDDL") (collectively, the
11.15 + * "License"). You may not use this file except in compliance with the
11.16 + * License. You can obtain a copy of the License at
11.17 + * http://www.netbeans.org/cddl-gplv2.html
11.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11.19 + * specific language governing permissions and limitations under the
11.20 + * License. When distributing the software, include this License Header
11.21 + * Notice in each file and include the License file at
11.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
11.23 + * particular file as subject to the "Classpath" exception as provided
11.24 + * by Oracle in the GPL Version 2 section of the License file that
11.25 + * accompanied this code. If applicable, add the following below the
11.26 + * License Header, with the fields enclosed by brackets [] replaced by
11.27 + * your own identifying information:
11.28 + * "Portions Copyrighted [year] [name of copyright owner]"
11.29 + *
11.30 + * If you wish your version of this file to be governed by only the CDDL
11.31 + * or only the GPL Version 2, indicate your decision by adding
11.32 + * "[Contributor] elects to include this software in this distribution
11.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
11.34 + * single choice of license, a recipient has the option to distribute
11.35 + * your version of this file under either the CDDL, the GPL Version 2 or
11.36 + * to extend the choice of license to its licensees as provided above.
11.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
11.38 + * Version 2 license, then the option applies only if the new code is
11.39 + * made subject to such option by the copyright holder.
11.40 + *
11.41 + * Contributor(s):
11.42 + *
11.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
11.44 + */
11.45 +package org.netbeans.modules.plsql.execution.impl;
11.46 +
11.47 +import java.beans.PropertyChangeListener;
11.48 +import java.beans.PropertyChangeSupport;
11.49 +import java.sql.CallableStatement;
11.50 +import java.sql.Connection;
11.51 +import java.sql.SQLException;
11.52 +import java.util.logging.Level;
11.53 +import java.util.logging.Logger;
11.54 +import org.netbeans.api.db.explorer.DatabaseConnection;
11.55 +import org.netbeans.api.progress.ProgressHandle;
11.56 +import org.netbeans.api.progress.ProgressHandleFactory;
11.57 +import org.netbeans.modules.plsqlsupport.options.OptionsUtilities;
11.58 +import org.openide.util.Exceptions;
11.59 +
11.60 +/**
11.61 + *
11.62 + * @author SubSLK
11.63 + * @author chrlse
11.64 + */
11.65 +class DatabaseTransactionDefault implements DatabaseTransaction {
11.66 +
11.67 + private static final Logger LOG = Logger.getLogger(DatabaseTransactionDefault.class.getName());
11.68 + static final String PROP_TRANSACTION = "TransactionOpen";
11.69 + private final PropertyChangeSupport changeSupport;
11.70 + private final DatabaseConnectionIO io;
11.71 + private DatabaseConnection connection;
11.72 + private boolean open = false;
11.73 + private String transactionId;
11.74 +
11.75 + DatabaseTransactionDefault(DatabaseConnectionIO io, DatabaseConnection connection) {
11.76 + changeSupport = new PropertyChangeSupport(this);
11.77 + this.io = io;
11.78 + this.connection = connection;
11.79 + }
11.80 +
11.81 + @Override
11.82 + public void setConnection(DatabaseConnection connection) {
11.83 + this.connection = connection;
11.84 + close();
11.85 + }
11.86 +
11.87 + private void close() {
11.88 + setOpen(false);
11.89 + }
11.90 +
11.91 + private void setOpen(boolean newOpen) {
11.92 + boolean oldOpen = open;
11.93 + open = newOpen;
11.94 + changeSupport.firePropertyChange(PROP_TRANSACTION, oldOpen, open);
11.95 + }
11.96 +
11.97 + public boolean isOpen() {
11.98 + return open;
11.99 + }
11.100 +
11.101 + /**
11.102 + *
11.103 + *
11.104 + */
11.105 + @Override
11.106 + public void commitTransaction() {
11.107 + ProgressHandle handle = ProgressHandleFactory.createHandle("Commit database file...");
11.108 + handle.start();
11.109 +
11.110 + try {
11.111 + if (hasOpenTransaction()) {
11.112 + commitRollbackTransactions(true);
11.113 + }
11.114 + close();
11.115 + io.println((new StringBuilder()).append("> Commit of Transaction ID = [")
11.116 + .append(transactionId).append("] successful"));
11.117 + } catch (Exception ex) {
11.118 + io.println((new StringBuilder()).append(">!!! Error Commit Statement"));
11.119 + Exceptions.printStackTrace(ex);
11.120 + } finally {
11.121 + handle.finish();
11.122 + }
11.123 + }
11.124 +
11.125 + /**
11.126 + *
11.127 + *
11.128 + */
11.129 + @Override
11.130 + public void rollbackTransaction() {
11.131 + ProgressHandle handle = ProgressHandleFactory.createHandle("Rollback database file...");
11.132 + handle.start();
11.133 +
11.134 + try {
11.135 + if (hasOpenTransaction()) {
11.136 + commitRollbackTransactions(false);
11.137 + }
11.138 + close();
11.139 + io.println((new StringBuilder()).append("> Rollback of Transaction ID = [")
11.140 + .append(transactionId).append("] successful"));
11.141 +
11.142 + } catch (Exception ex) {
11.143 + io.println((new StringBuilder()).append(">!!! Error Rollback Statement"));
11.144 + Exceptions.printStackTrace(ex);
11.145 + } finally {
11.146 + handle.finish();
11.147 + }
11.148 + }
11.149 +
11.150 + @Override
11.151 + public void addPropertyChangeListener(PropertyChangeListener listener) {
11.152 + PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
11.153 + for (int i = 0; i < listeners.length; i++) {
11.154 + if (listeners[i] == listener) {
11.155 + return;
11.156 + }
11.157 + }
11.158 + changeSupport.addPropertyChangeListener(listener);
11.159 + }
11.160 +
11.161 + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
11.162 + PropertyChangeListener[] listeners = changeSupport.getPropertyChangeListeners();
11.163 + for (int i = 0; i < listeners.length; i++) {
11.164 + if (listeners[i] == listener) {
11.165 + return;
11.166 + }
11.167 + }
11.168 + changeSupport.addPropertyChangeListener(propertyName, listener);
11.169 + }
11.170 +
11.171 + /**
11.172 + *
11.173 + *
11.174 + * @return True if there in on going transactions for a command window.
11.175 + */
11.176 + @Override
11.177 + public boolean hasOpenTransaction() {
11.178 + boolean isOpen = false;
11.179 + if (connection.getJDBCConnection() == null) {
11.180 + setOpen(isOpen);
11.181 + return isOpen;
11.182 + }
11.183 +
11.184 + try {
11.185 + String sqlProc = "{call ? := DBMS_TRANSACTION.local_transaction_id}";
11.186 + CallableStatement stmt = connection.getJDBCConnection().prepareCall(sqlProc);
11.187 + stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
11.188 + stmt.executeUpdate();
11.189 + transactionId = stmt.getString(1);
11.190 + if (transactionId != null) {
11.191 + io.println(("Transaction open with ID = [" + transactionId + "]"));
11.192 + isOpen = true;
11.193 + } else {
11.194 + isOpen = false;
11.195 + }
11.196 + } catch (SQLException ex) {
11.197 + LOG.log(Level.WARNING, "", ex);
11.198 + isOpen = false;
11.199 + }
11.200 + setOpen(isOpen);
11.201 + return isOpen;
11.202 + }
11.203 +
11.204 + /**
11.205 + *
11.206 + * @param commit the value of commit
11.207 + */
11.208 + private void commitRollbackTransactions(boolean commit) {
11.209 + try {
11.210 + if (connection.getJDBCConnection() == null) {
11.211 + return;
11.212 + }
11.213 + Connection con = connection.getJDBCConnection();
11.214 +
11.215 + if (commit) {
11.216 + con.commit();
11.217 + } else {
11.218 + con.rollback();
11.219 + }
11.220 + } catch (SQLException ex) {
11.221 + Exceptions.printStackTrace(ex);
11.222 + }
11.223 + }
11.224 +
11.225 + @Override
11.226 + public boolean autoCommit() {
11.227 + return OptionsUtilities.isCommandWindowAutoCommitEnabled();
11.228 + }
11.229 +}
12.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/PlsqlExecutor.java Mon May 27 14:06:08 2013 +0200
12.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/PlsqlExecutor.java Mon May 27 17:47:13 2013 +0200
12.3 @@ -23,6 +23,8 @@
12.4 import org.openide.util.Cancellable;
12.5 import org.openide.util.Lookup;
12.6 import org.openide.util.RequestProcessor;
12.7 +import org.openide.util.Task;
12.8 +import org.openide.util.TaskListener;
12.9
12.10 /**
12.11 * reference usage holder
12.12 @@ -36,9 +38,8 @@
12.13 private static final RequestProcessor RP = new RequestProcessor(PlsqlExecutor.class.getName(), 4, true);
12.14 private final DatabaseConnectionManager connectionProvider;
12.15 private final DatabaseConnectionIO io;
12.16 + private final DatabaseTransaction transaction;
12.17 private DatabaseConnection connection;
12.18 - // is set to null if run from other than tdb (command window).
12.19 - private DatabaseTransaction transaction;
12.20
12.21 // private final boolean isCommandWindow;
12.22 public PlsqlExecutor(DatabaseConnectionManager connectionProvider, DatabaseConnectionIO io, DatabaseConnection connection, DatabaseTransaction transaction) {
12.23 @@ -143,50 +144,20 @@
12.24
12.25 @Override
12.26 public void execute(List<PlsqlExecutableObject> executableObjects, Document document) {
12.27 - ProgressHandle handle = ProgressHandleFactory.createHandle("Executing database file...", new Cancellable() {
12.28 + final ProgressHandle handle = ProgressHandleFactory.createHandle("Executing database file...", new Cancellable() {
12.29 @Override
12.30 public boolean cancel() {
12.31 return handleCancel();
12.32 }
12.33 });
12.34 -// try {
12.35 -// handle.start();
12.36 -// // If autocommit OFF - take the connection from data object.
12.37 -// if (autoCommit()) {
12.38 -// if (!updateConnection(connectionProvider.getTemplateConnection())) {
12.39 -// return;
12.40 -// }
12.41 -// }
12.42 -//
12.43 -// if (connection == connectionProvider.getTemplateConnection()) {
12.44 -// updateConnection(connectionProvider.getPooledDatabaseConnection(false, true));
12.45 -// if (connection == null) {
12.46 -// return;
12.47 -// }
12.48 -// }
12.49 -// reconnectIfNeeded();
12.50 -//// final DataObject obj = FileExecutionUtil.getDataObject(document);
12.51 -//// FileObject file = obj.getPrimaryFile();
12.52 -//// if (file == null) {
12.53 -//// return;
12.54 -//// }
12.55 -// DataObject dataObj = FileExecutionUtil.getDataObject(document);
12.56 -// String fileName = dataObj.getPrimaryFile().getNameExt();
12.57 -// InputOutput io = initializeIO(fileName, dataObj.getNodeDelegate().getDisplayName(), dataObj, executableObjects.get(0));
12.58 -
12.59 - task = RP.post(new ExecutionTask(connection, executableObjects, document, handle));
12.60 -// task.waitFinished();
12.61 -// executor.executePLSQL(blocks, document);
12.62 -
12.63 -// } finally {
12.64 -// if (autoCommit()) {
12.65 -// connectionProvider.releaseDatabaseConnection(connection);
12.66 -// } else {
12.67 -// hasOpenTransaction();
12.68 -// }
12.69 -// handle.finish();
12.70 -// }
12.71 -// task = RP.post(new ExecutionTask(connectionProvider, connection, executableObjects, document));
12.72 + task = RP.create(new ExecutionTask(connection, executableObjects, document, handle));
12.73 + task.addTaskListener(new TaskListener() {
12.74 + @Override
12.75 + public void taskFinished(Task task) {
12.76 + handle.finish();
12.77 + }
12.78 + });
12.79 + task.schedule(0); //start the task
12.80 }
12.81 private RequestProcessor.Task task;
12.82
12.83 @@ -200,7 +171,7 @@
12.84 }
12.85
12.86 private boolean autoCommit() {
12.87 - return transaction == null || OptionsUtilities.isCommandWindowAutoCommitEnabled();
12.88 + return transaction.autoCommit();
12.89 }
12.90
12.91 private class ExecutionTask implements Runnable {
12.92 @@ -246,8 +217,11 @@
12.93 // return;
12.94 // }
12.95 reconnectIfNeeded();
12.96 - executor = new PlsqlFileExecutor(connectionProvider, connection, executableObjects, document, io.getIO());
12.97 - executor.run();
12.98 + executor = new PlsqlFileExecutor(connectionProvider, connection, io.getIO());
12.99 + executor.executePLSQL(executableObjects, document);
12.100 + } catch (InterruptedException ex) {
12.101 + LOG.info("the task was CANCELLED");
12.102 +// return;
12.103
12.104 } finally {
12.105 if (autoCommit()) {
13.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/PlsqlFileExecutor.java Mon May 27 14:06:08 2013 +0200
13.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/impl/PlsqlFileExecutor.java Mon May 27 17:47:13 2013 +0200
13.3 @@ -99,7 +99,7 @@
13.4 import org.openide.windows.OutputWriter;
13.5 import org.openide.windows.TopComponent;
13.6
13.7 -public class PlsqlFileExecutor implements Runnable {
13.8 +public class PlsqlFileExecutor {
13.9
13.10 // private static final RequestProcessor RP = new RequestProcessor("SQLExecution", 4, true);
13.11 private static final PlsqlFileValidatorService validator = Lookup.getDefault().lookup(PlsqlFileValidatorService.class);
13.12 @@ -108,19 +108,19 @@
13.13 private final DatabaseConnectionManager connectionProvider;
13.14 private final DatabaseConnection connection;
13.15 private final Connection jdbcConnection;
13.16 - private final List<PlsqlExecutableObject> executableObjs;
13.17 - private final Document doc;
13.18 +// private final List<PlsqlExecutableObject> executableObjs;
13.19 +// private final Document doc;
13.20 private PlsqlEditor plsqlEditor;
13.21 private final InputOutput io;
13.22 private final DatabaseContentManager cache;
13.23 private final String connectionDisplayName;
13.24
13.25 - PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, DatabaseConnection connection, List<PlsqlExecutableObject> executableObjects, Document document, InputOutput io) {
13.26 + PlsqlFileExecutor(DatabaseConnectionManager connectionProvider, DatabaseConnection connection, InputOutput io) {
13.27 this.connectionDisplayName = "Using DB: " + connection.getDisplayName() + " [" + connection.getName() + "]";
13.28 this.connection = connection;
13.29 this.jdbcConnection = connection.getJDBCConnection();
13.30 - this.executableObjs = executableObjects;
13.31 - this.doc = document;
13.32 +// this.executableObjs = executableObjects;
13.33 +// this.doc = document;
13.34 this.io = io;
13.35 this.connectionProvider = connectionProvider;
13.36 this.cache = DatabaseContentManager.getInstance(connection);
13.37 @@ -355,12 +355,7 @@
13.38
13.39 }
13.40
13.41 - @Override
13.42 - public void run() {
13.43 - executePLSQL(executableObjs, doc);
13.44 - }
13.45 -
13.46 - public void executePLSQL(List<PlsqlExecutableObject> executableObjs, Document doc) {
13.47 + public void executePLSQL(List<PlsqlExecutableObject> executableObjs, Document doc) throws InterruptedException {
13.48 Project project = null;
13.49
13.50 Object object = doc.getProperty(Document.StreamDescriptionProperty);
13.51 @@ -465,10 +460,11 @@
13.52 boolean firstSelectStatement = true;
13.53
13.54 for (PlsqlExecutableObject exeObj : executableObjs) {
13.55 -// if (cancel) {
13.56 -// io.getErr().println("!!!Execution cancelled. Performing rollback");
13.57 -// jdbcConnection.rollback();
13.58 -// return io;
13.59 + Thread.sleep(0); //throws InterruptedException is the task was cancelled
13.60 + // if (cancel) {
13.61 + // io.getErr().println("!!!Execution cancelled. Performing rollback");
13.62 + // jdbcConnection.rollback();
13.63 + // return io;
13.64 // }
13.65 int lineNumber = exeObj.getStartLineNo();
13.66 String plsqlText = exeObj.getPlsqlString();
13.67 @@ -1323,7 +1319,7 @@
13.68 return null;
13.69 }
13.70
13.71 - private void executeSqlPlusStart(String plsqlText, String firstWord, Document doc, InputOutput io) {
13.72 + private void executeSqlPlusStart(String plsqlText, String firstWord, Document doc, InputOutput io) throws InterruptedException {
13.73 try {
13.74 String fileName = null;
13.75 if (firstWord.equalsIgnoreCase("START")) {
14.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionExecutor.java Mon May 27 14:06:08 2013 +0200
14.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionExecutor.java Mon May 27 17:47:13 2013 +0200
14.3 @@ -1,7 +1,3 @@
14.4 -/*
14.5 - * To change this template, choose Tools | Templates
14.6 - * and open the template in the editor.
14.7 - */
14.8 package org.netbeans.modules.plsqlsupport.db;
14.9
14.10 import java.beans.PropertyChangeListener;