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