• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to implement equals for DB model?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to represent a relational database and its tables, so I have a class representing a database, and a class representating a table.

In the database class, there is a Set, containing Table objects, as I know that no two tables can have the same name within my database (ignoring more complex database structures for now...)

I can think of two equals() implementations that seem valid. I need to return true if two tables have the same name, so as to ensure no duplicate names in my collection, so that's one. However, if I do that, two table objects will be equal even if they contain different attributes and columns, so a direct comparison of two tables will be misleading.

Any thoughts on how to approach this best?

Many thanks,
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I know that no two tables can have the same name within my database


Knowing this, why do the attributes matter?
 
Paul Brabban
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Attributes & columns would matter if I was to try and implement something that diff'd the tables to identify differences.

eg. the database wouldn't care if two tables had different columns but the same name, but a comparison of the two tables would care that there were different columns.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that equality test is valid if you are trying to copy how an relational database works (object names are always unique within a schema). Perhaps I'm not understanding your requirements?
 
Paul Brabban
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're right - I'm looking at equality in the context of the container (if names are equal) and equality in the context of the object (exactly equal in state).

It's almost like I could do with passing a Comparator-like object for equals to the Set to tell it how to perform the equals() method from its point of view.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic