Search in sources :

Example 6 with ListEngineRecord

use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.

the class AsyncStorageActor method convertList.

private ArrayList<T> convertList(List<ListEngineRecord> records) {
    ArrayList<T> res = new ArrayList<T>();
    for (ListEngineRecord record : records) {
        try {
            T loaded = Bser.parse(creator.createInstance(), record.getData());
            res.add(loaded);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return res;
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 7 with ListEngineRecord

use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.

the class SQLiteList method loadCenter.

@Override
public List<ListEngineRecord> loadCenter(Long centerSortKey, int limit) {
    checkTable();
    Cursor cursor;
    if (centerSortKey == null) {
        cursor = database.query("\"" + tableName + "\"", new String[] { "\"LIST_ID\"", "\"ID\"", "\"SORT_KEY\"", "\"QUERY\"", "\"BYTES\"" }, null, null, null, null, "\"SORT_KEY\" DESC", String.valueOf(limit));
        return loadSlice(cursor);
    } else {
        ListEngineRecord centerItem = loadItemBySortKey(centerSortKey);
        ArrayList<ListEngineRecord> ret = new ArrayList<ListEngineRecord>();
        ret.addAll(loadBackward(centerSortKey, limit));
        if (centerItem != null)
            ret.add(centerItem);
        ret.addAll(loadForward(centerSortKey, limit));
        return ret;
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 8 with ListEngineRecord

use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.

the class SQLiteList method loadItemBySortKey.

public ListEngineRecord loadItemBySortKey(long key) {
    checkTable();
    Cursor cursor = database.query("\"" + tableName + "\"", new String[] { "\"ID\"", "\"SORT_KEY\"", "\"QUERY\"", "\"BYTES\"" }, "\"SORT_KEY\"=?", new String[] { String.valueOf(key) }, null, null, null);
    if (cursor == null) {
        return null;
    }
    try {
        if (cursor.moveToFirst()) {
            return new ListEngineRecord(key, cursor.getLong(cursor.getColumnIndex("SORT_KEY")), cursor.getString(cursor.getColumnIndex("QUERY")), cursor.getBlob(cursor.getColumnIndex("BYTES")));
        }
    } finally {
        cursor.close();
    }
    return null;
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) Cursor(android.database.Cursor)

Example 9 with ListEngineRecord

use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.

the class SQLiteList method loadSlice.

private ArrayList<ListEngineRecord> loadSlice(Cursor cursor) {
    // int queryColumn = enableSearch ? cursor.getColumnIndex("QUERY") : -1;
    ArrayList<ListEngineRecord> res = new ArrayList<ListEngineRecord>();
    if (cursor != null) {
        int idColumn = cursor.getColumnIndex("ID");
        int sortColumn = cursor.getColumnIndex("SORT_KEY");
        int bytesColumn = cursor.getColumnIndex("BYTES");
        int queryColumn = cursor.getColumnIndex("QUERY");
        try {
            if (cursor.moveToFirst()) {
                do {
                    res.add(new ListEngineRecord(cursor.getLong(idColumn), cursor.getLong(sortColumn), cursor.getString(queryColumn), cursor.getBlob(bytesColumn)));
                } while (cursor.moveToNext());
            }
        } finally {
            cursor.close();
        }
    }
    return res;
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList)

Example 10 with ListEngineRecord

use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.

the class MemoryListEngine method addOrUpdateItems.

@Override
public void addOrUpdateItems(List<T> items) {
    synchronized (LOCK) {
        ArrayList<ListEngineRecord> records = new ArrayList<ListEngineRecord>();
        for (T item : items) {
            cache.onObjectUpdated(item.getEngineId(), item);
            records.add(new ListEngineRecord(item.getEngineId(), item.getEngineSort(), item.getEngineSearch(), item.toByteArray()));
        }
        storage.updateOrAdd(records);
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList)

Aggregations

ListEngineRecord (im.actor.runtime.storage.ListEngineRecord)21 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)8 AutoreleasePool (com.google.j2objc.annotations.AutoreleasePool)4 Cursor (android.database.Cursor)3 BserValues (im.actor.runtime.bser.BserValues)1 DataInput (im.actor.runtime.bser.DataInput)1 List (java.util.List)1