List of usage examples for javax.persistence EntityTransaction commit
public void commit();
From source file:com.eucalyptus.images.Images.java
public static KernelImageInfo lookupKernel(final String kernelId) { EntityTransaction tx = Entities.get(KernelImageInfo.class); KernelImageInfo ret = new KernelImageInfo(); try {/*from w w w.ja v a 2 s .c o m*/ ret = Entities.uniqueResult(Images.exampleKernelWithImageId(kernelId)); tx.commit(); } catch (Exception e) { LOG.error("Kernel '" + kernelId + "' does not exist" + e); throw new NoSuchElementException("InvalidAMIID.NotFound"); } finally { if (tx.isActive()) tx.rollback(); } return ret; }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public void deleteProduct(int id) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Product p = entityManager.find(Product.class, id); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();// ww w . ja v a 2s .c o m entityManager.remove(p); entityTransaction.commit(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public void deleteCategory(int catid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Category c = entityManager.find(Category.class, catid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*from w ww .j av a 2 s .c om*/ entityManager.remove(c); entityTransaction.commit(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public void deleteProperty(int propid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); FStoreProperty c = entityManager.find(FStoreProperty.class, propid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//from w ww .j av a2 s . c o m entityManager.remove(c); entityTransaction.commit(); }
From source file:com.eucalyptus.images.Images.java
public static RamdiskImageInfo lookupRamdisk(final String ramdiskId) { EntityTransaction tx = Entities.get(RamdiskImageInfo.class); RamdiskImageInfo ret = new RamdiskImageInfo(); try {/*from w w w . j ava 2 s . c o m*/ ret = Entities.uniqueResult(Images.exampleRamdiskWithImageId(ramdiskId)); tx.commit(); } catch (Exception e) { LOG.error("Ramdisk '" + ramdiskId + "' does not exist" + e); throw new NoSuchElementException("InvalidAMIID.NotFound"); } finally { if (tx.isActive()) tx.rollback(); } return ret; }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public void deleteUser(int userid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); FStoreUser u = entityManager.find(FStoreUser.class, userid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();// w ww. ja v a 2 s. c o m entityManager.remove(u); entityTransaction.commit(); }
From source file:org.eclipse.smila.binarystorage.persistence.jpa.JPABinaryPersistence.java
/** * Stores the given BinaryStorageDao, updating an existing one or creating a new one. * * @param dao// w w w. j av a 2 s . co m * the BinaryStorageDao to store * @throws BinaryStorageException * if any error occurs */ // TODO: don't know if this synchronize is good, was needed to pass the JUNit test TestConcurrentBSSAccessJPA private synchronized void store(final BinaryStorageDao dao) throws BinaryStorageException { _lock.readLock().lock(); try { final EntityManager em = createEntityManager(); final EntityTransaction transaction = em.getTransaction(); try { transaction.begin(); if (findBinaryStorageDao(em, dao.getId()) == null) { em.persist(dao); } else { em.merge(dao); } transaction.commit(); if (_log.isTraceEnabled()) { _log.trace("stored content of id:" + dao.getId()); } } catch (final Exception e) { if (transaction.isActive()) { transaction.rollback(); } throw new BinaryStorageException(e, "error storing record id: " + dao.getId()); } finally { closeEntityManager(em); } } finally { _lock.readLock().unlock(); } }
From source file:com.eucalyptus.images.Images.java
public static void enableImage(String imageId) throws NoSuchImageException { final EntityTransaction db = Entities.get(ImageInfo.class); try {//from w ww . java 2 s. c o m final ImageInfo img = Entities.uniqueResult(Images.exampleWithImageId(imageId)); img.setState(ImageMetadata.State.available); db.commit(); } catch (final NoSuchElementException e) { db.rollback(); throw new NoSuchImageException("Failed to lookup image: " + imageId, e); } catch (final Exception e) { db.rollback(); throw new NoSuchImageException("Failed to lookup image: " + imageId, e); } finally { if (db.isActive()) db.rollback(); } }
From source file:org.apache.juddi.subscription.SubscriptionNotifier.java
/** * Obtains all subscriptions in the system. * @return Collection of All Subscriptions in the system. */// ww w . ja va 2s.com @SuppressWarnings("unchecked") protected Collection<Subscription> getAllAsyncSubscriptions() { Collection<Subscription> subscriptions = null; EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Query query = em.createQuery("SELECT s FROM Subscription s WHERE s.bindingKey IS NOT NULL"); subscriptions = (Collection<Subscription>) query.getResultList(); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } return subscriptions; }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public Category updateCategory(Category c) { EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/* w w w .j a v a2 s .c om*/ Category resis = entityManager.merge(c); entityTransaction.commit(); return resis; }