Search in sources :

Example 16 with ListEngineRecord

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);
        }
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) IOException(java.io.IOException)

Example 17 with ListEngineRecord

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();
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord)

Example 18 with ListEngineRecord

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;
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) Cursor(android.database.Cursor)

Example 19 with ListEngineRecord

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()));
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord)

Example 20 with ListEngineRecord

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