primary key in DAO pattern

F

f

I am writing a system which is going to be used on different
databases. I use the DAO design pattern. The idea is that my system
focus on business logic only and it is up to the implementation of the
DAO that links my system to different databases with different schema.
My question is how to design the primary key in my system for each
data piece. I think the key is nessary for me when I write this
system, even though I know my system is to used differently, because
sometimes I need to join the data or whatever. And the key needs to be
translated to different databases when DAO is implemented.

DO I need the primary key for my Data? How to design the key so it can
be easily implemented by different database?

THanks,

ff
 
P

Petarian

Hello,

I think that if you use an integer as a primary key, that should work in
an hetrogeneous enviroment. DO NOT use an auto incrementing integer as
some database do not support that.

Another suggestion is to have your clients use a third party tool that
generates the DAO classes. This way you will know how the keys will be
generated. One such tool is DB Architect (http://www.synametrics.com)


Regards,
Pete
 
B

brougham5

DO I need the primary key for my Data? How to design the key so it can
be easily implemented by different database?

I'd suggest that all tables have a primary key field that is a unique
integer. Even if you don't think it will ever possibly be needed. It will
be. :)

Set up a different sequence for each of these fields. If you're concerned
about migrating to a database that doesn't support sequences, wrap the
process of getting the sequence with your own class. A database that
doesn't support sequences is probably a database that you want to avoid,
though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top