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