List of usage examples for javax.persistence EntityManager merge
public <T> T merge(T entity);
From source file:org.apereo.portal.groups.pags.dao.jpa.JpaPersonAttributesGroupTestDefinitionDao.java
@PortalTransactional @Override/* w w w. j av a2 s . com*/ public void deletePersonAttributesGroupTestDefinition(IPersonAttributesGroupTestDefinition definition) { Validate.notNull(definition, "definition can not be null"); final IPersonAttributesGroupTestDefinition persistentDefinition; final EntityManager entityManager = this.getEntityManager(); if (entityManager.contains(definition)) { persistentDefinition = definition; } else { persistentDefinition = entityManager.merge(definition); } entityManager.remove(persistentDefinition); }
From source file:org.apereo.portal.groups.pags.dao.jpa.JpaPersonAttributesGroupTestGroupDefinitionDao.java
@PortalTransactional @Override/*from w w w . j ava 2s . c o m*/ public void deletePersonAttributesGroupTestGroupDefinition( IPersonAttributesGroupTestGroupDefinition definition) { Validate.notNull(definition, "definition can not be null"); final IPersonAttributesGroupTestGroupDefinition persistentDefinition; final EntityManager entityManager = this.getEntityManager(); if (entityManager.contains(definition)) { persistentDefinition = definition; } else { persistentDefinition = entityManager.merge(definition); } entityManager.remove(persistentDefinition); }
From source file:it.infn.ct.futuregateway.apiserver.resources.observers.TaskObserver.java
@Override public final void update(final Observable obs, final Object arg) { if (!(obs instanceof Task)) { log.error("Wrong abject associated with the oserver"); }// w w w . ja v a 2 s . c o m Task t = (Task) obs; if (t.getId() == null || t.getStatus() == null) { return; } log.debug("Task " + t.getId() + " updated"); if (t.getStatus().equals(Task.STATUS.WAITING) && t.getApplicationDetail() != null) { if (t.getInputFiles() != null) { for (TaskFile tf : t.getInputFiles()) { if (tf.getStatus().equals(TaskFile.FILESTATUS.NEEDED)) { return; } } } t.setStatus(Task.STATUS.READY); submit(t); } EntityManager em = emf.createEntityManager(); EntityTransaction et = em.getTransaction(); try { et.begin(); em.merge(t); et.commit(); } catch (RuntimeException re) { log.error("Impossible to update the task!"); log.error(re); if (et != null && et.isActive()) { et.rollback(); } } finally { em.close(); } }
From source file:com.appdynamicspilot.persistence.BasePersistenceImpl.java
/** * The method to update the serailizable business objects into the database. * // ww w . j a v a 2s .com * @param object -- * serializable object * @throws PersistenceException */ @Transactional public void update(final Serializable object) { EntityManager entityManager = getEntityManager(); EntityTransaction txn = entityManager.getTransaction(); txn.begin(); try { entityManager.merge(object); } catch (Exception ex) { logger.error(ex); txn.rollback(); } finally { if (!txn.getRollbackOnly()) { txn.commit(); } } }
From source file:org.ejbca.extra.db.MessageHome.java
/** * Method that updates the message data to the database. * // w w w . j a va2s . c o m * @param msg the message class. */ public void update(Message msg) { log.trace(">update : Message, Messageid : " + msg.getMessageid()); EntityManager entityManager = getNewEntityManager(); try { msg.setModifytime(new Date().getTime()); entityManager.merge(msg); } finally { closeEntityManager(entityManager); } log.trace("<update : Message, Messageid : " + msg.getMessageid()); }
From source file:com.webbfontaine.valuewebb.action.tt.TtLogger.java
public String deleteUserLog(TtLog log) { EntityManager entityManager = null; try {/*from w w w . j a v a2s . com*/ entityManager = Utils.createEntityManager(); entityManager.remove(entityManager.merge(log)); entityManager.flush(); reloadLogs(log); } finally { if (entityManager != null) { entityManager.close(); } } return ""; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.EmployerRepositoryImplementation.java
@Override public boolean update(Employer employer) { EntityManager em = entityManagerFactory.createEntityManager(); boolean success = true; try {// w ww . j a v a2 s .c o m em.getTransaction().begin(); em.merge(employer); em.flush(); em.getTransaction().commit(); success = true; } catch (RuntimeException e) { Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); success = false; } em.close(); } return success; }
From source file:org.apereo.portal.portlet.dao.jpa.JpaPortletTypeDao.java
@Override @PortalTransactional/*from w w w. j a v a 2s . c o m*/ public void deletePortletType(IPortletType type) { Validate.notNull(type, "definition can not be null"); final IPortletType persistentChanneltype; final EntityManager entityManager = this.getEntityManager(); if (entityManager.contains(type)) { persistentChanneltype = type; } else { persistentChanneltype = entityManager.merge(type); } entityManager.remove(persistentChanneltype); }
From source file:ox.softeng.burst.services.BurstService.java
public void generateStartupMessage() { Message message = new Message("burst-service", "Burst Service starting\n" + version(), SeverityEnum.INFORMATIONAL, OffsetDateTime.now(ZoneId.of("UTC")), "Burst Service Startup"); message.addTopic("service"); message.addTopic("startup"); message.addTopic("burst"); message.addMetadata("gmc", "gel"); message.addMetadata("burst_service_version", version()); try {/*w ww . ja v a2 s . c o m*/ EntityManager entityManager = entityManagerFactory.createEntityManager(); entityManager.getTransaction().begin(); entityManager.merge(message); entityManager.getTransaction().commit(); entityManager.close(); } catch (HibernateException he) { logger.error("Could not save startup message to database: " + he.getMessage(), he); } catch (Exception e) { logger.error("Unhandled exception trying to process startup message", e); } }
From source file:fr.mby.opa.picsimpl.dao.DbPictureDao.java
@Override public Picture updatePicture(final Picture picture) throws PictureNotFoundException { Assert.notNull(picture, "No Picture supplied !"); Assert.notNull(picture.getId(), "Id should be set for update !"); final TxCallbackReturn<Picture> txCallback = new TxCallbackReturn<Picture>(this.getEmf()) { @Override//from ww w . j a v a 2s.com protected Picture executeInTransaction(final EntityManager em) { final Picture updatedPicture = em.merge(picture); em.flush(); em.refresh(updatedPicture); return updatedPicture; } }; final Picture updatedPicture = txCallback.getReturnedValue(); return updatedPicture; }