List of usage examples for javax.persistence EntityManager merge
public <T> T merge(T entity);
From source file:org.opencastproject.messages.MailService.java
public static MessageSignatureDto mergeMessageSignature(MessageSignature signature, String organization, EntityManager em) { ArrayList<CommentDto> comments = new ArrayList<CommentDto>(); for (Comment c : signature.getComments()) { comments.add(CommentDatabaseUtils.mergeComment(c, em)); }// w w w . j a v a2s.c o m Option<MessageSignatureDto> signatureOption = findMessageSignature(option(signature.getId()), signature.getName(), organization, em); MessageSignatureDto dto; if (signatureOption.isSome()) { dto = signatureOption.get(); dto.setComments(comments); dto.setCreationDate(signature.getCreationDate()); dto.setCreator(signature.getCreator().getUsername()); dto.setSender(signature.getSender().getAddress()); dto.setSenderName(signature.getSender().getName()); dto.setReplyTo(signature.getReplyTo().map(getAddress).getOrElseNull()); dto.setReplyToName(signature.getReplyTo().map(getName).getOrElseNull()); dto.setName(signature.getName()); dto.setSignature(signature.getSignature()); em.merge(dto); } else { dto = new MessageSignatureDto(signature.getName(), organization, signature.getCreator().getUsername(), signature.getSender().getAddress(), signature.getSender().getName(), signature.getReplyTo().map(getAddress).getOrElseNull(), signature.getReplyTo().map(getName).getOrElseNull(), signature.getSignature(), signature.getCreationDate(), comments); em.persist(dto); } return dto; }
From source file:nl.b3p.kaartenbalie.struts.UserAction.java
@Override public ActionForward save(ActionMapping mapping, DynaValidatorForm dynaForm, HttpServletRequest request, HttpServletResponse response) throws Exception { User user = getUser(dynaForm, request, true); ActionForward af = saveCheck(user, mapping, dynaForm, request); if (af != null) { return af; /*/*from w w w.j ava 2 s.c o m*/ * Check if this user gets a valid capability when using this personalURL */ } Organization org = user.getMainOrganization(); if (org != null && !org.getHasValidGetCapabilities()) { // TODO: we should check for the combination of all organisations addAlternateMessage(mapping, request, CAPABILITY_WARNING_KEY); } /* controleren of er rollen zijn gekozen */ Integer[] roleSelected = (Integer[]) dynaForm.get("roleSelected"); int size = roleSelected.length; if (size < 1) { addAlternateMessage(mapping, request, NOROLES_WARNING_KEY); } populateUserObject(user, dynaForm, request); log.debug("Getting entity manager ......"); EntityManager em = getEntityManager(); if (user.getId() == null) { em.persist(user); } else { em.merge(user); } em.flush(); updatePrincipal(request, user); populateUserForm(user, dynaForm, request); createLists(dynaForm, request); prepareMethod(dynaForm, request, EDIT, EDIT); addDefaultMessage(mapping, request, ACKNOWLEDGE_MESSAGES); return getDefaultForward(mapping, request); }
From source file:de.egore911.opengate.services.PilotService.java
@GET @Path("/verify/{login}") @Produces("text/html") @Documentation("Verify a pilots email address. This URL is sent to the pilot after registration and is the final step to complete the registration. If the email could not be verified (e.g. duplicate verification) it will return a HTTP 400 (Bad Request).") public Response getVerifyForm(@PathParam("login") String login, @QueryParam("verification") @Documentation("The random generated verification code sent by mail to the user") String verificationCode) { if (verificationCode == null || verificationCode.isEmpty()) { return Response.ok( "<html><head></head><body><form method=\"post\"><input type=\"verification\"></form></body></html>") .build();/*from w w w . j ava 2 s .c o m*/ } else { EntityManager em = EntityManagerFilter.getEntityManager(); try { Pilot pilot = (Pilot) em .createQuery("select pilot from Pilot pilot " + "where pilot.login = :login " + "and pilot.verificationCode = :verificationCode") .setParameter("login", login).setParameter("verificationCode", verificationCode) .getSingleResult(); pilot.setVerificationCode(null); pilot.setModified(new Date()); em.merge(pilot); return Response.ok("E-Mail adress has been verified. You can log into the game now.").build(); } catch (NoResultException e) { return Response.status(Status.BAD_REQUEST).build(); } } }
From source file:org.nuxeo.theme.webwidgets.providers.PersistentProvider.java
public synchronized void setWidgetData(final Widget widget, final String dataName, final WidgetData data) throws ProviderException { if (widget == null) { throw new ProviderException("Widget is undefined"); }/* w w w. j a v a 2s . c om*/ if (dataName == null || "".equals(dataName)) { throw new ProviderException("Data name is undefined"); } try { getPersistenceProvider().run(true, new RunVoid() { public void runWith(EntityManager em) { Query query = em.createNamedQuery("Data.findByWidgetAndName"); query.setParameter("widgetUid", widget.getUid()); query.setParameter("dataName", dataName); List<?> results = query.getResultList(); final DataEntity dataEntity = results.size() > 0 ? (DataEntity) results.get(0) : new DataEntity(widget.getUid(), dataName); dataEntity.setData(data); em.merge(dataEntity); } }); } catch (ClientException e) { throw new ProviderException(e); } }
From source file:org.mule.module.jpa.command.Merge.java
public Object execute(EntityManager entityManager, Object entity, Map<String, Object> parameters, Boolean flush) throws Exception { logger.debug("Merging entity: " + entity); entityManager.merge(entity); if (flush) {/*from w w w. j a v a 2 s .co m*/ entityManager.flush(); } return entity; }
From source file:cn.buk.hotel.dao.HotelDaoImpl.java
@Override @Transactional// ww w . j a v a 2 s . c om public int updateCacheCity(CacheCity cacheCity) { int retCode = 0; EntityManager em = getEm(); try { em.merge(cacheCity); retCode = 1; } catch (Exception ex) { retCode = -1; } return retCode; }
From source file:cn.buk.hotel.dao.HotelDaoImpl.java
@Override @Transactional//www . ja v a 2s . c o m public int updateCacheHotel(CacheHotel cacheHotel) { int retCode = 0; EntityManager em = getEm(); try { em.merge(cacheHotel); retCode = 1; } catch (Exception ex) { retCode = -1; logger.error(ex.getMessage()); } return retCode; }
From source file:cn.buk.hotel.dao.HotelDaoImpl.java
@Override @Transactional/*from w w w . j av a 2s .c o m*/ public int updateCacheRatePlan(CacheRatePlan cacheRatePlan) { int retCode = 0; EntityManager em = getEm(); try { em.merge(cacheRatePlan); retCode = 1; } catch (Exception ex) { retCode = -1; logger.error(ex.getMessage()); } return retCode; }
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public BakerUser updateBakerUser(BakerUser bu) { EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*from w w w . j av a 2s .com*/ BakerUser resis = entityManager.merge(bu); entityTransaction.commit(); return resis; }
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public BakerProperty updateProperty(BakerProperty p) { EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*w w w. ja v a 2s . c o m*/ BakerProperty bp = entityManager.merge(p); entityTransaction.commit(); return bp; }