When calling CRUD check if "parent" exists with read or join?
All my entities can not be deleted - only deactivated, so they don't appear in any read methods (SELECT ... WHERE active=TRUE)
.
Now I have some 1:M tables on this entities on which all CRUD operations can be executed.
What is more efficient or has better performance?
My first solution: To add to all CRUD operations:
UPDATE ... JOIN entity e ... WHERE e.active=TRUE
My second solution: Before all CRUD operations check if entity is active:
if (getEntity(someId) != null) {
//do some CRUD
}
In getEntity
there's just SELECT * FROM entity WHERE id=? AND active=TRUE
.
Or any other solu开发者_运维百科tion, recommendation,...?
Second, plus an active second level cache ;) Chance is that the object already is in memory. Chance is acutally pretty high.
I would move all deactivated entities to a separate table and not worry about the entity being active.
精彩评论