WindowsDevCenter.com
oreilly.comSafari Books Online.Conferences.

advertisement


AddThis Social Bookmark Button

Object-Oriented Data Programming: C# Meets Caché
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Postscript: Looking Under the Hood

For those of you with unbridled curiosity, you certainly can look at the implementation provided by the proxy classes. For example, what follows is the code just for the Medication class!

namespace User {
    
    
    public class Medication : InterSystems.Data.CacheTypes.CachePersistent {
        
        public new const string ServerClassName = "User.Medication";
        
        static Medication() {
            InterSystems.Data.CacheClient.CacheConnection.AddClientTypeDescr("User.Medication", typeof(Medication));
        }
        
        public Medication() {
        }
        
        public Medication(InterSystems.Data.CacheClient.CacheConnection conn) {
            try {
                System.Threading.Monitor.Enter(conn);
                this.Init(conn, Medication.ServerClassName);
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public virtual string MedicationName {
            get {
                try {
                    System.Threading.Monitor.Enter(this.conn);
                    this.AssertIsConnected();
                    this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                    InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                    try {
                        mtdSignature.SetReturnType(this.conn, 4);
                        this.GetPropertyS("MedicationName", 2, 0, mtdSignature);
                        return ((InterSystems.Data.CacheTypes.CacheStringReturnValue)(mtdSignature.ReturnValue)).Value;
                    }
                    finally {
                        mtdSignature.Clear();
                    }
                }
                finally {
                    System.Threading.Monitor.Exit(this.conn);
                }
            }
            set {
                try {
                    System.Threading.Monitor.Enter(this.conn);
                    this.AssertIsConnected();
                    this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                    InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                    try {
                        mtdSignature.Add(value, this.conn, false);
                        this.SetPropertyS("MedicationName", mtdSignature, 2, 0, 2);
                    }
                    finally {
                        mtdSignature.Clear();
                    }
                }
                finally {
                    System.Threading.Monitor.Exit(this.conn);
                }
            }
        }
        
        public virtual InterSystems.Data.CacheTypes.CacheRelationshipObject PrescriptionToMedication {
            get {
                try {
                    System.Threading.Monitor.Enter(this.conn);
                    this.AssertIsConnected();
                    this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                    InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                    try {
                        mtdSignature.SetReturnType(this.conn, 0);
                        this.GetPropertyS("PrescriptionToMedication", 4, 0, mtdSignature);
                        return ((InterSystems.Data.CacheTypes.CacheRelationshipObject)(((InterSystems.Data.CacheTypes.CacheObjReturnValue)(mtdSignature.ReturnValue)).Value));
                    }
                    finally {
                        mtdSignature.Clear();
                    }
                }
                finally {
                    System.Threading.Monitor.Exit(this.conn);
                }
            }
            set {
                try {
                    System.Threading.Monitor.Enter(this.conn);
                    this.AssertIsConnected();
                    this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                    InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                    try {
                        mtdSignature.Add(value, this.conn, false);
                        this.SetPropertyS("PrescriptionToMedication", mtdSignature, 4, 0, 3);
                    }
                    finally {
                        mtdSignature.Clear();
                    }
                }
                finally {
                    System.Threading.Monitor.Exit(this.conn);
                }
            }
        }
        
        public static Medication Open(InterSystems.Data.CacheClient.CacheConnection conn, byte[] id, int concurrency, out InterSystems.Data.CacheTypes.CacheStatus status) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id, concurrency, out status)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static Medication Open(InterSystems.Data.CacheClient.CacheConnection conn, byte[] id, out InterSystems.Data.CacheTypes.CacheStatus status) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id, out status)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static Medication Open(InterSystems.Data.CacheClient.CacheConnection conn, byte[] id) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static Medication Open(InterSystems.Data.CacheClient.CacheConnection conn, byte[] id, int concurrency, int timeout, out InterSystems.Data.CacheTypes.CacheStatus status) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id, concurrency, timeout, out status)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static Medication OpenId(InterSystems.Data.CacheClient.CacheConnection conn, string id, int concurrency, out InterSystems.Data.CacheTypes.CacheStatus status) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id, concurrency, out status)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static Medication OpenId(InterSystems.Data.CacheClient.CacheConnection conn, string id, out InterSystems.Data.CacheTypes.CacheStatus status) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id, out status)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static Medication OpenId(InterSystems.Data.CacheClient.CacheConnection conn, string id) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static Medication OpenId(InterSystems.Data.CacheClient.CacheConnection conn, string id, int concurrency, int timeout, out InterSystems.Data.CacheTypes.CacheStatus status) {
            try {
                System.Threading.Monitor.Enter(conn);
                conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                return ((Medication)(conn.OpenProxyObj(Medication.ServerClassName, id, concurrency, timeout, out status)));
            }
            finally {
                System.Threading.Monitor.Exit(conn);
            }
        }
        
        public static System.Nullable<bool> ExistsId(InterSystems.Data.CacheClient.CacheConnection conn, string id) {
            return Medication.ExistsIdInternal(conn, Medication.ServerClassName, id);
        }
        
        public static InterSystems.Data.CacheTypes.CacheStatus DeleteId(InterSystems.Data.CacheClient.CacheConnection conn, string id) {
            return Medication.DeleteIdInternal(conn, Medication.ServerClassName, id);
        }
        
        public static InterSystems.Data.CacheTypes.CacheStatus KillExtent(InterSystems.Data.CacheClient.CacheConnection conn) {
            return Medication.KillExtentInternal(conn, Medication.ServerClassName);
        }
        
        public virtual System.Nullable<bool> IDKEYCheck(string K1, System.Nullable<long> lockonly) {
            try {
                System.Threading.Monitor.Enter(this.conn);
                this.AssertIsConnected();
                this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                try {
                    mtdSignature.SetReturnType(this.conn, 9);
                    mtdSignature.Add(K1, this.conn, false);
                    mtdSignature.Add(lockonly, this.conn, false);
                    this.RunMethodS("IDKEYCheck", mtdSignature);
                    return ((InterSystems.Data.CacheTypes.CacheBooleanReturnValue)(mtdSignature.ReturnValue)).Value;
                }
                finally {
                    mtdSignature.Clear();
                }
            }
            finally {
                System.Threading.Monitor.Exit(this.conn);
            }
        }
        
        public virtual System.Nullable<bool> IDKEYExists(string K1, ref string id) {
            try {
                System.Threading.Monitor.Enter(this.conn);
                this.AssertIsConnected();
                this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                try {
                    mtdSignature.SetReturnType(this.conn, 9);
                    mtdSignature.Add(K1, this.conn, false);
                    mtdSignature.Add(id, this.conn, true);
                    this.RunMethodS("IDKEYExists", mtdSignature);
                    id = ((InterSystems.Data.CacheTypes.CacheStringArgument)(mtdSignature.Arguments[1])).Value;
                    return ((InterSystems.Data.CacheTypes.CacheBooleanReturnValue)(mtdSignature.ReturnValue)).Value;
                }
                finally {
                    mtdSignature.Clear();
                }
            }
            finally {
                System.Threading.Monitor.Exit(this.conn);
            }
        }
        
        public virtual InterSystems.Data.CacheTypes.CacheObject IDKEYOpen(string K1, System.Nullable<long> concurrency, ref InterSystems.Data.CacheTypes.CacheStatus sc) {
            try {
                System.Threading.Monitor.Enter(this.conn);
                this.AssertIsConnected();
                this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                try {
                    mtdSignature.SetReturnType(this.conn, 0);
                    mtdSignature.Add(K1, this.conn, false);
                    mtdSignature.Add(concurrency, this.conn, false);
                    mtdSignature.Add(sc, this.conn, true);
                    this.RunMethodS("IDKEYOpen", mtdSignature);
                    sc = ((InterSystems.Data.CacheTypes.CacheStatusArgument)(mtdSignature.Arguments[2])).Value;
                    return ((InterSystems.Data.CacheTypes.CacheObject)(((InterSystems.Data.CacheTypes.CacheObjReturnValue)(mtdSignature.ReturnValue)).Value));
                }
                finally {
                    mtdSignature.Clear();
                }
            }
            finally {
                System.Threading.Monitor.Exit(this.conn);
            }
        }
        
        public virtual string PrescriptionToMedicationGetObjectId(System.Nullable<long> force) {
            try {
                System.Threading.Monitor.Enter(this.conn);
                this.AssertIsConnected();
                this.conn.GeneratedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
                InterSystems.Data.CacheTypes.CacheMethodSignature mtdSignature = this.conn.GetMtdSignature();
                try {
                    mtdSignature.SetReturnType(this.conn, 4);
                    mtdSignature.Add(force, this.conn, false);
                    this.RunMethodS("PrescriptionToMedicationGetObjectId", mtdSignature);
                    return ((InterSystems.Data.CacheTypes.CacheStringReturnValue)(mtdSignature.ReturnValue)).Value;
                }
                finally {
                    mtdSignature.Clear();
                }
            }
            finally {
                System.Threading.Monitor.Exit(this.conn);
            }
        }
        
        public static InterSystems.Data.CacheClient.CacheCommand Extent(InterSystems.Data.CacheClient.CacheConnection conn) {
            InterSystems.Data.CacheClient.CacheCommand cmd = new InterSystems.Data.CacheClient.CacheCommand("{ call SQLUser.Medication_Extent}", conn);
            return cmd;
        }
        
        public static InterSystems.Data.CacheClient.CacheCommand FindAllMedications(InterSystems.Data.CacheClient.CacheConnection conn) {
            InterSystems.Data.CacheClient.CacheCommand cmd = new InterSystems.Data.CacheClient.CacheCommand("{ call SQLUser.Medication_FindAllMedications}", conn);
            return cmd;
        }
    }
}

The truth is, however, that you never need to look at this proxy implementation. You are free to pretend that Medication is just another C# class, and it works just as you would expect it to.

Jesse Liberty is a senior program manager for Microsoft Silverlight where he is responsible for the creation of tutorials, videos and other content to facilitate the learning and use of Silverlight. Jesse is well known in the industry in part because of his many bestselling books, including O'Reilly Media's Programming .NET 3.5, Programming C# 3.0, Learning ASP.NET with AJAX and the soon to be published Programming Silverlight.


Return to the Windows DevCenter.