Class RDBMSStore

java.lang.Object
fr.inria.rules.dlgpemodel.HasItemInfoImpl
fr.inria.rules.dlgpemodel.SentenceImpl
fr.inria.rules.integraal.storage.external.rdbms.RDBMSStore
All Implemented Interfaces:
fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo, fr.inria.rules.dlgpemodel.api.sentences.IFact, fr.inria.rules.dlgpemodel.api.sentences.IPrintable, fr.inria.rules.dlgpemodel.api.sentences.ISentence, Labeled, Printable, Sentence, DatalogDelegable, MaterializedData, QueryableData, QueryDelegatableData, Writable, CSVCopyable, FactBase, TermCompound, Iterable<Atom>

public class RDBMSStore extends fr.inria.rules.dlgpemodel.SentenceImpl implements FactBase, QueryDelegatableData, DatalogDelegable, CSVCopyable
This wrapper represents RDBMS handled by InteGraal. They are accessed by translating atoms, queries and even some rules into SQL queries following the given storage strategy.
  • Field Details

    • COUNT_VARIABLE_NAME

      public static final String COUNT_VARIABLE_NAME
      Name of the column used when SQL delegation returns only the answer count.
      See Also:
  • Constructor Details

    • RDBMSStore

      public RDBMSStore(RDBMSDriver driver, RDBMSStorageLayout strategy, TermFactory termFactory, PredicateFactory predicateFactory) throws SQLException
      Creates a new wrapper over a RDBMS using user-given parameters
      Parameters:
      driver - the driver to use to connect to the database
      strategy - the strategy for representing atoms
      termFactory - the term factory
      predicateFactory - the predicate factory
      Throws:
      SQLException - if an error occurs during connection or initialization
  • Method Details

    • estimateBound

      public Optional<Long> estimateBound(BasicQuery query)
      //////////////////////////////////////////////
      Specified by:
      estimateBound in interface QueryableData
      Parameters:
      query - the query for which we want to know the upper bound
      Returns:
      an Optional containing the estimated upper bound of answers, or an empty Optional if estimation is not possible
    • getAtomicPattern

      public AtomicPattern getAtomicPattern(Predicate predicate)
      Description copied from interface: QueryableData
      Get the basic pattern for a given predicate
      Specified by:
      getAtomicPattern in interface QueryableData
      Parameters:
      predicate - the predicate for which we want to know the basic pattern
      Returns:
      a basic pattern for predicate
    • getTerms

      public Stream<Term> getTerms()
      Description copied from interface: TermCompound
      Streams the first-level terms contained in this object.
      Specified by:
      getTerms in interface TermCompound
      Returns:
      a stream over all the non-nested terms (i.e., all terms that are not themselves in a compound term) For instance, for p(a,g(b)), it returns a and g(b) but not b.
    • isEvaluable

      public boolean isEvaluable(Query query)
      Description copied from interface: QueryDelegatableData
      Checks if a query can be evaluated
      Specified by:
      isEvaluable in interface QueryDelegatableData
      Parameters:
      query - the query to check
      Returns:
      true iff tryEvaluate returns a non-empty optional
    • evaluate

      public Stream<Substitution> evaluate(Query query, boolean distinct) throws EvaluationException
      Description copied from interface: QueryDelegatableData
      Try to evaluate a basic query
      Specified by:
      evaluate in interface QueryDelegatableData
      Parameters:
      query - the query to evaluate
      distinct - whether duplicate substitutions should be filtered out
      Returns:
      Empty if the query is not evaluable, otherwise a stream containing substitutions that are the answers to the query
      Throws:
      EvaluationException - if delegated evaluation fails
    • evaluate

      public Stream<List<Term>> evaluate(BasicQuery query) throws EvaluationException
      Description copied from interface: QueryableData
      Try to evaluate a basic query
      Specified by:
      evaluate in interface QueryableData
      Parameters:
      query - the query to evaluate
      Returns:
      Empty if the query is not evaluable, otherwise a stream containing substitutions that are the answers to the query
      Throws:
      EvaluationException - if query evaluation fails
    • add

      public boolean add(FOFormula atoms)
      Description copied from interface: Writable
      Stores the given atoms
      Specified by:
      add in interface Writable
      Parameters:
      atoms - to add
      Returns:
      true iff at least one atom is new
    • addAll

      public boolean addAll(Stream<Atom> atoms)
      Description copied from interface: Writable
      Stores the given atoms
      Specified by:
      addAll in interface Writable
      Parameters:
      atoms - to add
      Returns:
      true iff at least one atom is new
    • addAll

      public boolean addAll(Collection<Atom> atoms)
      Description copied from interface: Writable
      Stores the given atoms
      Specified by:
      addAll in interface Writable
      Parameters:
      atoms - to add
      Returns:
      true iff at least one atom is new
    • add

      public boolean add(Atom atom)
      Description copied from interface: Writable
      Stores the given atom
      Specified by:
      add in interface Writable
      Parameters:
      atom - to add
      Returns:
      true iff the atom is new
    • remove

      public boolean remove(Atom atom)
      Description copied from interface: Writable
      Removes the given atom
      Specified by:
      remove in interface Writable
      Parameters:
      atom - to remove
      Returns:
      true iff the atom is removed
    • remove

      public boolean remove(FOFormula atoms)
      Description copied from interface: Writable
      Removes the given atoms
      Specified by:
      remove in interface Writable
      Parameters:
      atoms - to remove
      Returns:
      true iff at least one atom is removed
    • removeAll

      public boolean removeAll(Collection<Atom> atoms)
      Description copied from interface: Writable
      Removes the given atoms
      Specified by:
      removeAll in interface Writable
      Parameters:
      atoms - to remove
      Returns:
      true iff at least one atom is removed
    • getPredicates

      public Stream<Predicate> getPredicates()
      Description copied from interface: QueryableData
      Returns a collection of all predicates in this Readable.
      Specified by:
      getPredicates in interface QueryableData
      Returns:
      a collection of all predicates.
    • hasPredicate

      public boolean hasPredicate(Predicate p)
      Description copied from interface: QueryableData
      Allows checking if this QueryableData provides the predicate p
      Specified by:
      hasPredicate in interface QueryableData
      Parameters:
      p - the predicate to look up
      Returns:
      boolean that is true iff the QueryableData provides this predicate
    • getTermsByPredicatePosition

      public Stream<Term> getTermsByPredicatePosition(Predicate p, int position)
      Description copied from interface: MaterializedData
      Returns a stream over terms which are in a specific position in at least one atom with the given predicate.
      Specified by:
      getTermsByPredicatePosition in interface MaterializedData
      Parameters:
      p - predicate
      position - the position of the term in atoms, positions starts from 0.
      Returns:
      a stream over terms which appear in the specified position of the specified predicate.
    • getEvaluator

      public SQLParameterizedQueryEvaluator getEvaluator()
      Returns the SQL evaluator used by this store.
      Returns:
      the evaluator
    • getDriver

      public RDBMSDriver getDriver()
      Returns the RDBMS driver backing this store.
      Returns:
      the driver
    • getStrategy

      public RDBMSStorageLayout getStrategy()
      Returns the storage layout used by this store.
      Returns:
      the storage layout
    • delegate

      public boolean delegate(Collection<FORule> rules) throws Exception
      Description copied from interface: DatalogDelegable
      Apply all the given (datalog) rules.
      Specified by:
      delegate in interface DatalogDelegable
      Parameters:
      rules - the rules to apply
      Returns:
      true iff at least one atom have been produced by the application of the rules
      Throws:
      Exception - if a given rule is not datalog. The exact type is depending on the implementation
    • delegate

      public Iterator<Substitution> delegate(FOQuery<?> query, boolean onlyCountAnswers) throws Exception
      Description copied from interface: DatalogDelegable
      Evaluate the given (conjunctive) query
      Specified by:
      delegate in interface DatalogDelegable
      Parameters:
      query - the query to evaluate
      onlyCountAnswers - true iff the query has to return only the number of answers
      Returns:
      an Iterator of Substitution over all the answers of the given query with respect to the query answer variables.
      Throws:
      Exception - if the given query is not conjunctive. The exact type is depending on the implementation
    • copy

      public boolean copy(String csvFilePath, char separator, int headerSize, Atom witness) throws SQLException
      Description copied from interface: CSVCopyable
      Copy the content of the given CSV file into the storage system The exact layout of the resulting storage is dependent on the implementation
      Specified by:
      copy in interface CSVCopyable
      Parameters:
      csvFilePath - the csv file to copy
      separator - separator char of the CSV
      headerSize - size of the CSV header
      witness - atom used to pre-create the storing schema
      Returns:
      true iff at least one atom have been added by the copy
      Throws:
      SQLException
    • getAtomsByTerm

      public Stream<Atom> getAtomsByTerm(Term t)
      //////////////////////////////////////////////
      Specified by:
      getAtomsByTerm in interface MaterializedData
      Parameters:
      t - to search
      Returns:
      a stream over all atoms with the specified term
    • contains

      public boolean contains(Atom a)
      Description copied from interface: MaterializedData
      Tests whether a given atom is present in this data source.
      Specified by:
      contains in interface MaterializedData
      Parameters:
      a - the atom to find
      Returns:
      true iff this storage contains the given atom
    • size

      public long size()
      Description copied from interface: MaterializedData
      Counts the atoms contained in this data source.
      Specified by:
      size in interface MaterializedData
      Returns:
      the number of atoms
    • dictionarySize

      public long dictionarySize()
      Returns the number of entries stored in the dictionary table.
      Returns:
      the dictionary size, or -1 when it cannot be determined
    • dictionaryList

      public String dictionaryList()
      Returns a textual dump of the dictionary table.
      Returns:
      the formatted dictionary content
    • getType

      public FactBaseType getType(Predicate viewPredicate)
      Description copied from interface: FactBase
      Returns the storage type associated with a predicate.
      Specified by:
      getType in interface FactBase
      Parameters:
      viewPredicate - a predicate
      Returns:
      the type of storage used for the given predicate
    • getDescription

      public FactBaseDescription getDescription(Predicate viewPredicate)
      Description copied from interface: FactBase
      Returns the storage description associated with a predicate.
      Specified by:
      getDescription in interface FactBase
      Parameters:
      viewPredicate - a predicate
      Returns:
      the description of the storage
    • translate

      public Collection<SQLParameterizedQuery> translate(FORule rule) throws SQLException
      Preconditions : - the given rule have a body that can be translated by this.translate(FOQuery) - the head have no existential variables
      Parameters:
      rule - the rule to translate
      Returns:
      all the queries and there arguments that should be executed to apply the given rule on the database
      Throws:
      SQLException - if an error occur during translation
    • clear

      public void clear()
      Description copied from interface: FactBase
      Removes all atoms from the fact base.
      Specified by:
      clear in interface FactBase
      Specified by:
      clear in interface Writable
    • toDLGP

      public String toDLGP()
      Description copied from interface: Printable
      Renders this object in DLGP form.
      Specified by:
      toDLGP in interface Printable
      Returns:
      the DLGP serialization
    • getSupportedOperations

      public Collection<OperationsSupported> getSupportedOperations()
      Specified by:
      getSupportedOperations in interface QueryableData
      Returns:
      the set of operations and optimizations that are supported by the datasource