Re: Design for "archiving" data in EOF
Re: Design for "archiving" data in EOF
- Subject: Re: Design for "archiving" data in EOF
- From: "John Stewart" <email@hidden>
- Date: Tue, 20 Jun 2006 14:55:05 +0100
Hi,
The best solution will depend on what you want to do with the historic data.
If you archive (and remove) a set of data X from live data Y, you have
to make sure that Y has no references to X, so it can continue to
function.
Similarly, you have to be aware of X's references to Y if you restore
or recreate X.
You should be able to set status and 'unhook' with normal EO methods
in the Model code area.
For example if you replace a Question oldQuestion in an Exam exam, you
can do something like this in the Exam class (or better, subclass if
you use eogenerator)
****************************************************
public void replaceQuestion(Question oldQuestion, Question newQuestion) {
oldQuestion.setStatus(flag_historic);
oldQuestion.setOwningExam(null); // unhook it
newQuestion.setOwningExam(this); // hook in new one
newQuestion.setStatus(flag_live);
}
****************************************************
So in your editing context:
****************************************************
Question newQuestion = new Question();
newQuestion.setStuff(....); // question data
myExam.replaceQuestion(oldQuestion, newQuestion);
my_editing_context.insertObject(newQuestion);
my_editing_context.saveChanges();
****************************************************
However, that leaves you with 'floating' historic questions which are orphans.
What do you want to do with these? Simply display as a list? Restore
them to the live database or recreate elsewhere?
If restore, the archived items will need to somehow maintain their
references. It may be unsafe to rely on FKs, depending on database,
so perhaps some reference to a unique ExamCode would do. e.g.
****************************************************
// in replaceQuestion(..)
oldQuestion.setExamCode(this.examCode());
// now safe to unhook and archive
****************************************************
On restore, you can do something like;
****************************************************
// myQuestion already restored from archive
Exam parentExam = findExamWithCode(myQuestion.examCode());
myQuestion.setExam(parentExam);
****************************************************
If you're recreating elsewhere, you'll also need to archive the Exam
and any other dependent items in the data tree. In this case you
should be able to rely on FKs instead of examCodes. You may also want
to store Timestamps or DateTimes if you need to recreate a 'snapshot'
of an exam at a particular time. e.g.
****************************************************
NSArray augustQuestions = findLastBeforeInExam(DateTime dtAugust, Exam myExam);
****************************************************
Hope this is useful.
John
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden