コード例 #1
0
  public FetchConfiguration setWriteLockLevel(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 {
      assertActiveTransaction();
      if (level == DEFAULT)
        _state.writeLockLevel = _state.ctx.getConfiguration().getWriteLockLevelConstant();
      else _state.writeLockLevel = level;
    } finally {
      unlock();
    }
    return this;
  }
コード例 #2
0
 public FetchConfiguration setLockScope(int scope) {
   if (scope != DEFAULT
       && scope != LockScopes.LOCKSCOPE_NORMAL
       && scope != LockScopes.LOCKSCOPE_EXTENDED)
     throw new IllegalArgumentException(
         _loc.get("bad-lock-scope", Integer.valueOf(scope)).getMessage());
   if (scope == DEFAULT) _state.lockScope = LOCKSCOPE_NORMAL;
   else _state.lockScope = scope;
   return this;
 }
コード例 #3
0
 public FetchConfiguration setQueryTimeout(int timeout) {
   if (timeout == DEFAULT && _state.ctx != null)
     _state.queryTimeout = _state.ctx.getConfiguration().getQueryTimeout();
   else if (timeout != DEFAULT) {
     if (timeout < -1) {
       throw new IllegalArgumentException(_loc.get("invalid-timeout", timeout).getMessage());
     } else {
       _state.queryTimeout = timeout;
     }
   }
   return this;
 }
コード例 #4
0
 public FetchConfiguration clearFetchGroups() {
   lock();
   try {
     if (_state.fetchGroups != null) {
       _state.fetchGroups.clear();
       _state.fetchGroupContainsAll = false;
       _state.fetchGroupContainsDefault = true;
     }
   } finally {
     unlock();
   }
   return this;
 }
コード例 #5
0
 public FetchConfiguration removeFetchGroup(String group) {
   lock();
   try {
     if (_state.fetchGroups != null) {
       _state.fetchGroups.remove(group);
       if (FetchGroup.NAME_ALL.equals(group)) _state.fetchGroupContainsAll = false;
       else if (FetchGroup.NAME_DEFAULT.equals(group)) _state.fetchGroupContainsDefault = false;
     }
   } finally {
     unlock();
   }
   return this;
 }
コード例 #6
0
  public FetchConfiguration setFlushBeforeQueries(int flush) {
    if (flush != DEFAULT
        && flush != QueryFlushModes.FLUSH_TRUE
        && flush != QueryFlushModes.FLUSH_FALSE
        && flush != QueryFlushModes.FLUSH_WITH_CONNECTION)
      throw new IllegalArgumentException(
          _loc.get("bad-flush-before-queries", Integer.valueOf(flush)).getMessage());

    if (flush == DEFAULT && _state.ctx != null)
      _state.flushQuery = _state.ctx.getConfiguration().getFlushBeforeQueriesConstant();
    else if (flush != DEFAULT) _state.flushQuery = flush;
    return this;
  }
コード例 #7
0
  public FetchConfiguration addFetchGroup(String name) {
    if (StringUtils.isEmpty(name)) throw new UserException(_loc.get("null-fg"));

    lock();
    try {
      if (_state.fetchGroups == null) _state.fetchGroups = new HashSet<String>();
      _state.fetchGroups.add(name);
      if (FetchGroup.NAME_ALL.equals(name)) _state.fetchGroupContainsAll = true;
      else if (FetchGroup.NAME_DEFAULT.equals(name)) _state.fetchGroupContainsDefault = true;
    } finally {
      unlock();
    }
    return this;
  }
コード例 #8
0
 public FetchConfiguration setMaxFetchDepth(int depth) {
   if (depth == DEFAULT && _state.ctx != null)
     depth = _state.ctx.getConfiguration().getMaxFetchDepth();
   if (depth != DEFAULT) {
     _state.maxFetchDepth = depth;
     if (_parent == null) _availableDepth = depth;
   }
   return this;
 }
コード例 #9
0
 private void addHint(String name, Object value) {
   lock();
   try {
     if (_state.hints == null) _state.hints = new HashMap<String, Object>();
     _state.hints.put(name, value);
   } finally {
     unlock();
   }
 }
