Begin repository initialization sequence. This function sets the repository native class, names the repository and the working directory (location of data files). Once this function has completed, it may be followed by calls to InitMbrIndex() to add member-wise indexes to the repository. Lastly InitDone() is called to complete the process.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbObjRepos::InitStart | (hdbClass*,hzString&,hzString&,hdbReposMode,) |
Declared in file: hzDatabase.h
Defined in file : hdbObjRepos.cpp
Function Logic:
Function body:
hzEcode hdbObjRepos::InitStart (hdbClass* pNative)hzString& name, hzString& workdir, hdbReposMode eMode,
{
// Begin repository initialization sequence. This function sets the repository native class, names the repository and the working directory (location of data files). Once this
// function has completed, it may be followed by calls to InitMbrIndex() to add member-wise indexes to the repository. Lastly InitDone() is called to complete the process.
//
// Arguments: 1) pNative The data class
// 2) name The repository name
// 3) workdir The operaional directory
// 4) bCache Use RAM Primacy
//
// Returns: E_ARGUMENT If no data class is supplied
// E_NOINIT If no class members have been defined
// E_INITDUP If this is a repeat call
// E_DUPLICATE If the cache already exists
// E_OK If the operation was successful
_hzfunc("hdbObjRepos::InitStart") ;
// const hdbMember* pMbr ; // Named class member
// uint32_t nIndex ; // Member iterator
hzEcode rc ; // Return code
if (!this)
hzexit(E_CORRUPT, "No hdbObjRepos instance") ;
// Check init state and state of supplied class
_hdb_ck_initstate(name, m_eReposInit, HDB_CLASS_INIT_NONE) ;
// Check data class has been supplied and is initialized
if (!pNative)
return hzerr(E_ARGUMENT, "No data class supplied") ;
if (!pNative->IsInit())
return hzerr(E_NOINIT, "Supplied class (%s) is not initialized", pNative->txtName()) ;
if (pNative->HasBinaries())
{
if (eMode == HDB_REPOS_CACHE)
{
hzwarn(E_TYPE, "Ignoring CACHE mode, using DUAL") ;
eMode = HDB_REPOS_DUAL ;
}
}
// Ensure Repository Name is Unique
if (!name)
return hzerr(E_ARGUMENT, "No name supplied") ;
if (m_pADP->GetObjRepos(name))
return hzerr(E_DUPLICATE, "Repository %s already exists", *name) ;
// Ensure working directory is given and operational
if (!workdir)
return hzerr(E_ARGUMENT, "No working directory supplied for object cache %s", *name) ;
rc = AssertDir(*workdir, 0777);
if (rc != E_OK)
return hzerr(rc, "Cannot assert working directory %s for object cache %s\n", *workdir, *name) ;
// Proceed with initialization
m_pClass = pNative ;
m_Name = name ;
m_Workdir = workdir ;
if (eMode == HDB_REPOS_HARD || eMode == HDB_REPOS_DUAL)
{
// Set up the member data binary datum repostory
if (pNative->HasBinaries())
{
m_nameBR_Datum = m_Name + "_br_datum" ;
m_pBR_Datum = new hdbBinRepos(*m_pADP) ;
rc = m_pBR_Datum->Init(m_nameBR_Datum, m_Workdir) ;
if (rc != E_OK)
return hzerr(rc, "Failed to initialize binary data store: Repos %s, Datum BR (%s), workdir %s\n", *m_Name, *m_nameBR_Datum, *m_Workdir) ;
}
// Set up the default binary datum repostory
if (!m_pBR_Delta)
{
m_nameBR_Delta = m_Name + "_br_delta" ;
m_pBR_Delta = new hdbBinRepos(*m_pADP) ;
rc = m_pBR_Delta->Init(m_nameBR_Delta, m_Workdir) ;
if (rc != E_OK)
return hzerr(rc, "Failed to initialize binary data store %s (%s)\n", *m_nameBR_Delta, *m_Workdir) ;
}
}
// Set up RAM Primacy cache if applicable
if (eMode == HDB_REPOS_CACHE || eMode == HDB_REPOS_DUAL)
{
m_pathCD = m_Workdir ;
m_pathCD += "/" ;
m_pathCD += m_Name ;
m_pathCD += ".cache" ;
// m_pCache = new hzMapS<uint32_t,hzEdo> ;
}
// Set init state
m_eReposInit = HDB_REPOS_INIT_PROG ;
m_eMode = eMode ;
// Insert the repository
m_pADP->RegisterObjRepos(this) ;
return E_OK ;
}