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