OSDN Git Service

bc8b88288001a4d4479fec09494343d402ab2452
[train-delayed/source.git] / workspace / TrainDelayed / src / com / td / db / HistoryDao.java
1 package com.td.db;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.List;\r
5 \r
6 import android.content.ContentResolver;\r
7 import android.content.Context;\r
8 import android.database.Cursor;\r
9 \r
10 import com.td.HistoryContentProvider;\r
11 import com.td.utility.Debug;\r
12 \r
13 public class HistoryDao {\r
14         private static HistoryDao instance = null;\r
15         \r
16         public static HistoryDao getInstance(){\r
17                 if (instance == null){\r
18                         instance = new HistoryDao();\r
19                 }\r
20                 return instance;\r
21         }\r
22         \r
23         private HistoryDao(){\r
24                 \r
25         }\r
26         \r
27         private List<History> search(Context context, String selection, String[] selectionArgs){\r
28                 ContentResolver resolver = context.getContentResolver();\r
29                 Cursor cursor = resolver.query(HistoryContentProvider.CONTENT_URI,\r
30                                 HistoryContentProvider.Projection.projection,\r
31                                 selection,\r
32                                 selectionArgs,\r
33                                 HistoryContentProvider.Fields.ID + " ASC");\r
34                 \r
35                 List<History> list = new ArrayList<History>();\r
36         if (cursor.moveToFirst()) {\r
37             do {\r
38                 int n = 0;\r
39                 long id = cursor.getInt(n++);\r
40                         int routeId = cursor.getInt(n++);\r
41                                 int ymd = cursor.getInt(n++);\r
42                                 int hm = cursor.getInt(n++);\r
43                         int week = cursor.getInt(n++);\r
44                         int period = cursor.getInt(n++);\r
45                         int num = cursor.getInt(n++);\r
46                         int status = cursor.getInt(n++);\r
47                         \r
48                         // TODO\r
49                                 Debug.d(this, "" + id + " " + routeId + " " + ymd + " " + hm\r
50                                                 + " " + week + " " + period + " " + num + " " + status);\r
51                                 \r
52                                 History history = new History(id, routeId, ymd, hm, week,\r
53                                                 period, num, status);\r
54                                 list.add(history);\r
55             } while (cursor.moveToNext());\r
56         }               \r
57         return list;\r
58         }\r
59 \r
60         public List<History> search(Context context, int ymd, int startHm, int endHm){\r
61                 // TODO\r
62                 //      status\82Í?\r
63                 String selection = "YMD = ? AND ? <= HM AND HM <= ?";\r
64                 String[] selectionArgs = new String[3];\r
65                 selectionArgs[0] = String.valueOf(ymd);\r
66                 selectionArgs[1] = String.valueOf(startHm);\r
67                 selectionArgs[2] = String.valueOf(endHm);\r
68                 \r
69                 return search(context, selection, selectionArgs);\r
70         }\r
71 \r
72         public List<History> search(Context context){\r
73                 return search(context, null, null);\r
74         }\r
75 \r
76         public void delete(Context context){\r
77                 delete(context, null, null);\r
78         }\r
79         \r
80         private void delete(Context context, String selection, String[] selectionArgs){\r
81                 ContentResolver resolver = context.getContentResolver();\r
82                 resolver.delete(HistoryContentProvider.CONTENT_URI, selection, selectionArgs);\r
83         }\r
84 }\r