Attachments and Relationships
Attachments and Relationships: We also want to use references for Attachments, but since a message can have any number of attachments (as opposed to only one format), we’ll want to create either an array of references or a one-to-many relationship.
An attachment can be just about anything, so we’ll simply define the list of attachments as a list of ooObj objects, Objectivity/DB ’s base persistentcapable class. By doing this,any class we define can be used as an attachment, including other messages. We’ll still create a class called FileAttachment, from which we can derive specific classes for specific kinds of files. For now, we’ll just have two specific classes, TextData and BinaryData.
Obviously, if we find a virus in an attachment we’ll want to know quickly which message it has come from. If we find attachments by searching the attachments of messages, the virus-scanner can simply keep the reference to the “current message”. But if we search attachments independently, we’ll want each attachment to have a reference to the message it came from.
To do this, we’ll simply define an Objectivity/DB one-to-many bi-directional relationship between Message and Attachment. Each time we add an attachment reference to a message, Objectivity/DB will ensure that attachment OID will be added to the message and the message OID will be set in the attachment.
