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;
}
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;
}
}
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);
}
}
}
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;
}
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);
}
}
}
Aggregations