public void close() throws SQLException { pool.returnConnection(this); }
private void executeParsedFile(NameListMessage nameListMessage, ArrayList cmds) { BufferedWriter buffer = null; int connectionId = nameListMessage.connectionId; boolean commaSeparated = nameListMessage.commaSeparated; // get java.sql.Connection from connectionId Connection connection = ConnectionService.getConnection(connectionId); if (connection == null) { nameListMessage.errorMessage = kConnectionClosed; } else { try { Thread th = null; buffer = new BufferedWriter(writer); // if reader exists, create reading thread if (reader != null) { final ObjectNameReader objectReader = new ObjectNameReader(nameListMessage.nameList); // This thread will read stream until meets EOL (ie. when // writer is closed) th = new Thread() { public void run() { objectReader.readInputFile(reader); } }; } // end if // if no reader (offline reverse), never start the reading // thread // (because output is written down directly to the disk without // processing in counterpart). if (reader != null) th.start(); // execute each SQL statement // we skip objects that don't need to be reversed Iterator iter = cmds.iterator(); int index = -1; while (iter.hasNext()) { String cmd = (String) iter.next(); index++; // check if this statement id is marked as <to skip> if (nameListMessage.ignoredStatementIds != null && nameListMessage.ignoredStatementIds.contains(new Integer(index))) { if (commaSeparated) { buffer.flush(); buffer.newLine(); } continue; } if (writer != null) { if (cmd != null) { try { execute(connection, cmd, buffer, commaSeparated); } catch (SQLException e) { if (Debug.isDebug()) e.printStackTrace(); nameListMessage.errorMessage = nameListMessage.errorMessage == null ? e.toString() : nameListMessage.errorMessage.concat("\n" + e.toString()); // NOT // LOCALIZABLE, // escape // code } } if (commaSeparated) { buffer.flush(); buffer.newLine(); } } } } /* * catch (SQLException ex) { if (Debug.isDebug()) ex.printStackTrace(); * nameListMessage.errorMessage = nameListMessage.errorMessage == null ? ex.toString() : * nameListMessage.errorMessage.concat("\n" + ex.toString()); //NOT LOCALIZABLE, escape * code } */ catch (IOException ex) { if (Debug.isDebug()) ex.printStackTrace(); nameListMessage.errorMessage = nameListMessage.errorMessage == null ? ex.toString() : nameListMessage.errorMessage.concat( "\n" + ex.toString()); // NOT LOCALIZABLE, escape // code } // close writer: the reading thread terminates. try { // WARNING: we must make a pause after closing the buffer // otherwise // the nameList variable won't be well initialized...strange! // [FG] buffer.close(); Thread.sleep(400); } catch (IOException ex) { } catch (InterruptedException ex) { } } // end if } // end parseSqlFile()