List of usage examples for javax.persistence EntityTransaction commit
public void commit();
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public void deleteSubscribedResource(int smId) { EntityManager entityManager = entityManagerFactory.createEntityManager(); SubscribedResource sm = entityManager.find(SubscribedResource.class, smId); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();// w w w.jav a 2 s .c om entityManager.remove(sm); entityTransaction.commit(); }
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public void deleteDeployment(int id) { EntityManager entityManager = entityManagerFactory.createEntityManager(); DeploymentDescriptor c = entityManager.find(DeploymentDescriptor.class, id); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*from w w w.j a v a 2 s . c o m*/ entityManager.remove(c); entityTransaction.commit(); }
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public void deleteProperty(int propid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); BakerProperty c = entityManager.find(BakerProperty.class, propid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*from w w w. j a va2 s.c o m*/ entityManager.remove(c); entityTransaction.commit(); }
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public void deleteUser(int userid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); BakerUser u = entityManager.find(BakerUser.class, userid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*from w ww . j a v a 2 s . c o m*/ entityManager.remove(u); entityTransaction.commit(); }
From source file:uk.ac.horizon.ug.mrcreator.http.CRUDServlet.java
/** Create on POST. * E.g. curl -d '{...}' http://localhost:8888/author/configuration/ * @param req//w ww . j av a 2 s.c o m * @param resp * @throws ServletException * @throws IOException */ private void doCreate(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub try { Object o = parseObject(req); if (filterByCreator) { String creator = getRequestCreator(req); setCreator(o, creator); } Key key = validateCreate(o); // try adding EntityManager em = EMF.get().createEntityManager(); EntityTransaction et = em.getTransaction(); try { et.begin(); if (em.find(getObjectClass(), key) != null) throw new RequestException(HttpServletResponse.SC_CONFLICT, "object already exists (" + key + ")"); em.persist(o); et.commit(); logger.info("Added " + o); } finally { if (et.isActive()) et.rollback(); em.close(); } resp.setCharacterEncoding(ENCODING); resp.setContentType(JSON_MIME_TYPE); Writer w = new OutputStreamWriter(resp.getOutputStream(), ENCODING); JSONWriter jw = new JSONWriter(w); listObject(jw, o); w.close(); } catch (RequestException e) { resp.sendError(e.getErrorCode(), e.getMessage()); } catch (Exception e) { logger.log(Level.WARNING, "Getting object of type " + getObjectClass(), e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } }
From source file:com.eucalyptus.images.Images.java
public static ImageInfo createPendingFromDeviceMapping(UserFullName creator, String imageNameArg, String imageDescription, ImageMetadata.Architecture requestArch, ImageMetadata.Platform imagePlatform, final List<BlockDeviceMappingItemType> blockDeviceMappings) throws Exception { final String imageId = ResourceIdentifiers.generateString(ImageMetadata.Type.machine.getTypePrefix()); BlockStorageImageInfo ret = new BlockStorageImageInfo(creator, imageId, imageNameArg, imageDescription, new Long(-1), requestArch, imagePlatform, null, null, "snap-EUCARESERVED", false, Images.DEFAULT_ROOT_DEVICE); /// device with snap-EUCARESERVED is the placeholder to indicate register is for create-image only /// actual root device with snapshot is filled in later BlockDeviceMappingItemType toRemove = null; for (final BlockDeviceMappingItemType device : blockDeviceMappings) { if (Images.findCreateImageRoot().apply(device)) toRemove = device;/* ww w. j av a2s.co m*/ } if (toRemove != null) blockDeviceMappings.remove(toRemove); final EntityTransaction tx = Entities.get(BlockStorageImageInfo.class); try { ret = Entities.merge(ret); ret.setState(ImageMetadata.State.pending); ret.setImageFormat(ImageMetadata.ImageFormat.fulldisk.toString()); ret.getDeviceMappings() .addAll(Lists.transform(blockDeviceMappings, Images.deviceMappingGenerator(ret, -1))); tx.commit(); LOG.info("Registering image pk=" + ret.getDisplayName() + " ownerId=" + creator); } catch (Exception e) { tx.rollback(); throw new EucalyptusCloudException( "Failed to register pending bfebs image because of: " + e.getMessage(), e); } finally { if (tx.isActive()) tx.rollback(); } return ret; }
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public void deleteInstalledBun(final InstalledBun message) { EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*from w ww . j ava 2 s.co m*/ entityManager.remove(message); entityTransaction.commit(); }
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 a v a 2 s. co m 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();/*from www.j a v a 2 s . co m*/ BakerProperty bp = entityManager.merge(p); entityTransaction.commit(); return bp; }
From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java
public InstalledBun updateInstalledBun(InstalledBun is) { EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//ww w. jav a 2 s . c o m InstalledBun resis = entityManager.merge(is); entityTransaction.commit(); return resis; }