1 19 20 package org.netbeans.lib.ddl.util; 21 22 import java.util.*; 23 24 import org.openide.*; 25 26 import org.netbeans.lib.ddl.*; 27 28 44 public class CommandBuffer 45 { 46 47 Vector commands; 48 49 50 CommandBufferExceptionHandler handler; 51 52 53 boolean debugmode; 54 55 56 boolean executionWithException; 57 58 61 public void add(DDLCommand cmd) 62 { 63 if (commands == null) commands = new Vector(); 64 commands.add(cmd); 65 } 66 67 71 public void setExceptionHandler(CommandBufferExceptionHandler hand) 72 { 73 handler = hand; 74 } 75 76 80 public boolean isDebugMode() 81 { 82 return debugmode; 83 } 84 85 90 public void setDebugMode(boolean flag) 91 { 92 debugmode = flag; 93 } 94 95 97 public String getCommands() 98 throws DDLException 99 { 100 String cmds = ""; 101 Enumeration cmd_e = commands.elements(); 102 while (cmd_e.hasMoreElements()) { 103 DDLCommand e_cmd = (DDLCommand)cmd_e.nextElement(); 104 cmds = cmds + e_cmd.getCommand() + "\n"; 105 } 106 107 return cmds; 108 } 109 110 119 public void execute() 120 throws DDLException 121 { 122 boolean opencon = false; 123 executionWithException = false; 124 DatabaseSpecification spec = null; 125 Enumeration cmd_e = commands.elements(); 126 while (cmd_e.hasMoreElements()) { 127 DDLCommand e_cmd = (DDLCommand)cmd_e.nextElement(); 128 try { 129 if (spec == null) { 130 spec = e_cmd.getSpecification(); 131 if (spec.getJDBCConnection() == null) { 132 opencon = true; 133 spec.openJDBCConnection(); 134 } 135 } 136 if (debugmode) System.out.println(e_cmd); 137 e_cmd.execute(); 138 executionWithException = e_cmd.wasException(); 139 } catch (Exception e) { 140 executionWithException = true; 142 boolean exres = false; 143 if (handler != null) 144 exres = handler.shouldContinueAfterException(e); 145 if (!exres) 146 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE)); 147 } 148 } 149 150 if (opencon) spec.closeJDBCConnection(); 151 } 152 153 154 public boolean wasException() { 155 return executionWithException; 156 } 157 } 158 | Popular Tags |