A standard approach is a VO dirty flag that is set in every VO mutator method.
A change is applied to the EB by calling the EB setData(VO) method, thereby
avoiding the overhead of multiple remote EB set calls.
A more elaborate approach is to keep a StateManager field in each VO, e.g.
VO {
private StateManager stateMgr;
...
}
public class StateManager {
byte[] state;
void setLoaded(int index) { ... }
void setDirty(int index) { ... }
boolean isLoaded(int index) { ... }
boolean isDirty(int index) { ... }
}
where state is a bit vector of flags xx|xx|xx|... indicating whether fields
have been loaded and/or changed.
Each VO mutator method modifies a field flag, e.g.:
private static final int NAME_FLD_NDX = 1;
setName(String name) {
this.name = name;
stateMgr.setDirty(NAME_FLD_NDX);
}
It is then straight-forward to detect which VOs have changed and which fields
should be modified. This is useful for more complex VO data models with
collection or dependent object fields.
Steve Muench wrote:
> I'm building a session bean facade for my
> entity beans, and need to return a collection
> of updateable "rows" of data showing only
> some of the attributes from some of my
> underlying entities for the client interface.
> In fact it's kind of a "join" of the data
> from two underlying entity beans that needs
> to be returned.
>
> When using an approach to return a collection
> of hand-coded struct-like value objects, what is the
> best practice technique to allow the client of
> my session bean to make updates to any or all
> of the attributes being passed in the value object?
>
> I read conflicting reports in books that alternate
> between suggesting that:
>
> -> Value objects should be immutable to not
> give the false impression that calling
> setSalary() -- for example -- actually
> goes and sets the underlying entity bean.
>
> and
>
> -> Value objects should have get/set methods
> (i.e. be mutable). In fact some books suggest that
> my entity bean inherit from the value object.
>
> In any event, do I need to provide additional
> remote methods on my session bean facade which
> accept one of these hand-coded struct-like value objects...
>
> updateEmployee( empValueObject );
> updateEmployees( Collection ); // Of empValueObject's
>
> and then inside the implementation of this bean method
> write code that transfers the values back into the
> appropriate underlying entity bean inside the middle tier?
>
> If the client passes me a collection of these, what is a
> best-practice technique of determining which of the
> value objects have been changed by the client? or is it
> the client's responsibility to only pass me one's that
> have changed or been added?
>
> Thanks in advance,
>
> Steve
>
--
Fred Loney
Enterprise Java Consultant
Spirited Software, Inc.
[EMAIL PROTECTED]
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".