8535d980118ea9dc14175573df8ec04c52557161
[JavaForFun] /
1 /**
2  * Copyright 2014 Gustavo Martin Morcuende
3  *
4  * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 package name.gumartinm.weather.information.model;
17
18 import android.content.Context;
19
20 public class DatabaseQueries {
21         private final Context localContext;
22
23         public DatabaseQueries(final Context context) {
24                 this.localContext = context;
25         }
26         
27         public WeatherLocation queryDataBase() {
28         
29         final WeatherLocationDbHelper dbHelper = new WeatherLocationDbHelper(this.localContext);
30         try {
31                 final WeatherLocationDbQueries queryDb = new WeatherLocationDbQueries(dbHelper);        
32                 return queryDb.queryDataBase();
33         } finally {
34                 dbHelper.close();
35         } 
36     }
37     
38         public long insertIntoDataBase(final WeatherLocation weatherLocation) {
39         
40         final WeatherLocationDbHelper dbHelper = new WeatherLocationDbHelper(this.localContext);
41         try {
42                 final WeatherLocationDbQueries queryDb = new WeatherLocationDbQueries(dbHelper);        
43                 return queryDb.insertIntoDataBase(weatherLocation);
44         } finally {
45                 dbHelper.close();
46         } 
47     }
48     
49         public void updateDataBase(final WeatherLocation weatherLocation) {
50         
51         final WeatherLocationDbHelper dbHelper = new WeatherLocationDbHelper(this.localContext);
52         try {
53                 final WeatherLocationDbQueries queryDb = new WeatherLocationDbQueries(dbHelper);        
54                 queryDb.updateDataBase(weatherLocation);
55         } finally {
56                 dbHelper.close();
57         } 
58     }
59 }