У меня есть следующая схема БД.
SQL> describe USERS;
Name Null? Type
----------------------------------------- -------- ----------------------------
user_id NOT NULL NUMBER(38)
name NOT NULL VARCHAR2(50)
password NOT NULL VARCHAR2(50)
score NUMBER(38)
notify_before_expiration NUMBER(38)
is_admin NOT NULL NUMBER(1)
SQL> describe EMAIL;
Name Null? Type
----------------------------------------- -------- ----------------------------
email_id NOT NULL NUMBER(38)
email NOT NULL VARCHAR2(50)
user_id NOT NULL NUMBER(38)
Итак, у одного пользователя много писем.
Пользователи могут получить доступ к форме, где они могут добавить / удалить свою электронную почту.
Вопрос в том, что является лучшим способом обновления базы данных, содержащей список писем, полученных из этой формы?
Я думал что-то вроде: (псевдокод Java)
//List of mails in db.
ArrayList<String> emailsInDB = getAllMailsFromDB(user);
//List of mails from the form
ArrayList<String> emailsInForm = form.getAllMails();
//Iterates all emails gotten from the form.
for (String email : emailsInForm) {
if (emailsInDB.contains(email) {
//Already in the db
emailsInDB.remove(email, user);
} else {
//New mail! Add it in the db!
db.insertMail(email, user);
}
//All emails that were in the db, but not in the form,
//were deleted. Delete them from the db.
for (String email : emailsInDB) {
db.deleteMail(email);
}
Лучшие идеи приветствуются!
Спасибо за чтение.