db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ryan Bobko" <r...@ostrich-emulators.com>
Subject recommended practices? dealing with the database-application divide
Date Fri, 01 Jun 2007 13:24:01 GMT
Hi Folks,
This is something I seem to struggle with every time I write a new db
application. I feel like I design the database logically, but somewhere
in the application code, I always seem to define constants that directly
mirror what's in my database. I'm interested in how other people deal
with this, and/or if there's something I should be doing to avoid the
situation.

For example, suppose I have a two tables for dealing with users:

create table user( id int primary key, name varchar(20), level int );
create table privilege( id int primary key, desc text );
insert into privilege( id, desc ) values( 0, 'user' );
insert into privilege( id, desc ) values( 1, 'adminstrator' );

Then in my code, I can get users and their level, but somewhere I need
to define what the levels are. I seem to have statements like:

public static final int ADMIN=1;
if( ADMIN==user.level ){...}

Obviously, this is a simple case where I could just as easily add an
"isAdmin" column to the table, but what if I had ten different levels?

One of the things I like about using the database is that I can change
values easily, but that is of no value when the app is so tightly
coupled with the database. Any solutions out there?

Thanks for your time,

ry

Mime
View raw message