本文整理匯總了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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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());
}
示例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);
}