<commit_before>package edu.ucla.cens.awserver.dao;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import edu.ucla.cens.awserver.datatransfer.AwRequest;

/**
 * Utility DAO for checking a version_id exists for a campaign. The version_id is used to group all of the groups of prompts for a
 * particular campaign. The idea is that over time a campaign may need to change it's prompt structure. A version_id allows for 
 * data historicity.
 * 
 * @author selsky
 */
public class PromptVersionIdDao extends AbstractDao {
	private static Logger _logger = Logger.getLogger(PromptVersionIdDao.class);
	
	private final String _selectSql = "select campaign_prompt_version.id from campaign_prompt_version, campaign" +
			                          " where campaign_prompt_version.version_id = ?" +
			                          " and campaign.subdomain = ? " +
			                          " and campaign.id = campaign_prompt_version.id;";
	
	/**
	 * Creates an instance of this class that will use the supplied DataSource for data retrieval.
	 */
	public PromptVersionIdDao(DataSource dataSource) {
		super(dataSource);
	}
	
	public void execute(AwRequest request) {
		_logger.info("looking up prompt version_id");
		
		JdbcTemplate template = new JdbcTemplate(getDataSource());
		
		try {
			
			template.queryForInt(_selectSql, new Object[]{request.getAttribute("versionId"), request.getAttribute("subdomain")});
			
		} catch (IncorrectResultSizeDataAccessException irse) { // this exception is thrown if the queryForInt call returns
			                                                    // anything else but one row
			
			request.setFailedRequest(true);
			
		} catch (org.springframework.dao.DataAccessException dae) {
			
			throw new DataAccessException(dae); // Wrap the Spring exception and re-throw in order to avoid outside dependencies
			                                    // on the Spring Exception (in case Spring JDBC is replaced with another lib in 
			                                    // the future).
		}
	}
}
<commit_msg>added comments and fixed buggy SQL<commit_after>package edu.ucla.cens.awserver.dao;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import edu.ucla.cens.awserver.datatransfer.AwRequest;

/**
 * Utility DAO for checking if a version_id exists for a campaign. The version_id is used to group all of the groups of prompts for
 * a particular campaign. The idea is that over time a campaign may need to change it's prompt structure. A version_id allows for 
 * data historicity. Note that the version_id sent by the phone for data uploads is not the primary key for the campaign_prompt_version
 * table. The version_id sent by the phone is shared with the phone's config file.
 * 
 * @author selsky
 */
public class PromptVersionIdDao extends AbstractDao {
	private static Logger _logger = Logger.getLogger(PromptVersionIdDao.class);
	
	private final String _selectSql = "select campaign_prompt_version.id from campaign_prompt_version, campaign" +
			                          " where campaign_prompt_version.version_id = ?" +
			                          " and campaign.subdomain = ? " +
			                          " and campaign.id = campaign_prompt_version.campaign_id;";
	
	/**
	 * Creates an instance of this class that will use the supplied DataSource for data retrieval.
	 */
	public PromptVersionIdDao(DataSource dataSource) {
		super(dataSource);
	}
	
	public void execute(AwRequest request) {
		_logger.info("looking up prompt version_id for phone version id " + request.getAttribute("versionId") + " in campaign " +
				request.getAttribute("subdomain"));
		
		JdbcTemplate template = new JdbcTemplate(getDataSource());
		
		try {
			
			int campaignPromptVersionId = template.queryForInt(
				_selectSql, new Object[]{request.getAttribute("versionId"), request.getAttribute("subdomain")}
		    );
			// Push the id into the request because it will be used by future queries
			request.setAttribute("campaignPromptVersionId", campaignPromptVersionId);
			
		} catch (IncorrectResultSizeDataAccessException irse) { // this exception is thrown if the queryForInt call returns
			                                                    // anything else but one row
			
			request.setFailedRequest(true);
			
		} catch (org.springframework.dao.DataAccessException dae) {
			
			throw new DataAccessException(dae); // Wrap the Spring exception and re-throw in order to avoid outside dependencies
			                                    // on the Spring Exception (in case Spring JDBC is replaced with another lib in 
			                                    // the future).
		}
	}
}

{'fraction_non_alphanumeric': 0.07255262620069487, 'fraction_numerical': 0.0004087471898630697, 'mean_word_length': 2.91207034372502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '412276', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1228, 'n_words': 416}