Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

msd_user.cc

00001 //-----------------------------------------------------
00002 // msd_user.cc
00003 //
00004 // Project: PDBe API Framework, EBI  
00005 // Module:  Implementation of User Layer Classes for PDBe API Framework 
00006 //
00007 // 
00008 // User Layer
00009 // Last updated: 25 February 2004 10:17
00010 // (C) Siamak Sobhany
00011 //------------------------------------------------------
00012 #ifndef __MSD_USER_H__
00013 #include "msd_user.h"
00014 #endif
00015 #ifndef __MSD_CHEM_H__
00016 #include "msd_chem.h"
00017 #endif
00018 #ifndef __MSD_METADATA_H__
00019 #include "msd_metadata.h"
00020 #endif
00021 
00022 #include <cstdarg>
00023 
00024 
00025 using namespace std;
00026 
00027         
00028 #define msd_typecast(new_type,old_object) (*((new_type *)&old_object))
00029 
00030 
00031 size_t getsize(void){
00032  return sizeof(msdbConnect);
00033 }
00034 
00035 
00036 int msd_select (pMSDEnv msd, char* stm){
00037   if (msd->conn==NULL) {
00038                 msd->stat=NOOBJECT;
00039                 return(2);}
00040   genselect(*((msdbConnect *) msd->conn), stm); 
00041   return(0);
00042 }
00043 
00044 int msd_sqlinit (pMSDEnv msd, char* stm){
00045    if (msd->conn==NULL) {
00046                 msd->stat=NOOBJECT;
00047                 return(2);}
00048 
00049    msd->select=new MSDSelect();
00050    ((MSDSelect *) msd->select)->InitSql(*((msdbConnect *) msd->conn), stm);
00051    return (0);
00052 }
00053 
00054 int msd_setcriteria(pMSDEnv msd, const char* fmt,...){ 
00055   int i;
00056   float f;
00057   double d;
00058   char* s;
00059   const char *p=fmt;
00060  if (msd->conn==NULL) {return(2);}
00061   va_list ap;
00062   va_start(ap,fmt); // point to first element after fmt
00063   while(*p)
00064   {
00065    if (*p=='i') //int
00066    {
00067     i=va_arg(ap,int);
00068         ((MSDSelect *) msd->select)->SetCriteria(i);
00069    }
00070    else if (*p=='d') //double or float
00071    {
00072     d=va_arg(ap,double);
00073     ((MSDSelect *) msd->select)->SetCriteria(d);
00074    }
00075    else if (*p=='s') //string
00076    {
00077     s=va_arg(ap,char*);
00078         ((MSDSelect *) msd->select)->SetCriteria(s);
00079    }
00080    
00081    else 
00082    {
00083     printf("unsupported format flag");
00084     break;
00085    }
00086    ++p; // get the next char of the format string 
00087   }// while
00088   va_end(ap); //cleanup
00089   ((MSDSelect *) msd->select)->MakeRecord();
00090   return (0);
00091  }
00092 
00093 
00094 
00095 int msd_getrownum(pMSDEnv msd){
00096 if (msd->conn==NULL) {
00097                 msd->stat=NOOBJECT;
00098                 return(2);}
00099  return ((MSDSelect *) msd->select)->GetRowNum();
00100 }
00101 
00102 int msd_getnext(pMSDEnv msd){
00103  if (msd->conn==NULL) {
00104                 msd->stat=NOOBJECT;
00105                 return(2);}
00106  ((MSDSelect *) msd->select)->GetNext();
00107  return (0);
00108 }
00109 
00110 
00111 extern "C"  MSDValue msd_getvfloat(pMSDEnv msd,int col){
00112   MSDValue msdv= &(msd->node);
00113   ((MSDSelect *) msd->select)->GetVal(col,msdv->value.vfloat);
00114  
00115   return msdv;
00116 }
00117 extern "C"  MSDValue   msd_getvint(pMSDEnv msd,int col){
00118           MSDValue msdv= &(msd->node);
00119          ((MSDSelect *) msd->select)->GetVal(col,msdv->value.vint);
00120          return msdv;
00121 }
00122 extern "C"  MSDValue msd_getvstr(pMSDEnv msd,int col){
00123         MSDValue msdv= &(msd->node);
00124         
00125         msdv->value.vstr = new char[256];
00126         msdv->value.vstr[0]= '\0';
00127         ((MSDSelect *) msd->select)->GetVal(col,msdv->value.vstr);
00128         return msdv;
00129 }
00130 
00131 
00132 extern "C"  MSDValue msd_getvdouble(pMSDEnv msd,int col){
00133          MSDValue msdv= &(msd->node);
00134          ((MSDSelect *) msd->select)->GetVal(col,msdv->value.vdouble);
00135          return msdv;
00136 }
00137 
00138 extern "C"  MSDValue msd_getvalue(pMSDEnv msd,int col, MSDValue (*pGetFunc)(pMSDEnv,int))
00139    {
00140       MSDValue result = pGetFunc(msd, col);                         // call using function pointer
00141       return result;
00142    }
00143 
00144 
00145 extern "C"   float msd_ugetfloat(pMSDEnv msd,int col)
00146 {float f;
00147  ((MSDSelect *) msd->select)->GetVal(col,f);
00148  return f;
00149 }
00150 extern "C"      int msd_ugetint(pMSDEnv msd,int col)
00151 {int i;
00152  ((MSDSelect *) msd->select)->GetVal(col,i);
00153  return i;
00154 }
00155 extern "C"      char* msd_ugetstr(pMSDEnv msd,int col, char* s)
00156 {MSDGetValue (*msd,col,s,vstr); 
00157 return s;
00158 
00159 }
00160 extern "C"      double  msd_ugetdouble(pMSDEnv msd,int col)
00161 {double d;
00162 ((MSDSelect *) msd->select)->GetVal(col,d);
00163 return d;
00164 }
00165 
00166 
00167 #ifdef __WITH_XMMDB__
00168 
00169 extern "C" int msd_manager(pMSDEnv msd) 
00170 { msd->manager = NULL;
00171   msd->manager = (void*)new MSDManager();
00172   return (0);
00173 
00174 }
00175 
00176 extern "C" int msd_get_number_of_atoms(pMSDEnv msd) 
00177 { 
00178   return ((MSDManager*)msd->manager)->GetNumberOfAtoms(); 
00179 }
00180 
00181 
00182 extern "C" int msd_get_object_entry (pMSDEnv msd, int n_eID){
00183  if (msd->conn==NULL) {
00184                 msd->stat=NOOBJECT;
00185                 return(2);}
00186   if (((MSDManager*)msd->manager)->LoadWarehouse(*((msdbConnect *) msd->conn),n_eID) == S_OK)
00187   {return(0);
00188   }else
00189   return(1);
00190 }
00191 
00192 #endif
00193 
00194 extern "C" int msd_get_entry_id(pMSDEnv msd, char* acc_code){
00195  return getMSDEntryID(*((msdbConnect *) msd->conn), acc_code);
00196 }
00197 
00198 extern "C" char* msd_get_accession_code(pMSDEnv msd, int e_ID){
00199  char* acc_code;
00200  getMSDAccessionCode(*((msdbConnect *) msd->conn), e_ID, acc_code);
00201  return acc_code;
00202 }
00203 
00204 
00205 
00206 
00207 extern "C" int  msd_init(pMSDEnv msd){
00208     msd->ConID=0;
00209         msd->SqlID=0;
00210         msd->conn=NULL;
00211         msd->select=NULL;
00212         msd->manager=NULL;
00213         msd->data=NULL;
00214         for (int i=0;i<MAXRES;i++ )
00215         {msd->result[i]=NULL;
00216         }
00217         msd->conn = new msdbConnect();
00218         ((msdbConnect *)msd->conn)->msdbInit();
00219         msd->stat=INIT;
00220         return (0);
00221 
00222 }
00223 
00224 
00225 
00226 #ifdef MSD_ORACLE
00227  
00228 
00229  int msd_attach(pMSDEnv msd, char* oserver){
00230         
00231         if (msd->conn==NULL) {
00232                 msd->stat=NOOBJECT;
00233                 return(2);}
00234         try
00235  {
00236   ((msdbConnect *) msd->conn)->server_attach(oserver);
00237    msd->stat=ATTACHED;
00238  }
00239   catch(msdbException& p){ // intercept OTL exceptions
00240    cerr<<p.msg<<endl; // print out error message
00241    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00242    cerr<<p.var_info<<endl; // print out the variable that caused the error
00243    msd->stat=NOTATTACHED;
00244   }
00245   return(0);
00246  }
00247 
00248  int msd_begin(pMSDEnv msd, char* usern, char* passwd){
00249 if (msd->conn==NULL) {
00250         msd->stat=NOOBJECT;
00251         return(2);}
00252  try
00253  {
00254   ((msdbConnect *) msd->conn)->session_begin(usern, passwd);
00255    msd->stat=LOGGEDIN;
00256  }
00257   catch(msdbException& p){ // intercept OTL exceptions
00258    cerr<<p.msg<<endl; // print out error message
00259    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00260    cerr<<p.var_info<<endl; // print out the variable that caused the error
00261    msd->stat=NOTLOGGEDIN;
00262   }
00263   return(0);
00264  }
00265 int msd_end(pMSDEnv msd){
00266         if (msd->conn==NULL) {
00267                 msd->stat=NOOBJECT;
00268                 return(2);}
00269 try
00270 {
00271   ((msdbConnect *) msd->conn)->session_end();
00272    msd->stat=LOGGEDOUT;
00273 }
00274 catch(msdbException& p){ // intercept OTL exceptions
00275    cerr<<p.msg<<endl; // print out error message
00276    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00277    cerr<<p.var_info<<endl; // print out the variable that caused the error
00278    msd->stat=NOTLOGGEDOUT;
00279 }
00280 return(0);
00281 }
00282 int msd_detach(pMSDEnv msd){
00283         
00284         if (msd->conn==NULL) {
00285                 msd->stat=NOOBJECT;
00286                 return(2);}
00287 try
00288 {
00289   ((msdbConnect *)msd->conn)->server_detach();
00290    msd->stat=DETACHED;
00291 }
00292 catch(msdbException& p){ // intercept OTL exceptions
00293    cerr<<p.msg<<endl; // print out error message
00294    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00295    cerr<<p.var_info<<endl; // print out the variable that caused the error
00296     msd->stat=NOTDETACHED;
00297 }
00298 return(0);
00299 }
00300 int msd_disconnect(pMSDEnv msd){
00301         
00302         if (msd->conn==NULL) {
00303                 msd->stat=NOOBJECT;
00304                 return(2);}
00305         try
00306 {
00307   ((msdbConnect *) msd->conn)->session_end();
00308   ((msdbConnect *) msd->conn)->server_detach();
00309   ((msdbConnect *) msd->conn)->logoff();
00310    delete  (msdbConnect *)msd->conn;
00311 }
00312 catch(msdbException& p){ // intercept OTL exceptions
00313    cerr<<p.msg<<endl; // print out error message
00314    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00315    cerr<<p.var_info<<endl; // print out the variable that caused the error
00316 }
00317 return(0);
00318 }
00319 
00320 #endif //MSD_ORACLE
00321 
00322 int msd_rlogin(pMSDEnv msd, char* loginstring){
00323         if (msd->conn==NULL) {
00324                 msd->stat=NOOBJECT;
00325                 return(2);}
00326         try
00327 {
00328    ((msdbConnect *) msd->conn)->rlogon(loginstring);
00329    msd->stat=LOGGEDIN;
00330 }
00331 catch(msdbException& p){ // intercept OTL exceptions
00332    cerr<<p.msg<<endl; // print out error message
00333    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00334    cerr<<p.var_info<<endl; // print out the variable that caused the error
00335    msd->stat=NOTLOGGEDIN;
00336 }
00337 return (0);
00338 }
00339  
00340 
00341 
00342 int msd_logoff(pMSDEnv msd){
00343         if (msd->conn==NULL) {
00344                 msd->stat=NOOBJECT;
00345                 return(2);}
00346 try
00347 {
00348   ((msdbConnect *) msd->conn)->logoff();
00349   msd->stat=LOGGEDOUT;
00350 
00351 }
00352 catch(msdbException& p){ // intercept OTL exceptions
00353    cerr<<p.msg<<endl; // print out error message
00354    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00355    cerr<<p.var_info<<endl; // print out the variable that caused the error
00356    msd->stat=NOTLOGGEDOUT;
00357 }
00358 return (0);
00359 }
00360 int  msd_free(pMSDEnv msd){
00361    if (msd->conn)
00362    {delete (msdbConnect *)msd->conn;
00363    }
00364    if (msd->select)
00365    {delete (MSDSelect *)msd->select;
00366    }
00367    
00368    #ifdef __WITH_XMMDB__
00369    if (msd->manager)
00370    {delete (MSDManager *)msd->manager;
00371    }
00372    #endif
00373  
00374   return (0);
00375 }
00376 
00377 
00378 
00379 extern int  msd_write_table_attributes(char* schema, char* connstr, char* fname){
00380  
00381  return WriteTableAttributes(schema,  connstr, fname);
00382 }
00383 
00384 extern int  msd_soap_data_generator(char* schema, char* connstr, char* fname){
00385  
00386  return SoapDataGenerator(schema, connstr, fname);
00387 }
00388 
00389 extern int  msd_get_tables_relations(char* schema, char* connstr){
00390  extern struct TableArray datawarehouse;
00391  return GetTablesRelations(schema, &datawarehouse, connstr);
00392 }
00393 
00394 extern int msd_get_datamodel(char* schema, char* connstr){
00395  extern struct TableArray datawarehouse;
00396  return GetDataModel(schema, &datawarehouse, connstr);
00397 }
00398 extern int msd_load_metadata(char* schema, char* connstr){
00399  
00400  return LoadMetaData(schema,  connstr);
00401 }
00402 
00404 // LISP Evaluator
00406 int msd_lisp_init(int argc, char* argv[]){
00407   printf("EBI-MSD's API Framework 1.00, 17 January 2002\n");  
00408   xlCallbacks *callbacks = xlDefaultCallbacks(argv[0]);
00409   xlInit(callbacks,argc,argv,NULL);
00410   xlInfo("%s",xlBanner());
00411   return (0);
00412 }
00413 int msd_lisp_load(char * fn){
00414         xlLoadFile(fn);
00415         return (0);
00416 }
00417 int msd_lisp_eval(void){
00418  xlCallFunctionByName(NULL,0,"*TOPLEVEL*",0); 
00419  return (0);
00420 }
00421  

Generated on Fri Apr 16 13:47:44 2004 for MSDAPI by doxygen 1.3.4-20031005