Java Code Examples for javax.persistence.LockModeType#PESSIMISTIC_WRITE

The following examples show how to use javax.persistence.LockModeType#PESSIMISTIC_WRITE . 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: LockModeConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert from the Hibernate specific LockMode to the JPA defined LockModeType.
 *
 * @param lockMode The Hibernate LockMode.
 *
 * @return The JPA LockModeType
 */
public static LockModeType convertToLockModeType(LockMode lockMode) {
	if ( lockMode == LockMode.NONE ) {
		return LockModeType.NONE;
	}
	else if ( lockMode == LockMode.OPTIMISTIC || lockMode == LockMode.READ ) {
		return LockModeType.OPTIMISTIC;
	}
	else if ( lockMode == LockMode.OPTIMISTIC_FORCE_INCREMENT || lockMode == LockMode.WRITE ) {
		return LockModeType.OPTIMISTIC_FORCE_INCREMENT;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_READ ) {
		return LockModeType.PESSIMISTIC_READ;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_WRITE
			|| lockMode == LockMode.UPGRADE
			|| lockMode == LockMode.UPGRADE_NOWAIT
			|| lockMode == LockMode.UPGRADE_SKIPLOCKED) {
		return LockModeType.PESSIMISTIC_WRITE;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT
			|| lockMode == LockMode.FORCE ) {
		return LockModeType.PESSIMISTIC_FORCE_INCREMENT;
	}
	throw new AssertionFailure( "unhandled lock mode " + lockMode );
}
 
Example 2
Source File: ApplicationRepository.java    From steady with 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 File: ApplicationRepository.java    From steady with 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 File: TransactionDao.java    From payment with 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 5
Source File: TransactionDao.java    From payment with 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 6
Source File: CommentRepository.java    From wallride with 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 7
Source File: MediaRepository.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
Media findOneForUpdateById(String id);
 
Example 8
Source File: BlogRepository.java    From wallride with 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 9
Source File: TagRepository.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
Tag findOneForUpdateByIdAndLanguage(Long id, String language);
 
Example 10
Source File: TagRepository.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
Tag findOneForUpdateByNameAndLanguage(String name, String language);
 
Example 11
Source File: CustomFieldRepository.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
CustomField findOneForUpdateById(Long id);
 
Example 12
Source File: CustomFieldRepository.java    From wallride with Apache License 2.0 4 votes vote down vote up
@EntityGraph(value = CustomField.DEEP_GRAPH_NAME, type = EntityGraph.EntityGraphType.FETCH)
@Lock(LockModeType.PESSIMISTIC_WRITE)
CustomField findOneForUpdateByIdAndLanguage(Long id, String language);
 
Example 13
Source File: UserRepository.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
User findOneForUpdateById(Long id);
 
Example 14
Source File: UserInvitationRepository.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Lock(LockModeType.PESSIMISTIC_WRITE)
UserInvitation findOneForUpdateByToken(String token);
 
Example 15
Source File: JpaRepositoryCustomisations.java    From rest-example with 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);