Java 类org.hibernate.StaleStateException 实例源码

项目:lams    文件:Expectations.java   
private void checkBatched(int rowCount, int batchPosition) {
          if (rowCount == -2) LOG.debugf("Success of batch update unknown: %s", batchPosition);
          else if (rowCount == -3) throw new BatchFailedException("Batch update failed: " + batchPosition);
    else {
              if (expectedRowCount > rowCount) throw new StaleStateException(
                                                                             "Batch update returned unexpected row count from update ["
                                                                             + batchPosition + "]; actual row count: " + rowCount
                                                                             + "; expected: " + expectedRowCount);
        if ( expectedRowCount < rowCount ) {
            String msg = "Batch update returned unexpected row count from update [" +
                         batchPosition + "]; actual row count: " + rowCount +
                         "; expected: " + expectedRowCount;
            throw new BatchedTooManyRowsAffectedException( msg, expectedRowCount, rowCount, batchPosition );
        }
    }
}
项目:uflo    文件:IDGenerator.java   
public synchronized long nextId() {
    if (lastId < nextId) {
        for (int attempts = maxAttempts; (attempts > 0); attempts--) {
            try {
                AcquireDbidCommand command = new AcquireDbidCommand(blockSize);
                nextId = commandService.executeCommandInNewTransaction(command);
                lastId = nextId + blockSize - 1;
                break;
            } catch (StaleStateException e) {
                attempts--;
                if (attempts == 0) {
                    throw new IllegalStateException("couldn't acquire block of ids, tried "+ maxAttempts + " times");
                }
                // if there are still attempts left, first wait a bit
                int millis = 20 + random.nextInt(200);
                log.debug("optimistic locking failure while trying to acquire id block.  retrying in "+ millis + " millis");
                try {
                    Thread.sleep(millis);
                } catch (InterruptedException e1) {
                    log.debug("waiting after id block locking failure got interrupted");
                }
            }
        }
    }
    return nextId++;
}
项目:cacheonix-core    文件:Expectations.java   
private void checkBatched(int rowCount, int batchPosition) {
    if ( rowCount == -2 ) {
        if ( log.isDebugEnabled() ) {
            log.debug( "success of batch update unknown: " + batchPosition );
        }
    }
    else if ( rowCount == -3 ) {
        throw new BatchFailedException( "Batch update failed: " + batchPosition );
    }
    else {
        if ( expectedRowCount > rowCount ) {
            throw new StaleStateException(
                    "Batch update returned unexpected row count from update [" + batchPosition +
                    "]; actual row count: " + rowCount +
                    "; expected: " + expectedRowCount
            );
        }
        if ( expectedRowCount < rowCount ) {
            String msg = "Batch update returned unexpected row count from update [" +
                         batchPosition + "]; actual row count: " + rowCount +
                         "; expected: " + expectedRowCount;
            throw new BatchedTooManyRowsAffectedException( msg, expectedRowCount, rowCount, batchPosition );
        }
    }
}
项目:welshare    文件:UserServiceImpl.java   
/**
 * http://jaspan.com/improved_persistent_login_cookie_best_practice
 */
@Override
@Transactional(isolation=Isolation.READ_UNCOMMITTED, rollbackFor=StaleStateException.class)
public Login rememberMeLogin(String token, String series, String ip) {
    Login existingLogin = getDao().getLoginFromAuthToken(token, series);
    if (existingLogin == null) {
        Login loginBySeries = getDao().getByPropertyValue(Login.class, "series", series);
        // if a login series exists, assume the previous token was stolen, so deleting all persistent logins
        // an exception is a request made within a few seconds from the last login time
        // which may mean request from the same browser that is not yet aware of the renewed cookie
        if (loginBySeries != null && new Period(loginBySeries.getLastLoginTime(), new DateTime()).getSeconds() < 5) {
            log.info("Assuming login cookies theft; deleting all sessions for user " + loginBySeries.getUser());
            getDao().deleteLogins(loginBySeries.getUser().getId());
        } else if (log.isDebugEnabled()) {
            log.debug("No existing login found for token=" + token + ", series=" + series);
        }
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("Existing login found for token=" + token + " and series=" + series);
    }

    Login newLogin = createLoginAndUpdateUserData(existingLogin.getUser(), existingLogin.getSeries(), true, ip);
    delete(existingLogin);
    return newLogin;
}
项目:computoser    文件:UserService.java   
/**
 * http://jaspan.com/improved_persistent_login_cookie_best_practice
 */
@Transactional(rollbackFor=StaleStateException.class)
public User rememberMeLogin(String token, String series) {
    User existingLogin = userDao.getLoginFromAuthToken(token, series);
    if (existingLogin == null) {
        User loginBySeries = userDao.getByPropertyValue(User.class, "loginSeries", series);
        // if a login series exists, assume the previous token was stolen, so deleting all persistent logins.
        // An exception is a request made within a few seconds from the last login time
        // which may mean request from the same browser that is not yet aware of the renewed cookie
        if (loginBySeries != null && new Period(loginBySeries.getLastLoginTime(), new DateTime()).getSeconds() < 5) {
            logger.info("Assuming login cookies theft; deleting all sessions for user " + loginBySeries);
            loginBySeries.setLoginSeries(null);
            loginBySeries.setLoginToken(null);
            userDao.persist(loginBySeries);
        } else if (logger.isDebugEnabled()) {
            logger.debug("No existing login found for token=" + token + ", series=" + series);
        }
        return null;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Existing login found for token=" + token + " and series=" + series);
    }
    fillUserWithNewTokens(existingLogin, series);
    return existingLogin;
}
项目:lams    文件:Expectations.java   
private void checkNonBatched(int rowCount) {
    if ( expectedRowCount > rowCount ) {
        throw new StaleStateException(
                "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount
        );
    }
    if ( expectedRowCount < rowCount ) {
        String msg = "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount;
        throw new TooManyRowsAffectedException( msg, expectedRowCount, rowCount );
    }
}
项目:helium    文件:JobExecutorThread.java   
private static boolean isLockingException(Throwable throwable) {
    for (Throwable t = throwable; t != null; t = t.getCause()) {
        if (t instanceof StaleStateException || t instanceof LockAcquisitionException) {
            return true;
        }
    }
    return false;
}
项目:cacheonix-core    文件:Expectations.java   
private void checkNonBatched(int rowCount) {
    if ( expectedRowCount > rowCount ) {
        throw new StaleStateException(
                "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount
        );
    }
    if ( expectedRowCount < rowCount ) {
        String msg = "Unexpected row count: " + rowCount + "; expected: " + expectedRowCount;
        throw new TooManyRowsAffectedException( msg, expectedRowCount, rowCount );
    }
}
项目:scientific-publishing    文件:UserService.java   
/**
 * http://jaspan.com/improved_persistent_login_cookie_best_practice
 */
