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;
  }
 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();
   }
 }
 public FetchConfiguration removeFields(Collection<String> fields) {
   lock();
   try {
     if (_state.fields != null) _state.fields.removeAll(fields);
   } finally {
     unlock();
   }
   return this;
 }
 public FetchConfiguration clearFields() {
   lock();
   try {
     if (_state.fields != null) _state.fields.clear();
   } finally {
     unlock();
   }
   return this;
 }
 public FetchConfiguration removeField(String field) {
   lock();
   try {
     if (_state.fields != null) _state.fields.remove(field);
   } finally {
     unlock();
   }
   return this;
 }
 public FetchConfiguration removeFetchGroups(Collection<String> groups) {
   lock();
   try {
     if (_state.fetchGroups != null && groups != null)
       for (String group : groups) removeFetchGroup(group);
   } finally {
     unlock();
   }
   return this;
 }
  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;
  }
  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;
  }
 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;
 }
 public FetchConfiguration clearFetchGroups() {
   lock();
   try {
     if (_state.fetchGroups != null) {
       _state.fetchGroups.clear();
       _state.fetchGroupContainsAll = false;
       _state.fetchGroupContainsDefault = true;
     }
   } finally {
     unlock();
   }
   return this;
 }
 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;
 }
  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;
  }
 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;
 }