Search in sources :

Example 1 with ListEngineRecord

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

the class ClcListStorage method updateOrAdd.

@Override
public void updateOrAdd(List<ListEngineRecord> items) {
    checkTable();
    for (ListEngineRecord record : items) {
        Object[] args = new Object[] { record.getKey(), record.getQuery() != null ? record.getQuery().toLowerCase() : null, record.getOrder(), record.getData(), this.context };
        database.execSQL("REPLACE INTO \"" + tableName + "\" (\"ID\",\"QUERY\",\"SORT_KEY\",\"BYTES\",\"CONTEXT\") VALUES (?,?,?,?,?)", args);
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord)

Example 2 with ListEngineRecord

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

the class AsyncStorageActor method loadHead.

@AutoreleasePool
public void loadHead(LoadItemCallback<T> callback) {
    List<ListEngineRecord> records = storage.loadForward(null, 1);
    if (records.size() != 1) {
        callback.onLoaded(null);
        return;
    }
    ListEngineRecord record = records.get(0);
    try {
        callback.onLoaded(Bser.parse(creator.createInstance(), record.getData()));
    } catch (IOException e) {
        e.printStackTrace();
        callback.onLoaded(null);
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) IOException(java.io.IOException) AutoreleasePool(com.google.j2objc.annotations.AutoreleasePool)

Example 3 with ListEngineRecord

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

the class AsyncStorageActor method loadItem.

@AutoreleasePool
public void loadItem(long key, LoadItemCallback<T> callback) {
    ListEngineRecord record = storage.loadItem(key);
    if (record != null) {
        try {
            T res = Bser.parse(creator.createInstance(), record.getData());
            callback.onLoaded(res);
        } catch (IOException e) {
            e.printStackTrace();
            callback.onLoaded(null);
        }
    } else {
        callback.onLoaded(null);
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) IOException(java.io.IOException) AutoreleasePool(com.google.j2objc.annotations.AutoreleasePool)

Example 4 with ListEngineRecord

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

the class AsyncStorageActor method addOrUpdate.

@AutoreleasePool
public void addOrUpdate(List<T> items) {
    if (items.size() == 1) {
        T item = items.get(0);
        storage.updateOrAdd(new ListEngineRecord(item.getEngineId(), item.getEngineSort(), item.getEngineSearch(), item.toByteArray()));
    } else if (items.size() > 0) {
        List<ListEngineRecord> updated = new ArrayList<>();
        for (T i : items) {
            updated.add(new ListEngineRecord(i.getEngineId(), i.getEngineSort(), i.getEngineSearch(), i.toByteArray()));
        }
        storage.updateOrAdd(updated);
    }
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) List(java.util.List) ArrayList(java.util.ArrayList) AutoreleasePool(com.google.j2objc.annotations.AutoreleasePool)

Example 5 with ListEngineRecord

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

the class AsyncStorageActor method replace.

@AutoreleasePool
public void replace(List<T> items) {
    List<ListEngineRecord> updated = new ArrayList<>();
    for (T i : items) {
        updated.add(new ListEngineRecord(i.getEngineId(), i.getEngineSort(), i.getEngineSearch(), i.toByteArray()));
    }
    storage.clear();
    storage.updateOrAdd(updated);
}
Also used : ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) ArrayList(java.util.ArrayList) AutoreleasePool(com.google.j2objc.annotations.AutoreleasePool)

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