Projects >> realm-java >>92489a09e397a7f47fdd9c0b85292fe50159d384

Chunk
Conflicting content
@SupportedAnnotationTypes({"io.realm.annotations.RealmClass", "io.realm.annotations.Ignore"})
@SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_6)
public class RealmProcessor extends AbstractProcessor {
<<<<<<< HEAD
    private static Set classesToValidate = new HashSet();
    private static boolean done = false;
=======
    Set classesToValidate = new HashSet();
    boolean done = false;
>>>>>>> 7121a710aa7ced4c927831a1b0bba2609c232d97

    @Override
    public boolean process(Set annotations, RoundEnvironment roundEnv) {
Solution content
@SupportedAnnotationTypes({"io.realm.annotations.RealmClass", "io.realm.annotations.Ignore"})
@SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_6)
public class RealmProcessor extends AbstractProcessor {
    Set classesToValidate = new HashSet();
    boolean done = false;

    @Override
    public boolean process(Set annotations, RoundEnvironment roundEnv) {
File
RealmProcessor.java
Developer's decision
Version 2
Kind of conflict
Attribute
Method invocation
Chunk
Conflicting content
    }

    /**
     */
    public static Realm create(File writableFolder, String filename) {
        String absolutePath = new File(writableFolder, filename).getAbsolutePath();
<<<<<<< HEAD
        return createAndValidate(absolutePath, true);
    }

