Class JdbcSource

  • All Implemented Interfaces:
    ca.uqac.lif.azrael.Printable, ca.uqac.lif.azrael.Readable, ca.uqac.lif.cep.Contextualizable, ca.uqac.lif.cep.Duplicable, ca.uqac.lif.cep.DuplicableProcessor

    public class JdbcSource
    extends ca.uqac.lif.cep.tmf.Source
    Converts a query to a database into a trace of named tuples.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class ca.uqac.lif.cep.SynchronousProcessor

        ca.uqac.lif.cep.SynchronousProcessor.InputPushable, ca.uqac.lif.cep.SynchronousProcessor.OutputPullable
      • Nested classes/interfaces inherited from class ca.uqac.lif.cep.Processor

        ca.uqac.lif.cep.Processor.InternalProcessorState
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.sql.Connection m_connection
      The database connection object
      protected boolean m_feedOneByOne
      Whether the tuples of the underlying relation should be output one by one on every call to compute(Object[], Queue), or output all at once on the first call to that method.
      protected boolean m_hasRun
      Remembers whether the query has already been run on the database
      protected java.lang.String m_query
      The name of the database table to read from.
      protected java.sql.ResultSet m_resultSet
      The query's result set, out of which tuples will be extracted one by one
      protected java.sql.Statement m_statement
      The statement object corresponding to the SQL query being executed
      • Fields inherited from class ca.uqac.lif.cep.SynchronousProcessor

        m_inputPushables, m_outputPullables, m_tempQueue
      • Fields inherited from class ca.uqac.lif.cep.Processor

        m_context, m_eventTracker, m_hasBeenNotifiedOfEndOfTrace, m_inputArity, m_inputCount, m_inputPullables, m_inputQueues, m_notifiedEndOfTraceDownstream, m_outputArity, m_outputCount, m_outputPushables, m_outputQueues, MAX_PULL_RETRIES, s_versionString
    • Constructor Summary

      Constructors 
      Constructor Description
      JdbcSource​(java.sql.Connection conn, java.lang.String tablename)
      Builds a JDBC source.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean compute​(java.lang.Object[] inputs, java.util.Queue<java.lang.Object[]> outputs)  
      JdbcSource duplicate​(boolean with_state)  
      void reset()  
      void setFeedOneByOne​(boolean b)
      Sets whether the tuples of the underlying relation should be output one by one on every call to compute(Object[], Queue), or output all at once on the first call to that method.
      • Methods inherited from class ca.uqac.lif.cep.tmf.Source

        push
      • Methods inherited from class ca.uqac.lif.cep.SynchronousProcessor

        getPullableOutput, getPushableInput, setEventTracker
      • Methods inherited from class ca.uqac.lif.cep.Processor

        allNotifiedEndOfTrace, allNull, associateTo, associateToInput, associateToOutput, copyInputQueue, copyOutputQueue, duplicate, duplicateInto, equals, getAt, getContext, getContext, getEmptyQueue, getEventTracker, getId, getInputArity, getInputCount, getInputQueue, getInputType, getInputTypesFor, getLeaves, getLeaves, getOutputArity, getOutputCount, getOutputQueue, getOutputType, getPullableInput, getPullableOutput, getPushableInput, getPushableOutput, hashCode, leftShift, newContext, onEndOfTrace, or, or, print, printState, read, readState, rightShift, setContext, setContext, setPullableInput, setPushableOutput, start, startAll, stop, stopAll
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_query

        protected final java.lang.String m_query
        The name of the database table to read from. Actually, this does not need to be a table name, as any SQL expression that returns a table (e.g. a SELECT statement) can do.
      • m_connection

        protected java.sql.Connection m_connection
        The database connection object
      • m_statement

        protected java.sql.Statement m_statement
        The statement object corresponding to the SQL query being executed
      • m_resultSet

        protected java.sql.ResultSet m_resultSet
        The query's result set, out of which tuples will be extracted one by one
      • m_feedOneByOne

        protected boolean m_feedOneByOne
        Whether the tuples of the underlying relation should be output one by one on every call to compute(Object[], Queue), or output all at once on the first call to that method.
      • m_hasRun

        protected boolean m_hasRun
        Remembers whether the query has already been run on the database
    • Constructor Detail

      • JdbcSource

        public JdbcSource​(java.sql.Connection conn,
                          java.lang.String tablename)
        Builds a JDBC source.
        Parameters:
        conn - An open connection on the database
        tablename - The name of the table to be read from. Actually, this does not need to be a table name, as any SQL expression that returns a table (e.g. a SELECT statement) can do.
    • Method Detail

      • setFeedOneByOne

        public void setFeedOneByOne​(boolean b)
        Sets whether the tuples of the underlying relation should be output one by one on every call to compute(Object[], Queue), or output all at once on the first call to that method. While this has no effect on the end result, it might have an impact on the performance (e.g. if the source outputs a very large number of tuples in the output queue, which must be stored in memory).
        Parameters:
        b - Set to true to feed the tuples one by one, false otherwise
      • compute

        protected boolean compute​(java.lang.Object[] inputs,
                                  java.util.Queue<java.lang.Object[]> outputs)
        Specified by:
        compute in class ca.uqac.lif.cep.SynchronousProcessor
      • duplicate

        public JdbcSource duplicate​(boolean with_state)
        Specified by:
        duplicate in interface ca.uqac.lif.cep.Duplicable
        Specified by:
        duplicate in class ca.uqac.lif.cep.Processor
      • reset

        public void reset()
        Overrides:
        reset in class ca.uqac.lif.cep.Processor