Class DBTransaction

    • Field Detail

      • dbtable

        protected String dbtable
      • logThresholdOperation

        static int logThresholdOperation
        Number of pooled operation, by default 1000. This value can be adjusted for a particular server by setting DBLogThresholdOperation specific property.

        This property can be fixed only from java launching command, or through System.property method.

      • dbinsert

        protected String dbinsert
      • dbupdate

        protected String dbupdate
      • dbload

        protected String dbload
      • dbdelete

        protected String dbdelete
      • dbclose

        protected String dbclose
      • commitCount

        private int commitCount
        Number of commit operation since starting up.
      • commitBytes

        private long commitBytes
        Number of bytes written in commit.
      • JDBC_CONNECT_RETRY_COUNT_DFLT

        protected final int JDBC_CONNECT_RETRY_COUNT_DFLT
        See Also:
        Constant Field Values
      • connectRetryCount

        protected int connectRetryCount
      • JDBC_CONNECT_RETRY_MAX_PERIOD_DFLT

        protected final long JDBC_CONNECT_RETRY_MAX_PERIOD_DFLT
        See Also:
        Constant Field Values
      • connectRetryMaxPeriod

        protected long connectRetryMaxPeriod
      • JDBC_CONNECT_RETRY_MIN_DELAY_DFLT

        protected final long JDBC_CONNECT_RETRY_MIN_DELAY_DFLT
        See Also:
        Constant Field Values
      • connectRetryMinDelay

        protected long connectRetryMinDelay
      • nbinserts

        int nbinserts
      • badinserts

        int badinserts
      • nbupdates

        int nbupdates
      • badupdates

        int badupdates
      • nbdeletes

        int nbdeletes
      • nbnoop

        int nbnoop
    • Constructor Detail

      • DBTransaction

        protected DBTransaction()
    • Method Detail

      • getLogThresholdOperation

        public int getLogThresholdOperation()
        Returns the pool size for operation objects, by default 1000.
        Specified by:
        getLogThresholdOperation in interface DBTransactionMBean
        Returns:
        The pool size for operation objects.
      • initDB

        protected abstract void initDB()
                                throws IOException
        Instantiates the database driver and creates the table if necessary
        Throws:
        IOException - an error occurs.
      • getPersistenceDir

        public String getPersistenceDir()
        Returns the path of persistence directory.
        Returns:
        The path of persistence directory.
      • setPhase

        protected final void setPhase​(int newPhase)
        Description copied from class: AbstractTransaction
        Changes the transaction state.
        Specified by:
        setPhase in class AbstractTransaction
        Parameters:
        newPhase - the new transaction state.
      • getCommitBytes

        public final long getCommitBytes()
        Returns the number of bytes written to database since last boot.
        Specified by:
        getCommitBytes in interface DBTransactionMBean
        Returns:
        The number of commit operation.
      • getList

        public final String[] getList​(String prefix)
        Returns an array of strings naming the persistent objects denoted by a name that satisfy the specified prefix. Each string is an object name.
        Specified by:
        getList in interface Transaction
        Parameters:
        prefix - the prefix
        Returns:
        An array of strings naming the persistent objects denoted by a name that satisfy the specified prefix. The array will be empty if no names match.
      • loadAll

        public void loadAll​(String prefix,
                            Map map)
        Fills the map with all objects of the component whose name begins with the prefix.
        Specified by:
        loadAll in interface Transaction
        Overrides:
        loadAll in class AbstractTransaction
        Parameters:
        prefix - The prefix of searched objects.
        map - The map of corresponding objects.
      • saveInLog

        protected final void saveInLog​(byte[] buf,
                                       String dirName,
                                       String name,
                                       Hashtable log,
                                       boolean copy,
                                       boolean first)
                                throws IOException
        Description copied from class: AbstractTransaction
        Register the specified object in transaction log.
        Specified by:
        saveInLog in class AbstractTransaction
        Parameters:
        buf - the byte array containing the state of the object.
        dirName - the directory name of the object.
        name - the name of the object.
        log - the log to use.
        copy - the byte array can be modified, copy it.
        first - the object is a new one.
        Throws:
        IOException - an error occurs.
      • loadByteArray

        public byte[] loadByteArray​(String dirName,
                                    String name)
                             throws IOException
        Description copied from interface: Transaction
        Load the specified byte array.
        Specified by:
        loadByteArray in interface Transaction
        Parameters:
        dirName - the directory name of the object.
        name - the name of the object.
        Returns:
        the loaded byte array.
        Throws:
        IOException - an error occurs.
      • delete

        public void delete​(String dirName,
                           String name)
        Description copied from interface: Transaction
        Deletes the specified object.
        Specified by:
        delete in interface Transaction
        Parameters:
        dirName - the directory name of the object.
        name - the name of the object.
      • connectDB

        protected abstract void connectDB()
                                   throws IOException
        This method try to reconnect to the database, it is used in case of failure during commit. Be careful, unless a connection pool is used, we need to recreate the prepared statement.
        Throws:
        IOException - The reconnection has failed.
      • commit

        public final void commit​(boolean release)
                          throws IOException
        Description copied from interface: Transaction
        Commit the current transaction.
        Specified by:
        commit in interface Transaction
        Parameters:
        release - if true releases the transaction at the end of the commit.
        Throws:
        IOException - an error occurs.
      • dbLogCommit

        private void dbLogCommit​(Hashtable<String,​DBOperation> log)
                          throws SQLException
        Executes all SQL statements corresponding to log operations, and the commit.
        Parameters:
        log - Hashtable containing all operations to commit.
        Throws:
        SQLException - an error occurs.
      • getNbInserts

        public final int getNbInserts()
        Returns the number of inserts in database since last boot.
        Specified by:
        getNbInserts in interface DBTransactionMBean
        Returns:
        The number of inserts in database.
      • getBadInserts

        public final int getBadInserts()
        Returns the number of bad inserts in database since last boot (record already existing).
        Specified by:
        getBadInserts in interface DBTransactionMBean
        Returns:
        The number of bad insert in database.
      • getNbUpdates

        public final int getNbUpdates()
        Returns the number of updates in database since last boot.
        Specified by:
        getNbUpdates in interface DBTransactionMBean
        Returns:
        The number of updates in database.
      • getBadUpdates

        public int getBadUpdates()
        Returns the number of bad updates in database since last boot (record needing to be inserted)..
        Specified by:
        getBadUpdates in interface DBTransactionMBean
        Returns:
        The number of bad updates in database.
      • getNbDeletes

        public final int getNbDeletes()
        Returns the number of deletes in database since last boot.
        Specified by:
        getNbDeletes in interface DBTransactionMBean
        Returns:
        The number of deletes in database.
      • dbLogExecute

        private void dbLogExecute​(Hashtable<String,​DBOperation> log)
                           throws SQLException
        Executes all SQL statements corresponding to log operations.
        Parameters:
        log - Hashtable containing all operations to commit.
        Throws:
        SQLException - an error occurs.
      • stop

        public void stop()
        Stops the transaction module. It waits all transactions termination, then the module is kept in a FREE 'ready to use' state.
        Specified by:
        stop in interface Transaction
      • close

        public void close()
        Close the transaction module. It waits all transactions termination, the module will be initialized anew before reusing it.
        Specified by:
        close in interface Transaction
      • dumpProperties

        protected void dumpProperties​(StringBuilder strbuf)
      • backup

        public String backup​(String path)
                      throws Exception
        Backups the content of Transaction module. Produces a generic Backup/Restore file containing all living objects.
        Specified by:
        backup in interface Transaction
        Specified by:
        backup in interface TransactionMBean
        Parameters:
        path - Directory path to store the backup.
        Returns:
        the name of created backup file.
        Throws:
        Exception - An error occurs during backup.