Search in sources :

Example 41 with Transactional

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

the class JpaUserDao method getAll.

@Override
@Transactional
public Page<UserImpl> getAll(int maxItems, long skipCount) throws ServerException {
    // TODO need to ensure that 'getAll' query works with same data as 'getTotalCount'
    checkArgument(maxItems >= 0, "The number of items to return can't be negative.");
    checkArgument(skipCount >= 0 && skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be negative or greater than " + Integer.MAX_VALUE);
    try {
        final List<UserImpl> list = managerProvider.get().createNamedQuery("User.getAll", UserImpl.class).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(JpaUserDao::erasePassword).collect(toList());
        return new Page<>(list, skipCount, maxItems, getTotalCount());
    } 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) Page(org.eclipse.che.api.core.Page) Transactional(com.google.inject.persist.Transactional)

Example 42 with Transactional

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

the class JpaSshDao method doCreate.

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

Example 43 with Transactional

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

the class JpaSshDao method doRemove.

@Transactional
protected void doRemove(String owner, String service, String name) throws NotFoundException {
    EntityManager manager = managerProvider.get();
    SshPairImpl entity = manager.find(SshPairImpl.class, new SshPairPrimaryKey(owner, service, name));
    if (entity == null) {
        throw new NotFoundException(format("Ssh pair with service '%s' and name '%s' was not found.", service, name));
    }
    manager.remove(entity);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 44 with Transactional

use of com.google.inject.persist.Transactional in project pinot by linkedin.

the class TaskManagerImpl method deleteRecordsOlderThanDaysWithStatus.

@Override
@Transactional
public int deleteRecordsOlderThanDaysWithStatus(int days, TaskStatus status) {
    DateTime expireDate = new DateTime().minusDays(days);
    Timestamp expireTimestamp = new Timestamp(expireDate.getMillis());
    Predicate timestampPredicate = Predicate.LT("createTime", expireTimestamp);
    Predicate statusPredicate = Predicate.EQ("status", status.toString());
    List<TaskBean> list = genericPojoDao.get(Predicate.AND(statusPredicate, timestampPredicate), TaskBean.class);
    for (TaskBean bean : list) {
        deleteById(bean.getId());
    }
    return list.size();
}
Also used : TaskBean(com.linkedin.thirdeye.datalayer.pojo.TaskBean) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate) Transactional(com.google.inject.persist.Transactional)

Example 45 with Transactional

use of com.google.inject.persist.Transactional in project pinot by linkedin.

the class TaskManagerImpl method findByStatusNotIn.

@Override
@Transactional
public List<TaskDTO> findByStatusNotIn(TaskStatus status) {
    Predicate statusPredicate = Predicate.NEQ("status", status.toString());
    List<TaskBean> list = genericPojoDao.get(statusPredicate, TaskBean.class);
    List<TaskDTO> result = new ArrayList<>();
    for (TaskBean bean : list) {
        result.add((TaskDTO) MODEL_MAPPER.map(bean, TaskDTO.class));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) TaskBean(com.linkedin.thirdeye.datalayer.pojo.TaskBean) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate) 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