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
35 List<History> list = new ArrayList<History>();
\r
36 if (cursor.moveToFirst()) {
\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
49 Debug.d(this, "" + id + " " + routeId + " " + ymd + " " + hm
\r
50 + " " + week + " " + period + " " + num + " " + status);
\r
52 History history = new History(id, routeId, ymd, hm, week,
\r
53 period, num, status);
\r
55 } while (cursor.moveToNext());
\r
60 public List<History> search(Context context, int ymd, int startHm, int endHm){
\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
69 return search(context, selection, selectionArgs);
\r
72 public List<History> search(Context context){
\r
73 return search(context, null, null);
\r
76 public void delete(Context context){
\r
77 delete(context, null, null);
\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