Skip to content

Commit 79a0368

Browse files
committed
Fixed database selection when database information not present in query.
1 parent a56b279 commit 79a0368

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/main/java/org/influxdb/impl/InfluxDBImpl.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,13 @@ public void query(final Query query, final int chunkSize, final BiConsumer<Cance
608608
@Override
609609
public void query(final Query query, final int chunkSize, final BiConsumer<Cancellable, QueryResult> onNext,
610610
final Runnable onComplete, final Consumer<Throwable> onFailure) {
611-
612611
Call<ResponseBody> call;
613612
if (query instanceof BoundParameterQuery) {
614613
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
615-
call = this.influxDBService.query(query.getDatabase(), query.getCommandWithUrlEncoded(), chunkSize,
614+
call = this.influxDBService.query(getDatabase(query), query.getCommandWithUrlEncoded(), chunkSize,
616615
boundParameterQuery.getParameterJsonWithUrlEncoded());
617616
} else {
618-
call = this.influxDBService.query(query.getDatabase(), query.getCommandWithUrlEncoded(), chunkSize);
617+
call = this.influxDBService.query(getDatabase(query), query.getCommandWithUrlEncoded(), chunkSize);
619618
}
620619

621620
call.enqueue(new Callback<ResponseBody>() {
@@ -681,11 +680,11 @@ public QueryResult query(final Query query, final TimeUnit timeUnit) {
681680
Call<QueryResult> call = null;
682681
if (query instanceof BoundParameterQuery) {
683682
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
684-
call = this.influxDBService.query(query.getDatabase(),
683+
call = this.influxDBService.query(getDatabase(query),
685684
TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded(),
686685
boundParameterQuery.getParameterJsonWithUrlEncoded());
687686
} else {
688-
call = this.influxDBService.query(query.getDatabase(),
687+
call = this.influxDBService.query(getDatabase(query),
689688
TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded());
690689
}
691690
return executeQuery(call);
@@ -746,19 +745,15 @@ public boolean databaseExists(final String name) {
746745
*/
747746
private Call<QueryResult> callQuery(final Query query) {
748747
Call<QueryResult> call;
749-
String db = query.getDatabase();
750-
if (db == null) {
751-
db = this.database;
752-
}
753748
if (query instanceof BoundParameterQuery) {
754749
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
755-
call = this.influxDBService.postQuery(db, query.getCommandWithUrlEncoded(),
750+
call = this.influxDBService.postQuery(getDatabase(query), query.getCommandWithUrlEncoded(),
756751
boundParameterQuery.getParameterJsonWithUrlEncoded());
757752
} else {
758753
if (query.requiresPost()) {
759-
call = this.influxDBService.postQuery(db, query.getCommandWithUrlEncoded());
754+
call = this.influxDBService.postQuery(getDatabase(query), query.getCommandWithUrlEncoded());
760755
} else {
761-
call = this.influxDBService.query(db, query.getCommandWithUrlEncoded());
756+
call = this.influxDBService.query(getDatabase(query), query.getCommandWithUrlEncoded());
762757
}
763758
}
764759
return call;
@@ -926,6 +921,11 @@ public void dropRetentionPolicy(final String rpName, final String database) {
926921
executeQuery(this.influxDBService.postQuery(Query.encode(queryBuilder.toString())));
927922
}
928923

924+
private String getDatabase(final Query query) {
925+
String db = query.getDatabase();
926+
return db == null ? this.database : db;
927+
}
928+
929929
private interface ChunkProccesor {
930930
void process(ResponseBody chunkedBody, Cancellable cancellable,
931931
BiConsumer<Cancellable, QueryResult> consumer, Runnable onComplete) throws IOException;

0 commit comments

Comments
 (0)