Public Member Functions | Private Member Functions | Private Attributes | Friends

rm_JobIdGen Class Reference
[Resource Manager Database Library]

JobID Generator Generates a new Job ID on request. More...

#include <rmdb.h>

List of all members.

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

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 615 of file rmdb.h.


Constructor & Destructor Documentation

rm_JobIdGen::rm_JobIdGen (  ) 

Default constructor.

Definition at line 51 of file rm_jobidgen.cpp.

References log_FUNC_m.

                        {
    log_FUNC_m(rm_JobIdGen);
    /*empty*/
}

rm_JobIdGen::~rm_JobIdGen (  )  [virtual]

Definition at line 56 of file rm_jobidgen.cpp.

References log_FUNC_m.


Member Function Documentation

UInt64_t rm_JobIdGen::CheckInDB (  )  [private]

Definition at line 4962 of file librmdb.exx.

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

Referenced by Init().

                               {
    log_FUNC_m(CheckInDB);

    UInt32_t id(0);
    UInt32_t date(0) ;
    UInt32_t count(0);

    EXEC SQL
        SET TRANSACTION NAME readWriteTrans;

    EXEC SQL
        SELECT TRANSACTION readWriteTrans
        * INTO
            :id,
            :date,
            :count
        FROM JOBID WHERE id = 1;

    if ((SQLCODE == SQL_NOTFOUND) || (id != 1)) {
        EXEC SQL
            INSERT TRANSACTION readWriteTrans
            INTO JOBID VALUES(1,0,0);

        string sqlErrDesc = errorDesc(SQLCODE,"Insert Job Id record");
        SQL_CHECK_M( sqlErrDesc );
        return 0;
    }
    else {
        string sqlErrDesc = errorDesc(SQLCODE, "Insert Job Id record");
        SQL_CHECK_M( sqlErrDesc );
    }
    return( (UInt64_t)(date) * (UInt64_t)pow(10.0, 6) + count );
}

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 97 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().

                                 {
    log_FUNC_m(GenerateNew);
    cmn_MutexLock l(g_jobIdGen_x);
    time_t tTime;
    time(&tTime); 
    struct tm * tm_time;
    tm_time = localtime(&tTime);

    UInt64_t lastDay =  
                (UInt64_t)(1900 + tm_time-> tm_year)    * cmn_IntPow(UInt64_t(10), 10) +
                (UInt64_t)(1 + tm_time->tm_mon)         * cmn_IntPow(UInt64_t(10), 8) +
                (UInt64_t)(tm_time->tm_mday)            * cmn_IntPow(UInt64_t(10), 6);
    
    if (m_lastId >= lastDay ) {
        m_lastId++;
    } else {
        m_lastId = ++lastDay;
    }
    log_DBG_m(dbg_DETAIL, "generated new id " << m_lastId);
    UpdateInDB(m_lastId);
    return m_lastId;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rm_JobIdGen::Init (  )  [private]

Definition at line 61 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().

                      {

    log_FUNC_m(Init);
    cmn_MutexLock l(g_jobIdGen_x);
    //\todo check if we are in same date
    //\todo if not read last id from rmdb

    UInt64_t lastDBId = CheckInDB();
    log_DBG_m(dbg_DETAIL,"Found last Job Id:" << lastDBId);
    

    //else

    time_t tTime;
    time(&tTime); 
    struct tm * tm_time;
    tm_time = localtime(&tTime);
   
    log_DBG_m(dbg_DETAIL, " Creating new job id");
    // upper 32 bits
    log_DBG_m(dbg_DETAIL, "tm_time->tm_year" << tm_time->tm_year  );
    log_DBG_m(dbg_DETAIL, "tm_time->tm_mon" <<  tm_time->tm_mon );
    log_DBG_m(dbg_DETAIL, "tm_time->tm_mday" << tm_time->tm_mday  );

    m_lastId =  (UInt64_t)(1900 + tm_time-> tm_year)    * cmn_IntPow(UInt64_t(10), 10) +
                (UInt64_t)(1 + tm_time->tm_mon)         * cmn_IntPow(UInt64_t(10), 8) +
                (UInt64_t)(tm_time->tm_mday)            * cmn_IntPow(UInt64_t(10), 6);
    
    
    if (m_lastId < lastDBId) {
        m_lastId = lastDBId;
        UpdateInDB(m_lastId);
    }

}

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 4997 of file librmdb.exx.

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

Referenced by GenerateNew(), and Init().

                                            {
    log_FUNC_m(UpdateInDB);

    EXEC SQL
        SET TRANSACTION NAME readWriteTrans;

    UInt32_t date = static_cast<UInt32_t>( a_jobId / 1000000);
    UInt32_t count = static_cast<UInt32_t>(a_jobId - ((UInt64_t)date * 1000000));

    EXEC SQL
        UPDATE TRANSACTION readWriteTrans
        JOBID SET
            id = 1,
            jobdate = :date,
            jobcount = :count
        WHERE id = 1;

    string sqlErrDesc = errorDesc(SQLCODE,"Update Job Id record");
    SQL_CHECK_M( sqlErrDesc );

}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class dbo_InitJobIdGen [friend]

Definition at line 618 of file rmdb.h.

friend class dbo_NewJobIdGen [friend]

Definition at line 617 of file rmdb.h.


Member Data Documentation

Definition at line 631 of file rmdb.h.

Definition at line 627 of file rmdb.h.

Referenced by GenerateNew(), and Init().


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