Search in sources :

Example 11 with ListEngineRecord

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

the class MemoryListStorage method loadAllItems.

@Override
public List<ListEngineRecord> loadAllItems() {
    ArrayList<ListEngineRecord> res = new ArrayList<ListEngineRecord>();
    for (long id : records.keySet()) {
        Record record = records.get(id);
        res.add(new ListEngineRecord(id, record.getOrder(), record.getQuery(), record.getData()));
    }
    return res;
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList) ListEngineRecord(im.actor.runtime.storage.ListEngineRecord)

Example 12 with ListEngineRecord

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

the class ClcListStorage 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)

Example 13 with ListEngineRecord

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

the class JsListEngine method replaceItems.

@Override
public void replaceItems(List<T> items) {
    cache.clear();
    storage.clear();
    ArrayList<ListEngineRecord> records = new ArrayList<ListEngineRecord>();
    for (T t : items) {
        cache.put(t.getEngineId(), t);
        records.add(new ListEngineRecord(t.getEngineId(), t.getEngineSort(), t.getEngineSearch(), t.toByteArray()));
    }
    storage.updateOrAdd(records);
    for (JsListEngineCallback<T> callback : callbacks) {
        try {
            callback.onItemsReplaced(items);
        } catch (Exception e) {
            Log.d(TAG, "Exception during update (replaceItems)");
            Log.e(TAG, e);
        }
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 14 with ListEngineRecord

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

the class JsListEngine method getValue.

@Override
public T getValue(long key) {
    if (cache.containsKey(key)) {
        return cache.get(key);
    }
    ListEngineRecord record = storage.loadItem(key);
    if (record != null) {
        try {
            T res = Bser.parse(creator.createInstance(), record.getData());
            cache.put(key, res);
            return res;
        } catch (IOException e) {
            Log.d("JsListEngine", "Unable to decode: " + e.getMessage());
            Log.e(TAG, e);
        }
    }
    return null;
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) IOException(java.io.IOException)

Example 15 with ListEngineRecord

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

the class JsListEngine method addOrUpdateItems.

@Override
public void addOrUpdateItems(List<T> items) {
    ArrayList<ListEngineRecord> records = new ArrayList<ListEngineRecord>();
    for (T t : items) {
        cache.put(t.getEngineId(), t);
        records.add(new ListEngineRecord(t.getEngineId(), t.getEngineSort(), t.getEngineSearch(), t.toByteArray()));
    }
    storage.updateOrAdd(records);
    for (JsListEngineCallback<T> callback : callbacks) {
        try {
            callback.onItemsAddedOrUpdated(items);
        } catch (Exception e) {
            Log.d(TAG, "Exception during update (addOrUpdateItems)");
            Log.e(TAG, e);
        }
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

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