コード例 #10
0
 @Override
 public void transitionConfigurationState(
     final AutoScalingGroupMetadata group,
     final ConfigurationState from,
     final ConfigurationState to,
     final Collection<String> instanceIds)
     throws AutoScalingMetadataException {
   final AutoScalingInstance example = exampleForGroup(group);
   example.setConfigurationState(from);
   updateInstances(example, from, from.transitionTo(to), instanceIds);
 }
コード例 #11
0
  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();
  }
コード例 #12
0
  public FetchConfiguration addFields(Collection<String> fields) {
    if (fields == null || fields.isEmpty()) return this;

    lock();
    try {
      if (_state.fields == null) _state.fields = new HashSet<String>();
      _state.fields.addAll(fields);
    } finally {
      unlock();
    }
    return this;
  }
コード例 #13
0
  public FetchConfiguration addField(String field) {
    if (StringUtils.isEmpty(field)) throw new UserException(_loc.get("null-field"));

    lock();
    try {
      if (_state.fields == null) _state.fields = new HashSet<String>();
      _state.fields.add(field);
    } finally {
      unlock();
    }
    return this;
  }
コード例 #14
0
 public FetchConfiguration setRootClasses(Collection<Class<?>> classes) {
   lock();
   try {
     if (_state.rootClasses != null) _state.rootClasses.clear();
     if (classes != null && !classes.isEmpty()) {
       if (_state.rootClasses == null) _state.rootClasses = new HashSet<Class<?>>(classes);
       else _state.rootClasses.addAll(classes);
     }
   } finally {
     unlock();
   }
   return this;
 }
コード例 #15
0
 /** Clone this instance. */
 public Object clone() {
   FetchConfigurationImpl clone = newInstance(null);
   clone._state.ctx = _state.ctx;
   clone._parent = _parent;
   clone._fromField = _fromField;
   clone._fromType = _fromType;
   clone._directRelationOwner = _directRelationOwner;
   clone._load = _load;
   clone._availableRecursion = _availableRecursion;
   clone._availableDepth = _availableDepth;
   clone.copy(this);
   return clone;
 }
コード例 #16
0
 /**
  * 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);
 }
コード例 #17
0
  public void setContext(StoreContext ctx) {
    // can't reset non-null context to another context
    if (ctx != null && _state.ctx != null && ctx != _state.ctx) throw new InternalException();
    _state.ctx = ctx;
    if (ctx == null) return;

    // initialize to conf info
    OpenJPAConfiguration conf = ctx.getConfiguration();
    setFetchBatchSize(conf.getFetchBatchSize());
    setFlushBeforeQueries(conf.getFlushBeforeQueriesConstant());
    setLockTimeout(conf.getLockTimeout());
    setQueryTimeout(conf.getQueryTimeout());
    clearFetchGroups();
    addFetchGroups(Arrays.asList(conf.getFetchGroupsList()));
    setMaxFetchDepth(conf.getMaxFetchDepth());
  }
コード例 #18
0
 public FetchConfiguration setRootInstances(Collection<?> instances) {
   lock();
   try {
     if (_state.rootInstances != null) _state.rootInstances.clear();
     if (instances != null && !instances.isEmpty()) {
       if (_state.rootInstances == null) {
         _state.rootInstances = new HashSet<Object>(instances);
       } else {
         _state.rootInstances.addAll(instances);
       }
     }
   } finally {
     unlock();
   }
   return this;
 }
コード例 #19
0
 public FetchConfiguration setFetchBatchSize(int fetchBatchSize) {
   if (fetchBatchSize == DEFAULT && _state.ctx != null)
     fetchBatchSize = _state.ctx.getConfiguration().getFetchBatchSize();
   if (fetchBatchSize != DEFAULT) _state.fetchBatchSize = fetchBatchSize;
   return this;
 }
コード例 #20
0
 public FetchConfiguration setQueryCacheEnabled(boolean cache) {
   _state.queryCache = cache;
   return this;
 }
コード例 #21
0
 public FetchConfiguration setExtendedPathLookup(boolean flag) {
   _state.extendedPathLookup = flag;
   return this;
 }
コード例 #22
0
 public void setCacheStoreMode(DataCacheStoreMode mode) {
   _state.cacheStoreMode = mode;
 }
コード例 #23
0
 public void setCacheRetrieveMode(DataCacheRetrieveMode mode) {
   _state.cacheRetrieveMode = mode;
 }