use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.
the class JsListEngine method addOrUpdateItem.
@Override
public void addOrUpdateItem(T item) {
cache.put(item.getEngineId(), item);
storage.updateOrAdd(new ListEngineRecord(item.getEngineId(), item.getEngineSort(), item.getEngineSearch(), item.toByteArray()));
for (JsListEngineCallback<T> callback : callbacks) {
try {
callback.onItemAddedOrUpdated(item);
} catch (Exception e) {
Log.d(TAG, "Exception during update (addOrUpdateItem)");
Log.e(TAG, e);
}
}
}
use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.
the class SQLiteList method updateOrAdd.
@Override
public void updateOrAdd(List<ListEngineRecord> items) {
checkTable();
database.beginTransaction();
try {
for (ListEngineRecord record : items) {
Object[] args = new Object[] { record.getKey(), record.getQuery() != null ? record.getQuery().toLowerCase() : null, record.getOrder(), record.getData() };
database.execSQL("REPLACE INTO \"" + tableName + "\" (\"ID\",\"QUERY\",\"SORT_KEY\",\"BYTES\") VALUES (?,?,?,?)", args);
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
}
use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.
the class SQLiteList method loadItem.
@Override
public ListEngineRecord loadItem(long key) {
checkTable();
Cursor cursor = database.query("\"" + tableName + "\"", new String[] { "\"ID\"", "\"SORT_KEY\"", "\"QUERY\"", "\"BYTES\"" }, "\"ID\"=?", 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 MemoryListEngine method addOrUpdateItem.
@Override
public void addOrUpdateItem(T item) {
synchronized (LOCK) {
cache.onObjectUpdated(item.getEngineId(), item);
storage.updateOrAdd(new ListEngineRecord(item.getEngineId(), item.getEngineSort(), item.getEngineSearch(), item.toByteArray()));
}
}
use of im.actor.runtime.storage.ListEngineRecord in project actor-platform by actorapp.
the class MemoryListEngine method replaceItems.
@Override
public void replaceItems(List<T> items) {
synchronized (LOCK) {
cache.clear();
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.clear();
storage.updateOrAdd(records);
}
}
Aggregations