Return TypeFunction nameArguments
hzEcodehdbObjRepos::InitDone(void)

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

Function Logic:

0:START 1:_hdb_ck_initstate 2:!m_pClass 3:Return hzerr(E_INITFAIL,Repository %s: No data class,*m_Name) 4:!m_pClass->MbrCount() 5:Return hzerr(E_INITFAIL,Data class %s: No members!,*m_Name) 6:m_pathCD 7:lstat(*m_pathCD,&fs)<0 8:ofstream::open ofstream::fail 9:os.fail() 10:Return hzerr(E_WRITEFAIL,Data class %s Cannot open data file %s in write mode,*m_Name,*m_pathCD) 11:hdbClass::Desc ofstream::fail 12:os.fail() 13:close ofstream::clear 14:Return rc 15:ofstream::flush close ofstream::clear 16:open ifstream::fail 17:is.fail() 18:Return hzerr(E_OPENFAIL,Class %s data file %s exists but cannot be read in,*m_Name,*m_pathCD) 19:lineBuf nLine 20:; 21:ifstream::getline 22:!lineBuf[0] 23:items hzChain::AddByte strcmp 24:!strcmp(lineBuf,) 25:close lineBuf strDesc 26:strDesc!=m_pClass->Desc() 27:hdbClass::Desc 28:mbrNoMbrCount(); 29:hdbClass::GetMember pMbr hdbDatatype::txtName hdbMember::txtName hdbMember::DeltaId pIdx 30:!pIdx 31:pIdx->Whatami()==HZINDEX_UKEY 32:pIdxU hdbMember::strName hdbMember::Basetype hdbIndexUkey::Init rc 33:rc!=E_OK 34:Return hzerr(rc,Failed to initialize unique-key index %s (%s)\n,*m_Name,pMbr->txtName()) 35:rc!=E_OK 36:m_eReposInit 37:Return rc

Function body:

hzEcode hdbObjRepos::InitDone (void)
{
   _hzfunc("hdbObjRepos::InitDone") ;
   const hdbMember*    pMbr ;
   ifstream            is ;
   ofstream            os ;
   FSTAT               fs ;
   hzChain             E ;
   hzAtom              atom ;
   hdbIndex*           pIdx ;
   hdbIndexUkey*       pIdxU ;
   hzString            strDesc ;
   uint32_t            nLine ;
   uint32_t            mbrNo ;
   char*               lineBuf ;
   hzEcode             rc ;
   _hdb_ck_initstate(m_Name, m_eReposInit, HDB_REPOS_INIT_PROG) ;
   if (!m_pClass)
       return hzerr(E_INITFAIL, "Repository %s: No data class", *m_Name) ;
   if (!m_pClass->MbrCount())
       return hzerr(E_INITFAIL, "Data class %s: No members!", *m_Name) ;
   if (m_pathCD)
   {
       if (lstat(*m_pathCD, &fs) < 0)
       {
           os.open(*m_pathCD) ;
           if (os.fail())
               return hzerr(E_WRITEFAIL, "Data class %s Cannot open data file %s in write mode", *m_Name, *m_pathCD) ;
           os << m_pClass->Desc() ;
           if (os.fail())
           {
               os.close() ;
               os.clear() ;
               hzerr(rc, "Data class %s Cannot write class description to data file %s", *m_Name, *m_pathCD) ;
               return rc ;
           }
           os.flush() ;
           os.close() ;
           os.clear() ;
       }
       is.open(*m_pathCD) ;
       if (is.fail())
           return hzerr(E_OPENFAIL, "Class %s data file %s exists but cannot be read in", *m_Name, *m_pathCD) ;
       lineBuf = new char[512];
       for (nLine = 1;; nLine++)
       {
           is.getline(lineBuf, 500);
           if (!lineBuf[0])
               break ;
           E << lineBuf ;
           E.AddByte(CHAR_NL) ;
           if (!strcmp(lineBuf, "</class>"))
               break ;
       }
       is.close() ;
       delete lineBuf ;
       strDesc = E ;
       if (strDesc != m_pClass->Desc())
           hzerr(E_FORMAT, "Format error in data file %s. Existing description \n[\n%s\n]\nNew\n[\n%s\n]\n", *m_pathCD, *strDesc, *m_pClass->Desc()) ;
   }
   for (mbrNo = 0; mbrNo < m_pClass->MbrCount() ; mbrNo++)
   {
       pMbr = m_pClass->GetMember(mbrNo) ;
       threadLog("Initializing member %s:%s\n", m_pClass->txtName(), pMbr->txtName()) ;
       pIdx = m_mapIndex[pMbr->DeltaId()] ;
       if (!pIdx)
           continue ;
       if (pIdx->Whatami() == HZINDEX_UKEY)
       {
           pIdxU = (hdbIndexUkey*) pIdx ;
           rc = pIdxU->Init(this, pMbr->strName(), pMbr->Basetype()) ;
           if (rc != E_OK)
               return hzerr(rc, "Failed to initialize unique-key index %s (%s)\n", *m_Name, pMbr->txtName()) ;
       }
   }
   if (rc != E_OK)
       threadLog("Failed to init repos %s\n", *m_Name) ;
   else
   {
       threadLog("Complete init repos %s\n", *m_Name) ;
       m_eReposInit = HDB_REPOS_INIT_DONE ;
   }
   return rc ;
}