/** * Parses and sets a single database option. * * @param session REST session * @param param current parameter * @param force force execution * @return success flag, indicates if value was found * @throws BaseXException database exception */ static boolean parseOption( final RESTSession session, final Entry<String, String[]> param, final boolean force) throws BaseXException { final String key = param.getKey().toUpperCase(Locale.ENGLISH); final MainOptions options = session.context.options; final boolean found = options.option(key) != null; if (found || force) options.assign(key, param.getValue()[0]); return found; }
@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); } }
@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); } }