2013-04-11 20:49:08 +02:00
|
|
|
package com.commafeed.backend.dao;
|
|
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
import org.hibernate.SessionFactory;
|
2013-05-21 09:17:12 +02:00
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
import com.commafeed.backend.model.QUser;
|
2013-04-11 20:49:08 +02:00
|
|
|
import com.commafeed.backend.model.User;
|
|
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
@Singleton
|
2013-04-11 20:49:08 +02:00
|
|
|
public class UserDAO extends GenericDAO<User> {
|
|
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
private QUser user = QUser.user;
|
2013-04-12 10:29:34 +02:00
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
@Inject
|
2014-08-08 16:49:02 +02:00
|
|
|
public UserDAO(SessionFactory sessionFactory) {
|
|
|
|
|
super(sessionFactory);
|
|
|
|
|
}
|
2013-07-25 09:17:33 +02:00
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
public User findByName(String name) {
|
2015-07-09 12:34:54 +02:00
|
|
|
return query().selectFrom(user).where(user.name.equalsIgnoreCase(name)).fetchOne();
|
2013-04-11 20:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-01 21:56:59 +02:00
|
|
|
public User findByApiKey(String key) {
|
2015-07-09 12:34:54 +02:00
|
|
|
return query().selectFrom(user).where(user.apiKey.equalsIgnoreCase(key)).fetchOne();
|
2013-05-01 21:56:59 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-20 21:53:13 +02:00
|
|
|
public User findByEmail(String email) {
|
2015-07-09 12:34:54 +02:00
|
|
|
return query().selectFrom(user).where(user.email.equalsIgnoreCase(email)).fetchOne();
|
2013-05-20 21:53:13 +02:00
|
|
|
}
|
2014-08-11 05:33:00 +02:00
|
|
|
|
|
|
|
|
public long count() {
|
2015-07-09 12:34:54 +02:00
|
|
|
return query().selectFrom(user).fetchCount();
|
2014-08-11 05:33:00 +02:00
|
|
|
}
|
2013-04-11 20:49:08 +02:00
|
|
|
}
|