-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unmodifiable - Improved read only immutable entity beans / graphs #3570
base: master
Are you sure you want to change the base?
Conversation
…LazyLoad=true] Although this is ok, makes me think that another option is just to have query.setReadOnly(true) to mean ... readOnly + disableLazyLoad + error reading unloaded property or collection. As in, readOnly true without these extra things does not that good [as in the existing readOnly does not seem very good/safe/useful to use].
… existing use of IllegalStateException - Adds new exceptions UnloadedPropertyException and UnmodifiableEntityException - Change InterceptReadOnly to use these exception instead of IllegalStateException - Change collections BeanSet, BeanList, BeanMap from using IllegalStateException to UnsupportedOperationException [to bring these in line with JDK unmodifiable collections]
Add unmodified to DefaultOrmQuery query plan description Fix incorrect merge conflict
FYI @nedge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Rob, I took a short look on this PR.
I'm looking forward to this change.
We've always used a cumbersome combination of persistence-scope-query + readonly + cache etc.
I have to say that we also use the BeanCache.
I haven't looked at your PR in detail about what happens if data is partially present in the BeanCache and a partial bean is created and the missing data then has to be reloaded using lazy load
I would agree that. (if really necessary, we couldbadd a config flag for backward compatibility) But I think it still needs to be specified what should happen when caches are involved, as they already check the readOnly flag. QueryCache: Beans/IdLists in the queryCache should be always unmodifiable by default. (we use setUseQuerCache=true always together with setReadonly=true) It is also necessary to set the persistence-scope to QUERY when beans are put into the queryCache, otherwise we got memory leaks. So I have to pay attention always to use all 3 properties together correctly in my code. Therefore, I would appreciate it if setUseQuerCache(true) would set everything correctly (or maybe an other convenient method like BeanCache Imagine if I do the query This will put partial data to the bean cache. Next I do a What will we expect?
mutable types There are mutable types like Calendar or How do we handle this and protect from modification? I think there is not much we can do about this, which would be totally OK for me, if it is specified. Roland |
Noting that the freeze needs to occur after secondary queries have executed
Yes that makes sense. Yes I think we should migrate to setUseQuerCache(true) using unmodifiable implicitly.
Some we can freeze (and we do in this PR) and some we can't do anything about (like Calendar).
We need to figure this out but maybe we can't use the existing bean cache with unmodifiable. I have some thoughts around a new/different "bean cache" made of immutable beans (actually immutable graphs). My intention is to look at that first. |
Unmodifiable entities are:
Changes
Ugh
"Read Only" and "Unmodifiable" should probably be exactly the same thing/concept but read only existed before and so it slightly different [it does not include/imply disabled lazy loading + PersistenceContextScope.QUERY ]. Ideally we change query.setReadOnly(true) to be exactly the same as query.setUnmodifiable(true).