OracleConnectionFactory.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / DataOracleClient / System / Data / OracleClient / OracleConnectionFactory.cs / 1 / OracleConnectionFactory.cs

                            //------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
 
namespace System.Data.OracleClient 
{
    using System; 
    using System.Data.Common;
    using System.Data.ProviderBase;
    using System.Diagnostics;
    using System.Collections.Specialized; 
    using System.Configuration;
    using System.IO; 
 
    sealed internal class OracleConnectionFactory : DbConnectionFactory {
        private OracleConnectionFactory() : base(OraclePerformanceCounters.SingletonInstance) {} 

        public static readonly OracleConnectionFactory SingletonInstance = new OracleConnectionFactory();

        public const string _metaDataXml          = "MetaDataXml"; 

        override public DbProviderFactory ProviderFactory { 
            get { 
                return OracleClientFactory.Instance;
            } 
        }

        override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) {
            DbConnectionInternal result = new OracleInternalConnection(options as OracleConnectionString); 
            return result;
        } 
 
        override protected DbConnectionOptions CreateConnectionOptions(string connectionOptions, DbConnectionOptions previous) {
            Debug.Assert(!ADP.IsEmpty(connectionOptions), "null connectionOptions"); 
            OracleConnectionString result = new OracleConnectionString(connectionOptions);
            return result;
        }
 
        override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions( DbConnectionOptions connectionOptions ) {
            OracleConnectionString opt = (OracleConnectionString)connectionOptions; 
 
            DbConnectionPoolGroupOptions poolGroupOptions = null;
 
            if (opt.Pooling) {
                poolGroupOptions = new DbConnectionPoolGroupOptions(
                                                    opt.IntegratedSecurity,
                                                    opt.MinPoolSize, 
                                                    opt.MaxPoolSize,
                                                    30000,  // creationTimeout: 30 seconds 
                                                    opt.LoadBalanceTimeout, 
                                                    opt.Enlist,
                                                    false);  // useDeactivateQueue 
            }
            return poolGroupOptions;
        }
 
