code: @SuppressWarnings("unchecked")
      public static Object convertToPlain(final Object result, final Class returnClass,
                                          final Class entityClass, final boolean projection) {
          final boolean isOptional = Optionals.isOptional(returnClass);
          Object converted = convertPlainImpl(result, isOptional ? entityClass : returnClass, projection);
          if (isOptional) {
              // jdk8 or guava optional
              converted = Optionals.create(converted, returnClass);
          }
          return converted;
      }
docs: Convert result to plain value. The simplest cases are update queries where orient already returns plain value.
  For other cases, when orient returns collection, took first element (an possibly apply projection).
  <p>
  Special case is {@code Optional} result wrapping when plain value (from the logic above) is wrapped into
  optional (guava or jdk).
  
  @param result      result object
  @param returnClass required return class
  @param entityClass entity class (in most cases would be the same as resultClass, except optional cases)
  @param projection  true to apply projection, false otherwise
  @return converted result