소스 검색

opt: 优化部分变量命名;优化打包脚本

sensordb2 2 달 전
부모
커밋
04d393d185

+ 1 - 0
packageApiDemoProject.sh

@@ -12,6 +12,7 @@ rm -rf $ROOT/release/$DST_DIR_NAME/*
 mkdir -p $ROOT/release/$DST_DIR_NAME/log
 mkdir -p $ROOT/release/$DST_DIR_NAME/lib
 
+cp -rf $ROOT/target/cluster-dbapi-java-pro-1.0-SNAPSHOT.jar $ROOT/lib/dbapi.jar
 cp -rf $ROOT/lib/*.jar $ROOT/release/$DST_DIR_NAME/lib/
 cp -rf $ROOT/pomDemoProject.xml $ROOT/release/$DST_DIR_NAME/pom.xml
 

+ 1 - 1
packageApiSourceProject.sh

@@ -4,7 +4,7 @@ cur_date="`date +%Y-%m-%d`"
 ROOT=$(cd `dirname $0`; pwd)
 echo $ROOT
 
-DST_DIR_NAME=resodbapi-java
+DST_DIR_NAME=dbapi-java
 
 mkdir -p $ROOT/release/$DST_DIR_NAME
 rm -rf $ROOT/release/$DST_DIR_NAME/*

+ 18 - 19
src/main/java/db/DBApiEntry.java

@@ -8,7 +8,7 @@ import com.clickhouse.client.api.enums.Protocol;
 import com.clickhouse.client.api.metadata.TableSchema;
 import com.clickhouse.client.api.query.QueryResponse;
 import com.clickhouse.client.api.query.QuerySettings;
-import db.dto.ClickHousePointVal;
+import db.dto.StckPointVal;
 import db.page.MultiPointRangePagingQuery;
 import db.page.RangePagingQuery;
 import org.apache.commons.lang3.StringUtils;
@@ -22,7 +22,6 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.*;
-import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
 // TODO: Add log support
@@ -73,7 +72,7 @@ public class DBApiEntry implements AutoCloseable {
 
         // Init ClickHouse client
         TableSchema schema = client.getTableSchema(makeTableName(), currentDatabase);
-        client.register(db.dto.ClickHousePointVal.class, schema);
+        client.register(StckPointVal.class, schema);
     }
 
     public DBApiEntry(String addressHost, int publicPort, String token) throws IOException {
@@ -447,7 +446,7 @@ public class DBApiEntry implements AutoCloseable {
         pointVals.getPoint().ensureValid();
 
         // Convert to ClickHousePointVal for insertion
-        List<ClickHousePointVal> pointValsList = new LinkedList<>();
+        List<StckPointVal> pointValsList = new LinkedList<>();
         String metricName = pointVals.getMetricName();
         String pointName = pointVals.getPointName();
         HashMap<String, String> tags = new HashMap<>();
@@ -458,13 +457,13 @@ public class DBApiEntry implements AutoCloseable {
             tags.put(key, pointVals.getTags().get(key));
         }
         for (int i = 0; i < pointVals.getCount(); i++) {
-            ClickHousePointVal clickHousePointVal = new ClickHousePointVal();
-            clickHousePointVal.setMetricName(metricName);
-            clickHousePointVal.setPointName(pointName);
-            clickHousePointVal.setTags(tags);
-            clickHousePointVal.setNanoseconds(pointVals.getUtcTime(i));
-            clickHousePointVal.setValue(pointVals.getValue(i));
-            pointValsList.add(clickHousePointVal);
+            StckPointVal stckPointVal = new StckPointVal();
+            stckPointVal.setMetricName(metricName);
+            stckPointVal.setPointName(pointName);
+            stckPointVal.setTags(tags);
+            stckPointVal.setNanoseconds(pointVals.getUtcTime(i));
+            stckPointVal.setValue(pointVals.getValue(i));
+            pointValsList.add(stckPointVal);
         }
         try {
             client.insert(makeTableName(), pointValsList).get();
@@ -479,11 +478,11 @@ public class DBApiEntry implements AutoCloseable {
             return;
         }
 
-        List<ClickHousePointVal> pointValsList = new LinkedList<>();
+        List<StckPointVal> pointValsList = new LinkedList<>();
         for (DBVal dbVal : dbVals) {
-            ClickHousePointVal clickHousePointVal = new ClickHousePointVal();
-            clickHousePointVal.setMetricName(dbVal.getMetricName());
-            clickHousePointVal.setPointName(dbVal.getPointName());
+            StckPointVal stckPointVal = new StckPointVal();
+            stckPointVal.setMetricName(dbVal.getMetricName());
+            stckPointVal.setPointName(dbVal.getPointName());
             HashMap<String, String> tags = new HashMap<>();
             for (String key : dbVal.getTags().keySet()) {
                 if (StringUtils.equals(key, "pointName")) {
@@ -491,10 +490,10 @@ public class DBApiEntry implements AutoCloseable {
                 }
                 tags.put(key, dbVal.getTags().get(key));
             }
-            clickHousePointVal.setTags(tags);
-            clickHousePointVal.setNanoseconds(dbVal.getUtcTimeMilliSeconds());
-            clickHousePointVal.setValue(dbVal.getValue());
-            pointValsList.add(clickHousePointVal);
+            stckPointVal.setTags(tags);
+            stckPointVal.setNanoseconds(dbVal.getUtcTimeMilliSeconds());
+            stckPointVal.setValue(dbVal.getValue());
+            pointValsList.add(stckPointVal);
         }
         try {
             client.insert(makeTableName(), pointValsList).get();

+ 3 - 3
src/main/java/db/dto/ClickHousePointVal.java

@@ -2,17 +2,17 @@ package db.dto;
 
 import java.util.Map;
 
-public class ClickHousePointVal {
+public class StckPointVal {
     private String metricName;
     private String pointName;
     private Map<String, String> tags;
     private double value;
     private long nanoseconds;
 
-    public ClickHousePointVal() {
+    public StckPointVal() {
     }
 
-    public ClickHousePointVal(String metricName, String pointName, Map<String, String> tags, double value, long nanoseconds) {
+    public StckPointVal(String metricName, String pointName, Map<String, String> tags, double value, long nanoseconds) {
         this.metricName = metricName;
         this.pointName = pointName;
         this.tags = tags;

+ 0 - 25
src/test/java/sql/TestCreateTable.java

@@ -1,25 +0,0 @@
-package sql;
-
-import config.Globals;
-import db.DBApiEntry;
-import java.text.ParseException;
-
-public class TestCreateTable {
-    public static void main(String[] args) throws ParseException {
-//        String host = "192.168.101.87";
-        String host = Globals.HOST;
-        int port = Globals.port;
-        DBApiEntry entry = DBApiEntry.initApiEntry(host, port);
-//        entry.setUseLB(false);
-//        entry.setUseLB(true);
-
-        String sql = "create table test8 (city string tag default \"unknow\",area string tag default \"unknow\",company string tag,voltage float value,electricity float value default 0.0)";
-//        String sql = "create table test (city string tag ,area string tag,company string tag,voltage float value,electricity float value)";
-//        String sql = "select *";
-        long testBegin = System.currentTimeMillis();
-        String result = entry.execSql(sql);
-        long testEnd = System.currentTimeMillis();
-        System.out.println(String.format("spend total:%d (ms)", testEnd-testBegin));
-        System.out.println(String.format("result:%s", result));
-    }
-}

+ 0 - 26
src/test/java/sql/TestDeleteTable.java

@@ -1,26 +0,0 @@
-package sql;
-
-import config.Globals;
-import db.DBApiEntry;
-
-import java.text.ParseException;
-
-public class TestDeleteTable {
-    public static void main(String[] args) throws ParseException {
-//        String host = "192.168.101.87";
-        String host = Globals.HOST;
-        int port = Globals.port;
-        DBApiEntry entry = DBApiEntry.initApiEntry(host, port);
-//        entry.setUseLB(false);
-//        entry.setUseLB(true);
-
-        String sql = "delete * from test6";
-//        String sql = "delete from test2 where city = 'unknow'";
-        long testBegin = System.currentTimeMillis();
-        String result = entry.execSql(sql);
-        long testEnd = System.currentTimeMillis();
-        System.out.println(String.format("spend total:%d (ms)", testEnd-testBegin));
-        System.out.println(String.format("result:%s", result));
-    }
-
-}

+ 0 - 25
src/test/java/sql/TestDescribeTable.java

@@ -1,25 +0,0 @@
-package sql;
-
-import config.Globals;
-import db.DBApiEntry;
-
-import java.text.ParseException;
-
-public class TestDescribeTable {
-    public static void main(String[] args) throws ParseException {
-//        String host = "192.168.101.87";
-        String host = Globals.HOST;
-        int port = Globals.port;
-        DBApiEntry entry = DBApiEntry.initApiEntry(host, port);
-//        entry.setUseLB(false);
-//        entry.setUseLB(true);
-
-        String sql = "describe table test5";
-        long testBegin = System.currentTimeMillis();
-        String result = entry.execSql(sql);
-        long testEnd = System.currentTimeMillis();
-        System.out.println(String.format("spend total:%d (ms)", testEnd-testBegin));
-        System.out.println(String.format("result:%s", result));
-    }
-
-}

+ 0 - 25
src/test/java/sql/TestDropTable.java

@@ -1,25 +0,0 @@
-package sql;
-
-import config.Globals;
-import db.DBApiEntry;
-
-import java.text.ParseException;
-
-public class TestDropTable {
-    public static void main(String[] args) throws ParseException {
-//        String host = "192.168.101.87";
-        String host = Globals.HOST;
-        int port = Globals.port;
-        DBApiEntry entry = DBApiEntry.initApiEntry(host, port);
-//        entry.setUseLB(false);
-//        entry.setUseLB(true);
-
-        String sql = "drop table test5";
-        long testBegin = System.currentTimeMillis();
-        String result = entry.execSql(sql);
-        long testEnd = System.currentTimeMillis();
-        System.out.println(String.format("spend total:%d (ms)", testEnd-testBegin));
-        System.out.println(String.format("result:%s", result));
-    }
-
-}

+ 0 - 30
src/test/java/sql/TestInjectSelectTable.java

@@ -1,30 +0,0 @@
-package sql;
-
-import config.Globals;
-import db.DBApiEntry;
-
-import java.text.ParseException;
-
-public class TestInjectSelectTable {
-    public static void main(String[] args) throws ParseException {
-//        String host = "192.168.101.87";
-        String host = Globals.HOST;
-        int port = Globals.port;
-        DBApiEntry entry = DBApiEntry.initApiEntry(host, port);
-//        entry.setUseLB(false);
-//        entry.setUseLB(true);
-
-//        String sql = "SELECT * FROM test6 where city like 'shenzheng'";
-        String sql = "SELECT * FROM test7 where 2=2 or 1=1 ";
-//        String sql = "select * from test7 where city in ('nanjing','shenzhen')";
-//        String sql = "select * from test7 where city in ('shenzhen')";
-//        String sql = "select * from test7 where city like '.*n.*'";
-//        String sql = "delete from test2 where city = 'unknow'";
-        long testBegin = System.currentTimeMillis();
-        String result = entry.execSql(sql);
-        long testEnd = System.currentTimeMillis();
-        System.out.println(String.format("spend total:%d (ms)", testEnd-testBegin));
-        System.out.println(String.format("result:%s", result));
-    }
-
-}

+ 0 - 26
src/test/java/sql/TestInsertTable.java

@@ -1,26 +0,0 @@
-package sql;
-
-import config.Globals;
-import db.DBApiEntry;
-
-import java.text.ParseException;
-
-public class TestInsertTable {
-    public static void main(String[] args) throws ParseException {
-//        String host = "192.168.101.87";
-        String host = Globals.HOST;
-        int port = Globals.port;
-        DBApiEntry entry = DBApiEntry.initApiEntry(host, port);
-//        entry.setUseLB(false);
-//        entry.setUseLB(true);
-
-        String sql = "insert into test8 (datetime, city, area, company, voltage, electricity) values ('2022-04-16T00:00:00+08:00', 't1', 'nanjing', 'nuaa', 21, 22)";
-//        String sql = "create table test (city string tag ,area string tag,company string tag,voltage float value,electricity float value)";
-//        String sql = "select *";
-        long testBegin = System.currentTimeMillis();
-        String result = entry.execInsert(sql);
-        long testEnd = System.currentTimeMillis();
-        System.out.println(String.format("spend total:%d (ms)", testEnd-testBegin));
-        System.out.println(String.format("result:%s", result));
-    }
-}

+ 0 - 30
src/test/java/sql/TestSelectTable.java

@@ -1,30 +0,0 @@
-package sql;
-
-import config.Globals;
-import db.DBApiEntry;
-
-import java.text.ParseException;
-
-public class TestSelectTable {
-    public static void main(String[] args) throws ParseException {
-//        String host = "192.168.101.87";
-        String host = Globals.HOST;
-        int port = Globals.port;
-        DBApiEntry entry = DBApiEntry.initApiEntry(host, port);
-//        entry.setUseLB(false);
-//        entry.setUseLB(true);
-
-//        String sql = "SELECT * FROM test6 where city like 'shenzheng'";
-        String sql = "SELECT * FROM test8 ";
-//        String sql = "select * from test7 where city in ('nanjing','shenzhen')";
-//        String sql = "select * from test7 where city in ('shenzhen')";
-//        String sql = "select * from test7 where city like '.*n.*'";
-//        String sql = "delete from test2 where city = 'unknow'";
-        long testBegin = System.currentTimeMillis();
-        String result = entry.execSql(sql);
-        long testEnd = System.currentTimeMillis();
-        System.out.println(String.format("spend total:%d (ms)", testEnd-testBegin));
-        System.out.println(String.format("result:%s", result));
-    }
-
-}