10,7 → 10,7 |
import ch.ffhs.webE.domain.*; |
|
public class UserDAOImpl implements UserDAO { |
|
|
@SessionTarget |
Session session; |
@TransactionTarget |
18,14 → 18,14 |
|
@SuppressWarnings("unchecked") |
@Override |
public List<User> listUser() { |
List<User> courses = null; |
public List<User> listUser() { |
List<User> user = null; |
try { |
courses = session.createQuery("from User").list(); |
user = session.createQuery("from User").list(); |
} catch (Exception e) { |
e.printStackTrace(); |
} |
return courses; |
} |
return user; |
} |
|
@Override |
35,25 → 35,40 |
} catch (Exception e) { |
transaction.rollback(); |
e.printStackTrace(); |
} |
} |
} |
|
|
/** |
* Used to delete a user. |
*/ |
@Override |
public void deleteUser(int userId) { |
try { |
User user = (User) session.get(User.class, userId); |
session.delete(user); |
} catch (Exception e) { |
transaction.rollback(); |
e.printStackTrace(); |
} |
} |
|
/** |
* Returns a single user with this user name (used for login) |
* @param username: String - entire user name |
* @return User: Returns a user object if something is found. If not, null is returned |
* |
* @param username |
* : String - entire user name |
* @return User: Returns a user object if something is found. If not, null |
* is returned |
*/ |
public User searchUsername(String username) { |
User user = null; |
|
|
try { |
user = (User) session.createQuery( |
"FROM User " + |
"WHERE username = :username") |
.setParameter("username", username) |
.uniqueResult(); |
user = (User) session |
.createQuery("FROM User " + "WHERE username = :username") |
.setParameter("username", username).uniqueResult(); |
} catch (Exception e) { |
//TODO: Log error |
// TODO: Log error |
} |
return user; |
} |