本文整理汇总了Java中io.realm.RealmSchema.get方法的典型用法代码示例。如果您正苦于以下问题:Java RealmSchema.get方法的具体用法?Java RealmSchema.get怎么用?Java RealmSchema.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.RealmSchema
的用法示例。
在下文中一共展示了RealmSchema.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: migrate
import io.realm.RealmSchema; //导入方法依赖的package包/类
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
// During a migration, a DynamicRealm is exposed. A DynamicRealm is an untyped variant of a normal Realm, but
// with the same object creation and query capabilities.
// A DynamicRealm uses Strings instead of Class references because the Classes might not even exist or have been
// renamed.
// Access the Realm schema in order to create, modify or delete classes and their fields.
RealmSchema schema = realm.getSchema();
// Migrate from version 0 to version 1
if (oldVersion == 0) {
oldVersion++;
}
// Migrate from version 1 to version 2
if (oldVersion == 1) {
RealmObjectSchema bloodGlucoseDataSchema = schema.get("BloodGlucoseData");
bloodGlucoseDataSchema
.addField("timezoneOffsetInMinutes", int.class)
.transform(timezoneTransformFunction);
//oldVersion++;
}
}
示例2: migrate
import io.realm.RealmSchema; //导入方法依赖的package包/类
@Override
public void migrate(final DynamicRealm realm, long oldVersion, long newVersion) {
// During a migration, a DynamicRealm is exposed. A DynamicRealm is an untyped variant of a normal Realm, but
// with the same object creation and query capabilities.
// A DynamicRealm uses Strings instead of Class references because the Classes might not even exist or have been
// renamed.
// Access the Realm schema in order to create, modify or delete classes and their fields.
RealmSchema schema = realm.getSchema();
if(oldVersion==1){
RealmObjectSchema settingSchema = schema.get("Setting");
settingSchema.addField("locale",String.class)
.transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
obj.set("locale","Auto");
}
});
oldVersion++;
}
if(oldVersion==2){
RealmObjectSchema cacheSchema = schema.get("NetWorkCache");
cacheSchema.removeField("record").addField("record",String.class);
oldVersion++;
}
}
示例3: migrate
import io.realm.RealmSchema; //导入方法依赖的package包/类
@Override
public void migrate(@NonNull final DynamicRealm realm, long oldVersion, long newVersion) {
Log.d(TAG, "Starting migration from " + oldVersion + " to " + newVersion);
// Migration from versions < 9 not supported, versions prior 9 were missing the
// contentHash for items
if(oldVersion < 9) {
throw new IllegalStateException("Migration from Schema < 9 not supported");
}
RealmSchema schema = realm.getSchema();
/*
9 -> 10
- Add primary key ID to TemporaryFeed
- Rename TemporaryFeed id to treeItemId
- add TemporaryFeed object for list and pager activities
*/
if(oldVersion == 9) {
realm.delete("TemporaryFeed");
final RealmObjectSchema temporaryFeedSchema = schema.get("TemporaryFeed");
if(temporaryFeedSchema == null)
throw new IllegalStateException("TemporaryFeed schema not found");
temporaryFeedSchema
.renameField(TemporaryFeed.ID, TemporaryFeed.TREE_ITEM_ID)
.addField(TemporaryFeed.ID, long.class, FieldAttribute.PRIMARY_KEY);
realm.createObject("TemporaryFeed", TemporaryFeed.LIST_ID);
realm.createObject("TemporaryFeed", TemporaryFeed.PAGER_ID);
oldVersion++;
}
/*
10 -> 11
- Make sure every item has updatedAt != null, set updatedAt = pubDate if not
*/
if(oldVersion == 10) {
for(DynamicRealmObject object: realm.where("Item").isNull(Item.UPDATED_AT).findAll()) {
object.setDate(Item.UPDATED_AT, object.getDate(Item.PUB_DATE));
}
oldVersion++;
}
/*
11 -> 12
- Add active property to Item
*/
if(oldVersion == 11) {
final RealmObjectSchema itemSchema = schema.get("Item");
if(itemSchema == null)
throw new IllegalStateException("Item schema not found");
itemSchema
.addField(Item.ACTIVE, boolean.class, FieldAttribute.INDEXED);
//noinspection UnusedAssignment
oldVersion++;
}
}