rm_JobIdGen Class Reference
[Resource Manager Database Library]

#include <rmdb.h>

List of all members.


Detailed Description

JobID Generator Generates a new Job ID on request.

The Job ID consists of YYYYMMDD and a 6 digit decimal counter

Author:
Toni Pljakoski, HERMES SoftLab
See also:
<reference>

Definition at line 601 of file rmdb.h.


Public Member Functions

 rm_JobIdGen ()
 Default constructor.
virtual ~rm_JobIdGen ()

Private Member Functions

void Init ()
UInt64_t CheckInDB ()
void UpdateInDB (UInt64_t)
UInt64_t GenerateNew ()

Private Attributes

UInt64_t m_lastId
 log_CLASSID_m

Friends

class dbo_NewJobIdGen
class dbo_InitJobIdGen

Constructor & Destructor Documentation

rm_JobIdGen::rm_JobIdGen (  ) 

Default constructor.

Definition at line 37 of file rm_jobidgen.cpp.

References log_FUNC_m.

00037                         {
00038     log_FUNC_m(rm_JobIdGen);
00039     /*empty*/
00040 }

rm_JobIdGen::~rm_JobIdGen (  )  [virtual]

Definition at line 42 of file rm_jobidgen.cpp.

References log_FUNC_m.

00042                          {
00043     log_FUNC_m(~rm_JobIdGen);
00044 
00045 }


Member Function Documentation

void rm_JobIdGen::Init (  )  [private]

Definition at line 47 of file rm_jobidgen.cpp.

References CheckInDB(), cmn_IntPow(), dbg_DETAIL, localtime(), log_DBG_m, log_FUNC_m, m_lastId, and UpdateInDB().

Referenced by dbo_InitJobIdGen::Process().

00047                       {
00048 
00049     log_FUNC_m(Init);
00050     cmn_MutexLock l(g_jobIdGen_x);
00051     //\todo check if we are in same date
00052     //\todo if not read last id from rmdb
00053 
00054     UInt64_t lastDBId = CheckInDB();
00055     log_DBG_m(dbg_DETAIL,"Found last Job Id:" << lastDBId);
00056     
00057 
00058     //else
00059 
00060     time_t tTime;
00061     time(&tTime); 
00062     struct tm * tm_time;
00063     tm_time = localtime(&tTime);
00064    
00065     log_DBG_m(dbg_DETAIL, " Creating new job id");
00066     // upper 32 bits
00067     log_DBG_m(dbg_DETAIL, "tm_time->tm_year" << tm_time->tm_year  );
00068     log_DBG_m(dbg_DETAIL, "tm_time->tm_mon" <<  tm_time->tm_mon );
00069     log_DBG_m(dbg_DETAIL, "tm_time->tm_mday" << tm_time->tm_mday  );
00070 
00071     m_lastId =  (UInt64_t)(1900 + tm_time-> tm_year)    * cmn_IntPow(UInt64_t(10), 10) +
00072                 (UInt64_t)(1 + tm_time->tm_mon)         * cmn_IntPow(UInt64_t(10), 8) +
00073                 (UInt64_t)(tm_time->tm_mday)            * cmn_IntPow(UInt64_t(10), 6);
00074     
00075     
00076     if (m_lastId < lastDBId) {
00077         m_lastId = lastDBId;
00078         UpdateInDB(m_lastId);
00079     }
00080 
00081 }

Here is the call graph for this function:

Here is the caller graph for this function:

UInt64_t rm_JobIdGen::CheckInDB (  )  [private]

Definition at line 4930 of file librmdb.exx.

References errorDesc(), id, log_FUNC_m, NAME, SQL_CHECK_M, and SQL_NOTFOUND.

Referenced by Init().

