Return TypeFunction nameArguments
hzEcodehdbObjRepos::Insert(unsigned int&,const hdbObject&,)

Declared in file: hzDatabase.h
Defined in file : hdbObjRepos.cpp

Function Logic:

0:START 1:!this 2:Fatal 3:objId _hdb_ck_initstate hdbObject::Class 4:!theObj.Class() 5:Return hzerr(E_NOINIT,Supplied object is not initialized) 6:theObj.Class()!=m_pClass 7:hdbObject::Class hdbADP::IsSubClass 8:!m_pADP->IsSubClass(m_pClass,theObj.Class()) 9:hdbObject::Classname hdbDatatype::txtType 10:Return E_TYPE 11:theObj.GetObjId()!=0 12:Return hzerr(E_RANGE,Supplied object has an object id of %u,theObj.GetObjId()) 13:mbrNoMbrCount(); 14:hdbClass::GetMember pMbr hdbMember::DeltaId pIdx 15:!pIdx 16:pIdx->Whatami()==HZINDEX_UKEY 17:pIdxU hdbObject::GetValue rc 18:rc!=E_OK 19:Return hzerr(rc,%s: Could not select on index for member %s,*m_Name,pMbr->txtName()) 20:objId 21:Return hzerr(E_DUPLICATE,%s: Got objId of %d for member %s,*m_Name,objId,pMbr->txtName()) 22:objId hdbObject::SetObjId 23:m_pBR_Datum 24:hdbObject::CommitBinaries rc 25:rc!=E_OK 26:Return hzerr(rc,Could not commit binaries) 27:hdbObject::ExportDelta rc 28:rc!=E_OK 29:Return hzerr(rc,Could not export whole object delta) 30:items ofstream::flush 31:m_pMain 32:hdbObject::ExportEDO rc 33:rc!=E_OK 34:Return hzerr(rc,Could not export EDO) 35:hdbObjRepos::_cache::CommitEDO rc 36:rc!=E_OK 37:Return hzerr(rc,Could not commit EDO) 38:hdbObjRepos::_updateIdx rc 39:rc!=E_OK 40:Return hzerr(rc,Could not update indexes) 41:Return rc

Function body:

hzEcode hdbObjRepos::Insert (unsigned int& objId, const hdbObject& theObj)
{
   _hzfunc("hdbObjRepos::Insert") ;
   const hdbMember*    pMbr ;
   hzChain         Z ;
   hzChain         theChain ;
   hzChain         edo ;
   hzChain         delta ;
   hzAtom          atom ;
   _atomval        av ;
   hdbIndex*       pIdx ;
   hdbIndexUkey*   pIdxU ;
   hzString        strVal ;
   uint32_t        mbrNo ;
   hzEcode         rc = E_OK ;
   if (!this)
       Fatal("No Object\n") ;
   objId = 0;
   _hdb_ck_initstate(m_Name, m_eReposInit, HDB_REPOS_OPEN) ;
   if (!theObj.Class())
       return hzerr(E_NOINIT, "Supplied object is not initialized") ;
   if (theObj.Class() != m_pClass)
   {
       if (!m_pADP->IsSubClass(m_pClass, theObj.Class()))
       {
           hzerr(E_TYPE, "Supplied object class %s not compatible with this cache class %s", theObj.Classname(), m_pClass->txtType()) ;
           return E_TYPE ;
       }
   }
   if (theObj.GetObjId() != 0)
       return hzerr(E_RANGE, "Supplied object has an object id of %u", theObj.GetObjId()) ;
   /*
   **  ** Check members to see if any of them require unique values. Any that do will have an unique key index. If the member value already exists, abort the INSERT.
   **      */
   for (mbrNo = 0; mbrNo < m_pClass->MbrCount() ; mbrNo++)
   {
       pMbr = m_pClass->GetMember(mbrNo) ;
       pIdx = m_mapIndex[pMbr->DeltaId()] ;
       if (!pIdx)
           continue ;
       if (pIdx->Whatami() == HZINDEX_UKEY)
       {
           pIdxU = (hdbIndexUkey*) pIdx ;
           rc = theObj.GetValue(atom, pMbr) ;
           if (rc != E_OK)
               return hzerr(rc, "%s: Could not select on index for member %s", *m_Name, pMbr->txtName()) ;
           if (objId)
               return hzerr(E_DUPLICATE, "%s: Got objId of %d for member %s", *m_Name, objId, pMbr->txtName()) ;
       }
   }
   /*
   **  ** The new object does not conflict with an existing one and so insertation can proceed. The objId is assigned as the number of existing objects + 1
   **      */
   objId = ++m_nSeqId ;
   theObj.SetObjId(objId) ;
   if (m_pBR_Datum)
   {
       rc = theObj.CommitBinaries(m_pBR_Datum) ;
       if (rc != E_OK)
           return hzerr(rc, "Could not commit binaries") ;
   }
   rc = theObj.ExportDelta(delta) ;
   if (rc != E_OK)
       return hzerr(rc, "Could not export whole object delta") ;
   m_osDelta << delta ;
   m_osDelta.flush() ;
   if (m_pMain)
   {
       rc = theObj.ExportEDO(edo) ;
       if (rc != E_OK)
           return hzerr(rc, "Could not export EDO") ;
       rc = m_pMain->CommitEDO(edo, objId, false) ;
       if (rc != E_OK)
           return hzerr(rc, "Could not commit EDO") ;
   }
   rc = _updateIdx(theObj) ;
   if (rc != E_OK)
       return hzerr(rc, "Could not update indexes") ;
   return rc ;
}