Java Code Examples for io.realm.Realm#getInstance()
The following examples show how to use
io.realm.Realm#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SiberiRealmDB.java From siberi-android with MIT License | 6 votes |
@Override public ExperimentContent select(String testName) { realm = Realm.getInstance(configuration); try { RealmResults<ExperimentObject> results = realm.where(ExperimentObject.class).equalTo("testName", testName).findAll(); if (results.size() > 0) { ExperimentObject experimentObject = results.get(0); ExperimentContent experimentContent = new ExperimentContent(testName); experimentContent.setVariant(experimentObject.getVariant()); try { experimentContent.setMetaData(new JSONObject(experimentObject.getMetaData())); } catch (JSONException e) { e.printStackTrace(); } return experimentContent; } else { return null; } } finally { realm.close(); } }
Example 2
Source File: MainActivity.java From nosey with Apache License 2.0 | 6 votes |
private void populateModelWithData() { Log.d("populateModelWithData", "Adding 10 Items to Data."); Random random = new Random(); Realm realm = Realm.getInstance(this); realm.beginTransaction(); SomeModelA instance; for (int i = 0; i < 10; i++) { instance = realm.createObject(SomeModelA.class); instance.setField1(100 + random.nextInt() % 10); instance.setField2(200 + random.nextInt() % 10); instance.setField3(300 + random.nextInt() % 10); instance.setField4(400 + random.nextInt() % 10); instance.setField5(500 + random.nextInt() % 10); instance.setField6(600 + random.nextInt() % 10); instance.setField7(700 + random.nextInt() % 10); instance.setModelA(realm.createObject(SomeModelA.class)); instance.setField8("This is a string"); } realm.commitTransaction(); }
Example 3
Source File: RealmTokenSource.java From ETHWallet with GNU General Public License v3.0 | 5 votes |
private Realm getRealmInstance(NetworkInfo networkInfo, Wallet wallet) { RealmConfiguration config = new RealmConfiguration.Builder() .name(wallet.getAddress() + "-" + networkInfo.name + ".realm") .schemaVersion(1) .build(); return Realm.getInstance(config); }
Example 4
Source File: NetworkService.java From quill with MIT License | 5 votes |
@Subscribe public void onLogoutEvent(LogoutEvent event) { if (!event.forceLogout) { long numPostsWithPendingActions = mRealm .where(Post.class) .isNotEmpty("pendingActions") .count(); if (numPostsWithPendingActions > 0) { getBus().post(new LogoutStatusEvent(false, true)); return; } } // revoke access and refresh tokens in the background mAuthService.revokeToken(mAuthToken); // clear all persisted blog data to avoid primary key conflicts mRealm.close(); Realm.deleteRealm(mRealm.getConfiguration()); String activeBlogUrl = AccountManager.getActiveBlogUrl(); new AuthStore().deleteCredentials(activeBlogUrl); AccountManager.deleteBlog(activeBlogUrl); // switch the Realm to the now-active blog if (AccountManager.hasActiveBlog()) { mRealm = Realm.getInstance(AccountManager.getActiveBlog().getDataRealmConfig()); } // reset state, to be sure mAuthToken = null; mAuthService = null; mApiEventQueue.clear(); mRefreshEventsQueue.clear(); mbSyncOnGoing = false; mRefreshError = null; getBus().post(new LogoutStatusEvent(true, false)); }
Example 5
Source File: UserRealmRepositoryTests.java From DebugRank with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); RealmConfiguration config = new RealmConfiguration.Builder(getContext()). schemaVersion(1). name("test.realm"). inMemory(). build(); Realm.setDefaultConfiguration(config); realm = Realm.getInstance(config); ILogger logger = mock(ILogger.class); repository = new UserRealmRepository(realm, logger); //every test method needs data ProgrammingLanguage language = new ProgrammingLanguage("java_8", "Java 8", ".java", 1); Puzzle puzzle = new Puzzle("basic_operator", "Basic Operator", 1, 2, 3, new String[]{"testcase"}, new String[]{"answer"}); repository.saveCompletedPuzzle(language, puzzle); language = new ProgrammingLanguage("javascript", "JavaScript", ".js", 2); puzzle = new Puzzle("basic_operator", "Basic Operator", 4, 5, 6, new String[]{"testcase"}, new String[]{"answer"}); repository.saveCompletedPuzzle(language, puzzle); }
Example 6
Source File: InsertDataActivity.java From example with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_insert_data); ButterKnife.inject(this); realm = Realm.getInstance(this); }
Example 7
Source File: ManagedLiveResults.java From realm-monarchy with Apache License 2.0 | 5 votes |
@Override protected void onActive() { realm = Realm.getInstance(realmConfiguration); RealmQuery<T> realmQuery = query.createQuery(realm); if(asAsync) { realmResults = realmQuery.findAllAsync(); // sort/distinct should be done with new queries, 5.0+ } else { realmResults = realmQuery.findAll(); // sort/distinct should be done with new queries, 5.0+ } realmResults.addChangeListener(realmChangeListener); if(!asAsync) { setValue(new Monarchy.ManagedChangeSet<T>(realmResults, new EmptyChangeSet())); } }
Example 8
Source File: Monarchy.java From realm-monarchy with Apache License 2.0 | 5 votes |
/** * Allows to manually use Realm instance and will automatically close it when done. * * @param realmBlock the Realm execution block in which Realm should remain open */ public final void doWithRealm(final RealmBlock realmBlock) { RealmConfiguration configuration = getRealmConfiguration(); Realm realm = null; try { realm = Realm.getInstance(configuration); realmBlock.doWithRealm(realm); } finally { if(realm != null) { realm.close(); } } }
Example 9
Source File: ExportActivity.java From SensorDashboard with Apache License 2.0 | 5 votes |
private void deleteData() { mRealm = Realm.getInstance(this); mRealm.beginTransaction(); RealmResults<DataEntry> result = mRealm.where(DataEntry.class).findAll(); Log.e("SensorDashboard", "rows after delete = " + result.size()); // Delete all matches result.clear(); mRealm.commitTransaction(); result = mRealm.where(DataEntry.class).findAll(); Log.e("SensorDashboard", "rows after delete = " + result.size()); }
Example 10
Source File: FormatKit.java From 600SeriesAndroidUploader with MIT License | 5 votes |
public String getNameTempBasalPreset(int preset) { String name = ""; try { Realm storeRealm = Realm.getInstance(UploaderApplication.getStoreConfiguration()); DataStore dataStore = storeRealm.where(DataStore.class).findFirst(); name = dataStore.getNameTempBasalPreset(preset); storeRealm.close(); } catch (Exception ignored) {} return name; }
Example 11
Source File: ReadDataActivity.java From example with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_data); realm = Realm.getInstance(this); RealmQuery<User> query = realm.where(User.class); RealmResults<User> result = query.findAll(); for (User data : result) { Log.d("test", "Name : " + data.getName() + ", age : " + data.getAge()); } }
Example 12
Source File: RealmBufferResolver.java From TimberLorry with Apache License 2.0 | 5 votes |
@Override public void clear() { Realm realm = null; try { realm = Realm.getInstance(realmConfig); realm.beginTransaction(); realm.where(RecordObject.class).findAll().clear(); realm.commitTransaction(); } finally { if (realm != null) realm.close(); } }
Example 13
Source File: RealmTokenSource.java From Upchain-wallet with GNU Affero General Public License v3.0 | 5 votes |
private Realm getRealmInstance(NetworkInfo networkInfo, String walletAddress) { RealmConfiguration config = new RealmConfiguration.Builder() .name(walletAddress + "-" + networkInfo.name + ".realm") .schemaVersion(1) .build(); return Realm.getInstance(config); }
Example 14
Source File: TodoRealmManager.java From todo-android with Apache License 2.0 | 4 votes |
public TodoRealmManager(Context context) { realm = Realm.getInstance(context); }
Example 15
Source File: RealmDatabase.java From mvvm-template with GNU General Public License v3.0 | 4 votes |
public RepositoryDao newRepositoryDao() { return new RepositoryDaoImpl(Realm.getInstance(mRealmConfiguration)); }
Example 16
Source File: MainActivity.java From 600SeriesAndroidUploader with MIT License | 4 votes |
synchronized private void openRealmHistory() { if (historyRealm == null) historyRealm = Realm.getInstance(UploaderApplication.getHistoryConfiguration()); }
Example 17
Source File: EventDao.java From mvvm-template with GNU General Public License v3.0 | 4 votes |
@Inject public EventDao(RealmConfiguration config) { super(Realm.getInstance(config), Event.class); }
Example 18
Source File: NightscoutUploadService.java From 600SeriesAndroidUploader with MIT License | 4 votes |
public void run() { PowerManager.WakeLock wl = getWakeLock(mContext, TAG, 60000); storeRealm = Realm.getInstance(UploaderApplication.getStoreConfiguration()); dataStore = storeRealm.where(DataStore.class).findFirst(); statNightscout = (StatNightscout) Stats.getInstance().readRecord(StatNightscout.class); statNightscout.incRun(); pumpHistoryHandler = new PumpHistoryHandler(mContext); if (dataStore.isNightscoutUpload()) { new NightscoutStatus(mContext).check(); if (dataStore.isNightscoutAvailable()) { realm = Realm.getDefaultInstance(); do { rerun = false; updateDB(); uploadRecords(); if (rerun) { acquireWakelock(wl, 60000); if (nightscoutUploadProcess != null && !nightscoutUploadProcess.isCancel()) { // cooldown period try { Thread.sleep(5000); } catch (InterruptedException ignored) { } } // refresh database realm.refresh(); storeRealm.refresh(); pumpHistoryHandler.refresh(); } } while (rerun && dataStore.isNightscoutUpload()); } else { statNightscout.incSiteUnavailable(); updateDB(); } } else { updateDB(); } if (pumpHistoryHandler != null) pumpHistoryHandler.close(); if (realm != null) realm.close(); if (storeRealm != null) storeRealm.close(); releaseWakeLock(wl); stopSelf(); }
Example 19
Source File: RealmProvider.java From talk-android with MIT License | 4 votes |
public static Realm getInstance() { return Realm.getInstance(RealmConfig.getTalkRealm()); }
Example 20
Source File: UserReposDao.java From mvvm-template with GNU General Public License v3.0 | 4 votes |
@Inject public UserReposDao(RealmConfiguration realmConfiguration) { super(Realm.getInstance(realmConfiguration), Repo.class); }