下面列出了org.springframework.transaction.annotation.Propagation#REQUIRES_NEW 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@inheritDoc}
* <p/>
* This implementation starts a new transaction.
*/
@NamespacePermission(fields = "#request?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public EmrMasterSecurityGroup addSecurityGroupsToClusterMaster(EmrMasterSecurityGroupAddRequest request) throws Exception
{
return addSecurityGroupsToClusterMasterImpl(request);
}
/**
*
* @param obj
* @return the generated identifier.
* @throws AccessException
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public Serializable save(final O obj) throws AccessException
{
Validate.notNull(obj);
if (avoidNullIdCheckBeforeSave == false) {
Validate.isTrue(obj.getId() == null);
}
checkLoggedInUserInsertAccess(obj);
accessChecker.checkRestrictedOrDemoUser();
return internalSave(obj);
}
@NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.READ)
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public BusinessObjectDataDdl generateBusinessObjectDataDdl(BusinessObjectDataDdlRequest request)
{
return generateBusinessObjectDataDdlImpl(request, false);
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void add(AuditEvent event) {
if (!AUTHORIZATION_FAILURE.equals(event.getType()) &&
!Constants.ANONYMOUS_USER.equals(event.getPrincipal())) {
PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
persistentAuditEvent.setPrincipal(event.getPrincipal());
persistentAuditEvent.setAuditEventType(event.getType());
persistentAuditEvent.setAuditEventDate(event.getTimestamp());
Map<String, String> eventData = auditEventConverter.convertDataToStrings(event.getData());
persistentAuditEvent.setData(truncate(eventData));
persistenceAuditEventRepository.save(persistentAuditEvent);
}
}
/**
* {@inheritDoc}
* <p/>
* This implementation starts a new transaction.
*/
@PublishNotificationMessages
@NamespacePermission(fields = "#businessObjectDataStorageUnitKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public BusinessObjectDataStorageUnitStatusUpdateResponse updateBusinessObjectDataStorageUnitStatus(
BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey, BusinessObjectDataStorageUnitStatusUpdateRequest request)
{
return updateBusinessObjectDataStorageUnitStatusImpl(businessObjectDataStorageUnitKey, request);
}
@Retryable
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateEvents(List<NotificationEvent> events, NotificationEvent.Status status) {
for (NotificationEvent event : events) {
event = genericDao.findById(event.getId());
event.setStatus(status);
event.getSubscription().setLastNotifiedDate(new Date());
updateEvent(event);
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
public Collection<ExternalResource> findAllResources(final User user) {
Set<ExternalResource> result = new HashSet<>();
result.addAll(user.getResources());
findAllGroups(user).forEach(group -> result.addAll(group.getResources()));
return result;
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void add(AuditEvent event) {
if (!AUTHORIZATION_FAILURE.equals(event.getType()) &&
!Constants.ANONYMOUS_USER.equals(event.getPrincipal())) {
PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
persistentAuditEvent.setPrincipal(event.getPrincipal());
persistentAuditEvent.setAuditEventType(event.getType());
persistentAuditEvent.setAuditEventDate(event.getTimestamp());
Map<String, String> eventData = auditEventConverter.convertDataToStrings(event.getData());
persistentAuditEvent.setData(truncate(eventData));
persistenceAuditEventRepository.save(persistentAuditEvent);
}
}
/**
* Ohne Zugangsbegrenzung. Wird bei Anmeldung benötigt.
* @param username
* @param encryptedPassword
* @return
*/
@SuppressWarnings("unchecked")
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public PFUserDO authenticateUser(final String username, final String password)
{
Validate.notNull(username);
Validate.notNull(password);
PFUserDO user = getUser(username, password, true);
if (user != null) {
final int loginFailures = user.getLoginFailures();
final Timestamp lastLogin = user.getLastLogin();
user.setLastLogin(new Timestamp(new Date().getTime()));
user.setLoginFailures(0);
user.setMinorChange(true); // Avoid re-indexing of all dependent objects.
internalUpdate(user, false);
if (user.hasSystemAccess() == false) {
log.warn("Deleted/deactivated user tried to login: " + user);
return null;
}
final PFUserDO contextUser = new PFUserDO();
contextUser.copyValuesFrom(user);
contextUser.setLoginFailures(loginFailures); // Restore loginFailures for current user session.
contextUser.setLastLogin(lastLogin); // Restore lastLogin for current user session.
contextUser.setPassword(null);
return contextUser;
}
final List<PFUserDO> list = getHibernateTemplate().find("from PFUserDO u where u.username = ?", username);
if (list != null && list.isEmpty() == false && list.get(0) != null) {
user = list.get(0);
user.setLoginFailures(user.getLoginFailures() + 1);
internalUpdate(user);
}
return null;
}
@Override
@Transactional(propagation=Propagation.REQUIRES_NEW)
public void batchUpdateToSent(Collection<SendMessageContext<?>> ctxs) {
List<SendMessageEntity> messages = ctxs.stream().map(ctx -> {
SendMessageEntity e = ctx.getMessageEntity();
e.setState(SendStates.SENT);
return e;
}).collect(Collectors.toList());
getBaseEntityManager().getSessionFactory().getSession().batchUpdate(messages);
}
/**
* {@inheritDoc}
* <p/>
* This implementation starts a new transaction.
*/
@NamespacePermission(fields = "#businessObjectDataKey?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public BusinessObjectDataAttributeKeys getBusinessObjectDataAttributes(BusinessObjectDataKey businessObjectDataKey)
{
return getBusinessObjectDataAttributesImpl(businessObjectDataKey);
}
@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");
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Modifying
@Query("update Check c set c.lastSentEmail = current_timestamp, currentErrorCount = 0 where c.id = ?1")
void emailSent(int checkId);
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInNewTransaction() {
RTransaction transaction = transactionManager.getCurrentTransaction();
transaction.getMap("tr2").put("2", "4");
}
@Override
@Transactional(readOnly=true, propagation=Propagation.REQUIRES_NEW)
public T find() {
return _find();
}
@Override
@Transactional(readOnly=true, propagation=Propagation.REQUIRES_NEW)
public <K> List<K> listValue() {
return _listValue();
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addRequiresNewException(User2 user){
user2Mapper.insert(user);
throw new RuntimeException();
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Modifying
@Query("update Check c set c.currentErrorCount = 0 where c.id = ?1")
void clearErrorCount(int checkId);
@Override
@Transactional(value = "cacheTransactionManager", propagation = Propagation.REQUIRES_NEW)
public List<ProcessChange> doUpdateAbstractEquipment(final SubEquipment subEquipment, Properties properties) throws IllegalAccessException {
return super.updateAbstractEquipment(subEquipment, properties);
}
/**
* Saves the given synchronizer's configuration back in the databse.
* This method is intended to be used by Synchronizers themselves, this
* method does no tests at all to avoid deadlocks.
* <p>
* This method is unsafe and you should probably be using
* {@link #saveSynchronizerConf(SynchronizerConf)} instead.
* @param s to save.
*/
@Override
@Transactional (propagation = Propagation.REQUIRES_NEW)
public void saveSynchronizer (Synchronizer s)
{
this.synchronizerDao.update (s.getSynchronizerConf ());
}