RDM::DB::transaction< NEXT > Class Template Reference

Template Class for doing transactions. More...

#include "rdm_db_transaction.h"

Public Member Functions

RDM_RETCODE init (RDM_DB db)
Initialize this object. More...
RDM_RETCODE begin (void)
Start a transaction. More...
RDM_RETCODE end (void)
End a transaction. More...
RDM_RETCODE rollback (void)
Roll back a transaction. More...
void reset (void)
Reset this object. More...
RDM_RETCODE flush_value (uint32_t threshold=1, TRANSACTIONAL_T transactional=NOT_TRANSACTIONAL)
Flush this object. More...
RDM_RETCODE flush_stats (uint32_t threshold=1, TRANSACTIONAL_T transactional=NOT_TRANSACTIONAL)
Flush this object. More...
RDM_RETCODE flush_range (uint32_t threshold=1, TRANSACTIONAL_T transactional=NOT_TRANSACTIONAL)
Flush this object. More...
template<class SOURCE_VALUE_T >
RDM_RETCODE put_value (SOURCE_VALUE_T *source_value, TRANSACTIONAL_T transactional=NOT_TRANSACTIONAL)
Template method for receiving a data value. More...
template<class SOURCE_STATS_T >
RDM_RETCODE put_stats (SOURCE_STATS_T *source_stats, TRANSACTIONAL_T transactional=NOT_TRANSACTIONAL)
Template method for receiving statistics. More...
template<class SOURCE_RANGE_T >
RDM_RETCODE put_range (SOURCE_RANGE_T *source_range, TRANSACTIONAL_T transactional=NOT_TRANSACTIONAL)
Template method for receiving ranges. More...

Data Fields

NEXT next

Detailed Description

template<class NEXT>
class RDM::DB::transaction< NEXT >

Template Class for doing transactions.

Template class for doing transactions of data values, ranges, or statistics. What is received by this class will be forwarded to the next class. start() must be called before data can received. Call end() when done. Alternatively, rollback() can be called to roll back the transaction. Rolling back the transaction will also rewind the state of the time series classes back to the state when the transaction was started.

Template Parameters
NEXT The next class in the chain of classes to receive data, ranges, or statistics.
Examples
cpp70Example_main.cpp, and time_series_fft.cpp.

Member Function Documentation

begin()

template<class NEXT >
RDM_RETCODE RDM::DB::transaction< NEXT >::begin ( void )
inline

Start a transaction.

Before doing any put or flush operations, a transaction must be started by calling this method. Call end() or rollback() when done.

For the correct operation, none of the RDM transaction operations, such as rdm_dbStartUpdate(), rdm_dbStartRead(), and rdm_dbEnd(), should be called until end() has been called.

Return values
sOKAY Normal, successful return.
eTRACTIVE Transaction is active.
109 {
110RDM_RETCODE rc;
111
112if (transaction_active)
113 {
114 rc = eTRACTIVE;
115 }
116else
117 {
118if (RDM_LEN (tables_to_write_lock) > 1)
119 {
120 rc = rdm_dbStartUpdate (db, tables_to_write_lock, RDM_LEN (tables_to_write_lock) - 1, tables_to_read_lock, RDM_LEN (tables_to_read_lock) - 1, &trans);
121 }
122else
123 {
124 rc = rdm_dbStartRead (db, tables_to_read_lock, RDM_LEN (tables_to_read_lock) - 1, &trans);
125 }
126if (rc == sOKAY)
127 {
128 transaction_active = true;
129 next_backup_state = next;
130 }
131 }
132
133return rc;
134 }

References eTRACTIVE, RDM::DB::transaction< NEXT >::next, rdm_dbStartRead(), rdm_dbStartUpdate(), RDM_LEN, and sOKAY.

Here is the call graph for this function:

end()

template<class NEXT >
RDM_RETCODE RDM::DB::transaction< NEXT >::end ( void )
inline

End a transaction.

Call this method to end a transaction started with begin(). Any changes made using the put or flush methods will be applied.

Return values
sOKAY Normal, successful return.
eTRNOTACT Transaction not active.
146 {
147RDM_RETCODE rc;
148
149if (transaction_active)
150 {
151 rc = rdm_transEnd (trans);
152if (rc == sOKAY)
153 {
154 transaction_active = false;
155 }
156 }
157else
158 {
159 rc = eTRNOTACT;
160 }
161
162return rc;
163 }

