本文整理汇总了Java中io.realm.Realm.copyFromRealm方法的典型用法代码示例。如果您正苦于以下问题:Java Realm.copyFromRealm方法的具体用法?Java Realm.copyFromRealm怎么用?Java Realm.copyFromRealm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.Realm
的用法示例。
在下文中一共展示了Realm.copyFromRealm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAll
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public Flowable<Optional<List<T>>> getAll(List<T> items) {
Realm realm = Realm.getDefaultInstance();
RealmQuery<T> query = realm.where(clazz);
if(items.size() > 0){
String paramName = items.get(0).getUniqueIdentifierName();
Integer[] keys = new Integer[items.size()];
for(int i = 0; i < items.size(); i++){
keys[i] = items.get(i).getUniqueIdentifier();
}
query.in(paramName, keys);
}
List<T> copies = realm.copyFromRealm(query.findAll());
realm.close();
return Flowable.just(Optional.wrap(copies));
}
示例2: 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));
}
示例3: insertOrUpdate
import io.realm.Realm; //导入方法依赖的package包/类
/**
* Insert or update all
* @param items
* @return List of item copied from realm
*/
@Override
public Flowable<Optional<List<T>>> insertOrUpdate(List<T> items) {
final Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
items = realm.copyToRealmOrUpdate(items);
realm.commitTransaction();
List<T> copies = realm.copyFromRealm(items);
realm.close();
return Flowable.just(Optional.wrap(copies));
}
示例4: setPackageReadable
import io.realm.Realm; //导入方法依赖的package包/类
/**
* Set a package of specific number read or unread new.
* @param packageId The primary key or the package id.
* See {@link Package#number}
* @param readable Read or unread new.
* See {@link Package#readable}
*/
@Override
public void setPackageReadable(@NonNull String packageId, boolean readable) {
Realm rlm = RealmHelper.newRealmInstance();
Package p = rlm.copyFromRealm(rlm.where(Package.class)
.equalTo("number", packageId)
.findFirst());
if (p != null) {
rlm.beginTransaction();
p.setReadable(readable);
// When a package is not readable, it is not pushable.
p.setPushable(readable);
rlm.copyToRealmOrUpdate(p);
rlm.commitTransaction();
rlm.close();
}
}
示例5: 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();
}
示例6: setAllPackagesRead
import io.realm.Realm; //导入方法依赖的package包/类
/**
* Set all the packages which are the unread new read.
*/
@Override
public void setAllPackagesRead() {
Realm rlm = RealmHelper.newRealmInstance();
List<Package> results = rlm.copyFromRealm(rlm.where(Package.class).findAll());
for (Package p : results) {
p.setReadable(false);
p.setPushable(false);
rlm.beginTransaction();
rlm.copyToRealmOrUpdate(p);
rlm.commitTransaction();
}
rlm.close();
}
示例7: getViewAt
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public RemoteViews getViewAt(int position) {
RemoteViews remoteViews = new RemoteViews(
context.getPackageName(), R.layout.item_package_for_widget);
Realm rlm = Realm.getInstance(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.name(DATABASE_NAME)
.build());
List<Package> results = rlm.copyFromRealm(rlm.where(Package.class)
.notEqualTo("state", String.valueOf(Package.STATUS_DELIVERED))
.findAllSorted("timestamp", Sort.DESCENDING));
Package p = results.get(position);
if (p.getData() != null && p.getData().size() > 0) {
int state = Integer.parseInt(p.getState());
remoteViews.setTextViewText(R.id.textViewStatus,
String.valueOf(packageStatus[state]) + " - " + p.getData().get(0).getContext());
remoteViews.setTextViewText(R.id.textViewTime, p.getData().get(0).getTime());
} else {
remoteViews.setTextViewText(R.id.textViewTime, "");
remoteViews.setTextViewText(R.id.textViewStatus, statusError);
}
remoteViews.setTextViewText(R.id.textViewPackageName, p.getName());
remoteViews.setTextViewText(R.id.textViewAvatar, p.getName().substring(0, 1));
remoteViews.setImageViewResource(R.id.imageViewAvatar, p.getColorAvatar());
Intent intent = new Intent();
intent.putExtra(PackageDetailsActivity.PACKAGE_ID, p.getNumber());
remoteViews.setOnClickFillInIntent(R.id.layoutPackageItemMain, intent);
return remoteViews;
}
示例8: get
import io.realm.Realm; //导入方法依赖的package包/类
public static <O extends RealmObject> O get(Realm realmInstance, QueryFilters filters, Class<O> clazz) throws LocalDataNotFoundException{
Realm realm = realmInstance;
RealmQuery<O> query = realm.where(clazz);
query = filters.copyToRealmQuery(query);
O result = query.findFirst();
if(result != null){
O finalResult = realm.copyFromRealm(result);
realm.close();
return finalResult;
}
throw new SessionNotFoundException("queried data is not found");
}
示例9: getList
import io.realm.Realm; //导入方法依赖的package包/类
public static <O extends RealmObject> List<O> getList(Realm realmInstance, QueryFilters filters, Class<O> clazz) throws LocalDataNotFoundException{
Realm realm = realmInstance;
RealmQuery<O> query = realm.where(clazz);
query = filters.copyToRealmQuery(query);
List<O> results = realm.copyFromRealm(query.findAll());
realm.close();
return results;
}
示例10: setMother
import io.realm.Realm; //导入方法依赖的package包/类
public void setMother(final String id) {
Realm realm = Realm.getDefaultInstance();
elephant.mother = realm.where(Elephant.class).equalTo(ID, id).findFirst();
elephant.mother = realm.copyFromRealm(elephant.mother);
motherButton.setVisibility(View.GONE);
motherPreview.setElephant(elephant.mother);
motherPreview.setVisibility(View.VISIBLE);
realm.close();
}
示例11: setFather
import io.realm.Realm; //导入方法依赖的package包/类
public void setFather(String id) {
Realm realm = Realm.getDefaultInstance();
elephant.father = realm.where(Elephant.class).equalTo(ID, id).findFirst();
elephant.father = realm.copyFromRealm(elephant.father);
fatherButton.setVisibility(View.GONE);
fatherPreview.setElephant(elephant.father);
fatherPreview.setVisibility(View.VISIBLE);
realm.close();
}
示例12: loadDocuments
import io.realm.Realm; //导入方法依赖的package包/类
private void loadDocuments() {
Realm realm = Realm.getDefaultInstance();
Integer id = ((ShowElephantActivity)getActivity()).getElephant().id;
List<Document> results = realm.copyFromRealm(realm.where(Document.class).equalTo(Document.ELEPHANT_ID, id).findAll());
adapter = new DocumentAdapter(getContext(), results, new DocumentAdapter.Listener() {
@Override
public void onDocumentClick(Document document) {
((ShowElephantActivity)getActivity()).onDocumentClick(document);
}
});
}
示例13: onHandleIntent
import io.realm.Realm; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Log.d(TAG, "onHandleIntent: ");
boolean isDisturbMode = preference.getBoolean(SettingsUtil.KEY_DO_NOT_DISTURB_MODE, true);
// The alert mode is off
// or DO-NOT-DISTURB-MODE is off
// or time now is not in the DO-NOT-DISTURB-MODE range.
if (isDisturbMode && PushUtil.isInDisturbTime(this, Calendar.getInstance())) {
return;
}
Realm rlm = RealmHelper.newRealmInstance();
List<Package> results = rlm.copyFromRealm(
rlm.where(Package.class)
.notEqualTo("state", String.valueOf(Package.STATUS_DELIVERED))
.findAll());
for (int i = 0; i < results.size(); i++){
Package p = results.get(i);
// Avoid repeated pushing
if (p.isPushable()) {
Realm realm = RealmHelper.newRealmInstance();
p.setPushable(false);
pushNotification(i + 1001, setNotifications(i, p));
realm.beginTransaction();
realm.copyToRealmOrUpdate(p);
realm.commitTransaction();
realm.close();
} else if (NetworkUtil.networkConnected(getApplicationContext())) {
refreshPackage(i, results.get(i));
}
}
rlm.close();
}
示例14: populateUI
import io.realm.Realm; //导入方法依赖的package包/类
private void populateUI() {
Realm realm = Realm.getDefaultInstance();
trip = realm.copyFromRealm(realm.where(Trip.class).equalTo("id", tripId).findFirst());
realm.close();
originalPath = trip.toConnectionPath(network);
if (!trip.canBeCorrected()) {
finish();
}
List<Station> stations = new ArrayList<>(network.getStations());
startPicker.setStations(stations);
endPicker.setStations(stations);
startPicker.setAllStationsSortStrategy(new StationPickerView.DistanceSortStrategy(network, originalPath.getStartVertex()));
endPicker.setAllStationsSortStrategy(new StationPickerView.DistanceSortStrategy(network, originalPath.getEndVertex()));
startPicker.setWeakSelection(originalPath.getStartVertex().getStation());
endPicker.setWeakSelection(originalPath.getEndVertex().getStation());
StationPickerView.OnStationSelectedListener onStationSelectedListener = new StationPickerView.OnStationSelectedListener() {
@Override
public void onStationSelected(Station station) {
redrawPath();
}
};
startPicker.setOnStationSelectedListener(onStationSelectedListener);
endPicker.setOnStationSelectedListener(onStationSelectedListener);
StationPickerView.OnSelectionLostListener onSelectionLostListener = new StationPickerView.OnSelectionLostListener() {
@Override
public void onSelectionLost() {
redrawPath();
}
};
startPicker.setOnSelectionLostListener(onSelectionLostListener);
endPicker.setOnSelectionLostListener(onSelectionLostListener);
redrawPath();
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveChanges();
}
});
}
示例15: getAllBlogs
import io.realm.Realm; //导入方法依赖的package包/类
public static List<BlogMetadata> getAllBlogs() {
final Realm realm = Realm.getDefaultInstance();
return realm.copyFromRealm(realm
.where(BlogMetadata.class)
.findAll());
}