本文整理匯總了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));
}
示例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();
}
示例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();
}
示例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();
}
}
示例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;
}
}
示例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";
}
}
示例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));
}
示例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);
}
}
});
}
示例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);
}
}
}
});
}
示例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);
}
}
示例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();
}
示例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();
}
}
示例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);
}
示例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()
}
示例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();
}