Search in sources :

Example 36 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaProfileDao method getById.

@Override
@Transactional
public ProfileImpl getById(String userId) throws NotFoundException, ServerException {
    requireNonNull(userId, "Required non-null id");
    try {
        final EntityManager manager = managerProvider.get();
        final ProfileImpl profile = manager.find(ProfileImpl.class, userId);
        if (profile == null) {
            throw new NotFoundException(format("Couldn't find profile for user with id '%s'", userId));
        }
        manager.refresh(profile);
        return profile;
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 37 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaProfileDao method doCreate.

@Transactional
protected void doCreate(ProfileImpl profile) {
    EntityManager manager = managerProvider.get();
    manager.persist(profile);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) Transactional(com.google.inject.persist.Transactional)

Example 38 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaUserDao method doCreate.

@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(UserImpl user) throws ConflictException, ServerException {
    EntityManager manage = managerProvider.get();
    manage.persist(user);
    manage.flush();
    eventService.publish(new PostUserPersistedEvent(new UserImpl(user))).propagateException();
}
Also used : EntityManager(javax.persistence.EntityManager) PostUserPersistedEvent(org.eclipse.che.api.user.server.event.PostUserPersistedEvent) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Transactional(com.google.inject.persist.Transactional)

Example 39 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaUserDao method doUpdate.

@Transactional
protected void doUpdate(UserImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    final UserImpl user = manager.find(UserImpl.class, update.getId());
    if (user == null) {
        throw new NotFoundException(format("Couldn't update user with id '%s' because it doesn't exist", update.getId()));
    }
    final String password = update.getPassword();
    if (password != null) {
        update.setPassword(encryptor.encrypt(password));
    } else {
        update.setPassword(user.getPassword());
    }
    manager.merge(update);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 40 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaUserDao method getByAliasAndPassword.

@Override
@Transactional
public UserImpl getByAliasAndPassword(String emailOrName, String password) throws NotFoundException, ServerException {
    requireNonNull(emailOrName, "Required non-null email or name");
    requireNonNull(password, "Required non-null password");
    try {
        final UserImpl user = managerProvider.get().createNamedQuery("User.getByAliasAndPassword", UserImpl.class).setParameter("alias", emailOrName).getSingleResult();
        if (!encryptor.test(password, user.getPassword())) {
            throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
        }
        return erasePassword(user);
    } catch (NoResultException x) {
        throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Aggregations

Transactional (com.google.inject.persist.Transactional)51 EntityManager (javax.persistence.EntityManager)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)16 ServerException (org.eclipse.che.api.core.ServerException)12 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)6 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)5 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)4 NoResultException (javax.persistence.NoResultException)4 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 Timestamp (java.sql.Timestamp)3 AccountImpl (org.eclipse.che.account.spi.AccountImpl)3 FactoryImpl (org.eclipse.che.api.factory.server.model.impl.FactoryImpl)3 DateTime (org.joda.time.DateTime)3 TaskBean (com.linkedin.thirdeye.datalayer.pojo.TaskBean)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EntityTransaction (javax.persistence.EntityTransaction)2 Query (javax.persistence.Query)2