use of javax.persistence.EntityTransaction in project opencast by opencast.
the class SchedulerServiceDatabaseImpl method deleteEvent.
@Override
public void deleteEvent(String mediapackageId) throws NotFoundException, SchedulerServiceDatabaseException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
Opt<ExtendedEventDto> entity = getExtendedEventDto(mediapackageId, em);
if (entity.isNone()) {
throw new NotFoundException("Event with ID " + mediapackageId + " does not exist");
}
em.remove(entity.get());
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
if (tx.isActive())
tx.rollback();
logger.error("Could not delete extended event: {}", getStackTrace(e));
throw new SchedulerServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of javax.persistence.EntityTransaction in project joynr by bmwcarit.
the class DiscoveryEntryStorePersisted method add.
/*
* (non-Javadoc)
* @see io.joynr.capabilities.CapabilitiesStore#add(io.joynr.
* capabilities .DiscoveryEntry)
*/
@Override
public synchronized void add(DiscoveryEntry discoveryEntry) {
logger.debug("adding discovery entry: {}", discoveryEntry);
if (!(discoveryEntry instanceof GlobalDiscoveryEntryPersisted)) {
return;
}
GlobalDiscoveryEntryPersisted globalDiscoveryEntry = (GlobalDiscoveryEntryPersisted) discoveryEntry;
if (globalDiscoveryEntry.getDomain() == null || globalDiscoveryEntry.getInterfaceName() == null || globalDiscoveryEntry.getParticipantId() == null || globalDiscoveryEntry.getAddress() == null) {
String message = "discoveryEntry being registered is not complete: " + discoveryEntry;
logger.error(message);
throw new JoynrCommunicationException(message);
}
GlobalDiscoveryEntryPersisted discoveryEntryFound = entityManager.find(GlobalDiscoveryEntryPersisted.class, discoveryEntry.getParticipantId());
EntityTransaction transaction = entityManager.getTransaction();
try {
transaction.begin();
if (discoveryEntryFound != null) {
entityManager.merge(discoveryEntry);
} else {
entityManager.persist(discoveryEntry);
}
transaction.commit();
} catch (Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
logger.error("unable to add discoveryEntry: " + discoveryEntry, e);
}
}
use of javax.persistence.EntityTransaction in project joynr by bmwcarit.
the class DiscoveryEntryStorePersisted method touch.
@Override
public void touch(String clusterControllerId) {
String query = "from GlobalDiscoveryEntryPersisted where clusterControllerId=:clusterControllerId";
EntityTransaction transaction = entityManager.getTransaction();
try {
transaction.begin();
@SuppressWarnings("unchecked") List<DiscoveryEntry> capabilitiesList = entityManager.createQuery(query).setParameter("clusterControllerId", clusterControllerId).getResultList();
for (DiscoveryEntry discoveryEntry : capabilitiesList) {
logger.trace(" --> BEFORE entry {} last seen {}", discoveryEntry.getParticipantId(), discoveryEntry.getLastSeenDateMs());
((GlobalDiscoveryEntryPersisted) discoveryEntry).setLastSeenDateMs(System.currentTimeMillis());
logger.trace(" --> AFTER entry {} last seen {}", discoveryEntry.getParticipantId(), discoveryEntry.getLastSeenDateMs());
}
transaction.commit();
} catch (RuntimeException e) {
if (transaction.isActive()) {
transaction.rollback();
}
logger.error("Error updating last seen date for cluster controller with ID {}", clusterControllerId, e);
}
}
use of javax.persistence.EntityTransaction in project joynr by bmwcarit.
the class DiscoveryEntryStorePersisted method removeCapabilityFromStore.
private boolean removeCapabilityFromStore(String participantId) {
GlobalDiscoveryEntryPersisted discoveryEntry = entityManager.find(GlobalDiscoveryEntryPersisted.class, participantId);
EntityTransaction transaction = entityManager.getTransaction();
try {
transaction.begin();
entityManager.remove(discoveryEntry);
transaction.commit();
} catch (Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
logger.error("unable to remove capability: " + participantId, e);
return false;
} finally {
}
return true;
}
use of javax.persistence.EntityTransaction in project joynr by bmwcarit.
the class ChannelDatabase method addChannel.
@Override
public void addChannel(Channel channel) {
logger.trace("add channel {}", channel);
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
BounceProxyInformationEntity bpInfoEntity = em.find(BounceProxyInformationEntity.class, channel.getBounceProxy().getId());
if (bpInfoEntity == null) {
tx.rollback();
logger.error("No bounce proxy with ID {} registered for channel {}", channel.getBounceProxy().getId(), channel.getChannelId());
throw new IllegalArgumentException("No bounce proxy with ID '" + channel.getBounceProxy().getId() + "' registered for channel '" + channel.getChannelId() + "'");
}
ChannelEntity entity = new ChannelEntity(channel.getChannelId(), bpInfoEntity, channel.getLocation().toString());
em.persist(entity);
tx.commit();
} catch (RuntimeException ex) {
logger.error("Error persisting channel with ID {}: error: {}", channel.getChannelId(), ex.getMessage());
if (tx != null && tx.isActive())
tx.rollback();
throw ex;
}
}
Aggregations