/******************************************************************************/ /* File : VVops.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 *VVtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *VVtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int VVtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator VVtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ VV *VVtable::getLastRow() { VV *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 VVtable::Terminator() { return row.end(); } bool VVtable::isFirstRow(VV* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool VVtable::isLastRow(VV* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void VVtable::insertRow(VV *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 VVtable::removeRow(list::iterator i) { VV *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ VVtable::VVtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ VVtable::~VVtable() { VV *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 VV::set_SVid (hcg_key value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; char temp_fkey[HCG_KEY_SIZE+1]; hcg_key VVid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_KEY %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ), "SVid", decode_retstr(&value) ); } SVid = value ; VVid = RC::get_pkid(); decode(temp_key, &VVid); decode(temp_fkey, &value); sprintf(log_text,"PR_SET_KEY %s SVid %s\n",temp_key, temp_fkey); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void VV::set_vname (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key VVid; logwait(); if ( strlen(value) >= sizeof(vname) ) fprintf(stderr, "Warning: field vname in class VV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"vname", (value) ); } strncpy(vname, value, sizeof(vname)) ; VVid = RC::get_pkid(); decode(temp_key, &VVid); sprintf(log_text,"PR_SET_STR %s vname %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void VV::set_mode (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key VVid; logwait(); if ( strlen(value) >= sizeof(mode) ) fprintf(stderr, "Warning: field mode in class VV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"mode", (value) ); } strncpy(mode, value, sizeof(mode)) ; VVid = RC::get_pkid(); decode(temp_key, &VVid); sprintf(log_text,"PR_SET_STR %s mode %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void VV::set_num_tables (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key VVid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_INT %s %s %d\n", decode_retstr( (hcg_key*)(get_pkid()) ),"num_tables", (value) ); } num_tables = value ; #ifdef USE_STL VVid = get_pkid(); #else VVid = RC::get_pkid(); #endif decode(temp_key, &VVid); sprintf(log_text,"PR_SET_INT %s num_tables %d\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ hcg_key VV::get_SVid () { return SVid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* VV::get_vname () { return vname; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* VV::get_mode () { return mode; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int VV::get_num_tables () { return num_tables; } #ifndef USE_STL VV* VV::create_row() { VV *VVtmp; VVtmp = new VV; VVtmp->set_pkid(0); VVtmp->set_SVid(0); VVtmp->set_vname("\0"); VVtmp->set_mode("\0"); VVtmp->set_num_tables(0); VVtmp->next_ptr = NULL; VVtmp->prev_ptr = NULL; VVtmp->SVid_pp = NULL; VVtmp->SVid_fpp = NULL; VVtmp->SVid_bpp = NULL; VVtmp->TSid_fcp = NULL; VVtmp->TSid_bcp = NULL; return VVtmp; } #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 VV::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key VVid; 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("VV")) { strncpy_null(error_table, "VV", 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 VVelt = this; #endif pr_gen_pkey(viewname,VV,VVid); #ifdef USE_STL set_pkid(VVid); #else RC::set_pkid(VVid); #endif #ifndef USE_STL pr_check_fkey(VV,VVelt,SVid,SV,SVid,SVelt); #else pr_check_fkey(VV,this,SVid,SV,SVid,SVelt); #endif pr_check_str (VV,VVelt,vname,30); pr_check_str (VV,VVelt,mode,2); 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 VV::link_row() { hcg_key VVid; #ifndef USE_STL insert_element(VV); #else VVtab->insertRow(this); #endif /* USE_STL */ link_child_bp_m(TS,VV,VVid,VVid,VVid,TSid); link_parent_bp_m(VV,SV,SVid,SVid,SVid,VVid); } /******************************************************************************/ /* 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 VV::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); SVid = hcg_k; hcg_parse(buffer,hcg_t,&idx); mystrcpy(vname,hcg_t,30,1); hcg_parse(buffer,hcg_t,&idx); mystrcpy(mode,hcg_t,2,0); hcg_parse(buffer,hcg_t,&idx); set_num_tables(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 VV::delete_row (list::iterator rowIter) #else void VV::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key VVid; char log_text[BUFSIZE]; logwait(); unlink_child_bp_m(TS,VV,VVid,TSid); #ifdef USE_STL VVcurr = rowIter; #endif unlink_parent_bp_m(VV,SV,SVid,VVid); #ifdef DEBUG #ifdef USE_STL VVid = get_pkid(); #else VVid = RC::get_pkid(); #endif decode(temp_key, &VVid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = VVtab->removeRow(rowIter); delete this; #else del_row(VV); #endif /* The following is to support logging */ #ifdef USE_STL VVid = get_pkid(); #else VVid = RC::get_pkid(); #endif decode(temp_key, &VVid); 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 VVtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void VV::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,VV) { #ifndef USE_STL VVcurr->dump_row(viewname,file_name,new_version,modestr); #else (*VVcurr)->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 VV::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key VVid; 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 VVid = get_pkid(); #else VVid = RC::get_pkid(); #endif hcg_update_version(&VVid,VV_idx,new_version); decode(outkey[0], &VVid); hcg_update_version(&SVid,SV_idx,new_version); decode(outkey[1], &SVid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-8s %-30s %-2s %8d\n" , outkey[0], outkey[1], vname, mode, num_tables)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL void VV::insertChild_TSid(TS *childRow) { TSid_children.push_back(childRow); } void VV::removeChild_TSid(list::iterator rowIter) { TSid_children.remove((*rowIter)); } list::iterator VV::getFirstChild_TSid() { return TSid_children.begin(); } list::iterator VV::getLastChild_TSid() { list::iterator iter; iter = TSid_children.end(); if (!TSid_children.empty()) iter--; return iter; } list::iterator VV::TSid_Terminator() { return TSid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL void VV::setParent_SVid(SV *currentRow) { SVid_pp = currentRow; } SV *VV::getParent_SVid() { return SVid_pp; } #endif /* USE_STL */ #ifdef USE_STL /********************************************************************************/ /* Default constructor for VV. */ /********************************************************************************/ VV::VV () { set_pkid(0); /* initialize */ set_SVid(0); set_vname("\0"); set_mode("\0"); set_num_tables(0); setParent_SVid(NULL); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for VV. */ /********************************************************************************/ VV::~VV () { /* 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 VV::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key VVid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("VV"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL VVid = get_pkid(); #else VVid = RC::get_pkid(); #endif hcg_update_version(&VVid,VV_idx,0); decode(outkey[0], &VVid); hcg_update_version(&SVid,SV_idx,0); decode(outkey[1], &SVid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-8s %-30s %-2s %8d\n" , outkey[0], outkey[1], vname, mode, num_tables)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void VV::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); encode(hcg_t, &hcg_k); SVid = hcg_k; hcg_parse(theRest, hcg_t, &idx); mystrcpy(vname, hcg_t, 30, 1); hcg_parse(theRest, hcg_t, &idx); mystrcpy(mode, hcg_t, 2, 0); hcg_parse(theRest, hcg_t, &idx); num_tables = (atoi(hcg_t)); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void VV::log_do_set_int_row (const char fieldname[NAMELENGTH+1], const int newval) { if(strcmp(fieldname,"num_tables")==0) num_tables = newval; } /********************************************************************************/ /* This routine is used to set the value of an float field. */ /********************************************************************************/ void VV::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 VV::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"VVid")==0) #ifdef USE_STL set_pkid (new_key); #else RC::set_pkid (new_key); #endif else if (strcmp(fieldname,"SVid")==0) SVid = new_key; } /********************************************************************************/ /* This routine is used to set the value of an string field. */ /********************************************************************************/ void VV::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { if (strcmp(fieldname,"mode")==0) strcpy(mode,newval); }