Complete repository initialization. Deal with files if the working directory has been supplied. If files bearing the repository name exists in the stated working directory, these are assumed to be data files and will be read in to populate the repository. Delta files begin with a header which must match the class definition. This is checked before loading the rest of the data. If a file of the cache's name does not exist in the working directory, it will be created and a header will be written. If a backup directory has been specified and a file of the cache's name exists in this directory, the header will be checked and assuming this is OK, the length of the file will aslo be checked (should match with that in the work directory) Arguments: None

Return TypeFunction nameArguments
hzEcodehdbObjRepos::InitDone(void)

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

Function Logic:

0:START 1:items 2:unknown 3:Return hzerr(E_INITFAIL,Repository %s: No data class,*m_Name) 4:unknown 5:Return hzerr(E_INITFAIL,Data class %s: No members!,*m_Name) 6:unknown 7:unknown 8:items 9:unknown 10:Return hzerr(E_WRITEFAIL,Data class %s Cannot open data file %s in write mode,*m_Name,*m_pathCD) 11:items 12:unknown 13:items items items 14:Return rc 15:items items items 16:items 17:unknown 18:Return hzerr(E_OPENFAIL,Class %s data file %s exists but cannot be read in,*m_Name,*m_pathCD) 19:lineBuf 20:unknown 21:items 22:unknown 23:items items 24:unknown 25:items lineBuf strDesc 26:unknown 27:items 28:unknown 29:pMbr items pIdx 30:unknown 31:unknown 32:pIdxU rc 33:unknown 34:Return hzerr(rc,Failed to initialize unique-key index %s (%s)\n,*m_Name,pMbr->txtName()) 35:unknown 36:items 37:items m_eReposInit 38:Return rc

Function body:

hzEcode hdbObjRepos::InitDone (void)
{
   //  Complete repository initialization.
   //  
   //  Deal with files if the working directory has been supplied. If files bearing the repository name exists in the stated working directory, these are assumed to be data files
   //  and will be read in to populate the repository. Delta files begin with a header which must match the class definition. This is checked before loading the rest of the data.
   //  If a file of the cache's name does not exist in the working directory, it will be created and a header will be written.
   //  
   //  If a backup directory has been specified and a file of the cache's name exists in this directory, the header will be checked and assuming this is OK, the length of the file
   //  will aslo be checked (should match with that in the work directory)
   //  
   //  Arguments: None
   //  
   //  Returns: E_INITFAIL If Repository has no native data class, or the native data class has no members and/or no description
   //     E_WRITEFAIL If the data file cannot be opened in write mode
   _hzfunc("hdbObjRepos::InitDone") ;
   const hdbMember*    pMbr ;      //  Member
   ifstream            is ;        //  For reading in working data file
   ofstream            os ;        //  For writing in working data file
   FSTAT               fs ;        //  File status
   hzChain             E ;         //  Existing class description header from data file
   hzAtom              atom ;      //  For setting member values
   hdbIndex*           pIdx ;      //  The index to be added
   hdbIndexUkey*       pIdxU ;     //  The index to be added
   hzString            strDesc ;   //  Temp string holding memeber data
   uint32_t            nLine ;     //  Line number for reporting file errors
   uint32_t            mbrNo ;     //  Member number
   char*               lineBuf ;   //  For getline
   hzEcode             rc ;        //  Return code
   //  Check initialization and if there are some members added
   _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) ;
   //  Create and compare the XML Class Description
   if (m_pathCD)
   {
       //  Cache and cache delta applies
       if (lstat(*m_pathCD, &fs) < 0)
       {
           //  Working data file does not exist or is empty. Create a new one from the class description as per C++ calls
           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() ;
       }
       //  Working data file does exist and has content so read it in. Start with header
       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 ;
       //  Compare class description header from file to that of the class
       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()) ;
   }
   //  Initialize all allocated indexes
   for (mbrNo = 0; mbrNo < m_pClass->MbrCount() ; mbrNo++)
   {
       pMbr = m_pClass->GetMember(mbrNo) ;
       threadLog("Initializing member %s:%s\n", m_pClass->txtName(), pMbr->txtName()) ;
       //  Check if the member has an associated index
       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()) ;
       }
   }
   //  Init matrix
   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 ;
}