References eTRNOTACT, rdm_transEnd(), and sOKAY.

Here is the call graph for this function:

flush_range()

template<class NEXT >
RDM_RETCODE RDM::DB::transaction< NEXT >::flush_range ( uint32_t threshold = 1,
TRANSACTIONAL_T transactional = NOT_TRANSACTIONAL
)
inline

Flush this object.

Call this method to flush what has been collected so far. A threshold can also be provided. All the data collected for those ranges will be kept as is. The same is the case when the threshold has not been reached.

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
threshold [IN] Only flush objects where at least this many elements have been collected
transactional [IN] Is the flush required to be transactional
304 {
305RDM_RETCODE rc = next.flush_range (threshold, transactional);
306
307return rc;
308 }

References RDM::DB::transaction< NEXT >::next.

flush_stats()

template<class NEXT >
RDM_RETCODE RDM::DB::transaction< NEXT >::flush_stats ( uint32_t threshold = 1,
TRANSACTIONAL_T transactional = NOT_TRANSACTIONAL
)
inline

Flush this object.

Call this method to flush what has been collected so far. A threshold can also be provided. All the data collected for those statistics will be kept as is. The same is the case when the threshold has not been reached.

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
threshold [IN] Only flush objects where at least this many elements have been collected
transactional [IN] Is the flush required to be transactional
269 {
270RDM_RETCODE rc = next.flush_stats (threshold, transactional);
271
272return rc;
273 }

References RDM::DB::transaction< NEXT >::next.

flush_value()

template<class NEXT >
RDM_RETCODE RDM::DB::transaction< NEXT >::flush_value ( uint32_t threshold = 1,
TRANSACTIONAL_T transactional = NOT_TRANSACTIONAL
)
inline

Flush this object.

Call this method to flush what has been collected so far. A threshold can also be provided. All the data collected for those values will be kept as is. The same is the case when the threshold has not been reached.

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
threshold [IN] Only flush objects where at least this many elements have been collected
transactional [IN] Is the flush required to be transactional
234 {
235RDM_RETCODE rc = next.flush_value (threshold, transactional);
236
237return rc;
238 }

References RDM::DB::transaction< NEXT >::next.

init()

template<class NEXT >
RDM_RETCODE RDM::DB::transaction< NEXT >::init ( RDM_DB db )
inline

Initialize this object.

Call this method before sending it any data values, ranges, or statistics.

Return values
sOKAY Normal, successful return.
eINVARG Invalid argument.
eDBNOTOPEN Database not open.
eCURSORDB Cursor is associated with a different database.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
Parameters
db [IN] Use this database for chained classes that need to insert rows
79 {
80RDM_RETCODE rc = next.init (db);
81
82if (rc == sOKAY)
83 {
84 transaction::db = db;
85 transaction_active = false;
86 }
87
88 (void) next.init_tables_to_read_lock (tables_to_read_lock);
89 (void) next.init_tables_to_write_lock (tables_to_write_lock);
90
91return rc;
92 }

References RDM::DB::transaction< NEXT >::next, and sOKAY.

put_range()

template<class NEXT >
template<class SOURCE_RANGE_T >
RDM_RETCODE RDM::DB::transaction< NEXT >::put_range ( SOURCE_RANGE_T * source_range,
TRANSACTIONAL_T transactional = NOT_TRANSACTIONAL
)
inline

Template method for receiving ranges.

Receive one range and process it accordingly.

The type for the value provided is required to have columns for 'time_stamp_first', 'time_stamp_last', and 'value_range' with appropriate types. The column 'value_range' must be an array that is able to hold a static number of elements. Such a type can be generated using rdm-compile with a schema including a table similar to this:

CREATE TABLE range
(
value_range DOUBLE ARRAY [32] NOT NULL,
time_stamp_first UINT64 NOT NULL,
time_stamp_last UINT64 PRIMARY KEY
);

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Template Parameters
SOURCE_RANGE_T The actual type of the range received.
Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
[in] source_range The source range sent to this class
transactional [IN] Is the put required to be transactional
454 {
455RDM_RETCODE rc = next.put_range (source_range, transactional);
456
457return rc;
458 }

References RDM::DB::transaction< NEXT >::next.

put_stats()