        override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory){
 
            Debug.Assert (internalConnection != null,"internalConnection may not be null."); 
            cacheMetaDataFactory = false;
 
            NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.oracleclient");
            Stream XMLStream =null;
            if (settings != null){
                string [] values = settings.GetValues(_metaDataXml); 
                if (values != null) {
                    XMLStream = ADP.GetXmlStreamFromValues(values,_metaDataXml); 
                } 
            }
 
            // if the xml obtained from machine.config use the embedded XML resource
            if (XMLStream == null){
                XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OracleClient.OracleMetaData.xml");
                cacheMetaDataFactory = true; 
            }
            Debug.Assert (XMLStream != null,"XMLstream may not be null."); 
 
            return new DbMetaDataFactory (XMLStream,
                                          internalConnection.ServerVersion, 
                                          internalConnection.ServerVersionNormalized);

        }
 
        override internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnection connection) {
            OracleConnection c = (connection as OracleConnection); 
            if (null != c) { 
                return c.PoolGroup;
            } 
            return null;
        }

        override internal DbConnectionInternal GetInnerConnection(DbConnection connection) { 
            OracleConnection c = (connection as OracleConnection);
            if (null != c) { 
                return c.InnerConnection; 
            }
            return null; 
        }

        override protected int GetObjectId(DbConnection connection) {
            OracleConnection c = (connection as OracleConnection); 
            if (null != c) {
                return c.ObjectID; 
            } 
            return 0;
        } 

        override internal void PermissionDemand(DbConnection outerConnection) {
            OracleConnection c = (outerConnection as OracleConnection);
            if (null != c) { 
                c.PermissionDemand();
            } 
        } 

        override internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup) { 
            OracleConnection c = (outerConnection as OracleConnection);
            if (null != c) {
                c.PoolGroup = poolGroup;
            } 
        }
 
        override internal void SetInnerConnectionEvent(DbConnection owningObject, DbConnectionInternal to) { 
            OracleConnection c = (owningObject as OracleConnection);
            if (null != c) { 
                c.SetInnerConnectionEvent(to);
            }
        }
 
        override internal bool SetInnerConnectionFrom(DbConnection owningObject, DbConnectionInternal to, DbConnectionInternal from) {
            OracleConnection c = (owningObject as OracleConnection); 
            if (null != c) { 
                return c.SetInnerConnectionFrom(to, from);
            } 
            return false;
        }

        override internal void SetInnerConnectionTo(DbConnection owningObject, DbConnectionInternal to) { 
            OracleConnection c = (owningObject as OracleConnection);
            if (null != c) { 
                c.SetInnerConnectionTo(to); 
            }
        } 

    }

    sealed internal class OraclePerformanceCounters : DbConnectionPoolCounters { 
        private const string CategoryName = ".NET Data Provider for Oracle";
        private const string CategoryHelp = "Counters for System.Data.OracleClient"; 
 
        public static readonly OraclePerformanceCounters SingletonInstance = new OraclePerformanceCounters();
 
        [System.Diagnostics.PerformanceCounterPermissionAttribute(System.Security.Permissions.SecurityAction.Assert, PermissionAccess=PerformanceCounterPermissionAccess.Write, MachineName=".", CategoryName=CategoryName)]
        private OraclePerformanceCounters() : base (CategoryName, CategoryHelp) {
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
 
namespace System.Data.OracleClient 
{
    using System; 
    using System.Data.Common;
    using System.Data.ProviderBase;
    using System.Diagnostics;
    using System.Collections.Specialized; 
    using System.Configuration;
    using System.IO; 
 
    sealed internal class OracleConnectionFactory : DbConnectionFactory {
        private OracleConnectionFactory() : base(OraclePerformanceCounters.SingletonInstance) {} 

        public static readonly OracleConnectionFactory SingletonInstance = new OracleConnectionFactory();

        public const string _metaDataXml          = "MetaDataXml"; 

        override public DbProviderFactory ProviderFactory { 
            get { 
                return OracleClientFactory.Instance;
            } 
        }

        override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) {
            DbConnectionInternal result = new OracleInternalConnection(options as OracleConnectionString); 
            return result;
        } 
 
        override protected DbConnectionOptions CreateConnectionOptions(string connectionOptions, DbConnectionOptions previous) {
            Debug.Assert(!ADP.IsEmpty(connectionOptions), "null connectionOptions"); 
            OracleConnectionString result = new OracleConnectionString(connectionOptions);
            return result;
        }
 
        override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions( DbConnectionOptions connectionOptions ) {
            OracleConnectionString opt = (OracleConnectionString)connectionOptions; 
 
            DbConnectionPoolGroupOptions poolGroupOptions = null;
 
            if (opt.Pooling) {
                poolGroupOptions = new DbConnectionPoolGroupOptions(
                                                    opt.IntegratedSecurity,
                                                    opt.MinPoolSize, 
                                                    opt.MaxPoolSize,
                                                    30000,  // creationTimeout: 30 seconds 
                                                    opt.LoadBalanceTimeout, 
                                                    opt.Enlist,
                                                    false);  // useDeactivateQueue 
            }
            return poolGroupOptions;
        }
 
        override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory){
 
            Debug.Assert (internalConnection != null,"internalConnection may not be null."); 
            cacheMetaDataFactory = false;
 
            NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.oracleclient");
            Stream XMLStream =null;
            if (settings != null){
                string [] values = settings.GetValues(_metaDataXml); 
                if (values != null) {
                    XMLStream = ADP.GetXmlStreamFromValues(values,_metaDataXml); 
                } 
            }
 
            // if the xml obtained from machine.config use the embedded XML resource
            if (XMLStream == null){
                XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OracleClient.OracleMetaData.xml");
                cacheMetaDataFactory = true; 
            }
            Debug.Assert (XMLStream != null,"XMLstream may not be null."); 
 
            return new DbMetaDataFactory (XMLStream,
                                          internalConnection.ServerVersion, 
                                          internalConnection.ServerVersionNormalized);

        }
 
        override internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnection connection) {
            OracleConnection c = (connection as OracleConnection); 
            if (null != c) { 
                return c.PoolGroup;
            } 
            return null;
        }

        override internal DbConnectionInternal GetInnerConnection(DbConnection connection) { 
            OracleConnection c = (connection as OracleConnection);
            if (null != c) { 
                return c.InnerConnection; 
            }
            return null; 
        }

        override protected int GetObjectId(DbConnection connection) {
            OracleConnection c = (connection as OracleConnection); 
            if (null != c) {
                return c.ObjectID; 
            } 
            return 0;
        } 

        override internal void PermissionDemand(DbConnection outerConnection) {
            OracleConnection c = (outerConnection as OracleConnection);
            if (null != c) { 
                c.PermissionDemand();
            } 
        } 

        override internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup) { 
            OracleConnection c = (outerConnection as OracleConnection);
            if (null != c) {
                c.PoolGroup = poolGroup;
            } 
        }
 
        override internal void SetInnerConnectionEvent(DbConnection owningObject, DbConnectionInternal to) { 
            OracleConnection c = (owningObject as OracleConnection);
            if (null != c) { 
                c.SetInnerConnectionEvent(to);
            }
        }
 
        override internal bool SetInnerConnectionFrom(DbConnection owningObject, DbConnectionInternal to, DbConnectionInternal from) {
            OracleConnection c = (owningObject as OracleConnection); 
            if (null != c) { 
                return c.SetInnerConnectionFrom(to, from);
            } 
            return false;
        }

        override internal void SetInnerConnectionTo(DbConnection owningObject, DbConnectionInternal to) { 
            OracleConnection c = (owningObject as OracleConnection);
            if (null != c) { 
                c.SetInnerConnectionTo(to); 
            }
        } 

    }

    sealed internal class OraclePerformanceCounters : DbConnectionPoolCounters { 
        private const string CategoryName = ".NET Data Provider for Oracle";
        private const string CategoryHelp = "Counters for System.Data.OracleClient"; 
 
        public static readonly OraclePerformanceCounters SingletonInstance = new OraclePerformanceCounters();
 
        [System.Diagnostics.PerformanceCounterPermissionAttribute(System.Security.Permissions.SecurityAction.Assert, PermissionAccess=PerformanceCounterPermissionAccess.Write, MachineName=".", CategoryName=CategoryName)]
        private OraclePerformanceCounters() : base (CategoryName, CategoryHelp) {
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK