Well, the problem
can be looked at different way. First,
Castor architecture requires B to be loaded before it can be deleted. Second, it
is recommended that an identity should have no business meaning. The two
points together making that removing by id is very unlikely. In a prefect
world, you shouldn’t know the id beforehand anyway. Ok, in
real life, recommendation wasn’t always followed by the code you have no
control of. However,
lazy loading still saved many loading, especially in m-n relationship. In
which, many of
the collections will not be touched at all. On the
other hand, it is true that current Lazy collection load all ids at first. However,
it will change in the future. When it changed, removeById would make less
sense. After all,
RelationCollection is intended to be use as an instance of Collection, without assuming
user to cast it. Again, Castor
architecture requires B to be loaded before it can be deleted. The code in
RelationCollection didn’t show that, but it is true. RelationMap
might make sense. If you
attempt to do it, please also remember to do some test cases that base on the
current testing framework and can be run along with all other exist tests. Otherwise,
code will be kept in the mail archive and wait long long time until we would
have the time to review the code and write test cases for that. Thomas -----Original Message----- >From: Alexey A. Efimov
[mailto:[EMAIL PROTECTED]] >Sent: Wednesday, December 26, 2001 5:55
AM >To: [EMAIL PROTECTED] >Subject: [castor-dev] Why it is
RelationCollection? > >If I have two classes - A and B. A have a set of B (by
collection). >B depends on A. >Becose class B depends on A, I can't use OQL and db.load
per class B directly. But I have access to them via class A (a collection
field). >But this mean that I can only add and removeAll methods.
Other requered methods as removeById(Object id) getById(Object id) expected. >How I can remove item B from A collection by them id? Or
how I can get B by id? Now I must iterate all collection to find B item equals
to >specify id - and it break lazy loading conception, cos for
method next Castor load full item.' >Maybe need a RelationHashMap? Or RelationList? But why
Collection? >This method remove(Object o) from RelationCollection: > public boolean remove(Object o) { > Object id =
_molder.getIdentity( _tx, o ); > boolean changed
= false; > if (
_deleted.contains( id ) ) >
return false; > if (
_added.contains( id ) ) { >
_added.remove( id ); >
_changecount++; >
_size--; >
return true; > } else if (
_ids.contains( id ) ) { >
_deleted.add( id ); >
_changecount++; >
_size--; >
return true; > } > return false; > } >How u see - Object as is I needed only for retrive it ID
value. So method remove may be contain only id: > public boolean removeById(Object id) { > boolean changed
= false; > if (
_deleted.contains( id ) ) >
return false; > if (
_added.contains( id ) ) { >
_added.remove( id ); >
_changecount++; >
_size--; >
return true; > } else if (
_ids.contains( id ) ) { >
_deleted.add( id ); >
_changecount++; >
_size--; >
return true; > } > return false; > } > public boolean remove(Object o) { > Object id
= _molder.getIdentity( _tx, o ); > return
removeById(id); > } >Resume - Conception with depends objects in Castor now
unusible without id's access method to child objects. >Alexey Efimov - Software Engineer >Sputnik Labs >1st Kolobovsky per., 6/3 >Moscow, 103051, Russia >Phone: +7 (095) 725 5444 >Direct: +7 (501) 401 3217 >Fax: +7 (095) 725 5443 >E-Mail: mailto:[EMAIL PROTECTED]
> > |
Title: Why it is RelationCollection?
- [castor-dev] Why it is RelationCollection? Alexey A. Efimov
- Re: [castor-dev] Why it is RelationCollection? Thomas Yip
- Re: [castor-dev] Why it is RelationCollection? Alexey A. Efimov