Package datomic

Interface Database


  • public interface Database
    An immutable, point-in-time database value.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  Database.Predicate<T>
      Boolean-valued function for filtering a database.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      Database asOf​(java.lang.Object t)
      Returns the value of the database filtered to include data up to t, inclusive
      java.lang.Long asOfT()
      Attribute attribute​(java.lang.Object attrId)
      Returns information about an attribute.
      long basisT()
      t value of the most recent transaction in this db.
      java.lang.Iterable<Datom> datoms​(java.lang.Object index, java.lang.Object... components)
      Implements the Datoms API for raw access to matching index data.
      java.util.Map dbStats()
      Queries for database stats.
      java.lang.Object entid​(java.lang.Object entityId)
      Returns the entity id associated with any kind of entity identifier.
      java.lang.Object entidAt​(java.lang.Object partition, java.lang.Object timePoint)
      Returns a fabricated entity id in the supplied partition whose T component is at or after the supplied t
      Entity entity​(java.lang.Object entityId)
      Returns an entity: a lazy, dynamic associative view of datoms sharing an entity id.
      Database filter​(Database.Predicate<Datom> pred)
      Returns a value of the database containing only Datoms satisfying the predicate.
      Database filter​(java.lang.Object pred)  
      Database history()
      Returns a history database value containing all assertions and retractions across time.
      java.lang.String id()
      Opaque, globally unique database id.
      java.lang.Object ident​(java.lang.Object idOrKey)
      Returns the symbolic keyword associated with an id, or the key itself if passed.
      java.util.stream.Stream<java.lang.Object> indexPull​(java.lang.Object options)
      "Walks an index, pulling entities via :e if :avet or :v if :aevt, using the selector, returning a Stream of the results.
      java.lang.Iterable<Datom> indexRange​(java.lang.Object attrid, java.lang.Object start, java.lang.Object end)
      Returns a range of AVET-indexed datoms.
      java.lang.Object invoke​(java.lang.Object entityId, java.lang.Object... args)
      Look up the database function of the entity at entityId, and invoke the function with args.
      boolean isFiltered()
      Does database have a filter set with e.g.
      boolean isHistory()
      True for databases created with history()
      long nextT()
      next t value that will be assigned by this database.
      java.util.Map pull​(java.lang.Object pattern, java.lang.Object entityId)
      Returns a hierarchical selection of attributes for entityId.
      java.util.List<java.util.Map> pullMany​(java.lang.Object pattern, java.util.List entityIds)
      Returns hierarchical selections of attributes for entityIds.
      java.lang.Iterable<Datom> seekDatoms​(java.lang.Object index, java.lang.Object... components)
      Raw access to index data, starting at nearest match to input
      Database since​(java.lang.Object t)
      Returns the value of the database filtered to include only data since t, exclusive
      java.lang.Long sinceT()
      java.util.Map with​(java.util.List txData)
      Returns a database with txData applied locally in memory.
    • Method Detail

      • id

        java.lang.String id()
        Opaque, globally unique database id.
        Returns:
        the database id
      • basisT

        long basisT()
        t value of the most recent transaction in this db.
        Returns:
        a t value
      • nextT

        long nextT()
        next t value that will be assigned by this database.
        Returns:
        a t value
      • isHistory

        boolean isHistory()
        True for databases created with history()
        Returns:
        true for history databases
      • with

        java.util.Map with​(java.util.List txData)

        Returns a database with txData applied locally in memory.

        It is as if the data was applied in a transaction, but no actual transaction takes place.
        Parameters:
        txData - in the same format as expected by transact
        Returns:
        a map as returned by transact
      • asOf

        Database asOf​(java.lang.Object t)
        Returns the value of the database filtered to include data up to t, inclusive
        Parameters:
        t - a time-point
        Returns:
        the value of the database as of some point t, inclusive
      • since

        Database since​(java.lang.Object t)
        Returns the value of the database filtered to include only data since t, exclusive
        Parameters:
        t - a time-point
        Returns:
        the value of the database since some point t, exclusive
      • filter

        Database filter​(Database.Predicate<Datom> pred)

        Returns a value of the database containing only Datoms satisfying the predicate.

        The predicate will be passed the unfiltered db and a Datom Chained calls to filter compose predicates with logical 'and'.
        Parameters:
        pred - a Predicate<Datom> or clojure fn
        Returns:
        the value of the database satisfying the predicate
        Since:
        0.8.3627
      • filter

        Database filter​(java.lang.Object pred)
      • entity

        Entity entity​(java.lang.Object entityId)
        Returns an entity: a lazy, dynamic associative view of datoms sharing an entity id.
        Parameters:
        entityId - an entity identifier
        Returns:
        an Entity
      • attribute

        Attribute attribute​(java.lang.Object attrId)
        Returns information about an attribute.
        Parameters:
        attrId - an entity identifier for an attribute
        Returns:
        an Attribute}
        Since:
        0.9.4470
      • ident

        java.lang.Object ident​(java.lang.Object idOrKey)
        Returns the symbolic keyword associated with an id, or the key itself if passed.
        Parameters:
        idOrKey - an id or keyword
        Returns:
        a keyword, or nil if not found
      • entid

        java.lang.Object entid​(java.lang.Object entityId)
        Returns the entity id associated with any kind of entity identifier.
        Parameters:
        entityId - an entity identifier
        Returns:
        an id, or nil if not found
      • entidAt

        java.lang.Object entidAt​(java.lang.Object partition,
                                 java.lang.Object timePoint)

        Returns a fabricated entity id in the supplied partition whose T component is at or after the supplied t

        . Entity ids sort by partition, then T component, such T components interleaving with transaction numbers. Thus this method can be used to fabricate a time-based entity id component for use in #seekDatoms.
        Parameters:
        partition - an entity identifier for a partition
        timePoint - a time-point
        Returns:
        a fabricated entity id at or after some point t
      • invoke

        java.lang.Object invoke​(java.lang.Object entityId,
                                java.lang.Object... args)
        Look up the database function of the entity at entityId, and invoke the function with args.
        Parameters:
        entityId - an entity identifier
        args - the arguments to the database function
        Returns:
        the return value of the database function
      • datoms

        java.lang.Iterable<Datom> datoms​(java.lang.Object index,
                                         java.lang.Object... components)

        Implements the Datoms API for raw access to matching index data.

        The index must be supplied, and, optionally, one or more leading components of the index can be supplied to narrow the result. EAVT and AEVT indexes will contain all datoms AVET will contain datoms for attributes where either :db/index or :db/unique are true. VAET will contain datoms for attributes of :db.type/ref - it is the reverse index
        Parameters:
        index - one of EAVT, AEVT, AVET, or VAET
        components - supply any datom components to match, in order corresponding to the index
        Returns:
        the datoms in the specified index matching the specified components
      • seekDatoms

        java.lang.Iterable<Datom> seekDatoms​(java.lang.Object index,
                                             java.lang.Object... components)

        Raw access to index data, starting at nearest match to input

        . Arguments are the same as to datoms(java.lang.Object, java.lang.Object...), but their interpretation is different in two important ways:
        1. The match need not be exact. Results will begin with the closest matching datom
        2. No termination. Results will continue all the way to the end of the index.
        seekDatoms is for more advanced applications, and datoms(Object, Object...) should be preferred wherever it is adequate. seekDatoms is typically used in conjunction with entidAt(Object, Object) to implement new entity scans.
        Parameters:
        index - one of EAVT, AEVT, AVET, or VAET
        components - supply any datom components to search for, in order corresponding to the index
        Returns:
        all of the datoms in the specified index at or after the specified components
      • indexRange

        java.lang.Iterable<Datom> indexRange​(java.lang.Object attrid,
                                             java.lang.Object start,
                                             java.lang.Object end)

        Returns a range of AVET-indexed datoms.

        Parameters:
        attrid - an entity identifier naming an indexed attribute.
        start - start value or null if from beginning
        end - end value (non-inclusive), or null if through end
        Returns:
        an Iterable over Datom positioned between start (inclusive) and end (exclusive)
      • pull

        java.util.Map pull​(java.lang.Object pattern,
                           java.lang.Object entityId)
        Returns a hierarchical selection of attributes for entityId.
        Parameters:
        pattern - A pattern, or a String containing a pattern serialized into edn.
        entityId - An entity identifier
        Returns:
        A map containing a selection for the entityId passed in.
        Since:
        0.9.5040
      • indexPull

        java.util.stream.Stream<java.lang.Object> indexPull​(java.lang.Object options)
        "Walks an index, pulling entities via :e if :avet or :v if :aevt, using the selector, returning a Stream of the results.
        Parameters:
        options - a data structure describing the indexPull serialized into edn
        • a map that includes the :index, :selector, :start, and :reverse keys
        indexPull map keys
        :index  :avet or :aevt
        :selector  a pull selector (see 'pull')
        :start  A vector in the same order as the index indicating the initial position. At least :a must be specified. Iteration is limited to datoms matching :a.
        :reverse  optional, when true iterate the index in reverse order
        Returns:
        an Stream of the indexPull results
        Since:
        0.9.6079
      • pullMany

        java.util.List<java.util.Map> pullMany​(java.lang.Object pattern,
                                               java.util.List entityIds)
        Returns hierarchical selections of attributes for entityIds.
        Parameters:
        pattern - A pattern, or a String containing a pattern serialized into edn.
        entityIds - A list of entity identifiers
        Returns:
        A list of maps containing a selection for each entityId passed in.
        Since:
        0.9.5040
      • dbStats

        java.util.Map dbStats()
        Queries for database stats.
        Returns:
        a map with at least the following keys:
        dbStats return keys
        :datoms  total count of datoms in the (history) database