@@ -713,6 +713,90 @@ public void onFailure(final Call<ResponseBody> call, final Throwable t) {
713713 });
714714 }
715715
716+ /**
717+ * {@inheritDoc}
718+ */
719+ @ Override
720+ public void query (final Query query , final TimeUnit timeUnit , final int chunkSize , final BiConsumer <Cancellable , QueryResult > onNext ,
721+ final Runnable onComplete , final Consumer <Throwable > onFailure ) {
722+ Call <ResponseBody > call ;
723+ if (query .hasBoundParameters ()) {
724+ if (query .requiresPost ()) {
725+ call = this .influxDBService .postQuery (getDatabase (query ), query .getCommandWithUrlEncoded (), TimeUtil .toTimePrecision (timeUnit ), chunkSize ,
726+ query .getParameterJsonWithUrlEncoded ());
727+ } else {
728+ call = this .influxDBService .query (getDatabase (query ), query .getCommandWithUrlEncoded (), TimeUtil .toTimePrecision (timeUnit ), chunkSize ,
729+ query .getParameterJsonWithUrlEncoded ());
730+ }
731+ } else {
732+ if (query .requiresPost ()) {
733+ call = this .influxDBService .postQuery (getDatabase (query ), query .getCommandWithUrlEncoded (), TimeUtil .toTimePrecision (timeUnit ), chunkSize );
734+ } else {
735+ call = this .influxDBService .query (getDatabase (query ), query .getCommandWithUrlEncoded (), TimeUtil .toTimePrecision (timeUnit ), chunkSize );
736+ }
737+ }
738+
739+ call .enqueue (new Callback <ResponseBody >() {
740+ @ Override
741+ public void onResponse (final Call <ResponseBody > call , final Response <ResponseBody > response ) {
742+
743+ Cancellable cancellable = new Cancellable () {
744+ @ Override
745+ public void cancel () {
746+ call .cancel ();
747+ }
748+
749+ @ Override
750+ public boolean isCanceled () {
751+ return call .isCanceled ();
752+ }
753+ };
754+
755+ try {
756+ if (response .isSuccessful ()) {
757+ ResponseBody chunkedBody = response .body ();
758+ chunkProccesor .process (chunkedBody , cancellable , onNext , onComplete );
759+ } else {
760+ // REVIEW: must be handled consistently with IOException.
761+ ResponseBody errorBody = response .errorBody ();
762+ if (errorBody != null ) {
763+ InfluxDBException influxDBException = new InfluxDBException (errorBody .string ());
764+ if (onFailure == null ) {
765+ throw influxDBException ;
766+ } else {
767+ onFailure .accept (influxDBException );
768+ }
769+ }
770+ }
771+ } catch (IOException e ) {
772+ QueryResult queryResult = new QueryResult ();
773+ queryResult .setError (e .toString ());
774+ onNext .accept (cancellable , queryResult );
775+ //passing null onFailure consumer is here for backward compatibility
776+ //where the empty queryResult containing error is propagating into onNext consumer
777+ if (onFailure != null ) {
778+ onFailure .accept (e );
779+ }
780+ } catch (Exception e ) {
781+ call .cancel ();
782+ if (onFailure != null ) {
783+ onFailure .accept (e );
784+ }
785+ }
786+
787+ }
788+
789+ @ Override
790+ public void onFailure (final Call <ResponseBody > call , final Throwable t ) {
791+ if (onFailure == null ) {
792+ throw new InfluxDBException (t );
793+ } else {
794+ onFailure .accept (t );
795+ }
796+ }
797+ });
798+ }
799+
716800 /**
717801 * {@inheritDoc}
718802 */
0 commit comments