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


Java PrimaryKey类代码示例

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


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

示例1: addRealmAnnotations

import io.realm.annotations.PrimaryKey; //导入依赖的package包/类
private void addRealmAnnotations(Field f, SpannableStringBuilder builder) {
    List<Class<? extends Annotation>> classes = new ArrayList<>(3);
    classes.add(PrimaryKey.class);
    classes.add(Ignore.class);
    classes.add(Index.class);
    for (Class<? extends Annotation> c : classes) {
        if (f.isAnnotationPresent(c)) {
            addAnnotationName(builder, f.getAnnotation(c));
        }
    }
}
 
开发者ID:Scandltd,项目名称:realmbrowser,代码行数:12,代码来源:DbTableFragment.java

示例2: categorizeField

import io.realm.annotations.PrimaryKey; //导入依赖的package包/类
private boolean categorizeField(Element element) {
    VariableElement field = (VariableElement) element;

    // completely ignore any static fields
    if (field.getModifiers().contains(Modifier.STATIC)) { return true; }

    // Ignore fields marked with @Ignore or if they are transient
    if (field.getAnnotation(Ignore.class) != null || field.getModifiers().contains(Modifier.TRANSIENT)) {
        return true;
    }

    if (field.getAnnotation(Index.class) != null) {
        if (!categorizeIndexField(element, field)) { return false; }
    }

    // @Required annotation of RealmList field only affects its value type, not field itself.
    if (Utils.isRealmList(field)) {
        // We only check @Required annotation. @org.jetbrains.annotations.NotNull annotation should not affect nullability of the list values.
        if (!hasRequiredAnnotation(field)) {
            final List<? extends TypeMirror> fieldTypeArguments = ((DeclaredType) field.asType()).getTypeArguments();
            if (fieldTypeArguments.isEmpty() || !Utils.isRealmModel(fieldTypeArguments.get(0))) {
                nullableValueListFields.add(field);
            }
        }
    } else if (isRequiredField(field)) {
        categorizeRequiredField(element, field);
    } else {
        // The field doesn't have the @Required and @org.jetbrains.annotations.NotNull annotation.
        // Without @Required annotation, boxed types/RealmObject/Date/String/bytes should be added to
        // nullableFields.
        // RealmList of models, RealmResults(backlinks) and primitive types are NOT nullable. @Required annotation is not supported.
        if (!Utils.isPrimitiveType(field) && !Utils.isRealmResults(field)) {
            nullableFields.add(field);
        }
    }

    if (field.getAnnotation(PrimaryKey.class) != null) {
        if (!categorizePrimaryKeyField(field)) { return false; }
    }

    // @LinkingObjects cannot be @PrimaryKey or @Index.
    if (field.getAnnotation(LinkingObjects.class) != null) {
        // Do not add backlinks to fields list.
        return categorizeBacklinkField(field);
    }

    // Similarly, a MutableRealmInteger cannot be a @PrimaryKey or @LinkingObject.
    if (Utils.isMutableRealmInteger(field)) {
        if (!categorizeMutableRealmIntegerField(field)) { return false; }
    }

    // Standard field that appears to be valid (more fine grained checks might fail later).
    fields.add(field);

    return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:57,代码来源:ClassMetaData.java

示例3: matchMigratedField

import io.realm.annotations.PrimaryKey; //导入依赖的package包/类
private static void matchMigratedField(RealmObjectSchema objectSchema, String modelFieldName, Field field) {
    boolean isIndexed = false;
    boolean isRequired = false;
    boolean isPrimaryKey = false;
    if(field.isAnnotationPresent(Index.class)) {
        isIndexed = true;
    }
    if(field.isAnnotationPresent(Required.class)) {
        isRequired = true;
    }
    if(field.isAnnotationPresent(PrimaryKey.class)) {
        isPrimaryKey = true;
    }

    if(isPrimaryKey && !objectSchema.isPrimaryKey(modelFieldName)) {
        if(objectSchema.hasPrimaryKey()) {
            objectSchema.removePrimaryKey();
        }
        objectSchema.addPrimaryKey(modelFieldName);
    }
    if(!isPrimaryKey && objectSchema.isPrimaryKey(modelFieldName)) {
        objectSchema.removePrimaryKey();
    }
    // index management must be after primary key because removePrimaryKey() removes index as well.
    if((isIndexed || isPrimaryKey) && !objectSchema.hasIndex(modelFieldName)) {
        objectSchema.addIndex(modelFieldName);
    }
    if(!isIndexed && !isPrimaryKey /* primary key is indexed by default! */ && objectSchema.hasIndex(modelFieldName)) {
        objectSchema.removeIndex(modelFieldName);
    }
    if(isNonNullPrimitive(field.getType())) {
        if(!objectSchema.isRequired(modelFieldName)) {
            objectSchema.setNullable(modelFieldName, false);
        }
    } else {
        if(isRequired && objectSchema.isNullable(modelFieldName)) {
            objectSchema.setNullable(modelFieldName, false);
        }
        if(!isRequired && !objectSchema.isNullable(modelFieldName)) {
            objectSchema.setNullable(modelFieldName, true);
        }
    }
}
 
开发者ID:Zhuinden,项目名称:realm-helpers,代码行数:44,代码来源:RealmAutoMigration.java


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