All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sirix.index.cas.json.JsonCASIndexBuilder Maven / Gradle / Ivy

Go to download

SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.

There is a newer version: 0.11.0
Show newest version
package io.sirix.index.cas.json;

import io.sirix.access.trx.node.json.AbstractJsonNodeVisitor;
import io.sirix.api.json.JsonNodeReadOnlyTrx;
import io.sirix.api.visitor.VisitResult;
import io.sirix.index.cas.CASIndexBuilder;
import io.sirix.node.immutable.json.*;
import io.sirix.node.interfaces.immutable.ImmutableNode;

/**
 * Builds a content-and-structure (CAS) index.
 *
 * @author Johannes Lichtenberger
 */
final class JsonCASIndexBuilder extends AbstractJsonNodeVisitor {

  private final CASIndexBuilder indexBuilderDelegate;

  private final JsonNodeReadOnlyTrx rtx;

  JsonCASIndexBuilder(final CASIndexBuilder indexBuilderDelegate, final JsonNodeReadOnlyTrx rtx) {
    this.indexBuilderDelegate = indexBuilderDelegate;
    this.rtx = rtx;
  }

  @Override
  public VisitResult visit(ImmutableStringNode node) {
    final long PCR = getPathClassRecord(node);

    return indexBuilderDelegate.process(node, PCR);
  }

  @Override
  public VisitResult visit(ImmutableObjectStringNode node) {
    final long PCR = getPathClassRecord(node);

    return indexBuilderDelegate.process(node, PCR);
  }

  @Override
  public VisitResult visit(ImmutableBooleanNode node) {
    final long PCR = getPathClassRecord(node);

    return indexBuilderDelegate.process(node, PCR);
  }

  @Override
  public VisitResult visit(ImmutableObjectBooleanNode node) {
    final long PCR = getPathClassRecord(node);

    return indexBuilderDelegate.process(node, PCR);
  }

  @Override
  public VisitResult visit(ImmutableNumberNode node) {
    final long PCR = getPathClassRecord(node);

    return indexBuilderDelegate.process(node, PCR);
  }

  @Override
  public VisitResult visit(ImmutableObjectNumberNode node) {
    final long PCR = getPathClassRecord(node);

    return indexBuilderDelegate.process(node, PCR);
  }

  private long getPathClassRecord(ImmutableNode node) {
    rtx.moveTo(node.getParentKey());

    final long pcr;

    if (rtx.isObjectKey()) {
      pcr = ((ImmutableObjectKeyNode) rtx.getNode()).getPathNodeKey();
    } else if (rtx.isArray()) {
      pcr = ((ImmutableArrayNode) rtx.getNode()).getPathNodeKey();
    } else {
      pcr = 0;
    }

    return pcr;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy