当前位置: 首页>>代码示例>>Java>>正文


Java Realm类代码示例

本文整理汇总了Java中io.realm.Realm的典型用法代码示例。如果您正苦于以下问题:Java Realm类的具体用法?Java Realm怎么用?Java Realm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Realm类属于io.realm包,在下文中一共展示了Realm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOne

import io.realm.Realm; //导入依赖的package包/类
/**
 * Get one with a specific filter object
 * @param filter
 * @return
 */
@Override
public Flowable<Optional<T>> getOne(Filter filter, SortingMode sortingMode) {
    Realm realm = Realm.getDefaultInstance();
    RealmQuery<T> query = realm.where(clazz);
    query = filterToQuery(filter, query);
    T item = null;
    if (sortingMode != null) {
        RealmResults<T> items = applySortingMode(sortingMode, query);
        if (!items.isEmpty()) {
            item = items.first();
        }
    } else {
        item = query.findFirst();
    }
    T copy = null;
    if (item != null) {
        copy = realm.copyFromRealm(item);
    }
    realm.close();
    return Flowable.just(Optional.wrap(copy));
}
 
开发者ID:playmoweb,项目名称:store2realm,代码行数:27,代码来源:RealmDao.java

示例2: populateRealm

import io.realm.Realm; //导入依赖的package包/类
private void populateRealm() {
    final Realm realm = Realm.getDefaultInstance();

    final Author moses = new Author();
    moses.name = "Moses";
    final Book genesis = new Book();
    genesis.index = 0;
    genesis.name = "Genesis";
    genesis.author = moses;
    final Book exodus = new Book();
    exodus.index = 1;
    exodus.name = "Exodus";
    exodus.author = moses;
    final Book hebrews = new Book();
    hebrews.index = 57;
    hebrews.name = "Letter to the Hebrews";

    realm.beginTransaction();
    realm.copyToRealmOrUpdate(genesis);
    realm.copyToRealmOrUpdate(exodus);
    realm.copyToRealmOrUpdate(hebrews);
    realm.commitTransaction();

    realm.close();
}
 
开发者ID:xizzhu,项目名称:stetho-realm,代码行数:26,代码来源:App.java

示例3: searchCompanies

import io.realm.Realm; //导入依赖的package包/类
@Override
public Observable<List<Company>> searchCompanies(@NonNull String keyWords) {
    Realm rlm = RealmHelper.newRealmInstance();
    List<Company> results = rlm.copyFromRealm(
            rlm.where(Company.class)
                    .like("name","*" + keyWords + "*", Case.INSENSITIVE)
                    .or()
                    .like("tel", "*" + keyWords + "*", Case.INSENSITIVE)
                    .or()
                    .like("website", "*" + keyWords + "*", Case.INSENSITIVE)
                    .or()
                    .like("alphabet", "*" + keyWords + "*", Case.INSENSITIVE)
                    .findAllSorted("alphabet", Sort.ASCENDING));
    return Observable.fromIterable(results)
            .toList()
            .toObservable();
}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:18,代码来源:CompaniesLocalDataSource.java

示例4: getByUser

import io.realm.Realm; //导入依赖的package包/类
@Override
public void getByUser(String authorId, Callbacks.IResultsCallback<Post> callback) {
    Realm realm = Realm.getDefaultInstance();

    try {
        List<Post> result = realm
                .where(Post.class)
                .equalTo("authorId", authorId) // Fetch posts by author id
                .findAll();

        if (result == null || result.isEmpty()) {
            callback.onDataUnavailable();
            return;
        }

        // Retrieve the data
        callback.onSuccess(result);
    } catch (Exception ex) {
        ex.printStackTrace();
        callback.onDataUnavailable();
    }
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:23,代码来源:PostsLocalDataSource.java

示例5: fetchRandomMovieOrTvSeries

import io.realm.Realm; //导入依赖的package包/类
private Movie fetchRandomMovieOrTvSeries() {
    Realm realm = Realm.getDefaultInstance();
    //TODO: Add Random TV Series to fetch
    RealmResults<Movie> movieRealmResults = realm.where(Movie.class).equalTo("isNotified", false).findAll();

    Util.debugLog(TAG, "fetchRandomMovieOrTvSeries: Size of movies with isNotified false " + movieRealmResults.size());

    if (movieRealmResults.size() != 0) {

        Random r = new Random();
        int randomNumber = r.nextInt(movieRealmResults.size());

        Movie movie = movieRealmResults.get(randomNumber);

        realm.beginTransaction();
        movieRealmResults.get(randomNumber).setNotified(true);
        realm.commitTransaction();


        return movie;
    } else {
        return null;
    }
}
 
开发者ID:hsm59,项目名称:WatchIt,代码行数:25,代码来源:NotificationPublisher.java

示例6: getBadgeUrl

import io.realm.Realm; //导入依赖的package包/类
@Override
@NonNull
public String getBadgeUrl(String idTeam){
    try(Realm realm = realmProvider.get()){
        TeamRealm teamRealm = realm.where(TeamRealm.class).equalTo("idTeam",idTeam).findFirst();
        if(teamRealm != null){
            if(teamRealm.getStrTeamBadge() != null && ! teamRealm.getStrTeamBadge().isEmpty())
                return teamRealm.getStrTeamBadge();
            else if(teamRealm.getStrTeamLogo() != null && ! teamRealm.getStrTeamLogo().isEmpty())
                return teamRealm.getStrTeamLogo();
            else if(teamRealm.getStrTeamJersey() != null && ! teamRealm.getStrTeamJersey().isEmpty())
                return teamRealm.getStrTeamJersey();
        }
        return "http://www.wunapps.com/2015/lg/padres_lg/images/lg-team-badge-08.png";
    }
}
 
开发者ID:domgeorg,项目名称:INFOotball,代码行数:17,代码来源:RealmManager.java

示例7: updateCoverPhotos

import io.realm.Realm; //导入依赖的package包/类
public static void updateCoverPhotos() {
    long time = System.currentTimeMillis();
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    for (Album a : realm.where(Album.class).findAll()) {
        switch (Media.getMediaSortType()) {
            case ALPHABETICAL: {
                a.setCoverPath(a.getMedia().sort("name", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath());
                break;
            }
            case DATE: {
                a.setCoverPath(a.getMedia().sort("date", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath());
                break;
            }
        }
    }
    realm.commitTransaction();
    realm.close();
    Log.d(Util.LOG_TAG, "Reloading all cover photos took " + (System.currentTimeMillis() - time));
}
 
开发者ID:garretyoder,项目名称:Cluttr,代码行数:21,代码来源:MediaLoader.java

示例8: initRealm

import io.realm.Realm; //导入依赖的package包/类
private void initRealm() {
    realm = Realm.getDefaultInstance();
    realmResults = realm.where(ImageBean.class).equalTo("hasFace", true).findAllAsync();
    realmResults.addChangeListener(new RealmChangeListener<RealmResults<ImageBean>>() {
        @Override
        public void onChange(RealmResults<ImageBean> results) {
            if (results.size() > 0) {
                Log.e(TAG, "results size: " + results.size());
                mTvSearchHint.setVisibility(View.GONE);
                mImages.clear();
                mImages.addAll(results.subList(0, results.size()));
                if (mFaceAdapter != null) {
                    mFaceAdapter.notifyDataSetChanged();
                    Log.e(TAG, "getItemCount: " + mFaceAdapter.getItemCount());
                }
            } else {
                mTvSearchHint.setVisibility(View.VISIBLE);
            }
        }
    });
}
 
开发者ID:SimonCherryGZ,项目名称:face-landmark-android,代码行数:22,代码来源:ARFaceFragment.java

示例9: setFeeds

import io.realm.Realm; //导入依赖的package包/类
public static void setFeeds(final ArrayList<FeedWrapper> subs) {
    Realm.getDefaultInstance().executeTransaction(new Realm.Transaction() {
        @Override
        public void execute(Realm realm) {
            for (int i = 0; i < subs.size(); i++) {
                subs.get(i).setOrder(i);
            }
            for (FeedWrapper f : subs) {
                if(f instanceof Feed){
                    realm.insertOrUpdate((Feed)f);
                } else {
                    realm.insertOrUpdate((Category)f);
                }
            }
        }
    });
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:18,代码来源:UserFeeds.java

示例10: onPostExecute

import io.realm.Realm; //导入依赖的package包/类
@Override
protected void onPostExecute(final Feed feed) {
    if (feed != null) {
        new AlertDialogWrapper.Builder(ReorderFeeds.this).setTitle("Feed added successfully!").setPositiveButton("Ok!", null).show();
        Realm.getDefaultInstance().executeTransactionAsync(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                realm.copyToRealmOrUpdate(feed);
            }
        }, new Realm.Transaction.OnSuccess() {
            @Override
            public void onSuccess() {
                doAddSub(feed);
            }
        });
    } else {
        new SearchSiteTask().execute(url);
    }
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:20,代码来源:ReorderFeeds.java

示例11: onCreate

import io.realm.Realm; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();

    Realm.init(this);
    Stetho.initialize(Stetho.newInitializerBuilder(this)
        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
        .enableWebKitInspector(
            new StethoRealmInspectorModulesProvider.Builder(this).dirs(getFilesDir(),
                new File(getFilesDir(), "custom")).build())
        .build());

    populateRealm();
    populateRealm2();
    populateRealmIgnored();
}
 
开发者ID:xizzhu,项目名称:stetho-realm,代码行数:17,代码来源:App.java

示例12: getById

import io.realm.Realm; //导入依赖的package包/类
@Override
public void getById(String postId, Callbacks.IResultCallback<Post> callback) {
    Realm realm = Realm.getDefaultInstance();

    try {
        //Return the first item tha id match with postId
        Post result = realm
                .where(Post.class)
                .equalTo("id", postId)
                .findFirst();

        // Check if there is a valid data
        if (result == null) {
            callback.onDataUnavailable();
            return;
        }

        // Return the data
        callback.onSuccess(result);
    } catch (Exception ex) {
        ex.printStackTrace();
        callback.onDataUnavailable();
    }
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:25,代码来源:PostsLocalDataSource.java

示例13: btn_logout_click

import io.realm.Realm; //导入依赖的package包/类
public void btn_logout_click(View v) {
    RealmConfiguration config = new RealmConfiguration.Builder().name("yyox.realm").build();
    Realm objRealm = Realm.getInstance(config);

    //查找
    RealmUser realmUser = objRealm.where(RealmUser.class).findFirst();
    if (realmUser != null) {
        //先删除
        objRealm.beginTransaction();
        RealmResults results = objRealm.where(RealmUser.class).findAll();
        results.deleteAllFromRealm();
        objRealm.commitTransaction();

    }
    mPresenter.requestLogout(this);
    WEApplication weApplication = (WEApplication) getApplication();
    weApplication.setRealmUser(null);

    Intent intent = new Intent();
    setResult(CodeDefine.SETTING_RESULT, intent);
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:22,代码来源:UserSettingActivity.java

示例14: run

import io.realm.Realm; //导入依赖的package包/类
@Override
protected void run() {
    user = UserFactory.getInstance().loginWithDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;

    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl)
            .directory(getService().getRoot())
            .build();
    getService().setRealm(Realm.getInstance(syncConfig));
    Realm realm = getService().getRealm();

    realm.beginTransaction();
    ProcessInfo processInfo = realm.createObject(ProcessInfo.class);
    processInfo.setName("Background_Process1");
    processInfo.setPid(android.os.Process.myPid());
    processInfo.setThreadId(Thread.currentThread().getId());
    realm.commitTransaction();
    // FIXME: If we close the Realm here, the data won't be able to synced to the main process. Is it a bug
    // in sync client which stops too early?
    // Realm is currently configured with stop_immediately. This means the sync session is closed as soon as
    // the last realm instance is closed. Not doing this would make the Realm lifecycle really
    // unpredictable. We should have an easy way to wait for all changes to be uploaded though.
    // Perhaps SyncSession.uploadAllLocalChanges() or something similar to
    // SyncSesson.downloadAllServerChanges()
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ProcessCommitTests.java

示例15: onCreate

import io.realm.Realm; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = (TextView) findViewById(R.id.textView);

    if (realm == null) {
        realm = Realm.getDefaultInstance();
        processInfoResults = realm.where(ProcessInfo.class).findAllAsync();
        processInfoResults.addChangeListener(listener);
    }

    realm.beginTransaction();
    realm.copyToRealmOrUpdate(Utils.createStandaloneProcessInfo(this));
    realm.commitTransaction();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:MainActivity.java


注:本文中的io.realm.Realm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。