Skip to content

Commit

Permalink
[IOTDB-549] Reorganize exception (#893)
Browse files Browse the repository at this point in the history
* fix exception organization
  • Loading branch information
Jialin Qiao committed Mar 9, 2020
1 parent 9b943d2 commit 0bc56c4
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
*/
package org.apache.iotdb.rocketmq;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

import org.apache.iotdb.session.IoTDBSessionException;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
Expand All @@ -46,7 +44,8 @@ public class RocketMQConsumer {
private static final Logger logger = LoggerFactory.getLogger(RocketMQConsumer.class);

public RocketMQConsumer(String producerGroup, String serverAddresses, String connectionHost,
int connectionPort, String user, String password) throws ClassNotFoundException, SQLException, IoTDBSessionException {
int connectionPort, String user, String password)
throws IoTDBConnectionException, StatementExecutionException {
this.producerGroup = producerGroup;
this.serverAddresses = serverAddresses;
this.consumer = new DefaultMQPushConsumer(producerGroup);
Expand All @@ -55,7 +54,7 @@ public RocketMQConsumer(String producerGroup, String serverAddresses, String con
}

private void initIoTDB(String host, int port, String user, String password)
throws SQLException, IoTDBSessionException {
throws IoTDBConnectionException, StatementExecutionException {
if (host == null) {
host = Constant.IOTDB_CONNECTION_HOST;
port = Constant.IOTDB_CONNECTION_PORT;
Expand All @@ -72,19 +71,20 @@ private void initIoTDB(String host, int port, String user, String password)
}
}

private void addStorageGroup(String storageGroup) throws IoTDBSessionException {
private void addStorageGroup(String storageGroup)
throws IoTDBConnectionException, StatementExecutionException {
session.setStorageGroup(storageGroup);
}

private void createTimeseries(String[] sql) throws IoTDBSessionException {
private void createTimeseries(String[] sql) throws StatementExecutionException, IoTDBConnectionException {
String timeseries = sql[0];
TSDataType dataType = TSDataType.valueOf(sql[1]);
TSEncoding encoding = TSEncoding.valueOf(sql[2]);
CompressionType compressionType = CompressionType.valueOf(sql[3]);
session.createTimeseries(timeseries, dataType, encoding, compressionType);
}

private void insert(String data) throws IoTDBSessionException {
private void insert(String data) throws IoTDBConnectionException {
String[] dataArray = data.split(",");
String device = dataArray[0];
long time = Long.parseLong(dataArray[1]);
Expand All @@ -101,7 +101,7 @@ public void start() throws MQClientException {
* Subscribe topic and add regiser Listener
* @throws MQClientException
*/
public void prepareConsume() throws MQClientException, IoTDBSessionException {
public void prepareConsume() throws MQClientException {
/**
* Subscribe one more more topics to consume.
*/
Expand All @@ -120,7 +120,7 @@ public void prepareConsume() throws MQClientException, IoTDBSessionException {
new String(msg.getBody())));
try {
insert(new String(msg.getBody()));
} catch (IoTDBSessionException e) {
} catch (IoTDBConnectionException e) {
logger.error(e.getMessage());
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public void setServerAddresses(String serverAddresses) {
}

public static void main(String[] args)
throws MQClientException, SQLException, ClassNotFoundException, IoTDBSessionException {
throws MQClientException, StatementExecutionException, IoTDBConnectionException {
/**
*Instantiate with specified consumer group name and specify name server addresses.
*/
Expand Down
26 changes: 12 additions & 14 deletions example/session/src/main/java/org/apache/iotdb/SessionExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package org.apache.iotdb;

import org.apache.iotdb.rpc.IoTDBRPCException;
import org.apache.iotdb.session.IoTDBSessionException;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.session.SessionDataSet;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
Expand All @@ -28,9 +28,6 @@
import org.apache.iotdb.tsfile.write.record.RowBatch;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.apache.iotdb.tsfile.write.schema.Schema;
import org.apache.thrift.TException;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -39,7 +36,7 @@ public class SessionExample {
private static Session session;

public static void main(String[] args)
throws IoTDBSessionException, TException, IoTDBRPCException, SQLException {
throws IoTDBConnectionException, StatementExecutionException {
session = new Session("127.0.0.1", 6667, "root", "root");
session.open();

Expand All @@ -64,7 +61,7 @@ public static void main(String[] args)
session.close();
}

private static void insert() throws IoTDBSessionException {
private static void insert() throws IoTDBConnectionException {
String deviceId = "root.sg1.d1";
List<String> measurements = new ArrayList<>();
measurements.add("s1");
Expand All @@ -79,7 +76,7 @@ private static void insert() throws IoTDBSessionException {
}
}

private static void insertInBatch() throws IoTDBSessionException {
private static void insertInBatch() throws IoTDBConnectionException {
String deviceId = "root.sg1.d1";
List<String> measurements = new ArrayList<>();
measurements.add("s1");
Expand Down Expand Up @@ -126,7 +123,7 @@ private static void insertInBatch() throws IoTDBSessionException {
* Users need to control the count of RowBatch and write a batch when it reaches the maxBatchSize
*
*/
private static void insertRowBatch() throws IoTDBSessionException {
private static void insertRowBatch() throws IoTDBConnectionException {
// The schema of sensors of one device
Schema schema = new Schema();
schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
Expand Down Expand Up @@ -157,22 +154,23 @@ private static void insertRowBatch() throws IoTDBSessionException {
}
}

private static void deleteData() throws IoTDBSessionException {
private static void deleteData() throws IoTDBConnectionException {
String path = "root.sg1.d1.s1";
long deleteTime = 99;
session.deleteData(path, deleteTime);
}

private static void deleteTimeseries() throws IoTDBSessionException {
private static void deleteTimeseries() throws IoTDBConnectionException {
List<String> paths = new ArrayList<>();
paths.add("root.sg1.d1.s1");
paths.add("root.sg1.d1.s2");
paths.add("root.sg1.d1.s3");
session.deleteTimeseries(paths);
}

private static void query() throws TException, IoTDBRPCException, SQLException {
SessionDataSet dataSet = session.executeQueryStatement("select * from root.sg1.d1");
private static void query() throws IoTDBConnectionException, StatementExecutionException {
SessionDataSet dataSet;
dataSet = session.executeQueryStatement("select * from root.sg1.d1");
dataSet.setBatchSize(1024); // default is 512
while (dataSet.hasNext()){
System.out.println(dataSet.next());
Expand All @@ -181,7 +179,7 @@ private static void query() throws TException, IoTDBRPCException, SQLException {
dataSet.closeOperationHandle();
}

private static void nonQuery() throws TException, IoTDBRPCException, SQLException {
private static void nonQuery() throws IoTDBConnectionException, StatementExecutionException {
session.executeNonQueryStatement("insert into root.sg1.d1(timestamp,s1) values(200, 1);");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.iotdb.jdbc;

import org.apache.iotdb.rpc.IoTDBRPCException;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.service.rpc.thrift.TSCloseOperationReq;
import org.apache.iotdb.service.rpc.thrift.TSIService;
import org.apache.iotdb.service.rpc.thrift.TSStatus;
Expand Down Expand Up @@ -144,8 +144,8 @@ public void close() throws SQLException {
closeReq.setQueryId(queryId);
TSStatus closeResp = client.closeOperation(closeReq);
RpcUtils.verifySuccess(closeResp);
} catch (IoTDBRPCException e) {
throw new SQLException("Error occurs for close opeation in server side becasuse ", e);
} catch (StatementExecutionException e) {
throw new SQLException("Error occurs for close operation in server side because ", e);
} catch (TException e) {
throw new SQLException("Error occurs when connecting to server for close operation ", e);
}
Expand Down
9 changes: 5 additions & 4 deletions jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
import org.apache.iotdb.rpc.IoTDBRPCException;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.service.rpc.thrift.*;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
Expand Down Expand Up @@ -448,7 +449,7 @@ private void openSession() throws SQLException {
}
throw new SQLException(String.format("Can not establish connection with %s : %s. ",
params.getJdbcUriString(), e.getMessage()), e);
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
// failed to connect, disconnect from the server
transport.close();
throw new IoTDBSQLException(e.getMessage(), openResp.getStatus());
Expand Down Expand Up @@ -493,7 +494,7 @@ public String getTimeZone() throws TException, IoTDBSQLException {
TSGetTimeZoneResp resp = getClient().getTimeZone(sessionId);
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return resp.getTimeZone();
Expand All @@ -504,7 +505,7 @@ public void setTimeZone(String zoneId) throws TException, IoTDBSQLException {
TSStatus resp = getClient().setTimeZone(req);
try {
RpcUtils.verifySuccess(resp);
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), resp);
}
this.zoneId = ZoneId.of(zoneId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.iotdb.jdbc;

import java.sql.*;
import org.apache.iotdb.rpc.IoTDBRPCException;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataReq;
import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataResp;
import org.apache.iotdb.service.rpc.thrift.TSIService;
Expand Down Expand Up @@ -1013,7 +1013,7 @@ private String getMetadataInJsonFunc() throws TException, IoTDBSQLException {
resp = client.fetchMetadata(req);
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return resp.getMetadataInJson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.iotdb.jdbc;

import org.apache.iotdb.rpc.IoTDBRPCException;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.service.rpc.thrift.TSFetchResultsReq;
import org.apache.iotdb.service.rpc.thrift.TSFetchResultsResp;
import org.apache.iotdb.service.rpc.thrift.TSIService;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected boolean fetchResults() throws SQLException {

try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
if (!resp.hasResultSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.iotdb.jdbc;

import org.apache.iotdb.rpc.IoTDBRPCException;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.service.rpc.thrift.TSFetchResultsReq;
import org.apache.iotdb.service.rpc.thrift.TSFetchResultsResp;
import org.apache.iotdb.service.rpc.thrift.TSIService;
Expand Down Expand Up @@ -83,7 +83,7 @@ protected boolean fetchResults() throws SQLException {

try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
if (!resp.hasResultSet) {
Expand Down
8 changes: 4 additions & 4 deletions jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.iotdb.jdbc;

import org.apache.iotdb.rpc.IoTDBRPCException;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.iotdb.service.rpc.thrift.*;
import org.apache.thrift.TException;
Expand Down Expand Up @@ -217,7 +217,7 @@ private boolean executeSQL(String sql) throws TException, SQLException {
TSExecuteStatementResp execResp = client.executeStatement(execReq);
try {
RpcUtils.verifySuccess(execResp.getStatus());
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), execResp.getStatus());
}
if (execResp.isSetColumns()) {
Expand Down Expand Up @@ -325,7 +325,7 @@ private ResultSet executeQuerySQL(String sql) throws TException, SQLException {
queryId = execResp.getQueryId();
try {
RpcUtils.verifySuccess(execResp.getStatus());
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), execResp.getStatus());
}
if (execResp.queryDataSet == null) {
Expand Down Expand Up @@ -387,7 +387,7 @@ private int executeUpdateSQL(String sql) throws TException, IoTDBSQLException {
}
try {
RpcUtils.verifySuccess(execResp.getStatus());
} catch (IoTDBRPCException e) {
} catch (StatementExecutionException e) {
throw new IoTDBSQLException(e.getMessage(), execResp.getStatus());
}
return 0;
Expand Down
Loading

0 comments on commit 0bc56c4

Please sign in to comment.