Java Code Examples for org.springframework.data.jpa.repository.Lock

The following examples show how to use org.springframework.data.jpa.repository.Lock. These examples are extracted from open source projects. 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 Project: txle   Source File: CommandEntityRepository.java    License: Apache License 2.0 5 votes vote down vote up
@Lock(LockModeType.OPTIMISTIC)
  @Query(value = "SELECT * FROM Command AS c "
      + "WHERE c.eventId IN ("
      + " SELECT MAX(c1.eventId) FROM Command AS c1 "
      + " INNER JOIN Command AS c2 on c1.globalTxId = c2.globalTxId"
      + " WHERE c1.status = 'NEW' "
      + " GROUP BY c1.globalTxId "
      + " HAVING MAX( CASE c2.status WHEN 'PENDING' THEN 1 ELSE 0 END ) = 0) "
//      + "ORDER BY c.eventId ASC LIMIT 1", nativeQuery = true)// 'LIMIT 1' made an effect on performance, and Compensation Command is always executed one by one. So, we canceled 'LIMIT 1'.
      + "ORDER BY c.eventId ASC", nativeQuery = true)
  // 查询某全局事务没有PENDING状态且为NEW状态的Command
  List<Command> findFirstGroupByGlobalTxIdWithoutPendingOrderByIdDesc();
 
Example 2
Source Project: steady   Source File: ApplicationRepository.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Finds the applications whose dependencies include constructs from the given list.
 * Note: the outer select a was added because the lock does not allow the use of "distinct" and we want to avoid to update the same application multiple times in the subsequent update query
 *
 * @param listOfConstructs list of {@link ConstructId}
 * @return list of {@link Application}
 */
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Transactional
@Query("select a from Application a where a in"
		+ "( SELECT distinct d.app FROM Dependency d "
		+ "	  JOIN "
		+ "   d.lib l"
		+ "   JOIN "
		+ "   l.constructs lc "
		+ "	  WHERE lc IN :listOfConstructs "
		+ "   AND (NOT lc.type='PACK' "                        // Java + Python exception
		+ "   OR NOT EXISTS (SELECT 1 FROM ConstructChange cc1 JOIN cc1.constructId c1 WHERE c1 IN :listOfConstructs AND NOT c1.type='PACK' AND NOT c1.qname LIKE '%test%' AND NOT c1.qname LIKE '%Test%' and NOT cc1.constructChangeType='ADD') ) "
		+ "   AND NOT (lc.type='MODU' AND (lc.qname='setup' OR lc.qname='tests' OR lc.qname='test.__init__')) )" // Python-specific exception: setup.py is virtually everywhere, considering it would bring far too many FPs. Similarly tests.py originates such a generic module that would bring up too many FPs
		)
List<Application> findAppsByCC(@Param("listOfConstructs") List<ConstructId> listOfConstructs);
 
Example 3
Source Project: steady   Source File: ApplicationRepository.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Finds the applications whose dependencies include {@link LibraryId}s from the given list.
 * Note: the outer select a was added because the lock does not allow the use of "distinct" and we want to avoid to update the same application multiple times in the subsequent update query
 *
 * @return list of {@link Application}
 * @param affLibId a {@link com.sap.psr.vulas.backend.model.LibraryId} object.
 */
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Transactional
@Query("select a from Application a where a in"
		+ "( SELECT distinct d.app FROM Dependency d "
		+ "	  JOIN "
		+ "   d.lib l"
		+ "   JOIN "
		+ "   l.libraryId dep_libid"
		+ "	  WHERE dep_libid = :affLibId )"
		)
List<Application> findAppsByAffLib(@Param("affLibId") LibraryId affLibId);
 
Example 4
Source Project: servicecomb-pack   Source File: CommandEntityRepository.java    License: Apache License 2.0 5 votes vote down vote up
@Lock(LockModeType.OPTIMISTIC)
@Query(value = "SELECT * FROM Command AS c "
    + "WHERE c.eventId IN ("
    + " SELECT MAX(c1.eventId) FROM Command AS c1 "
    + " INNER JOIN Command AS c2 on c1.globalTxId = c2.globalTxId"
    + " WHERE c1.status = 'NEW' "
    + " GROUP BY c1.globalTxId "
    + " HAVING MAX( CASE c2.status WHEN 'PENDING' THEN 1 ELSE 0 END ) = 0) "
    + "ORDER BY c.eventId ASC LIMIT 1", nativeQuery = true)
List<Command> findFirstGroupByGlobalTxIdWithoutPendingOrderByIdDesc();
 
Example 5
Source Project: txle   Source File: TxTimeoutEntityRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.OPTIMISTIC)
@Query("SELECT t FROM TxTimeout AS t "
    + "WHERE t.status = 'NEW' "
    + "  AND t.expiryTime < CURRENT_TIMESTAMP "
    + "ORDER BY t.expiryTime ASC")
List<TxTimeout> findFirstTimeoutTxOrderByExpireTimeAsc(Pageable pageable);
 
Example 6
Source Project: txle   Source File: TxTimeoutEntityRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.OPTIMISTIC)
@Query(value = "SELECT * FROM TxTimeout AS t "
    + "WHERE t.status = 'NEW' "
    + "  AND t.expiryTime < ?1 "
    + "ORDER BY t.expiryTime ASC" + EventScanner.SCANNER_SQL, nativeQuery = true)
List<TxTimeout> findFirstTimeoutTxOrderByExpireTimeAsc(/*Pageable pageable, */Date currentDateTime);
 
