Closes connection, copies DB file, and opens again pointing to new file

        **Note** if filename equals current filename, does nothing!
557646
def _do_save_as(self, filename):
        
        if filename != self.filename:
            self._ensure_filename()
            self._close_if_open()
            shutil.copyfile(self.filename, filename)
            self.__get_conn(filename=filename)
1311009
public void commit() throws IOException {
        // assures we perform the close operation only once.
        if (open.compareAndSet(true, false)) {
            // flush & close
            fout.force(true);
            fout.close();

            // if the current file exists, and append is true, then append samples and remove temp file
            // otherwise write header and move tmp file to target
            boolean exists = Files.exists(target);
            if (logger.isInfoEnabled()) {
                logger.info("Finishing recording ...... append: " + append + " exists: " + exists + " target:" + target);
            }
            if (append && exists) {
                appendSamples(target, temp);
                writeHeader(target);
                Files.delete(temp);
            } else {
                writeHeader(temp);
                Files.move(temp, target, StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }
230058
def close( self ):
        
        if self.db is not None:
            self.db.commit()
            self.db.close()
            self.db = None

        return
23994
def Close(self):
    
    if not self._connection:
      raise RuntimeError('Cannot close database not opened.')

    # We need to run commit or not all data is stored in the database.
    self._connection.commit()
    self._connection.close()

    self._connection = None
    self._cursor = None
    self.filename = None
    self.read_only = None
1333625
public void close() throws IOException {
    try {
      if (OGlobalConfiguration.FILE_LOCK.getValueAsBoolean())
        unlock();
      if (channel != null && channel.isOpen()) {
        channel.close();
        channel = null;
      }

      if (accessFile != null) {
        accessFile.close();
        accessFile = null;
      }

    } catch (Exception e) {
      OLogManager.instance().error(this, "Error on closing file " + osFile.getAbsolutePath(), e, OIOException.class);
    }
  }
227747
@Override
	public void close() throws IOException {
		try {
			upload.executeBatch();
			batchCount = 0;
			upload.close();
			dbConn.close();
		} catch (SQLException sqe) {
			throw new IllegalArgumentException("close() failed:\t", sqe);
		}
	}
402110
@Override
  public void closeImpl() throws IOException
  {
    unlock();

    _fileChannel = null;

    RandomAccessFile file = _file;
    _file = null;

    if (file != null)
      file.close();
  }
765069
public void close() throws IOException {
        try {
            if (conn != null) conn.close();

            conn = null;
            mysqlInput = null;
            mysqlOutput = null;
        } catch (SQLException e) {
            logger.warn("Unable to close connection", e);
        }
    }
241329
@Override
	public void close() throws IOException {
		if (upload != null) {
			flush();
			// close the connection
			try {
				upload.close();
			} catch (SQLException e) {
				LOG.info("JDBC statement could not be closed: " + e.getMessage());
			} finally {
				upload = null;
			}
		}

		if (dbConn != null) {
			try {
				dbConn.close();
			} catch (SQLException se) {
				LOG.info("JDBC connection could not be closed: " + se.getMessage());
			} finally {
				dbConn = null;
			}
		}
	}
54374
function _tryReconnect(dbInfo) {
    _deferReadiness(dbInfo);

    var dbContext = dbContexts[dbInfo.name];
    var forages = dbContext.forages;

    for (var i = 0; i < forages.length; i++) {
        var forage = forages[i];
        if (forage._dbInfo.db) {
            forage._dbInfo.db.close();
            forage._dbInfo.db = null;
        }
    }
    dbInfo.db = null;

    return _getOriginalConnection(dbInfo).then(function (db) {
        dbInfo.db = db;
        if (_isUpgradeNeeded(dbInfo)) {
            // Reopen the database for upgrading.
            return _getUpgradedConnection(dbInfo);
        }
        return db;
    }).then(function (db) {
        // store the latest db reference
        // in case the db was upgraded
        dbInfo.db = dbContext.db = db;
        for (var i = 0; i < forages.length; i++) {
            forages[i]._dbInfo.db = db;
        }
    })["catch"](function (err) {
        _rejectReadiness(dbInfo, err);
        throw err;
    });
}
1227740
public void open(Connection conn, String fileName, final int serverId, boolean nonBlocking) throws IOException {
        open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, nonBlocking);
    }
477187
function saveFile() {
      if (currentFile) {
        if (!currentFile.oldName) {
          currentFile.oldName = possibleOldName;
        }

        if (!currentFile.newName) {
          currentFile.newName = possibleNewName;
        }

        if (currentFile.newName) {
          files.push(currentFile);
          currentFile = null;
        }
      }

      possibleOldName = undefined;
      possibleNewName = undefined;
    }
1039450
def create_new_connection(options, &block)
      if @connection
        logger.debug("[WinRM] shutting previous connection #{@connection}")
        @connection.close
      end

      @connection_options = options
      @connection = Connection.new(options, &block)
    end
936865
def __verify_db_file_existence(self, database_path):
        

        self.__validate_db_path(database_path)
        if not os.path.isfile(os.path.realpath(database_path)):
            raise IOError("file not found: " + database_path)

        try:
            connection = sqlite3.connect(database_path)
        except sqlite3.OperationalError as e:
            raise OperationalError(e)

        connection.close()
562116
def check_file(filename=None, show_filename=False, add_semicolon=False):
    
    # either work with sys.stdin or open the file
    if filename is not None:
        with open(filename, "r") as filelike:
            sql_string = filelike.read()
    else:
        with sys.stdin as filelike:
            sql_string = sys.stdin.read()

    success, msg = check_string(sql_string, add_semicolon=add_semicolon)

    # report results
    result = 0
    if not success:
        # possibly show the filename with the error message
        prefix = ""
        if show_filename and filename is not None:
            prefix = filename + ": "
        print(prefix + msg)
        result = 1

    return result
4428
public void lock() throws H2DBLockException {
        try {
            final File dir = settings.getDataDirectory();
            lockFile = new File(dir, "odc.update.lock");
            checkState();
            int ctr = 0;
            do {
                try {
                    if (!lockFile.exists() && lockFile.createNewFile()) {
                        file = new RandomAccessFile(lockFile, "rw");
                        lock = file.getChannel().lock();
                        file.writeBytes(magic);
                        file.getChannel().force(true);
                        Thread.sleep(20);
                        file.seek(0);
                        final String current = file.readLine();
                        if (current != null && !current.equals(magic)) {
                            lock.close();
                            lock = null;
                            LOGGER.debug("Another process obtained a lock first ({})", Thread.currentThread().getName());
                        } else {
                            addShutdownHook();
                            final Timestamp timestamp = new Timestamp(System.currentTimeMillis());
                            LOGGER.debug("Lock file created ({}) {} @ {}", Thread.currentThread().getName(), magic, timestamp.toString());
                        }
                    }
                } catch (IOException | InterruptedException ex) {
                    LOGGER.trace("Expected error as another thread has likely locked the file", ex);
                } finally {
                    if (lock == null && file != null) {
                        try {
                            file.close();
                            file = null;
                        } catch (IOException ex) {
                            LOGGER.trace("Unable to close the lock file", ex);
                        }
                    }
                }
                if (lock == null || !lock.isValid()) {
                    try {
                        final Timestamp timestamp = new Timestamp(System.currentTimeMillis());
                        LOGGER.debug("Sleeping thread {} ({}) for {} seconds because an exclusive lock on the database could not be obtained ({})",
                                Thread.currentThread().getName(), magic, SLEEP_DURATION / 1000, timestamp.toString());
                        Thread.sleep(SLEEP_DURATION);
                    } catch (InterruptedException ex) {
                        LOGGER.debug("sleep was interrupted.", ex);
                        Thread.currentThread().interrupt();
                    }
                }
            } while (++ctr < MAX_SLEEP_COUNT && (lock == null || !lock.isValid()));
            if (lock == null || !lock.isValid()) {
                throw new H2DBLockException("Unable to obtain the update lock, skipping the database update. Skippinig the database update.");
            }
        } catch (IOException ex) {
            throw new H2DBLockException(ex.getMessage(), ex);
        }
    }
834317
function createNewFile(db, fileName, fileReadStream, options, cb) {
  defaultLogger.debug("In createNewFile");
  createFileWithVersion(db, fileName, fileReadStream, constants.LOWEST_VERSION, options, cb);
}