Ejemplo n.º 1
0
 /**
  * Creates a container for the specified node values.
  *
  * @param doc document
  */
 protected static void create(final String doc) {
   try {
     new CreateDB(Util.className(SandboxTest.class), doc).execute(context);
   } catch (final BaseXException ex) {
     Util.notExpected(ex);
   }
 }
Ejemplo n.º 2
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);
    }
  }
Ejemplo n.º 3
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);
   }
 }
Ejemplo n.º 4
0
  @Override
  public void createIndex(final IndexType type, final MainOptions options, final Command cmd)
      throws IOException {

    // close existing index
    close(type);
    final IndexBuilder ib;
    switch (type) {
      case TEXT:
        ib = new DiskValuesBuilder(this, options, true);
        break;
      case ATTRIBUTE:
        ib = new DiskValuesBuilder(this, options, false);
        break;
      case FULLTEXT:
        ib = new FTBuilder(this, options);
        break;
      default:
        throw Util.notExpected();
    }
    if (cmd != null) cmd.proc(ib);
    set(type, ib.build());
  }
Ejemplo n.º 5
0
 /**
  * Parses a single command.
  *
  * @param cmd command definition
  * @return resulting command
  * @throws QueryException query exception
  */
 private Command parse(final Cmd cmd) throws QueryException {
   switch (cmd) {
     case CREATE:
       switch (consume(CmdCreate.class, cmd)) {
         case BACKUP:
           return new CreateBackup(glob(cmd));
         case DATABASE:
         case DB:
           return new CreateDB(name(cmd), remaining(null));
         case INDEX:
           return new CreateIndex(consume(CmdIndex.class, cmd));
         case USER:
           return new CreateUser(name(cmd), password());
         case EVENT:
           return new CreateEvent(name(cmd));
       }
       break;
     case COPY:
       return new Copy(name(cmd), name(cmd));
     case ALTER:
       switch (consume(CmdAlter.class, cmd)) {
         case DATABASE:
         case DB:
           return new AlterDB(name(cmd), name(cmd));
         case USER:
           return new AlterUser(name(cmd), password());
       }
       break;
     case OPEN:
       return new Open(name(cmd));
     case CHECK:
       return new Check(string(cmd));
     case ADD:
       String arg = key(S_TO, null) ? string(cmd) : null;
       return new Add(arg, remaining(cmd));
     case STORE:
       arg = key(S_TO, null) ? string(cmd) : null;
       return new Store(arg, remaining(cmd));
     case RETRIEVE:
       return new Retrieve(string(cmd));
     case DELETE:
       return new Delete(string(cmd));
     case RENAME:
       return new Rename(string(cmd), string(cmd));
     case REPLACE:
       return new Replace(string(cmd), remaining(cmd));
     case INFO:
       switch (consume(CmdInfo.class, cmd)) {
         case NULL:
           return new Info();
         case DATABASE:
         case DB:
           return new InfoDB();
         case INDEX:
           return new InfoIndex(consume(CmdIndexInfo.class, null));
         case STORAGE:
           String arg1 = number(null);
           final String arg2 = arg1 != null ? number(null) : null;
           if (arg1 == null) arg1 = xquery(null);
           return new InfoStorage(arg1, arg2);
       }
       break;
     case INSPECT:
       return new Inspect();
     case CLOSE:
       return new Close();
     case LIST:
       return new List(name(null), string(null));
     case DROP:
       switch (consume(CmdDrop.class, cmd)) {
         case DATABASE:
         case DB:
           return new DropDB(glob(cmd));
         case INDEX:
           return new DropIndex(consume(CmdIndex.class, cmd));
         case USER:
           return new DropUser(glob(cmd), key(ON, null) ? glob(cmd) : null);
         case BACKUP:
           return new DropBackup(glob(cmd));
         case EVENT:
           return new DropEvent(name(cmd));
       }
       break;
     case OPTIMIZE:
       switch (consume(CmdOptimize.class, cmd)) {
         case NULL:
           return new Optimize();
         case ALL:
           return new OptimizeAll();
       }
       break;
     case EXPORT:
       return new Export(string(cmd));
     case XQUERY:
       return new XQuery(xquery(cmd));
     case RUN:
       return new Run(string(cmd));
     case TEST:
       return new Test(string(cmd));
     case EXECUTE:
       return new Execute(string(cmd, false));
     case FIND:
       return new Find(string(cmd, false));
     case CS:
       return new Cs(xquery(cmd));
     case GET:
       return new Get(name(null));
     case SET:
       return new Set(name(cmd), string(null, false));
     case PASSWORD:
       return new Password(password());
     case HELP:
       return new Help(name(null));
     case EXIT:
       return new Exit();
     case FLUSH:
       return new Flush();
     case KILL:
       return new Kill(string(cmd));
     case RESTORE:
       return new Restore(name(cmd));
     case SHOW:
       switch (consume(CmdShow.class, cmd)) {
         case SESSIONS:
           return new ShowSessions();
         case USERS:
           return new ShowUsers(key(ON, null) ? name(cmd) : null);
         case BACKUPS:
           return new ShowBackups();
         case EVENTS:
           return new ShowEvents();
       }
       break;
     case GRANT:
       final CmdPerm perm = consume(CmdPerm.class, cmd);
       if (perm == null) throw help(null, cmd);
       final String db = key(ON, null) ? glob(cmd) : null;
       key(S_TO, cmd);
       return new Grant(perm, glob(cmd), db);
     case REPO:
       switch (consume(CmdRepo.class, cmd)) {
         case INSTALL:
           return new RepoInstall(string(cmd), new InputInfo(parser));
         case DELETE:
           return new RepoDelete(string(cmd), new InputInfo(parser));
         case LIST:
           return new RepoList();
       }
       break;
   }
   throw Util.notExpected("Command specified, but not implemented yet");
 }