Exemple #1
0
 @Override
 public void startUpdate(final MainOptions opts) throws IOException {
   if (!table.lock(true)) throw new BaseXException(Text.DB_PINNED_X, meta.name);
   if (opts.get(MainOptions.AUTOFLUSH)) {
     final IOFile uf = meta.updateFile();
     if (uf.exists()) throw new BaseXException(Text.DB_UPDATED_X, meta.name);
     if (!uf.touch()) throw Util.notExpected("%: could not create lock file.", meta.name);
   }
 }
  /**
   * Parses a string as XML and adds the resulting nodes to the specified parent.
   *
   * @param value string to parse
   * @param elem element
   */
  public static void add(final byte[] value, final FElem elem) {

    try {
      final Parser parser = new XMLParser(new IOContent(value), MainOptions.get(), true);
      for (final ANode node : new DBNode(parser).children()) elem.add(node.copy());
    } catch (final IOException ex) {
      // fallback: add string representation
      Util.debug(ex);
      elem.add(value);
    }
  }
Exemple #3
0
  @Override
  public synchronized void finishUpdate(final MainOptions opts) {
    // remove updating file
    final boolean auto = opts.get(MainOptions.AUTOFLUSH);
    if (auto) {
      final IOFile uf = meta.updateFile();
      if (!uf.exists()) throw Util.notExpected("%: lock file does not exist.", meta.name);
      if (!uf.delete()) throw Util.notExpected("%: could not delete lock file.", meta.name);
    }

    // db:optimize(..., true) will close the database before this function is called
    if (!closed) {
      flush(auto);
      if (!table.lock(false)) throw Util.notExpected("Database '%': could not unlock.", meta.name);
    }
  }