2020package org .apache .iotdb .jdbc ;
2121
2222import org .apache .iotdb .jdbc .i18n .JdbcMessages ;
23+ import org .apache .iotdb .rpc .RpcUtils ;
2324
2425import org .apache .thrift .transport .TTransportException ;
26+ import org .apache .tsfile .common .conf .TSFileConfig ;
2527import org .osgi .service .component .annotations .Component ;
2628
2729import java .sql .Connection ;
3032import java .sql .DriverPropertyInfo ;
3133import java .sql .SQLException ;
3234import java .sql .SQLFeatureNotSupportedException ;
35+ import java .time .ZoneId ;
36+ import java .util .Arrays ;
3337import java .util .Properties ;
3438import java .util .logging .Logger ;
3539import java .util .regex .Pattern ;
@@ -42,6 +46,11 @@ public class IoTDBDriver implements Driver {
4246 /** Is this driver JDBC compliant. */
4347 private static final boolean TSFILE_JDBC_COMPLIANT = false ;
4448
49+ private static final String [] BOOLEAN_CHOICES = {"true" , "false" };
50+ private static final String [] SQL_DIALECT_CHOICES = {Constant .TREE , Constant .TABLE };
51+ private static final String [] VERSION_CHOICES =
52+ Arrays .stream (Constant .Version .values ()).map (Enum ::name ).toArray (String []::new );
53+
4554 static {
4655 try {
4756 DriverManager .registerDriver (new IoTDBDriver ());
@@ -58,7 +67,7 @@ public IoTDBDriver() {
5867
5968 @ Override
6069 public boolean acceptsURL (String url ) {
61- return Pattern .matches (TSFILE_URL_PREFIX , url );
70+ return url != null && Pattern .matches (TSFILE_URL_PREFIX , url );
6271 }
6372
6473 @ Override
@@ -75,14 +84,12 @@ public Connection connect(String url, Properties info) throws SQLException {
7584
7685 @ Override
7786 public int getMajorVersion () {
78- // TODO Auto-generated method stub
79- return 0 ;
87+ return Config .DRIVER_MAJOR_VERSION ;
8088 }
8189
8290 @ Override
8391 public int getMinorVersion () {
84- // TODO Auto-generated method stub
85- return 0 ;
92+ return Config .DRIVER_MINOR_VERSION ;
8693 }
8794
8895 @ Override
@@ -92,12 +99,74 @@ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
9299
93100 @ Override
94101 public DriverPropertyInfo [] getPropertyInfo (String url , Properties info ) {
95- // TODO Auto-generated method stub
96- return new DriverPropertyInfo [0 ];
102+ Properties properties = info == null ? new Properties () : info ;
103+ return new DriverPropertyInfo [] {
104+ createProperty (
105+ Config .AUTH_USER , Config .DEFAULT_USER , "User name for authentication." , properties ),
106+ createProperty (
107+ Config .AUTH_PASSWORD ,
108+ Config .DEFAULT_PASSWORD ,
109+ "Password for authentication." ,
110+ properties ),
111+ createProperty (
112+ Config .DEFAULT_BUFFER_CAPACITY ,
113+ String .valueOf (RpcUtils .THRIFT_DEFAULT_BUF_CAPACITY ),
114+ "Thrift default buffer capacity in bytes." ,
115+ properties ),
116+ createProperty (
117+ Config .THRIFT_FRAME_MAX_SIZE ,
118+ String .valueOf (RpcUtils .THRIFT_FRAME_MAX_SIZE ),
119+ "Thrift max frame size in bytes." ,
120+ properties ),
121+ createProperty (
122+ Config .VERSION ,
123+ Config .DEFAULT_VERSION .name (),
124+ VERSION_CHOICES ,
125+ "Client compatibility version." ,
126+ properties ),
127+ createProperty (
128+ Config .NETWORK_TIMEOUT ,
129+ String .valueOf (Config .DEFAULT_CONNECTION_TIMEOUT_MS ),
130+ "Network timeout in milliseconds." ,
131+ properties ),
132+ createProperty (
133+ Config .TIME_ZONE , ZoneId .systemDefault ().toString (), "Connection time zone." , properties ),
134+ createProperty (
135+ Config .CHARSET , TSFileConfig .STRING_CHARSET .name (), "Connection charset." , properties ),
136+ createProperty (
137+ Config .USE_SSL , "false" , BOOLEAN_CHOICES , "Whether to enable SSL." , properties ),
138+ createProperty (Config .TRUST_STORE , null , "SSL trust store path." , properties ),
139+ createProperty (Config .TRUST_STORE_PWD , null , "SSL trust store password." , properties ),
140+ createProperty (
141+ Config .SQL_DIALECT ,
142+ Constant .TREE ,
143+ SQL_DIALECT_CHOICES ,
144+ "SQL dialect for the connection." ,
145+ properties )
146+ };
97147 }
98148
99149 @ Override
100150 public boolean jdbcCompliant () {
101151 return TSFILE_JDBC_COMPLIANT ;
102152 }
153+
154+ private static DriverPropertyInfo createProperty (
155+ String name , String defaultValue , String description , Properties properties ) {
156+ return createProperty (name , defaultValue , null , description , properties );
157+ }
158+
159+ private static DriverPropertyInfo createProperty (
160+ String name ,
161+ String defaultValue ,
162+ String [] choices ,
163+ String description ,
164+ Properties properties ) {
165+ DriverPropertyInfo propertyInfo =
166+ new DriverPropertyInfo (name , properties .getProperty (name , defaultValue ));
167+ propertyInfo .required = false ;
168+ propertyInfo .choices = choices ;
169+ propertyInfo .description = description ;
170+ return propertyInfo ;
171+ }
103172}
0 commit comments