public static Reader getAsciiReader(InputStream x) throws SQLException { try { return x == null ? null : new InputStreamReader(x, "US-ASCII"); } catch (UnsupportedEncodingException e) { throw Message.convert(e); } }
public static byte[] utf8Encode(String s) throws SQLException { try { // TODO UTF8: String.getBytes("UTF-8") only returns 1 byte for // 0xd800-0xdfff return s.getBytes(Constants.UTF8); } catch (UnsupportedEncodingException e) { throw Message.convert(e); } }
public static Reader getReader(InputStream in) throws SQLException { try { // InputStreamReader may read some more bytes return in == null ? null : new BufferedReader(new InputStreamReader(in, Constants.UTF8)); } catch (UnsupportedEncodingException e) { throw Message.convert(e); } }
public ReaderInputStream(Reader reader) throws SQLException { chars = new char[Constants.IO_BUFFER_SIZE]; this.reader = reader; out = new ByteArrayOutputStream(Constants.IO_BUFFER_SIZE); try { writer = new BufferedWriter(new OutputStreamWriter(out, Constants.UTF8)); } catch (UnsupportedEncodingException e) { throw Message.convert(e); } }
private Server(Service service, String[] args) throws SQLException { this.service = service; try { service.init(args); } catch (Exception e) { throw Message.convert(e); } }
public AggregateFunction getInstance() throws SQLException { if (javaClass == null) { javaClass = database.loadUserClass(className); } Object obj; try { obj = javaClass.newInstance(); AggregateFunction agg = (AggregateFunction) obj; return agg; } catch (Exception e) { throw Message.convert(e); } }
/** * Parse the statement, but don't prepare it for execution. * * @param sql the SQL statement to parse * @return the prepared object */ public Prepared parseOnly(String sql) throws SQLException { try { return parse(sql); } catch (Exception e) { throw Message.convert(e); } }
public static Writer openFileWriter(String fileName, boolean append) throws SQLException { OutputStream out = FileSystem.getInstance(fileName).openFileOutputStream(fileName, append); try { return new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); } catch (UnsupportedEncodingException e) { throw Message.convert(e); } }
/** * This method should not be called by an application. * * @return the new connection */ public Connection connect(String url, Properties info) throws SQLException { try { if (info == null) { info = new Properties(); } if (!acceptsURL(url)) { return null; } return new JdbcConnection(url, info); } catch (Throwable e) { throw Message.convert(e); } }
/** * Parse the statement and prepare it for execution. * * @param sql the SQL statement to parse * @return the prepared object */ public Prepared prepare(String sql) throws SQLException { try { Prepared p = parse(sql); p.prepare(); return p; } catch (Exception e) { throw Message.convert(e); } }
public boolean createNewFile(String fileName) throws SQLException { try { if (exists(fileName)) { return false; } openFileObject(fileName, "rw").close(); return true; } catch (IOException e) { throw Message.convert(e); } }
ClassUtils.loadUserClass(driver); } catch (ClassNotFoundException e) { throw Message.convert(e);
protected SQLException logAndConvert(Throwable e) { if (SysProperties.LOG_ALL_ERRORS) { synchronized (TraceObject.class) { // e.printStackTrace(); try { Writer writer = FileUtils.openFileWriter(SysProperties.LOG_ALL_ERRORS_FILE, true); PrintWriter p = new PrintWriter(writer); e.printStackTrace(p); p.close(); writer.close(); } catch (Exception e2) { e2.printStackTrace(); } } } if (trace == null) { TraceSystem.traceThrowable(e); } else { if (e instanceof SQLException) { trace.error("SQLException", e); return (SQLException) e; } else { trace.error("Uncaught Exception", e); } } return Message.convert(e); }
private void sendError(Throwable e) { try { SQLException s = Message.convert(e); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); String trace = writer.toString(); String message; String sql; if (e instanceof JdbcSQLException) { JdbcSQLException j = (JdbcSQLException) e; message = j.getOriginalMessage(); sql = j.getSQL(); } else { message = e.getMessage(); sql = null; } transfer.writeInt(SessionRemote.STATUS_ERROR).writeString(s.getSQLState()).writeString(message) .writeString(sql).writeInt(s.getErrorCode()).writeString(trace).flush(); } catch (IOException e2) { server.traceError(e2); // if writing the error does not work, close the connection stop = true; } }
throw Message.addSQL(Message.convert(e), this.originalSQL);
private void addRowsToIndex(Session session, ObjectArray list, Index index) throws SQLException { final Index idx = index; try { list.sort(new Comparator() { public int compare(Object o1, Object o2) { Row r1 = (Row) o1; Row r2 = (Row) o2; try { return idx.compareRows(r1, r2); } catch (SQLException e) { throw Message.convertToInternal(e); } } }); } catch (Exception e) { throw Message.convert(e); } for (int i = 0; i < list.size(); i++) { Row row = (Row) list.get(i); index.add(session, row); } list.clear(); }
/** * Execute a query and return a local result set. * This method prepares everything and calls {@link #query(int)} finally. * * @param maxrows the maximum number of rows to return * @return the local result set */ public LocalResult executeQueryLocal(int maxrows) throws SQLException { startTime = System.currentTimeMillis(); Database database = session.getDatabase(); Object sync = database.getMultiThreaded() ? (Object) session : (Object) database; session.waitIfExclusiveModeEnabled(); synchronized (sync) { try { database.checkPowerOff(); session.setCurrentCommand(this, startTime); return query(maxrows); } catch (Throwable e) { SQLException s = Message.convert(e); database.exceptionThrown(s, sql); throw s; } finally { stop(); } } }
void execute(Database db, Session systemSession, DatabaseEventListener listener) throws SQLException { try { Prepared command = systemSession.prepare(sql); command.setObjectId(id); command.setHeadPos(headPos); command.update(); } catch (Throwable e) { SQLException s = Message.addSQL(Message.convert(e), sql); db.getTrace(Trace.DATABASE).error(sql, s); if (listener != null) { listener.exceptionThrown(s, sql); // continue startup in this case } else { throw s; } } }
throw Message.convert(e); } catch (Throwable e) { database.getTrace(Trace.LOG).error("Error reading log file (non-fatal)", e);
public void addRow(Session session, Row row) throws SQLException { int i = 0; lastModificationId = database.getNextModificationDataId(); if (database.isMultiVersion()) { row.setSessionId(session.getId()); } try { for (; i < indexes.size(); i++) { Index index = (Index) indexes.get(i); index.add(session, row); checkRowCount(session, index, 1); } rowCount++; } catch (Throwable e) { try { while (--i >= 0) { Index index = (Index) indexes.get(i); index.remove(session, row); checkRowCount(session, index, 0); } } catch (SQLException e2) { // this could happen, for example on failure in the storage // but if that is not the case it means there is something wrong // with the database // TODO log this problem throw e2; } throw Message.convert(e); } }