Hi Michael,

On Oct 11, 2011, at 4:46 PM, Starch, Michael D (388L) wrote:

> Chris et all,
> 
> Do you see any problems overriding the default equals, and hashCode methods 
> in the Product class (checking by memory address/reference) to something that 
> checks to see if the products logically represent the same thing (same id, 
> name, etc)?
> 
> My issue is the following, I receive data back from the database, with 
> multiple lines representing a single product (this is a database thing, and 
> the desired behavior).

Can you explain what you mean by "multiple lines". Do you mean multiple rows 
present in a record set?

>  Thus if I iterate across the results, I will get multiple Product objects 
> that represent one real Product (and contain equivalent member variables).

Sure, so there's a way to *construct* a Product from a ResultSet, which may 
involve iterating over the ResultSet in different ways and by 
constructing intermediate objects, etc., See the way I do this in 
DbStructFactory in o.a.oodt.cas.filemgr.util. That "SerDe" 
(serializer-deserializer) 
works specifically with the DataSourceCatalog, but you could imagine adding a 
ColumnBasedDbStructFactory that equivalently 
unpackages a logical Product object from a SQL result set in the Column 
oriented schema.

>  In essence they are the same "Product".  I can write cleaner, faster, code 
> to combine the results, if I can test them for equality and hash them 
> directly, without first pulling out the productName, or Id.

This is possible, but I think more effort and complex than creating 
construction/factory objects with static methods to build up a Product object. 
Let me know what you think of the DbStructFactory and then we can iterate.

> 
> This will be a problem if there is some code that expects two "Products" that 
> have identical member variables to fail the equality test if they are 
> distinct objects.

Precisely, which is why overriding those methods might not be ideal.

Cheers,
Chris

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Chris Mattmann, Ph.D.
Senior Computer Scientist
NASA Jet Propulsion Laboratory Pasadena, CA 91109 USA
Office: 171-266B, Mailstop: 171-246
Email: [email protected]
WWW:   http://sunset.usc.edu/~mattmann/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adjunct Assistant Professor, Computer Science Department
University of Southern California, Los Angeles, CA 90089 USA
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Reply via email to