Ejemplo n.º 1
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);
 }