當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityTransaction.rollback方法代碼示例

本文整理匯總了Java中javax.persistence.EntityTransaction.rollback方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityTransaction.rollback方法的具體用法?Java EntityTransaction.rollback怎麽用?Java EntityTransaction.rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.persistence.EntityTransaction的用法示例。


在下文中一共展示了EntityTransaction.rollback方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: changeTask

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
private void changeTask(long taskId,String username,StatusOperation operation,String faultMessage) {
	EntityManager em=getEntityManager();
	EntityTransaction trans=em.getTransaction();
	try{
		trans.begin();
		Task task=em.find(Task.class, taskId);
		if(StringUtils.isNotEmpty(faultMessage)){
			task.setFaultMessage(faultMessage);
		}
		if(changeTaskStatus(task,operation)){
			em.persist(task);				
		}
		TaskStatus status=task.getStatus();
		if(status.equals(TaskStatus.Completed) || status.equals(TaskStatus.Error) || status.equals(TaskStatus.Exited) || status.equals(TaskStatus.Obsolete) || status.equals(TaskStatus.Failed)){
			StatefulKnowledgeSession session=this.bpmService.getSession(task.getSessionId());
			session.getWorkItemManager().completeWorkItem(task.getWorkItemId(),null);	
			session.dispose();
		}
		trans.commit();
	}catch(Exception ex){
		trans.rollback();
		throw new RuntimeException(ex);
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:25,代碼來源:TaskServiceImpl.java

示例2: merge

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static ReceivedTexts merge(ReceivedTexts text) {
    if (text != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            text = em.merge(text);
            trans.commit();
            return text;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:19,代碼來源:ReceivedTextDataAccessObject.java

示例3: insertButtonActionPerformed

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
private void insertButtonActionPerformed(ActionEvent evt) 
{
   Addresses address = new Addresses();
   address.setFirstname(firstNameTextField.getText());
   address.setLastname(lastNameTextField.getText());
   address.setPhonenumber(phoneTextField.getText());
   address.setEmail(emailTextField.getText());
   
   // get an EntityTransaction to manage insert operation
   EntityTransaction transaction = entityManager.getTransaction();
   
   try
   {
      transaction.begin(); // start transaction
      entityManager.persist(address); // store new entry
      transaction.commit(); // commit changes to the database
      JOptionPane.showMessageDialog(this, "Person added!",
         "Person added", JOptionPane.PLAIN_MESSAGE);
   }
   catch (Exception e) // if transaction failed
   {
      transaction.rollback(); // undo database operations 
      JOptionPane.showMessageDialog(this, "Person not added!",
         e.getMessage(), JOptionPane.PLAIN_MESSAGE);
   }
}
 
開發者ID:cleitonferreira,項目名稱:LivroJavaComoProgramar10Edicao,代碼行數:27,代碼來源:AddressBook.java

示例4: persist

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static Companies persist(Companies company) {
    if (company != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            em.persist(company);
            trans.commit();
            return company;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
            return null;
        } finally {
            em.close();
        }
    }
    return null;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:20,代碼來源:CompanyDataAccessObject.java

示例5: persist

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static Candidates persist(Candidates candidate) {
    if (candidate != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            em.persist(candidate);
            trans.commit();
            return candidate;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:19,代碼來源:CandidatePersistence.java

示例6: delete

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static boolean delete(int messageID) {
    if (messageID > 0) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        ConversationMessages message = em.find(ConversationMessages.class, messageID);
        if (message != null) {
            EntityTransaction trans = em.getTransaction();
            try {
                trans.begin();
                em.remove(message);
                trans.commit();
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                trans.rollback();
            } finally {
                em.close();
            }
        }
    }
    return false;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:22,代碼來源:ConversationMessageDataAccessObject.java

示例7: delete

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static boolean delete(int conversationID) {
    if (conversationID > 0) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        Conversations conversation = em.find(Conversations.class, conversationID);
        if (conversation != null) {
            EntityTransaction trans = em.getTransaction();
            try {
                trans.begin();
                em.remove(conversation);
                trans.commit();
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                trans.rollback();
            } finally {
                em.close();
            }
        }
    }
    return false;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:22,代碼來源:ConversationDataAccessObject.java

示例8: persist

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static ReceivedTexts persist(ReceivedTexts text) {
    if (text != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            em.persist(text);
            trans.commit();
            return text;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:19,代碼來源:ReceivedTextDataAccessObject.java

示例9: merge

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static Conversations merge (Conversations conversation) {
    if (conversation != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            conversation = em.merge(conversation);
            trans.commit();
            return conversation;
        } catch (Exception e) {
            trans.rollback();
            e.printStackTrace();
            return null;
        } finally {
            em.close();
        }
    }
    return null;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:20,代碼來源:ConversationDataAccessObject.java

示例10: persist

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static Conversations persist (Conversations conversation) {
    if (conversation != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            em.persist(conversation);
            trans.commit();
            return conversation;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:19,代碼來源:ConversationDataAccessObject.java

示例11: persistInATransaction

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
protected boolean persistInATransaction(Object... obj) {
    EntityTransaction tx = em.getTransaction();
    tx.begin();

    try {
        for (Object o : obj) {
            em.persist(o);
        }
        tx.commit();
    } catch (Exception e) {
        System.out.println("FAILED TRANSACTION: " + e.toString());
        tx.rollback();
        return false;
    }

    return true;
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:18,代碼來源:EntityTestBase.java

示例12: merge

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public static ProfileViewLogs merge (ProfileViewLogs log) {
    if (log != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            log = em.merge(log);
            trans.commit();
            return log;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:19,代碼來源:ProfileViewLogDataAccessObject.java

示例13: delegate

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public void delegate(long taskId, String username, String targetUsername) {
	EntityManager em=this.getEntityManager();
	EntityTransaction trans=em.getTransaction();
	try{
		trans.begin();
		String jpql="select d from "+TaskDelegate.class.getName()+" d where d.task.id=:taskId and d.delegator=:targetUsername";
		int size=em.createQuery(jpql).setParameter("taskId", taskId).setParameter("targetUsername", targetUsername).getResultList().size();
		if(size>0){
			throw new IllegalArgumentException("User "+targetUsername+" has already delegate task "+taskId+"");
		}
		Task task=new Task(taskId);
		TaskDelegate taskDelegate=new TaskDelegate();
		taskDelegate.setTask(task);
		em.persist(taskDelegate);
		taskEventSupport.fireEvents(StatusOperation.Delegate, task);
		trans.commit();
	}catch(Exception ex){
		trans.rollback();
		throw new RuntimeException(ex);
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:22,代碼來源:TaskServiceImpl.java

示例14: testDetach

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
@Test
public void testDetach(){

    String name = "foo";

    User user = new User();
    user.setName(name);

    assertTrue(persistInATransaction(user));

    assertTrue(em.contains(user));

    em.detach(user);

    assertFalse(em.contains(user));

    //"refresh" fails, as entity is detached
    EntityTransaction tx = em.getTransaction();
    tx.begin();
    try {
        em.refresh(user);
        tx.commit();
        fail();
    } catch (Exception e){
        tx.rollback();
    }

    //being detached from the EntityManager does not mean being removed from DB
    User found = em.find(User.class, user.getId());
    assertEquals(name, found.getName());
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:32,代碼來源:UserTest.java

示例15: testOrphanRemovalOwner

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
@Test
public void testOrphanRemovalOwner(){

    Address address = new Address();
    User user = new User();
    user.setAddress(address);

    //User refers to unmanaged Address, and no cascade for persist
    assertFalse(persistInATransaction(user));

    user.setId(null);

    assertTrue(persistInATransaction(user,address));

    Address found = em.find(Address.class, address.getId());
    assertNotNull(found);

    //now remove User from DB
    EntityTransaction tx = em.getTransaction();
    tx.begin();
    try {
        em.remove(user);
        tx.commit();
    } catch (Exception e){
        tx.rollback();
        fail();
    }

    //User is owner of the OneToOne relation, so, because of "orphanRemoval,
    //address get removed as well
    found = em.find(Address.class, address.getId());
    assertNull(found);
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:34,代碼來源:UserTest.java


注:本文中的javax.persistence.EntityTransaction.rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。