realm

How do i prevent duplicates in RealmSwift List?

∥☆過路亽.° 提交于 2019-12-22 05:24:21
问题 How do I prevent adding duplicates to a list in RealmSwift ? I have my User as a realm object, but the real data source is a server (simply caching the user locally with Realm). When I get the current user data from my server, i want to make sure that my user stored in realm has all the playlists coming from the server (and that their in sync wrt list of tracks and etc.). I'm worried that if i loop over those lists from the server, appending to myUser.playlists , that I may end up adding the

how to convert RealmSwift List to Results?

雨燕双飞 提交于 2019-12-22 04:26:23
问题 I am using a Realm List/Results as my dataSource for a UITableView . At some point I assign a list to it. like: var dataSource:List<SomeObject>! // Or >> Results<SomeObject>! let aRealmObject = realm.objectForPrimaryKey(SomeObject.self, key: objectId) dataSource = aRealmObject.someList // dataSource should be List Then I have a filter on this list If the user changed the filter dates, I do like this: dataSource = dataSource.filter("FILTER THE DATES",newDates) // dataSource should be Results

How to get Number of Records using LIMIT Query in Realm Database android

末鹿安然 提交于 2019-12-22 01:05:26
问题 I have Implemented my new project with Realm Database Plugin . I have a functionality of Pagination with Number of Record as 20. So How can I fetch 20 Record using Realm Query . I searched, but did not get any solution. 回答1: I wrote an article on Realm where I specifically mention that Common mistake : attempting to paginate a RealmResults<T> or “limit the number of results in it” for no valid reason whatsoever I’ve seen people on SO attempting to paginate a RealmResults, or “how do I do a

Shiro-菜鸟实战篇-缓存管理

我只是一个虾纸丫 提交于 2019-12-22 00:43:55
先看下面的测试类及测试结果 @Test public void bufferTest ( ) { Subject subject = ShiroUtil . login ( "zhangsan" , "123456" ) ; subject . isPermitted ( "sys:user:list" ) ; subject . isPermitted ( "sys:user:list" ) ; subject . isPermitted ( "sys:user:list" ) ; } } 我们会发现授权完成运行了3次,这并不是我们想看到的。 为什么要使用缓存? 在没有使用缓存的情况下,每发送一次请求都会调用一次doGetAuthorizationInfo方法来进行用户的授权操作,但是我们知道,一个用户具有的权限一般不会频繁的修改,也就是每次授权的内容都是一样的,所以我们希望在用户登录成功的第一次授权成功后将用户的权限保存在缓存中,下一次请求授权的话就直接从缓存中获取,这样效率会更高一些。 下面说几种缓存办法。 使用内置缓存 在shiro系列文章第一篇我们就已经提及到了 CacheManager(缓存管理器) ,这是shiro封装好的内置缓存器,现在我们来使用一下它。 看下我们的自定义的工具类 其实只要创建一个缓存管理器,并放入我们的安全管理器中就可以了。

Fetch a single column from Realm Database (Android)

强颜欢笑 提交于 2019-12-21 21:52:58
问题 I'm a beginner in Realm. I have a table with 3 columns which named Id, Name, Email,Address . To get the data of Name column, we use a query like 'SELECT Name from table_name' for SQLite. If we using Realm in Android, then which method do we have to use for fetching the data of only one column? I searched alot on Google & documentation but to no avail. Could anyone help me? Update: What I am tried: RealmResults<User> results = query.findAll(); ArrayList<String> name = new Arraylist(); for(i=0;

Cant add new object to RealmList due to null object reference

我只是一个虾纸丫 提交于 2019-12-21 20:53:06
问题 I have to realm objects, one is a basic RealmObject with a two strings and a boolean, the other is just a RealmList for that object for easier access. When I try to get the list from my instance of the ContactBook and add a new object I get the attempt to invoke virtual method on a null object reference. However Im able to get the size of the contactBook, and the amount of contacts so those are not null. Class Where I try to add new objects public void viewSetup() { setContentView(R.layout

How to store [String] or [Int] in react-native realm

我只是一个虾纸丫 提交于 2019-12-21 20:18:33
问题 I've read online where in Android/iOS I should inherit from RealmObject and create my own RealmString to use as my objectType in a list. What's the approach in react-native? I can't find any code samples on how to handle this issue. Thanks 回答1: You can use the same strategy in react-native: var intObject = { name: 'intObject', properties: { value: 'int' } }; var intListObject = { name: 'intListObject', properties: { 'intList': { type: 'list', objectType: 'intObject' } } }; var realm = new

How to get item with max id?

蹲街弑〆低调 提交于 2019-12-21 20:11:20
问题 I'm tryig to get the ítem with max id using this query realm.objects(Entity).filter("@max.id").first It's throwing an error saying that can't parse query so it seems this is not the correct way to do it. How can I write this query on Realm for Swift? 回答1: Filters alone cannot do what you're after as they only consider a single top-level object at a time. Beyond that conceptual issue, there are a few issues with the code you posted: @"@max.id" is not a valid NSPredicate format string.

Realm Cocoa: finding multiple objects by PKs

99封情书 提交于 2019-12-21 19:20:00
问题 Long time lurker, first time asker. I'm using Realm Cocoa (from Realm.io) in a project and am struggling to perform searches by PKs. Let's say I have an entity called RLMFoo which has a primary key called bar . I also have a list of PKs, let's say stored in an array: NSArray *primaryKeys = @[@"bar1", @"bar2", @"bar3"] Is there any way to retrieve all entities of class RLMFoo from my realm in one single query? I've tried so far: Predicate with format: [RLMFoo objectsInRealm:realm withPredicate

【Shiro】- 认证授权过程源码分析

前提是你 提交于 2019-12-21 15:14:32
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> shiro: apahce的开源安全框架,因其强大、灵活的特点,则we在应用中经常使用,shiro认证和授权过程是分开的,下面从shiro的源码解析shiro的认证过程 subject.login(token); DelegatingSubject public void login(AuthenticationToken token) throws AuthenticationException { clearRunAsIdentitiesInternal(); Subject subject = securityManager.login(this, token); PrincipalCollection principals; String host = null; if (subject instanceof DelegatingSubject) { DelegatingSubject delegating = (DelegatingSubject) subject; //we have to do this in case there are assumed identities - we don't want to lose the 'real' principals: principals =