package hu.prf.messaging.dao;

import java.util.List;
import java.util.logging.Logger;

import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.TypedQuery;

import hu.prf.messaging.entity.User;
import hu.prf.messaging.util.Session;

@Named
public class UserDAO extends GenericDAO<User, Long> {

	private static final long serialVersionUID = -5859058016736013679L;

	@Inject
	private Logger logger;

	@Inject
	private Session session;

	public UserDAO() {
		super(User.class);
	}

	public List<User> findByEmailAndPassword(String email, String password) {
		StringBuilder queryBuilder = new StringBuilder();
		queryBuilder.append("select ");
		queryBuilder.append("	u ");
		queryBuilder.append("from ");
		queryBuilder.append("	User u ");
		queryBuilder.append("where ");
		queryBuilder.append("	u.email = :email and u.password = :password");

		TypedQuery<User> query = getEntityManager().createQuery(queryBuilder.toString(), getEntityClass());
		query.setParameter("email", email);
		query.setParameter("password", password);
		return query.getResultList();
	}

	public List<User> listOtherUsers() {
		User loggedInUser = session.getUser();
		TypedQuery<User> q = getEntityManager().createQuery("select u from User u where u.id <> :id order by u.name", User.class);
		q.setParameter("id", loggedInUser.getId());
		logger.severe("ASDQWEQWEQWE; " + q.toString() + "; " + loggedInUser.getId());
		return q.getResultList();
	}

}

@@ -51,42 +51,8 @@
 st;%0A
-import java.util.logging.Logger;%0A%0A
 impo
@@ -139,17 +139,16 @@
 dQuery;%0A
-%0A
 import h
@@ -351,42 +351,8 @@
 L;%0A%0A
-%09@Inject%0A%09private Logger logger;%0A%0A
 %09@In
@@ -1265,88 +1265,8 @@
 ));%0A
-%09%09logger.severe(%22ASDQWEQWEQWE; %22 + q.toString() + %22; %22 + loggedInUser.getId());%0A
 %09%09re

debug message removed