private void setLockOptions(Map<String, Object> props, LockOptions options) { Object lockScope = props.get(AvailableSettings.LOCK_SCOPE); if (lockScope instanceof String && PessimisticLockScope.valueOf((String) lockScope) == PessimisticLockScope.EXTENDED) { options.setScope(true); } else if (lockScope instanceof PessimisticLockScope) { boolean extended = PessimisticLockScope.EXTENDED.equals((PessimisticLockScope) lockScope); options.setScope(extended); } else if (lockScope != null) { throw new PersistenceException( "Unable to parse " + AvailableSettings.LOCK_SCOPE + ": " + lockScope); } Object lockTimeout = props.get(AvailableSettings.LOCK_TIMEOUT); int timeout = 0; boolean timeoutSet = false; if (lockTimeout instanceof String) { timeout = Integer.parseInt((String) lockTimeout); timeoutSet = true; } else if (lockTimeout instanceof Number) { timeout = ((Number) lockTimeout).intValue(); timeoutSet = true; } else if (lockTimeout != null) { throw new PersistenceException( "Unable to parse " + AvailableSettings.LOCK_TIMEOUT + ": " + lockTimeout); } if (timeoutSet) { if (timeout < 0) { options.setTimeOut(LockOptions.WAIT_FOREVER); } else if (timeout == 0) { options.setTimeOut(LockOptions.NO_WAIT); } else { options.setTimeOut(timeout); } } }
/* 77: */ /* 78: */ protected String generateLockString(int lockTimeout) /* 79: */ { /* 80:122 */ SessionFactoryImplementor factory = getLockable().getFactory(); /* 81:123 */ LockOptions lockOptions = new LockOptions(getLockMode()); /* 82:124 */ lockOptions.setTimeOut(lockTimeout); /* 83:125 */ SimpleSelect select = new SimpleSelect(factory.getDialect()) .setLockOptions(lockOptions) .setTableName(getLockable().getRootTableName()) .addColumn(getLockable().getRootTableIdentifierColumnNames()[0]) .addCondition(getLockable().getRootTableIdentifierColumnNames(), "=?"); /* 84:130 */ if (getLockable().isVersioned()) { /* 85:131 */ select.addCondition(getLockable().getVersionColumnName(), "=?"); /* 86: */ } /* 87:133 */ if (factory.getSettings().isCommentsEnabled()) { /* 88:134 */ select.setComment(getLockMode() + " lock " + getLockable().getEntityName()); /* 89: */ } /* 90:136 */ return select.toStatementString(); /* 91: */ }
protected String generateLockString(int lockTimeout) { SessionFactoryImplementor factory = getLockable().getFactory(); LockOptions lockOptions = new LockOptions(getLockMode()); lockOptions.setTimeOut(lockTimeout); SimpleSelect select = new SimpleSelect(factory.getDialect()) .setLockOptions(lockOptions) .setTableName(getLockable().getRootTableName()) .addColumn(getLockable().getRootTableIdentifierColumnNames()[0]) .addCondition(getLockable().getRootTableIdentifierColumnNames(), "=?"); if (getLockable().isVersioned()) { select.addCondition(getLockable().getVersionColumnName(), "=?"); } if (factory.getSettings().isCommentsEnabled()) { select.setComment(getLockMode() + " lock " + getLockable().getEntityName()); } return select.toStatementString(); }
@Override protected String applyLocks( String sql, QueryParameters parameters, Dialect dialect, List<AfterLoadAction> afterLoadActions) throws QueryException { // can't cache this stuff either (per-invocation) final LockOptions lockOptions = parameters.getLockOptions(); final String result; if (lockOptions == null || (lockOptions.getLockMode() == LockMode.NONE && lockOptions.getAliasLockCount() == 0)) { return sql; } else { LockOptions locks = new LockOptions(); locks.setLockMode(lockOptions.getLockMode()); locks.setTimeOut(lockOptions.getTimeOut()); locks.setScope(lockOptions.getScope()); Iterator iter = lockOptions.getAliasLockIterator(); while (iter.hasNext()) { Map.Entry me = (Map.Entry) iter.next(); locks.setAliasSpecificLockMode( getAliasName((String) me.getKey()), (LockMode) me.getValue()); } Map keyColumnNames = null; if (dialect.forUpdateOfColumns()) { keyColumnNames = new HashMap(); for (int i = 0; i < names.length; i++) { keyColumnNames.put(names[i], persisters[i].getIdentifierColumnNames()); } } result = dialect.applyLocksToSql(sql, locks, keyColumnNames); } logQuery(queryString, result); return result; }