19,13 → 19,13 |
@SuppressWarnings("unchecked") |
@Override |
public List<User> listUser() { |
List<User> courses = null; |
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 |
39,19 → 39,34 |
} |
|
/** |
* 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 |
} |