Java Code Examples for io.realm.Realm#init()

The following examples show how to use io.realm.Realm#init() . 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 vote down vote up
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: DatabaseRealmConfig.java    From openwebnet-android with MIT License 6 votes vote down vote up
/**
 * @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 3
Source File: BaseInstrumentedTest.java    From mangosta-android with Apache License 2.0 6 votes vote down vote up
private void setUpRealmTestContext() {
    Realm.init(getContext());
    mRealmMock = Realm.getDefaultInstance();

    mRealmManagerMock = mock(RealmManager.class);

    when(mRealmManagerMock.getRealm()).thenReturn(mRealmMock);
    doReturn(new Chat()).when(mRealmManagerMock).getChatFromRealm(any(Realm.class), any(String.class));
    doReturn(UUID.randomUUID().toString()).when(mRealmManagerMock)
            .saveMessageLocally(any(Chat.class), any(String.class), any(String.class), any(int.class));
    doReturn(mRealmMock.where(ChatMessage.class).findAll())
            .when(mRealmManagerMock)
            .getMessagesForChat(any(Realm.class), any(String.class));
    doNothing().when(mRealmManagerMock).deleteAll();
    doNothing().when(mRealmManagerMock).deleteMessage(any(String.class));

    RealmManager.setSpecialInstanceForTesting(mRealmManagerMock);
}
 
Example 4
Source File: MyApplication.java    From journaldev with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Realm.init(getApplicationContext());


    RealmConfiguration config =
            new RealmConfiguration.Builder()
                    .deleteRealmIfMigrationNeeded()
                    .build();

    Realm.setDefaultConfiguration(config);
}
 
Example 5
Source File: MyApplication.java    From realm-android-adapters with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: BaseApp.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
protected void initRealm() {
    // Initialize Realm. Should only be done once when the application starts.
    Realm.init(this);
    // Get Realm config
    GoBeesDbConfig realmConfig = new GoBeesDbConfig();
    Realm.setDefaultConfiguration(realmConfig.getRealmConfiguration());
}
 
Example 7
Source File: MyApplication.java    From EMQ-Android-Toolkit with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    sContext = getApplicationContext();

    Realm.init(this);

}
 
Example 8
Source File: ReadingDataTest.java    From OpenLibre with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    Realm.init(context);
    setupRealm(context);

    realmRawData = Realm.getInstance(realmConfigRawData);
}
 
Example 9
Source File: App.java    From juda with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    FirebaseAnalytics.getInstance(this);

    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/font.ttf")
            .setFontAttrId(R.attr.fontPath)
            .build()
    );

    Realm.init(this);

}
 
Example 10
Source File: LoopApplication.java    From Loop with Apache License 2.0 5 votes vote down vote up
private void initializeRealm(){
    Realm.init(this);
    RealmConfiguration config =
            new RealmConfiguration.Builder()
                    .deleteRealmIfMigrationNeeded()
                    .build();
    Realm.setDefaultConfiguration(config);
}
 
Example 11
Source File: MyApplication.java    From carstream-android-auto with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Realm.init(this);
    RealmConfiguration config = new RealmConfiguration.Builder().name("db.realm").build();
    Realm.setDefaultConfiguration(config);
}
 
Example 12
Source File: Playa.java    From playa with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    applicationComponent = DaggerApplicationComponent.builder()
            .applicationModule(new ApplicationModule(this))
            .build();
    Realm.init(this);
}
 
Example 13
Source File: RealmExecutor.java    From android-orm-benchmark-updated with Apache License 2.0 4 votes vote down vote up
@Override
public void init(Context context, boolean useInMemoryDb)
{
    mContext = context;
    Realm.init(mContext);
}
 
Example 14
Source File: ChatApplication.java    From my-first-realm-app with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Realm.init(this);
}
 
Example 15
Source File: ExchangeRatesApplication.java    From exchange-rates-mvvm with Apache License 2.0 4 votes vote down vote up
protected void initRealm() {
    Realm.init(this);
}
 
Example 16
Source File: RealmInitWrapperImpl.java    From Forage with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void init() {
    Realm.init(application);
}
 
Example 17
Source File: OpenLibre.java    From OpenLibre with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // if it is the onCreate for ARCA, skip own init tasks
    if (ACRA.isACRASenderServiceProcess()) {
        return;
    }

    refreshApplicationSettings(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));

    Realm.init(this);

    setupRealm(getApplicationContext());

    parseRawData();

    StethoUtils.install(this, openLibreDataPath);
}
 
Example 18
Source File: RealmManager.java    From mangosta-android with Apache License 2.0 4 votes vote down vote up
public Realm getRealm() {
    Realm.init(MangostaApplication.getInstance());
    return Realm.getDefaultInstance();
}
 
Example 19
Source File: StartupActions.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * initialize realm and manage migration
 */
private void realmConfiguration() {
    /**
     * before call RealmConfiguration client need to Realm.init(context);
     */
    Realm.init(context);


    //  new SecureRandom().nextBytes(key);


    // An encrypted Realm file can be opened in Realm Studio by using a Hex encoded version
    // of the key. Copy the key from Logcat, then download the Realm file from the device using
    // the method described here: https://stackoverflow.com/a/28486297/1389357
    // The path is normally `/data/data/io.realm.examples.encryption/files/default.realm`

 /*   RealmConfiguration configuration = new RealmConfiguration.Builder().name("iGapLocalDatabase.realm")
            .schemaVersion(REALM_SCHEMA_VERSION).migration(new RealmMigration()).build();
    DynamicRealm dynamicRealm = DynamicRealm.getInstance(configuration);*/

    Realm configuredRealm = getInstance();
    DynamicRealm dynamicRealm = DynamicRealm.getInstance(configuredRealm.getConfiguration());



    /*if (configuration!=null)
        Realm.deleteRealm(configuration);*/

    /**
     * Returns version of Realm file on disk
     */
    if (dynamicRealm.getVersion() == -1) {
        Realm.setDefaultConfiguration(new RealmConfiguration.Builder().name("iGapLocalDatabaseEncrypted.realm").schemaVersion(REALM_SCHEMA_VERSION).deleteRealmIfMigrationNeeded().build());
        //   Realm.setDefaultConfiguration(configuredRealm.getConfiguration());
    } else {
        Realm.setDefaultConfiguration(configuredRealm.getConfiguration());

    }
    dynamicRealm.close();
    configuredRealm.close();
    try {
        Realm.compactRealm(configuredRealm.getConfiguration());

    } catch (UnsupportedOperationException e) {
        e.printStackTrace();
    }
}
 
Example 20
Source File: UpChainWalletApp.java    From Upchain-wallet with GNU Affero General Public License v3.0 3 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    sInstance = this;
    init();

    Realm.init(this);

    refWatcher = LeakCanary.install(this);

    AppFilePath.init(this);

}