AdFactum ObjectMapper .NET Blog

Official blog of the AdFactum ObjectMapper .NET

Using Oracle DECODE function to evaluate if an aggregated object does exists

Posted by Gerhard Stephan on August 23rd, 2007

When you are doing a flat load of an object, the aggregated child objects won’t be loaded and the property in your entity class is set to NULL. At the first glance you can’t say whether the aggregated child object is not loaded or the aggregated child object does not exist in database.

To change this, we have to grab into our bag of tricks. Using the DECODE Function of Oracle we can determinate if a aggregated child object does exists or not.

public class Invitee : ValueObject   
{
        Contact _invitedContact;
        bool    _hasInvitedContact;

        /// <summary>

        /// The aggregated Contact

        /// </summary>

        [PropertyName("CONTACT")]

        public Contact InvitedContact

        {

            get { return _invitedContact; }

            set { _invitedContact = value; }

        }

             

        /// <summary>

        /// Using the Select Function the decide if an

        /// aggregated object does exists in database.

        /// </summary>

        [SelectFunction("DECODE(#SR#INVITEE.CONTACT,NULL,0,1)")]

        public bool HasInvitedContact

        {

            get { return _hasInvitedContact; }

            set { _hasInvitedContact = value; }

        }

 

 

 

 

As you can see the Select Function is using the Oracle DECODE function to determinate whether the aggregated contact does exists or not. The result of the SelectFunction will be mapped to the boolean value "HasInvitedContact". Using this hint you don’t have to explicit load the aggregated child object from database in order to say whether it does exists or not.

Remark: The placeholder #SR# is a constant used by the AdFactum ObjectMapper .NET. The constant will be replaced with the oracle shema when generating the SQL.

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>