當前位置: 首頁>>代碼示例>>Java>>正文


Java Realm.executeTransaction方法代碼示例

本文整理匯總了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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:17,代碼來源:TaskListAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:18,代碼來源:TaskListAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:17,代碼來源:TaskAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:22,代碼來源:TaskAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:20,代碼來源:TaskAdapter.java

示例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();
        }
    }
}
 
開發者ID:TrustWallet,項目名稱:trust-wallet-android,代碼行數:23,代碼來源:RealmTokenSource.java

示例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);
		}
	});
}
 
開發者ID:chickendude,項目名稱:GlossikaSchedule,代碼行數:26,代碼來源:ScheduleData.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:DogRepositoryImpl.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:MyApplication.java

示例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();
    }
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:28,代碼來源:SignInActivity.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:14,代碼來源:TaskListAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:8,代碼來源:TaskListAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:29,代碼來源:TaskListAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:13,代碼來源:TaskListAdapter.java

示例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();
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:12,代碼來源:TaskAdapter.java


注:本文中的io.realm.Realm.executeTransaction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。