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

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

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

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

/**
 * DAO for checking campaign existence. The subdomain from the initial request URI is used to attempt lookup of a campaign id. 
 * 
 * @author selsky
 */
public class CampaignExistsDao extends AbstractDao {
	private static Logger _logger = Logger.getLogger(CampaignExistsDao.class);
	private static final String _selectSql = "select id from campaign where subdomain = ?";
	
	/**
	 * 
	 */
	public CampaignExistsDao(DataSource dataSource) {
		super(dataSource);
	}
	
	/**
	 * Checks the db for the existence of a user represented by a user name and a subdomain found in the AwRequest.
	 * If a user is found, the campaigns that user belongs to are placed in the AwRequest payload Map.
	 */
	public void execute(AwRequest request) {
		_logger.info("executing campaign existence check against subdomain " + request.getPayload().get("subdomain"));
		
		JdbcTemplate template = new JdbcTemplate(getDataSource());
		
		try {

			Map<String, Object> map = request.getPayload();
			map.put("results", template.query(_selectSql, 
					                          new Object[]{map.get("subdomain")}, 
					                          new QueryRowMapper()));
			
		} catch (org.springframework.dao.DataAccessException dae) {
			
			throw new DataAccessException(dae); // wrap the Spring exception and re-throw in order to avoid dependencies
			                                    // on the Spring Exception in case we want to replace the data layer
		}
	}

	/**
	 * Maps a query ResultSet to a TestResult object. Used by JdbcTemplate. 
	 * 
	 * @author selsky<commit_msg>changed log messages from INFO to DEBUG<commit_after>package edu.ucla.cens.awserver.dao;

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

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

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

/**
 * DAO for checking campaign existence. The subdomain from the initial request URI is used to attempt lookup of a campaign id. 
 * This class relies on Spring JDBC (specifically JdbcTemplate) to handle boilerplate JDBC activities.
 * 
 * @author selsky
 */
public class CampaignExistsDao extends AbstractDao {
	private static Logger _logger = Logger.getLogger(CampaignExistsDao.class);
	private static final String _selectSql = "select id from campaign where subdomain = ?";
	
	/**
	 * 
	 */
	public CampaignExistsDao(DataSource dataSource) {
		super(dataSource);
	}
	
	/**
	 * Checks the db for the existence of a user represented by a user name and a subdomain found in the AwRequest.
	 * If a user is found, the campaigns that user belongs to are placed in the AwRequest payload Map.
	 */
	public void execute(AwRequest request) {
		if(_logger.isDebugEnabled()) {
			_logger.debug("executing campaign existence check against subdomain " + request.getPayload().get("subdomain"));
		}
		
		JdbcTemplate template = new JdbcTemplate(getDataSource());
		
		try {

			Map<String, Object> map = request.getPayload();
			map.put("results", template.query(_selectSql, 
					                          new Object[]{map.get("subdomain")}, 
					                          new QueryRowMapper()));
			
		} catch (org.springframework.dao.DataAccessException dae) {
			
			throw new DataAccessException(dae); // wrap the Spring exception and re-throw in order to avoid dependencies
			                                    // on the Spring Exception in case we want to replace the data layer
		}
	}

	/**
	 * Maps a query ResultSet to a TestResult object. Used by JdbcTemplate. 
	 * 
	 * @author selsky
{'fraction_non_alphanumeric': 0.08755644756648269, 'fraction_numerical': 0.0005017561465127947, 'mean_word_length': 3.2870967741935484, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1212518', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1067, 'n_words': 367}