<commit_before>package edu.ucar.unidata.rosetta.repository;

import edu.ucar.unidata.rosetta.domain.RosettaProperties;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

/**
 * Implementation of a properties DAO.
 *
 * @author <EMAIL>
 */
public class JdbcPropertiesDao extends JdbcDaoSupport implements PropertiesDao {

    protected static Logger logger = Logger.getLogger(JdbcPropertiesDao.class);

    private SimpleJdbcInsert insertActor;

    /**
     * Looks up and retrieves the persisted uploads directory.
     *
     * @return The persisted uploads directory.
     * @throws DataRetrievalFailureException  If unable to lookup uploads directory.
     */
    @Override
    public String lookupUploadDirectory() throws DataRetrievalFailureException {
        String sql = "SELECT * FROM properties WHERE propertyKey = 'uploadDir'";
        List<RosettaProperties> properties = getJdbcTemplate().query(sql, new JdbcPropertiesDao.DataMapper());
        if (properties.isEmpty()) {
            String message = "Unable to find persisted Rosetta properties";
            logger.error(message);
            throw new DataRetrievalFailureException(message);
        }
        return properties.get(0).getPropertyValue();
    }

    /**
     * Looks up and retrieves the persisted downloads directory.
     *
     * @return The persisted downloads directory.
     */
    public String lookupDownloadDirectory() {
        String sql = "SELECT * FROM properties WHERE propertyKey = 'downloadDir'";
        List<RosettaProperties> properties = getJdbcTemplate().query(sql, new JdbcPropertiesDao.DataMapper());
        if (properties.isEmpty()) {
            String message = "Unable to find persisted Rosetta properties";
            logger.error(message);
            throw new DataRetrievalFailureException(message);
        }
        return properties.get(0).getPropertyValue();
    }

    /**
     * This DataMapper only used by JdbcPropertiesDao.
     */
    private static class DataMapper implements RowMapper<RosettaProperties> {
        /**
         * Maps each row of rosettaProperties in the ResultSet to the RosettaProperties object.
         *
         * @param rs  The ResultSet to be mapped.
         * @param rowNum  The number of the current row.
         * @return  The populated RosettaProperties object.
         * @throws SQLException  If an SQLException is encountered getting column values.
         */<commit_msg>corrects key name for property lookup<commit_after>package edu.ucar.unidata.rosetta.repository;

import edu.ucar.unidata.rosetta.domain.RosettaProperties;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

/**
 * Implementation of a properties DAO.
 *
 * @author <EMAIL>
 */
public class JdbcPropertiesDao extends JdbcDaoSupport implements PropertiesDao {

    protected static Logger logger = Logger.getLogger(JdbcPropertiesDao.class);

    private SimpleJdbcInsert insertActor;

    /**
     * Looks up and retrieves the persisted uploads directory.
     *
     * @return The persisted uploads directory.
     * @throws DataRetrievalFailureException  If unable to lookup uploads directory.
     */
    @Override
    public String lookupUploadDirectory() throws DataRetrievalFailureException {
        String sql = "SELECT * FROM properties WHERE propertyKey = 'rosetta.uploadDir'";
        List<RosettaProperties> properties = getJdbcTemplate().query(sql, new JdbcPropertiesDao.DataMapper());
        if (properties.isEmpty()) {
            String message = "Unable to find persisted Rosetta properties";
            logger.error(message);
            throw new DataRetrievalFailureException(message);
        }
        return properties.get(0).getPropertyValue();
    }

    /**
     * Looks up and retrieves the persisted downloads directory.
     *
     * @return The persisted downloads directory.
     */
    public String lookupDownloadDirectory() {
        String sql = "SELECT * FROM properties WHERE propertyKey = 'rosetta.downloadDir'";
        List<RosettaProperties> properties = getJdbcTemplate().query(sql, new JdbcPropertiesDao.DataMapper());
        if (properties.isEmpty()) {
            String message = "Unable to find persisted Rosetta properties";
            logger.error(message);
            throw new DataRetrievalFailureException(message);
        }
        return properties.get(0).getPropertyValue();
    }

    /**
     * This DataMapper only used by JdbcPropertiesDao.
     */
    private static class DataMapper implements RowMapper<RosettaProperties> {
        /**
         * Maps each row of rosettaProperties in the ResultSet to the RosettaProperties object.
         *
         * @param rs  The ResultSet to be mapped.
         * @param rowNum  The number of the current row.
         * @return  The populated RosettaProperties object.
         * @throws SQLException  If an SQLException is encountered getting column values.
         */
{'fraction_non_alphanumeric': 0.08172902288412641, 'fraction_numerical': 0.0010897203051216855, 'mean_word_length': 3.171969696969697, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5650198', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1396, 'n_words': 399}