本文整理汇总了Java中io.realm.Realm.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Realm.getInstance方法的具体用法?Java Realm.getInstance怎么用?Java Realm.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.Realm
的用法示例。
在下文中一共展示了Realm.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logoutRealmUser
import io.realm.Realm; //导入方法依赖的package包/类
private void logoutRealmUser() {
//注册成功写数据库
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();
//再添加
objRealm.beginTransaction();
RealmUser realmUserNew = objRealm.createObject(RealmUser.class);
realmUserNew.setName("");
objRealm.commitTransaction();
mRealmUser = null;
}
}
示例2: insert
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public boolean insert(TodoListItem item) {
Realm realm = Realm.getInstance(configuration);
final TodoListItemDAO dao = RealmConverter.convert(item);
realm.beginTransaction();
try {
realm.copyToRealm(dao);
realm.commitTransaction();
} catch (Throwable throwable) {
realm.cancelTransaction();
realm.close();
return false;
}
realm.close();
return true;
}
示例3: populateRealmIgnored
import io.realm.Realm; //导入方法依赖的package包/类
private void populateRealmIgnored() {
final Realm realm =
Realm.getInstance(new RealmConfiguration.Builder().name("realm.ignored").build());
final Author moses = new Author();
moses.name = "Moses";
final Book genesis = new Book();
genesis.index = 0;
genesis.name = "Genesis";
genesis.author = moses;
realm.beginTransaction();
realm.copyToRealmOrUpdate(genesis);
realm.commitTransaction();
realm.close();
}
示例4: processRawData
import io.realm.Realm; //导入方法依赖的package包/类
public static ReadingData processRawData(String sensorTagId, byte[] data) {
// copy data to database
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
Realm realmRawData = Realm.getInstance(realmConfigRawData);
// commit raw data into realm for debugging
realmRawData.beginTransaction();
RawTagData rawTagData = realmRawData.copyToRealmOrUpdate(new RawTagData(sensorTagId, data));
realmRawData.commitTransaction();
// commit processed data into realm
realmProcessedData.beginTransaction();
ReadingData readingData = realmProcessedData.copyToRealmOrUpdate(new ReadingData(rawTagData));
realmProcessedData.commitTransaction();
realmProcessedData.close();
realmRawData.close();
return readingData;
}
示例5: onCreate
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Settings.init(this);
Realm.init(this);
realm = Realm.getInstance(getRealmConfiguration());
if (!BuildConfig.DEBUG) {
Fabric.with(this, new Crashlytics());
} else {
initStrictMode();
}
}
示例6: RealmHelper
import io.realm.Realm; //导入方法依赖的package包/类
private RealmHelper() {
try {
mRealm = Realm.getDefaultInstance();
} catch (Exception e) {
RealmConfiguration config = new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.build();
mRealm = Realm.getInstance(config);
}
}
示例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包/类
@Override
public Optional<Note> get(String uuid) {
Realm realm = Realm.getInstance(configuration);
Optional<NoteDAO> noteDAO = Optional.fromNullable(realm.where(NoteDAO.class).equalTo("uuid", uuid).findFirst());
Optional<Note> note = noteDAO.transform(new NoteDAOConverter());
realm.close();
return note;
}
示例9: getHeaderCountOfTodoList
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public int getHeaderCountOfTodoList(String uuid) {
Realm realm = Realm.getInstance(configuration);
int size = (int) realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", uuid).count();
realm.close();
return size;
}
示例10: loadDataFromDB
import io.realm.Realm; //导入方法依赖的package包/类
private void loadDataFromDB() {
Realm realm = Realm.getInstance(ApplicationController.getInstance().getRealmConfig());
RealmResults<RMoviesDTO> rMoviesDTOs = realm.where(RMoviesDTO.class).findAllSorted("release_date", Sort.DESCENDING);
for (RMoviesDTO rMoviesDTO : rMoviesDTOs) {
moviesDTOs.add(new MoviesDTO(rMoviesDTO));
}
moviesAdapter.notifyDataSetChanged();
realm.close();
}
示例11: before
import io.realm.Realm; //导入方法依赖的package包/类
@BeforeExperiment
public void before() {
RealmConfiguration config = new RealmConfiguration.Builder().build();
Realm.deleteRealm(config);
realm = Realm.getInstance(config);
realm.beginTransaction();
writeObject = realm.createObject(AllTypes.class);
}
示例12: logout
import io.realm.Realm; //导入方法依赖的package包/类
/**
* Logs the user out of their current session.
*/
public static void logout(Context context)
{
// Destroy USER database
Realm realm = Realm.getInstance(getRealmConfig(context, RealmLevel.USER));
realm.beginTransaction();
realm.deleteAll();
realm.commitTransaction();
// Clear "session"
USER = null;
USERNAME = null;
DEK = null;
}
示例13: getSectionsOfTodoListId
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public List<TodoListSection> getSectionsOfTodoListId(String uuid) {
Realm realm = Realm.getInstance(configuration);
RealmResults<TodoListHeaderDAO> headerDAOs = realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", uuid).findAll();
List<TodoListSection> sections = new ArrayList<>(headerDAOs.size());
for (TodoListHeaderDAO dao : headerDAOs) {
sections.add(constructSection(realm, dao));
}
realm.close();
return sections;
}
示例14: open
import io.realm.Realm; //导入方法依赖的package包/类
public void open() {
// Don't use Realm.setDefaultInstance() in library projects. It is unsafe as app developers can override the
// default configuration. So always use explicit configurations in library projects.
realm = Realm.getInstance(realmConfig);
}
示例15: ViewerFileDao
import io.realm.Realm; //导入方法依赖的package包/类
@Inject
public ViewerFileDao(RealmConfiguration realmConfiguration) {
super(Realm.getInstance(realmConfiguration), ViewerFile.class);
}