io.realm.RealmConfiguration Java Examples
The following examples show how to use
io.realm.RealmConfiguration.
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: SaudeApp.java From Saude-no-Mapa with MIT License | 6 votes |
@Override public void onCreate() { super.onCreate(); Fabric.with(this, new Crashlytics()); Timber.plant(new Timber.DebugTree()); RealmConfiguration configuration = new RealmConfiguration.Builder(this) .deleteRealmIfMigrationNeeded() .build(); Realm.setDefaultConfiguration(configuration); FacebookSdk.sdkInitialize(getApplicationContext()); Timber.i("Signature " + FacebookSdk.getApplicationSignature(getApplicationContext())); }
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: SecureUserStoreTests.java From realm-android-user-store with Apache License 2.0 | 6 votes |
@Before public void setUp() throws KeyStoreException { Realm.init(InstrumentationRegistry.getTargetContext()); // This will set the 'm_metadata_manager' in 'sync_manager.cpp' to be 'null' // causing the SyncUser to remain in memory. // They're actually not persisted into disk. // move this call to `tearDown` to clean in-memory & on-disk users // once https://github.com/realm/realm-object-store/issues/207 is resolved TestHelper.resetSyncMetadata(); RealmConfiguration realmConfig = configFactory.createConfiguration(); realm = Realm.getInstance(realmConfig); userStore = new SecureUserStore(InstrumentationRegistry.getTargetContext()); assertTrue("KeyStore Should be Unlocked before running tests on device!", userStore.isKeystoreUnlocked()); SyncManager.setUserStore(userStore); }
Example #4
Source File: DatabaseRealmConfig.java From openwebnet-android with MIT License | 6 votes |
/** * @return RealmConfiguration */ public RealmConfiguration getConfig() { initRealmKey(); Realm.init(mContext); if (DEBUG_DATABASE) { writeKeyToFile(); } boolean existsUnencryptedRealm = new File(mContext.getFilesDir(), DATABASE_NAME).exists(); if (existsUnencryptedRealm) { RealmConfiguration unencryptedConfig = getUnencryptedConfig(); try { migrateToEncryptedConfig(unencryptedConfig); log.debug("migration to encrypted realm successful"); } catch (IOException e) { log.error("error migrating encrypted realm", e); return unencryptedConfig; } } return getEncryptedConfig(); }
Example #5
Source File: AppDelegate.java From AndroidSchool with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); sContext = this; Hawk.init(this) .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM) .setStorage(HawkBuilder.newSharedPrefStorage(this)) .setLogLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE) .build(); RealmConfiguration configuration = new RealmConfiguration.Builder(this) .rxFactory(new RealmObservableFactory()) .build(); Realm.setDefaultConfiguration(configuration); ApiFactory.recreate(); RepositoryProvider.init(); }
Example #6
Source File: MainApplication.java From AndroidDatabaseLibraryComparison with MIT License | 6 votes |
@Override public void onCreate() { super.onCreate(); ActiveAndroid.initialize(new Configuration.Builder(this) .setDatabaseName("activeandroid") .setDatabaseVersion(1) .setModelClasses(SimpleAddressItem.class, AddressItem.class, AddressBook.class, Contact.class).create()); Ollie.with(this) .setName("ollie") .setVersion(1) .setLogLevel(Ollie.LogLevel.FULL) .init(); FlowManager.init(this); Sprinkles.init(this, "sprinkles.db", 2); RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build(); Realm.setDefaultConfiguration(realmConfig); mDatabase = getDatabase(); }
Example #7
Source File: WidgetListFactory.java From WanAndroid with Apache License 2.0 | 6 votes |
@Override public RemoteViews getViewAt(int i) { RemoteViews remoteViews = new RemoteViews( context.getPackageName(), R.layout.item_list_app_widget); Realm realm=Realm.getInstance(new RealmConfiguration.Builder() .deleteRealmIfMigrationNeeded() .name(RealmHelper.DATABASE_NAME) .build()); List<ReadLaterArticleData> list = realm.copyFromRealm( realm.where(ReadLaterArticleData.class) .equalTo("userId", userId) .sort("timestamp", Sort.DESCENDING) .findAll()); ReadLaterArticleData data = list.get(i); remoteViews.setTextViewText(R.id.text_view_author,data.getAuthor()); remoteViews.setTextViewText(R.id.text_view_title, StringUtil.replaceInvalidChar(data.getTitle())); Intent intent = new Intent(); intent.putExtra(DetailActivity.ID, data.getId()); intent.putExtra(DetailActivity.TITLE, data.getTitle()); intent.putExtra(DetailActivity.URL, data.getLink()); intent.putExtra(DetailActivity.FROM_FAVORITE_FRAGMENT, false); intent.putExtra(DetailActivity.FROM_BANNER, false); remoteViews.setOnClickFillInIntent(R.id.item_main, intent); return remoteViews; }
Example #8
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 #9
Source File: SaklarAdapter.java From AndroidSmartHome with Apache License 2.0 | 6 votes |
@Override public SaklarHolder onCreateViewHolder(ViewGroup parent, int viewType) { context = parent.getContext(); View itemView = LayoutInflater.from(context) .inflate(R.layout.item_recycler_saklar, parent, false); // Init Realm RealmConfiguration config = new RealmConfiguration.Builder(context) .name("agnosthings.realm") .schemaVersion(1) .build(); realm = Realm.getInstance(config); return new SaklarHolder(itemView); }
Example #10
Source File: DbManager.java From Socket.io-FLSocketIM-Android with MIT License | 6 votes |
public static void createDb(String userName) { if (dbName != null && dbName.equals(userName)) { return; } dbName = userName; config = new RealmConfiguration.Builder() .name( dbName + ".realm") //文件名 .deleteRealmIfMigrationNeeded() .schemaVersion(0) //版本号 .build(); if (mRealm != null) { mRealm.close(); } mainHandler.post(new Runnable() { @Override public void run() { mRealm = Realm.getInstance(config); } }); }
Example #11
Source File: RxRealmUtils.java From AcgClub with MIT License | 6 votes |
public static Completable completableExec(final RealmConfiguration configuration, final Consumer<Realm> transaction) { return Completable.fromAction(new Action() { @Override public void run() throws Exception { try (Realm realm = Realm.getInstance(configuration)) { realm.executeTransaction(new Transaction() { @Override public void execute(Realm r) { try { transaction.accept(r); } catch (Exception e) { e.printStackTrace(); } } }); } } }); }
Example #12
Source File: MoeQuestApp.java From MoeQuest with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); mAppContext = this; // 配置Realm数据库 RealmConfiguration configuration = new RealmConfiguration .Builder(this) .deleteRealmIfMigrationNeeded() .schemaVersion(6) .migration(new RealmMigration() { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { } }).build(); Realm.setDefaultConfiguration(configuration); //配置腾讯bugly CrashReport.initCrashReport(getApplicationContext(), ConstantUtil.BUGLY_ID, false); }
Example #13
Source File: MainApp.java From HAPP with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); sInstance = this; //initialize Realm RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(instance()) .name("happ.realm") .schemaVersion(0) .deleteRealmIfMigrationNeeded() // TODO: 03/08/2016 remove .build(); Realm.setDefaultConfiguration(realmConfiguration); Migration.runMigrationCheck(); }
Example #14
Source File: ApplicationModule.java From example with Apache License 2.0 | 5 votes |
@Provides static Realm provideRealm(@ApplicationContext Context context) { RealmConfiguration configuration = new RealmConfiguration.Builder(context).name("pratamablog.realm") .schemaVersion(DATABASE_VERSION) .migration(new Migration()) .build(); return Realm.getInstance(configuration); }
Example #15
Source File: RealmManager.java From sleep-cycle-alarm with GNU General Public License v3.0 | 5 votes |
public static void initializeRealmConfig() { if(realmConfiguration == null) { Log.d(RealmManager.class.getName(), "Initializing Realm configuration."); setRealmConfiguration(new RealmConfiguration.Builder() .initialData(new RealmInitialData()) .deleteRealmIfMigrationNeeded() .build()); } }
Example #16
Source File: DataModule.java From realm-monarchy with Apache License 2.0 | 5 votes |
@Provides @Singleton RealmConfiguration realmConfiguration() { return new RealmConfiguration.Builder() // .deleteRealmIfMigrationNeeded() // .initialData(realm -> { // RealmDog dog = realm.createObject(RealmDog.class); dog.setName("Corgi"); }).build(); }
Example #17
Source File: PerfTestRealm.java From android-database-performance with Apache License 2.0 | 5 votes |
protected void createRealm() { Realm.init(getTargetContext()); RealmConfiguration.Builder configBuilder = new RealmConfiguration.Builder(); if (inMemory) { configBuilder.name("inmemory.realm").inMemory(); } else { configBuilder.name("ondisk.realm"); } realm = Realm.getInstance(configBuilder.build()); }
Example #18
Source File: MyApplication.java From ApiClient with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this) .deleteRealmIfMigrationNeeded() .build(); Realm.setDefaultConfiguration(realmConfiguration); Github.init(); }
Example #19
Source File: RealmDatabaseTest.java From rx-realm with MIT License | 5 votes |
@Before public void setUp() throws Exception { RealmConfiguration configuration = new RealmConfiguration .Builder(InstrumentationRegistry.getContext()) .setModules(new TestModule()) .schemaVersion(0) .build(); RealmDatabase.init(configuration); RealmDatabase.deleteDatabase(); }
Example #20
Source File: MyApplication.java From healthgo with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); serviceRun=false; Realm.init(this); RealmConfiguration realmConfig = new RealmConfiguration.Builder() .name("step_db") .build(); Log.d("app","app create()"); Realm.setDefaultConfiguration(realmConfig); // Make this Realm the default }
Example #21
Source File: MeiziApp.java From Meizi with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); Realm.setDefaultConfiguration(new RealmConfiguration.Builder(this) .schemaVersion(1) .deleteRealmIfMigrationNeeded() .build()); MeiziContext.getInstance().init(this); }
Example #22
Source File: MyApplication.java From journaldev with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); Realm.init(getApplicationContext()); RealmConfiguration config = new RealmConfiguration.Builder() .deleteRealmIfMigrationNeeded() .build(); Realm.setDefaultConfiguration(config); }
Example #23
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 #24
Source File: LeisureReadApp.java From LeisureRead with Apache License 2.0 | 5 votes |
/** * 初始化Realm数据库配置 */ private void initRealm() { Realm.setDefaultConfiguration(new RealmConfiguration.Builder(this) .deleteRealmIfMigrationNeeded() .schemaVersion(1) .build()); }
Example #25
Source File: GankApp.java From gank.io-unofficial-android-client with Apache License 2.0 | 5 votes |
/** * 配置Realm数据库 */ private void initRealm() { RealmConfiguration configuration = new RealmConfiguration .Builder(this) .deleteRealmIfMigrationNeeded() .schemaVersion(7).migration((realm, oldVersion, newVersion) -> { }).build(); Realm.setDefaultConfiguration(configuration); }
Example #26
Source File: TestDataModule.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
/** * Init realm configuration and instance * @return * @throws Exception */ @Provides @Singleton RealmConfiguration provideRealmConfiguration(){ mockStatic(RealmCore.class); mockStatic(RealmLog.class); mockStatic(Realm.class); mockStatic(RealmConfiguration.class); Realm.init(RuntimeEnvironment.application); // TODO: Better solution would be just mock the RealmConfiguration.Builder class. But it seems there is some // problems for powermock to mock it (static inner class). We just mock the RealmCore.loadLibrary(Context) which // will be called by RealmConfiguration.Builder's constructor. doNothing().when(RealmCore.class); RealmCore.loadLibrary(any(Context.class)); final RealmConfiguration mockRealmConfig = PowerMockito.mock(RealmConfiguration.class); try { whenNew(RealmConfiguration.class).withAnyArguments().thenReturn(mockRealmConfig); } catch (Exception e) { e.printStackTrace(); } when(Realm.getDefaultConfiguration()).thenReturn(mockRealmConfig); // init mock realm Realm mockRealm = PowerMockito.mock(Realm.class);; // Anytime getInstance is called with any configuration, then return the mockRealm when(Realm.getDefaultInstance()).thenReturn(mockRealm); when(Realm.getInstance(mockRealmConfig)).thenReturn(mockRealm); return mockRealmConfig; }
Example #27
Source File: GoBeesDbConfig.java From go-bees with GNU General Public License v3.0 | 5 votes |
public RealmConfiguration getRealmConfiguration() { if (realmConfiguration != null) { return realmConfiguration; } // Create config realmConfiguration = new RealmConfiguration.Builder() .name(DATABASE_NAME) .schemaVersion(DATABASE_VERSION) .migration(new GoBeesDbMigration()) .build(); return realmConfiguration; }
Example #28
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 #29
Source File: DatabaseManager.java From redgram-for-reddit with GNU General Public License v3.0 | 5 votes |
@Inject public DatabaseManager(App app) { this.app = app; this.context = app.getApplicationContext(); this.configuration = new RealmConfiguration.Builder(context) // .name(DB_NAME) .deleteRealmIfMigrationNeeded() .setModules(this) .build(); Realm.setDefaultConfiguration(configuration); initCurrentAccessToken(); }
Example #30
Source File: MoviesApp.java From AndroidSchool with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); sInstance = this; Picasso picasso = new Picasso.Builder(this) .downloader(new OkHttp3Downloader(this)) .build(); Picasso.setSingletonInstance(picasso); RealmConfiguration configuration = new RealmConfiguration.Builder(this) .rxFactory(new RealmObservableFactory()) .build(); Realm.setDefaultConfiguration(configuration); }