Ejemplo n.º 1
0
  /**
   * Default constructor, called from {@link Open#open}.
   *
   * @param meta meta data
   * @throws IOException I/O Exception
   */
  public DiskData(final MetaData meta) throws IOException {
    super(meta);

    try (final DataInput in = new DataInput(meta.dbfile(DATAINF))) {
      meta.read(in);
      while (true) {
        final String k = string(in.readToken());
        if (k.isEmpty()) break;
        if (k.equals(DBTAGS)) elemNames = new Names(in, meta);
        else if (k.equals(DBATTS)) attrNames = new Names(in, meta);
        else if (k.equals(DBPATH)) paths = new PathSummary(this, in);
        else if (k.equals(DBNS)) nspaces = new Namespaces(in);
        else if (k.equals(DBDOCS)) resources.read(in);
      }
    }

    // open data and indexes
    init();
    if (meta.updindex) {
      idmap = new IdPreMap(meta.dbfile(DATAIDP));
      if (meta.textindex) textIndex = new UpdatableDiskValues(this, true);
      if (meta.attrindex) attrIndex = new UpdatableDiskValues(this, false);
    } else {
      if (meta.textindex) textIndex = new DiskValues(this, true);
      if (meta.attrindex) attrIndex = new DiskValues(this, false);
    }
    if (meta.ftxtindex) ftxtIndex = new FTIndex(this);
  }
Ejemplo n.º 2
0
  /**
   * Lists all databases.
   *
   * @return success flag
   * @throws IOException I/O exception
   */
  private boolean list() throws IOException {
    final Table table = new Table();
    table.description = DATABASES_X;

    final boolean create = context.user.has(Perm.CREATE);
    table.header.add(T_NAME);
    table.header.add(RESOURCES);
    table.header.add(SIZE);
    if (create) table.header.add(INPUT_PATH);

    for (final String name : context.databases.listDBs()) {
      String file = null;
      long size = 0;
      int docs = 0;
      final MetaData meta = new MetaData(name, context);
      try {
        meta.read();
        size = meta.dbsize();
        docs = meta.ndocs;
        if (context.perm(Perm.READ, meta)) file = meta.original;
      } catch (final IOException ex) {
        file = ERROR;
      }

      // count number of raw files
      final IOFile dir = new IOFile(mprop.dbpath(name), M_RAW);
      final int bin = dir.descendants().size();

      // create entry
      if (file != null) {
        final TokenList tl = new TokenList(4);
        tl.add(name);
        tl.add(docs + bin);
        tl.add(size);
        if (create) tl.add(file);
        table.contents.add(tl);
      }
    }
    out.println(table.sort().finish());
    return true;
  }