00001 #include<AbsSqlStatement.h>
00002 #include<SqlFactory.h>
00003
00004 #include <jni.h>
00005
00006
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #endif
00010
00011
00012
00013
00014
00015 JNIEXPORT void JNICALL Java_csql_jdbc_JSqlConnection_alloc
00016 (JNIEnv *env, jobject obj, jint mode)
00017 {
00018 jclass cls;
00019 jfieldID fid;
00020
00021
00022 AbsSqlConnection *con;
00023 if (mode ==1 )
00024 con = SqlFactory::createConnection(CSql);
00025 else
00026 con = SqlFactory::createConnection(CSqlGateway);
00027
00028 cls = env->GetObjectClass( obj );
00029 fid = env->GetFieldID( cls, "sqlConPtr", "J");
00030 if (fid == 0)
00031 {
00032 jclass Exception = env->FindClass("java/lang/Exception");
00033 env->ThrowNew(Exception,"JNI: GetFieldID failed.\n");
00034 return;
00035 }
00036 env->SetLongField( obj, fid, (jlong) con );
00037 return;
00038 }
00039
00040
00041
00042
00043
00044
00045 JNIEXPORT void JNICALL Java_csql_jdbc_JSqlConnection_free
00046 (JNIEnv *env, jobject obj)
00047 {
00048 jclass cls;
00049 jfieldID fid;
00050
00051 cls = env->GetObjectClass( obj );
00052 fid = env->GetFieldID( cls, "sqlConPtr", "J");
00053 if (fid == 0)
00054 {
00055 jclass Exception = env->FindClass("java/lang/Exception");
00056 env->ThrowNew(Exception,"JNI: GetFieldID failed.\n");
00057 return;
00058 }
00059 AbsSqlConnection *con = (AbsSqlConnection*) env->GetLongField( obj, fid );
00060 delete con;
00061 return;
00062 }
00063
00064
00065
00066
00067
00068
00069 JNIEXPORT jint JNICALL Java_csql_jdbc_JSqlConnection_connect
00070 (JNIEnv *env, jobject obj, jstring user, jstring pass)
00071 {
00072 jclass cls;
00073 jfieldID fid;
00074 char *username=0, *password=0;
00075
00076 cls = env->GetObjectClass( obj );
00077 fid = env->GetFieldID( cls, "sqlConPtr", "J");
00078 if (fid == 0)
00079 {
00080 jclass Exception = env->FindClass("java/lang/Exception");
00081 env->ThrowNew(Exception,"JNI: GetFieldID failed.\n");
00082 return( -1 );
00083 }
00084 AbsSqlConnection *con = (AbsSqlConnection*) env->GetLongField( obj, fid );
00085 jboolean isCopy = JNI_TRUE;
00086 username = (char*) env->GetStringUTFChars( user, &isCopy );
00087 password = (char*) env->GetStringUTFChars( pass, &isCopy );
00088 jint rv = (jint) con->connect(username, password);
00089 return rv;
00090 }
00091
00092
00093
00094
00095
00096
00097 JNIEXPORT jint JNICALL Java_csql_jdbc_JSqlConnection_disconnect
00098 (JNIEnv *env, jobject obj)
00099 {
00100 jclass cls;
00101 jfieldID fid;
00102
00103 cls = env->GetObjectClass( obj );
00104 fid = env->GetFieldID( cls, "sqlConPtr", "J");
00105 if (fid == 0)
00106 {
00107 jclass Exception = env->FindClass("java/lang/Exception");
00108 env->ThrowNew(Exception,"JNI: GetFieldID failed.\n");
00109 return( -1 );
00110 }
00111 AbsSqlConnection *con = (AbsSqlConnection*) env->GetLongField( obj, fid );
00112 jint rv = (jint) con->disconnect();
00113 return rv;
00114
00115 }
00116
00117
00118
00119
00120
00121
00122 JNIEXPORT jboolean JNICALL Java_csql_jdbc_JSqlConnection_isOpen
00123 (JNIEnv *env, jobject obj)
00124 {
00125
00126 return false;
00127 }
00128
00129
00130
00131
00132
00133
00134 JNIEXPORT jint JNICALL Java_csql_jdbc_JSqlConnection_beginTrans
00135 (JNIEnv *env, jobject obj, jint type)
00136 {
00137 jclass cls;
00138 jfieldID fid;
00139
00140 cls = env->GetObjectClass( obj );
00141 fid = env->GetFieldID( cls, "sqlConPtr", "J");
00142 if (fid == 0)
00143 {
00144 jclass Exception = env->FindClass("java/lang/Exception");
00145 env->ThrowNew(Exception,"JNI: GetFieldID failed.\n");
00146 return( -1 );
00147 }
00148 AbsSqlConnection *con = (AbsSqlConnection*) env->GetLongField( obj, fid );
00149 jint rv = (jint) con->beginTrans((IsolationLevel) type );
00150 return rv;
00151 }
00152
00153
00154
00155
00156
00157
00158 JNIEXPORT jint JNICALL Java_csql_jdbc_JSqlConnection_commit
00159 (JNIEnv *env, jobject obj)
00160 {
00161 jclass cls;
00162 jfieldID fid;
00163
00164 cls = env->GetObjectClass( obj );
00165 fid = env->GetFieldID( cls, "sqlConPtr", "J");
00166 if (fid == 0)
00167 {
00168 jclass Exception = env->FindClass("java/lang/Exception");
00169 env->ThrowNew(Exception,"JNI: GetFieldID failed.\n");
00170 return( -1 );
00171 }
00172 AbsSqlConnection *con = (AbsSqlConnection*) env->GetLongField( obj, fid );
00173 jint rv = (jint) con->commit();
00174 return rv;
00175
00176 }
00177
00178
00179
00180
00181
00182
00183 JNIEXPORT jint JNICALL Java_csql_jdbc_JSqlConnection_rollback
00184 (JNIEnv *env, jobject obj)
00185 {
00186 jclass cls;
00187 jfieldID fid;
00188
00189 cls = env->GetObjectClass( obj );
00190 fid = env->GetFieldID( cls, "sqlConPtr", "J");
00191 if (fid == 0)
00192 {
00193 jclass Exception = env->FindClass("java/lang/Exception");
00194 env->ThrowNew(Exception,"JNI: GetFieldID failed.\n");
00195 return( -1 );
00196 }
00197 AbsSqlConnection *con = (AbsSqlConnection*) env->GetLongField( obj, fid );
00198 jint rv = (jint) con->rollback();
00199 return rv;
00200
00201 }
00202
00203 #ifdef __cplusplus
00204 }
00205 #endif