package edu.uci.lighthouse.model.jpa;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import edu.uci.lighthouse.model.LighthouseEvent;

public class LHEventDAO extends AbstractDAO<LighthouseEvent, Integer> {

	public List<LighthouseEvent> executeQueryEntitiesAndTime(
			Map<String, Date> parameters) {
		String strQuery = "SELECT event " + "FROM LighthouseEvent event "
				+ "WHERE ";
		strQuery += " ( ";
		for (Map.Entry<String, Date> entry : parameters.entrySet()) {
			String fqn = entry.getKey();
			Date timestamp = entry.getValue();
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String strTimestamp = formatter.format(timestamp);
			strQuery += " ( ";
			strQuery += "event.entity" + " = " + "'" + fqn + "'";
			strQuery += " AND ";
			strQuery += "event.timestamp" + " >= " + "'" + strTimestamp + "'" ;
			strQuery += " ) ";
			strQuery += "OR ";
		}
		strQuery = strQuery.substring(0, strQuery.lastIndexOf("OR"));
		strQuery += " )";
		return executeDynamicQuery(strQuery);
	}
	
}

@@ -267,16 +267,226 @@
 eger%3E %7B%0D
+%0A%09%0D%0A%09@Override%0D%0A%09public LighthouseEvent save(LighthouseEvent entity) throws JPAUtilityException %7B%0D%0A%09%09Date timestamp = getCurrentTimestamp();%0D%0A%09%09entity.setTimestamp(timestamp);%0D%0A%09%09return super.save(entity);%0D%0A%09%7D%0D
 %0A%0D%0A%09publ
@@ -874,16 +874,23 @@
 eFormat(
+%0D%0A%09%09%09%09%09
 %22yyyy-MM
@@ -1135,17 +1135,16 @@
 mp + %22'%22
- 
 ;%0D%0A%09%09%09st
@@ -1320,14 +1320,692 @@
 );%0D%0A%09%7D%0D%0A
-
 %09%0D%0A
+%09public void updateCommittedEvents(List%3CString%3E listClazz, String authorName) %7B%0D%0A%09%09String command = %09%22UPDATE LighthouseEvent e %22 +%0D%0A%09%09%09%09%09%09%09%22SET e.committed = 1 %22 +%0D%0A%09%09%09%09%09%09%09%22WHERE e.author.name = %22 + %22'%22 + authorName + %22'%22 + %22 %22 +%0D%0A%09%09%09%09%09%09%09%22AND e.entity.fullyQualifiedName IN ( %22 +%0D%0A%09%09%09%09%09%09%09%22SELECT rel.primaryKey.from %22 +%0D%0A%09%09%09%09%09%09%09%22FROM LighthouseRelationship rel %22 +%0D%0A%09%09%09%09%09%09%09%22WHERE rel.primaryKey.type = 0 %22;%0D%0A%09%09command+= %22AND ( %22;%0D%0A%09%09for (String fqnClazz : listClazz) %7B%0D%0A%09%09%09command+= %22rel.primaryKey.to = %22 + %22'%22 + fqnClazz + %22'%22;%0D%0A%09%09%09command+= %22 OR %22;%0D%0A%09%09%7D%0D%0A%09%09command = command.substring(0, command.lastIndexOf(%22OR%22));%0D%0A%09%09command += %22 ) )%22;%0D%0A%09%09executeUpdateQuery(command);%0D%0A%09%7D%0D%0A
 %7D%0D%0A

create method updateCommittedEvents()