javaextensions/iapinfo/src.s60/javacommdb.cpp
branchRCL_3
changeset 66 2455ef1f5bbc
parent 65 ae942d28ec0e
child 71 d5e927d5853b
equal deleted inserted replaced
65:ae942d28ec0e 66:2455ef1f5bbc
    22 #include <e32base.h>
    22 #include <e32base.h>
    23 #include <e32debug.h>
    23 #include <e32debug.h>
    24 #include "logger.h"
    24 #include "logger.h"
    25 #include "javajniutils.h"
    25 #include "javajniutils.h"
    26 
    26 
    27 #include "fs_methodcall.h"
       
    28 #include "com_nokia_mid_iapinfo_IAPInfoImpl.h"
       
    29 
       
    30 using namespace CommsDat;
    27 using namespace CommsDat;
    31 using namespace java::util;
    28 using namespace java::util;
    32 
    29 
    33 // CONSTANTS
    30 // CONSTANTS
    34 _LIT(KIAPTable, "IAP");
    31 _LIT(KIAPTable, "IAP");
    36 _LIT(KGlobalSettingsTable, "GlobalSettings");
    33 _LIT(KGlobalSettingsTable, "GlobalSettings");
    37 //_LIT( KNetworkTable, "Network" );
    34 //_LIT( KNetworkTable, "Network" );
    38 _LIT(KFieldNameRecordId, "RecordId");
    35 _LIT(KFieldNameRecordId, "RecordId");
    39 _LIT(KFieldNameName, "Name");
    36 _LIT(KFieldNameName, "Name");
    40 
    37 
    41 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_IAPInfoImpl__1createSession
       
    42 (JNIEnv *, jobject)
       
    43 {
       
    44     IapInfoSession *sess = NULL;
       
    45     TRAPD(err,sess =  IapInfoSession::NewL(););
       
    46     if (err!=KErrNone)
       
    47     {
       
    48         return err;
       
    49     }
       
    50     return reinterpret_cast<int>(sess);
       
    51 
       
    52 }
       
    53 
       
    54 
       
    55 JNIEXPORT void JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1destroy(JNIEnv* ,
    38 JNIEXPORT void JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1destroy(JNIEnv* ,
    56         jclass,
    39         jclass,
    57         jint /*aHandle*/)
    40         jint aHandle)
    58 {
    41 {
    59     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + destroy()");
    42     LOG1(ESOCKET, EInfo, "CJAVACOMMDB + destroy() handle: %D", aHandle);
    60     // JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
    43     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
    61     //  delete commdb;
    44     delete commdb;
    62     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - destroy()");
    45     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - destroy()");
    63 }
    46 }
    64 
    47 
       
    48 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1construct(JNIEnv* ,
       
    49         jclass)
       
    50 {
       
    51     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + construct()");
       
    52     JavaCommDB *cdb = new JavaCommDB();
       
    53     TInt handle = reinterpret_cast<jint>(cdb);
       
    54     LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB - construct() handle: %D", handle);
       
    55     return handle;
       
    56 }
    65 
    57 
    66 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1open(JNIEnv* aJni,
    58 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1open(JNIEnv* aJni,
    67         jclass, jint aSessionHandle,
    59         jclass, jint aHandle,
    68         jstring aTableName)
    60         jstring aTableName)
    69 {
    61 {
    70     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + open()gggggggggg");
    62     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + open()");
    71     IapInfoSession* session = reinterpret_cast<IapInfoSession *>(aSessionHandle);
    63     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
    72     JavaCommDB *cdb = new JavaCommDB(session);
       
    73     JStringUtils table(*aJni, aTableName);
    64     JStringUtils table(*aJni, aTableName);
    74     int err = -1;
    65 
    75     TRAP(err,CallMethodL(cdb, &JavaCommDB::OpenL,table,cdb->iSession););
    66     //LOG1(EJavaIapInfo,  EInfo,  "CJAVACOMMDB opening table: %S", table );
    76     TInt handle = reinterpret_cast<jint>(cdb);
    67     TRAPD(error, commdb->OpenL(table));
    77     if (err < 0)
    68     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - open()");
    78         handle = err;
    69     return error;
    79     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - open()hhhhhh");
    70 }
    80     return handle;
       
    81 }
       
    82 
       
    83 
    71 
    84 JNIEXPORT void JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1close(JNIEnv* ,
    72 JNIEXPORT void JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1close(JNIEnv* ,
    85         jclass, jint aHandle)
    73         jclass, jint aHandle)
    86 {
    74 {
    87     LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB + close() handle: %D", aHandle);
    75     LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB + close() handle: %D", aHandle);
    88     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
    76     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
    89     CallMethod(commdb, &JavaCommDB::Close,commdb->iSession);
    77     TRAP_IGNORE(commdb->Close());
    90     //TRAP_IGNORE(commdb->Close());
       
    91     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - close()");
    78     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - close()");
    92 }
    79 }
    93 
    80 
    94 void JavaCommDB::Destroy(JavaCommDB* aObj)
       
    95 {
       
    96     delete aObj;
       
    97 
       
    98 }
       
    99 
       
   100 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1getRecordCount(JNIEnv* ,
    81 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1getRecordCount(JNIEnv* ,
   101         jclass,
    82         jclass,
   102         jint aHandle)
    83         jint aHandle)
   103 {
    84 {
   104     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + getRecordCount()");
    85     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + getRecordCount()");
   105     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
    86     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   106     TInt count = 0;
    87     TInt count = 0;
   107     CallMethod(count, commdb, &JavaCommDB::GetRecordCount,commdb->iSession);
    88     count = commdb->GetRecordCount();
   108     //count = commdb->GetRecordCount();
       
   109     LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB returning value: %D", count);
    89     LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB returning value: %D", count);
   110     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - getRecordCount()");
    90     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - getRecordCount()");
   111     return count;
    91     return count;
   112 }
    92 }
   113 
    93 
   122 
   102 
   123     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   103     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   124     JStringUtils field(*aJni, aFieldName);
   104     JStringUtils field(*aJni, aFieldName);
   125 
   105 
   126     //LOG1(EJavaIapInfo,  EInfo,  "CJAVACOMMDB  reading field value: %S", field );
   106     //LOG1(EJavaIapInfo,  EInfo,  "CJAVACOMMDB  reading field value: %S", field );
   127 
   107     TRAPD(err, value = commdb->GetIntFieldValueL(field));
   128     TRAPD(err,CallMethodL(value, commdb, &JavaCommDB::GetIntFieldValueL,field,commdb->iSession););
       
   129     //TRAPD(err, value = commdb->GetIntFieldValueL(field));
       
   130 
   108 
   131     // Put the native error code into the Java error array
   109     // Put the native error code into the Java error array
   132     jint javaError[1] =
   110     jint javaError[1] =
   133         {   err};
   111         {   err};
   134     aJni->SetIntArrayRegion(aError, 0, 1, javaError);
   112     aJni->SetIntArrayRegion(aError, 0, 1, javaError);
   151 
   129 
   152     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   130     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   153     JStringUtils field(*aJni, aFieldName);
   131     JStringUtils field(*aJni, aFieldName);
   154 
   132 
   155     //LOG1(EJavaIapInfo,  EInfo,  "CJAVACOMMDB  reading field value: %S", field );
   133     //LOG1(EJavaIapInfo,  EInfo,  "CJAVACOMMDB  reading field value: %S", field );
   156     TRAPD(err,CallMethodL(value, commdb, &JavaCommDB::GetStringFieldValueL,field,commdb->iSession););
   134     TRAPD(err, value = commdb->GetStringFieldValueL(field));
   157     // TRAPD(err, value = commdb->GetStringFieldValueL(field));
       
   158     if (NULL != value && KErrNone == err)
   135     if (NULL != value && KErrNone == err)
   159     {
   136     {
   160         str = S60CommonUtils::NativeToJavaString(*aJni, value->Des());
   137         str = S60CommonUtils::NativeToJavaString(*aJni, value->Des());
   161         //LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB  returning value: %S", value->Des() );
   138         //LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB  returning value: %S", value->Des() );
   162         delete value;
   139         delete value;
   174 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1next(JNIEnv* ,
   151 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1next(JNIEnv* ,
   175         jclass, jint aHandle)
   152         jclass, jint aHandle)
   176 {
   153 {
   177     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + next()");
   154     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + next()");
   178     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   155     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   179     TInt rec;
   156     TInt rec = commdb->Next();
   180     CallMethod(rec, commdb, &JavaCommDB::Next,commdb->iSession);
       
   181     //TInt rec = commdb->Next();
       
   182     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - next()");
   157     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - next()");
   183     return rec;
   158     return rec;
   184 }
   159 }
   185 
   160 
   186 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1previous(JNIEnv* ,
   161 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1previous(JNIEnv* ,
   197 {
   172 {
   198     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + findById()");
   173     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + findById()");
   199     TInt recId = 0;
   174     TInt recId = 0;
   200 
   175 
   201     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   176     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   202     CallMethod(recId, commdb, &JavaCommDB::FindById,aId,commdb->iSession);
   177     recId = commdb->FindById(aId);
   203     //recId = commdb->FindById(aId);
       
   204     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - findById()");
   178     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - findById()");
   205     return recId;
   179     return recId;
   206 }
   180 }
   207 
   181 
   208 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1findByName(JNIEnv* aJni,
   182 JNIEXPORT jint JNICALL Java_com_nokia_mid_iapinfo_CommsTable__1findByName(JNIEnv* aJni,
   213     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + findByName()");
   187     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + findByName()");
   214     TInt recId = 0;
   188     TInt recId = 0;
   215     JStringUtils name(*aJni, aName);
   189     JStringUtils name(*aJni, aName);
   216 
   190 
   217     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   191     JavaCommDB* commdb = reinterpret_cast<JavaCommDB *>(aHandle);
   218     TRAPD(err,CallMethodL(recId, commdb, &JavaCommDB::FindByNameL,name,commdb->iSession););
   192     TRAP(recId, recId = commdb->FindByNameL(name));
   219     if (err < KErrNone)
       
   220         recId = err;
       
   221     //TRAP(recId, recId = commdb->FindByNameL(name));
       
   222     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - findByName()");
   193     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - findByName()");
   223     return recId;
   194     return recId;
   224 }
   195 }
   225 
   196 
   226 /* ---------------------------------------------------------------------------
   197 /* ---------------------------------------------------------------------------
   227  *    JavaCommDB class implementation ;
   198  *    JavaCommDB class implementation ;
   228  * ---------------------------------------------------------------------------
   199  * ---------------------------------------------------------------------------
   229  */
   200  */
   230 
   201 
   231 JavaCommDB::JavaCommDB(IapInfoSession *aSession)
       
   232 {
       
   233     iSession = aSession;
       
   234 
       
   235 
       
   236 }
       
   237 
       
   238 // ---------------------------------------------------------------------------
   202 // ---------------------------------------------------------------------------
   239 //    Delete allocated member objects.
   203 //    Delete allocated member objects.
   240 // -----------------------------------------------------------------------------
   204 // -----------------------------------------------------------------------------
   241 JavaCommDB::~JavaCommDB()
   205 JavaCommDB::~JavaCommDB()
   242 {
   206 {
   245     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB  - ~JavaCommDB()");
   209     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB  - ~JavaCommDB()");
   246 }
   210 }
   247 
   211 
   248 // ---------------------------------------------------------------------------
   212 // ---------------------------------------------------------------------------
   249 //    Delete allocated member objects.
   213 //    Delete allocated member objects.
   250 // -----------------------------------------------------------------------------
   214 //    @return error code
   251 void JavaCommDB::Close()
   215 // -----------------------------------------------------------------------------
       
   216 TInt JavaCommDB::Close()
   252 {
   217 {
   253     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + Close()");
   218     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB + Close()");
   254     iCurrentRecord = 0;
   219     iCurrentRecord = 0;
   255     if (iTable)
   220     delete iTable;
   256         delete iTable;
       
   257 
       
   258     iTable = NULL;
   221     iTable = NULL;
       
   222     delete iDb;
       
   223     iDb = NULL;
   259 
   224 
   260     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - Close()");
   225     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - Close()");
   261 
   226     return KErrNone;
   262 }
   227 }
   263 
   228 
   264 // ---------------------------------------------------------------------------
   229 // ---------------------------------------------------------------------------
   265 //    Opens the given table.
   230 //    Opens the given table.
   266 //    @param aTablename name of the CommDB table to be opened
   231 //    @param aTablename name of the CommDB table to be opened
   267 //    @return error code
   232 //    @return error code
   268 // -----------------------------------------------------------------------------
   233 // -----------------------------------------------------------------------------
   269 void JavaCommDB::OpenL(const TDesC& aTableName)
   234 void JavaCommDB::OpenL(const TDesC& aTableName)
   270 {
   235 {
   271     //LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB + OpenL(): open table: %S",   aTableName);
   236     //LOG1(EJavaIapInfo, EInfo, "CJAVACOMMDB + OpenL(): open table: %S",   aTableName);
   272     //iDb = CMDBSession::NewL(KCDVersion1_1);
   237     iDb = CMDBSession::NewL(KCDVersion1_1);
   273     iCurrentRecord = 0;
   238     iCurrentRecord = 0;
   274 
   239 
   275     if (0 == aTableName.Compare(KIAPTable))
   240     if (0 == aTableName.Compare(KIAPTable))
   276     {
   241     {
   277         // Create IAP table recordset
   242         // Create IAP table recordset
   292                  CCDConnectionPrefsRecord> (KCDTIdConnectionPrefsRecord);
   257                  CCDConnectionPrefsRecord> (KCDTIdConnectionPrefsRecord);
   293         LOG(EJavaIapInfo, EInfo,
   258         LOG(EJavaIapInfo, EInfo,
   294             "CJAVACOMMDB  OpenL(): ConnectionPreferences table opened.");
   259             "CJAVACOMMDB  OpenL(): ConnectionPreferences table opened.");
   295     }
   260     }
   296     // Load the table
   261     // Load the table
   297 
   262     iTable->LoadL(*iDb);
   298     iTable->LoadL(*(iSession->iDb));
       
   299     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - OpenL()");
   263     LOG(EJavaIapInfo, EInfo, "CJAVACOMMDB - OpenL()");
   300 }
   264 }
   301 
   265 
   302 // ---------------------------------------------------------------------------
   266 // ---------------------------------------------------------------------------
   303 //    Get number of records in the current table.
   267 //    Get number of records in the current table.