Tizen 2.1 base
[apps/osp/Home.git] / inc / HmGenericDatabaseManager.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        HmGenericDatabaseManager.h
19  * @brief       Keeps the declaration of DatabaseManager and related interfaces
20  * declaration of the various functions which may be needed for various database operations
21  */
22
23 #ifndef _HM_GENERIC_DATABASE_MANAGER_H_
24 #define _HM_GENERIC_DATABASE_MANAGER_H_
25
26 #include <FBase.h>
27 #include <FIo.h>
28
29 /**
30  * @class       GenericDatabaseManager
31  * @brief       The class contains declaration of various database functions.
32  */
33 class GenericDatabaseManager
34         : public Tizen::Base::Object
35 {
36 public:
37         /**
38          * Returns an object of the database manager
39          *
40          * @return              HomeDatabaseManager*, pointer to the singleton object of HomeDatabaseManager
41          */
42         static GenericDatabaseManager* GetInstance(void);
43
44         /**
45          * Creates or opens(if already created) the database.
46          *
47          * @return              E_SUCCESS in case of success else system wide error code
48          * @param[in]   dbName, absolute path for the database file.
49          */
50         result CreateDataBase(const Tizen::Base::String& dbName);
51
52         /**
53          * Creates a Table of given name if not already exists.
54          *
55          * @return              E_SUCCESS in case of success else system wide error code
56          * @param[in]   tableName, name of the table to be created.
57          * @param[in]   pColumnNames, the names for each columns in the table
58          * @param[in]   pColumnTypes, the type of corresponding column names
59          */
60         result CreateTable(const Tizen::Base::String& tableName, Tizen::Base::Collection::ArrayList* pColumnNames, Tizen::Base::Collection::ArrayList* pColumnTypes);
61
62         /**
63          * Deletes records from the table
64          *
65          * @return              E_SUCCESS in case of success else system wide error code
66          * @param[in]   tableName, the table name from which the rows to be deleted
67          * @param[in]   whereCondition, the criteria to select the correct row to be modified
68          */
69         result DeleteFromTable(const Tizen::Base::String& tableName, const Tizen::Base::String& whereCondition);
70
71         /**
72          * Reads data from the database.
73          *
74          * @return              E_SUCCESS in case of success else system wide error code
75          * @param[in]   tableName, the table name from which the rows to be deleted
76          * @param[in]   whereCondition, the criteria to select the correct row to be modified
77          * @param[out]  the retrieved data, the column name to be keys and values as value.
78          */
79         result GetDataRowFromTable(const Tizen::Base::String& tableName, const Tizen::Base::String& whereCondition, Tizen::Base::Collection::HashMap& rowDataHashMap);
80
81         /**
82          * Returns the last added records recordId,
83          * this record id is the value of the PRIMARY AutoIncremented column in the table
84          *
85          * @return              int, the value of record id.
86          * @param[in]   tableName, table name for which the record id has to be fetched
87          *
88          * @remark : if fails it returns -1 and the error can be fetched using GetLastResult() Method
89          */
90         int GetLastAddedRowID(const Tizen::Base::String& tableName);
91
92         /**
93          * Inserts the data in given table.
94          *
95          * @return              E_SUCCESS in case of success else system wide error code
96          * @param[in]   tableName, name of the table to be created.
97          * @param[in]   pColumnNames, the names for each columns in the table
98          * @param[in]   pColumnTypes, the type of corresponding columns
99          * @param[in]   pColumnValues, the values for corresponding columns
100          */
101         result InsertToTable(const Tizen::Base::String& tableName, Tizen::Base::Collection::ArrayList* pColumnNames, Tizen::Base::Collection::ArrayList* pColumnTypes, Tizen::Base::Collection::ArrayList* pColumnValues);
102
103         /**
104          * Inserts the data in given table.
105          *
106          * @return              E_SUCCESS in case of success else system wide error code
107          * @param[in]   tableName, name of the table to be created.
108          * @param[in]   pColumnsToModify, the column names which needs to be updated
109          * @param[in]   pColumnTypes, the type of corresponding columns
110          * @param[in]   pColumnsNewData, the values for corresponding columns
111          * @param[in]   whereCondition, the criteria to select the correct row to be modified
112          */
113         result UpdateTable(const Tizen::Base::String& tableName, Tizen::Base::Collection::ArrayList* pColumnsToModify, Tizen::Base::Collection::ArrayList* pColumnTypes, Tizen::Base::Collection::ArrayList* pColumnsNewData, const Tizen::Base::String* pWhereCondition);
114
115 private:
116         /**
117          * Destructor
118          * This destructor is intentionally declared as private to implement the Singleton semantic.
119          */
120         ~GenericDatabaseManager(void);
121
122         /**
123          * Constructor
124          * This Constructor is intentionally declared as private to implement the Singleton semantic.
125          */
126         GenericDatabaseManager(void);
127
128         /**
129          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
130          */
131         GenericDatabaseManager(const GenericDatabaseManager&);
132
133         /**
134          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
135          */
136         GenericDatabaseManager& operator =(const GenericDatabaseManager&);
137
138         /**
139          * Creates the singleton object of HomeDatabaseManager
140          */
141         static void CreateInstance(void);
142
143         /**
144          * Destroys the singleton object of HomeDatabaseManager
145          */
146         static void DestroyInstance(void);
147
148         /**
149          * returns the column type of the mentioned column name
150          *
151          * @return              DbColumnType, tells about the data type of the column.
152          * @param[in]   columnName, column name for which type is to be known.
153          */
154         Tizen::Io::DbColumnType GetColumnType(Tizen::Io::DbEnumerator* pDbEnumerator, Tizen::Base::String* pColumnName);
155
156         /**
157          * returns the columntype of the mentioned columnName
158          *
159          * @return              int, tells about the datatype of the column.
160          * @param[in]   pColumnName, column name for which type is to be known.
161          */
162         int GetColumnIndex(Tizen::Io::DbEnumerator* pDbEnumerator, Tizen::Base::String* pColumnName);
163
164 private:
165         static GenericDatabaseManager* __pDatabaseManager; // singleton object of this class
166         Tizen::Io::Database* __pDatabase; // database instance
167 };
168
169 #endif //_HM_GENERIC_DATABASE_MANAGER_H_