greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

Added support for transient of properties. #103

Open mojtabakaviani opened 11 years ago

mojtabakaviani commented 11 years ago

please add support greendao core than can create transient properties. entity.addBooleanProperty("isSelected").transient();

yigit commented 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.

mojtabakaviani commented 11 years ago

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.

kierans commented 10 years ago

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.

xeridea commented 9 years ago

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.

mak0t0san commented 8 years ago

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.

michel-t-86 commented 8 years ago

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.

michel-t-86 commented 8 years ago

And id property field too. Those are irrelevant when you want multiple devices to sync with the same data.

michel-t-86 commented 8 years ago

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:

image

Ugly but it works.

Tried and tested.

niveuseverto commented 8 years ago

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...