    private static Realm createAndValidate(String absolutePath, boolean validateSchema) {
        Map realms = realmsCache.get();
        Realm realm = realms.get(absolutePath);
        if (realm == null) {
            realm = new Realm(absolutePath);
            realms.put(absolutePath, realm);
            realmsCache.set(realms);
=======
        return create(absolutePath, null);
    }

    /**
     * Realm static constructor
     * @param context an Android context
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm getInstance(Context context, byte[] key) {
        return Realm.getInstance(context, DEFAULT_REALM_NAME, key);
    }

    /**
     * Realm static constructor
     * @param context an Android context
     * @param fileName the name of the file to save the Realm to
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm getInstance(Context context, String fileName, byte[] key) {
        return Realm.create(context.getFilesDir(), fileName, key);
    }

    /**
     * Realm static constructor
     * @param writableFolder absolute path to a writable directory
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm getInstance(File writableFolder, byte[] key) {
        return Realm.create(writableFolder, DEFAULT_REALM_NAME, key);
     * Realm static constructor
     * @param writableFolder absolute path to a writable directory
     * @param filename the name of the file to save the Realm to
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm create(File writableFolder, String filename, byte[] key) {
        String absolutePath = new File(writableFolder, filename).getAbsolutePath();
        return create(absolutePath, key);
    }

    private static Realm create(String absolutePath, byte[] key) {
        ThreadRealm threadRealm = realms.get(absolutePath);
        if (threadRealm == null) {
            threadRealm = new ThreadRealm(absolutePath, key);
            realms.put(absolutePath, threadRealm);
        }
        SoftReference realmSoftReference = threadRealm.get();
        Realm realm = realmSoftReference.get();
        if (realm == null) {
            // The garbage collector decided to get rid of the realm instance
            threadRealm = new ThreadRealm(absolutePath, key);
            realms.put(absolutePath, threadRealm);
            realmSoftReference = threadRealm.get();
            realm = realmSoftReference.get();
>>>>>>> 7121a710aa7ced4c927831a1b0bba2609c232d97
        }
        if (validateSchema) {
            // FIXME - get rid fo validatedPaths - only validate if we don't have a cached realm
Solution content
     * Realm static constructor
     * @param context an Android context
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm getInstance(Context context, byte[] key) {
        return Realm.getInstance(context, DEFAULT_REALM_NAME, key);
    }

    /**
     * Realm static constructor
     * @param context an Android context
     * @param fileName the name of the file to save the Realm to
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm getInstance(Context context, String fileName, byte[] key) {
        return Realm.create(context.getFilesDir(), fileName, key);
    }

    /**
     * Realm static constructor
     * @param writableFolder absolute path to a writable directory
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm getInstance(File writableFolder, byte[] key) {
        return Realm.create(writableFolder, DEFAULT_REALM_NAME, key);
    }

    /**
     * @param writableFolder absolute path to a writable directory
     * @param filename the name of the file to save the Realm to
     * @param key a 32-byte encryption key
     * @return an instance of the Realm class
     */
    public static Realm create(File writableFolder, String filename, byte[] key) {
        String absolutePath = new File(writableFolder, filename).getAbsolutePath();
        return createAndValidate(absolutePath, key, true);
    }

    private static Realm createAndValidate(String absolutePath, byte[] key, boolean validateSchema) {
        ThreadRealm threadRealm = realms.get(absolutePath);
        boolean needsValidation = (threadRealm == null);
        if (threadRealm == null) {
            threadRealm = new ThreadRealm(absolutePath, key);
        }
        SoftReference realmSoftReference = threadRealm.get();
        Realm realm = realmSoftReference.get();
        if (realm == null) {
            // The garbage collector decided to get rid of the realm instance
            threadRealm = new ThreadRealm(absolutePath, key);
            realmSoftReference = threadRealm.get();
            realm = realmSoftReference.get();
        }
File
Realm.java
Developer's decision
Manual
Kind of conflict
Comment
If statement
Method declaration
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
                    throw new RealmException("An exception was thrown in the getProxyClasses method in the ValidationList class");
                }

<<<<<<< HEAD
                long version = realm.getVersion();
                try {
                    realm.beginTransaction();
                    if (version == UNVERSIONED) {
                        realm.setVersion(0);
                    }

                    for (String className : proxyClasses) {
                        String modelClassName = Iterables.getLast(Splitter.on(".").split(className));
                        String generatedClassName = "io.realm." + modelClassName + "RealmProxy";
                        Class generatedClass;
                        try {
                            generatedClass = Class.forName(generatedClassName);
                        } catch (ClassNotFoundException e) {
                            throw new RealmException("Could not find the generated " + generatedClassName + " class");
                        }

                        // if not versioned, create table
                        if (version == UNVERSIONED) {
                            Method initTableMethod;
                            try {
                                initTableMethod = generatedClass.getMethod("initTable", new Class[]{ImplicitTransaction.class});
                            } catch (NoSuchMethodException e) {
                                throw new RealmException("Could not find the initTable method in the generated " + generatedClassName + " class");
                            }
                            try {
                                initTableMethod.invoke(null, realm.transaction);
                            } catch (IllegalAccessException e) {
                                throw new RealmException("Could not execute the initTable method in the " + generatedClassName + " class");
                            } catch (InvocationTargetException e) {
                                throw new RealmException("An exception was thrown in the initTable method in the " + generatedClassName + " class");
                            }
                        }

                        // validate created table
                        Method validateMethod;
                        try {
                            validateMethod = generatedClass.getMethod("validateTable", new Class[]{ImplicitTransaction.class});
                        } catch (NoSuchMethodException e) {
                            throw new RealmException("Could not find the validateTable method in the generated " + generatedClassName + " class");
                        }
                        try {
                            validateMethod.invoke(null, realm.transaction);
                        } catch (IllegalAccessException e) {
                            throw new RealmException("Could not execute the validateTable method in the " + generatedClassName + " class");
                        } catch (InvocationTargetException e) {
                            throw new RealmMigrationNeededException(e.getMessage());
                        }

                        // Populate the columnIndices table
                        Method fieldNamesMethod;
                        try {
                            fieldNamesMethod = generatedClass.getMethod("getFieldNames");
                        } catch (NoSuchMethodException e) {
                            throw new RealmException("Could not find the getFieldNames method in the generated " + generatedClassName + " class");
                        }
                        List fieldNames;
                        try {
                            fieldNames = (List)fieldNamesMethod.invoke(null);
                        } catch (IllegalAccessException e) {
                            throw new RealmException("Could not execute the getFieldNames method in the generated " + generatedClassName + " class");
                        } catch (InvocationTargetException e) {
                            throw new RealmException("An exception was thrown in the getFieldNames method in the generated " + generatedClassName + " class");
                        }
                        Table table = realm.transaction.getTable(TABLE_PREFIX + modelClassName);
                        for (String fieldName : fieldNames) {
                            long columnIndex = table.getColumnIndex(fieldName);
                            if (columnIndex == -1) {
                                throw new RealmMigrationNeededException("Column '" + fieldName + "' not found for type '" + modelClassName + "'");
                            }
                            columnIndices.put(modelClassName, fieldName, columnIndex);
                        }
                    }
                    validatedPaths.add(absolutePath);
                }
                finally {
                    realm.commitTransaction();
                }
            }
=======
    // This class stores soft-references to realm objects per thread per realm file
    private static class ThreadRealm extends ThreadLocal> {
        private String absolutePath;
        private byte[] key;

