1 33 package com.internetcds.jdbc.tds; 34 35 96 public class CancelController 97 { 98 public static final String cvsVersion = "$Id: CancelController.java,v 1.1 2006/06/23 10:39:04 sinisa Exp $"; 99 100 101 boolean awaitingData = false; 102 int cancelsRequested = 0; 103 int cancelsProcessed = 0; 104 105 public synchronized void setQueryInProgressFlag() 106 { 107 awaitingData = true; 108 } 109 110 private synchronized void clearQueryInProgressFlag() 111 { 112 awaitingData = false; 113 } 114 115 public synchronized void finishQuery( 116 boolean wasCanceled, 117 boolean moreResults) 118 { 119 if (! moreResults) 132 { 133 clearQueryInProgressFlag(); 134 } 135 136 if (wasCanceled) 137 { 138 handleCancelAck(); 139 } 140 141 } 144 145 146 public synchronized void doCancel(TdsComm comm) 147 throws java.io.IOException 148 { 149 if (awaitingData) 150 { 151 comm.startPacket(TdsComm.CANCEL); 152 comm.sendPacket(); 153 cancelsRequested++; 154 155 156 while(cancelsRequested > cancelsProcessed) 157 { 158 try 159 { 160 wait(); 161 } 165 catch(java.lang.InterruptedException e) 166 { 167 } 169 } 170 } 171 else 172 { 173 176 } 178 } 179 180 181 182 private synchronized void handleCancelAck() 183 { 184 cancelsProcessed++; 185 notify(); 186 } 187 } 188 | Popular Tags |