Validates connection object based on its driver
Unnecessary fields will be stripped out
@param {object} connection
482517
function validateConnection(connection) {
  const coreFields = ['_id', 'name', 'driver', 'createdDate', 'modifiedDate'];
  if (!connection.name) {
    throw new Error('connection.name required');
  }
  if (!connection.driver) {
    throw new Error('connection.driver required');
  }
  const driver = drivers[connection.driver];
  if (!driver) {
    throw new Error(`driver implementation ${connection.driver} not found`);
  }
  const validFields = driver.fields.map(field => field.key).concat(coreFields);
  const cleanedConnection = validFields.reduce(
    (cleanedConnection, fieldKey) => {
      if (connection.hasOwnProperty(fieldKey)) {
        let value = connection[fieldKey];
        const fieldDefinition =
          drivers[connection.driver].fieldsByKey[fieldKey];

        // field definition may not exist since
        // this could be a core field like _id, name
        if (fieldDefinition) {
          if (fieldDefinition.formType === 'CHECKBOX') {
            value = utils.ensureBoolean(value);
          }
        }

        cleanedConnection[fieldKey] = value;
      }
      return cleanedConnection;
    },
    {}
  );

  return cleanedConnection;
}
115844
private void validateSQLFields()
	{

		boolean flag = controller.isEnableSQLDatabaseOutput();

		enableSQLDatabaseConnection.setSelected(flag);

		sqlHostLabel.setEnabled(flag);
		sqlHostField.setEnabled(flag);
		sqlDatabaseLabel.setEnabled(flag);
		sqlDatabaseField.setEnabled(flag);
		sqlUserLabel.setEnabled(flag);
		sqlUserField.setEnabled(flag);
		sqlPasswordLabel.setEnabled(flag);
		sqlPasswordField.setEnabled(flag);

		enableZipEncodingCheckBox.setEnabled(flag);
	}
211023
protected void validateConnections(ManagedConnectionFactory managedConnectionFactory, boolean prepopulateEnabled) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "validateConnections", gConfigProps.cfName);
        }

        /*
         * Get all of the managed connections wrappers.
         */
        Set<ManagedConnection> mcSet = new HashSet<ManagedConnection>();
        LinkedList<MCWrapper> failedMCWList = new LinkedList<MCWrapper>();
        mcToMCWMapWrite.lock();
        try {
            Collection<MCWrapper> mcWrappers = mcToMCWMap.values();
            Iterator<MCWrapper> mcWrapperIt = mcWrappers.iterator();
            while (mcWrapperIt.hasNext()) {
                MCWrapper mcw = mcWrapperIt.next();
                if (mcw.getPoolState() == 1 && !mcw.isStale()) {
                    /*
                     * Only add valid managed connections to this set.
                     */
                    mcSet.add(mcw.getManagedConnection());
                    mcw.setPoolState(50); // set the state to 50, which basically means we are interacting with the resource adapter
                    try {
                        Set<?> set = ((ValidatingManagedConnectionFactory) managedConnectionFactory).getInvalidConnections(mcSet);
                        Iterator<?> it = set.iterator();

                        while (it.hasNext()) {
                            it.next();
                            failedMCWList.add(mcw);
                        }
                        mcSet.clear();
                    } catch (ResourceException e) {
                        Object[] parms = new Object[] { "fatalErrorNotification", CommonFunction.exceptionList(e), "ResourceException", gConfigProps.cfName };
                        Tr.error(tc, "ATTEMPT_TO_VALIDATE_MC_CONNECTIONS_J2CA0285", parms);
                    } finally {
                        // we do a check above to ensure we are in the free pool (1), therefore we shouldn't have to worry
                        // about capturing the current state and setting it back here - it is expected to be the free pool.
                        mcw.setPoolState(MCWrapper.ConnectionState_freePool);
                    }

                    if (prepopulateEnabled) {
                        // We prepopulate is enabled, we need to reset
                        // the idle time out to keep the good connections
                        // in the pool.  All of the bad connection will be
                        // destored before we leave this method.  The idle
                        // time will not matter for them.  :-)
                        ((com.ibm.ejs.j2c.MCWrapper) mcw).resetIdleTimeOut();
                    }
                }
            }
        } finally {
            mcToMCWMapWrite.unlock();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(this, tc, "Calling getInvalidConnections on the managedConnectionFactory with " + mcSet.size()
                               + " managed connections");
        }
        /*
         * Ask the mcf to validate the managed connections and return the
         * failing managed connections
         */

        if (!failedMCWList.isEmpty()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(this, tc, "Returned from getInvalidConnections. There are " + failedMCWList.size() + " failing connections.");
            }
            /*
             * Check for failing connections
             */
            /*
             * Transfer the failing connection to an iterator
             */
            Iterator<MCWrapper> it = failedMCWList.iterator();
            /*
             * Iterate through the failed managed connection marking the
             * associated mcw stale
             */
            while (it.hasNext()) {
                MCWrapper mcWrapper = it.next();
                if (mcWrapper != null) {
                    mcWrapper.markStale();
                    checkForConnectionInFreePool(mcWrapper);
                } else {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(this, tc, "null mc in set returned from getInvalidConnections");
                    }
                }
            }
        } else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(this, tc, "Returned from getInvalidConnections. The returned set is null");
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "validateConnections");
        }
    }
