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 ;
@@ -40,7 +44,12 @@ public class IoTDBDriver implements Driver {
4044 org .slf4j .LoggerFactory .getLogger (IoTDBDriver .class );
4145
4246 /** Is this driver JDBC compliant. */
43- private static final boolean TSFILE_JDBC_COMPLIANT = false ;
47+ private static final boolean IOTDB_JDBC_COMPLIANT = false ;
48+
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 );
4453
4554 static {
4655 try {
@@ -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,77 @@ 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+ createSensitiveProperty (Config .AUTH_PASSWORD , "Password for authentication." ),
107+ createProperty (
108+ Config .DEFAULT_BUFFER_CAPACITY ,
109+ String .valueOf (RpcUtils .THRIFT_DEFAULT_BUF_CAPACITY ),
110+ "Thrift default buffer capacity in bytes." ,
111+ properties ),
112+ createProperty (
113+ Config .THRIFT_FRAME_MAX_SIZE ,
114+ String .valueOf (RpcUtils .THRIFT_FRAME_MAX_SIZE ),
115+ "Thrift max frame size in bytes." ,
116+ properties ),
117+ createProperty (
118+ Config .VERSION ,
119+ Config .DEFAULT_VERSION .name (),
120+ VERSION_CHOICES ,
121+ "Client compatibility version." ,
122+ properties ),
123+ createProperty (
124+ Config .NETWORK_TIMEOUT ,
125+ String .valueOf (Config .DEFAULT_CONNECTION_TIMEOUT_MS ),
126+ "Network timeout in milliseconds." ,
127+ properties ),
128+ createProperty (
129+ Config .TIME_ZONE , ZoneId .systemDefault ().toString (), "Connection time zone." , properties ),
130+ createProperty (
131+ Config .CHARSET , TSFileConfig .STRING_CHARSET .name (), "Connection charset." , properties ),
132+ createProperty (
133+ Config .USE_SSL , "false" , BOOLEAN_CHOICES , "Whether to enable SSL." , properties ),
134+ createProperty (Config .TRUST_STORE , null , "SSL trust store path." , properties ),
135+ createSensitiveProperty (Config .TRUST_STORE_PWD , "SSL trust store password." ),
136+ createProperty (
137+ Config .SQL_DIALECT ,
138+ Constant .TREE ,
139+ SQL_DIALECT_CHOICES ,
140+ "SQL dialect for the connection." ,
141+ properties )
142+ };
97143 }
98144
99145 @ Override
100146 public boolean jdbcCompliant () {
101- return TSFILE_JDBC_COMPLIANT ;
147+ return IOTDB_JDBC_COMPLIANT ;
148+ }
149+
150+ private static DriverPropertyInfo createProperty (
151+ String name , String defaultValue , String description , Properties properties ) {
152+ return createProperty (name , defaultValue , null , description , properties );
153+ }
154+
155+ private static DriverPropertyInfo createSensitiveProperty (String name , String description ) {
156+ DriverPropertyInfo propertyInfo = new DriverPropertyInfo (name , null );
157+ propertyInfo .required = false ;
158+ propertyInfo .description = description ;
159+ return propertyInfo ;
160+ }
161+
162+ private static DriverPropertyInfo createProperty (
163+ String name ,
164+ String defaultValue ,
165+ String [] choices ,
166+ String description ,
167+ Properties properties ) {
168+ DriverPropertyInfo propertyInfo =
169+ new DriverPropertyInfo (name , properties .getProperty (name , defaultValue ));
170+ propertyInfo .required = false ;
171+ propertyInfo .choices = choices ;
172+ propertyInfo .description = description ;
173+ return propertyInfo ;
102174 }
103175}
0 commit comments