3 import java.util.ArrayList;
\r
4 import java.util.List;
\r
6 import android.content.ContentResolver;
\r
7 import android.content.Context;
\r
8 import android.database.Cursor;
\r
10 import com.td.HistoryContentProvider;
\r
11 import com.td.utility.Debug;
\r
13 public class HistoryDao {
\r
14 private static HistoryDao instance = null;
\r
16 public static HistoryDao getInstance(){
\r
17 if (instance == null){
\r
18 instance = new HistoryDao();
\r
23 private HistoryDao(){
\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
33 HistoryContentProvider.Fields.ID + " ASC");
\r
34 List<History> list = new ArrayList<History>();
\r
37 if (cursor.moveToFirst()) {
\r
40 long id = cursor.getLong(n++);
\r
41 long routeId = cursor.getLong(n++);
\r
42 int ymd = cursor.getInt(n++);
\r
43 int hm = cursor.getInt(n++);
\r
44 int week = cursor.getInt(n++);
\r
45 int period = cursor.getInt(n++);
\r
46 long num = cursor.getLong(n++);
\r
47 int status = cursor.getInt(n++);
\r
49 if (Debug.isDebug()){
\r
50 Debug.d(this, "" + id + " " + routeId + " " + ymd + " " + hm
\r
51 + " " + week + " " + period + " " + num + " " + status);
\r
53 History history = new History(id, routeId, ymd, hm, week,
\r
54 period, num, status);
\r
56 } while (cursor.moveToNext());
\r
60 if (cursor != null){
\r
68 public List<History> search(Context context, long routeId, int ymd, int startHm, int endHm){
\r
69 String selection = "YMD = ? AND ? <= HM AND HM <= ? AND ROUTE_ID = ?";
\r
70 String[] selectionArgs = new String[4];
\r
71 selectionArgs[0] = String.valueOf(ymd);
\r
72 selectionArgs[1] = String.valueOf(startHm);
\r
73 selectionArgs[2] = String.valueOf(endHm);
\r
74 selectionArgs[3] = String.valueOf(routeId);
\r
76 return search(context, selection, selectionArgs);
\r
79 public List<History> search(Context context, int ymd, int startHm, int endHm){
\r
80 String selection = "YMD = ? AND ? <= HM AND HM <= ?";
\r
81 String[] selectionArgs = new String[3];
\r
82 selectionArgs[0] = String.valueOf(ymd);
\r
83 selectionArgs[1] = String.valueOf(startHm);
\r
84 selectionArgs[2] = String.valueOf(endHm);
\r
86 return search(context, selection, selectionArgs);
\r
89 public List<History> search(Context context){
\r
90 return search(context, null, null);
\r
93 public void delete(Context context){
\r
94 delete(context, null, null);
\r
97 public void deleteByYmd(Context context, int ymd){
\r
98 String selection = "YMD < ?";
\r
99 String[] selectionArgs = new String[1];;
\r
100 selectionArgs[0] = String.valueOf(ymd);
\r
102 delete(context, selection, selectionArgs);
\r
105 private void delete(Context context, String selection, String[] selectionArgs){
\r
106 ContentResolver resolver = context.getContentResolver();
\r
107 resolver.delete(HistoryContentProvider.CONTENT_URI, selection, selectionArgs);
\r