|
|
@@ -1,131 +1,132 @@
|
|
|
-package com.xzjmyk.pm.activity.db.dao;
|
|
|
-
|
|
|
-import android.content.ContentValues;
|
|
|
-import android.database.Cursor;
|
|
|
-import android.database.SQLException;
|
|
|
-import android.database.sqlite.SQLiteDatabase;
|
|
|
-import android.util.Log;
|
|
|
-
|
|
|
-import com.xzjmyk.pm.activity.MyApplication;
|
|
|
-import com.xzjmyk.pm.activity.bean.message.SubscriptionMessage;
|
|
|
-import com.xzjmyk.pm.activity.db.OtherSqliteHelper;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by gongpm on 2016/6/7.
|
|
|
- */
|
|
|
-public class SubscriptionDao {
|
|
|
- private static SubscriptionDao instance = null;
|
|
|
- private OtherSqliteHelper sqliteHelper;
|
|
|
- private String titleName = "SubscriptionMessage";
|
|
|
-
|
|
|
- private SubscriptionDao() {
|
|
|
- sqliteHelper = new OtherSqliteHelper(MyApplication.getInstance());
|
|
|
- }
|
|
|
-
|
|
|
- public static SubscriptionDao getInstance() {
|
|
|
- if (instance == null) {
|
|
|
- synchronized (SubscriptionDao.class) {
|
|
|
- instance = new SubscriptionDao();
|
|
|
- }
|
|
|
- }
|
|
|
- return instance;
|
|
|
- }
|
|
|
-
|
|
|
- //添加多个数据
|
|
|
- public long addMessage(ArrayList<SubscriptionMessage> messages) {
|
|
|
- long k = 0;
|
|
|
- SQLiteDatabase db = sqliteHelper.getWritableDatabase();
|
|
|
- db.beginTransaction();
|
|
|
- try {
|
|
|
- ContentValues values;
|
|
|
- String nullColumn = null;
|
|
|
- SubscriptionMessage message = null;
|
|
|
- for (int i = 0; i < messages.size(); i++) {
|
|
|
- message = messages.get(i);
|
|
|
- values = new ContentValues();
|
|
|
- values.put("id_", message.getId_());
|
|
|
- values.put("num_id", message.getNum_id());
|
|
|
- values.put("instance_id", message.getInstance_id());
|
|
|
- values.put("createdate_", message.getCreatedate_());
|
|
|
- values.put("data_", message.getData_());
|
|
|
- values.put("title_", message.getTitle_());
|
|
|
- values.put("son_title_", message.getSon_title_());
|
|
|
- values.put("status", message.getStatus());
|
|
|
- k += db.insert(titleName, nullColumn, values);
|
|
|
- }
|
|
|
- db.setTransactionSuccessful();
|
|
|
- return k;
|
|
|
- } catch (android.database.SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- db.endTransaction();
|
|
|
- db.close();
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- //添加单个数据
|
|
|
- public long addMessage(SubscriptionMessage message) {
|
|
|
- long k = 0;
|
|
|
- SQLiteDatabase db = sqliteHelper.getWritableDatabase();
|
|
|
- db.beginTransaction();
|
|
|
- try {
|
|
|
- ContentValues values;
|
|
|
- String nullColumn = null;
|
|
|
- values = new ContentValues();
|
|
|
- values.put("id_", message.getId_());
|
|
|
- values.put("num_id", message.getNum_id());
|
|
|
- values.put("instance_id", message.getInstance_id());
|
|
|
- values.put("createdate_", message.getCreatedate_());
|
|
|
- values.put("data_", message.getData_());
|
|
|
- values.put("title_", message.getTitle_());
|
|
|
- values.put("son_title_", message.getSon_title_());
|
|
|
- values.put("status", message.getStatus());
|
|
|
- k += db.insert(titleName, nullColumn, values);
|
|
|
- db.setTransactionSuccessful();
|
|
|
-
|
|
|
- } catch (SQLException e) {
|
|
|
- Log.i("gong", e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- db.endTransaction();
|
|
|
- db.close();
|
|
|
- }
|
|
|
- return k;
|
|
|
- }
|
|
|
-
|
|
|
- public ArrayList<SubscriptionMessage> findAll() {
|
|
|
- ArrayList<SubscriptionMessage> messages = new ArrayList<>();
|
|
|
- SQLiteDatabase db = sqliteHelper.getReadableDatabase();
|
|
|
- String[] colums = {"id_", "num_id", "instance_id", "createdate_", "data_", "title_", "son_title_", "status"};
|
|
|
- String selection = null;
|
|
|
- String[] selectionArgs = null;
|
|
|
- try {
|
|
|
- SubscriptionMessage message = null;
|
|
|
- Cursor values = db.query(titleName, colums, selection, selectionArgs, null, null, null);
|
|
|
- Log.i("gong", "读取完成values=" + values.moveToNext());
|
|
|
- while (values.moveToNext()) {
|
|
|
- message = new SubscriptionMessage();
|
|
|
- message.setId_(values.getInt(0));
|
|
|
- message.setNum_id(values.getInt(1));
|
|
|
- message.setInstance_id(values.getInt(2));
|
|
|
- message.setCreatedate_(values.getString(3));
|
|
|
- message.setData_(values.getString(4));
|
|
|
- message.setTitle_(values.getString(5));
|
|
|
- message.setSon_title_(values.getString(6));
|
|
|
- message.setStatus(values.getInt(7));
|
|
|
- messages.add(message);
|
|
|
- Log.i("gong", "获取到一个");
|
|
|
-
|
|
|
- }
|
|
|
- return messages;
|
|
|
- } catch (SQLException e) {
|
|
|
- Log.i("gong", e.getMessage());
|
|
|
- } finally {
|
|
|
- db.close();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.xzjmyk.pm.activity.db.dao;
|
|
|
+//
|
|
|
+//import android.content.ContentValues;
|
|
|
+//import android.database.Cursor;
|
|
|
+//import android.database.SQLException;
|
|
|
+//import android.database.sqlite.SQLiteDatabase;
|
|
|
+//import android.util.Log;
|
|
|
+//
|
|
|
+//import com.xzjmyk.pm.activity.MyApplication;
|
|
|
+//import com.xzjmyk.pm.activity.bean.message.SubscriptionMessage;
|
|
|
+//import com.xzjmyk.pm.activity.db.OtherSqliteHelper;
|
|
|
+//
|
|
|
+//import java.util.ArrayList;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * Created by gongpm on 2016/6/7.
|
|
|
+// */
|
|
|
+//public class SubscriptionDao {
|
|
|
+// private static SubscriptionDao instance = null;
|
|
|
+// private OtherSqliteHelper sqliteHelper;
|
|
|
+// private String titleName = "SubscriptionMessage";
|
|
|
+//
|
|
|
+// private SubscriptionDao() {
|
|
|
+// sqliteHelper = new OtherSqliteHelper(MyApplication.getInstance());
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static SubscriptionDao getInstance() {
|
|
|
+// if (instance == null) {
|
|
|
+// synchronized (SubscriptionDao.class) {
|
|
|
+// instance = new SubscriptionDao();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return instance;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //添加多个数据
|
|
|
+// public long addMessage(ArrayList<SubscriptionMessage> messages) {
|
|
|
+// long k = 0;
|
|
|
+// SQLiteDatabase db = sqliteHelper.getWritableDatabase();
|
|
|
+// db.beginTransaction();
|
|
|
+// try {
|
|
|
+// ContentValues values;
|
|
|
+// String nullColumn = null;
|
|
|
+// SubscriptionMessage message = null;
|
|
|
+// for (int i = 0; i < messages.size(); i++) {
|
|
|
+// message = messages.get(i);
|
|
|
+// values = new ContentValues();
|
|
|
+// values.put("id_", message.getId_());
|
|
|
+// values.put("num_id", message.getNum_id());
|
|
|
+// values.put("instance_id", message.getInstance_id());
|
|
|
+// values.put("createdate_", message.getCreatedate_());
|
|
|
+// values.put("title_", message.getTitle_());
|
|
|
+// values.put("son_title_", message.getSon_title_());
|
|
|
+// values.put("status", message.getStatus());
|
|
|
+// values.put("EMP_ID_", message.getStatus());
|
|
|
+// values.put("RN", message.getStatus());
|
|
|
+// k += db.insert(titleName, nullColumn, values);
|
|
|
+// }
|
|
|
+// db.setTransactionSuccessful();
|
|
|
+// return k;
|
|
|
+// } catch (android.database.SQLException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// } finally {
|
|
|
+// db.endTransaction();
|
|
|
+// db.close();
|
|
|
+// }
|
|
|
+// return 0;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //添加单个数据
|
|
|
+// public long addMessage(SubscriptionMessage message) {
|
|
|
+// long k = 0;
|
|
|
+// SQLiteDatabase db = sqliteHelper.getWritableDatabase();
|
|
|
+// db.beginTransaction();
|
|
|
+// try {
|
|
|
+// ContentValues values;
|
|
|
+// String nullColumn = null;
|
|
|
+// values = new ContentValues();
|
|
|
+// values.put("id_", message.getId_());
|
|
|
+// values.put("num_id", message.getNum_id());
|
|
|
+// values.put("instance_id", message.getInstance_id());
|
|
|
+// values.put("createdate_", message.getCreatedate_());
|
|
|
+// values.put("title_", message.getTitle_());
|
|
|
+// values.put("son_title_", message.getSon_title_());
|
|
|
+// values.put("status", message.getStatus());
|
|
|
+// values.put("EMP_ID_", message.getStatus());
|
|
|
+// values.put("RN", message.getStatus());
|
|
|
+// k += db.insert(titleName, nullColumn, values);
|
|
|
+// db.setTransactionSuccessful();
|
|
|
+//
|
|
|
+// } catch (SQLException e) {
|
|
|
+// Log.i("gong", e.getMessage());
|
|
|
+// e.printStackTrace();
|
|
|
+// } finally {
|
|
|
+// db.endTransaction();
|
|
|
+// db.close();
|
|
|
+// }
|
|
|
+// return k;
|
|
|
+// }
|
|
|
+//
|
|
|
+// public ArrayList<SubscriptionMessage> findAll() {
|
|
|
+// ArrayList<SubscriptionMessage> messages = new ArrayList<>();
|
|
|
+// SQLiteDatabase db = sqliteHelper.getReadableDatabase();
|
|
|
+// String[] colums = {"id_", "num_id", "instance_id", "createdate_", "data_", "title_", "son_title_", "status"};
|
|
|
+// String selection = null;
|
|
|
+// String[] selectionArgs = null;
|
|
|
+// try {
|
|
|
+// SubscriptionMessage message = null;
|
|
|
+// Cursor values = db.query(titleName, colums, selection, selectionArgs, null, null, null);
|
|
|
+// Log.i("gong", "读取完成values=" + values.moveToNext());
|
|
|
+// while (values.moveToNext()) {
|
|
|
+// message = new SubscriptionMessage();
|
|
|
+// message.setId_(values.getInt(0));
|
|
|
+// message.setNum_id(values.getInt(1));
|
|
|
+// message.setInstance_id(values.getInt(2));
|
|
|
+// message.setCreatedate_(values.getString(3));
|
|
|
+// message.setTitle_(values.getString(5));
|
|
|
+// message.setSon_title_(values.getString(6));
|
|
|
+// message.setStatus(values.getInt(7));
|
|
|
+// messages.add(message);
|
|
|
+// Log.i("gong", "获取到一个");
|
|
|
+//
|
|
|
+// }
|
|
|
+// return messages;
|
|
|
+// } catch (SQLException e) {
|
|
|
+// Log.i("gong", e.getMessage());
|
|
|
+// } finally {
|
|
|
+// db.close();
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//}
|