design pattern: facade for delete?

Hi guys,

I have the following info (db):

department (dep_id, name, description)

empl(empl_id, dep_id, name)

invoice (inv_id, dep_id, description).

.

.

.

question is this: say I would like to delete the department (which include the empl as well). What is the best way to do that?

obviously, I can do something like this:

1. delete department by id

2. delete user associated to department etc

the problem is that in the future there might be more information relating the department that will need to be deleted (and I'm not going to go over the code to check for deletion and add another one)

I thought that the facade design pattern can work here. I'm not sure if I'm on the right track and wonder if someone can put some light and describe how to do that.

should it be something like this:

Class DepartmentDeleteFacade(int id department)

{

//delete department

//delet users associated

.

.

.

}

thanks for any thoughts

[1069 byte] By [xianwinwina] at [2007-10-3 9:49:42]
# 1
my thought:Just create a stored procedure to delete. That way if later on you add new associates all you would have to do is update the stored procedure.Also, I would suggest deleting the associations before deleting the department.
zadoka at 2007-7-15 5:06:47 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
ok....why is it recommended to start with the associations first?
xianwinwina at 2007-7-15 5:06:47 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

> ok....why is it recommended to start with the

> associations first?

Because the foreign keys will probably require it.

And unless there is a very good reason to not do it there should only be one stored procedure that deletes the main entity and all of the child entites at once.

jschella at 2007-7-15 5:06:47 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
Not an answer to your question per se but you might want to disable things instead of deleting them. Deleting from the db destroys information and disabling does not. Also, it's a lot easier to disable something than doing a recursive delete.
dubwaia at 2007-7-15 5:06:47 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
mark as delete then in eg oracle, partition later
mchan0a at 2007-7-15 5:06:47 > top of Java-index,Other Topics,Patterns & OO Design...
# 6
Thank you dubwai & mchan0, this is an excellent tip, I'll use it.
xianwinwina at 2007-7-15 5:06:47 > top of Java-index,Other Topics,Patterns & OO Design...
# 7
Another possibility is to define the primary table (Department) as RI = cascade delete, which will automatically delete all its children.
TimRyanNZa at 2007-7-15 5:06:47 > top of Java-index,Other Topics,Patterns & OO Design...