Can we change Query in NSFetchedRequestController? - objective-c

Some says we cannot change the request object. Some says we can change the query. Some says we cannot change the predicate.
How do you change the query if you do not change the predicate?
That's kind of strange right.

It's not an SQL query, it's fetch. A query is a SQL specific concept while a fetch is a Core Data concept that works with any type of Core Data store.
You can change the fetchRequest value of a NSFetchedResultsController but its somewhat involved. From the docs:
Modifying the Fetch Request
You cannot simply change the fetch request
to modify the results. If you want to change the fetch request, you
must:
(1) If you are using a cache, delete it (using deleteCacheWithName:).
Typically you should not use a cache if you are changing the fetch
request.
(2) Change the fetch request.
(3) Invoke performFetch:.
It is the cache that causes the problems with modifying the fetch request.
You can also change the predicate of a NSFetchRequest object but if you use that fetch with a fetched results controller, you have to perform the above steps.
The problems comes when the cached objects are not the same set returned by the new fetch request. Often it is simpler and cleaner to just create a new fetch request object or a new fetched results controller object.
You do have to freeze the tableview with beginUpdate while all this is going on otherwise the tableview's rows and sections will come out of sync with the data causing a crash.

Related

Update single attribute with Restkit

I want to update ONE SINGLE attribute on the Core Data Object and send the change to the server using RestKit.
I see that ResKit is always sending Object with ALL attributes and not only with the changed ones. That makes my app slow(er).
I also see that update response from server should return whole object back to the RestKit which is again slower that it could be (All I need is success/failure response)
Is there elegant solution for this? (I am pretty new to the RestKit)
You can create a request descriptor on-the-fly which includes only the attributes you want to send, you would either simply need to use a mapping operation yourself or be sure to only run one such operation at a time and call removeRequestDescriptor: on the object manager (this could be tricky for you to manage). The alternate is to put the data to upload into a dictionary and upload that, but that isn't ideal.
For the response, the mapping says what to map but it doesn't all have to be there, RestKit will take whatever it can and map that.

Play framework, fake formdata for batch call

I'm trying to implement a batch call method for inserting a lot of objects at once.
The thing is, the method for individual inserts gets a Form for the insert, which is bound from the Request.
My idea here is to retrieve a json array, with all the data for the required inserts.
I would then loop over it and call the regular insert method for each one. But that means having to pass the data to the Form. But the Form gets data from seeing if there's data attached to the HTTP Request. But there isn't an HTTP Request.
Is there a way for me to do this without using a FakeRequest?

mvc4 passing data between paging action and views

i have an action which will invoke a service (not database)to get some data for display,and i want to do paging on these data.however,every time a second page is clicked,it will invoke this action and of course invoke the service again,actually when i click the first page link,it already generate the whole data including what the second page needs. i just want to invoke the service once and get all the data,and later when paging,i don't need to invoke the service again,how can i deal with that?hope someone could give me a hint~
There are several ways to address this. If it's practical and a limited amount of data, it's ok to return the entire data set in the first request.
If that's your case I would consider returning a pure JSON object when you load the page initially. You can then deserialize this into a JS object variable on the web page that you can perform your paging operations against. This is an example of client side paging where all the data exists client side.
Another approach is to do Ajax based paging where you request the data for the next page as needed. I would still recommend returning JSON in this scenario as well.
The two approaches differ in that the first one returns all the data upfront, whereas the second one only returns what you need to render any given page.

nsfetchrequestcontroller.request

Is it okay to change that thing if we are not using the cache anyway?
To repeat, we're not supposed to change the fetchrequestcontroller request only if we do not use the cache right?
If I am displaying a table based on user search and the search change, should I create a whole new fetchrequestcontroller?
The documentation states "You must not reuse the same fetched results controller for multiple queries unless you set the cacheName to nil". It also states you should delete the cache if modifying the fetch request. I often use two different caches depending on the application. You can read more about NSFetchedResultsController here and it's delegate here.

Load vs Get in Nhibernate

The master page in my web application does authentication and loads up the user entity using a Get.
After this whenever the user object is needed by the usercontrols or any other class I do a Load.
Normally nhibernate is supposed to load the object from cache or return the persistent loaded object whenever Load of called. But this is not the behavior shown by my web application. NHprof always shows the sql whenever Load is called. How do I verify the correct behavior of Load?
I use the S#arp architecture framework.
Actually, calling Load on an entity not marked as lazy causes immediate loading. That is because non-lazy entities are never proxied. In this case, it just acts the same way as Get.
If you use Get, then a hit to a database is made.
If you use Load, no hit to a database is made, but the object (User in your case) is created with 'lazy loading'. So when you check a property it knows that you want data so it hits the database with a query to get the data.
If you want to get an object from cache, you need to consider 2 options.
First level cache, is a cache that is in use in ONE session. So when you close a session or load the same object in a different session, you get additional hits.
Second level cache works accross all sessions. If one session gets the object, the other session gets it from cache.
So what you want is probably a second level cache.