Re: Setting a relationship to a generic DataObject in order to log the primary key value

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Dec 30 2005 - 12:26:17 EST

  • Next message: Andrus Adamchik: "Re: 3t server enchancements"

    Mike,

    See my message on cayenne-devel regarding a possible general solution
    to the audit problem. Suggested two-phase commit should solve this
    problem as well.

    http://objectstyle.org/cayenne/lists/cayenne-devel/2005/12/0087.html

    Andrus

    On Dec 20, 2005, at 7:40 PM, Mike Kienenberger wrote:

    > I need to create audit log database records each time I commit
    > changes. One of the fields in the audit record needs to be the
    > primary key of the record being audited.
    >
    > In a past project I handled this by creating a relationship from my
    > audit log entity to every other entity in existance, using the same
    > "foreignRecordID" in my audit log. Then my class generation template
    > would substitute in the correct name of the relationship to use.
    >
    > setForeignAccount(Account)
    > setForeignAccountActivation(AccountActivation)
    > setForeignACHProcessingQueue(ACHProcessingQueue)
    > setForeignApplicationData(ApplicationData)
    > setForeignBank(Bank)
    > setForeignBankAccount(BankAccount)
    > setForeignBatchJobData(BatchJobData)
    > setForeignComment(Comment)
    > setForeignConsolidatedAccount(ConsolidatedAccount)
    > setForeignCreditCard(CreditCard)
    > setForeignDataDictionary(DataDictionary)
    > setForeignHelpTopic(HelpTopic)
    > setForeignJustBilledAccount(JustBilledAccount)
    > setForeignLocalization(Localization)
    > setForeignPaperBillWarning(PaperBillWarning)
    > setForeignPaymentHistory(PaymentHistory)
    > setForeignPaymentInProgress(PaymentInProgress)
    > setForeignPaymentMethod(PaymentMethod)
    > setForeignPendingPayment(PendingPayment)
    > setForeignProcessingResultAction(ProcessingResultAction)
    > setForeignRecordKey(Integer)
    > setForeignScheduledPayment(ScheduledPayment)
    > setForeignSendPaperBillChange(SendPaperBillChange)
    > setForeignStateProvince(StateProvince)
    > setForeignUser(User)
    > setForeignUserAccountRelationship(UserAccountRelationship)
    >
    > This was really ackward as it required adding a new relationship to
    > the audit log whenever a new Entity was added, and invariably these
    > new relationships didn't get created, and the application crashed.
    >
    > What I'd really like to do is be able to use
    > "changeLog.setForeignRecord(DataObject dataObject)" generically, but I
    > can't figure out a way to do this.
    >
    > I can do the following, but it fails on insert logging since the
    > primary key doesn't exist yet.
    >
    > Object primaryKey = DataObjectUtils.pkForObject(dataObject);
    > Number primaryKeyNumber = (Number)primaryKey;
    > changeLog.setForeignRecordId(new Integer
    > (primaryKeyNumber.intValue()));
    >
    > I really don't want to go back to the old methodology. It was painful
    > with just a few tables, and now I've got hundreds of tables to deal
    > with.
    >
    > The only idea I've come up with is to programmically create the
    > relationships when the application starts up instead of defining them
    > in the modeler.
    >
    > -Mike
    >



    This archive was generated by hypermail 2.0.0 : Fri Dec 30 2005 - 12:26:29 EST