Return Type | Function name | Arguments |
---|---|---|
hzEcode | hdbObjRepos::Insert | (unsigned int&,const hdbObject&,) |
Declared in file: hzDatabase.h
Defined in file : hdbObjRepos.cpp
Function Logic:
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 ; }