<commit_before>package model.dao;
import static tools.Replace.ENTER;
import static tools.Replace.PATTERN;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.db.Template;
import model.entity.Module;
import model.entity.Student;
import model.mapping.StudentMapping;

import org.skife.csv.CSVReader;
import org.skife.csv.SimpleReader;

public class StudentDAO {
	private Template template = new Template();
	private CSVReader reader = new SimpleReader();
	
	public boolean save(Student student){
		String sql = "INSERT INTO student"		+ENTER+
							"			(student_id, " +
							"			 first_name, "+
							"			 last_name, "+
							"			 email, " 		+
							"			 project_title, " +
							"			 project_description, " +
							"			 supervisor, "+
							"			 username, "+
							"			 password, "+
							"			 module_id)"		 +ENTER+
							"values"							 +ENTER+
							"			(?,?,?,?,?,?,?,?,?,?)";
		try {
			return (template.update(sql, student.getStudent_id(), 
													student.getFirst_name(),
													student.getLast_name(),
													student.getEmail(),
													student.getProject_title(),
													student.getProject_description(),
													student.getSupervisor(),
													student.getUsername(),
													student.getPassword(),
													student.getModule_id()) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Save opertaion failed !");
		}
		return false;
	}
	
	
	public boolean update(Student student){
		String sql = "update student"									+ENTER+
							"set"														+ENTER+
							"			 first_name= ?, "+
							"			 last_name= ?, "+
							"			 email= ?, " 		+
							"			 project_title= ?, " +
							"			 project_description= ?, " +
							"			 supervisor= ?, "+
							"			 username= ?, "+
							"			 password= ?, "+
							"			 module_id= ?"					+ENTER+
							"where"											+ENTER+
							"			student_id = ?";
		try {
			return (template.update(sql, student.getFirst_name(),
															student.getLast_name(),
															student.getEmail(),
															student.getProject_title(),
															student.getProject_description(),
															student.getSupervisor(),
															student.getUsername(),
															student.getPassword(),
															student.getModule_id(),
															student.getStudent_id()) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Update opertaion failed !");
		}
		return false;
	}
	
	public boolean deleteByID(int ID){
		String sql = "delete from student where student_id = '"+ID+"'";
		try {
			return (template.update(sql) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Delete opertaion failed !");
		}
		return false;
	}
	
	public boolean deleteByName(String firstName, String lastName){
		String sql = "delete from student where first_name = " + "'"+firstName+ "'" + 
																"and last_name = " + "'"+lastName+"'";			
		try {
			return (template.update(sql) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Delete opertaion failed !");
		}
		return false;
	}
	
	public Student findByStudentID(int ID){
		String sql = "SELECT  * " + 
							"FROM student " + 
							"WHERE student_id= " + "'" + ID + "'";
		List<Student> students = null;
		try {
			students = template.query(sql, new StudentMapping());
		} catch (ClassNotFoundException e) {
		e.printStackTrace();<commit_msg>delete all students by module_id<commit_after>package model.dao;
import static tools.Replace.ENTER;
import static tools.Replace.PATTERN;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.db.Template;
import model.entity.Module;
import model.entity.Student;
import model.mapping.StudentMapping;

import org.skife.csv.CSVReader;
import org.skife.csv.SimpleReader;

public class StudentDAO {
	private Template template = new Template();
	private CSVReader reader = new SimpleReader();
	
	public boolean save(Student student){
		String sql = "INSERT INTO student"		+ENTER+
							"			(student_id, " +
							"			 first_name, "+
							"			 last_name, "+
							"			 email, " 		+
							"			 project_title, " +
							"			 project_description, " +
							"			 supervisor, "+
							"			 username, "+
							"			 password, "+
							"			 module_id)"		 +ENTER+
							"values"							 +ENTER+
							"			(?,?,?,?,?,?,?,?,?,?)";
		try {
			return (template.update(sql, student.getStudent_id(), 
													student.getFirst_name(),
													student.getLast_name(),
													student.getEmail(),
													student.getProject_title(),
													student.getProject_description(),
													student.getSupervisor(),
													student.getUsername(),
													student.getPassword(),
													student.getModule_id()) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Save opertaion failed !");
		}
		return false;
	}
	
	
	public boolean update(Student student){
		String sql = "update student"									+ENTER+
							"set"														+ENTER+
							"			 first_name= ?, "+
							"			 last_name= ?, "+
							"			 email= ?, " 		+
							"			 project_title= ?, " +
							"			 project_description= ?, " +
							"			 supervisor= ?, "+
							"			 username= ?, "+
							"			 password= ?, "+
							"			 module_id= ?"					+ENTER+
							"where"											+ENTER+
							"			student_id = ?";
		try {
			return (template.update(sql, student.getFirst_name(),
															student.getLast_name(),
															student.getEmail(),
															student.getProject_title(),
															student.getProject_description(),
															student.getSupervisor(),
															student.getUsername(),
															student.getPassword(),
															student.getModule_id(),
															student.getStudent_id()) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Update opertaion failed !");
		}
		return false;
	}
	
	public boolean deleteByID(int ID){
		String sql = "delete from student where student_id = '"+ID+"'";
		try {
			return (template.update(sql) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Delete opertaion failed !");
		}
		return false;
	}
	
	public boolean deleteByName(String firstName, String lastName){
		String sql = "delete from student where first_name = " + "'"+firstName+ "'" + 
																"and last_name = " + "'"+lastName+"'";			
		try {
			return (template.update(sql) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Delete opertaion failed !");
		}
		return false;
	}
	
	public boolean deleteALLByModuleId(int ID){
		String sql = "delete from student where module_id = '"+ID+"'";
		try {
			return (template.update(sql) == 1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Class not found !");
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Delete opertaion failed !");
		}
		return false;
	}
	
	public Student findByStudentID(int ID){
		String sql = "SELECT  * " + 
							"FROM student " + 
							"WHERE student_id= " + "'" + ID + "'";
		List<Student> students = null;
		try {
			students = template.query(sql, new StudentMapping());
		} catch (ClassNotFoundException e) {
		e.printStackTrace();
{'fraction_non_alphanumeric': 0.1398067517595133, 'fraction_numerical': 0.0010736013360372182, 'mean_word_length': 2.454470539761022, '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': '3602131', 'n_tokens_mistral': 3648, 'n_tokens_neox': 2520, 'n_words': 525}