当前位置: 首页>>代码示例>>Java>>正文


Java RealmMigrationNeededException类代码示例

本文整理汇总了Java中io.realm.exceptions.RealmMigrationNeededException的典型用法代码示例。如果您正苦于以下问题:Java RealmMigrationNeededException类的具体用法?Java RealmMigrationNeededException怎么用?Java RealmMigrationNeededException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RealmMigrationNeededException类属于io.realm.exceptions包,在下文中一共展示了RealmMigrationNeededException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: waitForInitialRemoteData_readOnlyTrue_throwsIfWrongServerSchema

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void waitForInitialRemoteData_readOnlyTrue_throwsIfWrongServerSchema() {
    SyncCredentials credentials = SyncCredentials.usernamePassword(UUID.randomUUID().toString(), "password", true);
    SyncUser user = SyncUser.login(credentials, Constants.AUTH_URL);
    final SyncConfiguration configNew = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM)
            .waitForInitialRemoteData()
            .readOnly()
            .schema(StringOnly.class)
            .build();
    assertFalse(configNew.realmExists());

    Realm realm = null;
    try {
        // This will fail, because the server Realm is completely empty and the Client is not allowed to write the
        // schema.
        realm = Realm.getInstance(configNew);
        fail();
    } catch (RealmMigrationNeededException ignored) {
    } finally {
        if (realm != null) {
            realm.close();
        }
        user.logout();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:SyncedRealmTests.java

示例2: Realm

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
/**
 * The constructor is private to enforce the use of the static one.
 *
 * @param cache the {@link RealmCache} associated to this Realm instance.
 * @throws IllegalArgumentException if trying to open an encrypted Realm with the wrong key.
 */
private Realm(RealmCache cache) {
    super(cache, createExpectedSchemaInfo(cache.getConfiguration().getSchemaMediator()));
    schema = new ImmutableRealmSchema(this,
            new ColumnIndices(configuration.getSchemaMediator(), sharedRealm.getSchemaInfo()));
    // FIXME: This is to work around the different behaviour between the read only Realms in the Object Store and
    // in current java implementation. Opening a read only Realm with some missing schemas is allowed by Object
    // Store and realm-cocoa. In that case, any query based on the missing schema should just return an empty
    // results. Fix this together with https://github.com/realm/realm-java/issues/2953
    if (configuration.isReadOnly()) {
        RealmProxyMediator mediator = configuration.getSchemaMediator();
        Set<Class<? extends RealmModel>> classes = mediator.getModelClasses();
        for (Class<? extends RealmModel> clazz  : classes) {
            String tableName = Table.getTableNameForClass(mediator.getSimpleClassName(clazz));
            if (!sharedRealm.hasTable(tableName)) {
                sharedRealm.close();
                throw new RealmMigrationNeededException(configuration.getPath(),
                        String.format(Locale.US, "Cannot open the read only Realm. '%s' is missing.",
                                Table.getClassNameForTable(tableName)));
            }
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:Realm.java

示例3: getInstance_realmClosedAfterMigrationException

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void getInstance_realmClosedAfterMigrationException() throws IOException {
    String REALM_NAME = "default0.realm";
    RealmConfiguration realmConfig = configFactory.createConfiguration(REALM_NAME);
    configFactory.copyRealmFromAssets(context, REALM_NAME, REALM_NAME);
    try {
        Realm.getInstance(realmConfig);
        fail("A migration should be triggered");
    } catch (RealmMigrationNeededException expected) {
        Realm.deleteRealm(realmConfig); // Deletes old realm.
    }

    // This should recreate the Realm with proper schema.
    Realm realm = Realm.getInstance(realmConfig);
    int result = realm.where(AllTypes.class).equalTo("columnString", "Foo").findAll().size();
    assertEquals(0, result);
    realm.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:RealmMigrationTests.java

示例4: migrationException_realmListChanged

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void migrationException_realmListChanged() throws IOException {
    RealmConfiguration config = configFactory.createConfiguration();
    // Initialize the schema with RealmList<Cat>
    Realm.getInstance(configFactory.createConfiguration()).close();

    DynamicRealm dynamicRealm = DynamicRealm.getInstance(config);
    dynamicRealm.beginTransaction();
    // Change the RealmList type to RealmList<Dog>
    RealmObjectSchema dogSchema = dynamicRealm.getSchema().get(Dog.CLASS_NAME);
    RealmObjectSchema ownerSchema = dynamicRealm.getSchema().get(CatOwner.CLASS_NAME);
    ownerSchema.removeField(CatOwner.FIELD_CATS);
    ownerSchema.addRealmListField(CatOwner.FIELD_CATS, dogSchema);
    dynamicRealm.commitTransaction();
    dynamicRealm.close();

    try {
        realm = Realm.getInstance(config);
        fail();
    } catch (RealmMigrationNeededException ignored) {
        assertThat(ignored.getMessage(),
                CoreMatchers.containsString("Property 'CatOwner.cats' has been changed from 'array<Dog>' to 'array<Cat>'"));
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RealmMigrationTests.java

示例5: migrating_nullableField_toward_notNullable_PrimaryKeyThrows

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void migrating_nullableField_toward_notNullable_PrimaryKeyThrows() throws IOException {
    configFactory.copyRealmFromAssets(context, "default-nullable-primarykey.realm", Realm.DEFAULT_REALM_NAME);
    final Class[] classes = {PrimaryKeyAsByte.class, PrimaryKeyAsShort.class, PrimaryKeyAsInteger.class, PrimaryKeyAsLong.class};
    for (final Class clazz : classes) {
        try {
            RealmConfiguration realmConfig = configFactory.createConfigurationBuilder()
                    .schema(clazz)
                    .build();
            Realm realm = Realm.getInstance(realmConfig);
            realm.close();
            fail();
        } catch (RealmMigrationNeededException expected) {
            assertThat(expected.getMessage(), CoreMatchers.containsString(
                    String.format("Property '%s.%s' has been made required", clazz.getSimpleName(), "id")));
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:RealmMigrationTests.java

示例6: migrationRequired_throwsOriginalException

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void migrationRequired_throwsOriginalException() {
    RealmConfiguration config = configFactory.createConfigurationBuilder()
            // .migration() No migration block provided, but one is required
            .assetFile("default0.realm") // This Realm does not have the correct schema
            .build();

    Realm realm = null;
    try {
        realm = Realm.getInstance(config);
        fail();
    } catch (RealmMigrationNeededException ignored) {
    } finally {
        if (realm != null) {
            realm.close();
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:RealmMigrationTests.java

示例7: getInstance_wrongSchemaInReadonlyThrows

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void getInstance_wrongSchemaInReadonlyThrows() {
    RealmConfiguration config = configFactory.createConfigurationBuilder()
            .name("readonly.realm")
            .schema(StringOnlyReadOnly.class, AllJavaTypes.class)
            .assetFile("readonly.realm")
            .readOnly()
            .build();

    // This will throw because the Realm doesn't have the correct schema, and a new file cannot be re-created
    // because it is read only.
    try {
        realm = Realm.getInstance(config);
        fail();
    } catch (RealmMigrationNeededException ignored) {
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:RealmTests.java

示例8: constructBuilder_versionEqualWhenSchemaChangesThrows

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void constructBuilder_versionEqualWhenSchemaChangesThrows() {
    // Creates initial Realm.
    RealmConfiguration config = new RealmConfiguration.Builder(context)
            .directory(configFactory.getRoot())
            .schemaVersion(42)
            .schema(StringOnly.class)
            .build();
    Realm.getInstance(config).close();

    // Creates new instance with a configuration containing another schema.
    try {
        config = new RealmConfiguration.Builder(context)
                .directory(configFactory.getRoot())
                .schemaVersion(42)
                .schema(StringAndInt.class)
                .build();
        realm = Realm.getInstance(config);
        fail("A migration should be required");
    } catch (RealmMigrationNeededException ignored) {
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RealmConfigurationTests.java

示例9: setupMetadataRealm

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
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));
}
 
开发者ID:vickychijwani,项目名称:quill,代码行数:25,代码来源:SpectreApplication.java

示例10: setupRealm

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
public static void setupRealm(Context context) {
    // Setup
    RealmConfiguration realmConfig = getRealmConfiguration(context);

    Realm.setDefaultConfiguration(realmConfig);

    try {
        Realm realm = Realm.getDefaultInstance();
        realm.close();
    }
    catch (RealmMigrationNeededException exception) {
        Log.d(TAG, "New version! Destroy everything");
        Realm.deleteRealm(realmConfig);
    }

}
 
开发者ID:emilioeduardob,项目名称:listahu-android,代码行数:17,代码来源:RealmManager.java

示例11: migrationException_getPath

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@Test
public void migrationException_getPath() throws IOException {
    configFactory.copyRealmFromAssets(context, "default0.realm", Realm.DEFAULT_REALM_NAME);
    File realm = new File(configFactory.getRoot(), Realm.DEFAULT_REALM_NAME);
    try {
        Realm.getInstance(configFactory.createConfiguration());
        fail();
    } catch (RealmMigrationNeededException expected) {
        assertEquals(expected.getPath(), realm.getCanonicalPath());
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:RealmMigrationTests.java

示例12: migration_backlinkedFieldInUse

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
/**
 * Table validation should fail if the backlinked column already exists in the target table.
 * The realm `backlinks-fieldInUse.realm` contains the classes `BacklinksSource` and `BacklinksTarget`
 * except that in the definition of {@code BacklinksTarget}, the field parent is defined as:
 * <pre>
 * {@code
 *     private RealmList<BacklinksSource> parents;
 * }
 * </pre>
 *
 * <p/>
 * The backlinked field does exist but it is list of links to {@code BacklinksSource} children
 * not a list of backlinks to  {@code BacklinksSource} parents of which the {@code BacklinksTarget}
 * is a child.
 */
@Test
public void migration_backlinkedFieldInUse() {
    final String realmName = "backlinks-fieldInUse.realm";

    RealmConfiguration realmConfig = configFactory.createConfigurationBuilder()
            .name(realmName)
            .schema(BacklinksSource.class, BacklinksTarget.class)
            .build();

    try {
        configFactory.copyRealmFromAssets(context, realmName, realmName);

        Realm localRealm = Realm.getInstance(realmConfig);
        localRealm.close();
        fail("A migration should have been required");
    } catch (IOException e) {
        fail("Failed copying realm");
    } catch (RealmMigrationNeededException expected) {
        assertThat(expected.getMessage(),
                CoreMatchers.allOf(
                        CoreMatchers.containsString("Property 'BacklinksSource.name' has been added"),
                        CoreMatchers.containsString("Property 'BacklinksTarget.parents' has been removed")));
    } finally {
        Realm.deleteRealm(realmConfig);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:42,代码来源:LinkingObjectsManagedTests.java

示例13: migrate

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
@SuppressLint("DefaultLocale")
@Override
public void migrate(@NonNull DynamicRealm realm, long oldVersion, long newVersion) {
    if (oldVersion < newVersion) {
        // Unknown migration
        throw new RealmMigrationNeededException(realm.getPath(), String.format("Migration missing from v%d to v%d", oldVersion, newVersion));
    }
}
 
开发者ID:djuelg,项目名称:Neuronizer,代码行数:9,代码来源:RealmMigrator.java

示例14: RealmHelper

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
public RealmHelper(Application application) {
    RealmConfiguration configuration = new RealmConfiguration.Builder(application).deleteRealmIfMigrationNeeded().build();
    try {
        Realm.setDefaultConfiguration(configuration);
        realmDB = Realm.getDefaultInstance();
    } catch (RealmMigrationNeededException e) {
        Realm.deleteRealm(configuration);
        realmDB = Realm.getDefaultInstance();
    }
}
 
开发者ID:kam6512,项目名称:RxBleGattManager,代码行数:11,代码来源:RealmHelper.java

示例15: GreenHubDb

import io.realm.exceptions.RealmMigrationNeededException; //导入依赖的package包/类
public GreenHubDb() {
    try {
        mRealm = Realm.getDefaultInstance();
    } catch (RealmMigrationNeededException e) {
        // handle migration exception io.realm.exceptions.RealmMigrationNeededException
        e.printStackTrace();
    }
}
 
开发者ID:greenhub-project,项目名称:batteryhub,代码行数:9,代码来源:GreenHubDb.java


注:本文中的io.realm.exceptions.RealmMigrationNeededException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。