@@ -608,14 +608,13 @@ public void query(final Query query, final int chunkSize, final BiConsumer<Cance
608
608
@ Override
609
609
public void query (final Query query , final int chunkSize , final BiConsumer <Cancellable , QueryResult > onNext ,
610
610
final Runnable onComplete , final Consumer <Throwable > onFailure ) {
611
-
612
611
Call <ResponseBody > call ;
613
612
if (query instanceof BoundParameterQuery ) {
614
613
BoundParameterQuery boundParameterQuery = (BoundParameterQuery ) query ;
615
- call = this .influxDBService .query (query . getDatabase (), query .getCommandWithUrlEncoded (), chunkSize ,
614
+ call = this .influxDBService .query (getDatabase (query ), query .getCommandWithUrlEncoded (), chunkSize ,
616
615
boundParameterQuery .getParameterJsonWithUrlEncoded ());
617
616
} else {
618
- call = this .influxDBService .query (query . getDatabase (), query .getCommandWithUrlEncoded (), chunkSize );
617
+ call = this .influxDBService .query (getDatabase (query ), query .getCommandWithUrlEncoded (), chunkSize );
619
618
}
620
619
621
620
call .enqueue (new Callback <ResponseBody >() {
@@ -681,11 +680,11 @@ public QueryResult query(final Query query, final TimeUnit timeUnit) {
681
680
Call <QueryResult > call = null ;
682
681
if (query instanceof BoundParameterQuery ) {
683
682
BoundParameterQuery boundParameterQuery = (BoundParameterQuery ) query ;
684
- call = this .influxDBService .query (query . getDatabase (),
683
+ call = this .influxDBService .query (getDatabase (query ),
685
684
TimeUtil .toTimePrecision (timeUnit ), query .getCommandWithUrlEncoded (),
686
685
boundParameterQuery .getParameterJsonWithUrlEncoded ());
687
686
} else {
688
- call = this .influxDBService .query (query . getDatabase (),
687
+ call = this .influxDBService .query (getDatabase (query ),
689
688
TimeUtil .toTimePrecision (timeUnit ), query .getCommandWithUrlEncoded ());
690
689
}
691
690
return executeQuery (call );
@@ -746,19 +745,15 @@ public boolean databaseExists(final String name) {
746
745
*/
747
746
private Call <QueryResult > callQuery (final Query query ) {
748
747
Call <QueryResult > call ;
749
- String db = query .getDatabase ();
750
- if (db == null ) {
751
- db = this .database ;
752
- }
753
748
if (query instanceof BoundParameterQuery ) {
754
749
BoundParameterQuery boundParameterQuery = (BoundParameterQuery ) query ;
755
- call = this .influxDBService .postQuery (db , query .getCommandWithUrlEncoded (),
750
+ call = this .influxDBService .postQuery (getDatabase ( query ) , query .getCommandWithUrlEncoded (),
756
751
boundParameterQuery .getParameterJsonWithUrlEncoded ());
757
752
} else {
758
753
if (query .requiresPost ()) {
759
- call = this .influxDBService .postQuery (db , query .getCommandWithUrlEncoded ());
754
+ call = this .influxDBService .postQuery (getDatabase ( query ) , query .getCommandWithUrlEncoded ());
760
755
} else {
761
- call = this .influxDBService .query (db , query .getCommandWithUrlEncoded ());
756
+ call = this .influxDBService .query (getDatabase ( query ) , query .getCommandWithUrlEncoded ());
762
757
}
763
758
}
764
759
return call ;
@@ -926,6 +921,11 @@ public void dropRetentionPolicy(final String rpName, final String database) {
926
921
executeQuery (this .influxDBService .postQuery (Query .encode (queryBuilder .toString ())));
927
922
}
928
923
924
+ private String getDatabase (final Query query ) {
925
+ String db = query .getDatabase ();
926
+ return db == null ? this .database : db ;
927
+ }
928
+
929
929
private interface ChunkProccesor {
930
930
void process (ResponseBody chunkedBody , Cancellable cancellable ,
931
931
BiConsumer <Cancellable , QueryResult > consumer , Runnable onComplete ) throws IOException ;
0 commit comments