Class AbstractSqlDialect

    • Field Detail

      • multiEngineMode

        protected boolean multiEngineMode
        if multiple engines could be running together, you MUST turn it on
      • supportsMultipleEngines

        protected final boolean supportsMultipleEngines
      • supportsClob

        protected final boolean supportsClob
      • defaultStaleResponseRemovalTimeout

        protected long defaultStaleResponseRemovalTimeout
      • ACQUIRE_BLOCKING_WAIT_SEC

        protected final int ACQUIRE_BLOCKING_WAIT_SEC
        See Also:
        Constant Field Values
      • dbBatchingLatencyMSec

        protected int dbBatchingLatencyMSec
      • queryUpdateQueueState

        protected java.lang.String queryUpdateQueueState
      • selectQueueSizeStmtStatistic

        protected StmtStatistic selectQueueSizeStmtStatistic
    • Constructor Detail

      • AbstractSqlDialect

        public AbstractSqlDialect()
      • AbstractSqlDialect

        @Deprecated
        public AbstractSqlDialect​(boolean supportsMultipleEngines,
                                  boolean defaultMultiEngineMode)
        Deprecated.
      • AbstractSqlDialect

        public AbstractSqlDialect​(boolean supportsMultipleEngines,
                                  boolean defaultMultiEngineMode,
                                  boolean supportsClob)
    • Method Detail

      • setEngineId

        public void setEngineId​(java.lang.String engineId)
      • setEngineIdProvider

        public void setEngineIdProvider​(EngineIdProvider engineIdProvider)
      • setDbBatchingLatencyMSec

        public void setDbBatchingLatencyMSec​(int dbBatchingLatencyMSec)
        Specified by:
        setDbBatchingLatencyMSec in interface org.copperengine.management.DatabaseDialectMXBean
      • getDbBatchingLatencyMSec

        public int getDbBatchingLatencyMSec()
        Specified by:
        getDbBatchingLatencyMSec in interface org.copperengine.management.DatabaseDialectMXBean
      • setDefaultStaleResponseRemovalTimeout

        public void setDefaultStaleResponseRemovalTimeout​(long defaultStaleResponseRemovalTimeout)
        Sets the default removal timeout for stale responses in the underlying database. A response is stale/timed out when there is no workflow instance waiting for it within the specified amount of time.
        Specified by:
        setDefaultStaleResponseRemovalTimeout in interface org.copperengine.management.DatabaseDialectMXBean
        Parameters:
        defaultStaleResponseRemovalTimeout - removal timeout
      • getDefaultStaleResponseRemovalTimeout

        public long getDefaultStaleResponseRemovalTimeout()
        Specified by:
        getDefaultStaleResponseRemovalTimeout in interface org.copperengine.management.DatabaseDialectMXBean
      • setSerializer

        public void setSerializer​(Serializer serializer)
      • setRuntimeStatisticsCollector

        public void setRuntimeStatisticsCollector​(RuntimeStatisticsCollector runtimeStatisticsCollector)
      • computeLockId

        protected static int computeLockId​(java.lang.String s)
        Parameters:
        s - a given lock id string from which a integer id shall be generated (Using s.hashCode())
        Returns:
        an int value between 0 and 1073741823 (exclusive)
      • getResourceAsString

        protected java.lang.String getResourceAsString​(java.lang.String name)
      • getResourceAsString

        protected static java.lang.String getResourceAsString​(java.lang.Class<?> baseClass,
                                                              java.lang.String name)
      • setRemoveWhenFinished

        public void setRemoveWhenFinished​(boolean removeWhenFinished)
        Specified by:
        setRemoveWhenFinished in interface DatabaseDialect
        Specified by:
        setRemoveWhenFinished in interface org.copperengine.management.DatabaseDialectMXBean
        Parameters:
        removeWhenFinished - If true (default), finished workflow instances are removed from the database.
      • isRemoveWhenFinished

        public boolean isRemoveWhenFinished()
        Specified by:
        isRemoveWhenFinished in interface org.copperengine.management.DatabaseDialectMXBean
      • resumeBrokenBusinessProcesses

        public void resumeBrokenBusinessProcesses​(java.sql.Connection con)
                                           throws java.lang.Exception
        Specified by:
        resumeBrokenBusinessProcesses in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • dequeue

        public java.util.List<Workflow<?>> dequeue​(java.lang.String ppoolId,
                                                   int max,
                                                   java.sql.Connection con)
                                            throws java.lang.Exception
        Specified by:
        dequeue in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • updateQueueState

        public int updateQueueState​(int max,
                                    java.sql.Connection con)
                             throws java.sql.SQLException
        Specified by:
        updateQueueState in interface DatabaseDialect
        Throws:
        java.sql.SQLException
      • deleteStaleResponse

        public int deleteStaleResponse​(java.sql.Connection con,
                                       int maxRows)
                                throws java.lang.Exception
        Specified by:
        deleteStaleResponse in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • lock

        protected void lock​(java.sql.Connection con,
                            java.lang.String lockContext)
                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • releaseLock

        protected void releaseLock​(java.sql.Connection con,
                                   java.lang.String lockContext)
      • doLock

        protected void doLock​(java.sql.Connection con,
                              java.lang.String lockContext)
                       throws java.sql.SQLException
        Locks on the lockContext, implement this to provide multiple engine support It will block wait until the lock was successfully hold, must be used together with releaseLock(java.sql.Connection, java.lang.String)
        Parameters:
        con - connection object on which the lock will be acquired on
        lockContext - String for the lock name (Will be transformed to an int by computeLockId(String).
        Throws:
        java.sql.SQLException - If anything goes wrong in acquiring the lock on the database
      • doReleaseLock

        protected void doReleaseLock​(java.sql.Connection con,
                                     java.lang.String lockContext)
        Releases the lock on the lockContext, use together with lock(Connection, String)
        Parameters:
        con - connection object on which the lock will be released on
        lockContext - String for the lock name
      • restart

        public void restart​(java.lang.String workflowInstanceId,
                            java.sql.Connection c)
                     throws java.lang.Exception
        Specified by:
        restart in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • restartFiltered

        public void restartFiltered​(org.copperengine.management.model.WorkflowInstanceFilter filter,
                                    java.sql.Connection con)
                             throws java.lang.Exception
        Specified by:
        restartFiltered in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • deleteBroken

        public void deleteBroken​(java.lang.String workflowInstanceId,
                                 java.sql.Connection c)
                          throws java.lang.Exception
        Specified by:
        deleteBroken in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • deleteWaiting

        public void deleteWaiting​(java.lang.String workflowInstanceId,
                                  java.sql.Connection c)
                           throws java.lang.Exception
        Specified by:
        deleteWaiting in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • restartAll

        public void restartAll​(java.sql.Connection c)
                        throws java.lang.Exception
        Specified by:
        restartAll in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • deleteFiltered

        public void deleteFiltered​(org.copperengine.management.model.WorkflowInstanceFilter filter,
                                   java.sql.Connection con)
                            throws java.lang.Exception
        Specified by:
        deleteFiltered in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • notify

        public void notify​(java.util.List<Response<?>> responses,
                           java.sql.Connection c)
                    throws java.lang.Exception
        Specified by:
        notify in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • createBatchCommand4NotifyNoEarlyResponseHandling

        public abstract BatchCommand createBatchCommand4NotifyNoEarlyResponseHandling​(Response<?> response,
                                                                                      Acknowledge ack)
                                                                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • insert

        public void insert​(Workflow<?> wf,
                           java.sql.Connection con)
                    throws java.lang.Exception
        Specified by:
        insert in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • splitt

        protected java.util.List<java.util.List<java.lang.String>> splitt​(java.util.Collection<java.lang.String> keySet,
                                                                          int n)
      • createUpdateStateStmt

        protected abstract java.sql.PreparedStatement createUpdateStateStmt​(java.sql.Connection c,
                                                                            int max)
                                                                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • createDequeueStmt

        protected abstract java.sql.PreparedStatement createDequeueStmt​(java.sql.Connection c,
                                                                        java.lang.String ppoolId,
                                                                        int max)
                                                                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • createDeleteStaleResponsesStmt

        protected abstract java.sql.PreparedStatement createDeleteStaleResponsesStmt​(java.sql.Connection c,
                                                                                     int MAX_ROWS)
                                                                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • checkDbConsistency

        public java.util.List<java.lang.String> checkDbConsistency​(java.sql.Connection con)
                                                            throws java.lang.Exception
        Description copied from interface: DatabaseDialect
        Checks the DB consistency, e.g. at system startup, by deserialising all workflow instances in the underlying database.
        Specified by:
        checkDbConsistency in interface DatabaseDialect
        Parameters:
        con - database connection
        Returns:
        list of ids of bad workflows which could not be deserialized
        Throws:
        java.lang.Exception - For any SQL error like losing connection or such.
      • setWorkflowPersistencePlugin

        public void setWorkflowPersistencePlugin​(WorkflowPersistencePlugin workflowPersistencePlugin)
      • read

        public Workflow<?> read​(java.lang.String workflowInstanceId,
                                java.sql.Connection con)
                         throws java.lang.Exception
        Specified by:
        read in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • createReadStmt

        protected java.sql.PreparedStatement createReadStmt​(java.sql.Connection c,
                                                            java.lang.String workflowId)
                                                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • createQueryAllActiveStmt

        protected abstract java.sql.PreparedStatement createQueryAllActiveStmt​(java.sql.Connection c,
                                                                               java.lang.String className,
                                                                               int max)
                                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • queryAllActive

        public java.util.List<Workflow<?>> queryAllActive​(java.lang.String className,
                                                          java.sql.Connection c,
                                                          int max)
                                                   throws java.sql.SQLException
        Description copied from interface: DatabaseDialect
        Query workflows that were active at the moment in (ENQUEUE, RUNNING or WAITING) state
        Specified by:
        queryAllActive in interface DatabaseDialect
        Parameters:
        className - - optional, specify which className it want to return. May be null. (No filtering for class name done in this case) If specified, the className must fully match the class name, so no regexp or similar is allowed. className must be given as fully qualified name (i.e. with package names prepending). Example is org.copperengine.examples.workflows.MyWorkflow
        c - - database connection
        max - maximum number to be queried (Translates to LIMIT max or FETCH ,max or similar on SQL queries SELECT)
        Returns:
        List of active workflows.
        Throws:
        java.sql.SQLException - If anything goes wrong regarding SQL.
      • setMultiEngineMode

        public void setMultiEngineMode​(boolean multiEngineMode)
      • readDatabaseClock

        public java.util.Date readDatabaseClock​(java.sql.Connection con)
                                         throws java.sql.SQLException
        Description copied from interface: DatabaseDialect
        Read the current system time from the underlying database system
        Specified by:
        readDatabaseClock in interface DatabaseDialect
        Parameters:
        con - database connection
        Returns:
        Current database clock time
        Throws:
        java.sql.SQLException - Any sql error happening in here.
      • queryQueueSize

        public int queryQueueSize​(java.lang.String processorPoolId,
                                  int max,
                                  java.sql.Connection con)
                           throws java.sql.SQLException
        Specified by:
        queryQueueSize in interface DatabaseDialect
        Throws:
        java.sql.SQLException
      • queryObjectState

        public java.lang.String queryObjectState​(java.lang.String id,
                                                 java.sql.Connection con)
                                          throws java.lang.Exception
        Specified by:
        queryObjectState in interface DatabaseDialect
        Throws:
        java.lang.Exception
      • queryWorkflowInstances

        public java.util.List<Workflow<?>> queryWorkflowInstances​(org.copperengine.management.model.WorkflowInstanceFilter filter,
                                                                  java.sql.Connection con)
                                                           throws java.sql.SQLException
        Specified by:
        queryWorkflowInstances in interface DatabaseDialect
        Throws:
        java.sql.SQLException
      • countWorkflowInstances

        public int countWorkflowInstances​(org.copperengine.management.model.WorkflowInstanceFilter filter,
                                          java.sql.Connection con)
                                   throws java.sql.SQLException
        Specified by:
        countWorkflowInstances in interface DatabaseDialect
        Throws:
        java.sql.SQLException
      • queryAuditTrailInstances

        public java.util.List<org.copperengine.management.model.AuditTrailInfo> queryAuditTrailInstances​(org.copperengine.management.model.AuditTrailInstanceFilter filter,
                                                                                                         java.sql.Connection con)
                                                                                                  throws java.sql.SQLException
        Specified by:
        queryAuditTrailInstances in interface DatabaseDialect
        Throws:
        java.sql.SQLException
      • countAuditTrailInstances

        public int countAuditTrailInstances​(org.copperengine.management.model.AuditTrailInstanceFilter filter,
                                            java.sql.Connection con)
                                     throws java.sql.SQLException
        Specified by:
        countAuditTrailInstances in interface DatabaseDialect
        Throws:
        java.sql.SQLException
      • queryAuditTrailMessage

        public java.lang.String queryAuditTrailMessage​(long id,
                                                       java.sql.Connection con)
                                                throws java.sql.SQLException
        Specified by:
        queryAuditTrailMessage in interface DatabaseDialect
        Throws:
        java.sql.SQLException
      • decode

        protected PersistentWorkflow<?> decode​(java.sql.ResultSet rs)
                                        throws java.sql.SQLException,
                                               java.lang.Exception
        Throws:
        java.sql.SQLException
        java.lang.Exception
      • addLimitation

        protected abstract void addLimitation​(java.lang.StringBuilder sql,
                                              int max)
      • addLimitationAndOffset

        protected abstract void addLimitationAndOffset​(java.lang.StringBuilder sql,
                                                       int max,
                                                       int offset)
      • isBlank

        protected boolean isBlank​(java.lang.String str)