Tabnine Logo
DbException
Code IndexAdd Tabnine to your IDE (free)

How to use
DbException
in
org.h2.message

Best Java code snippets using org.h2.message.DbException (Showing top 20 results out of 315)

origin: com.h2database/h2

@Override
public Index addIndex(Session session, String indexName,
    int indexId, IndexColumn[] cols, IndexType indexType,
    boolean create, String indexComment) {
  throw DbException.getUnsupportedException("SYSTEM_RANGE");
}
origin: com.h2database/h2

@Override
public int readLob(long lobId, byte[] hmac, long offset, byte[] buff,
    int off, int length) {
  throw DbException.throwInternalError();
}
origin: com.h2database/h2

/**
 * 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");
  }
}
origin: com.h2database/h2

/**
 * 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));
}
origin: com.h2database/h2

/**
 * 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();
}
origin: com.h2database/h2

/**
 * 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());
}
origin: com.h2database/h2

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);
  }
}
origin: com.h2database/h2

@Override
public void checkWritingAllowed() {
  if (readOnly) {
    throw DbException.get(ErrorCode.DATABASE_IS_READ_ONLY);
  }
  if (fileLockMethod == FileLockMethod.SERIALIZED) {
    if (!reconnectChangePending) {
      throw DbException.get(ErrorCode.DATABASE_IS_READ_ONLY);
    }
  }
}
origin: com.h2database/h2

    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) {
origin: com.eventsourcing/h2

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;
}
origin: com.h2database/h2

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;
}
origin: com.h2database/h2

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;
}
origin: com.h2database/h2

/**
 * Close the underlying reader.
 */
@Override
public void close() {
  try {
    reader.close();
  } catch (IOException e) {
    throw DbException.convertIOException(e, null);
  }
}
origin: com.h2database/h2

  @Override
  public void close() throws IOException {
    if (closed) {
      return;
    }
    closed = true;
    try {
      rs.close();
    } catch (SQLException e) {
      throw DbException.convertToIOException(e);
    }
  }
};
origin: com.h2database/h2

/**
 * 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);
}
origin: com.h2database/h2

/**
 * 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;
}
origin: com.h2database/h2

/**
 * 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;
    }
  }
}
origin: com.h2database/h2

/**
 * 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());
}
origin: com.h2database/h2

/**
 * Get the SQLException object.
 *
 * @return the exception
 */
public SQLException getSQLException() {
  return (SQLException) getCause();
}
origin: com.h2database/h2

/**
 * 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));
}
org.h2.messageDbException

Javadoc

This exception wraps a checked exception. It is used in methods where checked exceptions are not supported, for example in a Comparator.

Most used methods

  • getUnsupportedException
    Gets a SQL exception meaning this feature is not supported.
  • throwInternalError
    Throw an internal error. This method seems to return an exception object, so that it can be used ins
  • convert
    Convert a throwable to an SQL exception using the default mapping. All errors except the following a
  • get
    Create a database exception for a specific error code.
  • <init>
  • addSQL
    Set the SQL statement of the given exception. This method may create a new object.
  • convertIOException
    Convert an IO exception to a database exception.
  • convertInvocation
    Convert an InvocationTarget exception to a database exception.
  • convertToIOException
    Convert an exception to an IO exception.
  • getCause
  • getErrorCode
    Get the error code.
  • getInvalidValueException
    Gets a SQL exception meaning this value is invalid.
  • getErrorCode,
  • getInvalidValueException,
  • getJdbcSQLException,
  • getMessage,
  • getSQLException,
  • getSource,
  • getSyntaxError,
  • printStackTrace,
  • setSource,
  • toSQLException

Popular in Java

  • Making http requests using okhttp
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onCreateOptionsMenu (Activity)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now