• 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

[ DAO ] A question

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the DAO sample from pet store, the DAO
class signature reads like this:

My question: why is it that the create method
returns a CustomerVO (Value object)? Is the
returned CustomerVO the same the as the one
passed into create() ? If not, what's the difference. Thanks.
Pho
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One point might be to include extra data that was added while creation of the VO in the database... Like IDs (Primary-Key) for example that are auto-generated... By returning the freshly added VO out of the create-method you would have an easy way of accessing these extra values within your calling code...
Best Regards,
Chris
 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chris,
If primary keys (e.g. surrogate keys) are auto generated during the insert, does it imply that I would need to do an additional select to compose the returned CustomerVO ? In informix (which is what I'm using); there is a feature to retrieve an auto generated key from an insert (without doing another round trip to the db server).
Thanks
Pho
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to get the primary key is most likely implementation specific. You can disable autogenerated primary keys for a table and insert your own primary key. Then you know what the primary key will be before you insert it. This method is cross-database, gives you more control, but is slightly more work to implement.
If your primary key is autogenerated you can 1) use vendor specific syntax to return the last inserted primary key like @@identity in TransactSQL or 2) use a select statement based on a 'date_added' column with other values just inserted.
Then set the primary key of your value object and return that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic