@Override public Object execute(OSQLAsynchQuery<ODocument> request, OCommandContext context, OProgressListener progressListener) {
    try {
      ODatabaseDocumentInternal db = getDatabase();

      final OStorage storage = db.getStorage();
      if (on) {
        // activate the profiler
        ((OAbstractPaginatedStorage) storage).startGatheringPerformanceStatisticForCurrentThread();
        ODocument result = new ODocument();
        result.field("result", "OK");
        request.getResultListener().result(result);
      } else {
        // stop the profiler and return the stats
        final OSessionStoragePerformanceStatistic performanceStatistic = ((OAbstractPaginatedStorage) storage)
            .completeGatheringPerformanceStatisticForCurrentThread();

        if (performanceStatistic != null)
          request.getResultListener().result(performanceStatistic.toDocument());
        else {
          ODocument result = new ODocument();
          result.field("result", "Error: profiling of storage was not started.");
          request.getResultListener().result(result);
        }

      }
      return getResult(request);
    } finally {
      if (request.getResultListener() != null) {
        request.getResultListener().end();
      }
    }
  }
@Override public Object execute(OSQLAsynchQuery<ODocument> request, OCommandContext context, OProgressListener progressListener) {
    try {
      ODatabaseDocumentInternal db = getDatabase();

      final OStorage storage = db.getStorage();
      if (on) {
        
        ((OAbstractPaginatedStorage) storage).startGatheringPerformanceStatisticForCurrentThread();
        ODocument result = new ODocument();
        result.field("result", "OK");
        request.getResultListener().result(result);
      } else {
        
        final OSessionStoragePerformanceStatistic performanceStatistic = ((OAbstractPaginatedStorage) storage)
            .completeGatheringPerformanceStatisticForCurrentThread();

        if (performanceStatistic != null)
          request.getResultListener().result(performanceStatistic.toDocument());
        else {
          ODocument result = new ODocument();
          result.field("result", "Error: profiling of storage was not started.");
          request.getResultListener().result(result);
        }

      }
      return getResult(request);
    } finally {
      if (request.getResultListener() != null) {
        request.getResultListener().end();
      }
    }
  }
@ Override public Object execute ( OSQLAsynchQuery < ODocument > request , OCommandContext context , OProgressListener progressListener ) { try { ODatabaseDocumentInternal db = getDatabase ( ) ; final OStorage storage = db . getStorage ( ) ; if ( on ) { // activate the profiler ( ( OAbstractPaginatedStorage ) storage ) . startGatheringPerformanceStatisticForCurrentThread ( ) ; ODocument result = new ODocument ( ) ; result . field ( "result" , "OK" ) ; request . getResultListener ( ) . result ( result ) ; } else { // stop the profiler and return the stats final OSessionStoragePerformanceStatistic performanceStatistic = ( ( OAbstractPaginatedStorage ) storage ) . completeGatheringPerformanceStatisticForCurrentThread ( ) ; if ( performanceStatistic != null ) request . getResultListener ( ) . result ( performanceStatistic . toDocument ( ) ) ; else { ODocument result = new ODocument ( ) ; result . field ( "result" , "Error: profiling of storage was not started." ) ; request . getResultListener ( ) . result ( result ) ; } } return getResult ( request ) ; } finally { if ( request . getResultListener ( ) != null ) { request . getResultListener ( ) . end ( ) ; } } }
old execution logic
old execution logic