本文整理汇总了Java中io.realm.Realm.executeTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java Realm.executeTransaction方法的具体用法?Java Realm.executeTransaction怎么用?Java Realm.executeTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.Realm
的用法示例。
在下文中一共展示了Realm.executeTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onItemReverted
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemReverted()
{
if (getData().size() == 0)
{
return;
}
final Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(realm1 ->
{
final TaskList taskList = getData().get(0);
taskList.getItems().deleteAllFromRealm();
taskList.deleteFromRealm();
});
realm.close();
}
示例2: onItemChanged
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemChanged(final ItemViewHolder viewHolder)
{
final Realm realm = Realm.getDefaultInstance();
final int position = viewHolder.getAdapterPosition();
if (position < 0)
{
realm.close();
return;
}
realm.executeTransaction(realm1 ->
{
TaskList taskList = getItem(position);
taskList.setText(viewHolder.getText().getText().toString());
});
realm.close();
}
示例3: onItemAdded
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemAdded()
{
final Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(realm1 ->
{
// TaskList might have been deleted, in that case, don't create any new.
if (getData().isValid())
{
final Task task = realm1.createObject(Task.class);
task.setText("");
getData().add(0, task);
}
});
realm.close();
}
示例4: onItemCompleted
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemCompleted(final int position)
{
final Task task = getData().get(position);
final Realm realm = Realm.getDefaultInstance();
final int count = (int) getData().where().equalTo(Task.FIELD_COMPLETED, false).count();
realm.executeTransaction(realm1 ->
{
if (!task.isCompleted())
{
task.setCompleted(true);
moveItems(position, count - 1);
}
else
{
task.setCompleted(false);
moveItems(position, count);
}
});
realm.close();
}
示例5: onItemChanged
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemChanged(final ItemViewHolder viewHolder)
{
final Realm realm = Realm.getDefaultInstance();
final int position = viewHolder.getAdapterPosition();
if (position < 0)
{
realm.close();
return;
}
realm.executeTransaction(realm1 ->
{
Task task = getData().get(position);
task.setText(viewHolder.getText().getText().toString());
task.setDate(null); // remove date on text change, server will set
// new value if there is a value to be set.
});
realm.close();
}
示例6: putInNeed
import io.realm.Realm; //导入方法依赖的package包/类
private void putInNeed(NetworkInfo networkInfo, Wallet wallet, TokenInfo tokenInfo) {
Realm realm = null;
try {
realm = getRealmInstance(networkInfo, wallet);
RealmTokenInfo realmTokenInfo = realm.where(RealmTokenInfo.class)
.equalTo("address", tokenInfo.address)
.findFirst();
if (realmTokenInfo == null) {
realm.executeTransaction(r -> {
RealmTokenInfo obj = r.createObject(RealmTokenInfo.class, tokenInfo.address);
obj.setName(tokenInfo.name);
obj.setSymbol(tokenInfo.symbol);
obj.setDecimals(tokenInfo.decimals);
obj.setAddedTime(System.currentTimeMillis());
});
}
} finally {
if (realm != null) {
realm.close();
}
}
}
示例7: createSchedule
import io.realm.Realm; //导入方法依赖的package包/类
public static void createSchedule(Realm realm, ScheduleType selectedSchedule, LanguageType selectedLanguage, String title) {
// get schedule as a 2D list of strings
String[][] scheduleStrings = selectedSchedule.getSchedule();
// save schedule into db
realm.executeTransaction(r -> {
// create schedule object
Schedule schedule = r.createObject(Schedule.class, UUID.randomUUID().toString());
schedule.setTitle(title);
schedule.setLanguage(selectedLanguage.getName());
// add all days to the schedule
int dayNumber = 1;
for (String[] dayItems : scheduleStrings) {
Day day = r.createObject(Day.class, UUID.randomUUID().toString());
day.setDayNumber(dayNumber++);
// each day has a set of files to listen to
for (String dayItem : dayItems) {
StudyItem studyItem = r.createObject(StudyItem.class, UUID.randomUUID().toString());
studyItem.setTitle(dayItem);
studyItem.setCompleted(false);
day.getStudyItems().add(studyItem);
}
schedule.getSchedule().add(day);
}
});
}
示例8: createDog
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void createDog(final String name) {
Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(r -> {
Dog dog = r.createObject(Dog.class);
dog.setName(name);
});
realm.close();
}
示例9: createTestData
import io.realm.Realm; //导入方法依赖的package包/类
private void createTestData() {
final Random random = new Random(42);
Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(r -> {
for (Map.Entry<String, String> entry : testPersons.entrySet()) {
Person p = r.createObject(Person.class);
p.setName(entry.getKey());
p.setGithubUserName(entry.getValue());
p.setAge(random.nextInt(100));
}
});
realm.close();
}
示例10: createInitialDataIfNeeded
import io.realm.Realm; //导入方法依赖的package包/类
private static void createInitialDataIfNeeded()
{
final Realm realm = Realm.getDefaultInstance();
//noinspection TryFinallyCanBeTryWithResources
try
{
if (realm.where(TaskListList.class).count() != 0)
{
return;
}
realm.executeTransaction(realm1 ->
{
if (realm1.where(TaskListList.class).count() == 0)
{
final TaskListList taskListList = realm1.createObject(TaskListList.class, 0);
final TaskList taskList = new TaskList();
taskList.setId(App.DEFAULT_LIST_ID);
taskList.setText(App.DEFAULT_LIST_NAME);
taskListList.getItems().add(taskList);
}
});
}
finally
{
realm.close();
}
}
示例11: onItemAdded
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemAdded()
{
final Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(realm1 ->
{
final TaskList taskList = new TaskList();
taskList.setId(UUID.randomUUID().toString());
taskList.setText("");
getData().add(0, taskList);
});
realm.close();
}
示例12: onItemMoved
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemMoved(final int fromPosition, final int toPosition)
{
final Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(realm1 -> moveItems(fromPosition, toPosition));
realm.close();
}
示例13: onItemCompleted
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemCompleted(final int position)
{
final TaskList taskList = getItem(position);
final Realm realm = Realm.getDefaultInstance();
final int count = (int) getData().where().equalTo(TaskList.FIELD_COMPLETED, false).count();
realm.executeTransaction(realm1 ->
{
if (!taskList.isCompleted())
{
if (taskList.isCompletable())
{
taskList.setCompleted(true);
moveItems(position, count - 1);
}
else
{
Toast.makeText(context, R.string.no_item, Toast.LENGTH_SHORT).show();
}
}
else
{
taskList.setCompleted(false);
moveItems(position, count);
}
});
realm.close();
}
示例14: onItemDismissed
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemDismissed(final int position)
{
final Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(realm1 ->
{
final TaskList taskList = getData().get(position);
taskList.getItems().deleteAllFromRealm();
taskList.deleteFromRealm();
});
realm.close();
}
示例15: onItemDismissed
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onItemDismissed(final int position)
{
final Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(realm1 ->
{
final Task task = getData().get(position);
task.deleteFromRealm();
});
realm.close();
}