04930                                {
04931     log_FUNC_m(CheckInDB);
04932 
04933     UInt32_t id(0);
04934     UInt32_t date(0) ;
04935     UInt32_t count(0);
04936 
04937     EXEC SQL
04938         SET TRANSACTION NAME readWriteTrans;
04939 
04940     EXEC SQL
04941         SELECT TRANSACTION readWriteTrans
04942         * INTO
04943             :id,
04944             :date,
04945             :count
04946         FROM JOBID WHERE id = 1;
04947 
04948     if ((SQLCODE == SQL_NOTFOUND) || (id != 1)) {
04949         EXEC SQL
04950             INSERT TRANSACTION readWriteTrans
04951             INTO JOBID VALUES(1,0,0);
04952 
04953         string sqlErrDesc = errorDesc(SQLCODE,"Insert Job Id record");
04954         SQL_CHECK_M( sqlErrDesc );
04955         return 0;
04956     }
04957     else {
04958         string sqlErrDesc = errorDesc(SQLCODE, "Insert Job Id record");
04959         SQL_CHECK_M( sqlErrDesc );
04960     }
04961     return( (UInt64_t)(date) * (UInt64_t)pow(10.0, 6) + count );
04962 }

Here is the call graph for this function:

Here is the caller graph for this function:

void rm_JobIdGen::UpdateInDB ( UInt64_t  a_jobId  )  [private]

Definition at line 4965 of file librmdb.exx.

References errorDesc(), log_FUNC_m, NAME, and SQL_CHECK_M.

Referenced by GenerateNew(), and Init().

04965                                             {
04966     log_FUNC_m(UpdateInDB);
04967 
04968     EXEC SQL
04969         SET TRANSACTION NAME readWriteTrans;
04970 
04971     UInt32_t date = static_cast<UInt32_t>( a_jobId / 1000000);
04972     UInt32_t count = static_cast<UInt32_t>(a_jobId - ((UInt64_t)date * 1000000));
04973 
04974     EXEC SQL
04975         UPDATE TRANSACTION readWriteTrans
04976         JOBID SET
04977             id = 1,
04978             jobdate = :date,
04979             jobcount = :count
04980         WHERE id = 1;
04981 
04982     string sqlErrDesc = errorDesc(SQLCODE,"Update Job Id record");
04983     SQL_CHECK_M( sqlErrDesc );
04984 
04985 }

Here is the call graph for this function:

Here is the caller graph for this function:

UInt64_t rm_JobIdGen::GenerateNew (  )  [private]

Definition at line 83 of file rm_jobidgen.cpp.

References cmn_IntPow(), dbg_DETAIL, localtime(), log_DBG_m, log_FUNC_m, m_lastId, and UpdateInDB().

Referenced by dbo_NewJobIdGen::Process().

00083                                  {
00084     log_FUNC_m(GenerateNew);
00085     cmn_MutexLock l(g_jobIdGen_x);
00086     time_t tTime;
00087     time(&tTime); 
00088     struct tm * tm_time;
00089     tm_time = localtime(&tTime);
00090 
00091     UInt64_t lastDay =  
00092                 (UInt64_t)(1900 + tm_time-> tm_year)    * cmn_IntPow(UInt64_t(10), 10) +
00093                 (UInt64_t)(1 + tm_time->tm_mon)         * cmn_IntPow(UInt64_t(10), 8) +
00094                 (UInt64_t)(tm_time->tm_mday)            * cmn_IntPow(UInt64_t(10), 6);
00095     
00096     if (m_lastId >= lastDay ) {
00097         m_lastId++;
00098     } else {
00099         m_lastId = ++lastDay;
00100     }
00101     log_DBG_m(dbg_DETAIL, "generated new id " << m_lastId);
00102     UpdateInDB(m_lastId);
00103     return m_lastId;
00104 }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class dbo_NewJobIdGen [friend]

Definition at line 603 of file rmdb.h.

friend class dbo_InitJobIdGen [friend]

Definition at line 604 of file rmdb.h.


Member Data Documentation

Definition at line 613 of file rmdb.h.

Referenced by GenerateNew(), and Init().

Definition at line 617 of file rmdb.h.


The documentation for this class was generated from the following files:

Generated on Mon Feb 27 19:46:42 2012 for OPENARCHIVE by  doxygen 1.5.6