/******************************************************************************/ /* File : HLops.cc */ /* Schema : bdeschema.sch */ /* GENCPP Version : Chgen V 12 - Sathya */ /******************************************************************************/ #include #include #include #include "bdeschema.h" #include "SVschema.h" #include "TTschema.h" #include "TAschema.h" #include "VVschema.h" #include "TSschema.h" #include "FOschema.h" #include "GDschema.h" #include "HGschema.h" #include "HNschema.h" #include "HAschema.h" #include "HLschema.h" #include "HPschema.h" #include "HIschema.h" #include "CGschema.h" #include "GXschema.h" #ifdef USE_STL /******************************************************************************/ /* This routine returns table abbreviation. */ /******************************************************************************/ char *HLtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *HLtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int HLtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator HLtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ HL *HLtable::getLastRow() { HL *retval; list::iterator iter; if (row.empty()) { retval = NULL; } else { iter = row.end(); iter--; retval = *iter; } return retval; } /******************************************************************************/ /* This routine returns the terminator after last row in the table. */ /******************************************************************************/ list::iterator HLtable::Terminator() { return row.end(); } bool HLtable::isFirstRow(HL* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool HLtable::isLastRow(HL* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void HLtable::insertRow(HL *newRow) { list::iterator iter; iter = row.begin(); while (iter != row.end() && (*iter)->get_pkid() < newRow->get_pkid()) iter++; row.insert(iter, newRow); } #endif /* USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine returns removes the specified row from the table. */ /******************************************************************************/ list::iterator HLtable::removeRow(list::iterator i) { HL *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ HLtable::HLtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ HLtable::~HLtable() { HL *currRow; list::iterator iterator; iterator = row.begin(); while (iterator != row.end()) { currRow = *iterator; iterator = currRow->delete_row(iterator); } delete [] name; } #endif /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HL::set_HNid1 (hcg_key value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; char temp_fkey[HCG_KEY_SIZE+1]; hcg_key HLid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_KEY %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ), "HNid1", decode_retstr(&value) ); } HNid1 = value ; HLid = RC::get_pkid(); decode(temp_key, &HLid); decode(temp_fkey, &value); sprintf(log_text,"PR_SET_KEY %s HNid1 %s\n",temp_key, temp_fkey); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HL::set_HNid2 (hcg_key value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; char temp_fkey[HCG_KEY_SIZE+1]; hcg_key HLid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_KEY %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ), "HNid2", decode_retstr(&value) ); } HNid2 = value ; HLid = RC::get_pkid(); decode(temp_key, &HLid); decode(temp_fkey, &value); sprintf(log_text,"PR_SET_KEY %s HNid2 %s\n",temp_key, temp_fkey); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HL::set_HPcount (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HLid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_INT %s %s %d\n", decode_retstr( (hcg_key*)(get_pkid()) ),"HPcount", (value) ); } HPcount = value ; #ifdef USE_STL HLid = get_pkid(); #else HLid = RC::get_pkid(); #endif decode(temp_key, &HLid); sprintf(log_text,"PR_SET_INT %s HPcount %d\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HL::set_allvisible (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HLid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_INT %s %s %d\n", decode_retstr( (hcg_key*)(get_pkid()) ),"allvisible", (value) ); } allvisible = value ; #ifdef USE_STL HLid = get_pkid(); #else HLid = RC::get_pkid(); #endif decode(temp_key, &HLid); sprintf(log_text,"PR_SET_INT %s allvisible %d\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ hcg_key HL::get_HNid1 () { return HNid1; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ hcg_key HL::get_HNid2 () { return HNid2; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int HL::get_HPcount () { return HPcount; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int HL::get_allvisible () { return allvisible; } #ifndef USE_STL HL* HL::create_row() { HL *HLtmp; HLtmp = new HL; HLtmp->set_pkid(0); HLtmp->set_HNid1(0); HLtmp->set_HNid2(0); HLtmp->set_HPcount(0); HLtmp->set_allvisible(0); HLtmp->next_ptr = NULL; HLtmp->prev_ptr = NULL; HLtmp->HNid1_pp = NULL; HLtmp->HNid1_fpp = NULL; HLtmp->HNid1_bpp = NULL; HLtmp->HNid2_pp = NULL; HLtmp->HNid2_fpp = NULL; HLtmp->HNid2_bpp = NULL; HLtmp->HIid_fcp = NULL; HLtmp->HIid_bcp = NULL; HLtmp->HPid_fcp = NULL; HLtmp->HPid_bcp = NULL; return HLtmp; } #endif /******************************************************************************/ /* This routine is used to add a single row to a virtual database table. */ /* Validations for valid table-id, table is within view, and the version */ /* number is the right one for this table in this view. if all this passes, */ /* the row is added to the database, and linked in to its parents, etc... */ /******************************************************************************/ void HL::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key HLid; char VNstring[NAMELENGTH] = "VN "; if (hcg_log == 1) { logwait(); if (strcmp(viewname, hcg_viewname)) { logstr(strcat (strcat (VNstring, viewname), "\n")); strcpy (hcg_viewname, viewname); } } if (!hcg_initialized) { printf("Error: pr_add() called when database is not yet initialized.\n"); add_row_log (viewname); return; } if (!find_view_idx(viewname)) { printf("Error: view %s passed to pr_load is not defined.\n",viewname); add_row_log (viewname); return; } if (!find_tbl_idx("HL")) { strncpy_null(error_table, "HL", HCG_ABBR_SIZE); printf("Warning: unknown table (%s) passed to pr_add, ignored.\n",error_table); add_row_log (viewname); return; } hcg_version = hcg_view_list.view_list[hcg_view_idx].version_list[hcg_tbl_idx]; hcg_table_seq_list[hcg_tbl_idx].rcount++; hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].rcount++; #ifndef USE_STL HLelt = this; #endif pr_gen_pkey(viewname,HL,HLid); #ifdef USE_STL set_pkid(HLid); #else RC::set_pkid(HLid); #endif #ifndef USE_STL pr_check_fkey(HL,HLelt,HNid1,HN,HNid,HNelt); #else pr_check_fkey(HL,this,HNid1,HN,HNid,HNelt); #endif #ifndef USE_STL pr_check_fkey(HL,HLelt,HNid2,HN,HNid,HNelt); #else pr_check_fkey(HL,this,HNid2,HN,HNid,HNelt); #endif add_row_log (viewname); link_row(); hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].maxrow++; } /******************************************************************************/ /* This routine is used to link a single row to a virtual database table. */ /******************************************************************************/ void HL::link_row() { hcg_key HLid; #ifndef USE_STL insert_element(HL); #else HLtab->insertRow(this); #endif /* USE_STL */ link_child_bp_m(HI,HL,HLid,HLid,HLid,HIid); link_child_bp_m(HP,HL,HLid,HLid,HLid,HPid); link_parent_bp_m(HL,HN,HNid1,HNid,HNid1,HLid1); link_parent_bp_m(HL,HN,HNid2,HNid,HNid2,HLid2); } /******************************************************************************/ /* This routine is used to parse a single row to a virtual database table. */ /* Validations for valid table-id, table is within view, and the version */ /* number is the right one for this table in this view. if all this passes, */ /* the row is added to the database, and linked in to its parents, etc... */ /******************************************************************************/ void HL::parse_row (char *buffer, int idx, hcg_key hcg_k) { #ifdef USE_STL set_pkid(hcg_k); #else RC::set_pkid(hcg_k); #endif hcg_parse(buffer, hcg_t, &idx); encode(hcg_t, &hcg_k); HNid1 = hcg_k; hcg_parse(buffer, hcg_t, &idx); encode(hcg_t, &hcg_k); HNid2 = hcg_k; hcg_parse(buffer,hcg_t,&idx); set_HPcount(atoi(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_allvisible(atoi(hcg_t)); } /******************************************************************************/ /* This routine will delete a single row from the database. The row is the */ /* one pointed to by the XXcurr variable. */ /******************************************************************************/ #ifdef USE_STL list::iterator HL::delete_row (list::iterator rowIter) #else void HL::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key HLid; char log_text[BUFSIZE]; logwait(); unlink_child_bp_m(HI,HL,HLid,HIid); unlink_child_bp_m(HP,HL,HLid,HPid); #ifdef USE_STL HLcurr = rowIter; #endif unlink_parent_bp_m(HL,HN,HNid1,HLid1); #ifdef USE_STL HLcurr = rowIter; #endif unlink_parent_bp_m(HL,HN,HNid2,HLid2); #ifdef DEBUG #ifdef USE_STL HLid = get_pkid(); #else HLid = RC::get_pkid(); #endif decode(temp_key, &HLid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = HLtab->removeRow(rowIter); delete this; #else del_row(HL); #endif /* The following is to support logging */ #ifdef USE_STL HLid = get_pkid(); #else HLid = RC::get_pkid(); #endif decode(temp_key, &HLid); sprintf(log_text,"DL %s\n",temp_key); logstr(log_text); #ifdef USE_STL return rowIter; #endif } /******************************************************************************/ /* This routine will write-out (dump) all rows that meet the specified */ /* view to the specified file_name. The tbl indicates which table's row */ /* will be dumped. The open_file flag of 1 indicates open a file for dumping */ /* a single row. Otherwise doesn't open file because pr_dump had opened a */ /* file. If the mode of the view is write, the caller is allowed to specify a */ /* new_version flag of 1, which will cause a version number update. Finally, */ /* the modestr parameter indicates if a new file should be generated ('w'), */ /* or append to an existing file ('a'). */ /******************************************************************************/ #ifdef USE_STL void HLtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void HL::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,HL) { #ifndef USE_STL HLcurr->dump_row(viewname,file_name,new_version,modestr); #else (*HLcurr)->dump_row(viewname,file_name,new_version,modestr); #endif /* USE_STL */ } } /******************************************************************************/ /* This routine will write-out (dump) a single row that meet the specified */ /* view to the specified file_name. The tbl indicates which table's row */ /* will be dumped. The open_file flag of 1 indicates open a file for dumping */ /* a single row. Otherwise doesn't open file because pr_dump had opened a */ /* file. If the mode of the view is write, the caller is allowed to specify a */ /* new_version flag of 1, which will cause a version number update. Finally, */ /* the modestr parameter indicates if a new file should be generated ('w'), */ /* or append to an existing file ('a'). */ /******************************************************************************/ void HL::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key HLid; if (open_file==1) { if ((hcg_dump_fp=fopen(file_name,modestr)) == NULL) { printf("Error: dump_row() cannot open %s using file mode %s\n", file_name,modestr); exit(1); } } #ifdef USE_STL HLid = get_pkid(); #else HLid = RC::get_pkid(); #endif hcg_update_version(&HLid,HL_idx,new_version); decode(outkey[0], &HLid); hcg_update_version(&HNid1,HN_idx,new_version); decode(outkey[1], &HNid1); hcg_update_version(&HNid2,HN_idx,new_version); decode(outkey[2], &HNid2); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-8s %-8s %8d %8d\n" , outkey[0], outkey[1], outkey[2], HPcount, allvisible)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL void HL::insertChild_HIid(HI *childRow) { HIid_children.push_back(childRow); } void HL::removeChild_HIid(list::iterator rowIter) { HIid_children.remove((*rowIter)); } list::iterator HL::getFirstChild_HIid() { return HIid_children.begin(); } list::iterator HL::getLastChild_HIid() { list::iterator iter; iter = HIid_children.end(); if (!HIid_children.empty()) iter--; return iter; } list::iterator HL::HIid_Terminator() { return HIid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL void HL::insertChild_HPid(HP *childRow) { HPid_children.push_back(childRow); } void HL::removeChild_HPid(list::iterator rowIter) { HPid_children.remove((*rowIter)); } list::iterator HL::getFirstChild_HPid() { return HPid_children.begin(); } list::iterator HL::getLastChild_HPid() { list::iterator iter; iter = HPid_children.end(); if (!HPid_children.empty()) iter--; return iter; } list::iterator HL::HPid_Terminator() { return HPid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL void HL::setParent_HNid1(HN *currentRow) { HNid1_pp = currentRow; } HN *HL::getParent_HNid1() { return HNid1_pp; } #endif /* USE_STL */ #ifdef USE_STL void HL::setParent_HNid2(HN *currentRow) { HNid2_pp = currentRow; } HN *HL::getParent_HNid2() { return HNid2_pp; } #endif /* USE_STL */ #ifdef USE_STL /********************************************************************************/ /* Default constructor for HL. */ /********************************************************************************/ HL::HL () { set_pkid(0); /* initialize */ set_HNid1(0); set_HNid2(0); set_HPcount(0); set_allvisible(0); setParent_HNid1(NULL); setParent_HNid2(NULL); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for HL. */ /********************************************************************************/ HL::~HL () { /* Empty */ } #endif /********************************************************************************/ /* This routine is used to log a call to pr_add to hcg_logfile */ /* The tbl indicates which table is having a row added. */ /* tbl_ptr points to the record to be added. */ /********************************************************************************/ void HL::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key HLid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("HL"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL HLid = get_pkid(); #else HLid = RC::get_pkid(); #endif hcg_update_version(&HLid,HL_idx,0); decode(outkey[0], &HLid); hcg_update_version(&HNid1,HN_idx,0); decode(outkey[1], &HNid1); hcg_update_version(&HNid2,HN_idx,0); decode(outkey[2], &HNid2); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-8s %-8s %8d %8d\n" , outkey[0], outkey[1], outkey[2], HPcount, allvisible)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void HL::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); encode(hcg_t, &hcg_k); HNid1 = hcg_k; hcg_parse(theRest, hcg_t, &idx); encode(hcg_t, &hcg_k); HNid2 = hcg_k; hcg_parse(theRest, hcg_t, &idx); HPcount = (atoi(hcg_t)); hcg_parse(theRest, hcg_t, &idx); allvisible = (atoi(hcg_t)); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void HL::log_do_set_int_row (const char fieldname[NAMELENGTH+1], const int newval) { if(strcmp(fieldname,"HPcount")==0) HPcount = newval; else if(strcmp(fieldname,"allvisible")==0) allvisible = newval; } /********************************************************************************/ /* This routine is used to set the value of an float field. */ /********************************************************************************/ void HL::log_do_set_flt_row (const char fieldname[NAMELENGTH+1], const int newval) { } /********************************************************************************/ /* This routine is used to set the value of an key field. */ /********************************************************************************/ void HL::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"HLid")==0) #ifdef USE_STL set_pkid (new_key); #else RC::set_pkid (new_key); #endif else if (strcmp(fieldname,"HNid1")==0) HNid1 = new_key; else if (strcmp(fieldname,"HNid2")==0) HNid2 = new_key; } /********************************************************************************/ /* This routine is used to set the value of an string field. */ /********************************************************************************/ void HL::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { }