package com.db.influxdb.Testing;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;

import com.db.influxdb.Configuration;
import com.db.influxdb.DataReader;
import com.db.influxdb.DataWriter;
import com.db.influxdb.Query;
import com.db.influxdb.ResultSet;

public class Test {
	public static void main(String[] args) throws Exception {
		writeData();
		readData();
	}

	public static void writeData() throws Exception {
		Configuration configuration = new Configuration("localhost", "8086", "root", "root", "mydb");
		DataWriter writer = new DataWriter(configuration);
		writer.setTableName("sampleTable1");
		writer.setTimeUnit(TimeUnit.SECONDS);
		
		writer.addField("column1", 12212);
		writer.addField("column2", 22.44);
		writer.addField("column3", "thisIsString");
		writer.addField("column4", false);
		writer.addTag("hostname", "server001");
		
		// If we'll set time it will set automatically
		writer.setTime(System.currentTimeMillis() / 1000);
		writer.writeData();

		writer.addField("column1", 112);
		writer.addField("column2", 21.44);
		writer.addField("column3", "thisIsString1");
		writer.addField("column4", true);
		writer.addTag("disk_type", "HDD");
		
		// Influxdb saves one point at one time. Therefore we have to add another point at another time.
		writer.setTime(System.currentTimeMillis() / 1000 + 1);
		writer.writeData();

	}

	public static void readData() throws IOException, URISyntaxException {
		Configuration configuration = new Configuration("localhost", "8086", "root", "root", "mydb");

		Query query = new Query();
		query.setTableName("sampleTable1");
		// selects all columns by default, if not specified as below.
		query.addColumn("column1");
		query.addColumn("column2");
		query.addColumn("column3");
		// fetches reaults of last 1 hour. (supported format are d, h, m, s)
		// query.setDuration("1h");

		// uncomment below line to apply aggregate functions and grouping
		// query.setAggregateFunction(AggregateFunction.MEAN);
		// query.setGroupByTime("1m");
		query.setLimit(1000);
		query.fillNullValues("0");

		DataReader dataReader = new DataReader(query, configuration);

		ResultSet resultSet = dataReader.getResult();
		System.out.println(resultSet);
		
		Query query1 = new Query();
		query1.setCustomQuery("select * from sampleTable1");
		dataReader.setQuery(query1);
		resultSet = dataReader.getResult();
		System.out.println(resultSet);
	}
}

@@ -694,18 +694,16 @@
 CONDS);%0A
-%09%09
 %0A%09%09write
@@ -890,26 +890,24 @@
 erver001%22);%0A
-%09%09
 %0A%09%09// If we'
@@ -1179,48 +1179,8 @@
 e);%0A
-%09%09writer.addTag(%22disk_type%22, %22HDD%22);%0A%09%09%0A
 %09%09//
@@ -1223,26 +1223,8 @@
 e. T
-herefore we have t
 o ad
@@ -1246,21 +1246,122 @@
  at 
-another time.
+same%0A%09%09// time we can use tags otherwise it will override the previous point.%0A%09%09writer.addTag(%22disk_type%22, %22HDD%22);
 %0A%09%09w
@@ -1411,14 +1411,13 @@
 1000
- + 1);
+);%0A%09%09
 %0A%09%09w
@@ -2290,18 +2290,16 @@
 ltSet);%0A
-%09%09
 %0A%09%09Query

Update Test class