Search in sources :

Example 16 with SchedulerServiceDatabaseException

use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.

the class SchedulerServiceDatabaseImpl method getLastModified.

@Override
public Date getLastModified(String agentId) throws NotFoundException, SchedulerServiceDatabaseException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        LastModifiedDto entity = em.find(LastModifiedDto.class, agentId);
        if (entity == null)
            throw new NotFoundException("Agent with ID " + agentId + " does not exist");
        return entity.getLastModifiedDate();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not retrieve last modified date for agent with id '{}': {}", agentId, getStackTrace(e));
        throw new SchedulerServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 17 with SchedulerServiceDatabaseException

use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.

the class SchedulerServiceDatabaseImpl method deleteTransaction.

@Override
public void deleteTransaction(String id) throws NotFoundException, SchedulerServiceDatabaseException {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        Opt<TransactionDto> entity = getTransactionDto(id, em);
        if (entity.isNone())
            throw new NotFoundException("Transaction with ID " + id + " does not exist");
        em.remove(entity.get());
        tx.commit();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not delete transaction with id '{}': {}", id, getStackTrace(e));
        if (tx.isActive())
            tx.rollback();
        throw new SchedulerServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

EntityManager (javax.persistence.EntityManager)17 NoResultException (javax.persistence.NoResultException)17 SchedulerServiceDatabaseException (org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException)17 NotFoundException (org.opencastproject.util.NotFoundException)17 Query (javax.persistence.Query)10 EntityTransaction (javax.persistence.EntityTransaction)4 Date (java.util.Date)3 Fn (com.entwinemedia.fn.Fn)1 HashMap (java.util.HashMap)1