Search in sources :

Example 91 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class MentionCommentsTimeLineDBTask method updatePosition.

private static void updatePosition(TimeLinePosition position, String accountId) {
    String sql = "select * from " + MentionCommentsTable.TABLE_NAME + " where " + MentionCommentsTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    if (c.moveToNext()) {
        try {
            String[] args = { accountId };
            ContentValues cv = new ContentValues();
            cv.put(MentionCommentsTable.TIMELINEDATA, gson.toJson(position));
            getWsd().update(MentionCommentsTable.TABLE_NAME, cv, MentionCommentsTable.ACCOUNTID + "=?", args);
        } catch (JsonSyntaxException e) {
        }
    } else {
        ContentValues cv = new ContentValues();
        cv.put(MentionCommentsTable.ACCOUNTID, accountId);
        cv.put(MentionCommentsTable.TIMELINEDATA, gson.toJson(position));
        getWsd().insert(MentionCommentsTable.TABLE_NAME, MentionCommentsTable.ID, cv);
    }
}
Also used : ContentValues(android.content.ContentValues) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 92 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class MentionCommentsTimeLineDBTask method addCommentLineMsg.

public static void addCommentLineMsg(CommentListBean list, String accountId) {
    Gson gson = new Gson();
    List<CommentBean> msgList = list.getItemList();
    DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), MentionCommentsTable.MentionCommentsDataTable.TABLE_NAME);
    final int mblogidColumn = ih.getColumnIndex(MentionCommentsTable.MentionCommentsDataTable.MBLOGID);
    final int accountidColumn = ih.getColumnIndex(MentionCommentsTable.MentionCommentsDataTable.ACCOUNTID);
    final int jsondataColumn = ih.getColumnIndex(MentionCommentsTable.MentionCommentsDataTable.JSONDATA);
    try {
        getWsd().beginTransaction();
        for (CommentBean msg : msgList) {
            ih.prepareForInsert();
            ih.bind(mblogidColumn, msg.getId());
            ih.bind(accountidColumn, accountId);
            String json = gson.toJson(msg);
            ih.bind(jsondataColumn, json);
            ih.execute();
        }
        getWsd().setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        getWsd().endTransaction();
        ih.close();
    }
    reduceCommentTable(accountId);
}
Also used : SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 93 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class MentionCommentsTimeLineDBTask method getPosition.

public static TimeLinePosition getPosition(String accountId) {
    String sql = "select * from " + MentionCommentsTable.TABLE_NAME + " where " + MentionCommentsTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(MentionCommentsTable.TIMELINEDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
                c.close();
                return value;
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    c.close();
    return TimeLinePosition.empty();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Example 94 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class MentionWeiboTimeLineDBTask method getPosition.

public static TimeLinePosition getPosition(String accountId) {
    String sql = "select * from " + RepostsTable.TABLE_NAME + " where " + RepostsTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(RepostsTable.TIMELINEDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
                c.close();
                return value;
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    c.close();
    return TimeLinePosition.empty();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Example 95 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class DraftDBManager method insertReply.

public void insertReply(String content, CommentBean commentBean, String accountId) {
    ContentValues cv = new ContentValues();
    cv.put(DraftTable.CONTENT, content);
    cv.put(DraftTable.ACCOUNTID, accountId);
    cv.put(DraftTable.JSONDATA, new Gson().toJson(commentBean));
    cv.put(DraftTable.TYPE, DraftTable.TYPE_REPLY);
    wsd.insert(DraftTable.TABLE_NAME, DraftTable.ID, cv);
}
Also used : ContentValues(android.content.ContentValues) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)1309 Test (org.junit.Test)280 HashMap (java.util.HashMap)227 GsonBuilder (com.google.gson.GsonBuilder)174 JsonObject (com.google.gson.JsonObject)157 IOException (java.io.IOException)147 CommandWrapper (ClientServerApi.CommandWrapper)123 ArrayList (java.util.ArrayList)121 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 JsonSyntaxException (com.google.gson.JsonSyntaxException)103 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 JsonElement (com.google.gson.JsonElement)78 Type (java.lang.reflect.Type)77 Map (java.util.Map)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 InputStreamReader (java.io.InputStreamReader)49 List (java.util.List)49 TypeToken (com.google.gson.reflect.TypeToken)44