Replace the datum identified by the supplied id (arg1), with the contents of the supplied hzChain (arg2). In all cases this action is a DEPRECATE of the existing datum, and an INSERT of the new.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbBinRepos::Update | (uint32_t&,hzChain&,) |
Declared in file: hzDatabase.h
Defined in file : hdbBinRepos.cpp
Function Logic:
Function body:
hzEcode hdbBinRepos::Update (uint32_t& datumId)hzChain& datum,
{
// Replace the datum identified by the supplied id (arg1), with the contents of the supplied hzChain (arg2). In all cases this action is a DEPRECATE of the existing datum, and
// an INSERT of the new.
//
// Arguments: 1) datumId Datum ID - Set in the call to the original datum, set by this function to the new datum id
// 2) datum The datum
//
// Returns: E_NOINIT The datacron is not initialized
// E_NOTOPEN Attempt to modify object zero
// E_NOTFOUND Attempt to modify non existant object
// E_WRITEFAIL The datacron is not open for writing
// E_RANGE The requested item does not exist
// E_OK The operation was successful
_hzfunc("hdbBinRepos::Update") ;
_datum_hd hdr ; // Datum header
hzEcode rc = E_OK ; // Return code
// Repos not initialized?
if (m_nInitState < 1)
return E_NOINIT ;
// Repos not open?
if (m_nInitState < 2)
return E_NOTOPEN ;
// No datum id supplied?
if (datumId == 0)
return E_NOTOPEN ;
// Datum id out of range
if (datumId > m_nSeqId)
return E_NOTFOUND ;
// Empty datum?
if (!datum.Size())
return E_NODATA ;
hdr.m_XDate.SysDateTime() ;
hdr.m_Size = datum.Size() ;
hdr.m_Prev = datumId ;
// rem = ((16 - datum.Size()) % 16) % 16 ;
// tot = datum.Size() + rem ;
// Write to the index
m_LockIwr.Lock() ;
hdr.m_Addr = m_nSize ;
datumId = ++m_nSeqId ;
m_nSize += datum.Size() ;
m_WrI.write((char*) &hdr, sizeof(_datum_hd)) ;
// Internal write error?
if (m_WrI.fail())
{ threadLog("Could not update index delta for datum %d\n", datumId) ; rc = E_WRITEFAIL ; }
m_LockIwr.Unlock() ;
m_LockDwr.Lock() ;
// No errors?
if (rc == E_OK)
{
// Write to the data file
m_WrD << datum ;
// Internal write error?
if (m_WrD.fail())
{ threadLog("Could not update data file for datum %d\n", datumId) ; rc = E_WRITEFAIL ; }
}
m_LockDwr.Unlock() ;
// No errors?
if (rc == E_OK)
{
// Flush index and data files
m_WrI.flush() ;
m_WrD.flush() ;
}
return rc ;
}