Java Code Examples for io.realm.Realm#deleteRealm()
The following examples show how to use
io.realm.Realm#deleteRealm() .
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: SpectreApplication.java From quill with MIT License | 7 votes |
private void setupMetadataRealm() { final int METADATA_DB_SCHEMA_VERSION = 4; Realm.init(this); RealmConfiguration config = new RealmConfiguration.Builder() .modules(new BlogMetadataModule()) .schemaVersion(METADATA_DB_SCHEMA_VERSION) .migration(new BlogMetadataDBMigration()) .build(); Realm.setDefaultConfiguration(config); // open the Realm to check if a migration is needed try { Realm realm = Realm.getDefaultInstance(); realm.close(); } catch (RealmMigrationNeededException e) { // delete existing Realm if we're below v4 if (mHACKOldSchemaVersion >= 0 && mHACKOldSchemaVersion < 4) { Realm.deleteRealm(config); mHACKOldSchemaVersion = -1; } } AnalyticsService.logMetadataDbSchemaVersion(String.valueOf(METADATA_DB_SCHEMA_VERSION)); }
Example 2
Source File: OpenLibre.java From OpenLibre with GNU General Public License v3.0 | 6 votes |
private static boolean tryRealmStorage(File path) { // check where we can actually store the databases on this device RealmConfiguration realmTestConfiguration; // catch all errors when creating directory and db try { realmTestConfiguration = new RealmConfiguration.Builder() .directory(path) .name("test_storage.realm") .deleteRealmIfMigrationNeeded() .build(); Realm testInstance = Realm.getInstance(realmTestConfiguration); testInstance.close(); Realm.deleteRealm(realmTestConfiguration); } catch (Throwable e) { Log.i(LOG_ID, "Test creation of realm failed for: '" + path.toString() + "': " + e.toString()); return false; } return true; }
Example 3
Source File: TestRealmConfigurationFactory.java From realm-android-user-store with Apache License 2.0 | 6 votes |
@Override protected void after() { try { for (RealmConfiguration configuration : configurations) { Realm.deleteRealm(configuration); } } catch (IllegalStateException e) { // Only throw the exception caused by deleting the opened Realm if the test case itself doesn't throw. if (!unitTestFailed) { throw e; } } finally { // This will delete the temp directory. super.after(); } }
Example 4
Source File: ReadingDataTest.java From OpenLibre with GNU General Public License v3.0 | 5 votes |
private void parseTestData() { // open empty processed data realm for use in parsing data Realm.deleteRealm(realmConfigProcessedData); realmProcessedData = Realm.getInstance(realmConfigProcessedData); // get all raw data RealmResults<RawTagData> rawTags = realmRawData.where(RawTagData.class).findAllSorted(RawTagData.DATE, Sort.ASCENDING); // reduce data set to just the raw data of the most recent sensor String tagId = rawTags.last().getTagId(); rawTags = rawTags.where().equalTo(RawTagData.TAG_ID, tagId).findAllSorted(RawTagData.DATE, Sort.ASCENDING); // reduce data set further to only MAX_READINGS_TO_TEST sensor readings for (int i = 0; i < min(MAX_READINGS_TO_TEST, rawTags.size()); i++) { addDataIfValid(rawTags.get(i)); } /* // add oldest readings of sensor for (int i = 0; i < min(MAX_READINGS_TO_TEST / 2, rawTags.size() / 2); i++) { addDataIfValid(rawTags.get(i)); } // add newest readings of sensor for (int i = max(rawTags.size() / 2, rawTags.size() - 1 - MAX_READINGS_TO_TEST / 2); i < rawTags.size() - 1; i++) { addDataIfValid(rawTags.get(i)); } */ assertThat(realmRawData.isEmpty(), is(false)); assertThat(readingDataList.size(), greaterThan(0)); }
Example 5
Source File: ReadingDataTest.java From OpenLibre with GNU General Public License v3.0 | 5 votes |
@After public void tearDown() { realmRawData.close(); // if any test opened the processed data realm, close it and delete the data if (realmProcessedData != null) { realmProcessedData.close(); Realm.deleteRealm(realmConfigProcessedData); } }
Example 6
Source File: ReadingDataTest.java From OpenLibre with GNU General Public License v3.0 | 5 votes |
@Test public void testReparseAllData() { // delete all parsed readings before the tests Realm.deleteRealm(realmConfigProcessedData); // reparse all readings from raw data parseRawData(); Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData); assertThat(realmProcessedData.isEmpty(), is(false)); realmProcessedData.close(); }
Example 7
Source File: RealmConfig.java From talk-android with MIT License | 5 votes |
public static void deleteRealm() { try { Realm.deleteRealm(realmConfiguration); } catch (Exception e) { } }
Example 8
Source File: RealmBaseActivity.java From Stayfit with Apache License 2.0 | 5 votes |
@Override protected void onResume() { super.onResume(); RealmConfiguration config = new RealmConfiguration.Builder(this) .name("myrealm.realm") .build(); Realm.deleteRealm(config); Realm.setDefaultConfiguration(config); mRealm = Realm.getInstance(config); }
Example 9
Source File: App.java From go-bees with GNU General Public License v3.0 | 5 votes |
@Override protected void initRealm() { // Initialize Realm. Should only be done once when the application starts. Realm.init(this); GoBeesDbConfig realmConfig = new GoBeesDbConfig(); // Delete all Realm.deleteRealm(realmConfig.getRealmConfiguration()); // Set config Realm.setDefaultConfiguration(realmConfig.getRealmConfiguration()); }
Example 10
Source File: MyApplication.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); Realm.init(this); RealmConfiguration realmConfig = new RealmConfiguration.Builder() .initialData(new Realm.Transaction() { @Override public void execute(Realm realm) { realm.createObject(Parent.class); }}) .build(); Realm.deleteRealm(realmConfig); // Delete Realm between app restarts. Realm.setDefaultConfiguration(realmConfig); }
Example 11
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 12
Source File: AccountManager.java From quill with MIT License | 5 votes |
public static void deleteBlog(@NonNull String blogUrl) { RealmResults<BlogMetadata> matchingBlogs = findAllBlogsMatchingUrl(blogUrl); if (matchingBlogs.isEmpty()) { throw new IllegalStateException("No blog found matching the URL: " + blogUrl); } // we don't allow adding more than 1 blog with the same URL, so this should never happen if (matchingBlogs.size() > 1) { throw new IllegalStateException("More than 1 blog found matching the URL: " + blogUrl); } // delete blog metadata before data because data without metadata is harmless, but vice-versa is not // keep a copy of the metadata around so we can delete the data Realm after this final Realm realm = Realm.getDefaultInstance(); BlogMetadata blogToDelete = matchingBlogs.get(0); RealmConfiguration dataRealmToDelete = realm.copyFromRealm(blogToDelete).getDataRealmConfig(); RealmUtils.executeTransaction(realm, r -> { RealmObject.deleteFromRealm(blogToDelete); }); // delete blog data Realm.deleteRealm(dataRealmToDelete); // if the active blog was deleted, set the active blog to a different one if (blogUrl.equals(getActiveBlogUrl())) { List<BlogMetadata> allBlogs = getAllBlogs(); if (!allBlogs.isEmpty()) { setActiveBlog(allBlogs.get(0).getBlogUrl()); } else { setActiveBlog(""); } } }
Example 13
Source File: StartupActions.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
public Realm getInstance() { SharedPreferences sharedPreferences = G.context.getSharedPreferences("AES-256", Context.MODE_PRIVATE); String stringArray = sharedPreferences.getString("myByteArray", null); if (stringArray == null) { byte[] key = new byte[64]; new SecureRandom().nextBytes(key); SharedPreferences.Editor editor = sharedPreferences.edit(); String saveThis = Base64.encodeToString(key, Base64.DEFAULT); editor.putString("myByteArray", saveThis); editor.commit(); } byte[] mKey = Base64.decode(sharedPreferences.getString("myByteArray", null), Base64.DEFAULT); RealmConfiguration newConfig = new RealmConfiguration.Builder() .name(context.getResources().getString(R.string.encriptedDB)) .encryptionKey(mKey) .schemaVersion(REALM_SCHEMA_VERSION) .migration(new RealmMigration()) .build(); File newRealmFile = new File(newConfig.getPath()); if (newRealmFile.exists()) { return Realm.getInstance(newConfig); } else { Realm realm = null; try { configuration = new RealmConfiguration.Builder().name(context.getResources().getString(R.string.planDB)) .schemaVersion(REALM_SCHEMA_VERSION) .compactOnLaunch() .migration(new RealmMigration()).build(); realm = Realm.getInstance(configuration); realm.writeEncryptedCopyTo(newRealmFile, mKey); realm.close(); Realm.deleteRealm(configuration); return Realm.getInstance(newConfig); } catch (OutOfMemoryError oom) { realm.close(); return getPlainInstance(); } catch (Exception e) { realm.close(); return getPlainInstance(); } } }
Example 14
Source File: App.java From RealmSearchView with Apache License 2.0 | 4 votes |
private void initializeDB() { long initTime = System.currentTimeMillis(); // Realm DB configuration object RealmConfiguration config = new RealmConfiguration.Builder(this) .name(getResources().getString(R.string.realm_db_filename)) .schemaVersion(0) .build(); // Clear Realm DB Realm.deleteRealm(config); Realm realm = Realm.getInstance(config); // All writes must be wrapped in a transaction to facilitate safe multi threading realm.beginTransaction(); Map<Class, Integer> JSONres = new HashMap<Class, Integer>(); JSONres.put(City.class, R.raw.cities); Resources res = getResources(); try { for (Map.Entry<Class, Integer> resource : JSONres.entrySet()) { InputStream stream = res.openRawResource(resource.getValue()); realm.createAllFromJson(resource.getKey(), stream); } } catch (IOException e) { e.printStackTrace(); } // When the transaction is committed, all changes a synced to disk. realm.commitTransaction(); long duration = (System.currentTimeMillis() - initTime); long sleepTime = TimeUnit.SECONDS.toMillis(getResources().getInteger(R.integer.splash_max_delay_sec)) - duration; Log.d(TAG, "DB insert time: " + duration + "ms"); if(sleepTime > 0) { SystemClock.sleep(sleepTime); } Log.d(TAG, "Cities in DB: " + realm.where(City.class).findAll().size()); realm.close(); }
Example 15
Source File: RealmDatabase.java From rx-realm with MIT License | 4 votes |
public static void deleteDatabase() { Realm.deleteRealm(configuration); }
Example 16
Source File: DatabaseRealmConfig.java From openwebnet-android with MIT License | 4 votes |
private void migrateToEncryptedConfig(RealmConfiguration unencryptedConfig) throws IOException { Realm realm = Realm.getInstance(unencryptedConfig); realm.writeEncryptedCopyTo(new File(mContext.getFilesDir(), DATABASE_NAME_CRYPT), getRealmKey()); realm.close(); Realm.deleteRealm(unencryptedConfig); }