javacommons/javastorage/src.s60/client/javadataaccessimpl.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  JavaDataAccessImpl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef JAVADATAACCESSIMPL_H
       
    20 #define JAVADATAACCESSIMPL_H
       
    21 
       
    22 #include <sqldb.h>
       
    23 
       
    24 #include "javadataaccess.h"
       
    25 #include "javaosheaders.h"
       
    26 
       
    27 namespace java
       
    28 {
       
    29 namespace comms
       
    30 {
       
    31 class CommsMessage;
       
    32 }    // end namespace comms
       
    33 namespace storage
       
    34 {
       
    35 
       
    36 class JavaStorageException;
       
    37 
       
    38 /**
       
    39  * JavaDataAccessImpl implements JavaDataAccess interface.
       
    40  */
       
    41 OS_NONSHARABLE_CLASS(JavaDataAccessImpl) : public JavaDataAccess
       
    42 {
       
    43 
       
    44     friend class JavaDataAccess;
       
    45 
       
    46 public:
       
    47     /**
       
    48      * Destructor. If destructor is called while having active connection
       
    49      * Connection is rollbacked and closed before closing database connection.
       
    50      */
       
    51     OS_IMPORT virtual ~JavaDataAccessImpl();
       
    52 
       
    53     /**
       
    54      * Open given storage. If storage does not exists it is created. If storage
       
    55      * is default system storage also database schema is created.
       
    56      *
       
    57      * @param aHeaders connection headers.
       
    58      * @param aStorageName storage name.
       
    59      * @param[out] aReceiveMessage response message.
       
    60      * @throws JavaStorageException if communication fails.
       
    61      */
       
    62     OS_IMPORT virtual void open(const std::string& aHeaders,
       
    63                                 const std::string& aStorageName,
       
    64                                 comms::CommsMessage& aReceivedMessage)
       
    65     throw(JavaStorageException);
       
    66 
       
    67     /**
       
    68      * Close storage. If storage has ongoing session it is rollbacked.
       
    69      *
       
    70      * @param aHeaders connection headers.
       
    71      * @param[out] aReceiveMessage response message.
       
    72      * @throws JavaStorageException if communication fails.
       
    73      */
       
    74     OS_IMPORT virtual void close(const std::string& aHeaders,
       
    75                                  comms::CommsMessage& aReceivedMessage)
       
    76     throw(JavaStorageException);
       
    77 
       
    78     /**
       
    79      * Execute given SQL statement against database and create response.
       
    80      *
       
    81      * @param aHeaders connection headers.
       
    82      * @param aSqlStatement SQL statement.
       
    83      * @param[out] aReceiveMessage received comms message.
       
    84      * @throws JavaStorageException if communication fails.
       
    85      */
       
    86     OS_IMPORT virtual void execute(const std::string& aHeaders,
       
    87                                    const std::wstring& aSqlStatement,
       
    88                                    comms::CommsMessage& aReceivedMessage)
       
    89     throw(JavaStorageException);
       
    90 
       
    91 private:
       
    92     JavaDataAccessImpl();
       
    93 
       
    94     /**
       
    95      * Check whether given storage is initialized or not.
       
    96      * Supports only predefined tables. If table is not predefined
       
    97      * false is returned.
       
    98      *
       
    99      * @param aStorageName to be checked is initialized.
       
   100      * @return true if already initialized, false otherwise.
       
   101      */
       
   102     bool isDBInitialized(const std::string& aStorageName);
       
   103 
       
   104     /**
       
   105      * Open given storage. If open fails storage is created and
       
   106      * initialized. If storage is not predefined storage is created but not
       
   107      * initialized.
       
   108      *
       
   109      * @param aStorageName to be opened.
       
   110      * @throws JavaStorageException if storage creation fails.
       
   111      */
       
   112     void openDatabase(const std::string& aStorageName)
       
   113     throw(JavaStorageException);
       
   114 
       
   115     /**
       
   116      * Create database. Database is created to Symbian's SqlServer private
       
   117      * data cage with predefined security policy.
       
   118      *
       
   119      * @param aDbName to be created.
       
   120      * @param aIsDefault is this default database.
       
   121      * @throws JavaStorageException if database creation fails. Failure code
       
   122      *         is stored to Exception status code.
       
   123      */
       
   124     void createDatabase(const TDesC& aDbName, bool aIsDefault)
       
   125     throw(JavaStorageException);
       
   126 
       
   127     /**
       
   128      * Create single table to storage.
       
   129      *
       
   130      * @param aSqlStatement containing storage creation statement.
       
   131      * @throws JavaStorageException if table creation failed.
       
   132      */
       
   133     void createTable(const TDesC& aStatement) throw(JavaStorageException);
       
   134 
       
   135     /**
       
   136      * Initialise given storage. Create database structures.
       
   137      *
       
   138      * @param aStorageName storage to be initialized.
       
   139      * @throws JavaStorageException if table creation fails.
       
   140      */
       
   141     void initializeDatabase(const std::string& aStorageName)
       
   142     throw(JavaStorageException);
       
   143 
       
   144     /**
       
   145      * Read column name from statement.
       
   146      *
       
   147      * @param aIndex Index where name is read.
       
   148      * @param aStmt Statement where name is read.
       
   149      * @param[out] aColName column name.
       
   150      */
       
   151     void columnName(int aIndex,
       
   152                     RSqlStatement& aStmt,
       
   153                     std::wstring& aColName);
       
   154 
       
   155     /**
       
   156      * Read column value from statement.
       
   157      *
       
   158      * @param aIndex Index where value is read.
       
   159      * @param aStmt Statement where value is read.
       
   160      * @param aColumnType Column type.
       
   161      * @param[out] aColValue column value.
       
   162      */
       
   163     void columnValue(const int aIndex,
       
   164                      RSqlStatement& aStmt,
       
   165                      const TSqlColumnType aColumnType,
       
   166                      std::wstring& aColValue);
       
   167 
       
   168 private:
       
   169     bool mConnOpen;
       
   170     bool mHavingTransaction;
       
   171     std::string mSessionId;
       
   172     RSqlDatabase mDatabase;
       
   173 };
       
   174 
       
   175 } // end namespace storage
       
   176 } // end namespace java
       
   177 
       
   178 #endif // JAVADATAACCESSIMPL_H
       
   179