782258
function validateNewCredentialProperties (credentialConfig, credentialDetail) {
  // Tmp — horrible hack to remove.
  const credentialDetails = JSON.parse(JSON.stringify(credentialDetail));
  delete credentialDetails.scopes;

  const validationResult = validate(credentialConfig, credentialDetails);
  if (!validationResult.isValid) {
    return Promise.reject(new Error(validationResult.error));
  };

  return Promise.resolve(credentialDetails);
}
881968
function validateObject(job, object, callback) {
		if (typeof object.value === 'undefined') {
			var onLoad = function (err, obj) {
				if (err) {
					job.error = err;
					return callback(err);
				}
				object.value = obj;
				doValidateObject(job, object, callback);
			};
			var opts = {
				timeout: (job.context.options.timeout || 5000)
			};
			//TODO verify http:, file: and plain paths all load properly
			if (object.path) {
				loader.loadPath(object.path, opts, onLoad);
			}
			else if (object.url) {
				loader.load(object.url, opts, onLoad);
			}
			else {
				callback(new Error('object missing value, path or url'));
			}
		}
		else {
			doValidateObject(job, object, callback);
		}
	}
1048019
private void onCleanup(Object connection)
    {
        // if not running within transaction boundary
        if (this.connection != null)
        {
            if (settings != null)
            {
                ((Jedis) connection).configResetStat();
            }
            factory.releaseConnection((Jedis) this.connection);
        }

        this.connection = null;
    }
43067
function getSchema(connection) {
  connection.maxRows = Number.MAX_SAFE_INTEGER;
  const driver = drivers[connection.driver];
  return driver.getSchema(connection);
}
955974
function stripConnectionHeaders(req) {
  var conn = req.getHeader("connection");
  if (typeof(conn) === 'undefined' || conn === null)
    return;

  conn.split(/\s+/g).forEach(function(header) {
    if (header.length === 0)
      return;
    req.removeHeader(header);
  });
  req.removeHeader("connection");
}
813303
function(_connection) {
    return function() {
      // Destroyed state return
      if (self.state === DESTROYED || self.state === DESTROYING) {
        // Remove the connection from the list
        removeConnection(self, _connection);
        return _connection.destroy();
      }

      // Destroy all event emitters
      handlers.forEach(function(e) {
        _connection.removeAllListeners(e);
      });

      // Add the final handlers
      _connection.once('close', connectionFailureHandler(self, 'close'));
      _connection.once('error', connectionFailureHandler(self, 'error'));
      _connection.once('timeout', connectionFailureHandler(self, 'timeout'));
      _connection.once('parseError', connectionFailureHandler(self, 'parseError'));

      // Signal
      reauthenticate(self, _connection, function(err) {
        if (self.state === DESTROYED || self.state === DESTROYING) {
          return _connection.destroy();
        }
        // Remove the connection from the connectingConnections list
        removeConnection(self, _connection);

        // Handle error
        if (err) {
          return _connection.destroy();
        }

        // If we are c at the moment
        // Do not automatially put in available connections
        // As we need to apply the credentials first
        if (self.authenticating) {
          self.nonAuthenticatedConnections.push(_connection);
        } else {
          // Push to available
          self.availableConnections.push(_connection);
          // Execute any work waiting
          _execute(self)();
        }
      });
    };
  }