        private ThreadRealm(String absolutePath, byte[] key) {
            this.absolutePath = absolutePath;
            this.key = key;
>>>>>>> 7121a710aa7ced4c927831a1b0bba2609c232d97
        }
        return realm;
    }
Solution content
                }

                for (String className : proxyClasses) {
                    String modelClassName = Iterables.getLast(Splitter.on(".").split(className));
                    String generatedClassName = "io.realm." + modelClassName + "RealmProxy";
                    Class generatedClass;
                    try {
                        generatedClass = Class.forName(generatedClassName);
                    } catch (ClassNotFoundException e) {
                        throw new RealmException("Could not find the generated " + generatedClassName + " class");
                    }

                    // if not versioned, create table
                    if (version == UNVERSIONED) {
                        Method initTableMethod;
                        try {
                            initTableMethod = generatedClass.getMethod("initTable", new Class[]{ImplicitTransaction.class});
                        } catch (NoSuchMethodException e) {
                            throw new RealmException("Could not find the initTable method in the generated " + generatedClassName + " class");
                        }
                        try {
                            initTableMethod.invoke(null, realm.transaction);
                        } catch (IllegalAccessException e) {
                            throw new RealmException("Could not execute the initTable method in the " + generatedClassName + " class");
                        } catch (InvocationTargetException e) {
                            throw new RealmException("An exception was thrown in the initTable method in the " + generatedClassName + " class");
                        }
                    }

                    // validate created table
                    Method validateMethod;
                    try {
                        validateMethod = generatedClass.getMethod("validateTable", new Class[]{ImplicitTransaction.class});
                    } catch (NoSuchMethodException e) {
                        throw new RealmException("Could not find the validateTable method in the generated " + generatedClassName + " class");
                    }
                    try {
                        validateMethod.invoke(null, realm.transaction);
                    } catch (IllegalAccessException e) {
                        throw new RealmException("Could not execute the validateTable method in the " + generatedClassName + " class");
                    } catch (InvocationTargetException e) {
                        throw new RealmMigrationNeededException(e.getMessage());
                    }

                    // Populate the columnIndices table
                    Method fieldNamesMethod;
                    try {
                        fieldNamesMethod = generatedClass.getMethod("getFieldNames");
                    } catch (NoSuchMethodException e) {
                        throw new RealmException("Could not find the getFieldNames method in the generated " + generatedClassName + " class");
                    }
                    List fieldNames;
                    try {
                        fieldNames = (List)fieldNamesMethod.invoke(null);
                    } catch (IllegalAccessException e) {
                        throw new RealmException("Could not execute the getFieldNames method in the generated " + generatedClassName + " class");
                    } catch (InvocationTargetException e) {
                        throw new RealmException("An exception was thrown in the getFieldNames method in the generated " + generatedClassName + " class");
                    }
                    Table table = realm.transaction.getTable(TABLE_PREFIX + modelClassName);
                    for (String fieldName : fieldNames) {
                        long columnIndex = table.getColumnIndex(fieldName);
                        if (columnIndex == -1) {
                            throw new RealmMigrationNeededException("Column '" + fieldName + "' not found for type '" + modelClassName + "'");
                        }
                        columnIndices.put(modelClassName, fieldName, columnIndex);
                    }
                }

