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


Java LockModeType类代码示例

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


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

示例1: release

import javax.persistence.LockModeType; //导入依赖的package包/类
@Override
public void release() {
    final Lock lock = entityManager.find(Lock.class, applicationId, LockModeType.PESSIMISTIC_WRITE);

    if (lock == null) {
        return;
    }
    // Only the current owner can release the lock
    final String owner = lock.getUniqueId();
    if (uniqueId.equals(owner)) {
        lock.setUniqueId(null);
        lock.setExpirationDate(null);
        logger.debug("Releasing {} lock held by {}.", applicationId, uniqueId);
        entityManager.persist(lock);
    } else {
        throw new IllegalStateException("Cannot release lock owned by " + owner);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:JpaLockingStrategy.java

示例2: release

import javax.persistence.LockModeType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 **/
@Override
@Transactional(readOnly = false)
public void release() {
    final Lock lock = entityManager.find(Lock.class, applicationId, LockModeType.PESSIMISTIC_WRITE);

    if (lock == null) {
        return;
    }
    // Only the current owner can release the lock
    final String owner = lock.getUniqueId();
    if (uniqueId.equals(owner)) {
        lock.setUniqueId(null);
        lock.setExpirationDate(null);
        logger.debug("Releasing {} lock held by {}.", applicationId, uniqueId);
        entityManager.persist(lock);
    } else {
        throw new IllegalStateException("Cannot release lock owned by " + owner);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:23,代码来源:JpaLockingStrategy.java

示例3: deleteTicketAndChildren

import javax.persistence.LockModeType; //导入依赖的package包/类
/**
 * Delete the TGt and all of its service tickets.
 *
 * @param ticket the ticket
 */
private void deleteTicketAndChildren(final Ticket ticket) {
    final List<TicketGrantingTicketImpl> ticketGrantingTicketImpls = entityManager
        .createQuery("select t from TicketGrantingTicketImpl t where t.ticketGrantingTicket.id = :id",
                TicketGrantingTicketImpl.class)
        .setLockMode(LockModeType.PESSIMISTIC_WRITE)
        .setParameter("id", ticket.getId())
        .getResultList();
    final List<ServiceTicketImpl> serviceTicketImpls = entityManager
            .createQuery("select s from ServiceTicketImpl s where s.ticketGrantingTicket.id = :id",
                    ServiceTicketImpl.class)
            .setParameter("id", ticket.getId())
            .getResultList();

    for (final ServiceTicketImpl s : serviceTicketImpls) {
        removeTicket(s);
    }

    for (final TicketGrantingTicketImpl t : ticketGrantingTicketImpls) {
        deleteTicketAndChildren(t);
    }

    removeTicket(ticket);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:29,代码来源:JpaTicketRegistry.java

示例4: aggregate

import javax.persistence.LockModeType; //导入依赖的package包/类
private <S> S aggregate(CriteriaBuilder builder, CriteriaQuery<S> query, Root<E> root, Specification<E> spec, List<Selection<?>> selectionList, LockModeType lockMode) {
	if (selectionList != null) {
		Predicate predicate = spec.toPredicate(root, query, builder);
		if (predicate != null) {
			query.where(predicate);
		}
		query.multiselect(selectionList);
		return (S) em.createQuery(query).setLockMode(lockMode).getSingleResult();
	}
	return null;
}
 
开发者ID:onsoul,项目名称:os,代码行数:12,代码来源:GenericRepositoryImpl.java

示例5: findOneByProperty

import javax.persistence.LockModeType; //导入依赖的package包/类
/**
 * 根据某些属性获取对象L
 * @param name 属性名称
 * @param value 属性值
 * @param lockMode 对象锁类型
 * @return
 */
public T findOneByProperty(String name, Object value, LockModeType lockMode) {
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<T> query = cb.createQuery(entityClass);
	Root<T> root = query.from(entityClass);
	query.where(cb.equal(QueryFormHelper.getPath(root, name), value));
	TypedQuery<T> typedQuery = em.createQuery(query);
	typedQuery.setLockMode(lockMode);
	try {
		List<T> list = typedQuery.getResultList();
		if (list.isEmpty()) {
			return null;
		} else {
			return list.get(0);
		}
	} catch (NoResultException e) {
		return null;
	}
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:26,代码来源:BaseDao.java

示例6: deleteTicketAndChildren

import javax.persistence.LockModeType; //导入依赖的package包/类
private void deleteTicketAndChildren(final Ticket ticket) {
    final List<TicketGrantingTicketImpl> ticketGrantingTicketImpls = entityManager
        .createQuery("select t from TicketGrantingTicketImpl t where t.ticketGrantingTicket.id = :id",
                TicketGrantingTicketImpl.class)
        .setLockMode(LockModeType.PESSIMISTIC_WRITE)
        .setParameter("id", ticket.getId())
        .getResultList();
    final List<ServiceTicketImpl> serviceTicketImpls = entityManager
            .createQuery("select s from ServiceTicketImpl s where s.ticketGrantingTicket.id = :id",
                    ServiceTicketImpl.class)
            .setParameter("id", ticket.getId())
            .getResultList();

    for (final ServiceTicketImpl s : serviceTicketImpls) {
        removeTicket(s);
    }

    for (final TicketGrantingTicketImpl t : ticketGrantingTicketImpls) {
        deleteTicketAndChildren(t);
    }

    removeTicket(ticket);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:24,代码来源:JpaTicketRegistry.java

示例7: executeTransaction

import javax.persistence.LockModeType; //导入依赖的package包/类
@Override
public void executeTransaction(EntityManager em) throws Exception {
    log.debug("Start excecuting RegisterMgrPolicyNotificationTask Task. MC: '" + this.mc.getName() + "'");

    this.mc = em.find(ApplianceManagerConnector.class, this.mc.getId(),
            LockModeType.PESSIMISTIC_WRITE);
    ManagerCallbackNotificationApi mgrApi = null;
    try {
        mgrApi = this.apiFactoryService.createManagerUrlNotificationApi(this.mc);
        mgrApi.createPolicyGroupNotificationRegistration(Server.getApiPort(), RestConstants.OSC_DEFAULT_LOGIN,
                this.passwordUtil.getOscDefaultPass());
        this.mc.setLastKnownNotificationIpAddress(ServerUtil.getServerIP());
        OSCEntityManager.update(em, this.mc, this.txBroadcastUtil);
    } finally {
        if (mgrApi != null) {
            mgrApi.close();
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:20,代码来源:RegisterMgrPolicyNotificationTask.java

示例8: executeTransaction

import javax.persistence.LockModeType; //导入依赖的package包/类
@Override
public void executeTransaction(EntityManager em) throws Exception {
    log.debug("Start excecuting RegisterMgrDomainNotificationTask Task. MC: '" + this.mc.getName() + "'");

    this.mc = em.find(ApplianceManagerConnector.class, this.mc.getId(),
            LockModeType.PESSIMISTIC_WRITE);
    ManagerCallbackNotificationApi mgrApi = null;
    try {
        mgrApi = this.apiFactoryService.createManagerUrlNotificationApi(this.mc);
        mgrApi.createDomainNotificationRegistration(Server.getApiPort(), RestConstants.OSC_DEFAULT_LOGIN,
                this.passwordUtil.getOscDefaultPass());
        this.mc.setLastKnownNotificationIpAddress(ServerUtil.getServerIP());
        OSCEntityManager.update(em, this.mc, this.txBroadcastUtil);
    } finally {
        if (mgrApi != null) {
            mgrApi.close();
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:20,代码来源:RegisterMgrDomainNotificationTask.java

示例9: executeTransaction

import javax.persistence.LockModeType; //导入依赖的package包/类
@Override
public void executeTransaction(EntityManager em) throws Exception {
    log.debug("Start excecuting RegisterMgrPolicyNotificationTask Task. MC: '" + this.mc.getName() + "'");

    this.mc = em.find(ApplianceManagerConnector.class, this.mc.getId(),
            LockModeType.PESSIMISTIC_WRITE);
    ManagerCallbackNotificationApi mgrApi = null;
    try {
        mgrApi = this.apiFactoryService.createManagerUrlNotificationApi(this.mc);
        mgrApi.updatePolicyGroupNotificationRegistration(this.oldBrokerIp, Server.getApiPort(),
                RestConstants.OSC_DEFAULT_LOGIN, this.passwordUtil.getOscDefaultPass());
        this.mc.setLastKnownNotificationIpAddress(ServerUtil.getServerIP());
        OSCEntityManager.update(em, this.mc, this.txBroadcastUtil);
    } finally {
        if (mgrApi != null) {
            mgrApi.close();
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:20,代码来源:UpdateMgrPolicyNotificationTask.java

示例10: generateUniqueTag

import javax.persistence.LockModeType; //导入依赖的package包/类
/**
 * List all tags used within a VS and locate the next 'minimum' available tag starting with 2. If there are tags
 * 'holes' (i.e. for "1,2,3,6,7,9" - 4,5,8,10... will be available for allocation). If no 'holes' available,
 * will allocate the next minimum number (10 in our example).
 *
 * @param session
 *            database session
 * @param vs
 *            Virtual System Object to get tag for
 * @return Minimum and unique tag for given VS.
 */
@SuppressWarnings("unchecked")
public static synchronized Long generateUniqueTag(EntityManager em, VirtualSystem vs) {
    vs = em.find(VirtualSystem.class, vs.getId(),
            LockModeType.PESSIMISTIC_WRITE);
    String sql = "SELECT CONVERT(SUBSTR(tag,LOCATE('-',tag)+1), LONG) AS tag_val "
            + "FROM security_group_interface WHERE virtual_system_fk = " + vs.getId() + " ORDER BY tag_val";
    List<Object> list = em.createNativeQuery(sql).getResultList();
    // Start with 2 as 1 is reserved in some cases
    // TODO: arvindn - Some security partners require tag's larger than 300. Remove once problem is fixed on the
    // partners side.
    Long prevVal = 301L;
    for (Object tag : list) {
        long tagValue = ((BigInteger) tag).longValue();
        if (tagValue != prevVal) {
            return prevVal;
        }
        prevVal++;
    }
    return prevVal;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:32,代码来源:VirtualSystemEntityMgr.java

示例11: testInitialize

import javax.persistence.LockModeType; //导入依赖的package包/类
@Before
public void testInitialize() throws Exception {
    MockitoAnnotations.initMocks(this);

    Mockito.when(this.em.getTransaction()).thenReturn(this.tx);

    this.txControl.setEntityManager(this.em);

    Mockito.when(this.dbMgr.getTransactionalEntityManager()).thenReturn(this.em);
    Mockito.when(this.dbMgr.getTransactionControl()).thenReturn(this.txControl);

    this.vs = new VirtualSystem();
    this.vs.setId(2L);
    this.vs.setName("vs");
    Appliance appliance = new Appliance();
    this.applianceSoftwareVersion = new ApplianceSoftwareVersion(appliance);
    this.applianceSoftwareVersion.setApplianceSoftwareVersion("applianceSoftwareVersion");
    this.vs.setApplianceSoftwareVersion(this.applianceSoftwareVersion);

    Mockito.when(this.em.find(Mockito.eq(VirtualSystem.class), Mockito.eq(this.vs.getId()),
            Mockito.eq(LockModeType.PESSIMISTIC_WRITE))).thenReturn(this.vs);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:23,代码来源:UpdateVsWithImageVersionTaskTest.java

示例12: convertToLockModeType

import javax.persistence.LockModeType; //导入依赖的package包/类
/**
 * 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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:LockModeConverter.java

示例13: acquire

import javax.persistence.LockModeType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 **/
@Override
@Transactional(readOnly = false)
public boolean acquire() {
    Lock lock;
    try {
        lock = entityManager.find(Lock.class, applicationId, LockModeType.PESSIMISTIC_WRITE);
    } catch (final PersistenceException e) {
        logger.debug("{} failed querying for {} lock.", uniqueId, applicationId, e);
        return false;
    }

    boolean result = false;
    if (lock != null) {
        final DateTime expDate = new DateTime(lock.getExpirationDate());
        if (lock.getUniqueId() == null) {
            // No one currently possesses lock
            logger.debug("{} trying to acquire {} lock.", uniqueId, applicationId);
            result = acquire(entityManager, lock);
        } else if (new DateTime().isAfter(expDate)) {
            // Acquire expired lock regardless of who formerly owned it
            logger.debug("{} trying to acquire expired {} lock.", uniqueId, applicationId);
            result = acquire(entityManager, lock);
        }
    } else {
        // First acquisition attempt for this applicationId
        logger.debug("Creating {} lock initially held by {}.", applicationId, uniqueId);
        result = acquire(entityManager, new Lock());
    }
    return result;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:34,代码来源:JpaLockingStrategy.java

示例14: getRawTicket

import javax.persistence.LockModeType; //导入依赖的package包/类
/**
 * Gets the ticket from the database, as is.
 *
 * @param ticketId the ticket id
 * @return the raw ticket
 */
private Ticket getRawTicket(final String ticketId) {
    try {
        if (ticketId.startsWith(this.ticketGrantingTicketPrefix)) {
            return entityManager.find(TicketGrantingTicketImpl.class, ticketId, LockModeType.PESSIMISTIC_WRITE);
        }

        return entityManager.find(ServiceTicketImpl.class, ticketId);
    } catch (final Exception e) {
        logger.error("Error getting ticket {} from registry.", ticketId, e);
    }
    return null;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:JpaTicketRegistry.java

示例15: acquire

import javax.persistence.LockModeType; //导入依赖的package包/类
@Override
public boolean acquire() {
    final Lock lock;
    try {
        lock = this.entityManager.find(Lock.class, this.applicationId, LockModeType.OPTIMISTIC);
    } catch (final Exception e) {
        LOGGER.debug("[{}] failed querying for [{}] lock.", this.uniqueId, this.applicationId, e);
        return false;
    }

    boolean result = false;
    if (lock != null) {
        final ZonedDateTime expDate = lock.getExpirationDate();
        if (lock.getUniqueId() == null) {
            // No one currently possesses lock
            LOGGER.debug("[{}] trying to acquire [{}] lock.", this.uniqueId, this.applicationId);
            result = acquire(lock);
        } else if (expDate == null || ZonedDateTime.now(ZoneOffset.UTC).isAfter(expDate)) {
            // Acquire expired lock regardless of who formerly owned it
            LOGGER.debug("[{}] trying to acquire expired [{}] lock.", this.uniqueId, this.applicationId);
            result = acquire(lock);
        }
    } else {
        // First acquisition attempt for this applicationId
        LOGGER.debug("Creating [{}] lock initially held by [{}].", applicationId, uniqueId);
        result = acquire(new Lock());
    }
    return result;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:JpaLockingStrategy.java


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