问题描述
我当前在我的一个Android项目中运行Realm版本0.82.0.我已经有一段时间没有接触Realm了,直到最近我注意到它们同时升级到了2.0.2版.我想升级我的Realm版本,不幸的是,我不知道从旧版本到当前版本的升级是否有效或破坏了我的代码.
I'm currently running Realm Version 0.82.0 in one of my Android projects. I didn't touch Realm for quite some time, until I recently noticed that they went up until version 2.0.2 in the meantime. I would like to upgrade my version of Realm, unfortunately, I don't know if the upgrade from my old version to the current release will be working or breaking my code.
我特别关注迁移,因为自代码以来,用于迁移的API似乎已发生了一些变化,而且我不确定如果只是更新版本,迁移是否会中断.不幸的是,他们的网页上没有关于升级Realm版本的文档.
I'm especially concerned of migrations, since the API for migrations seemed to have changed a bit since my code, and I'm unsure if my migrations will break if I just update my version. Unfortunately, there is no documentation about upgrading Realm version available on their webpage.
任何人都没有升级Realm的经验,尤其是在两个主要版本上都增加了版本吗?
Does anyone have any experience with upgrading Realm, especiall a version increase over two major versions?
推荐答案
重大更改列表可在 CHANGELOG.MD 在其Github上.
The list of breaking changes is available in the CHANGELOG.MD on their Github.
但是,值得注意的是,道路上发生了许多重大变化,尤其是0.89.0.
However, it's worth noting that there were quite a few breaking changes on the road, especially noting 0.89.0.
从0.82.0
到5.1.0
(以下是目前最稳定的版本):
From 0.82.0
to 5.1.0
is the following (which is the most stable version at the moment):
0.82.0 :
(0.82.2在这里最稳定,但在Blackberry设备上不起作用.在Blackberry上使用的第一个 stable 版本是0.87.2.)
(0.82.2 was most stable here, but it didn't work on Blackberry devices. The first stable version to use on Blackberry was 0.87.2.)
在0.86.0及更高版本中,您可以使用
In 0.86.0+, you can add an index to the annotated field using
@Override
public void migrate(final DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
// version check and stuff
RealmObjectSchema personSchema = schema.get("Person");
personSchema.addIndex("fieldName");
0.83 :
BREAKING CHANGE:从Realm类中删除了不赞成使用的方法和构造函数.
BREAKING CHANGE: Removed deprecated methods and constructors from the Realm class.
BREAKING CHANGE:引入了盒装类型Boolean,Byte,Short,Integer,Long,Float和Double.添加了空支持.引入了注释@Required以指示字段不可为空.默认情况下,String,Date和byte []可以为空,这意味着如果打开Realm文件的先前版本,则将引发RealmMigrationNeededException.
BREAKING CHANGE: Introduced boxed types Boolean, Byte, Short, Integer, Long, Float and Double. Added null support. Introduced annotation @Required to indicate a field is not nullable. String, Date and byte[] became nullable by default which means a RealmMigrationNeededException will be thrown if an previous version of a Realm file is opened.
哦,男孩,这是一个好人. NULL支持.
Oh boy, this is a nice one. NULL support.
框的基本类型可用.装箱的类型默认情况下可以为空.所有String
,Date
和byte[]
必须使用@Required
或schema.setNullable("fieldName", nullability)
进行注释,并使它们都可以为空.
Boxed types for primitives became available. Boxed types are nullable by default. All String
, Date
, and byte[]
must be annotated with @Required
, or schema.setNullable("fieldName", nullability)
and make them all nullable.
0.84.0:
添加了异步查询.就架构而言,这里没有什么新鲜的东西.
Async queries were added. Nothing new here in terms of schema.
0.85.0:
BREAKING CHANGE:Realm.executeTransaction()现在直接引发任何RuntimeException,而不是将其包装在RealmException(#1682)中.
BREAKING CHANGE: Realm.executeTransaction() now directly throws any RuntimeException instead of wrapping it in a RealmException (#1682).
BREAKING CHANGE:现在,如果字段名称是链接字段并且最后一个元素是链接(#1693),则RealmQuery.isNull()和RealmQuery.isNotNull()抛出IllegalArgumentException而不是RealmError.
BREAKING CHANGE: RealmQuery.isNull() and RealmQuery.isNotNull() now throw IllegalArgumentException instead of RealmError if the fieldname is a linked field and the last element is a link (#1693).
这里没有什么重要的,尽管:
Nothing important here yet, although:
这个很有趣.以前它只是失败了,所以这是最好的.但这也是Realm的最大限制.
This one is an interesting one. Previously it just failed, so this is for the best. But it is Realm's largest limitation, too.
0.86.0 :
BREAKING CHANGE:RealmResults.SORT_ORDER_ASCENDING和RealmResults.SORT_ORDER_DESCENDING常量已被Sort.ASCENDING和Sort.DESCENDING枚举取代.
BREAKING CHANGE: RealmResults.SORT_ORDER_ASCENDING and RealmResults.SORT_ORDER_DESCENDING constants have been replaced by Sort.ASCENDING and Sort.DESCENDING enums.
突破性变化:RealmQuery.CASE_SENSITIVE和RealmQuery.CASE_INSENSITIVE常量已替换为Case.SENSITIVE和Case.INSENSITIVE枚举.
BREAKING CHANGE: RealmQuery.CASE_SENSITIVE and RealmQuery.CASE_INSENSITIVE constants have been replaced by Case.SENSITIVE and Case.INSENSITIVE enums.
BREAKING CHANGE:Realm.addChangeListener,RealmObject.addChangeListener和RealmResults.addChangeListener拥有对侦听器的强引用,您应该注销该侦听器以避免内存泄漏.
BREAKING CHANGE: Realm.addChangeListener, RealmObject.addChangeListener and RealmResults.addChangeListener hold a strong reference to the listener, you should unregister the listener to avoid memory leaks.
BREAKING CHANGE:删除了不推荐使用的方法RealmQuery.minimum {Int,Float,Double},RealmQuery.maximum {Int,Float,Double},RealmQuery.sum {Int,Float,Double}和RealmQuery.average {Int,Float,双倍的}.改用RealmQuery.min(),RealmQuery.max(),RealmQuery.sum()和RealmQuery.average().
BREAKING CHANGE: Removed deprecated methods RealmQuery.minimum{Int,Float,Double}, RealmQuery.maximum{Int,Float,Double}, RealmQuery.sum{Int,Float,Double} and RealmQuery.average{Int,Float,Double}. Use RealmQuery.min(), RealmQuery.max(), RealmQuery.sum() and RealmQuery.average() instead.
BREAKING CHANGE:删除了错误地公开的RealmConfiguration.getSchemaMediator().然后添加RealmConfiguration.getRealmObjectClasses()作为替代方案,以获得一组模型类(#1797).
BREAKING CHANGE: Removed RealmConfiguration.getSchemaMediator() which is public by mistake. And RealmConfiguration.getRealmObjectClasses() is added as an alternative in order to obtain the set of model classes (#1797).
BREAKING CHANGE:当在非Looper线程上调用Realm.addChangeListener,RealmObject.addChangeListener和RealmResults.addChangeListener时,将抛出IllegalStateException.这是为了防止注册不会被调用的侦听器.
BREAKING CHANGE: Realm.addChangeListener, RealmObject.addChangeListener and RealmResults.addChangeListener will throw an IllegalStateException when invoked on a non-Looper thread. This is to prevent registering listeners that will not be invoked.
使用DynamicRealm和DynamicRealmObject添加了新的Dynamic API.
Added new Dynamic API using DynamicRealm and DynamicRealmObject.
添加了Realm.getSchema()和DynamicRealm.getSchema().
Added Realm.getSchema() and DynamicRealm.getSchema().
新的迁移API,使用DynamicRealm
而不是Realm.getTable()
.
某些内容已重命名,如果结果集仍然有效,则应该注销更改侦听器.但是值得注意的是,您仍然应该为RealmResults
保留字段变量,因为Realm的Context
对其引用很少.
Some stuff were renamed, and you ought to unregister your change listeners if your result set is still valid. But it's worth noting that you should still retain a field variable to your RealmResults
, because Realm's Context
only has a weak reference to it.
0.87.0 :
RX支持.没什么.
0.87.2 :
最后,Realm又恢复了稳定! :)
Finally, Realm got stable again! :)
0.88.0 :
Realm现在将作为Gradle插件安装.
Realm has now to be installed as a Gradle plugin.
DynamicRealm.executeTransaction()现在直接引发任何RuntimeException,而不是将其包装在RealmException(#1682)中.
DynamicRealm.executeTransaction() now directly throws any RuntimeException instead of wrapping it in a RealmException (#1682).
DynamicRealm.executeTransaction()现在引发IllegalArgumentException,而不是静默接受空的Transaction对象.
DynamicRealm.executeTransaction() now throws IllegalArgumentException instead of silently accepting a null Transaction object.
现在,字符串设置器会抛出IllegalArgumentException而不是RealmError来替代无效代理.
String setters now throw IllegalArgumentException instead of RealmError for invalid surrogates.
对于无效类型或无效索引字段,DynamicRealm.distinct()/distinctAsync()和Realm.distinct()/distinctAsync()现在会抛出IllegalArgumentException而不是UnsupportedOperationException.
DynamicRealm.distinct()/distinctAsync() and Realm.distinct()/distinctAsync() now throw IllegalArgumentException instead of UnsupportedOperationException for invalid type or unindexed field.
所有线程本地更改侦听器现在都延迟到下一个Looper事件,而不是在提交时被触发.
All thread local change listeners are now delayed until the next Looper event instead of being triggered when committing.
从公共API中删除了RealmConfiguration.getSchemaMediator(),该API在0.86.0中已弃用.请使用RealmConfiguration.getRealmObjectClasses()获取一组模型类(#1797).
Removed RealmConfiguration.getSchemaMediator() from public API which was deprecated in 0.86.0. Please use RealmConfiguration.getRealmObjectClasses() to obtain the set of model classes (#1797).
Realm.migrateRealm()如果Realm文件不存在,则抛出FileNotFoundException.
Realm.migrateRealm() throws a FileNotFoundException if the Realm file doesn't exist.
现在需要取消订阅所有Realm RxJava可观察对象,以完全关闭Realm(#2357).
It is now required to unsubscribe from all Realm RxJava observables in order to fully close the Realm (#2357).
欢迎.现在是AAR.您必须添加到classpath
并使用apply plugin: 'realm-android'
而不是compile ...
依赖项来运行它.
Welp. It's an AAR now. You have to add to classpath
and run it with apply plugin: 'realm-android'
instead of compile ...
dependency.
仅在下一个事件循环上调用更改侦听器,而不是在提交后立即调用.我..坦白说,我不能完全确定此问题的后果,但这意味着更改侦听器无法在后台线程上工作.仅在循环程序线程(主要是UI线程)上.
Change listeners are only called on the next event loop, instead of immediately after commit. I'm.. honestly not entirely sure of the ramifications of this, but it means change listeners don't work on background threads. Only on looper threads (primarily the UI thread).
支持自定义方法,访问器中的自定义逻辑,自定义访问器名称,接口实现和Realm对象中的公共字段(#909).
Support for custom methods, custom logic in accessors, custom accessor names, interface implementation and public fields in Realm objects (#909).
使用ReLinker改进了.so加载.
Improved .so loading by using ReLinker.
但这是非常必要的,因此我不想肯定会陷入0.87.5的境地.
This is quite necessary though, so I wouldn't want to get stuck on 0.87.5 for sure.
0.89.0:
@PrimaryKey字段值现在可以为空.应使用RealmObjectSchema.setNullable()或添加@Required批注来迁移较旧的领域. (#2515).
@PrimaryKey field value can now be null for String, Byte, Short, Integer, and Long types. Older Realms should be migrated, using RealmObjectSchema.setNullable(), or by adding the @Required annotation. (#2515).
RealmResults.clear()现在引发UnsupportedOperationException.改用RealmResults.deleteAllFromRealm().
RealmResults.clear() now throws UnsupportedOperationException. Use RealmResults.deleteAllFromRealm() instead.
RealmResults.remove(int)现在引发UnsupportedOperationException.改用RealmResults.deleteFromRealm(int).
RealmResults.remove(int) now throws UnsupportedOperationException. Use RealmResults.deleteFromRealm(int) instead.
RealmResults.sort()和RealmList.sort()现在返回已排序的结果,而不是就地排序.
RealmResults.sort() and RealmList.sort() now return the sorted result instead of sorting in-place.
如果RealmList为空,则RealmList.first()和RealmList.last()现在会引发ArrayIndexOutOfBoundsException.
RealmList.first() and RealmList.last() now throw ArrayIndexOutOfBoundsException if RealmList is empty.
从公共API中删除了不赞成使用的方法Realm.getTable().
Removed deprecated method Realm.getTable() from public API.
在Looper上的Realm.refresh()和DynamicRealm.refresh()不再起作用. RealmObject和RealmResults总是在下一个事件循环中更新.
Realm.refresh() and DynamicRealm.refresh() on a Looper no longer have any effect. RealmObject and RealmResults are always updated on the next event loop.
好的,这是最混乱的一个.
Okay, this one is the most messy one.
1.),您必须为@PrimaryKey
带注释的字段添加@Required
注释,因为null
是有效的主键值.
1.) you must add @Required
annotation for @PrimaryKey
annotated fields, because null
is a valid primary key value.
2.)realm.refresh()
不再起作用.无论如何,它将被删除.不过,这是1.1.1的解决方法,仅应在后台线程上使用.不过,它再次在Realm 3.2中可用.
2.) realm.refresh()
no longer works. It will be removed anyways. Here's a workaround for 1.1.1 though, should be used only on background threads. It is available in Realm 3.2 again, though.
3.)getTable()
被删除.不要使用它.使用新的迁移API.
3.) getTable()
is removed. Don't use it. Use the new migration API.
4.)realmResults.sort()
返回一个新的RealmResults,该RealmResults也需要附加更改侦听器.我认为这是不可靠的,所以我只使用findAllSorted()
即可.
4.) realmResults.sort()
returns a new RealmResults, which needs to have the change listener appended to it as well. I think it's unreliable, so I'd just use findAllSorted()
instead.
5.)您可能不会想太多,但是
5.) You might not think much of it, but
从字面上看,这意味着RealmResults
仅在事件循环发生时才更新,而在调用realm.commitTransaction()
时并没有立即更新.这也意味着,在后台线程上,commitTransaction()
时RealmResults不会更新,而您必须重新查询它们.
This literally meant that RealmResults
were only updated when the event loop occured, it was NOT immediately updated when you call realm.commitTransaction()
. This also means that on background threads, the RealmResults did NOT update when you commitTransaction()
, you had to requery them.
仅在调用附加的RealmChangeListener
之后才更新RealmResults
.在1.1.1中,调用RealmChangeListener
时,所有结果都已更新.
The RealmResults
are only known to be updated after the appended RealmChangeListener
is called. In 1.1.1, when the RealmChangeListener
is called, all Results had been updated.
但是,此更改还更改了事务中的迭代行为.在交易中,您始终会看到最新版本.这意味着您在迭代查询和修改元素时会重新评估查询. (从REALM 3.0开始也是这种情况)
This change however also changed iteration behavior in transactions. In transactions, you always saw the newest version. This meant that a query was re-evaluated as you were iterating on it, and modifying elements. (THIS IS ALSO THE CASE SINCE REALM 3.0)
示例,以前这是有效的代码:
Example, previously this was valid code:
RealmResults<Stuff> stuffs = realm.where(Stuff.class).equalTo("something", false).findAll();
while(!stuffs.isEmpty()) {
stuffs.get(0).setSomething(true);
}
// you end up here because stuffs will be empty
// because of live auto-updates in transactions
但是,这将不再起作用.对我来说,这引起了问题,因为有时我会这样迭代
However, this will no longer work. For me, this caused issues because I iterated sometimes like this
RealmResults<Stuff> stuffs = realm.where(Stuff.class).equalTo("something", false).findAll();
for(int i = 0; i < stuffs.size(); i++) {
stuffs.get(i--).setSomething(true);
}
// I end up here because of live auto-updates
这是一个问题,因为stuffs
将不再更改.我必须在代码中搜索--
并修复所有这样的迭代.
This is a problem, because the stuffs
will no longer change. I had to do a search for --
in my code and fix all iteration like this.
过去的官方解决方法是:
The official workaround used to be this:
RealmResults<Stuff> stuffs = realm.where(Stuff.class).equalTo("something", false).findAll();
for(int i = stuffs.size()-1; i >= 0; i--) {
stuffs.get(i).setSomething(true);
}
// I end up here because of normal iteration
在0.89.0中仍然可以正常工作.
This would still work fine in 0.89.0.
从0.89.0开始,这也是有效的代码(,而在3.0.0+版本中,这将自动创建快照集合):
Since 0.89.0, this is valid code too (and in 3.0.0+, this automatically creates a snapshot collection):
RealmResults<Stuff> stuffs = realm.where(Stuff.class).equalTo("something", false).findAll();
for(Stuff stuff : stuffs) {
stuff.setSomething(true);
}
尽管结果中的元素仍然无效,但是结果本身不会改变. (对于快照集合,在Realm 3.0.0+中也是如此.)
The elements in the results still get invalidated though, but the results themselves don't change. (This is the same for snapshot collections as well in Realm 3.0.0+).
0.90.0:
RealmChangeListener还提供更改的对象/领域/集合(#1594).
RealmChangeListener provides the changed object/Realm/collection as well (#1594).
Realm上的所有JSON方法现在仅将JSONException包装在RealmException中.所有其他异常均按原样抛出.
All JSON methods on Realm now only wraps JSONException in RealmException. All other Exceptions are thrown as they are.
标记RealmObject上的所有方法和所有公共类为final(#1594).
Marked all methods on RealmObject and all public classes final (#1594).
从公共API中删除了BaseRealm.
Removed BaseRealm from the public API.
从公共API中删除了HandlerController.
Removed HandlerController from the public API.
从公共API(#1594)中删除了RealmAsyncTask的构造函数.
Removed constructor of RealmAsyncTask from the public API (#1594).
RealmBaseAdapter已移至其自己的GitHub存储库: https://github.com/realm/realm-android-adapters
RealmBaseAdapter has been moved to its own GitHub repository: https://github.com/realm/realm-android-adapters
Realm文件的文件格式已更改.文件将自动升级,但是无法使用旧版本的Realm打开Realm文件.
File format of Realm files is changed. Files will be automatically upgraded but opening a Realm file with older versions of Realm is not possible.
因此RealmBaseAdapter
现在位于realm-android-adapters
中,对于Realm的1.1.1
,请使用1.3.0
.还添加RealmRecyclerViewAdapter
.对于3.5.0
,请使用2.0.0
或更高版本.
So RealmBaseAdapter
is now in realm-android-adapters
, for 1.1.1
of Realm, use 1.3.0
. Also adds RealmRecyclerViewAdapter
. For 3.5.0
, use 2.0.0
or newer.
RealmChangeListeners得到一个element
参数.是的.
RealmChangeListeners got an element
parameter. Yay.
而且,日期现在具有milisecond
精度.
Also, Date now has milisecond
precision.
0.91.0:
删除了所有@Deprecated方法.
Removed all @Deprecated methods.
即使autoRefresh为false(#2820),从非Looper线程调用Realm.setAutoRefresh()或DynamicRealm.setAutoRefresh()也会引发IllegalStateException.
Calling Realm.setAutoRefresh() or DynamicRealm.setAutoRefresh() from non-Looper thread throws IllegalStateException even if the autoRefresh is false (#2820).
在0.90.0中不推荐使用许多方法,所以
Deprecated a lot of methods in 0.90.0, so
Realm.allObjects *().改用Realm.where(clazz).findAll *().
Realm.allObjects*(). Use Realm.where(clazz).findAll*() instead.
Realm.distinct *().改用Realm.where(clazz).distinct *().
Realm.distinct*(). Use Realm.where(clazz).distinct*() instead.
DynamicRealm.allObjects *().改用DynamicRealm.where(className).findAll *().
DynamicRealm.allObjects*(). Use DynamicRealm.where(className).findAll*() instead.
DynamicRealm.distinct *().改用DynamicRealm.where(className).distinct *().
DynamicRealm.distinct*(). Use DynamicRealm.where(className).distinct*() instead.
Realm.allObjectsSorted(字段,排序,字段,排序,字段,排序).改用RealmQuery.findAllSorted(field [],sort [])`.
Realm.allObjectsSorted(field, sort, field, sort, field, sort). Use RealmQuery.findAllSorted(field[], sort[])` instead.
RealmQuery.findAllSorted(字段,排序,字段,排序,字段,排序).改用RealmQuery.findAllSorted(field [],sort [])`.
RealmQuery.findAllSorted(field, sort, field, sort, field, sort). Use RealmQuery.findAllSorted(field[], sort[])` instead.
RealmQuery.findAllSortedAsync(字段,排序,字段,排序,字段,排序).改用RealmQuery.findAllSortedAsync(field [],sort [])`.
RealmQuery.findAllSortedAsync(field, sort, field, sort, field, sort). Use RealmQuery.findAllSortedAsync(field[], sort[])` instead.
RealmConfiguration.setModules().请改用RealmConfiguration.modules().
RealmConfiguration.setModules(). Use RealmConfiguration.modules() instead.
Realm.refresh()和DynamicRealm.refresh().改用Realm.waitForChange()/stopWaitForChange()或DynamicRealm.waitForChange()/stopWaitForChange().
Realm.refresh() and DynamicRealm.refresh(). Use Realm.waitForChange()/stopWaitForChange() or DynamicRealm.waitForChange()/stopWaitForChange() instead.
waitForChange()
并没有真正起作用,因为人们打算使用它,因此这是1.1.1至3.1的解决方法. 4 不过,仅应在后台线程上使用. refresh()
将在3.2.0中重新添加.
waitForChange()
doesn't really work as people would intend to use it, so here's a workaround for 1.1.1 to 3.1.4 though, should be used only on background threads. refresh()
will be re-added in 3.2.0.
此外,在某些时候已删除了Realm.getInstance(Context)
,请改用Realm.getInstance(new RealmConfiguration.Builder(Context).build())
.
Also, at some point Realm.getInstance(Context)
was removed, use Realm.getInstance(new RealmConfiguration.Builder(Context).build())
instead.
在那之后,出现了1.0.0,所以就差不多了.
After that, 1.0.0 came, so it's pretty much just that.
顺便说一句,在1.1.0中,添加了insertOrUpdate()
,它比copyToRealmOrUpdate()
快,并且不返回代理.
By the way, in 1.1.0, insertOrUpdate()
was added which is faster than copyToRealmOrUpdate()
, and doesn't return a proxy.
2.0.2 :
-
主键在托管对象上是不变的,一旦设置,就无法更改,如果尝试,它将引发异常.另外,如果使用
createObject()
创建对象,请使用realm.createObject(clazz, primaryKeyValue)
.
您必须在某个时候致电Realm.init(Context)
.
You must call Realm.init(Context)
at some point.
配置生成器不再接收上下文.
Configuration Builder no longer receives Context.
armeabi
. (仅适用于v7a和其他版本)
armeabi
is no longer supported. (only v7a and the others)
3.0.0之前没有重大更改,但有大量错误修正.
No breaking changes until 3.0.0, but a ton of bugfixes.
3.0.0:
RealmResults会不断自动更新.当前线程上的任何可能影响RealmResults顺序或元素的事务都将立即更改RealmResults,而不是在下一个事件循环中更改它.标准的RealmResults.iterator()将继续正常运行,这意味着您仍然可以删除或修改元素,而不会影响迭代器.对于简单的for循环,情况并非如此.在某些情况下,简单的for循环不起作用( https://realm.io/docs/java/3.0.0/api/io/realm/OrderedRealmCollection.html#loops ),并且必须使用新的createSnapshot()方法.
RealmResults is auto-updated continuously. Any transaction on the current thread which may have an impact on the order or elements of the RealmResults will change the RealmResults immediately instead of change it in the next event loop. The standard RealmResults.iterator() will continue to work as normal, which means that you can still delete or modify elements without impacting the iterator. The same is not true for simple for-loops. In some cases a simple for-loop will not work (https://realm.io/docs/java/3.0.0/api/io/realm/OrderedRealmCollection.html#loops), and you must use the new createSnapshot() method.
RealmChangeListener.使用RealmObject.isValid()检查此状态(#3138). RealmObject.asObservable()现在将在删除对象时发出该对象.使用RealmObject.isValid()检查此状态(#3138).
RealmChangeListener on RealmObject will now also be triggered when the object is deleted. Use RealmObject.isValid() to check this state(#3138). RealmObject.asObservable() will now emit the object when it is deleted. Use RealmObject.isValid() to check this state (#3138).
删除了不赞成使用的类Logger和AndroidLogger(#4050).
Removed deprecated classes Logger and AndroidLogger (#4050).
由于与Realm ObjectStore Results集成,RealmResults
在交易中又有效,就像在0.88.3及更低版本中一样.
Due to the Realm ObjectStore Results integration, RealmResults
is live again in transactions, just like back in 0.88.3 and before.
因此simple for loops
(用for(int i = 0; ...
编制索引)很容易损坏- 这意味着您要么需要反向迭代它们,要么首先创建快照集合.
So simple for loops
(indexing with for(int i = 0; ...
) is prone to break - meaning you either need to reverse iterate them, or create a snapshot collection first.
OrderedRealmCollection<Thing> snapshot = results.createSnapshot();
for(int i = 0; i < snapshot.size(); i++) { ...
此外,RealmObject
更改侦听器现在也会在删除时发出,您需要在更改侦听器中检查isValid()
.这样,如果在后台删除了对象,则可以更新UI.
Also, RealmObject
change listener will now also emit on deletion, you need to check for isValid()
in the change listener. This is so that you can update the UI if the object has been deleted in the background.
3.1.0:
这里什么也没做,但是值得一提.
Nothing to do here, but it's worth a mention.
3.2.0-3.2.1:
除了update proguard之外,这里什么都不做,因为这里引入了一个错误.添加了proguard部分.
Nothing to do here, except update proguard, because there was a bug introduced here. Added proguard section.
3.3.0:(和3.3.1)
这里无所事事,该错误已修复,该错误导致了3.2.0版中的Proguard问题.
Nothing to do here, the bug was fixed which caused the Proguard problem in 3.2.0.
3.4.0:
这里无事可做,尽管值得研究新的用于逆关系的@LinkingObjects
API.
Nothing to do here, although it's worth looking at the new @LinkingObjects
API for inverse relationships.
实际上,建议将双向链接替换为单向链接+逆向关系.
In fact, it is recommended to replace bi-directional links with uni-directional link + inverse relationship.
3.5.0:
如果给定的RealmModule不包括所有必需的模型类(#3398),则将引发IllegalStateException.
An IllegalStateException will be thrown if the given RealmModule doesn't include all required model classes (#3398).
如果您未在modules()
中指定所有RealmObject(如果使用多个模块而不是默认模块,例如来自库项目的RealmObject),则需要确保您实际提供了所有RealmObject是模块中架构的一部分.
If you haven't specified all RealmObjects in the modules()
(in case you use multiple modules instead of just the default, for example RealmObjects from a library project), then you need to make sure you actually provide all RealmObjects that are part of the schema in your modules.
以前,即使它们不在模块中,它也会以静默方式添加它们,现在情况并非如此.
Previously it silently added them even if they were not in the modules, now that is not the case.
4.0.0:
内部文件格式已升级.打开旧的领域 会自动升级文件,但是较旧版本的Realm会 不再能够读取文件.
The internal file format has been upgraded. Opening an older Realm will upgrade the file automatically, but older versions of Realm will no longer be able to read the file.
[ObjectServer]将协议版本更新为22,仅兼容 使用Realm对象服务器> = 2.0.0.
[ObjectServer] Updated protocol version to 22 which is only compatible with Realm Object Server >= 2.0.0.
[ObjectServer]已过时,已删除 API SyncUser.retrieveUser()和SyncUser.retrieveUserAsync().使用 改为SyncUser.retrieveInfoForUser()和retrieveInfoForUserAsync().
[ObjectServer] Removed deprecated APIs SyncUser.retrieveUser() and SyncUser.retrieveUserAsync(). Use SyncUser.retrieveInfoForUser() and retrieveInfoForUserAsync() instead.
[ObjectServer] SyncUser.Callback现在接受通用参数 指示调用onSuccess时返回的对象的类型.
[ObjectServer] SyncUser.Callback now accepts a generic parameter indicating type of object returned when onSuccess is called.
[ObjectServer]重命名为SyncUser.getAccessToken到 SyncUser.getRefreshToken.
[ObjectServer] Renamed SyncUser.getAccessToken to SyncUser.getRefreshToken.
[ObjectServer]删除了不推荐使用的API SyncUser.getManagementRealm().
[ObjectServer] Removed deprecated API SyncUser.getManagementRealm().
在已排序的对象上调用distinct() RealmResults不再清除定义的任何排序(#3503).
Calling distinct() on a sorted RealmResults no longer clears any sorting defined (#3503).
放松 RealmList,RealmQuery,RealmResults, RealmCollection,OrderedRealmCollection和 OrderedRealmCollectionSnapshot.
Relaxed upper bound of type parameter of RealmList, RealmQuery, RealmResults, RealmCollection, OrderedRealmCollection and OrderedRealmCollectionSnapshot.
Realm已升级了对RxJava1的支持 到RxJava2(#3497)Realm.asObservable()已重命名为 Realm.asFlowable(). RealmList.asObservable()已重命名为 RealmList.asFlowable(). RealmResults.asObservable()已重命名 到RealmResults.asFlowable(). RealmObject.asObservable()已被 重命名为RealmObject.asFlowable(). RxObservableFactory现在返回 RxJava2类型而不是RxJava1类型.
Realm has upgraded its RxJava1 support to RxJava2 (#3497) Realm.asObservable() has been renamed to Realm.asFlowable(). RealmList.asObservable() has been renamed to RealmList.asFlowable(). RealmResults.asObservable() has been renamed to RealmResults.asFlowable(). RealmObject.asObservable() has been renamed to RealmObject.asFlowable(). RxObservableFactory now return RxJava2 types instead of RxJava1 types.
已删除不推荐使用的API RealmSchema.close()和RealmObjectSchema.close().那些不必 被称为.
Removed deprecated APIs RealmSchema.close() and RealmObjectSchema.close(). Those don't have to be called anymore.
已删除不推荐使用的API RealmResults.removeChangeListeners().使用 改为使用RealmResults.removeAllChangeListeners().
Removed deprecated API RealmResults.removeChangeListeners(). Use RealmResults.removeAllChangeListeners() instead.
已删除,已弃用 API RealmObject.removeChangeListeners().使用 改为使用RealmObject.removeAllChangeListeners().
Removed deprecated API RealmObject.removeChangeListeners(). Use RealmObject.removeAllChangeListeners() instead.
已删除 来自的UNSUPPORTED_TABLE,UNSUPPORTED_MIXED和UNSUPPORTED_DATE RealmFieldType.
Removed UNSUPPORTED_TABLE, UNSUPPORTED_MIXED and UNSUPPORTED_DATE from RealmFieldType.
已删除不推荐使用的API RealmResults.distinct()/RealmResults.distinctAsync().使用 代替RealmQuery.distinct()/RealmQuery.distinctAsync().
Removed deprecated API RealmResults.distinct()/RealmResults.distinctAsync(). Use RealmQuery.distinct()/RealmQuery.distinctAsync() instead.
RealmQuery.createQuery(Realm,Class), RealmQuery.createDynamicQuery(DynamicRealm,String), RealmQuery.createQueryFromResult(RealmResults)和 RealmQuery.createQueryFromList(RealmList)已被删除.使用 Realm.where(Class),DynamicRealm.where(String),RealmResults.where() 和RealmList.where()代替.
RealmQuery.createQuery(Realm, Class), RealmQuery.createDynamicQuery(DynamicRealm, String), RealmQuery.createQueryFromResult(RealmResults) and RealmQuery.createQueryFromList(RealmList) have been removed. Use Realm.where(Class), DynamicRealm.where(String), RealmResults.where() and RealmList.where() instead.
因此Rx1支持被Rx2支持取代,并且removeChangeListeners()
重命名为removeAllChangeListeners()
.
So Rx1 support was replaced with Rx2 support, and removeChangeListeners()
was renamed to removeAllChangeListeners()
.
大多数其他情况仅影响同步领域,从这一点出发,可以将RealmList<String>
,RealmList<Date>
和RealmList<Integer>
用作Realm模式的一部分.尚不支持查询它们,并且create*FromJson
方法未填写它们.
Most other things only affect sync Realms, and from this point it is possible to use RealmList<String>
, RealmList<Date>
, and RealmList<Integer>
as part of the Realm schema. Querying them is not yet supported, and they are not filled out by create*FromJson
methods.
4.3.1:
RealmQuery.findAllSorted()和RealmQuery.findAllSortedAsync() 支持谓词RealmQuery.sort().findAll()的变体.
RealmQuery.findAllSorted() and RealmQuery.findAllSortedAsync() variants in favor of predicate RealmQuery.sort().findAll().
支持RealmQuery.distinct()和RealmQuery.distinctAsync()变体 谓词RealmQuery.distinctValues().findAll()
RealmQuery.distinct() and RealmQuery.distinctAsync() variants in favor of predicate RealmQuery.distinctValues().findAll()
您现在可以执行
realm.where(Blah.class)
.distinctValues("something") // subject to change to `distinct()`
.sort("something") // hopefully will change to `sorted()`? // nope, it's `sort`
.findAll();
5.0.0:
删除了先前不推荐使用的RealmQuery.findAllSorted(),RealmQuery.findAllSortedAsync()RealmQuery.distinct()和RealmQuery.distinctAsync()`.
Removed previously deprecated RealmQuery.findAllSorted(), RealmQuery.findAllSortedAsync() RealmQuery.distinct() andRealmQuery.distinctAsync()`.
OrderedRealmCollectionChangeListener.onChange()中的OrderedCollectionChangeSet参数不再可以为空.改用changeSet.getState()(#5619).
The OrderedCollectionChangeSet parameter in OrderedRealmCollectionChangeListener.onChange() is no longer nullable. Use changeSet.getState() instead (#5619).
所以这意味着realm.where(...).findAllSorted("field")
应该是realm.where(...).sort("field").findAll()
.
还出现了OrderedRealmCollectionChangeListener
用于发送null
作为初始更改集的情况,现在已经不复存在了,并且== null
应该替换为.getState() == OrderedCollectionChangeSet.State.INITIAL
.这也意味着您需要在Realm 5.0+中使用realm-android-adapters 3.0.0
或更高版本.
Also comes that OrderedRealmCollectionChangeListener
used to send null
as the initial change set, now that is no longer the case, and == null
should be replaced with .getState() == OrderedCollectionChangeSet.State.INITIAL
. This also means that you need to use realm-android-adapters 3.0.0
or newer with Realm 5.0+.
此外,如果您依赖__RealmProxy
类的名称:它们以其完全限定的名称来命名,包括像my_package_SomeObjectRealmProxy
这样的包.
Also, if you relied on the names of __RealmProxy
classes: they are named by their fully qualified name, including packages, like my_package_SomeObjectRealmProxy
.
程序规则
#realm older than 0.84.1
-keepnames public class * extends io.realm.RealmObject
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.** { *; }
-dontwarn javax.**
-dontwarn io.realm.**
#realm 0.84.1+ and older than 1.0.0
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class *
-dontwarn javax.**
-dontwarn io.realm.**
#realm 0.89.0+ and older than 1.0.0
-keep class io.realm.RealmCollection
-keep class io.realm.OrderedRealmCollection
#realm 3.2.0 and 3.2.1
-keepnames public class * extends io.realm.RealmObject
这篇关于在Android项目中升级领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!