discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objective-C Object Persistency


From: Andreas Höschler
Subject: Objective-C Object Persistency
Date: Fri, 14 Jan 2005 15:41:37 +0100

Hi all,

when developing business application we usually use RDBMs and some kind of mapping (e.g. EOF) to convert raw data into Objective-C objects and vice versa. Though well known and broadly used this concept has serious and hard to overcome drawbacks. Here is a simple example:

• We have a class Store with properties name, incomingDeliveries, outgoingDeliveries, value. name is a string (column in the database), incomingDeliveries and outgoingDeliveries are oneToMany-relatonships to entity Delivery, value is a derived attribute. Derived means here that we have an Objective-C method

- (void)validateValue
{
        float sum = [self startValue];

        for all incomingDeliveries do
        {
        sum += [incomingDelivery freightCosts];
        sum += [incomingDelivery ekCosts];
        }

        for all outgoingDeliveries do
        {
        sum += [outgoingDelivery ekYield];
        }

        [self setValue:sum];    
}

that calculates the value when necessary and validates a redundance. Since we want to use the property in fetch operations (give me all stores with value > 1000), we need to have a corresponding column in the database. But the user never sets this value on its own. We need a mechanism to update this property in the database whenever needed.

Now [Delivery freightCosts], [Delivery ekCosts], [Delivery ekYield] again are derived attributes, means there is a corresponding column in the database that is to be updated by an Objective-C method (automatically). Say freightCosts is calulated as follows.

- (void)validateFreightCosts
{
        NSNumber *distance = [self valueForKey:@"transportorder.distance"];
        NSNumber *rate = [self valueForKey:@"transportorder.rate"];
        NSNumber *product = distance * rate
        [self setFreightCosts: product];        
}

Now suppose that a user connects to the database and modifies the rate of a transportorder. This should invalidate the property freighCosts in all referenced deliveries, and this again must invalidate the value of referenced stores.

It is surely possible to find a pattern for this with the typical object-relational mapping scheme. However, I am wondering if anybody has ever tried to solve this problem generally. Are there any Objective-C based persistence layers (ObjectBases) available that at least try to solve this problem?

Thanks for any hints!

Regards,

  Andreas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]