use of javax.persistence.EntityTransaction in project opencast by opencast.
the class OrganizationDatabaseImpl method deleteOrganization.
/**
* @see org.opencastproject.kernel.security.persistence.OrganizationDatabase#deleteOrganization(java.lang.String)
*/
@Override
public void deleteOrganization(String orgId) throws OrganizationDatabaseException, NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
JpaOrganization organization = getOrganizationEntity(orgId, em);
if (organization == null)
throw new NotFoundException("Organization " + orgId + " does not exist");
em.remove(organization);
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not delete organization: {}", e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new OrganizationDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of javax.persistence.EntityTransaction in project opencast by opencast.
the class MailService method updateEmailConfiguration.
public EmailConfiguration updateEmailConfiguration(EmailConfiguration emailConfiguration) throws MailServiceException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
String orgId = securityService.getOrganization().getId();
EmailConfigurationDto emailConfig = mergeEmailConfiguration(emailConfiguration, orgId, em);
tx.commit();
EmailConfiguration updatedEmailConfiguration = emailConfig.toEmailConfiguration();
updateSmtpConfiguration(updatedEmailConfiguration);
return updatedEmailConfiguration;
} catch (Exception e) {
logger.error("Could not update email configuration '{}': {}", emailConfiguration, e.getMessage());
if (tx.isActive())
tx.rollback();
throw new MailServiceException(e);
} finally {
if (em != null)
em.close();
}
}
use of javax.persistence.EntityTransaction in project opencast by opencast.
the class TranscriptionJobControlDto method store.
/**
* Store new job control
*/
public static TranscriptionJobControlDto store(EntityManager em, String mediaPackageId, String trackId, String transcriptionJobId, String jobStatus, long trackDuration) throws TranscriptionDatabaseException {
TranscriptionJobControlDto dto = new TranscriptionJobControlDto(mediaPackageId, trackId, transcriptionJobId, new Date(), null, jobStatus, trackDuration);
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
em.persist(dto);
tx.commit();
return dto;
} catch (Exception e) {
if (tx.isActive()) {
tx.rollback();
}
throw new TranscriptionDatabaseException(e);
} finally {
em.close();
}
}
use of javax.persistence.EntityTransaction in project opencast by opencast.
the class ThemesServiceDatabaseImpl method deleteTheme.
@Override
public void deleteTheme(long id) throws ThemesServiceDatabaseException, NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
ThemeDto themeDto = getThemeDto(id, em);
if (themeDto == null)
throw new NotFoundException("No theme with id=" + id + " exists");
tx = em.getTransaction();
tx.begin();
em.remove(themeDto);
tx.commit();
messageSender.sendObjectMessage(ThemeItem.THEME_QUEUE, MessageSender.DestinationType.Queue, ThemeItem.delete(id));
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not delete theme '{}': {}", id, ExceptionUtils.getStackTrace(e));
if (tx.isActive())
tx.rollback();
throw new ThemesServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of javax.persistence.EntityTransaction in project opencast by opencast.
the class CaptureAgentStateServiceImpl method deleteAgentFromDatabase.
/**
* Removes an agent from the database.
*
* @param agentName
* The name of the agent you wish to remove.
*/
private void deleteAgentFromDatabase(String agentName) throws NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
String org = securityService.getOrganization().getId();
Agent existing = getAgentEntity(agentName, org, em);
if (existing == null)
throw new NotFoundException();
em.remove(existing);
tx.commit();
agentCache.invalidate(agentName.concat(DELIMITER).concat(org));
} catch (RollbackException e) {
logger.warn("Unable to commit to DB in deleteAgent.");
} finally {
if (em != null)
em.close();
}
}
Aggregations