Dods: Re: Dods: features

Nenad Vico <[email protected]> Fri, 21 Feb 2003 16:14:29 +0100
Newsgroups gmane.comp.java.enhydra.dods
Organization LAB_OVI
Message-ID <[email protected]>
Hello Jesse,

If I understood problem good, it is possible to make this as follows:

You need to reference Person object from Patient and do some linking
in bussines logic like this:

public class Person {
    protected PersonDO personDO = null;
    public Person() {
        try {
            this.personDO = PersonDO.createVirgin();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    public Person(PersonDO thePerson) {
        this.personDO = thePerson; 
    }
   ...
}

public class Patient extends Person {
    protected PatientDO patientDO = null;
    public Patient() {
        super();
        try {
            this.patientDO = PatientDO.createVirgin();
            this.patientDO.setPerson(this.personDO);  // linking
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    protected Patient(PatientDO thePatient) {
        this.patientDO = thePatient;
        try {
            this.personDO = thePatient.getPerson(); // linking
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    ...

    public void save() {
        try {
            this.patientDO.commit(); // also commit references
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    public void delete() {
        try {
            this.patientDO.delete();  // also delete references
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    ...
}

public class PatientFactory {
        public static Patient findPatientByID(String id) {
            Patient thePatient = null;
            try {
                PatientQuery query = new PatientQuery();
                //set query
                query.setQueryOId(new ObjectId(id));
                // Throw an exception if more than one user by this name is found
                query.requireUniqueInstance();
                PatientDO thePatientDO = query.getNextDO();
                thePatient = new Patient(thePatientDO);
                return thePatient;
            }catch(Exception ex) {
                ex.printStackTrace();
            }
        }
}

-- 
Best regards,
 Nenad