@Transactional(rollbackFor = StaleStateException.class)
public User rememberMeLogin(String token, String series) {
    User existingLogin = dao.getLoginFromAuthToken(token, series);
    if (existingLogin == null) {
        User loginBySeries = dao.getByPropertyValue(User.class, "loginSeries", series);
        // if a login series exists, assume the previous token was stolen, so deleting all persistent logins.
        // An exception is a request made within a few seconds from the last login time
        // which may mean request from the same browser that is not yet aware of the renewed cookie
        // Note: fallback to joda-time, as java.time is insufficient 
        if (loginBySeries != null && new Period(new DateTime(loginBySeries.getLastLoginTime().toInstant(ZoneOffset.UTC).toEpochMilli()), 
                DateTime.now()).getSeconds() < 5) {
            logger.info("Assuming login cookies theft; deleting all sessions for user " + loginBySeries);
            loginBySeries.setLoginSeries(null);
            loginBySeries.setLoginToken(null);
            dao.persist(loginBySeries);
        } else if (logger.isDebugEnabled()) {
            logger.debug("No existing login found for token=" + token + ", series=" + series);
        }
        return null;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Existing login found for token=" + token + " and series=" + series);
    }
    fillUserWithNewTokens(existingLogin, series);
    return existingLogin;
}
项目:openMAXIMS    文件:AppointmentOutcomeDialogImpl.java   
public Boolean hasTCI(Booking_AppointmentRefVo appointment)
{
    if (appointment == null)
        return Boolean.FALSE;

    long count = 0;

    String query = "SELECT COUNT (tci.id) FROM TCIForPatientElectiveList AS tci LEFT JOIN tci.appointment AS appt WHERE appt.id = :APPT_ID and tci.isRIE is null";

    //WDEV-23321
    try
    {
        count = getDomainFactory().countWithHQL(query, new String[] {"APPT_ID"}, new Object[] {appointment.getID_Booking_Appointment()});
    }
    catch (RuntimeException e) {
        if (e instanceof LockAcquisitionException) 
        {
            try
            {
                count = getDomainFactory().countWithHQL(query, new String[] {"APPT_ID"}, new Object[] {appointment.getID_Booking_Appointment()});
            }
            catch (RuntimeException e1) 
            {
                if (e1 instanceof LockAcquisitionException) 
                {
                    throw new StaleStateException(ConfigFlag.UI.STALE_OBJECT_MESSAGE.getValue());
                }
            }
        }
    }
    //WDEV-23321 ends here
    if (count > 0)
        return Boolean.TRUE;

    return Boolean.FALSE;
}
项目:lams    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(StaleStateException ex) {
    super(ex.getMessage(), ex);
}
项目:lams    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(StaleStateException ex) {
    super(ex.getMessage(), ex);
}
项目:gitplex-mit    文件:WebModule.java   
@Override
protected void configure() {
    super.configure();

    bind(WicketServlet.class).to(DefaultWicketServlet.class);
    bind(WicketFilter.class).to(DefaultWicketFilter.class);
    bind(WebSocketPolicy.class).toInstance(WebSocketPolicy.newServerPolicy());
    bind(EditSupportRegistry.class).to(DefaultEditSupportRegistry.class);
    bind(WebSocketManager.class).to(DefaultWebSocketManager.class);

    contribute(CommitMessageTransformer.class, PatternCommitMessageTransformer.class);

    contributeFromPackage(EditSupport.class, EditSupport.class);

    bind(WebApplication.class).to(GitPlexWebApplication.class);
    bind(Application.class).to(GitPlexWebApplication.class);
    bind(AvatarManager.class).to(DefaultAvatarManager.class);
    bind(WebSocketManager.class).to(DefaultWebSocketManager.class);

    contributeFromPackage(EditSupport.class, EditSupportLocator.class);

    bind(CommitIndexedBroadcaster.class);

    contributeFromPackage(DiffRenderer.class, DiffRenderer.class);
    contributeFromPackage(BlobRendererContribution.class, BlobRendererContribution.class);

    contribute(Extension.class, new EmojiExtension());
    contribute(Extension.class, new SourcePositionTrackExtension());
    contribute(HtmlTransformer.class, new MentionTransformer());
    contribute(HtmlTransformer.class, new PullRequestTransformer());

    contribute(ResourcePackScopeContribution.class, new ResourcePackScopeContribution() {

        @Override
        public Collection<Class<?>> getResourcePackScopes() {
            return Lists.newArrayList(WebModule.class);
        }

    });
    contribute(ExpectedExceptionContribution.class, new ExpectedExceptionContribution() {

        @SuppressWarnings("unchecked")
        @Override
        public Collection<Class<? extends Exception>> getExpectedExceptionClasses() {
            return Sets.newHashSet(ConstraintViolationException.class, EntityNotFoundException.class, 
                    ObjectNotFoundException.class, StaleStateException.class, UnauthorizedException.class, 
                    GitException.class, PageExpiredException.class, StalePageException.class);
        }

    });

    bind(UrlManager.class).to(DefaultUrlManager.class);
    bind(CodeCommentChangeBroadcaster.class);
    bind(PullRequestChangeBroadcaster.class);
    bind(TaskChangeBroadcaster.class);
}
项目:spring4-understanding    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(StaleStateException ex) {
    super(ex.getMessage(), ex);
}
项目:spring4-understanding    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(StaleStateException ex) {
    super(ex.getMessage(), ex);
}
项目:spring4-understanding    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(StaleStateException ex) {
    super(ex.getMessage(), ex);
}
项目:openMAXIMS    文件:WardViewImpl.java   
public BedSpaceStateLiteVo getBedSpaceState(BedSpaceRefVo bed) 
{
    if(bed == null )
        throw new DomainRuntimeException("Invalid BedRefVo");

    String hql = "select bs,(select adm.healthyLodger from AdmissionDetail as adm where adm.pasEvent.id = bs.inpatientEpisode.pasEvent.id) from BedSpaceState as bs left join bs.bedSpace as bed where bed.id = " + bed.getID_BedSpace();

    List<?> bedState = null;

    //WDEV-23014 - Catch the Lock error and retry the entire transaction. After two retries, throw a SOE message. 

    try
    {
        bedState = getDomainFactory().find(hql);
    }
    catch (RuntimeException e) {
        if (e instanceof LockAcquisitionException) 
        {
            try
            {
                bedState = getDomainFactory().find(hql);
            }
            catch (RuntimeException e1) 
            {
                if (e1 instanceof LockAcquisitionException) 
                {
                    throw new StaleStateException(ConfigFlag.UI.STALE_OBJECT_MESSAGE.getValue());
                }
            }
        }
    }
    //WDEV-23014 ends here

    //WDEV-11039
    boolean hasAlerts = false;
    BedSpaceStateLiteVoCollection voColl  = new BedSpaceStateLiteVoCollection();
    if (bedState != null && bedState.size() > 0 && bedState.get(0) instanceof Object[])
    {
        Object[] recordDO = (Object[]) bedState.get(0);
        BedSpaceStateLiteVo bs = null;
        for (int i =0;i<recordDO.length;i++)
        {               
            if (recordDO[0] instanceof BedSpaceState)
            {   
                BedSpaceState doBed = (BedSpaceState)recordDO[0];
                if(doBed.getInpatientEpisode() != null && doBed.getInpatientEpisode().getPasEvent() != null && doBed.getInpatientEpisode().getPasEvent().getPatient() != null && doBed.getInpatientEpisode().getPasEvent().getPatient().getPatientAlerts() != null)
                    if(doBed.getInpatientEpisode().getPasEvent().getPatient().getPatientAlerts().size() > 0 && isOneActive(doBed.getInpatientEpisode().getPasEvent().getPatient().getPatientAlerts(), true))
                        hasAlerts = true;

                bs  = BedSpaceStateLiteVoAssembler.create((BedSpaceState)recordDO[0]);
            }   
            if (bs.getInpatientEpisodeIsNotNull() && recordDO[1] != null && recordDO[1] instanceof HealthyLodger)
                bs.getInpatientEpisode().setHealthyLodgerDetails(HealthyLodgerVoAssembler.create((HealthyLodger)recordDO[1]));
        }
        if (bs != null)
            voColl.add(bs);

    }
    //BedSpaceStateLiteVoCollection voColl = BedSpaceStateLiteVoAssembler.createBedSpaceStateLiteVoCollectionFromBedSpaceState(bedState);

    if (voColl != null && voColl.size() > 0)
    {
        if(voColl.get(0).getInpatientEpisodeIsNotNull() && voColl.get(0).getInpatientEpisode().getPasEventIsNotNull() && voColl.get(0).getInpatientEpisode().getPasEvent().getPatientIsNotNull())
            voColl.get(0).getInpatientEpisode().getPasEvent().getPatient().setHasAlerts(hasAlerts);

        return voColl.get(0);       
    }
    return null;
}
项目:class-guard    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(StaleStateException ex) {
    super(ex.getMessage(), ex);
}
项目:class-guard    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(StaleStateException ex) {
    super(ex.getMessage(), ex);
}