Return Type | Function name | Arguments |
---|---|---|
hzEcode | hdbObjRepos::InitDone | (void) |
Declared in file: hzDatabase.h
Defined in file : hdbObjRepos.cpp
Function Logic:
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 ; }