Search in sources :

Example 11 with EntityManager

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);
}
Also used : EntityManager(javax.persistence.EntityManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with EntityManager

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);
}
Also used : Inject(javax.inject.Inject) TckRepository(org.eclipse.che.commons.test.tck.repository.TckRepository) Provider(javax.inject.Provider) EntityManagerFactory(javax.persistence.EntityManagerFactory) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Collection(java.util.Collection) PasswordEncryptor(org.eclipse.che.security.PasswordEncryptor) EntityManager(javax.persistence.EntityManager) TckRepositoryException(org.eclipse.che.commons.test.tck.repository.TckRepositoryException) Transactional(com.google.inject.persist.Transactional) EntityManager(javax.persistence.EntityManager) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl)

Example 13 with EntityManager

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();
}
Also used : StackPersistedEvent(org.eclipse.che.api.workspace.server.event.StackPersistedEvent) EntityManager(javax.persistence.EntityManager) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Example 14 with EntityManager

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) BeforeStackRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeStackRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 15 with EntityManager

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;
}
Also used : EntityManager(javax.persistence.EntityManager) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Aggregations

EntityManager (javax.persistence.EntityManager)1395 Test (org.junit.Test)876 Priority (org.hibernate.envers.test.Priority)249 Query (javax.persistence.Query)200 TestForIssue (org.hibernate.testing.TestForIssue)97 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)87 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)79 List (java.util.List)69 NoResultException (javax.persistence.NoResultException)65 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)63 EntityManagerFactory (javax.persistence.EntityManagerFactory)56 HashMap (java.util.HashMap)50 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)50 ArrayList (java.util.ArrayList)41 PersistenceException (javax.persistence.PersistenceException)40 EntityNotFoundException (javax.persistence.EntityNotFoundException)39 Transactional (com.google.inject.persist.Transactional)38 EntityTransaction (javax.persistence.EntityTransaction)36 Item (org.hibernate.jpa.test.Item)36 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)34