702803
function (connection, attempt) {
  var clonedAttempt = EJSON.clone(attempt);
  clonedAttempt.connection = connection;
  return clonedAttempt;
}
855361
function _checkConnection(conn) {
  // Return Promise for getConnection callback wrapping
  return new Promise((resolve, reject) => {
    if (conn) {
      resolve(conn);
    } else {
      _pool.getConnection((err, conn) => {
        if (err) reject(err); // Reject this error
        else resolve(conn); // Resolve the connection
      })
    }
  });
}
365996
function validate (errObj, request, schema, location, allowUnknown, context) {
  if (!request || !schema) return;

  var joiOptions = {
    context: context || request,
    allowUnknown: allowUnknown,
    abortEarly: false
  };

  Joi.validate(request, schema, joiOptions, function (errors, value) {
    if (!errors || errors.details.length === 0) {
      assignIn(request, value); // joi responses are parsed into JSON
      return;
    }
    errors.details.forEach(function (error) {
      var errorExists = find(errObj, function (item) {
        if (item && item.field === error.path && item.location === location) {
          item.messages.push(error.message);
          item.types.push(error.type);
          return item;
        }
        return;
      });

      if (!errorExists) {
        errObj.push({
          field: error.path,
          location: location,
          messages: [error.message],
          types: [error.type]
        });
      }

    });
  });
}
316369
void connectionCloses(final Session connection) {
        synchronized (connections) {
            final ExecutorService executorService = connectionThreads.get(connection);
            if (executorService != null) {
                executorService.shutdownNow();
            }
            connectionThreads.remove(connection);
            connections.remove(connection);
        }
    }
1165572
function validate(cmd, args, info) {
  AbstractCommand.prototype.validate.apply(this, arguments);
  var index = parseInt(args[0]);
  if(isNaN(index) || index < 0 || index >= info.conf.databases) {
    throw DatabaseIndex;
  }
  // update the index with the integer value
  // connection expects an integer
  args[0] = index;
}
120094
function onConnectionError(err) {
        var codeName = errors.classify(err);

        var loggerInfo = conn.extendLogInfo({
            error: err
        });

        if (codeName === 'Timeout' ||
            codeName === 'NetworkError') {
            self.logger.warn('Got a connection error', loggerInfo);
        } else {
            self.logger.error('Got an unexpected connection error', loggerInfo);
        }
        delete self.serverConnections[socketRemoteAddr];
    }
943608
public void evictConnection(Connection connection)
   {
      ProxyConnection proxyConnection = (ProxyConnection) connection;
      proxyConnection.cancelLeakTask();

      try {
         softEvictConnection(proxyConnection.getPoolEntry(), "(connection evicted by user)", !connection.isClosed() /* owner */);
      }
      catch (SQLException e) {
         // unreachable in HikariCP, but we're still forced to catch it
      }
   }
310867
function ReconnectingConnection(id, connection) {
  this.id = id;
  this.connection = null;
  this.closed = false;
  this.queue = [];

  this.setConnection(connection);
}