Wednesday, April 11, 2012

Database Modification Logic

Onward and upward, I dare say.

With my Florida trip less than 4 days away, I'm really pushing to get as much of ChefHelper completed as possible. So I'm working on writing methods for each class to write to the database.

Here is one thing that should really help this process - I don't intend on making the validation lists updateable through the GUI. So I don't need to write methods for these. I don't have time to work in ways to control their update so I just won't allow updates. This only applies to the commitment, meal part, fraction, and measure validations, since foodstuffs, food types, ethnicities, and methods need to be extensible. I guess I'm really half and half.

I'm starting on Notes because they only have a single foreign key constraint. Then I'll branch out to some of the other areas. Well, that wasn't as good an idea as I'd originally thought. You see, the Notes table is one of the few where I've included dates. Working with dates in Java is a lot more complicated than you'd expect. So instead of blasting through Notes and moving on to my next Database-writing victim, I had to take a refresher course on dealing with dates and work out how to handle null dates (just in case).

I was hoping to use a standard writeToDB() method for all of my classes, which would determine if an INSERT or an UPDATE was warranted and just do so. I started to get confused while building two simultaneous similar (yet different) SQL strings to use, so kept the same method and separated the implementation into two private methods. I think this will help keep things clearer, though it does add one more area to check if I need to debug the writing process. I'll have to test this pretty thoroughly before giving it the all-clear.

Yup, the date stumped me for tonight. I can't seem to figure out out to convert a java.sql.date to a java.Calendar.date and it's already half past midnight. It's a good thing I'm going into work late tomorrow! I'll be back to sort this date crap out Friday night or Saturday. Oy!

No comments:

Post a Comment