@@ -93,6 +93,7 @@ public class InfluxDBImpl implements InfluxDB {
93
93
private String database ;
94
94
private String retentionPolicy = "autogen" ;
95
95
private ConsistencyLevel consistency = ConsistencyLevel .ONE ;
96
+ private final boolean messagePack ;
96
97
private final ChunkProccesor chunkProccesor ;
97
98
98
99
/**
@@ -112,6 +113,7 @@ public class InfluxDBImpl implements InfluxDB {
112
113
*/
113
114
public InfluxDBImpl (final String url , final String username , final String password , final OkHttpClient .Builder client ,
114
115
final ResponseFormat responseFormat ) {
116
+ this .messagePack = ResponseFormat .MSGPACK .equals (responseFormat );
115
117
this .hostAddress = parseHostAddress (url );
116
118
this .username = username ;
117
119
this .password = password ;
@@ -148,15 +150,6 @@ public InfluxDBImpl(final String url, final String username, final String passwo
148
150
.build ();
149
151
this .influxDBService = this .retrofit .create (InfluxDBService .class );
150
152
151
- if (ResponseFormat .MSGPACK .equals (responseFormat )) {
152
- String [] versionNumbers = version ().split ("\\ ." );
153
- final int major = Integer .parseInt (versionNumbers [0 ]);
154
- final int minor = Integer .parseInt (versionNumbers [1 ]);
155
- final int fromMinor = 4 ;
156
- if ((major < 2 ) && ((major != 1 ) || (minor < fromMinor ))) {
157
- throw new InfluxDBException ("MessagePack format is only supported from InfluxDB version 1.4 and later" );
158
- }
159
- }
160
153
}
161
154
162
155
public InfluxDBImpl (final String url , final String username , final String password ,
@@ -168,6 +161,7 @@ public InfluxDBImpl(final String url, final String username, final String passwo
168
161
InfluxDBImpl (final String url , final String username , final String password , final OkHttpClient .Builder client ,
169
162
final InfluxDBService influxDBService , final JsonAdapter <QueryResult > adapter ) {
170
163
super ();
164
+ this .messagePack = false ;
171
165
this .hostAddress = parseHostAddress (url );
172
166
this .username = username ;
173
167
this .password = password ;
@@ -505,7 +499,7 @@ public void write(final int udpPort, final List<String> records) {
505
499
*/
506
500
@ Override
507
501
public QueryResult query (final Query query ) {
508
- return execute (callQuery (query ));
502
+ return executeQuery (callQuery (query ));
509
503
}
510
504
511
505
/**
@@ -591,7 +585,7 @@ public QueryResult query(final Query query, final TimeUnit timeUnit) {
591
585
call = this .influxDBService .query (this .username , this .password , query .getDatabase (),
592
586
TimeUtil .toTimePrecision (timeUnit ), query .getCommandWithUrlEncoded ());
593
587
}
594
- return execute (call );
588
+ return executeQuery (call );
595
589
}
596
590
597
591
/**
@@ -604,15 +598,15 @@ public void createDatabase(final String name) {
604
598
if (this .version ().startsWith ("0." )) {
605
599
createDatabaseQueryString = String .format ("CREATE DATABASE IF NOT EXISTS \" %s\" " , name );
606
600
}
607
- execute (this .influxDBService .postQuery (this .username , this .password , Query .encode (createDatabaseQueryString )));
601
+ executeQuery (this .influxDBService .postQuery (this .username , this .password , Query .encode (createDatabaseQueryString )));
608
602
}
609
603
610
604
/**
611
605
* {@inheritDoc}
612
606
*/
613
607
@ Override
614
608
public void deleteDatabase (final String name ) {
615
- execute (this .influxDBService .postQuery (this .username , this .password ,
609
+ executeQuery (this .influxDBService .postQuery (this .username , this .password ,
616
610
Query .encode ("DROP DATABASE \" " + name + "\" " )));
617
611
}
618
612
@@ -621,7 +615,7 @@ public void deleteDatabase(final String name) {
621
615
*/
622
616
@ Override
623
617
public List <String > describeDatabases () {
624
- QueryResult result = execute (this .influxDBService .query (this .username ,
618
+ QueryResult result = executeQuery (this .influxDBService .query (this .username ,
625
619
this .password , SHOW_DATABASE_COMMAND_ENCODED ));
626
620
// {"results":[{"series":[{"name":"databases","columns":["name"],"values":[["mydb"]]}]}]}
627
621
// Series [name=databases, columns=[name], values=[[mydb], [unittest_1433605300968]]]
@@ -675,6 +669,20 @@ static class ErrorMessage {
675
669
public String error ;
676
670
}
677
671
672
+ private QueryResult executeQuery (final Call <QueryResult > call ) {
673
+ if (messagePack ) {
674
+ String [] versionNumbers = version ().split ("\\ ." );
675
+ final int major = Integer .parseInt (versionNumbers [0 ]);
676
+ final int minor = Integer .parseInt (versionNumbers [1 ]);
677
+ final int fromMinor = 4 ;
678
+ if ((major < 2 ) && ((major != 1 ) || (minor < fromMinor ))) {
679
+ throw new UnsupportedOperationException (
680
+ "MessagePack format is only supported from InfluxDB version 1.4 and later" );
681
+ }
682
+ }
683
+ return execute (call );
684
+ }
685
+
678
686
private <T > T execute (final Call <T > call ) {
679
687
try {
680
688
Response <T > response = call .execute ();
@@ -762,7 +770,7 @@ public void createRetentionPolicy(final String rpName, final String database, fi
762
770
if (isDefault ) {
763
771
queryBuilder .append (" DEFAULT" );
764
772
}
765
- execute (this .influxDBService .postQuery (this .username , this .password , Query .encode (queryBuilder .toString ())));
773
+ executeQuery (this .influxDBService .postQuery (this .username , this .password , Query .encode (queryBuilder .toString ())));
766
774
}
767
775
768
776
/**
@@ -797,7 +805,7 @@ public void dropRetentionPolicy(final String rpName, final String database) {
797
805
.append ("\" ON \" " )
798
806
.append (database )
799
807
.append ("\" " );
800
- execute (this .influxDBService .postQuery (this .username , this .password ,
808
+ executeQuery (this .influxDBService .postQuery (this .username , this .password ,
801
809
Query .encode (queryBuilder .toString ())));
802
810
}
803
811
0 commit comments