List of usage examples for javax.persistence EntityManager refresh
public void refresh(Object entity);
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Initialize entity attribute/*from w w w . j a va2 s . c om*/ * @param em * @param entity * @param a * @param depth */ @SuppressWarnings("rawtypes") private static void intialize(EntityManager em, Object entity, Object attached, Attribute a, int depth) { Object value = PropertyAccessorFactory.forDirectFieldAccess(attached).getPropertyValue(a.getName()); if (!em.getEntityManagerFactory().getPersistenceUnitUtil().isLoaded(value)) { em.refresh(value); } PropertyAccessorFactory.forDirectFieldAccess(entity).setPropertyValue(a.getName(), value); initialize(em, value, depth - 1); }
From source file:org.spc.ofp.tubs.domain.purseseine.TripRepository.java
public void save(final PurseSeineTrip trip) { final EntityManager mgr = emf.createEntityManager(); final EntityTransaction xa = mgr.getTransaction(); try {/*from www .j ava2 s . com*/ xa.begin(); mgr.persist(trip); mgr.flush(); xa.commit(); mgr.refresh(trip); } catch (Exception ex) { if (xa.isActive()) { xa.rollback(); } } finally { mgr.close(); } }
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/* w ww . j a v a 2 s . 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; }
From source file:com.emc.plants.service.impl.LoginBean.java
/** * Update an existing user.//from w w w .jav a 2 s.c o m * * @param customerID The customer ID. * @param firstName First name. * @param lastName Last name. * @param addr1 Address line 1. * @param addr2 Address line 2. * @param addrCity City address information. * @param addrState State address information. * @param addrZip Zip code address information. * @param phone User's phone number. * @return CustomerInfo */ public CustomerInfo updateUser(String customerID, String firstName, String lastName, String addr1, String addr2, String addrCity, String addrState, String addrZip, String phone) { CustomerInfo customerInfo = null; // TODO: lowp: no lock check is performed to see if cust data has changed since fetch! /* customerHome = (CustomerHome) Util.getEJBLocalHome("java:comp/env/ejb/Customer", com.ibm.websphere.samples.pbwjpa.CustomerHome.class); Customer customer = customerHome.findByPrimaryKeyUpdate(customerID); customer.update(firstName, lastName, addr1, addr2, addrCity, addrState, addrZip, phone); customerInfo = new CustomerInfo(customer); */ EntityManager em = entityManagerFactory.createEntityManager(); em.getTransaction().begin(); Customer c = em.find(Customer.class, customerID); em.lock(c, LockModeType.WRITE); em.refresh(c); // TODO: lowp: test and set for update performance? c.setFirstName(firstName); c.setLastName(lastName); c.setAddr1(addr1); c.setAddr2(addr2); c.setAddrCity(addrCity); c.setAddrState(addrState); c.setAddrZip(addrZip); c.setPhone(phone); customerInfo = new CustomerInfo(c); em.getTransaction().commit(); return customerInfo; }
From source file:de.zib.gndms.infra.model.GridEntityModelHandler.java
public final @NotNull M refreshModel(final EntityManager emParam, final @NotNull M model) { return txRun(emParam, new Function<EntityManager, M>() { public M apply(@com.google.common.base.Nullable @NotNull EntityManager em) { em.refresh(model); return model; }// w w w. j ava 2s. c o m }); }
From source file:fr.mby.opa.picsimpl.dao.DbProposalDao.java
/** * @param proposalBag/* w w w. j a v a 2 s. c om*/ * @return */ protected ProposalBag _updateProposalBagInternal(final ProposalBag proposalBag) { final TxCallbackReturn<ProposalBag> txCallback = new TxCallbackReturn<ProposalBag>(this.getEmf()) { @Override protected ProposalBag executeInTransaction(final EntityManager em) { final ProposalBag updatedBag = em.merge(proposalBag); em.flush(); em.refresh(updatedBag); return updatedBag; } }; final ProposalBag updatedBag = txCallback.getReturnedValue(); return updatedBag; }
From source file:fr.mby.opa.picsimpl.dao.DbProposalDao.java
@Override public ProposalBranch updateBranch(final ProposalBranch branch) { Assert.notNull(branch, "No ProposalBag supplied !"); Assert.notNull(branch.getId(), "Id should be set for update !"); final TxCallbackReturn<ProposalBranch> txCallback = new TxCallbackReturn<ProposalBranch>(this.getEmf()) { @Override/*from w w w .jav a2s . c o m*/ protected ProposalBranch executeInTransaction(final EntityManager em) { final ProposalBranch updatedBranch = em.merge(branch); em.flush(); em.refresh(updatedBranch); return updatedBranch; } }; final ProposalBranch updatedBag = txCallback.getReturnedValue(); return updatedBag; }
From source file:com.chiralbehaviors.CoRE.access.resource.CollectionResource.java
@POST @Path("{parentId}") @Produces(MediaType.APPLICATION_JSON)/*from ww w . j a v a 2s . c om*/ public Product createNewProduct(@PathParam("parentId") String parentId, @QueryParam("relId") String relId, Product child) throws JsonProcessingException { return perform(new Transactionally<Product>() { @Override public Product exec(Model model) throws SQLException { EntityManager em = model.getEntityManager(); Product parent = em.find(Product.class, parentId); Relationship rel = em.find(Relationship.class, relId); em.persist(child); ProductNetwork net = new ProductNetwork(parent, rel, child, parent.getUpdatedBy()); em.persist(net); em.flush(); em.refresh(child); return child; } }); }
From source file:org.eclipse.jubula.client.ui.rcp.editors.CentralTestDataEditor.java
/** * update the param nodes which reference test data cube, e.g. because of * renaming of test data cube/* w w w . ja v a2 s .c om*/ */ private void updateReferencedParamNodes() { Set<INodePO> nodesToRefresh = new HashSet<INodePO>(); for (ITestDataCubePO tdc : getElementsToRefresh()) { nodesToRefresh.addAll(TestDataCubeBP.getReuser(tdc)); } EntityManager masterSession = GeneralStorage.getInstance().getMasterSession(); for (INodePO node : nodesToRefresh) { masterSession.refresh(node); } getElementsToRefresh().clear(); }
From source file:org.eclipse.jubula.client.core.persistence.EditSupport.java
/** * because of Persistence (JPA / EclipseLink)-Bug HHH-1280 we can't use * refresh<br>/*from www . j av a 2 s . co m*/ * therefore we use evict to remove the old object from master session and * reload the object<br> * please attend, that in this case the Java-IDs of the old and the reloaded * object are different<br> * refreshs the original versions, which were possibly modified in editor * * @throws ProjectDeletedException * if the project was deleted in another instance */ private void refreshOriginalVersions() throws ProjectDeletedException { try { final EntityManager masterSession = GeneralStorage.getInstance().getMasterSession(); IPersistentObject original = getOriginal(); if (original != null) { masterSession.refresh(original); GeneralStorage.getInstance().fireDataModified(original); } } catch (PersistenceException e) { log.error(Messages.RefreshOfOriginalVersionFailed + StringConstants.DOT, e); GeneralStorage.getInstance().reloadMasterSession(new NullProgressMonitor()); } }