* org.apache.james.user.lib.AbstractUsersRepository#doAddUser(java.lang.String, java.lang.String)
*/
protected void doAddUser(String username, String password) throws UsersRepositoryException {
String lowerCasedUsername = username.toLowerCase();
if (contains(lowerCasedUsername)) {
throw new UsersRepositoryException(lowerCasedUsername + " already exists.");
}
EntityManager entityManager = entityManagerFactory.createEntityManager();
final EntityTransaction transaction = entityManager.getTransaction();
try {
transaction.begin();
JPAUser user = new JPAUser(lowerCasedUsername, password, algo);
entityManager.persist(user);
transaction.commit();
} catch (PersistenceException e) {
getLogger().debug("Failed to save user", e);
if (transaction.isActive()) {
transaction.rollback();
}
throw new UsersRepositoryException("Failed to add user" + username, e);
} finally {
entityManager.close();
}
}