当前位置: 首页>>代码示例>>Java>>正文


Java UnexpectedRollbackException类代码示例

本文整理汇总了Java中org.springframework.transaction.UnexpectedRollbackException的典型用法代码示例。如果您正苦于以下问题:Java UnexpectedRollbackException类的具体用法?Java UnexpectedRollbackException怎么用?Java UnexpectedRollbackException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnexpectedRollbackException类属于org.springframework.transaction包,在下文中一共展示了UnexpectedRollbackException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: commit

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
/**
 * This implementation of commit handles participating in existing
 * transactions and programmatic rollback requests.
 * Delegates to {@code isRollbackOnly}, {@code doCommit}
 * and {@code rollback}.
 * @see org.springframework.transaction.TransactionStatus#isRollbackOnly()
 * @see #doCommit
 * @see #rollback
 */
@Override
public final void commit(TransactionStatus status) throws TransactionException {
	if (status.isCompleted()) {
		throw new IllegalTransactionStateException(
				"Transaction is already completed - do not call commit or rollback more than once per transaction");
	}

	DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
	if (defStatus.isLocalRollbackOnly()) {
		if (defStatus.isDebug()) {
			logger.debug("Transactional code has requested rollback");
		}
		processRollback(defStatus);
		return;
	}
	if (!shouldCommitOnGlobalRollbackOnly() && defStatus.isGlobalRollbackOnly()) {
		if (defStatus.isDebug()) {
			logger.debug("Global transaction is marked as rollback-only but transactional code requested commit");
		}
		processRollback(defStatus);
		// Throw UnexpectedRollbackException only at outermost transaction boundary
		// or if explicitly asked to.
		if (status.isNewTransaction() || isFailEarlyOnGlobalRollbackOnly()) {
			throw new UnexpectedRollbackException(
					"Transaction rolled back because it has been marked as rollback-only");
		}
		return;
	}

	processCommit(defStatus);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:AbstractPlatformTransactionManager.java

示例2: removeEquipmentFromProcess

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
public void removeEquipmentFromProcess(Long equipmentId, Long processId) {
  try {
    processCache.acquireWriteLockOnKey(processId);
    try {
      Process processCopy = processCache.getCopy(processId);
      log.debug("Removing Process Equipment {} for process {}", equipmentId, processCopy.getName());
      processCopy.getEquipmentIds().remove(equipmentId);
      processCache.putQuiet(processCopy);
    } finally {
      processCache.releaseWriteLockOnKey(processId);
    }
  } catch (RuntimeException e) {
    throw new UnexpectedRollbackException("Unable to remove equipment reference in process.", e);
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:17,代码来源:ProcessConfigTransactedImpl.java

示例3: doRemoveSubEquipment

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
@Transactional(value = "cacheTransactionManager", propagation = Propagation.REQUIRES_NEW)
public List<ProcessChange> doRemoveSubEquipment(final SubEquipment subEquipment, final ConfigurationElementReport subEquipmentReport) {
  List<ProcessChange> processChanges = new ArrayList<ProcessChange>();

  try {
    subEquipmentDAO.deleteItem(subEquipment.getId());
    Long processId = this.subEquipmentFacade.getProcessIdForAbstractEquipment(subEquipment.getId());

    SubEquipmentUnitRemove subEquipmentUnitRemove = new SubEquipmentUnitRemove(0L, subEquipment.getId(), subEquipment.getParentId());
    processChanges.add(new ProcessChange(processId, subEquipmentUnitRemove));

  } catch (RuntimeException e) {
    subEquipmentReport.setFailure("Rolling back removal of sub-equipment " + subEquipment.getId());
    throw new UnexpectedRollbackException("Exception caught while removing Sub-equipment from DB: rolling back", e);
  }

  return processChanges;
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:20,代码来源:SubEquipmentConfigTransactedImpl.java

示例4: updateRuleTag

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
public void updateRuleTag(Long id, Properties elementProperties) throws IllegalAccessException {
 try {
  ruleTagConfigTransacted.doUpdateRuleTag(id, elementProperties);
  ruleEvaluator.evaluateRule(id);
  if (LOGGER.isTraceEnabled()) {
	  LOGGER.trace("updateRuleTag - Notifying Configuration update listeners");
  }
  this.configurationUpdateImpl.notifyListeners(id);
 } catch (UnexpectedRollbackException e) {
  LOGGER.error("Rolling back Rule update in cache");
  ruleTagCache.remove(id);
  ruleTagCache.loadFromDb(id);
  throw e;
 }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:17,代码来源:RuleTagConfigHandlerImpl.java

示例5: createProcess

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
public ProcessChange createProcess(final ConfigurationElement element) throws IllegalAccessException {
  LOGGER.debug("Creating process with id " + element.getEntityId());
  if (processCache.hasKey(element.getEntityId())) {
    throw new ConfigurationException(ConfigurationException.ENTITY_EXISTS, "Attempting to create a process with an already existing id: "
        + element.getEntityId());
  }
  Process process = null;
  try {
    ProcessChange change = processConfigTransacted.doCreateProcess(element);
    process = processCache.get(element.getEntityId());
    jmsContainerManager.subscribe(process);
    processFacade.loadAndStartAliveTag(element.getEntityId());
    processCache.notifyListenersOfUpdate(element.getEntityId());
    return change;
  } catch (RuntimeException ex) {
    LOGGER.error("Exception caught while creating a new Process - rolling back DB changes and removing from cache.");
    processCache.remove(element.getEntityId());
    if (process != null){
      jmsContainerManager.unsubscribe(process);
    }
    throw new UnexpectedRollbackException("Unexpected error while creating a new Process.", ex);
  }

}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:26,代码来源:ProcessConfigHandlerImpl.java

示例6: updateDataTag

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
public ProcessChange updateDataTag(Long id, Properties elementProperties) {
 try {
  ProcessChange processChange = dataTagConfigTransacted.doUpdateDataTag(id, elementProperties);
  if (LOGGER.isTraceEnabled()) {
    	LOGGER.trace("createDataTag - Notifying Configuration update listeners");
    }
  this.configurationUpdateImpl.notifyListeners(id);
  return processChange;
 } catch (UnexpectedRollbackException e) {
  LOGGER.error("Rolling back update in cache");
  dataTagCache.remove(id); //DB transaction is rolled back here: reload the tag
  dataTagCache.loadFromDb(id);
  throw e;
 }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:17,代码来源:DataTagConfigHandlerImpl.java

示例7: registerNewMember

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.POST)
public String registerNewMember(@Valid @ModelAttribute("newMember") Member newMember, BindingResult result, Model model) {
    if (!result.hasErrors()) {
        try {
            memberDao.register(newMember);
            return "redirect:/";
        } catch (UnexpectedRollbackException e) {
            model.addAttribute("members", memberDao.findAllOrderedByName());
            model.addAttribute("error", e.getCause().getCause());
            return "index";
        }
    } else {
        model.addAttribute("members", memberDao.findAllOrderedByName());
        return "index";
    }
}
 
开发者ID:ComposiTeam,项目名称:MWService,代码行数:17,代码来源:MemberController.java

示例8: unexpectedRollbackTest

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Test
public void unexpectedRollbackTest() {
    final String testName = TestUtils.getMethodName();
    logger.info("-{}----------------------------------------------------", testName);

    List<String> values = Lists.newArrayList(TransactionTestService.ValuePrefix + "X01");
    List<String> values2 = Lists.newArrayList(TransactionTestService.ValuePrefix + "X02");
    List<String> values3 = Lists.newArrayList(TransactionTestService.ValuePrefix + "X03");
    try {
        transactionTestService.insertAndAbortThenInsert(values, values2, values3);

        // 必ず例外発生
        assertThat(testName, true);

    } catch (UnexpectedRollbackException ignored) {
    } catch (RuntimeException e) {
        logger.warn(e.getMessage());
        assertThat(testName, true);
    }

    logger.info("----------------------------------------------------{}-", testName);
}
 
开发者ID:XenonAbe,项目名称:dbflute-play-guice-java-example,代码行数:23,代码来源:TransactionTest.java

示例9: rollback

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
public void rollback() {
    if (rollbackCalled) {
        throw new UnexpectedRollbackException("Cannot rollback Redis transaction. Transaction already rolled back!");
    }
    try {
        redisTemplate.discard();
        rollbackCalled = true;
    } catch (Exception e) {
        throw new TransactionSystemException("Exception occurred rolling back Redis transaction: " + e.getMessage());
    }
}
 
开发者ID:grails,项目名称:gorm-redis,代码行数:12,代码来源:RedisTransaction.java

示例10: cannotCommitTransaction

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
/**
 * Simulate failure of the underlying transaction infrastructure to commit.
 * Check that the target method was invoked, but that the transaction
 * infrastructure exception was thrown to the client
 */
@Test
public void cannotCommitTransaction() throws Exception {
	TransactionAttribute txatt = new DefaultTransactionAttribute();

	Method m = setNameMethod;
	MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
	tas.register(m, txatt);
	// Method m2 = getNameMethod;
	// No attributes for m2

	PlatformTransactionManager ptm = mock(PlatformTransactionManager.class);

	TransactionStatus status = mock(TransactionStatus.class);
	given(ptm.getTransaction(txatt)).willReturn(status);
	UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null);
	willThrow(ex).given(ptm).commit(status);

	TestBean tb = new TestBean();
	ITestBean itb = (ITestBean) advised(tb, ptm, tas);

	String name = "new name";
	try {
		itb.setName(name);
		fail("Shouldn't have succeeded");
	}
	catch (UnexpectedRollbackException thrown) {
		assertTrue(thrown == ex);
	}

	// Should have invoked target and changed name
	assertTrue(itb.getName() == name);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:AbstractTransactionAspectTests.java

示例11: doRemoveEquipment

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
@Transactional(value = "cacheTransactionManager", propagation=Propagation.REQUIRES_NEW)
public void doRemoveEquipment(final Equipment equipment, final ConfigurationElementReport equipmentReport) {
  LOGGER.debug("Removing Equipment " + equipment.getId() + " from DB");
  try {
    equipmentDAO.deleteItem(equipment.getId());                                     
  } catch (UnexpectedRollbackException ex) {
    equipmentReport.setFailure("Aborting removal of equipment " + equipment.getId() + " as unable to remove it from DB."); 
      throw new UnexpectedRollbackException("Interrupting removal of Equipment as failed to remove it from DB - " 
          + "control tags will not be removed.", ex);      
  }              
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:13,代码来源:EquipmentConfigTransactedImpl.java

示例12: doRemoveRuleTag

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
@Transactional(value = "cacheTransactionManager", propagation=Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
public void doRemoveRuleTag(final Long id, final ConfigurationElementReport elementReport) {
  LOGGER.trace("Removing RuleTag " + id);
  try {
    RuleTag ruleTag = tagCache.get(id);
    Collection<Long> ruleIds = ruleTag.getCopyRuleIds();  
    if (!ruleIds.isEmpty()) {
      LOGGER.debug("Removing rules dependent on RuleTag " + id);
      for (Long ruleId : ruleIds) { //concurrent modifcation as a rule is removed from the list during the remove call!
        if (tagLocationService.isInTagCache(ruleId)) { //may already have been removed if a previous rule in the list was used in this rule!
          ConfigurationElementReport newReport = new ConfigurationElementReport(Action.REMOVE, Entity.RULETAG, ruleId);
          elementReport.addSubReport(newReport);
          ruleTagConfigHandler.removeRuleTag(ruleId, newReport); //call config handler bean so transaction annotation is noticed
        }         
      }                
    }
    tagCache.acquireWriteLockOnKey(id);      
    Collection<Long> ruleInputTagIds = Collections.EMPTY_LIST;
    try {
      ruleInputTagIds = ruleTag.getCopyRuleInputTagIds();                
      Collection<Long> alarmIds = ruleTag.getCopyAlarmIds();                  
      if (!alarmIds.isEmpty()) {
        LOGGER.debug("Removing Alarms dependent on RuleTag " + id);
        for (Long alarmId : alarmIds) { //need copy as modified concurrently by remove alarm
          ConfigurationElementReport alarmReport = new ConfigurationElementReport(Action.REMOVE, Entity.ALARM, alarmId);
          elementReport.addSubReport(alarmReport);
          alarmConfigHandler.removeAlarm(alarmId, alarmReport);
        }        
      }
      for (Long inputTagId : ruleInputTagIds) {
        tagConfigGateway.removeRuleFromTag(inputTagId, id); //allowed to lock tag below the rule...
      }

      for (ConfigurationEventListener listener : configurationEventListeners) {
        listener.onConfigurationEvent(ruleTag, Action.REMOVE);
      }

      configurableDAO.deleteItem(ruleTag.getId());                                           
    }
    catch (RuntimeException rEx) {
      String errMessage = "Exception caught when removing rule tag with id " + id;
      LOGGER.error(errMessage, rEx); 
      throw new UnexpectedRollbackException(errMessage, rEx);   
    } finally {
      if (tagCache.isWriteLockedByCurrentThread(id)) {
        tagCache.releaseWriteLockOnKey(id);
      }        
    }
  } catch (CacheElementNotFoundException e) {
    LOGGER.debug("Attempting to remove a non-existent RuleTag - no action taken.");
    elementReport.setWarning("Attempting to removed a non-existent RuleTag");      
  }       
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:55,代码来源:RuleTagConfigTransactedImpl.java

示例13: createAbstractEquipment

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
/**
 * Creates the abstract equipment, puts it in the DB and then loads it into
 * the cache (in that order). The AliveTimer and CommFaultTag are then
 * generated in their respective caches.
 * 
 * @param element
 *          contains the creation detais
 * @return the generated AbstractEquipment object
 * @throws IllegalAccessException
 *           should not be thrown here (inherited at interface from Tag
 *           creation).
 */
protected T createAbstractEquipment(final ConfigurationElement element) throws IllegalAccessException {
  abstractEquipmentCache.acquireWriteLockOnKey(element.getEntityId());
  try {
    LOGGER.debug("Creating (Sub)Equipment " + element.getEntityId());
    T abstractEquipment = commonEquipmentFacade.createCacheObject(element.getEntityId(), element.getElementProperties());
    try {
      configurableDAO.insert(abstractEquipment);
      abstractEquipmentCache.putQuiet(abstractEquipment);
      
      // clear alive and commfault caches and refresh
      // (synch ok as locked equipment so no changes to these ids)
      if (abstractEquipment.getAliveTagId() != null) {
        commonEquipmentFacade.loadAndStartAliveTag(abstractEquipment.getId());
      }
      if (abstractEquipment.getCommFaultTagId() != null) {
        commFaultTagCache.remove(abstractEquipment.getCommFaultTagId());
        commFaultTagCache.loadFromDb(abstractEquipment.getCommFaultTagId());
      }
      
    } catch (Exception e) {
      if (abstractEquipment.getAliveTagId() != null) {
        aliveTimerCache.remove(abstractEquipment.getId());
      }
      if (abstractEquipment.getCommFaultTagId() != null) {
        commFaultTagCache.remove(abstractEquipment.getCommFaultTagId());
      }
      throw new UnexpectedRollbackException("Exception caught while creating equipment: rolling back changes", e);
    }
    // TODO necessary to use DB loading or not?? to check...
    // removed as now rely on automatic cache loading from DB: problem: also
    // used in checking if tag is alive or commfault, so added again
    // abstractEquipmentCache.putQuiet(abstractEquipment);
    // aliveTimerFacade.generateFromEquipment(abstractEquipment);
    // commFaultTagFacade.generateFromEquipment(abstractEquipment);
    return abstractEquipment;
  } finally {
    abstractEquipmentCache.releaseWriteLockOnKey(element.getEntityId());
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:52,代码来源:AbstractEquipmentConfigTransacted.java

示例14: updateDeviceClass

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
public ProcessChange updateDeviceClass(Long id, Properties elementProperties) {
  try {
    ProcessChange processChange = deviceClassConfigTransacted.doUpdateDeviceClass(id, elementProperties);
    return processChange;

  } catch (UnexpectedRollbackException e) {
    LOGGER.error("Rolling back update in cache");
    // DB transaction is rolled back here: reload the tag
    deviceClassCache.remove(id);
    deviceClassCache.loadFromDb(id);
    throw e;
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:15,代码来源:DeviceClassConfigHandlerImpl.java

示例15: updateControlTag

import org.springframework.transaction.UnexpectedRollbackException; //导入依赖的package包/类
@Override
public ProcessChange updateControlTag(Long id, Properties elementProperties) throws IllegalAccessException {
  acquireEquipmentWriteLockForElement(id, elementProperties);
  try {
    return controlTagConfigTransacted.doUpdateControlTag(id, elementProperties); 
  } catch (UnexpectedRollbackException e) {
    LOGGER.error("Rolling back ControlTag update in cache");
    controlTagCache.remove(id);
    controlTagCache.loadFromDb(id);
    throw e;
  } finally {
    releaseEquipmentWriteLockForElement(id, elementProperties);
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:15,代码来源:ControlTagConfigHandlerImpl.java


注:本文中的org.springframework.transaction.UnexpectedRollbackException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。