Beispiel #1
0
  /**
   * Checks if the table of the specified database is locked.
   *
   * @param db name of database
   * @param ctx database context
   * @return result of check
   */
  public static boolean locked(final String db, final Context ctx) {
    final IOFile table = MetaData.file(ctx.globalopts.dbpath(db), DATATBL);
    if (!table.exists()) return false;

    try (final RandomAccessFile file = new RandomAccessFile(table.file(), "rw")) {
      return file.getChannel().tryLock() == null;
    } catch (final ClosedChannelException ex) {
      return false;
    } catch (final OverlappingFileLockException | IOException ex) {
      return true;
    }
  }