<commit_before>/*  Copyright (C) 2011  <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package io;
import java.awt.Image;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.InvalidParameterException;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
/**
 * Class for database communication.
 */
public class MySQL{
	HashMap<String, PreparedStatement> prepStmts = new HashMap<String, PreparedStatement>();
	protected static Logger logger = Logger.getLogger(MySQL.class.getName());
	Connection cn = null;
	Properties mySqlProps;
	int retries = 0;
	private static int MAX_RETRY = 3; // reconnect attempts
	private static int RETRY_WAIT = 5000;	// time to wait between reconnect attempts, in milliseconds
	private static int VALID_CHECK_TIME_OUT = 10; // time to wait for a response when validating connection, in seconds

	public MySQL(Properties mySqlProps){
		this.mySqlProps = mySqlProps;
	}

	/**
	 * Initialize the class, preparing the statements needed for the methods.
	 */
	public void init(){
		addPrepStmt("filterState"		, "SELECT status FROM filter WHERE  id = ?");
		addPrepStmt("addFilter"			, "INSERT IGNORE INTO filter (id, board, reason, status) VALUES (?,?,?,?)");
		addPrepStmt("pendingFilter"		, "SELECT board, reason, id FROM filter WHERE status = 1 ORDER BY board, reason ASC");
		addPrepStmt("updateFilter"		, "UPDATE filter SET status = ? WHERE id = ?");
		addPrepStmt("addCache"			, "REPLACE INTO cache SET id=?, timestamp=?");
		addPrepStmt("addThumb"			, "INSERT INTO thumbs (url, filename, thumb) VALUES(?,?,?)");
		addPrepStmt("getThumb"			, "SELECT thumb FROM thumbs WHERE url = ? ORDER BY filename ASC");
		addPrepStmt("sizeCache"			, "SELECT count(*) FROM cache");
		addPrepStmt("sizeFilter"		, "SELECT count(*) FROM filter");
		addPrepStmt("pending"			, "SELECT count(*) FROM filter WHERE status = 1");
		addPrepStmt("isCached"			, "SELECT timestamp FROM `cache` WHERE `id` = ?");
		addPrepStmt("isArchive"			, "SELECT * FROM `archive` WHERE `hash` = ?");
		addPrepStmt("isDnw"				, "SELECT * FROM `dnw` WHERE `hash` = ?");
		addPrepStmt("prune"				, "DELETE FROM `cache` WHERE `timestamp` < ?");
		addPrepStmt("isHashed"			, "SELECT hash FROM `hash` WHERE `hash` = ?");
		addPrepStmt("addHash"			, "INSERT INTO hash (hash, dir, filename, size) VALUES (?,?,?,?)");
		addPrepStmt("deleteHash"		, "DELETE FROM hash WHERE hash = ?");
		addPrepStmt("deleteFilter"		, "DELETE FROM filter WHERE id = ?");
		addPrepStmt("deleteDnw"			, "DELETE FROM dnw WHERE hash = ?");
		addPrepStmt("deleteBlock"		, "DELETE FROM block WHERE hash = ?");
		addPrepStmt("deleteArchive"		, "DELETE FROM archive WHERE hash = ?");
		addPrepStmt("isBlacklisted"		, "SELECT * FROM `block` WHERE `hash` = ?");
		addPrepStmt("addDirectory"		, "INSERT INTO dirlist (dirpath) VALUES (?)",PreparedStatement.RETURN_GENERATED_KEYS);
		addPrepStmt("getDirectory"		, "SELECT id FROM dirlist WHERE dirpath = ?");
		addPrepStmt("addFilename"		, "INSERT INTO filelist (filename) VALUES (?)",PreparedStatement.RETURN_GENERATED_KEYS);
		addPrepStmt("getFilename"		, "SELECT id FROM filelist WHERE filename = ?");
	}

	public void reconnect(){<commit_msg>moved SQL statements to MySQLaid<commit_after>/*  Copyright (C) 2011  <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package io;
import java.awt.Image;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.InvalidParameterException;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
/**
 * Class for database communication.
 */
public class MySQL{
	HashMap<String, PreparedStatement> prepStmts = new HashMap<String, PreparedStatement>();
	protected static Logger logger = Logger.getLogger(MySQL.class.getName());
	Connection cn = null;
	Properties mySqlProps;
	int retries = 0;
	private static int MAX_RETRY = 3; // reconnect attempts
	private static int RETRY_WAIT = 5000;	// time to wait between reconnect attempts, in milliseconds
	private static int VALID_CHECK_TIME_OUT = 10; // time to wait for a response when validating connection, in seconds

	public MySQL(Properties mySqlProps){
		this.mySqlProps = mySqlProps;
	}

	/**
	 * Initialize the class, preparing the statements needed for the methods.
	 */
	public void init(){
		addPrepStmt("addCache"			, "REPLACE INTO cache SET id=?, timestamp=?");
		addPrepStmt("addThumb"			, "INSERT INTO thumbs (url, filename, thumb) VALUES(?,?,?)");
		addPrepStmt("getThumb"			, "SELECT thumb FROM thumbs WHERE url = ? ORDER BY filename ASC");
		addPrepStmt("sizeCache"			, "SELECT count(*) FROM cache");
		addPrepStmt("sizeFilter"		, "SELECT count(*) FROM filter");
		addPrepStmt("pending"			, "SELECT count(*) FROM filter WHERE status = 1");
		addPrepStmt("isCached"			, "SELECT timestamp FROM `cache` WHERE `id` = ?");
		addPrepStmt("isArchive"			, "SELECT * FROM `archive` WHERE `hash` = ?");
		addPrepStmt("isDnw"				, "SELECT * FROM `dnw` WHERE `hash` = ?");
		addPrepStmt("prune"				, "DELETE FROM `cache` WHERE `timestamp` < ?");
		addPrepStmt("isHashed"			, "SELECT hash FROM `hash` WHERE `hash` = ?");
		addPrepStmt("addHash"			, "INSERT INTO hash (hash, dir, filename, size) VALUES (?,?,?,?)");
		addPrepStmt("deleteHash"		, "DELETE FROM hash WHERE hash = ?");
		addPrepStmt("deleteFilter"		, "DELETE FROM filter WHERE id = ?");
		addPrepStmt("deleteDnw"			, "DELETE FROM dnw WHERE hash = ?");
		addPrepStmt("deleteBlock"		, "DELETE FROM block WHERE hash = ?");
		addPrepStmt("deleteArchive"		, "DELETE FROM archive WHERE hash = ?");
		addPrepStmt("isBlacklisted"		, "SELECT * FROM `block` WHERE `hash` = ?");
		addPrepStmt("addDirectory"		, "INSERT INTO dirlist (dirpath) VALUES (?)",PreparedStatement.RETURN_GENERATED_KEYS);
		addPrepStmt("getDirectory"		, "SELECT id FROM dirlist WHERE dirpath = ?");
		addPrepStmt("addFilename"		, "INSERT INTO filelist (filename) VALUES (?)",PreparedStatement.RETURN_GENERATED_KEYS);
		addPrepStmt("getFilename"		, "SELECT id FROM filelist WHERE filename = ?");
	}

	public void reconnect(){
{'fraction_non_alphanumeric': 0.11890813910008725, 'fraction_numerical': 0.0036146080019942664, 'mean_word_length': 4.619047619047619, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462815', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2420, 'n_words': 798}