Advertisement
Guest User

Tastebin - Tkabber Plugin

a guest
Apr 30th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. class MessagesDbHelper extends SQLiteOpenHelper {
  2. private String[] allColumns = {"id", "timestamp", "author", "message"};
  3.  
  4. public MessagesDbHelper(Context ctx) {
  5. super(ctx, "messages.db", null, 5);
  6. }
  7. @Override
  8. public void onCreate(SQLiteDatabase sqLiteDatabase) {
  9. sqLiteDatabase.execSQL("create table messages (id string primary key, timestamp long not null, author text not null, message text not null );");
  10. }
  11.  
  12. @Override
  13. public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
  14. sqLiteDatabase.execSQL("drop table if exists messages;");
  15. onCreate(sqLiteDatabase);
  16. }
  17.  
  18. public void test() {
  19. new Thread(new Runnable() {
  20. @Override
  21. public void run() {
  22. XmppContact contact = new XmppContact("ooooooooo@w.tu", "999");
  23. long delay = System.currentTimeMillis();
  24. HistoryStorage history = HistoryStorage.getHistory(contact);
  25. history.clearAll(true);
  26. for (int i = 0; i < 100; ++i) {
  27. history.addText("sthsthxghhhhhhhhsttttttttttttttwwytrujkfk", true, "ii" + i, 9869905);
  28. }
  29. Log.e("HistoryStorage time", ""+(System.currentTimeMillis() - delay)/1000);
  30.  
  31. long delay2 = System.currentTimeMillis();
  32. MessagesDbHelper messagesHelper = new MessagesDbHelper(SawimApplication.getContext());
  33. SQLiteDatabase db = messagesHelper.getWritableDatabase();
  34. db.execSQL("drop table if exists messages;");
  35. messagesHelper.onCreate(db);
  36. for (int i = 0; i < 100; ++i) {
  37. ContentValues values = new ContentValues();
  38. values.put("id", "ooooooooo@w.tu" + i);
  39. values.put("timestamp", 9869905);
  40. values.put("author", "ii");
  41. values.put("message", "sthsthxghhhhhhhhsttttttttttttttwwytrujkfk");
  42. db.insert("messages", null, values);
  43. }
  44.  
  45. Cursor rowIds = messagesHelper.getIds(db);
  46. for (int i = 0; i < 100; ++i) {
  47. rowIds.moveToPosition(i);
  48. String rowId = rowIds.getString(rowIds.getColumnIndex("id"));
  49. Cursor cursor = messagesHelper.getRowById(db, rowId);
  50. cursor.moveToFirst();
  51. Log.e("get", cursor.getString(cursor.getColumnIndex("author"))+" "+
  52. cursor.getString(cursor.getColumnIndex("message"))+" "+new Date(cursor.getLong(cursor.getColumnIndex("timestamp"))).toLocaleString());
  53. }
  54. Log.e("Database time", ""+(System.currentTimeMillis() - delay2)/1000);
  55. }
  56. }).start();
  57. }
  58.  
  59. public Cursor getIds(SQLiteDatabase db) {
  60. return db.rawQuery("select id from messages limit 1000", new String[]{});
  61. }
  62.  
  63. public Cursor getRowById(SQLiteDatabase db, String id) {
  64. return db.query("messages", allColumns, "id='" + id + "'", null, null, null, null, null);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement