use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.
the class SchedulerServiceDatabaseImpl method hasTransaction.
@Override
public boolean hasTransaction(String source) throws SchedulerServiceDatabaseException {
EntityManager em = null;
try {
em = emf.createEntityManager();
String orgId = securityService.getOrganization().getId();
Query q = em.createNamedQuery("Transaction.findBySource").setParameter("source", source).setParameter("org", orgId);
q.getSingleResult();
return true;
} catch (NoResultException e) {
return false;
} catch (Exception e) {
logger.error("Could not retrieve transaction with source '{}': {}", source, getStackTrace(e));
throw new SchedulerServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.
the class SchedulerServiceDatabaseImpl method touchLastEntry.
@Override
public void touchLastEntry(String agentId) throws SchedulerServiceDatabaseException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
LastModifiedDto entity = em.find(LastModifiedDto.class, agentId);
if (entity == null) {
entity = new LastModifiedDto();
entity.setCaptureAgentId(agentId);
entity.setLastModifiedDate(new Date());
em.persist(entity);
} else {
entity.setLastModifiedDate(new Date());
em.merge(entity);
}
tx.commit();
} catch (Exception e) {
if (tx.isActive())
tx.rollback();
logger.error("Could not updated last modifed date of agent {} status: {}", agentId, getStackTrace(e));
throw new SchedulerServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.
the class SchedulerServiceDatabaseImpl method getTransactions.
@Override
@SuppressWarnings("unchecked")
public List<String> getTransactions() throws SchedulerServiceDatabaseException {
EntityManager em = null;
try {
em = emf.createEntityManager();
String orgId = securityService.getOrganization().getId();
Query q = em.createNamedQuery("Transaction.findAll").setParameter("org", orgId);
List<TransactionDto> resultList = q.getResultList();
return $(resultList).map(new Fn<TransactionDto, String>() {
@Override
public String apply(TransactionDto trx) {
return trx.getId();
}
}).toList();
} catch (Exception e) {
logger.error("Could not retrieve transactions: {}", getStackTrace(e));
throw new SchedulerServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.
the class SchedulerServiceDatabaseImpl method countQuarterConfirmedResponses.
public long countQuarterConfirmedResponses() throws SchedulerServiceDatabaseException {
EntityManager em = null;
try {
em = emf.createEntityManager();
Query q = em.createNamedQuery("ExtendedEvent.countConfirmedByDateRange");
setDateForQuarterQuery(q);
Number countResult = (Number) q.getSingleResult();
return countResult.longValue();
} catch (Exception e) {
throw new SchedulerServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.
the class SchedulerServiceDatabaseImpl method storeTransaction.
@Override
public void storeTransaction(String id, String source) throws SchedulerServiceDatabaseException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
Opt<TransactionDto> entityOpt = getTransactionDto(id, em);
TransactionDto entity = entityOpt.getOr(new TransactionDto());
if (entityOpt.isNone()) {
entity.setId(id);
entity.setOrganization(securityService.getOrganization().getId());
entity.setSource(source);
entity.setLastModifiedDate(new Date());
em.persist(entity);
} else {
entity.setLastModifiedDate(new Date());
em.merge(entity);
}
tx.commit();
} catch (Exception e) {
logger.error("Could not store transaction: {}", getStackTrace(e));
if (tx.isActive())
tx.rollback();
throw new SchedulerServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
Aggregations