Example 7
@Lock(LockModeType.OPTIMISTIC)
@Query("SELECT t FROM TxTimeout AS t "
    + "WHERE t.status = 'NEW' "
    + "  AND t.expiryTime < CURRENT_TIMESTAMP "
    + "ORDER BY t.expiryTime ASC")
List<TxTimeout> findFirstTimeoutTxOrderByExpireTimeAsc(Pageable pageable);
 
Example 8
Source Project: payment   Source File: TransactionDao.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT m FROM #{#entityName} m WHERE m.id=:transactionId")
TransactionPO findOneOnLock(@Param("transactionId") Long transactionId);
 
Example 9
Source Project: payment   Source File: TransactionDao.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT m FROM #{#entityName} m WHERE m.transactionNo=:orderNo")
List<TransactionPO> findByOrderNoOnLock(@Param("orderNo") String orderNo);
 
Example 10
Source Project: wallride   Source File: CommentRepository.java    License: Apache License 2.0 4 votes vote down vote up
@EntityGraph(value = Comment.DEEP_GRAPH_NAME, type = EntityGraph.EntityGraphType.FETCH)
@Lock(LockModeType.PESSIMISTIC_WRITE)
Comment findOneForUpdateById(Long id);
 
Example 11
Source Project: wallride   Source File: MediaRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
Media findOneForUpdateById(String id);
 
Example 12
Source Project: wallride   Source File: BlogRepository.java    License: Apache License 2.0 4 votes vote down vote up
@EntityGraph(value = Blog.DEEP_GRAPH_NAME, type = EntityGraph.EntityGraphType.FETCH)
@Lock(LockModeType.PESSIMISTIC_WRITE)
Blog findOneForUpdateById(Long id);
 
Example 13
Source Project: wallride   Source File: TagRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
Tag findOneForUpdateByIdAndLanguage(Long id, String language);
 
Example 14
Source Project: wallride   Source File: TagRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
Tag findOneForUpdateByNameAndLanguage(String name, String language);
 
Example 15
Source Project: wallride   Source File: UserRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
User findOneForUpdateById(Long id);
 
Example 16
Source Project: wallride   Source File: UserInvitationRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
UserInvitation findOneForUpdateByToken(String token);
 
Example 17
Source Project: tutorials   Source File: PersonRepository.java    License: MIT License 4 votes vote down vote up
@Lock(LockModeType.NONE)
@Query("SELECT COUNT(*) FROM Person p")
long getPersonCount();
 
Example 18
Source Project: spring-data-examples   Source File: BookRatingRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(OPTIMISTIC)
@Query("select br from BookRating br where br.book.isbn = :isbn")
BookRating findByBookIsbnOptimisticLock(String isbn);
 
Example 19
Source Project: spring-data-examples   Source File: BookRatingRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(OPTIMISTIC_FORCE_INCREMENT)
@Query("select br from BookRating br where br.book.isbn = :isbn")
BookRating findByBookIsbnOptimisticForceIncrementLock(String isbn);
 
Example 20
Source Project: spring-data-examples   Source File: BookRatingRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(PESSIMISTIC_WRITE)
@Query("select br from BookRating br where br.book.isbn = :isbn")
BookRating findByBookIsbnPessimisticWriteLock(String isbn);
 
Example 21
Source Project: spring-data-examples   Source File: BookRatingRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Lock(PESSIMISTIC_READ)
@Query("select br from BookRating br where br.book.isbn = :isbn")
BookRating findByBookIsbnPessimisticReadLock(String isbn);
 
Example 22
Source Project: heimdall   Source File: AppRepository.java    License: Apache License 2.0 2 votes vote down vote up
/**
* Finds a active App by its client Id.
* 
* @param  clientId		The client id
* @return				The App found
*/
   @Lock(LockModeType.NONE)
   @Cacheable(ConstantsCache.APPS_ACTIVE_CACHE)
   @Query("select a from App a join a.plans p where a.clientId = :clientId and a.status = 'ACTIVE' and p.status = 'ACTIVE' ")
   App findAppActive(@Param("clientId") String clientId);
 
Example 23
Source Project: heimdall   Source File: AppRepository.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Finds a App by its client Id.
 * 
 * @param  clientId		The client id
 * @return				The App found
 */
    @Lock(LockModeType.NONE)
    @Cacheable(ConstantsCache.APPS_CLIENT_ID)
App findByClientId(String clientId);
 
Example 24
Source Project: heimdall   Source File: AppRepository.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Finds a App by its name.
 * 
 * @param  name			The App name
 * @return				The App found
 */
    @Lock(LockModeType.NONE)
App findByName(String name);
 
Example 25
Source Project: heimdall   Source File: AppRepository.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Finds a List of {@link Plan} associated with a App.
 * 
 * @param  appId		The App Id
 * @return				The list of Plan
 */
    @Lock(LockModeType.NONE)
@Query("select p from App a join a.plans p where a.id = :appId")
List<Plan> findPlansByApp(@Param("appId") Long appId);
 
Example 26
Source Project: rest-example   Source File: JpaRepositoryCustomisations.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Persists the supplied entity.
 * If the entity has an id and previously has been persisted, it will be merged
 *  to the persistence context otherwise it will be inserted into the
 *  persistence context.
 *
 * @param inEntity Entity to persist.
 * @return Persisted entity.
 */
@Lock(LockModeType.PESSIMISTIC_WRITE)
T persist(T inEntity);