<commit_before>package com.laytonsmith.persistance;

import com.laytonsmith.PureUtilities.DaemonManager;
import com.laytonsmith.PureUtilities.StringUtils;
import com.laytonsmith.annotations.datasource;
import com.laytonsmith.core.CHVersion;
import com.laytonsmith.persistance.io.ConnectionMixin;
import com.laytonsmith.persistance.io.ConnectionMixinFactory;
import java.io.IOException;
import java.net.URI;
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.HashSet;
import java.util.Set;

/**
 *
 * @author lsmith
 */
@datasource("sqlite")
public class SQLiteDataSource extends AbstractDataSource{
	
	/* These values may not be changed without creating an upgrade routine */
	private static final String KEY_COLUMN = "key";
	private static final String VALUE_COLUMN = "value";
	private static final String TABLE_NAME = "persistance";
	Connection connection;
	String path;
	ConnectionMixin mixin;
	
	private SQLiteDataSource(){
		
	}
	public SQLiteDataSource(URI uri, ConnectionMixinFactory.ConnectionMixinOptions options) throws DataSourceException{
		super(uri, options);		
		mixin = getConnectionMixin();		
		try {
			try{
				Class.forName("org.sqlite.JDBC");
				path = mixin.getPath();
				connect();
				Statement statement = connection.createStatement();
				statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + TABLE_NAME + "` (`" + KEY_COLUMN + "` TEXT PRIMARY KEY,"
						+ " `" + VALUE_COLUMN + "` TEXT)");
			}finally {
				disconnect();
			}
		} catch (Exception ex) {
			throw new DataSourceException("An error occured while setting up a connection to the SQLite database", ex);
		} 
	}
	
	/**
	 * All calls to connect must have a corresponding call to disconnect() in
	 * a finally block.
	 */
	private void connect() throws IOException, SQLException{
		connection = DriverManager.getConnection("jdbc:sqlite:" + mixin.getPath());		
	}
	
	private void disconnect() throws SQLException{
		if(connection != null){
			connection.close();
		}
	}

	public Set<String[]> keySet() throws DataSourceException{
		try{
			try {<commit_msg>Don't hardcode the connection name<commit_after>package com.laytonsmith.persistance;

import com.laytonsmith.PureUtilities.DaemonManager;
import com.laytonsmith.PureUtilities.StringUtils;
import com.laytonsmith.annotations.datasource;
import com.laytonsmith.core.CHVersion;
import com.laytonsmith.persistance.io.ConnectionMixin;
import com.laytonsmith.persistance.io.ConnectionMixinFactory;
import java.io.IOException;
import java.net.URI;
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.HashSet;
import java.util.Set;

/**
 *
 * @author lsmith
 */
@datasource("sqlite")
public class SQLiteDataSource extends AbstractDataSource{
	
	/* These values may not be changed without creating an upgrade routine */
	private static final String KEY_COLUMN = "key";
	private static final String VALUE_COLUMN = "value";
	private static final String TABLE_NAME = "persistance";
	Connection connection;
	String path;
	ConnectionMixin mixin;
	
	private SQLiteDataSource(){
		
	}
	public SQLiteDataSource(URI uri, ConnectionMixinFactory.ConnectionMixinOptions options) throws DataSourceException{
		super(uri, options);		
		mixin = getConnectionMixin();		
		try {
			try{
				Class.forName(org.sqlite.JDBC.class.getName());
				path = mixin.getPath();
				connect();
				Statement statement = connection.createStatement();
				statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + TABLE_NAME + "` (`" + KEY_COLUMN + "` TEXT PRIMARY KEY,"
						+ " `" + VALUE_COLUMN + "` TEXT)");
			}finally {
				disconnect();
			}
		} catch (Exception ex) {
			throw new DataSourceException("An error occured while setting up a connection to the SQLite database", ex);
		} 
	}
	
	/**
	 * All calls to connect must have a corresponding call to disconnect() in
	 * a finally block.
	 */
	private void connect() throws IOException, SQLException{
		connection = DriverManager.getConnection("jdbc:sqlite:" + mixin.getPath());		
	}
	
	private void disconnect() throws SQLException{
		if(connection != null){
			connection.close();
		}
	}

	public Set<String[]> keySet() throws DataSourceException{
		try{
			try {
{'fraction_non_alphanumeric': 0.10658520027155464, 'fraction_numerical': 0.0, 'mean_word_length': 4.673940949935815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1371895', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1286, 'n_words': 344}