Java Code Examples for org.springframework.transaction.annotation.Isolation#REPEATABLE_READ
The following examples show how to use
org.springframework.transaction.annotation.Isolation#REPEATABLE_READ .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LikeHelperService.java From xmfcn-spring-cloud with Apache License 2.0 | 6 votes |
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, isolation = Isolation.REPEATABLE_READ, timeout = 30, rollbackFor = Exception.class) public Like save(Like like) throws Exception { Like ret = null; if (like == null) { return ret; } if (like.getId() != null && like.getId() > 0) { updateById(like); ret = like; } else { like.setId(null); likeDao.add(like); ret = like; } return ret; }
Example 2
Source File: BuildingsServiceImpl.java From retro-game with GNU Affero General Public License v3.0 | 6 votes |
@Override @Transactional(isolation = Isolation.REPEATABLE_READ) public void moveUp(long bodyId, int sequenceNumber) { Body body = bodyRepository.getOne(bodyId); SortedMap<Integer, BuildingQueueEntry> queue = body.getBuildingQueue(); if (!queue.containsKey(sequenceNumber)) { logger.warn("Moving up entry in building queue failed, no such queue entry: bodyId={} sequenceNumber={}", bodyId, sequenceNumber); throw new NoSuchQueueEntryException(); } SortedMap<Integer, BuildingQueueEntry> head = queue.headMap(sequenceNumber); if (head.isEmpty()) { logger.warn("Moving up entry in building queue failed, the entry is first: bodyId={} sequenceNumber={}", bodyId, sequenceNumber); throw new CannotMoveException(); } // Moving an entry up is equivalent to moving the previous one down. moveDown(bodyId, head.lastKey()); }
Example 3
Source File: BaseDao.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ) public void internalMarkAsDeleted(final O obj) { if (obj instanceof Historizable == false) { log.error("Object is not historizable. Therefore marking as deleted is not supported. Please use delete instead."); throw new InternalErrorException(); } onDelete(obj); final O dbObj = getHibernateTemplate().load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE); onSaveOrModify(obj); copyValues(obj, dbObj, "deleted"); // If user has made additional changes. dbObj.setDeleted(true); dbObj.setLastUpdate(); final Session session = getHibernateTemplate().getSessionFactory().getCurrentSession(); session.flush(); Search.getFullTextSession(session).flushToIndexes(); afterSaveOrModify(obj); afterDelete(obj); getSession().flush(); log.info("Object marked as deleted: " + dbObj.toString()); }
Example 4
Source File: DemoBusiness.java From maven-archetype with GNU Lesser General Public License v2.1 | 6 votes |
/** * This method was generated by MyBatis Generator. * This method corresponds to the database table demo * * @mbggenerated */ @Transactional(propagation=Propagation.REQUIRED,isolation =Isolation.REPEATABLE_READ, rollbackFor = Exception.class) public int update(List<Demo> list) throws Exception { int updateCount = 0; if (list == null || list.size() == 0) { return updateCount; } for (Demo obj : list) { if (obj == null || obj.getId() == null || obj.getId() <= 0 ) { continue; } try { updateCount += this.demoMapper.updateByPrimaryKeySelective(obj); } catch (Exception e) { throw e; } } return updateCount; }
Example 5
Source File: DatevImportDao.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ) public void commit(final ImportStorage< ? > storage, final String sheetName) { checkLoggeinUserRight(accessChecker); Validate.notNull(storage.getSheets()); final ImportedSheet< ? > sheet = storage.getNamedSheet(sheetName); Validate.notNull(sheet); if (sheet.getStatus() != ImportStatus.RECONCILED) { throw new UserException("common.import.action.commit.error.notReconciled"); } int no = -1; if (storage.getId() == Type.KONTENPLAN) { no = commitKontenplan((ImportedSheet<KontoDO>) sheet); } else { no = commitBuchungsdaten((ImportedSheet<BuchungssatzDO>) sheet); } sheet.setNumberOfCommittedElements(no); sheet.setStatus(ImportStatus.IMPORTED); }
Example 6
Source File: StatisticsServiceImpl.java From retro-game with GNU Affero General Public License v3.0 | 6 votes |
@Override @Transactional(isolation = Isolation.REPEATABLE_READ, readOnly = true) public List<Tuple2<Date, StatisticsDistributionDto>> getDistributionChanges(long bodyId, long userId, StatisticsPeriodDto period) { Iterator<BuildingsStatistics> buildingsIt = fetch(buildingsStatisticsRepository, period, userId).iterator(); Iterator<TechnologiesStatistics> technologiesIt = fetch(technologiesStatisticsRepository, period, userId).iterator(); Iterator<FleetStatistics> fleetIt = fetch(fleetStatisticsRepository, period, userId).iterator(); Iterator<DefenseStatistics> defenseIt = fetch(defenseStatisticsRepository, period, userId).iterator(); List<Tuple2<Date, StatisticsDistributionDto>> distribution = new ArrayList<>(); while (buildingsIt.hasNext() && technologiesIt.hasNext() && fleetIt.hasNext() && defenseIt.hasNext()) { BuildingsStatistics b = buildingsIt.next(); TechnologiesStatistics t = technologiesIt.next(); FleetStatistics f = fleetIt.next(); DefenseStatistics d = defenseIt.next(); assert t.getAt().equals(b.getAt()); assert f.getAt().equals(b.getAt()); assert d.getAt().equals(b.getAt()); distribution.add(Tuple.of(b.getAt(), new StatisticsDistributionDto(b.getPoints(), t.getPoints(), f.getPoints(), d.getPoints()))); } return distribution; }
Example 7
Source File: BaseDao.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ) public void internalUndelete(final O obj) { final O dbObj = getHibernateTemplate().load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE); onSaveOrModify(obj); copyValues(obj, dbObj, "deleted"); // If user has made additional changes. dbObj.setDeleted(false); obj.setDeleted(false); dbObj.setLastUpdate(); obj.setLastUpdate(dbObj.getLastUpdate()); log.info("Object undeleted: " + dbObj.toString()); final Session session = getHibernateTemplate().getSessionFactory().getCurrentSession(); session.flush(); Search.getFullTextSession(session).flushToIndexes(); afterSaveOrModify(obj); afterUndelete(obj); }
Example 8
Source File: DefaultInterpretationService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @Transactional( isolation = Isolation.REPEATABLE_READ ) public boolean likeInterpretation( long id ) { Interpretation interpretation = getInterpretation( id ); if ( interpretation == null ) { return false; } User user = currentUserService.getCurrentUser(); if ( user == null ) { return false; } boolean userLike = interpretation.like( user ); notifySubscribers( interpretation, null, NotificationType.INTERPRETATION_LIKE ); return userLike; }
Example 9
Source File: DefaultInterpretationService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @Transactional( isolation = Isolation.REPEATABLE_READ ) public boolean unlikeInterpretation( long id ) { Interpretation interpretation = getInterpretation( id ); if ( interpretation == null ) { return false; } User user = currentUserService.getCurrentUser(); if ( user == null ) { return false; } return interpretation.unlike( user ); }
Example 10
Source File: PersonalContactDao.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @param obj * @return the generated identifier. */ @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ) public Serializable saveOrUpdate(final PersonalContactDO obj) { if (internalUpdate(obj) == true) { return obj.getId(); } return internalSave(obj); }
Example 11
Source File: DemoBusiness.java From maven-archetype with GNU Lesser General Public License v2.1 | 5 votes |
/** * This method was generated by MyBatis Generator. * This method corresponds to the database table demo * * @mbggenerated */ @Transactional(propagation=Propagation.REQUIRED,isolation =Isolation.REPEATABLE_READ, rollbackFor = Exception.class) public int update(Demo obj) throws Exception { if(obj == null ){ return 0; } return this.demoMapper.updateByPrimaryKeySelective(obj); }
Example 12
Source File: AllianceServiceImpl.java From retro-game with GNU Affero General Public License v3.0 | 5 votes |
@Override @Transactional(isolation = Isolation.REPEATABLE_READ) public void leave(long bodyId, long allianceId) { UserAndAllianceAndMemberTuple tuple = getUserAndAllianceAndMember(allianceId); long userId = tuple.user.getId(); if (tuple.alliance.getOwner().getId() == userId) { logger.warn("Leaving alliance failed, the owner cannot leave: userId={} allianceId={}", userId, allianceId); throw new OwnerCannotLeaveException(); } AllianceMember member = tuple.member; if (member == null) { logger.warn("Leaving alliance failed, user is not a member of the alliance: userId={} allianceId={}", userId, allianceId); throw new UserIsNotAMemberException(); } logger.info("Leaving alliance successful: userId={} allianceId={}", userId, allianceId); allianceMemberRepository.delete(member); // Update cache. TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCommit() { userAllianceCache.removeUserAlliance(userId); } }); }
Example 13
Source File: UserXmlPreferencesDao.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.REPEATABLE_READ) public void saveOrUpdate(final Integer userId, final String key, final Object entry, final boolean checkAccess) { if (accessChecker.isDemoUser(userId) == true) { // Do nothing. return; } boolean isNew = false; UserXmlPreferencesDO userPrefs = getUserPreferencesByUserId(userId, key, checkAccess); final Date date = new Date(); if (userPrefs == null) { isNew = true; userPrefs = new UserXmlPreferencesDO(); userPrefs.setCreated(date); userPrefs.setUser(userDao.internalGetById(userId)); userPrefs.setKey(key); } final String xml = serialize(userPrefs, entry); userPrefs.setLastUpdate(date); userPrefs.setVersion(); if (isNew == true) { if (log.isDebugEnabled() == true) { log.debug("Storing new user preference for user '" + userId + "': " + xml); } getHibernateTemplate().save(userPrefs); } else { if (log.isDebugEnabled() == true) { log.debug("Updating user preference for user '" + userPrefs.getUserId() + "': " + xml); } getHibernateTemplate().update(userPrefs); } }
Example 14
Source File: TeamCalImportDao.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ) public void commit(final ImportStorage< ? > storage, final ImportedSheet<?> sheet, final Integer teamCalId) { Validate.notNull(storage.getSheets()); Validate.notNull(sheet); Validate.isTrue(sheet.getStatus() == ImportStatus.RECONCILED); final int no = commit((ImportedSheet<TeamEventDO>)sheet, teamCalId); sheet.setNumberOfCommittedElements(no); sheet.setStatus(ImportStatus.IMPORTED); }
Example 15
Source File: BaseDao.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * * @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); }
Example 16
Source File: UserServiceImpl.java From cc-s with MIT License | 4 votes |
/** * 保存用户 * @param user * @return */ @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.REPEATABLE_READ) @Override public Integer saveUser(UserBean user){ return this.userMapper.saveUser(user); }
Example 17
Source File: TechnologyServiceImpl.java From retro-game with GNU Affero General Public License v3.0 | 4 votes |
@Override @Transactional(isolation = Isolation.REPEATABLE_READ) public void handle(Event event) { long userId = event.getParam(); User user = userRepository.getOne(userId); Date at = event.getAt(); eventRepository.delete(event); Collection<TechnologyQueueEntry> values = user.getTechnologyQueue().values(); Iterator<TechnologyQueueEntry> it = values.iterator(); // This shouldn't happen. if (!it.hasNext()) { logger.error("Handling technology queue, queue is empty: userId={}", userId); return; } TechnologyQueueEntry entry = it.next(); TechnologyKind kind = entry.getKind(); it.remove(); technologyQueueEntryRepository.delete(entry); // Update technologies. var oldLevel = user.getTechnologyLevel(kind); assert oldLevel >= 0; var newLevel = oldLevel + 1; logger.info("Handling technology queue, updating technology level: userId={} kind={} oldLevel={} newLevel={}", userId, kind, oldLevel, newLevel); user.setTechnologyLevel(kind, newLevel); while (it.hasNext()) { entry = it.next(); kind = entry.getKind(); int sequenceNumber = entry.getSequence(); var level = user.getTechnologyLevel(kind) + 1; Body body = entry.getBody(); long bodyId = body.getId(); bodyServiceInternal.updateResources(body, at); var cost = ItemCostUtils.getCost(kind, level); if (!body.getResources().greaterOrEqual(cost)) { logger.info("Handling technology queue, removing entry, not enough resources: userId={} bodyId={} kind={}" + " sequenceNumber={}", userId, bodyId, kind, sequenceNumber); it.remove(); technologyQueueEntryRepository.delete(entry); continue; } var requiredEnergy = ItemCostUtils.getRequiredEnergy(kind, level); if (requiredEnergy > 0) { int totalEnergy = bodyServiceInternal.getProduction(body).getTotalEnergy(); if (requiredEnergy > totalEnergy) { logger.info("Handling technology queue, removing entry, not enough energy: userId={} bodyId={} kind={}" + " sequenceNumber={}", userId, bodyId, kind, sequenceNumber); it.remove(); technologyQueueEntryRepository.delete(entry); continue; } } var item = Item.get(kind); if (!ItemRequirementsUtils.meetsRequirements(item, body)) { logger.info("Handling technology queue, removing entry, requirements not met: userId={} bodyId={} kind={}" + " sequenceNumber={}", userId, bodyId, kind, sequenceNumber); it.remove(); technologyQueueEntryRepository.delete(entry); continue; } logger.info("Handling technology queue, creating an event: userId={} bodyId={} kind={} sequenceNumber={}", userId, bodyId, kind, sequenceNumber); body.getResources().sub(cost); int[] table = getEffectiveLevelTables(user, Collections.singletonList(bodyId)).get(bodyId); int requiredLabLevel = item.getBuildingsRequirements().getOrDefault(BuildingKind.RESEARCH_LAB, 0); int effectiveLabLevel = table[requiredLabLevel]; var irnLevel = user.getTechnologyLevel(TechnologyKind.INTERGALACTIC_RESEARCH_NETWORK); var requiredTime = itemTimeUtils.getTechnologyResearchTime(cost, effectiveLabLevel, irnLevel); Date startAt = Date.from(Instant.ofEpochSecond(at.toInstant().getEpochSecond() + requiredTime)); Event newEvent = new Event(); newEvent.setAt(startAt); newEvent.setKind(EventKind.TECHNOLOGY_QUEUE); newEvent.setParam(userId); eventScheduler.schedule(newEvent); break; } }
Example 18
Source File: AllianceServiceImpl.java From retro-game with GNU Affero General Public License v3.0 | 4 votes |
@Override @Transactional(isolation = Isolation.REPEATABLE_READ) public void acceptApplication(long bodyId, long applicationId) { processApplication(applicationId, true); }
Example 19
Source File: AllianceServiceImpl.java From retro-game with GNU Affero General Public License v3.0 | 4 votes |
@Override @Transactional(isolation = Isolation.REPEATABLE_READ) public void rejectApplication(long bodyId, long applicationId) { processApplication(applicationId, false); }
Example 20
Source File: BaseDao.java From projectforge-webapp with GNU General Public License v3.0 | 2 votes |
/** * This method is for internal use e. g. for updating objects without check access. * @param obj * @return true, if modifications were done, false if no modification detected. * @see #internalUpdate(ExtendedBaseDO, boolean) */ @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.REPEATABLE_READ) public ModificationStatus internalUpdate(final O obj) { return internalUpdate(obj, false); }