template<class NEXT >
template<class SOURCE_STATS_T >
RDM_RETCODE RDM::DB::transaction< NEXT >::put_stats ( SOURCE_STATS_T * source_stats,
TRANSACTIONAL_T transactional = NOT_TRANSACTIONAL
)
inline

Template method for receiving statistics.

Receive one statistic and process it accordingly.

The type for the value provided is required to have columns for 'time_stamp_first', 'time_stamp_last', 'n', 'value_sum', and 'value_sum2' with appropriate types. Such a type can be generated using rdm-compile with a schema including a table similar to this:

CREATE TABLE stats
(
time_stamp_first UINT64 NOT NULL,
time_stamp_last UINT64 PRIMARY KEY,
n UINT64 NOT NULL,
value_sum DOUBLE NOT NULL,
value_sum2 DOUBLE NOT NULL
);

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Template Parameters
SOURCE_STAT_T The actual type of the statistic received.
Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
[in] source_stats The source statistics sent to this class
transactional [IN] Is the put required to be transactional
403 {
404RDM_RETCODE rc = next.put_stats (source_stats, transactional);
405
406return rc;
407 }

References RDM::DB::transaction< NEXT >::next.

put_value()

template<class NEXT >
template<class SOURCE_VALUE_T >
RDM_RETCODE RDM::DB::transaction< NEXT >::put_value ( SOURCE_VALUE_T * source_value,
TRANSACTIONAL_T transactional = NOT_TRANSACTIONAL
)
inline

Template method for receiving a data value.

Receive one data value and process it accordingly.

The type for the value provided is required to have columns for 'time_stamp_current' and 'value_current' with appropriate types. Such a type can be generated using rdm-compile with a schema including a table similar to this:

CREATE TABLE measurement
(
time_stamp_current UINT64 PRIMARY KEY,
value_current DOUBLE NOT NULL
);

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Template Parameters
SOURCE_VALUE_T The actual type of the source values received
Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
[in] source_value The source value sent to this class
transactional [IN] Is the put required to be transactional
352 {
353RDM_RETCODE rc = next.put_value (source_value, transactional);
354
355return rc;
356 }

References RDM::DB::transaction< NEXT >::next.

reset()

template<class NEXT >
void RDM::DB::transaction< NEXT >::reset ( void )
inline

Reset this object.

Call this method to discard all internally kept data values, ranges, and statistics that have not yet been persisted and start over from scratch.

202 {
203next.reset ();
204 }

References RDM::DB::transaction< NEXT >::next.

rollback()

template<class NEXT >
RDM_RETCODE RDM::DB::transaction< NEXT >::rollback ( void )
inline

Roll back a transaction.

Call this method to roll back a transaction started with begin(). Any changes made using the put or flush methods will be rolled back.

Return values
sOKAY Normal, successful return.
eTRNOTACT Transaction not active.
175 {
176RDM_RETCODE rc;
177
178if (transaction_active)
179 {
180 rc = rdm_transEndRollback (trans);
181if (rc == sOKAY)
182 {
183 transaction_active = false;
184next = next_backup_state;
185 }
186 }
187else
188 {
189 rc = eTRNOTACT;
190 }
191
192return rc;
193 }

References eTRNOTACT, RDM::DB::transaction< NEXT >::next, rdm_transEndRollback(), and sOKAY.

Here is the call graph for this function:

Field Documentation

next


The documentation for this class was generated from the following file:
RDM_RETCODE rdm_transEnd(RDM_TRANS trans)
End a transactional operation.
@ eTRACTIVE
Definition: rdmretcodetypes.h:109
@ eTRNOTACT
Definition: rdmretcodetypes.h:110
RDM_RETCODE rdm_transEndRollback(RDM_TRANS trans)
End a transactional operation with a rollback.
RDM_RETCODE rdm_dbStartRead(RDM_DB db, const RDM_TABLE_ID *tableIds, uint32_t numTableIds, RDM_TRANS *pTrans)
Get read locks.
@ sOKAY
Definition: rdmretcodetypes.h:97
NEXT next
Definition: rdm_db_transaction.h:64
RDM_RETCODE rdm_dbStartUpdate(RDM_DB db, const RDM_TABLE_ID *writeTableIds, uint32_t numWriteTableIds, const RDM_TABLE_ID *readTableIds, uint32_t numReadTableIds, RDM_TRANS *pTrans)
Get write locks.
#define RDM_LEN(x)
Definition: psptypes.h:78
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:43