// execute and get results private void execute(Connection conn, String text, Writer writer, boolean commaSeparator) throws SQLException { BufferedWriter buffer = new BufferedWriter(writer); Statement stmt = conn.createStatement(); stmt.execute(text); ResultSet rs = stmt.getResultSet(); ResultSetMetaData metadata = rs.getMetaData(); int nbCols = metadata.getColumnCount(); String[] labels = new String[nbCols]; int[] colwidths = new int[nbCols]; int[] colpos = new int[nbCols]; int linewidth = 1; // read each occurrence try { while (rs.next()) { for (int i = 0; i < nbCols; i++) { Object value = rs.getObject(i + 1); if (value != null) { buffer.write(value.toString()); if (commaSeparator) buffer.write(","); } } } buffer.flush(); rs.close(); } catch (IOException ex) { if (Debug.isDebug()) ex.printStackTrace(); // ok, exit from the loop } catch (SQLException ex) { if (Debug.isDebug()) ex.printStackTrace(); } }
// dump warnings too public void warning(SAXParseException err) throws SAXParseException { Debug.trace( "** Warning" // NOT LOCALIZABLE + ", line " + err.getLineNumber() // NOT LOCALIZABLE + ", uri " + err.getSystemId()); // NOT LOCALIZABLE Debug.trace(" " + err.getMessage()); }
// get drivername, user, pw & server, and return connection id public void serve(InputStream i, OutputStream o) throws IOException { // TODOServiceList.getSingleInstance(); initialize(); NameListMessage nameListMessage = null; try { // read input to know which target panel is required ObjectInputStream input = new ObjectInputStream(i); nameListMessage = (NameListMessage) input.readObject(); // parse the required panel parseSqlFile(nameListMessage); } catch (ClassNotFoundException ex) { if (Debug.isDebug()) ex.printStackTrace(); nameListMessage.errorMessage = ex.toString(); } // send object to the caller ObjectOutputStream output = new ObjectOutputStream(o); output.writeObject(nameListMessage); // end socket connection o.close(); i.close(); }
public void initialize() { try { PipedWriter src = new PipedWriter(); reader = new PipedReader(src); writer = new PrintWriter(src); } catch (IOException ex) { if (Debug.isDebug()) ex.printStackTrace(); } }
public boolean expand(Writer output, Serializable object, RuleOptions options) throws IOException, RuleException { boolean expanded = false; boolean prefixPrinted = false; boolean atLeastOneChildPrinted = false; if (object == null) { if (Debug.isDebug()) { throw new NullPointerException(); // disclose programming error // in debug.. } else { return false; } } // end if if (!(object instanceof DbObject)) { return false; } // end if DbObject dbObject = (DbObject) object; MetaRelationship metaRelation = getMetaRelation(dbObject); MetaClass childrenMetaClass = getChildrenMetaClass(); try { // get metaRelation from its string representation if (metaRelation == null) metaRelation = (MetaRelationship) getMetaField(dbObject, sConnector); boolean state[] = {prefixPrinted, atLeastOneChildPrinted}; if (metaRelation instanceof MetaRelation1) { MetaRelation1 metaRelation1 = (MetaRelation1) metaRelation; expanded |= expandMetaRelation1(output, dbObject, metaRelation1, state, childrenMetaClass, options); } else if (metaRelation instanceof MetaRelationN) { expanded |= expandMetaRelationN(output, dbObject, metaRelation, state, childrenMetaClass, options); } else if (metaRelation instanceof MetaChoice) { MetaChoice choice = (MetaChoice) metaRelation; expanded |= expandMetaChoice(output, dbObject, choice, state, childrenMetaClass, options); } else { // TODO: throw 'meta-relationship not supported' } super.terminate(output, options); } catch (DbException ex) { String msg = ex.getMessage(); throw new RuleException(msg); } catch (RuntimeException ex) { String conn = m_connector.getGUIName(); String objectKind = dbObject.getMetaClass().getGUIName(); String msg = InvalidConnectorRuleException.buildMessage(m_ruleName, conn, objectKind); throw new InvalidConnectorRuleException(msg); } return expanded; }
public static void main(String[] args) throws IOException { String filename = "z.xml"; // NOT LOCALIZABLE, main try { String uri = "file:" + new File(filename).getAbsolutePath(); // NOT LOCALIZABLE, main // // turn it into an in-memory object. // Parser parser = getParser(); parser.setDocumentHandler(new XmlParser()); parser.setErrorHandler(new MyErrorHandler()); parser.parse(uri); } catch (SAXParseException err) { Debug.trace( "** Parsing error" // NOT LOCALIZABLE, main + ", line " + err.getLineNumber() // NOT LOCALIZABLE + ", uri " + err.getSystemId()); // NOT LOCALIZABLE Debug.trace(" " + err.getMessage()); } catch (SAXException e) { Exception x = e; if (e.getException() != null) x = e.getException(); x.printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } byte[] buf = new byte[256]; Debug.trace("Press ENTER to exit."); // NOT LOCALIZABLE System.in.read(buf, 0, 256); System.exit(0); }
private void parseSqlFile(NameListMessage nameListMessage) { BufferedWriter buffer = null; ArrayList cmds = new ArrayList(); try { URL url = new URL(nameListMessage.filename.toExternalForm()); InputStreamReader inputStreamReader = new InputStreamReader(url.openStream()); // InputStream inputStream = new // FileInputStream(nameListMessage.filename); //reporté à 2.6 // InputStreamReader inputStreamReader = new // InputStreamReader(inputStream); //reporté à 2.6 BufferedReader bugReader = new BufferedReader(inputStreamReader); SQLLexerStream stream = new SQLLexerStream(bugReader); // execute each SQL statement boolean done = false; int i = 0; while (!done) { int tokenID = stream.nextToken(); // only print statement tokens switch (tokenID) { case SQLLexerStream.TT_STATEMENT: i++; String text = stream.sval; if (text != null) { cmds.add(text); } break; case SQLLexerStream.TT_EOF: done = true; break; default: break; } // end switch } // end while } catch (Exception ex) { if (Debug.isDebug()) ex.printStackTrace(); nameListMessage.errorMessage = ex.toString(); } executeParsedFile(nameListMessage, cmds); } // end parseSqlFile()
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()
protected PropertyChangeListener createActionPropertyChangeListener(Action a) { // should be evorrided -- if needed, we can provide one org.modelsphere.jack.debug.Debug.assert2( false, "JackComboBox: createActionPropertyChangeListener -- should not be in this method"); return null; }