Applied latest source code
[apps/native/preloaded/Clock.git] / inc / ClkDataServiceProvider.h
1 //
2 // Tizen Native SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        ClkPresentationModelBase.h
20  * @brief       This is the header file for PresentationModelBase class
21  */
22
23 #ifndef _CLK_DATA_SERVICE_PROVIDER_H_
24 #define _CLK_DATA_SERVICE_PROVIDER_H_
25
26 #include <FIo.h>
27
28 #include "ClkTypes.h"
29
30 /**
31  * @class       DataServiceProvider
32  * @brief       This class declares functions which will manage database
33  */
34 class DataServiceProvider
35 {
36 public:
37         /**
38          * Initialize storage service
39          */
40         static result Initialize(void);
41
42         /**
43          * Deinitialize storage service
44          */
45         static result UnInitialize(void);
46
47 public:
48         /**
49          * This function deletes the database
50          *
51          * @return      An error code
52          * @param               No parameter
53          * @exception   E_SUCCESS               The database closed successfully
54          * @exception   E_FAILURE               The database is not closed successfully
55          */
56         static result CloseDb(void);
57
58         /**
59          * This function commits the database
60          *
61          * @return      An error code
62          * @param               No parameter
63          * @exception   E_SUCCESS               The database closed successfully
64          * @exception   E_FAILURE               The database is not closed successfully
65          */
66         static result CommitDb(void);
67
68         /**
69          * This function creates the table in database
70          *
71          * @return      An error code
72          * @param               tableType               The name of the table
73          * @exception   E_SUCCESS               The table is created successfully in database
74          * @exception   E_FAILURE               The table creation in database is not successful
75          */
76         static result CreateDBTables(ClockDbTableTypes tableType);
77
78         /**
79          * This function finds the next row present in the database or not.
80          *
81          * @return      An error code
82          * @param               nextRowpresent  true/false : the next row present or not.
83          * @exception   E_SUCCESS               The table is dropped successfully from database
84          * @exception   E_FAILURE               The table drop is unsuccessful
85          */
86         static result DbIsNextRowPresent(bool& nextRowpresent);
87
88         /**
89          * This function drops the existing tables from database
90          *
91          * @return      An error code
92          * @param               No parameter
93          * @exception   E_SUCCESS               The table is dropped successfully from database
94          * @exception   E_FAILURE               The table drop is unsuccessful
95          */
96         static result DropDBTables(void);
97
98         /**
99          * This function drops the existing tables from database
100          *
101          * @return      An error code
102          * @param               No parameter
103          * @exception   E_SUCCESS               The table is dropped successfully from database
104          * @exception   E_FAILURE               The table drop is unsuccessful
105          */
106         static result ExecuteQuery(const Tizen::Base::String pszFormatQuery, int& nRowCount);
107
108         /**
109          * This function returns the instance of WorldClockPresentationModel
110          *
111          * @return      The instance of WorldClockPresentationModel
112          */
113         static DataServiceProvider* GetInstance();
114
115         /**
116          * This function gives the last inserted row id
117          *
118          * @return      An error code
119          * @param               tableName       The name of the table
120          * @param               rowId           The rowId in which last inserted rowId will be saved.
121          * @exception   E_SUCCESS               The method is successful
122          * @exception   E_FAILURE               The method is not successful
123          * @remarks             To work properly , the table name should be passed properly
124          */
125          result GetLastInsertedId(Tizen::Base::String& tableName, int& rowId);
126
127         /**
128          * This function creates the database and constructs it.
129          *
130          * @return      An error code
131          * @param               No parameter
132          * @exception   E_SUCCESS               The database created successfully
133          * @exception   E_FAILURE               The database creation is failed
134          */
135         static result OpenDb(void);
136
137         /**
138          * This function calls the CreateDBTables function for all the tables
139          *
140          * @return      An error code
141          * @param               No parameter
142          */
143         static result InitializeDBTables(void);
144
145
146
147         static result IsNullColumn(int nIndex, bool& isColumNull);
148         static result GetColumn(int nIndex, Tizen::Base::String& strVal);
149         static result GetColumn(int nIndex, int& nIntVal);
150         static result GetColumn(int nIndex, double& dblVal);
151         static result GetColumn(int nIndex, Tizen::Base::DateTime& dtVal);
152         static result RollbackDb(void);
153
154         static bool GetCurrentDateTime(Tizen::Base::DateTime& dt);
155
156 private:
157         /**
158          * Default constructor
159          */
160         DataServiceProvider(void);
161
162         /**
163          * Default destructor
164          */
165         ~DataServiceProvider(void);
166
167         /**
168          * This function constructs the instance of DataServiceProvider
169          *
170          */
171         result Construct(void);
172
173         /**
174          * This function creates the instance of DataServiceProvider
175          *
176          * @return      No return value
177          */
178         static void CreateInstance(void);
179
180         /**
181          * This function destroys the instance of DataServiceProvider
182          *
183          * @return      No return value
184          */
185         static void DestroyInstance(void);
186
187 public:
188     static Tizen::Base::String DB_FILE_PATH;
189
190 private:
191     static bool __isBeginTransaction;
192         static Tizen::Io::Database* __pDataBase;
193         static Tizen::Io::DbEnumerator* __pDbEnum;
194         static Tizen::Io::DbStatement* __pDbStatement;
195         static DataServiceProvider* __pInstance;
196 };
197
198  #endif //_CLK_DATA_SERVICE_PROVIDER_H_