public FetchConfiguration setReadLockLevel(int level) { if (_state.ctx == null) return this; if (level != DEFAULT && level != MixedLockLevels.LOCK_NONE && level != MixedLockLevels.LOCK_READ && level != MixedLockLevels.LOCK_OPTIMISTIC && level != MixedLockLevels.LOCK_WRITE && level != MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT && level != MixedLockLevels.LOCK_PESSIMISTIC_READ && level != MixedLockLevels.LOCK_PESSIMISTIC_WRITE && level != MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT) throw new IllegalArgumentException( _loc.get("bad-lock-level", Integer.valueOf(level)).getMessage()); lock(); try { if (level != MixedLockLevels.LOCK_NONE) assertActiveTransaction(); if (level == DEFAULT) _state.readLockLevel = _state.ctx.getConfiguration().getReadLockLevelConstant(); else _state.readLockLevel = level; } finally { unlock(); } return this; }
public void copy(FetchConfiguration fetch) { setFetchBatchSize(fetch.getFetchBatchSize()); setMaxFetchDepth(fetch.getMaxFetchDepth()); setQueryCacheEnabled(fetch.getQueryCacheEnabled()); setFlushBeforeQueries(fetch.getFlushBeforeQueries()); setExtendedPathLookup(fetch.getExtendedPathLookup()); setLockTimeout(fetch.getLockTimeout()); setQueryTimeout(fetch.getQueryTimeout()); setLockScope(fetch.getLockScope()); clearFetchGroups(); addFetchGroups(fetch.getFetchGroups()); clearFields(); copyHints(fetch); setCacheRetrieveMode(fetch.getCacheRetrieveMode()); setCacheStoreMode(fetch.getCacheStoreMode()); addFields(fetch.getFields()); // don't use setters because require active transaction _state.readLockLevel = fetch.getReadLockLevel(); _state.writeLockLevel = fetch.getWriteLockLevel(); }
/** * Sets the hint to the given value. If the key corresponds to a known key, then that value is set * via the setter method. Otherwise it is put into opaque hints map. <br> * In either case, the original value is put in the hints map. So essential difference between * setting a value directly by a setter and via a hint is the memory of this original value. <br> * The other important difference is setting lock levels. Setting of lock level via setter method * needs active transaction. But setting via hint does not. * * @param key a hint key. If it is one of the statically registered hint key then the setter is * called. * @param value to be set. The given value type must match the argument type of the setter, if one * exists. * @param original value as specified by the caller. This value is put in the hints map. * @exception IllegalArgumentException if the given value is not acceptable by the setter method, * if one exists corresponds the given hint key. */ public void setHint(String key, Object value, Object original) { if (key == null) return; if (_hintSetters.containsKey(key)) { Method setter = _hintSetters.get(key); String methodName = setter.getName(); try { if ("setReadLockLevel".equals(methodName) && !isActiveTransaction()) { _state.readLockLevel = (Integer) value; } else if ("setWriteLockLevel".equals(methodName) && !isActiveTransaction()) { _state.writeLockLevel = (Integer) value; } else { setter.invoke(this, Filters.convertToMatchMethodArgument(value, setter)); } } catch (Exception e) { String message = _loc.get("bad-hint-value", key, toString(value), toString(original)).getMessage(); if (e instanceof IllegalArgumentException) { throw new IllegalArgumentException(message); } throw new IllegalArgumentException(message, e); } } addHint(key, original); }