• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FieldAttribute类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: removingPrimaryKeyRemovesConstraint_typeSetters

import io.realm.FieldAttribute; //导入依赖的package包/类
/**
 * This test surfaces a bunch of problems, most of them seem to be around caching of the schema
 * during a transaction
 *
 * 1) Removing the primary key do not invalidate the cache in RealmSchema and those cached
 *    are ImmutableRealmObjectSchema so do not change when the primary key is removed.
 *
 * 2) Addding `schema.refresh()` to RealmObjectSchema.removePrimaryKey()` causes
 *    RealmPrimaryKeyConstraintException anyway. Unclear why.
 */
@Test
public void removingPrimaryKeyRemovesConstraint_typeSetters() {
    RealmConfiguration config = configFactory.createConfigurationBuilder()
            .name("removeConstraints").build();

    DynamicRealm realm = DynamicRealm.getInstance(config);
    RealmSchema realmSchema = realm.getSchema();
    realm.beginTransaction();
    RealmObjectSchema tableSchema = realmSchema.create("Employee")
            .addField("name", String.class, FieldAttribute.PRIMARY_KEY);

    realm.createObject("Employee", "Foo");
    DynamicRealmObject obj = realm.createObject("Employee", "Foo2");

    try {
        // Tries to create 2nd entry with name Foo.
        obj.setString("name", "Foo");
    } catch (IllegalArgumentException e) {
        tableSchema.removePrimaryKey();
        obj.setString("name", "Foo");
    } finally {
        realm.close();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:PrimaryKeyTests.java


示例2: changeFieldType

import io.realm.FieldAttribute; //导入依赖的package包/类
private static void changeFieldType(RealmObjectSchema objectSchema, String fieldName,
                             Class newType, @Nullable FieldAttribute attribute,
                             Action3<DynamicRealmObject, String, String> transformation) {
    String tempFieldName = fieldName + "_temp";
    if (attribute != null) {
        if (attribute == FieldAttribute.PRIMARY_KEY && objectSchema.hasPrimaryKey()) {
            // remove existing primary key
            objectSchema.removePrimaryKey();
        }
        objectSchema.addField(tempFieldName, newType, attribute);
    } else {
        objectSchema.addField(tempFieldName, newType);
    }
    objectSchema
            .transform(obj -> {
                transformation.call(obj, fieldName, tempFieldName);
            })
            .removeField(fieldName)
            .renameField(tempFieldName, fieldName);
}
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:21,代码来源:RealmUtils.java


示例3: migrate

import io.realm.FieldAttribute; //导入依赖的package包/类
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
    if (newVersion > oldVersion) {
        RealmSchema realmSchema = realm.getSchema();
        if (oldVersion == 1) {
            realmSchema.create("UpgradeModel")
                    .addField("localId", String.class, FieldAttribute.PRIMARY_KEY)
                    .addField("version", String.class)
                    .addField("url", String.class)
                    .addField("compulsive_upgrade", String.class)
                    .addField("description", String.class);
        }
        updateLearningModel(realmSchema);
    }
}
 
开发者ID:Jusenr,项目名称:androidgithub,代码行数:16,代码来源:APPRealmMigration.java


示例4: migrate

import io.realm.FieldAttribute; //导入依赖的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++;
    }
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:69,代码来源:DatabaseMigration.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PowerModel类代码示例发布时间:2022-05-22
下一篇:
Java RegexQNamePattern类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap