Update a JSON-backeed cache object in RoboSpice? - robospice

Is it possible to update the cached json of an already cached object? If so, how? Could I update the corresponding POJO and then "persist" it manullly somehow? I cannot find reference to any methods in Robospice that would allow one to do that. Thanks in advance!

I read somewhere that if you use the Jackson Persister from the jackson2springandroidspiceservice, you cannot as the cache is read-only but I was able to change the persisted object stored using the ORMlite module and RS returned the changed object.

Related

Detect specific change during Eloquent Updated event

Using Eloquent Events/Observers, is it possible to detect which properties were updated within an Update event? Or, can you gain access to the previous/new values to do a comparison?
I'm finding the only solution is to manually fire events by detecting the specific field exists in the validated request data, in the controller.
Yes, absolutely. You can use the Model class's existing methods to gain access to various sets of data. The following methods should be helpful for what you want to do.
getChanges()
Get the attributes that were changed. (and saved)
$model->getChanges()
getOriginal()
Get the model's original attribute values.
$model->getOriginal()
getDirty()
Get the attributes that have been changed since last sync. (but not saved yet)
$model->getDirty()

Retrieving Affected Object from serialized data

Am working on finding the differences between two Json objects and storing the respective Diff in Json format(using Javers), so that can be retrieve later and presented to the user in a meaningful manner. Now, the challenge is, the Affected Object(where the change has happened) is not being serialized during serialization.
I understand that it is not possible to retrieve the domain objects from Diff.
Could see that the "affectedCdo" has been marked as transient not allowing to serialize it.
Any other alternative for doing this?
Thanks,
Ravi.
Restoring orginal domain objects from persisted snapshots will be possible when we implemen the shadows feature in JaVers. We are working on it. https://github.com/javers/javers/issues/133

What does Spring Data Couchbase use the _class field for?

I'm guessing that the type is used for CRUD operations. Is it used for anything else besides that? I'm wondering what impact there could be from configuring how it gets populated.
The _class field is written to allow polymorphic properties in your domain model. See this sample:
class Wrapper {
Object inner;
}
Wrapper wrapper = new Wrapper();
wrapper.inner = new Foo();
couchbaseOperations.save(wrapper);
You see how the field inner will get Foo serialized and persisted. On the reading side of things we now have to find out which type to create an object of and the type information in Wrapper is not enough to do so as it only states Object.
That's why Spring Data object mapping persists an additional field (name customizable but defaulting to _class) to store that information to be able to inspect the source document, derive a type from the value written for that field and eventually map that document back to that particular type.
The Spring Data Couchbase reference documentation doesn't really document it, you can find information about the way this works in the docs for the MongoDB module. I've also created a ticket for Spring Data Couchbase to improve on the docs for that.

When can I access the data of my NSDocument during the initialization?

I need to instantiate some properties with the content of the saved document. Since theses properties are used by my interface, I would like to instantiate them before the NIB is loaded.
At which point of my initialization can I access the data of the loaded document ?
If possible, I would like to access it not from the initFromURL method. Indeed, when I create a document, I also create this data. So, if it is possible, I would like to put the instanciation at only one point, that will work for both the creation and the opening of a document.
So, is there an accessible point after the initFromURL and initWithType methods but before the windowControllerDidLoadNib.
Thanks !
Easy !
-windowControllerWillLoadNib

How to make an attribute transient (not marshalled)

I'm using Ruby 1.8.6 and have a class (not an ActiveRecord class) that I want to cache using memcache-client, which serializes it with Marshal.dump before storing it in the cache. However, it has an instance variable (which does refer to an ActiveRecord class) that I don't want to serialize, as I don't want multiple objects running around corresponding to the same database row. Instead, I want to set the attribute to refer to the appropriate object (which I already have a reference to) after the serialized object is loaded from the cache and reconstructed.
What's the easiest way to prevent only one attribute from being marshalled?
(I'm aware of this question, but the given answer appears to apply only to ActiveRecord classes.)
from http://www.ruby-doc.org/core-1.9.3/Marshal.html
When dumping an object the method marshal_dump will be called.
marshal_dump must return a result containing the information necessary
for marshal_load to reconstitute the object. The result can be any
object.
When loading an object dumped using marshal_dump the object is first
allocated then marshal_load is called with the result from
marshal_dump. marshal_load must recreate the object from the
information in the result.
so the question you are linking to also applies to you. just override those two methods and you should be fine.

Resources