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


Java RealmModule类代码示例

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


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

示例1: generate

import io.realm.annotations.RealmModule; //导入依赖的package包/类
public void generate() throws IOException {
    String qualifiedGeneratedClassName = String.format(Locale.US, "%s.%s", Constants.REALM_PACKAGE_NAME, Constants.DEFAULT_MODULE_CLASS_NAME);
    JavaFileObject sourceFile = env.getFiler().createSourceFile(qualifiedGeneratedClassName);
    JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
    writer.setIndent("    ");

    writer.emitPackage(Constants.REALM_PACKAGE_NAME);
    writer.emitEmptyLine();

    Map<String, Boolean> attributes = new HashMap<String, Boolean>();
    attributes.put("allClasses", Boolean.TRUE);
    writer.emitAnnotation(RealmModule.class, attributes);
    writer.beginType(
            qualifiedGeneratedClassName,        // full qualified name of the item to generate
            "class",                            // the type of the item
            Collections.<Modifier>emptySet(),   // modifiers to apply
            null);                              // class to extend
    writer.emitEmptyLine();

    writer.endType();
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DefaultModuleGenerator.java

示例2: processModules

import io.realm.annotations.RealmModule; //导入依赖的package包/类
private boolean processModules(RoundEnvironment roundEnv) {
    ModuleMetaData moduleMetaData = new ModuleMetaData(classesToValidate);
    if (!moduleMetaData.generate(roundEnv.getElementsAnnotatedWith(RealmModule.class))) {
        return false;
    }

    // Create default module if needed
    if (moduleMetaData.shouldCreateDefaultModule()) {
        if (!createDefaultModule()) {
            return false;
        }
    }

    // Create RealmProxyMediators for all Realm modules
    for (Map.Entry<String, Set<ClassMetaData>> module : moduleMetaData.getAllModules().entrySet()) {
        if (!createMediator(Utils.stripPackage(module.getKey()), module.getValue())) {
            return false;
        }
    }

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

示例3: forRecovery

import io.realm.annotations.RealmModule; //导入依赖的package包/类
/**
 * Returns a {@link RealmConfiguration} appropriate to open a read-only, non-synced Realm to recover any pending changes.
 * This is useful when trying to open a backup/recovery Realm (after a client reset).
 *
 * @param canonicalPath the absolute path to the Realm file defined by this configuration.
 * @param encryptionKey the key used to encrypt/decrypt the Realm file.
 * @param modules if specified it will restricts Realm schema to the provided module.
 * @return RealmConfiguration that can be used offline
 */
public static RealmConfiguration forRecovery(String canonicalPath, @Nullable byte[] encryptionKey, @Nullable Object... modules) {
    HashSet<Object> validatedModules = new HashSet<>();
    if (modules != null && modules.length > 0) {
        for (Object module : modules) {
            if (!module.getClass().isAnnotationPresent(RealmModule.class)) {
                throw new IllegalArgumentException(module.getClass().getCanonicalName() + " is not a RealmModule. " +
                        "Add @RealmModule to the class definition.");
            }
            validatedModules.add(module);
        }
    } else {
        if (Realm.getDefaultModule() != null) {
            validatedModules.add(Realm.getDefaultModule());
        }
    }

    RealmProxyMediator schemaMediator = createSchemaMediator(validatedModules, Collections.<Class<? extends RealmModel>>emptySet());
    return forRecovery(canonicalPath, encryptionKey, schemaMediator);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:SyncConfiguration.java

示例4: getAnnotationMirror

import io.realm.annotations.RealmModule; //导入依赖的package包/类
private AnnotationMirror getAnnotationMirror(Element classElement) {
    AnnotationMirror annotationMirror = null;
    for (AnnotationMirror am : classElement.getAnnotationMirrors()) {
        if (am.getAnnotationType().toString().equals(RealmModule.class.getCanonicalName())) {
            annotationMirror = am;
            break;
        }
    }
    return annotationMirror;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:ModuleMetaData.java

示例5: testCompositeMediatorModelClassesCount

import io.realm.annotations.RealmModule; //导入依赖的package包/类
public void testCompositeMediatorModelClassesCount() {
    final CompositeMediator mediator = new CompositeMediator(
            new HumanModuleMediator(),
            new AnimalModuleMediator()
    );

    final int modelsInHumanModule = HumanModule.class.getAnnotation(RealmModule.class).classes().length;
    final int modelsInAnimalModule = AnimalModule.class.getAnnotation(RealmModule.class).classes().length;

    assertEquals(modelsInHumanModule + modelsInAnimalModule, mediator.getModelClasses().size());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:MediatorTest.java

示例6: generate

import io.realm.annotations.RealmModule; //导入依赖的package包/类
public void generate() throws IOException {
    String qualifiedGeneratedClassName = String.format(Locale.US, "%s.%sMediator", REALM_PACKAGE_NAME, className);
    JavaFileObject sourceFile = processingEnvironment.getFiler().createSourceFile(qualifiedGeneratedClassName);
    JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
    writer.setIndent("    ");

    writer.emitPackage(REALM_PACKAGE_NAME);
    writer.emitEmptyLine();

    writer.emitImports(
            "android.util.JsonReader",
            "java.io.IOException",
            "java.util.Collections",
            "java.util.HashSet",
            "java.util.List",
            "java.util.Map",
            "java.util.HashMap",
            "java.util.Set",
            "java.util.Iterator",
            "java.util.Collection",
            "io.realm.internal.ColumnInfo",
            "io.realm.internal.RealmObjectProxy",
            "io.realm.internal.RealmProxyMediator",
            "io.realm.internal.Row",
            "io.realm.internal.OsSchemaInfo",
            "io.realm.internal.OsObjectSchemaInfo",
            "org.json.JSONException",
            "org.json.JSONObject"
    );

    writer.emitEmptyLine();

    writer.emitAnnotation(RealmModule.class);
    writer.beginType(
            qualifiedGeneratedClassName,        // full qualified name of the item to generate
            "class",                            // the type of the item
            Collections.<Modifier>emptySet(),   // modifiers to apply
            "RealmProxyMediator");              // class to extend
    writer.emitEmptyLine();

    emitFields(writer);
    emitGetExpectedObjectSchemaInfoMap(writer);
    emitCreateColumnInfoMethod(writer);
    emitGetFieldNamesMethod(writer);
    emitGetSimpleClassNameMethod(writer);
    emitNewInstanceMethod(writer);
    emitGetClassModelList(writer);
    emitCopyToRealmMethod(writer);
    emitInsertObjectToRealmMethod(writer);
    emitInsertListToRealmMethod(writer);
    emitInsertOrUpdateObjectToRealmMethod(writer);
    emitInsertOrUpdateListToRealmMethod(writer);
    emitCreteOrUpdateUsingJsonObject(writer);
    emitCreateUsingJsonStream(writer);
    emitCreateDetachedCopyMethod(writer);
    writer.endType();
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:59,代码来源:RealmProxyMediatorGenerator.java

示例7: generate

import io.realm.annotations.RealmModule; //导入依赖的package包/类
/**
 * Builds the meta data structures for this class. Any errors or messages will be posted on the provided Messager.
 *
 * @return True if meta data was correctly created and processing can continue, false otherwise.
 */
public boolean generate(Set<? extends Element> clazzes) {

    // Check that modules are setup correctly
    for (Element classElement : clazzes) {
        String classSimpleName = classElement.getSimpleName().toString();

        // Check that the annotation is only applied to a class
        if (!classElement.getKind().equals(ElementKind.CLASS)) {
            Utils.error("The RealmModule annotation can only be applied to classes", classElement);
            return false;
        }

        // Check that allClasses and classes are not set at the same time
        RealmModule module = classElement.getAnnotation(RealmModule.class);
        Utils.note("Processing module " + classSimpleName);
        if (module.allClasses() && hasCustomClassList(classElement)) {
            Utils.error("Setting @RealmModule(allClasses=true) will override @RealmModule(classes={...}) in " + classSimpleName);
            return false;
        }

        // Check that classes added are proper Realm model classes
        String qualifiedName = ((TypeElement) classElement).getQualifiedName().toString();
        Set<ClassMetaData> classes;
        if (module.allClasses()) {
            classes = availableClasses;
        } else {
            classes = new HashSet<ClassMetaData>();
            Set<String> classNames = getClassMetaDataFromModule(classElement);
            for (String fullyQualifiedClassName : classNames) {
                ClassMetaData metadata = classMetaData.get(fullyQualifiedClassName);
                if (metadata == null) {
                    Utils.error(Utils.stripPackage(fullyQualifiedClassName) + " could not be added to the module. " +
                            "Only classes extending RealmObject, which are part of this project, can be added.");
                    return false;
                }
                classes.add(metadata);
            }
        }

        // Create either a Library or App module
        if (module.library()) {
            libraryModules.put(qualifiedName, classes);
        } else {
            modules.put(qualifiedName, classes);
        }
    }

    // Check that app and library modules are not mixed
    if (modules.size() > 0 && libraryModules.size() > 0) {
        Utils.error("Normal modules and library modules cannot be mixed in the same project");
        return false;
    }

    // Create default Realm module if needed.
    // Note: Kotlin will trigger the annotation processor even if no Realm annotations are used.
    // The DefaultRealmModule should not be created in this case either.
    if (libraryModules.size() == 0 && availableClasses.size() > 0) {
        shouldCreateDefaultModule = true;
        String defaultModuleName = Constants.REALM_PACKAGE_NAME + "." + Constants.DEFAULT_MODULE_CLASS_NAME;
        modules.put(defaultModuleName, availableClasses);
    }

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

示例8: checkModule

import io.realm.annotations.RealmModule; //导入依赖的package包/类
private void checkModule(Object module) {
    if (!module.getClass().isAnnotationPresent(RealmModule.class)) {
        throw new IllegalArgumentException(module.getClass().getCanonicalName() + " is not a RealmModule. " +
                "Add @RealmModule to the class definition.");
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:RealmConfiguration.java


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