                // cache realm after validation
                realms.put(absolutePath, threadRealm);
            }
            finally {
                realm.commitTransaction();
            }
        }

        return realm;
    }

    // This class stores soft-references to realm objects per thread per realm file
    private static class ThreadRealm extends ThreadLocal> {
        private String absolutePath;
        private byte[] key;

        private ThreadRealm(String absolutePath, byte[] key) {
            this.absolutePath = absolutePath;
            this.key = key;
        }
File
Realm.java
Developer's decision
Manual
Kind of conflict
Attribute
Class signature
Comment
Method invocation
Method signature
Try statement
Variable
Chunk
Conflicting content
    // This class stores soft-references to realm objects per thread per realm file
    private static class ThreadRealm extends ThreadLocal> {
        @Override
<<<<<<< HEAD
        protected Map initialValue() {
            return new HashMap();
=======
        protected SoftReference initialValue() {
            Realm realm = new Realm(absolutePath, key);
            key = null;
            return new SoftReference(realm);
>>>>>>> 7121a710aa7ced4c927831a1b0bba2609c232d97
        }
    }
Solution content
        @Override
        protected SoftReference initialValue() {
            Realm realm = new Realm(absolutePath, key);
            key = null;
            return new SoftReference(realm);
        }
    }
File
Realm.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
        getTable(classSpec).clear();
    }

<<<<<<< HEAD
    private long getVersion() {
        if (!transaction.hasTable("metadata")) {
            return UNVERSIONED;
        }
        Table metadataTable = transaction.getTable("metadata");
        return metadataTable.getLong(0, 0);
    }

    private void setVersion(long version) {
        Table metadataTable = transaction.getTable("metadata");
        if (metadataTable.getColumnCount() == 0) {
            metadataTable.addColumn(ColumnType.INTEGER, "version");
            metadataTable.addEmptyRow();
        }
        metadataTable.setLong(0, 0, version);
    }

    static public void migrateRealmAtPath(String realmPath, RealmMigration migration) {
        Realm realm = Realm.createAndValidate(realmPath, false);
        realm.beginTransaction();
        realm.setVersion(migration.execute(realm, realm.getVersion()));
        realm.commitTransaction();
        // Update the cache
        Map realms = realmsCache.get();
        realms.put(realmPath, new Realm(realmPath));
        realmsCache.set(realms);
=======
    private int getVersion() {
        return version;
    }

    private void setVersion(int version) {
        this.version = version;
>>>>>>> 7121a710aa7ced4c927831a1b0bba2609c232d97
    }

    /**
Solution content
        getTable(classSpec).clear();
    }

    private long getVersion() {
        if (!transaction.hasTable("metadata")) {
            return UNVERSIONED;
        }
        Table metadataTable = transaction.getTable("metadata");
        return metadataTable.getLong(0, 0);
    }

    private void setVersion(long version) {
        Table metadataTable = transaction.getTable("metadata");
        if (metadataTable.getColumnCount() == 0) {
            metadataTable.addColumn(ColumnType.INTEGER, "version");
            metadataTable.addEmptyRow();
        }
        metadataTable.setLong(0, 0, version);
    }

    static public void migrateRealmAtPath(String realmPath, RealmMigration migration) {
        migrateRealmAtPath(realmPath, null, migration);
    }

    static public void migrateRealmAtPath(String realmPath, byte [] key, RealmMigration migration) {
        Realm realm = Realm.createAndValidate(realmPath, key, false);
        realm.beginTransaction();
        realm.setVersion(migration.execute(realm, realm.getVersion()));
        realm.commitTransaction();
    }

    /**
File
Realm.java
Developer's decision
Manual
Kind of conflict
Attribute
Comment
Method declaration
Method invocation
Method signature
Variable