00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdio.h>
00016 #include <jni.h>
00017 #include "MSDJapi.h"
00018 #ifndef __MSD_USER_H__
00019 #include "msd_user.h"
00020 #endif
00021
00022
00023 extern "C" {static pMSDEnv ptr2MSDEnv = new MSDEnv;}
00024
00025
00026
00027
00028 JNIEXPORT jint JNICALL Java_MSDJapi_initMSDJapi(
00029 JNIEnv * env ,
00030 jobject this_object
00031
00032 )
00033 {
00034 msd_init(ptr2MSDEnv);
00035 if (ptr2MSDEnv->stat==INIT){
00036 printf ("\nConnection to the PDBe initialized.\n");
00037 }
00038
00039
00040
00041 }
00042
00043 JNIEXPORT jint JNICALL Java_MSDJapi_rloginMSDJapi(
00044 JNIEnv * env ,
00045 jobject this_object,
00046 jstring loginstring
00047 )
00048 {
00049 char buf[128];
00050 if (ptr2MSDEnv->stat==INIT){
00051 const char * cloginstring= env->GetStringUTFChars(loginstring, 0);
00052 strcpy(buf, cloginstring);
00053 msd_rlogin(ptr2MSDEnv,buf);
00054 if (ptr2MSDEnv->stat==LOGGEDIN)
00055 {
00056 printf ("\nrlogin to the '%s' server successfully.\n", buf);
00057 }
00058 env->ReleaseStringUTFChars(loginstring, cloginstring);
00059
00060 }
00061 }
00062
00063
00064 JNIEXPORT jint JNICALL Java_MSDJapi_attachMSDJapi(
00065 JNIEnv * env ,
00066 jobject this_object ,
00067 jstring host
00068 )
00069 {
00070
00071 char buf[128];
00072 const char * chost= env->GetStringUTFChars(host, 0);
00073 strcpy(buf, chost);
00074 if (msd_attach(ptr2MSDEnv,buf)==0)
00075 {
00076 printf ("\nAttached to '%s' server successfully.\n", buf);
00077 }
00078
00079
00080 env->ReleaseStringUTFChars(host, chost);
00081
00082
00083 }
00084
00085 JNIEXPORT jint JNICALL Java_MSDJapi_beginMSDJapi(
00086 JNIEnv * env ,
00087 jobject this_object ,
00088 jstring user ,
00089 jstring pass
00090 )
00091 {char buf1[128];
00092 char buf2[128];
00093 const char * cuser= env->GetStringUTFChars(user, 0);
00094 strcpy(buf1, cuser);
00095 env->ReleaseStringUTFChars(user, cuser);
00096 const char * cpass= env->GetStringUTFChars(pass, 0);
00097 strcpy(buf2, cpass);
00098 env->ReleaseStringUTFChars(pass, cpass);
00099 printf ("\nUser '%s' logging...\n", buf1);
00100 if (msd_begin(ptr2MSDEnv,buf1,buf2)==0)
00101 {
00102 printf ("\nUser '%s' logged in successfully.\n", buf1);
00103 }else fprintf(stderr, "Login failed");
00104
00105
00106 }
00107
00108 JNIEXPORT jint JNICALL Java_MSDJapi_sqlinitMSDJapi(
00109 JNIEnv * env ,
00110 jobject this_object ,
00111 jstring sql
00112 )
00113 {
00114 char buf[3072];
00115 const char * csql= env->GetStringUTFChars(sql, 0);
00116 sprintf(buf, "%s", csql);
00117
00118 msd_sqlinit(ptr2MSDEnv,buf);
00119 if (ptr2MSDEnv->stat==LOGGEDIN)
00120 {
00121 printf ("\nSQL sratement: '%s' initialized successfully.\n", csql);
00122 }
00123 env->ReleaseStringUTFChars(sql, csql);
00124 }
00125
00126
00127 JNIEXPORT jint JNICALL Java_MSDJapi_setcriteriaMSDJapi(
00128 JNIEnv * env ,
00129 jobject this_object ,
00130 jstring fmt ,
00131 jobjectArray arglist
00132 )
00133 {char buf[16];
00134 if (ptr2MSDEnv->conn==NULL) {return(2);}
00135 const char * ps= env->GetStringUTFChars(fmt, 0);
00136 char p[128];
00137 sprintf(p,ps);
00138 int j=0;
00139
00140 while(p[j] != '\0'){
00141 if (p[j]=='i')
00142 {
00143 jstring s =(jstring)env->GetObjectArrayElement(arglist, j);
00144 const char * cs= env->GetStringUTFChars(s, 0);
00145 strcpy(buf, cs);
00146 int i = atoi(buf);
00147 ((MSDSelect *) ptr2MSDEnv->select)->SetCriteria(i);
00148 env->ReleaseStringUTFChars(s, cs);
00149 }
00150 else if (p[j]=='d')
00151 {
00152 jstring s =(jstring)env->GetObjectArrayElement(arglist, j);
00153 const char * cs= env->GetStringUTFChars(s, 0);
00154 strcpy(buf, cs);
00155 double d = atof(buf);
00156 ((MSDSelect *) ptr2MSDEnv->select)->SetCriteria(d);
00157 env->ReleaseStringUTFChars(s, cs);
00158 }
00159 else if (p[j]=='s')
00160 {
00161 jstring s =(jstring)env->GetObjectArrayElement(arglist, j);
00162 const char * cs= env->GetStringUTFChars(s, 0);
00163 strcpy(buf, cs);
00164 ((MSDSelect *) ptr2MSDEnv->select)->SetCriteria(buf);
00165 env->ReleaseStringUTFChars(s, cs);
00166 }
00167 else
00168 {
00169 fprintf(stderr,"\nunsupported format flag");
00170 break;
00171 }
00172 j++;
00173 }
00174 env->ReleaseStringUTFChars(fmt, ps);
00175 ((MSDSelect *) ptr2MSDEnv->select)->MakeRecord();
00176
00177 }
00178
00179
00180
00181
00182 JNIEXPORT jint JNICALL Java_MSDJapi_getrownumMSDJapi(
00183 JNIEnv * env ,
00184 jobject this_object
00185 )
00186 {
00187 return ((MSDSelect *) ptr2MSDEnv->select)->GetRowNum();
00188 }
00189
00190
00191 JNIEXPORT jint JNICALL Java_MSDJapi_getnextMSDJapi(
00192 JNIEnv * env ,
00193 jobject this_object
00194 )
00195 {msd_getnext(ptr2MSDEnv);
00196
00197 }
00198
00199 JNIEXPORT jfloat JNICALL Java_MSDJapi_getfloatMSDJapi(
00200 JNIEnv * env ,
00201 jobject this_object ,
00202 jint col
00203 )
00204 {return msd_ugetfloat(ptr2MSDEnv,col);
00205 }
00206
00207 JNIEXPORT jint JNICALL Java_MSDJapi_getintMSDJapi(
00208 JNIEnv * env ,
00209 jobject this_object ,
00210 jint col
00211 )
00212 {return msd_ugetint(ptr2MSDEnv,col);
00213 }
00214
00215 JNIEXPORT jdouble JNICALL Java_MSDJapi_getdoubleMSDJapi(
00216 JNIEnv * env ,
00217 jobject this_object ,
00218 jint col
00219 )
00220 {return msd_ugetdouble(ptr2MSDEnv,col);
00221 }
00222
00223 JNIEXPORT jstring JNICALL Java_MSDJapi_getstrMSDJapi(
00224 JNIEnv * env ,
00225 jobject this_object ,
00226 jint col
00227 )
00228 {char* strval;
00229 static char buf[1024];
00230 sprintf(buf,"%s",msd_ugetstr(ptr2MSDEnv,col,strval));
00231 return env->NewStringUTF( buf);
00232 }
00233
00234 JNIEXPORT jint JNICALL Java_MSDJapi_endMSDJapi(
00235 JNIEnv * env ,
00236 jobject this_object
00237 )
00238 { return msd_end(ptr2MSDEnv);
00239 }
00240
00241 JNIEXPORT jint JNICALL Java_MSDJapi_detachMSDJapi(
00242 JNIEnv * env ,
00243 jobject this_object
00244 )
00245 { return msd_detach(ptr2MSDEnv);
00246 }
00247
00248 JNIEXPORT jint JNICALL Java_MSDJapi_logoffMSDJapi(
00249 JNIEnv * env ,
00250 jobject this_object
00251 )
00252 { return msd_logoff(ptr2MSDEnv);
00253 }
00254
00255 JNIEXPORT jint JNICALL Java_MSDJapi_freeMSDJapi(
00256 JNIEnv * env ,
00257 jobject this_object
00258 )
00259 { return msd_free(ptr2MSDEnv);
00260 }
00261
00262
00263 JNIEXPORT jstring JNICALL Java_MSDJapi_getAccessionCodeMSDJapi(
00264 JNIEnv * env ,
00265 jobject this_object ,
00266 jint eID
00267 )
00268 { static char buf[16];
00269 sprintf(buf,"%s", msd_get_accession_code(ptr2MSDEnv, eID));
00270 return env->NewStringUTF( buf );
00271 }
00272
00273 JNIEXPORT jint JNICALL Java_MSDJapi_getEntryIDMSDJapi(
00274 JNIEnv * env ,
00275 jobject this_object ,
00276 jstring acc_code
00277 )
00278 {char buf[16];
00279 const char * cacc_code= env->GetStringUTFChars(acc_code, 0);
00280 sprintf(buf, "%s", cacc_code);
00281 jint ret = msd_get_entry_id(ptr2MSDEnv,buf);
00282 env->ReleaseStringUTFChars(acc_code, cacc_code);
00283 return ret;
00284 }
00285
00286
00287 JNIEXPORT jint JNICALL Java_MSDJapi_managerMSDJapi(
00288 JNIEnv * env ,
00289 jobject this_object
00290 )
00291 { return msd_manager(ptr2MSDEnv);
00292 }
00293
00294 JNIEXPORT jint JNICALL Java_MSDJapi_getObjectEntryMSDJapi(
00295 JNIEnv * env ,
00296 jobject this_object ,
00297 jint eID
00298 )
00299 {return msd_get_object_entry(ptr2MSDEnv,eID);
00300 }
00301
00302 JNIEXPORT jint JNICALL Java_MSDJapi_getNumOfAtomsMSDJapi(
00303 JNIEnv * env ,
00304 jobject this_object
00305 )
00306 {return msd_get_number_of_atoms(ptr2MSDEnv);
00307 }
00308
00309
00310
00311 JNIEXPORT jint JNICALL Java_MSDJapi_printfMSDJapi(
00312 JNIEnv * env ,
00313 jobject this_object,
00314 jstring text
00315 )
00316 {
00317 char buf[128];
00318 const char * ctext= env->GetStringUTFChars(text, 0);
00319 strcpy(buf, ctext);
00320 printf( "MSDJapi.printfMSDJapi( \"%s\" )\n", buf);
00321 env->ReleaseStringUTFChars(text, ctext);
00322 }
00323