use of javax.persistence.EntityManager in project che by eclipse.
the class JpaUserDaoTest method setup.
@BeforeMethod
public void setup() throws Exception {
EntityManager entityManager = mock(EntityManager.class);
when(entityManager.createNamedQuery(anyString(), anyObject())).thenReturn(typedQuery);
when(managerProvider.get()).thenReturn(entityManager);
when(typedQuery.setMaxResults(anyInt())).thenReturn(typedQuery);
when(typedQuery.setFirstResult(anyInt())).thenReturn(typedQuery);
when(typedQuery.setFirstResult(anyInt())).thenReturn(typedQuery);
}
use of javax.persistence.EntityManager in project che by eclipse.
the class UserJpaTckRepository method createAll.
@Override
public void createAll(Collection<? extends UserImpl> entities) throws TckRepositoryException {
final EntityManager manager = managerProvider.get();
entities.stream().map(user -> new UserImpl(user.getId(), user.getEmail(), user.getName(), encryptor.encrypt(user.getPassword()), user.getAliases())).forEach(manager::persist);
}
use of javax.persistence.EntityManager in project che by eclipse.
the class JpaStackDao method doCreate.
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(StackImpl stack) throws ConflictException, ServerException {
if (stack.getWorkspaceConfig() != null) {
stack.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
}
EntityManager manager = managerProvider.get();
manager.persist(stack);
manager.flush();
eventService.publish(new StackPersistedEvent(stack)).propagateException();
}
use of javax.persistence.EntityManager in project che by eclipse.
the class JpaStackDao method doRemove.
@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(String id) throws ServerException {
final EntityManager manager = managerProvider.get();
final StackImpl stack = manager.find(StackImpl.class, id);
if (stack != null) {
eventService.publish(new BeforeStackRemovedEvent(new StackImpl(stack))).propagateException();
manager.remove(stack);
manager.flush();
}
}
use of javax.persistence.EntityManager in project che by eclipse.
the class JpaStackDao method doUpdate.
@Transactional
protected StackImpl doUpdate(StackImpl update) throws NotFoundException {
final EntityManager manager = managerProvider.get();
if (manager.find(StackImpl.class, update.getId()) == null) {
throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId()));
}
if (update.getWorkspaceConfig() != null) {
update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
}
StackImpl merged = manager.merge(update);
manager.flush();
return merged;
}
Aggregations