Insert the supplied datum (hzChain content) into the repository and set the supplied datum id in respect of the datum. This is a matter of appending the data file of the current partition with the datum, and of appending the index file of the current partition with the datum metadata. Purpose: Insert data contained in the supplied row source. This could be any of the row source classes. This function is for mass import
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbBinRepos::Insert | (uint32_t&,hzChain&,) |
Declared in file: hzDatabase.h
Defined in file : hdbBinRepos.cpp
Function Logic:
Function body:
hzEcode hdbBinRepos::Insert (uint32_t& datumId)hzChain& datum,
{
// Insert the supplied datum (hzChain content) into the repository and set the supplied datum id in respect of the datum.
//
// This is a matter of appending the data file of the current partition with the datum, and of appending the index file of the current partition with the datum metadata.
//
// Purpose: Insert data contained in the supplied row source. This could be any of the row source
// classes. This function is for mass import
//
// Arguments: 1) datumId The datum id - the address the will occupy (if specified)
// 2) datum The datum.
//
// Returns: E_NOINIT If the repos has not been initialized
// E_NOTOPEN If the repos is not open
// E_NODATA If the supplied datum is of zero size
// E_WRITEFAIL If the data could not be written to disk.
// E_OK If operation successful
_hzfunc("hdbBinRepos::Insert") ;
_datum_hd hdr ; // Datum header
hzEcode rc = E_OK ; // Return code
if (!this)
Fatal("NO INSTANCE!\n") ;
if (m_nInitState < 1) return E_NOINIT ;
if (m_nInitState < 2) return E_NOTOPEN ;
datumId = 0;
if (!datum.Size())
return E_NODATA ;
threadLog("Storing Datum %u of size %u at address %u\n", m_nSeqId + 1,datum.Size(), m_nSize) ;
hdr.m_XDate.SysDateTime() ;
hdr.m_Size = datum.Size() ;
hdr.m_Prev = 0;
// Write to the index
m_LockIwr.Lock() ;
hdr.m_Addr = m_nSize ;
datumId = ++m_nSeqId ;
m_nPopulation++ ;
m_nSize += datum.Size() ;
m_WrI.write((char*) &hdr, sizeof(_datum_hd)) ;
if (m_WrI.fail())
{ threadLog("Could not update index delta for datum %d\n", datumId) ; rc = E_WRITEFAIL ; }
m_LockIwr.Unlock() ;
m_LockDwr.Lock() ;
if (rc == E_OK)
{
// Write to the data file
m_WrD << datum ;
if (m_WrD.fail())
{ threadLog("Could not update data file for datum %d\n", datumId) ; rc = E_WRITEFAIL ; }
}
m_LockDwr.Unlock() ;
if (rc == E_OK)
{
m_WrI.flush() ;
m_WrD.flush() ;
}
// DeltaOriginate() ;
return rc ;
}