HashMap serialization in Realm (mobile database) - dictionary

We would like to use Realm mobile database, but couldn't find any reference about how do you read and write a HashMap (Map/Dictionary in Apple languages) or any other Collection type field of your RealmObject subclass?
Is there a way to make Realm handle these fields like primitive type fields for serialization?

There's no direct support for anything but List in Realm right now. One workaround is to define your own tuple as a model class and operate on that instead. You can specify your key to be a primary key so that will ensure uniqueness.

Related

Change lookup call of field

I have EntityField and UsersField(ListBox). When I change Entity to USERS, I need to pass: UsersLookupCall, when I change Entity to Projects, i need to pass ProjectUsersLookupCall to UsersField.
Also if that is possible, how to pass a parameter to that lookup call I am passing to another field?
Thanks
You can exchange the lookup-call on a (Smart-)Field simply by calling the setLookupCall(ILookupCall<T>) method on the field. However, since the value of the field is strongly typed and the type of the lookup must match the type of the field you can only set lookup calls with the same type.
You find a lot of examples on how to react on value changes in the Scout Beginners Guide.
You can set additional parameters on the lookup call by implementing the execPrepareLookup(ILookupCall<T>) method. Note: there are also specialized execPrepare* methods for the three lookup modes: key, text and rec.

map<text, object> Cassandra, is it possible

I want to create a table with a map accepting string as key and any object as value (boolean, string, int, timestamp).
Is it possible ?
Thanks
Currently, no, keys and values in a map must be of a known CQL type. There is a request for "dynamic types", but nobody has worked on it so far.
Any object isn't possible. You can create user defined types but this type isn't dynamic: https://docs.datastax.com/en/cql/3.1/cql/cql_reference/cqlRefcreateType.html
You can parse your object as json and this json as string. You can insert this string in a text column.
There is no native support for dynamic types.
So you got two work arounds.
Handle it in your application logic.
Create map<text, blob> or map<text, text>
Create JSON or ByteBuffer in your application logic. JSON is better as it is language independent, but can consume more storage.
Create UDT with all the possible types and store it accordingly.
If you have very little variety, then you should choose 2nd option, else 1 should be better. Using 1st option you can store complex objects also.
Hope it helps!

Getting timestamp from Objecify entity?

Is it possible to obtain the timestamp that is used for optimistic concurrency control from an Objectify entity (or a lower-level part of the Google Datastore infrastructure) and if so, how?
It should be possible to obtain the version timestamp by specifying a field like this in your entity POJO:
#IgnoreSave long __version__;
The version # is found in the Entity properties with that key. If you're looking for official documentation, check javadocs (and source code) for Entity.VERSION_RESERVED_PROPERTY and Entities.getVersionProperty(Entity)
Why This Works
When you load a low-level Entity, it comes pre-populated with a synthetic property named __version__. Simply by adding a field to your Objectify POJO with that name, Objectify will load it out of the Entity. Use #IgnoreSave so that the value is only loaded, never saved.

How to use inner join of persistence js

I am new programmer student, now i develop mobile app with phonegap. So I use sqlite and persistence js.but I don't know how to write "inner join" in persistence js function. Hope all of you help me.
Take a look at documentation:
https://github.com/zefhemel/persistencejs
Some text from it:
The methods to define relationships to other entities:
EntityName.hasMany(property, Entity, inverseProperty)
defines a 1:N or N:M relationship (depending on the inverse property).
EntityName.hasOne(property, Entity)
defines a 1:1 or N:1 relationship.
If an object has a hasOne relationship to another which has not yet been fetched from the database (e.g. when prefetch wasn't used), you can fetch in manually using fetch. When the property object is retrieved the callback function is invoked with the result, the result is also cached in the entity object itself.
obj.fetch(prop, callback)

Get the entity context in a Data Transformer

I have a problem concerning the usage of a DataTransformer.
Basically, I am developing a translation tool for my application whose goal is to be as generic as possible.
For that, I chose to follow that model : Database modeling for international and multilingual purposes
So, in different entities in my application, I have translatable attributes that simply are references to i18n elements. Then, this i18n ID is referenced in Translation table entries, that handle translation strings.
I succeed handling my translation interface, but I now have a problem with my forms : Indeed, I want some of my entities to be created/updated via forms. The problem is that I don't want the user to set a i18n ID for the translatable fields, of course, but a text, so that it can be handled by my application to either update or create the related translation in database.
I thought then that creating a DataTransformer could be a good idea, so that I can get the related translation string from the i18nID that is in my Entity entry (for that way, no problem). But my problem here is for the opposite way :
How can I deal with creating/updating i18n entries in my reverseTransform() method without knowing the entity values context?
Is there any way to get the previous entity values so that I could get the i18 ID that is stored originally in my entity? I understand that a Data Transformer is theorically totally independent from my forms and my entities, but I'm totally blocked about how to handle this case.
Indeed, when I save my entity with my translated string, I have no way to know the entity context in my reverseTransform() method, that would have permitted me to get the i18nID of the entity and to update it.
I just have the string that typed the user, but I can't do anything with that, because I can't know if it is an update or not since I don't have access to my entities.
Do you have any clue to do that? Is trying to use a DataTransformer to perform this a bad idea?
Thank you !

Resources