@Override public Index addIndex(Session session, String indexName, int indexId, IndexColumn[] cols, IndexType indexType, boolean create, String indexComment) { throw DbException.getUnsupportedException("SYSTEM_RANGE"); }
@Override public int readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length) { throw DbException.throwInternalError(); }
/** * Converts a LocalTime to a Value. * * @param localTime the LocalTime to convert, not {@code null} * @return the value */ public static Value localTimeToTimeValue(Object localTime) { try { return ValueTime.fromNanos((Long) LOCAL_TIME_TO_NANO.invoke(localTime)); } catch (IllegalAccessException e) { throw DbException.convert(e); } catch (InvocationTargetException e) { throw DbException.convertInvocation(e, "time conversion failed"); } }
/** * Create a database exception for a specific error code. * * @param errorCode the error code * @param params the list of parameters of the message * @return the exception */ public static DbException get(int errorCode, String... params) { return new DbException(getJdbcSQLException(errorCode, null, params)); }
/** * Convert an exception to a SQL exception using the default mapping. * * @param e the root cause * @return the SQL exception object */ public static SQLException toSQLException(Throwable e) { if (e instanceof SQLException) { return (SQLException) e; } return convert(e).getSQLException(); }
/** * Convert a throwable to an SQL exception using the default mapping. All * errors except the following are re-thrown: StackOverflowError, * LinkageError. * * @param e the root cause * @return the exception object */ public static DbException convert(Throwable e) { if (e instanceof DbException) { return (DbException) e; } else if (e instanceof SQLException) { return new DbException((SQLException) e); } else if (e instanceof InvocationTargetException) { return convertInvocation((InvocationTargetException) e, null); } else if (e instanceof IOException) { return get(ErrorCode.IO_EXCEPTION_1, e, e.toString()); } else if (e instanceof OutOfMemoryError) { return get(ErrorCode.OUT_OF_MEMORY, e); } else if (e instanceof StackOverflowError || e instanceof LinkageError) { return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); } else if (e instanceof Error) { throw (Error) e; } return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); }
FunctionCursorResultSet(FunctionIndex index, SearchRow first, SearchRow last, Session session, ResultSet result) { super(index, first, last, session); this.result = result; try { this.meta = result.getMetaData(); } catch (SQLException e) { throw DbException.convert(e); } }
throw DbException.convert(e); } catch (Throwable e) { throw DbException.convert(e); e = e.addSQL(sql); SQLException s = e.getSQLException(); database.exceptionThrown(s, sql); if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
private long filterConcurrentUpdate(DbException e, long start) { int errorCode = e.getErrorCode(); if (errorCode != ErrorCode.CONCURRENT_UPDATE_1 && errorCode != ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1) { throw e; } long now = System.nanoTime() / 1000000; if (start != 0 && now - start > session.getLockTimeout()) { throw DbException.get(ErrorCode.LOCK_TIMEOUT_1, e.getCause(), ""); } Database database = session.getDatabase(); int sleep = 1 + MathUtils.randomInt(10); while (true) { try { if (database.isMultiThreaded()) { Thread.sleep(sleep); } else { database.wait(sleep); } } catch (InterruptedException e1) { // ignore } long slept = System.nanoTime() / 1000000 - now; if (slept >= sleep) { break; } } return start == 0 ? now : start; }
private DbException getExceptionAlreadyInUse(String reason) { DbException e = DbException.get( ErrorCode.DATABASE_ALREADY_OPEN_1, reason); if (fileName != null) { try { Properties prop = load(); String server = prop.getProperty("server"); if (server != null) { String serverId = server + "/" + prop.getProperty("id"); e = e.addSQL(serverId); } } catch (DbException e2) { // ignore } } return e; }
public DbException getNewDuplicateKeyException() { String sql = "PRIMARY KEY ON " + table.getSQL(); if (mainIndexColumn >= 0 && mainIndexColumn < indexColumns.length) { sql += "(" + indexColumns[mainIndexColumn].getSQL() + ")"; } DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, sql); e.setSource(this); return e; }
/** * Close the underlying reader. */ @Override public void close() { try { reader.close(); } catch (IOException e) { throw DbException.convertIOException(e, null); } }
@Override public void close() throws IOException { if (closed) { return; } closed = true; try { rs.close(); } catch (SQLException e) { throw DbException.convertToIOException(e); } } };
/** * Set the SQL statement of the given exception. * This method may create a new object. * * @param sql the SQL statement * @return the exception */ public DbException addSQL(String sql) { SQLException e = getSQLException(); if (e instanceof JdbcSQLException) { JdbcSQLException j = (JdbcSQLException) e; if (j.getSQL() == null) { j.setSQL(sql); } return this; } e = new JdbcSQLException(e.getMessage(), sql, e.getSQLState(), e.getErrorCode(), e, null); return new DbException(e); }
/** * Parse the statement, but don't prepare it for execution. * * @param sql the SQL statement to parse * @return the prepared object */ Prepared parse(String sql) { Prepared p; try { // first, try the fast variant p = parse(sql, false); } catch (DbException e) { if (e.getErrorCode() == ErrorCode.SYNTAX_ERROR_1) { // now, get the detailed exception p = parse(sql, true); } else { throw e.addSQL(sql); } } p.setPrepareAlways(recompileAlways); p.setParameterList(parameters); return p; }
/** * Execute the meta data statement. * * @param db the database * @param systemSession the system session * @param listener the database event listener */ void execute(Database db, Session systemSession, DatabaseEventListener listener) { try { Prepared command = systemSession.prepare(sql); command.setObjectId(id); command.update(); } catch (DbException e) { e = e.addSQL(sql); SQLException s = e.getSQLException(); db.getTrace(Trace.DATABASE).error(s, sql); if (listener != null) { listener.exceptionThrown(s, sql); // continue startup in this case } else { throw e; } } }
/** * Set the SQL statement of the exception to the given row. * * @param e the exception * @param rowId the row number * @param values the values of the row * @return the exception */ protected DbException setRow(DbException e, int rowId, String values) { StringBuilder buff = new StringBuilder(); if (sqlStatement != null) { buff.append(sqlStatement); } buff.append(" -- "); if (rowId > 0) { buff.append("row #").append(rowId + 1).append(' '); } buff.append('(').append(values).append(')'); return e.addSQL(buff.toString()); }
/** * Get the SQLException object. * * @return the exception */ public SQLException getSQLException() { return (SQLException) getCause(); }
/** * Create a database exception for an arbitrary SQLState. * * @param sqlstate the state to use * @param message the message to use * @return the exception */ public static DbException fromUser(String sqlstate, String message) { // do not translate as sqlstate is arbitrary : avoid "message not found" return new DbException(new JdbcSQLException(message, null, sqlstate, 0, null, null)); }