Open mojtabakaviani opened 11 years ago
Transient for java serialization? I don't understand why you would want a transient & persistent field. Can you add more details on why you need this? If you are just trying to add a field, you can use keep sections
.
sometimes need add properties that just in model and not column of table. with keep sections every generate schema must witre properties again. with transient method say not column of table.
I think transient fields are a good idea as they allow flags or counters relating to how the state of the data has changed to be in the Entities without needing to worry about that state not being persisted.
In my case, I encrypt certain properties of my Entity. The first time the Entity is loaded from disk I want to decrypt those properties. The next time the Entity is accessed, due to caching the decryption does not need to be performed again. If I had a transient flag on the Entity I could mark when encryption/decryption needs to be performed.
Having a transient operator in the Generator is better than using Keep Sections.
As with many of GreenDao shortcomings, there is a workaround. I just made a small script to easily be able to replace the properties with transient versions after they have all been generated.
For our case, we need the id field to be transient because we are using GUIDs, since we have app/server syncing. Keep sections would not be possible.
I would actually like this as well. I have an entity that also gets serialized to JSON and sent up to a web server, but there are some fields that I don't want serialized in the JSON body. To prevent these fields from being serialized and sent up to the server, I need to mark them as transient.
Same for me too. For example, a password field would be marked transient so that for example, Gson doesn't serialize it when sent over a network.
And id property field too. Those are irrelevant when you want multiple devices to sync with the same data.
Actually you can achieve this by doing something like this:
Entity user = schema.addEntity("User"); user.addStringProperty("Password").codeBeforeField("transient");
You end up with something like this:
Ugly but it works.
Tried and tested.
One more thing I think should be implemented:
transient state to be added into relation properties, as sometimes object contains link to parent and parent contains (of course) link to childrens...
please add support greendao core than can create transient properties. entity.addBooleanProperty("isSelected").transient();