Initialize the hdbIsamfile instance. This is a matter of asserting the working directory, the index and the data file. exist and are open for reading and writing. This is a matter of opening an input stream for the data file, an output stream for the data file and an output stream for the index file. Note both the output streams are opened with ios::app as they will only ever append and that there is no input stream for the index file as during normal operation of a binary datacron, the index is never read. nd index file as append only files. The first step is to open the index file for reading and load the index into the memory. This file is then closed but opened again in write mode. If it does not exists then it is created and left open in write mode. The second step is to create or open the data file for both reading and writing. The hdbIsamfile is then ready to store and retrieve binary objects. Errors: Any false return is due to an irrecoverable error. The calling function must check the return value.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbIsamfile::Init | (hdbADP&,hzString&,hzString&,uint32_t,uint32_t,uint32_t,) |
Declared in file: hzDatabase.h
Defined in file : hdbIsamfile.cpp
Function Logic:
Function body:
hzEcode hdbIsamfile::Init (hdbADP& adp)hzString& name, hzString& opdir, uint32_t keySize, uint32_t objSize, uint32_t blkSize,
{
// Initialize the hdbIsamfile instance.
//
// This is a matter of asserting the working directory, the index and the data file. exist and are open for reading and writing.
//
// This is a matter of opening an input stream for the data file, an output stream for the data file and an output stream for the index file. Note both the
// output streams are opened with ios::app as they will only ever append and that there is no input stream for the index file as during normal operation of
// a binary datacron, the index is never read.
//
// nd index file as append only files. The first step is to open the index file for reading and load the index into the memory. This file is then closed but
// opened again in write mode. If it does not exists then it is created and left open in write mode. The second step is to create or open the data file for
// both reading and writing. The hdbIsamfile is then ready to store and retrieve binary objects.
//
// Arguments: 1) adp The Application Delta Profile.
// 2) name Name of ISAM-file (will be base name of the delta and data store files)
// 3) opdir Full pathname of working directory
//
// Returns: E_OPENFAIL The files could not be opened or created (no space or wrong permissions)
// E_OK Operation was successful.
//
// Errors: Any false return is due to an irrecoverable error. The calling function
// must check the return value.
_hzfunc("hdbIsamfile::Init") ;
FSTAT fs ; // File status
ifstream is ; // Input stream for reading index file
int32_t fd ; // File descriptor
hzEcode rc ; // Return code
if (m_nInitState)
return hzerr(E_INITDUP, "Resource already initialized") ;
// Check we have a name and working directory
if (!name) return hzerr(E_ARGUMENT, "No name") ;
if (!opdir) return hzerr(E_ARGUMENT, "Repository %s: No working directory", *name) ;
// Check we do not already have a datacron of the name
if (adp.GetBinRepos(name))
return hzerr(E_DUPLICATE, "Binary datum cron %s already exists", *name) ;
// Assign internal structure, name and working directory
m_Name = name ;
m_Workdir = opdir ;
m_Error.Printf("%s called with cron name %s and workdir %s\n", *_fn, *m_Name, *m_Workdir) ;
// Assert working directory
if (lstat(*m_Workdir, &fs) < 0)
{
rc = AssertDir(*m_Workdir, 0777);
if (rc != E_OK)
return hzerr(rc, "Could not assert working dir of %s", *m_Workdir) ;
}
// Set the pathnames for the index and data file
m_fileDelta = m_Workdir + "/" + m_Name + ".idx" ;
m_fileStore = m_Workdir + "/" + m_Name + ".dat" ;
m_Error.Printf("%s Have index file of %s and data file of %s\n", *_fn, *m_fileDelta, *m_fileStore) ;
// memset(m_Buf, 0, HZ_BLOCKSIZE) ;
// m_Buf[0] = m_Buf[1] = m_Buf[2] = m_Buf[3] = m_Buf[4] = m_Buf[5] = m_Buf[6] = m_Buf[7] = '0' ;
// m_Buf[8] = CHAR_EOT ;
// m_Buf[9] = CHAR_NL ;
if (lstat(*m_fileDelta, &fs) < 0)
{
fd = open(*m_fileDelta, O_RDWR|O_CREAT|O_TRUNC, 0600);
if (fd < -1)
return hzerr(E_OPENFAIL, "Cannot create %s, error %s", *m_fileDelta, Err2Txt(errno)) ;
close(fd) ;
}
if (lstat(*m_fileStore, &fs) < 0)
{
fd = open(*m_fileStore, O_RDWR|O_CREAT|O_TRUNC, 0600);
if (fd < -1)
return hzerr(E_OPENFAIL, "Cannot create %s, error %s", *m_fileStore, Err2Txt(errno)) ;
close(fd) ;
}
// Set init state etc
m_nInitState = 1;
return E_OK ;
}