/// <summary> /// Searches the shared and pooled connector lists for a /// matching connector object or creates a new one. /// </summary> /// <param name="provider">Provider requested to connect to the database server</param> /// <param name="Shared">Allows multiple connections on a single connector. </param> /// <returns>A pooled connector object.</returns> internal Connector RequestConnector(IProvider provider, bool Shared) { // if a shared connector is requested then the Shared // Connector List is searched first: if (Shared) { foreach (Connector Connector in SharedConnectors) { if (Connector.Provider.ConnectionID == provider.ConnectionID) { // Bingo! // Return the shared connector to caller. // The connector is already in use. Connector._ShareCount++; return Connector; } } } // if a shared connector could not be found or a // nonshared connector is requested, then the pooled // (unused) connectors are beeing searched. foreach (Connector Connector in PooledConnectors) { if (Connector.Provider.ConnectionID == provider.ConnectionID) { // Bingo! // Remove the Connector from the pooled connectors list. PooledConnectors.Remove(Connector); // Make the connector shared if requested if (Connector.Shared = Shared) { SharedConnectors.Add(Connector); Connector._ShareCount = 1; } // done... Connector.InUse = true; return Connector; } } // No suitable connector found, so create new one Connector NewConnector = new Connector(provider, Shared); // Shared connections must be added to the shared // connectors list if (Shared) { SharedConnectors.Add(NewConnector); NewConnector._ShareCount = 1; } // and then returned to the caller NewConnector.InUse = true; NewConnector.Open(); return NewConnector; }
/// <summary> /// Searches the shared and pooled connector lists for a /// matching connector object or creates a new one. /// </summary> /// <param name="entity">Entity to be pooled.</param> /// <param name="Shared">Allows multiple connections on a single connector. </param> /// <returns>A pooled connector object.</returns> internal Connector RequestConnector(IFileBased entity, bool Shared) { // if a shared connector is requested then the Shared // Connector List is searched first: if (Shared) { foreach (Connector connector in this.SharedConnectors) { if (entity.Path == connector.PooledEntity.Path) { // Bingo! // Return the shared connector to caller. // The connector is already in use. connector._ShareCount++; return connector; } } } // if a shared connector could not be found or a // nonshared connector is requested, then the pooled // (unused) connectors are beeing searched. foreach (Connector connector in this.PooledConnectors) { if (connector.PooledEntity.Path == entity.Path) { // Bingo! // Remove the Connector from the pooled connectors list. this.PooledConnectors.Remove(connector); // Make the connector shared if requested if (connector.Shared = Shared) { this.SharedConnectors.Add(connector); connector._ShareCount = 1; } // done... connector.InUse = true; return connector; } } // No suitable connector found, so create new one Connector NewConnector = new Connector(entity, Shared); // Shared connections must be added to the shared // connectors list if (Shared) { this.SharedConnectors.Add(NewConnector); NewConnector._ShareCount = 1; } // and then returned to the caller NewConnector.InUse = true; NewConnector.Open(); return NewConnector; }