Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
0e987bb9
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0e987bb9
编写于
1月 21, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
9a55077b
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
442 addition
and
950 deletion
+442
-950
src/connector/jdbc/src/main/java/App3.java
src/connector/jdbc/src/main/java/App3.java
+0
-60
src/connector/jdbc/src/main/java/TdEngineSuperDataGen.java
src/connector/jdbc/src/main/java/TdEngineSuperDataGen.java
+0
-67
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
...main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
+390
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData.java
.../jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData.java
+36
-36
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
...src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
+11
-408
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java
...in/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java
+5
-379
未找到文件。
src/connector/jdbc/src/main/java/App3.java
已删除
100755 → 0
浏览文件 @
9a55077b
import
org.apache.commons.dbcp2.BasicDataSource
;
import
java.sql.*
;
public
class
App3
{
public
static
void
main
(
String
[]
args
)
throws
SQLException
,
ClassNotFoundException
{
// 添加数据源1-TDengine,并且作为schema命名为“public”
String
url
=
"jdbc:TAOS://127.0.0.1:6030/hdb"
;
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
BasicDataSource
dataSource
=
new
BasicDataSource
();
dataSource
.
setUrl
(
url
);
dataSource
.
setUsername
(
"root"
);
dataSource
.
setPassword
(
"taosdata"
);
// 执行SQL语句,sql语句中表的引用必须用前面设置的schema名称,例如“testdata”就是schema“public“下的表,”datedim“是schema”test“下的表。
String
sql
=
"select cast(s.updates as date ),t.id,t.cmt from public.testdata t , test.datedim s "
+
"where cast(t.uptime as date )=s.updates and t.uptime<'2011-12-01 00:00:00' and t.id>100 limit 100 offset 10 "
;
long
startTime
=
System
.
currentTimeMillis
();
Connection
conn
=
dataSource
.
getConnection
();
Statement
stmt
=
conn
.
createStatement
();
// ResultSet rs = stmt.executeQuery(sql);
long
rowCount
=
0
;
String
[]
types
=
{
"TABLE"
};
ResultSet
rs
=
conn
.
getMetaData
().
getTables
(
"hdb"
,
null
,
null
,
types
);
while
(
rs
.
next
())
{
// if (rowCount < 5) {
for
(
int
j
=
0
;
j
<
rs
.
getMetaData
().
getColumnCount
();
j
++)
{
System
.
out
.
print
(
rs
.
getMetaData
().
getColumnName
(
j
+
1
)
+
": "
+
rs
.
getObject
(
j
)
+
", "
);
}
System
.
out
.
println
();
// }
rowCount
++;
}
rs
.
close
();
System
.
out
.
println
(
"\nGET COLUMN:"
);
rs
=
conn
.
getMetaData
().
getColumns
(
"hdb"
,
null
,
"sdata"
,
null
);
while
(
rs
.
next
())
{
// if (rowCount < 5) {
ResultSetMetaData
meta
=
rs
.
getMetaData
();
for
(
int
j
=
0
;
j
<
rs
.
getMetaData
().
getColumnCount
();
j
++)
{
if
(
j
!=
7
)
{
System
.
out
.
print
(
rs
.
getMetaData
().
getColumnName
(
j
+
1
)
+
": "
+
rs
.
getObject
(
j
)
+
", "
);
System
.
out
.
println
();
}
}
System
.
out
.
println
();
// }
rowCount
++;
}
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"execute time:"
+
(
endTime
-
startTime
)
+
"ms, resultset rows "
+
rowCount
+
", "
+
rowCount
*
1000
/
(
endTime
-
startTime
)
+
" rows/sec"
);
rs
.
close
();
stmt
.
close
();
conn
.
close
();
}
}
src/connector/jdbc/src/main/java/TdEngineSuperDataGen.java
已删除
100755 → 0
浏览文件 @
9a55077b
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Random
;
import
org.apache.commons.codec.digest.DigestUtils
;
public
class
TdEngineSuperDataGen
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
String
url
=
"jdbc:TAOS://127.0.0.1:6030/test?user=root&password=taosdata"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
);
Statement
stmt
=
conn
.
createStatement
();
// create database
stmt
.
executeUpdate
(
"create database if not exists hdb"
);
// use database
stmt
.
executeUpdate
(
"use hdb"
);
stmt
.
executeUpdate
(
"drop table if exists sdata"
);
// create table
stmt
.
executeUpdate
(
"create table if not exists sdata (uptime timestamp, id int, x int , y int ,cmt binary(100)) tags(location nchar(100),tname nchar(100))"
);
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
Map
<
String
,
String
>
table
=
new
HashMap
<>();
table
.
put
(
"dt001"
,
"beijing"
);
table
.
put
(
"dt002"
,
"shanghai"
);
table
.
put
(
"dt003"
,
"chongqing"
);
table
.
put
(
"dt004"
,
"xian"
);
for
(
Entry
<
String
,
String
>
kv
:
table
.
entrySet
())
{
LocalDateTime
d
=
LocalDateTime
.
now
().
minusMonths
(
2
);
long
rowCount
=
LocalDateTime
.
now
().
atZone
(
zoneId
).
toEpochSecond
()
-
d
.
atZone
(
zoneId
).
toEpochSecond
();
Random
r
=
new
Random
();
StringBuilder
sb
=
null
;
long
startTime
=
System
.
currentTimeMillis
();
try
{
for
(
long
i
=
0
;
i
<
rowCount
;
i
++)
{
sb
=
new
StringBuilder
(
"insert into "
+
kv
.
getKey
()
+
" using sdata tags("
+
kv
.
getValue
()
+
","
+
kv
.
getKey
()
+
") values('"
);
d
=
d
.
plusSeconds
(
1
);
sb
.
append
(
d
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss.MS"
)));
sb
.
append
(
"',"
+
i
+
","
+
r
.
nextInt
(
100
)
+
","
+
r
.
nextInt
(
100
)
+
",'"
);
sb
.
append
(
DigestUtils
.
md5Hex
(
d
.
toString
()));
sb
.
append
(
"')"
);
System
.
out
.
println
(
"SQL >>> "
+
sb
.
toString
());
stmt
.
executeUpdate
(
sb
.
toString
());
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
d
);
System
.
out
.
println
(
sb
.
toString
());
e
.
printStackTrace
();
}
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"generate data execute time:"
+
(
endTime
-
startTime
)
+
"ms, resultset rows "
+
rowCount
+
", "
+
rowCount
*
1000
/
(
endTime
-
startTime
)
+
" rows/sec"
);
}
stmt
.
close
();
conn
.
close
();
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
浏览文件 @
0e987bb9
...
...
@@ -495,6 +495,102 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
public
abstract
ResultSet
getTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
[]
types
)
throws
SQLException
;
protected
ResultSet
getTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
[]
types
,
Connection
connection
)
throws
SQLException
{
try
(
Statement
stmt
=
connection
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
2
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
3
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
4
);
col4
.
setColName
(
"TABLE_TYPE"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
5
);
col5
.
setColName
(
"REMARKS"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col5
);
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
6
);
col6
.
setColName
(
"TYPE_CAT"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
ColumnMetaData
col7
=
new
ColumnMetaData
();
col7
.
setColIndex
(
7
);
col7
.
setColName
(
"TYPE_SCHEM"
);
col7
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col7
);
ColumnMetaData
col8
=
new
ColumnMetaData
();
col8
.
setColIndex
(
8
);
col8
.
setColName
(
"TYPE_NAME"
);
col8
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col8
);
ColumnMetaData
col9
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
col9
.
setColName
(
"SELF_REFERENCING_COL_NAME"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col9
);
ColumnMetaData
col10
=
new
ColumnMetaData
();
col10
.
setColIndex
(
10
);
col10
.
setColName
(
"REF_GENERATION"
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col10
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
tables
=
stmt
.
executeQuery
(
"show tables"
);
while
(
tables
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
10
);
rowData
.
setString
(
0
,
dbname
);
rowData
.
setString
(
2
,
tables
.
getString
(
"table_name"
));
rowData
.
setString
(
3
,
"TABLE"
);
rowData
.
setString
(
4
,
""
);
rowDataList
.
add
(
rowData
);
}
ResultSet
stables
=
stmt
.
executeQuery
(
"show stables"
);
while
(
stables
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
10
);
rowData
.
setString
(
0
,
dbname
);
rowData
.
setString
(
2
,
stables
.
getString
(
"name"
));
rowData
.
setString
(
3
,
"TABLE"
);
rowData
.
setString
(
4
,
"STABLE"
);
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
}
public
ResultSet
getSchemas
()
throws
SQLException
{
return
getEmptyResultSet
();
}
...
...
@@ -803,4 +899,298 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
public
boolean
isWrapperFor
(
Class
<?>
iface
)
throws
SQLException
{
return
iface
.
isInstance
(
this
);
}
protected
ResultSet
getCatalogs
(
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
rs
=
stmt
.
executeQuery
(
"show databases"
);
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
1
);
rowData
.
setString
(
0
,
rs
.
getString
(
"name"
));
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
}
protected
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
,
Connection
conn
)
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
24
);
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
2
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
3
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColSize
(
193
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// COLUMN_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
4
);
col4
.
setColName
(
"COLUMN_NAME"
);
col4
.
setColSize
(
65
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
// DATA_TYPE
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
5
);
col5
.
setColName
(
"DATA_TYPE"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col5
);
// TYPE_NAME
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
6
);
col6
.
setColName
(
"TYPE_NAME"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
// COLUMN_SIZE
ColumnMetaData
col7
=
new
ColumnMetaData
();
col7
.
setColIndex
(
7
);
col7
.
setColName
(
"COLUMN_SIZE"
);
col7
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col7
);
// BUFFER_LENGTH ,not used
columnMetaDataList
.
add
(
null
);
// DECIMAL_DIGITS
ColumnMetaData
col9
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
col9
.
setColName
(
"DECIMAL_DIGITS"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col9
);
// add NUM_PREC_RADIX
ColumnMetaData
col10
=
new
ColumnMetaData
();
col10
.
setColIndex
(
10
);
col10
.
setColName
(
"NUM_PREC_RADIX"
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col10
);
// NULLABLE
ColumnMetaData
col11
=
new
ColumnMetaData
();
col11
.
setColIndex
(
11
);
col11
.
setColName
(
"NULLABLE"
);
col11
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col11
);
// REMARKS
ColumnMetaData
col12
=
new
ColumnMetaData
();
col12
.
setColIndex
(
12
);
col12
.
setColName
(
"REMARKS"
);
col12
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col12
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set up rowDataList
ResultSet
rs
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
"."
+
tableNamePattern
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
int
index
=
0
;
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
24
);
// set TABLE_CAT
rowData
.
setString
(
0
,
dbname
);
// set TABLE_NAME
rowData
.
setString
(
2
,
tableNamePattern
);
// set COLUMN_NAME
rowData
.
setString
(
3
,
rs
.
getString
(
"Field"
));
// set DATA_TYPE
String
typeName
=
rs
.
getString
(
"Type"
);
rowData
.
setInt
(
4
,
getDataType
(
typeName
));
// set TYPE_NAME
rowData
.
setString
(
5
,
typeName
);
// set COLUMN_SIZE
int
length
=
rs
.
getInt
(
"Length"
);
rowData
.
setInt
(
6
,
getColumnSize
(
typeName
,
length
));
// set DECIMAL_DIGITS
rowData
.
setInt
(
8
,
getDecimalDigits
(
typeName
));
// set NUM_PREC_RADIX
rowData
.
setInt
(
9
,
10
);
// set NULLABLE
rowData
.
setInt
(
10
,
getNullable
(
index
,
typeName
));
// set REMARKS
rowData
.
setString
(
11
,
rs
.
getString
(
"Note"
));
rowDataList
.
add
(
rowData
);
index
++;
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
protected
ResultSet
getPrimaryKeys
(
String
catalog
,
String
schema
,
String
table
,
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
0
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
1
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
2
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// COLUMN_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
3
);
col4
.
setColName
(
"COLUMN_NAME"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
// KEY_SEQ
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
4
);
col5
.
setColName
(
"KEY_SEQ"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col5
);
// PK_NAME
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
5
);
col6
.
setColName
(
"PK_NAME"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set rowData
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
rs
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
"."
+
table
);
rs
.
next
();
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
6
);
rowData
.
setString
(
0
,
null
);
rowData
.
setString
(
1
,
null
);
rowData
.
setString
(
2
,
table
);
String
pkName
=
rs
.
getString
(
1
);
rowData
.
setString
(
3
,
pkName
);
rowData
.
setInt
(
4
,
1
);
rowData
.
setString
(
5
,
pkName
);
rowDataList
.
add
(
rowData
);
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
}
protected
ResultSet
getSuperTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
0
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
1
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
2
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// SUPERTABLE_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
3
);
col4
.
setColName
(
"SUPERTABLE_NAME"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
ResultSet
rs
=
stmt
.
executeQuery
(
"show tables like '"
+
tableNamePattern
+
"'"
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
4
);
rowData
.
setString
(
2
,
rs
.
getString
(
1
));
rowData
.
setString
(
3
,
rs
.
getString
(
4
));
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
}
}
\ No newline at end of file
src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData.java
浏览文件 @
0e987bb9
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
浏览文件 @
0e987bb9
...
...
@@ -14,9 +14,9 @@
*****************************************************************************/
package
com.taosdata.jdbc
;
import
java.sql.
*
;
import
java.
util.ArrayLis
t
;
import
java.
util.List
;
import
java.sql.
Connection
;
import
java.
sql.ResultSe
t
;
import
java.
sql.SQLException
;
public
class
TSDBDatabaseMetaData
extends
AbstractDatabaseMetaData
{
...
...
@@ -59,435 +59,38 @@ public class TSDBDatabaseMetaData extends AbstractDatabaseMetaData {
if
(
conn
==
null
||
conn
.
isClosed
())
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
2
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
3
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
4
);
col4
.
setColName
(
"TABLE_TYPE"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
5
);
col5
.
setColName
(
"REMARKS"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col5
);
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
6
);
col6
.
setColName
(
"TYPE_CAT"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
ColumnMetaData
col7
=
new
ColumnMetaData
();
col7
.
setColIndex
(
7
);
col7
.
setColName
(
"TYPE_SCHEM"
);
col7
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col7
);
ColumnMetaData
col8
=
new
ColumnMetaData
();
col8
.
setColIndex
(
8
);
col8
.
setColName
(
"TYPE_NAME"
);
col8
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col8
);
ColumnMetaData
col9
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
col9
.
setColName
(
"SELF_REFERENCING_COL_NAME"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col9
);
ColumnMetaData
col10
=
new
ColumnMetaData
();
col10
.
setColIndex
(
10
);
col10
.
setColName
(
"REF_GENERATION"
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col10
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
tables
=
stmt
.
executeQuery
(
"show tables"
);
while
(
tables
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
10
);
rowData
.
setString
(
0
,
dbname
);
rowData
.
setString
(
2
,
tables
.
getString
(
"table_name"
));
rowData
.
setString
(
3
,
"TABLE"
);
rowData
.
setString
(
4
,
""
);
rowDataList
.
add
(
rowData
);
return
super
.
getTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
types
,
conn
);
}
ResultSet
stables
=
stmt
.
executeQuery
(
"show stables"
);
while
(
stables
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
10
);
rowData
.
setString
(
0
,
dbname
);
rowData
.
setString
(
2
,
stables
.
getString
(
"name"
));
rowData
.
setString
(
3
,
"TABLE"
);
rowData
.
setString
(
4
,
"STABLE"
);
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
}
public
ResultSet
getCatalogs
()
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
conn
.
createStatement
())
{
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
24
);
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
rs
=
stmt
.
executeQuery
(
"show databases"
);
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
1
);
rowData
.
setString
(
0
,
rs
.
getString
(
"name"
));
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
return
super
.
getCatalogs
(
conn
);
}
public
ResultSet
getTableTypes
()
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
ColumnMetaData
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
0
);
colMetaData
.
setColName
(
"TABLE_TYPE"
);
colMetaData
.
setColSize
(
10
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
colMetaData
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set up rowDataList
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
1
);
rowData
.
setString
(
0
,
"TABLE"
);
rowDataList
.
add
(
rowData
);
rowData
=
new
TSDBResultSetRowData
(
1
);
rowData
.
setString
(
0
,
"STABLE"
);
rowDataList
.
add
(
rowData
);
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
return
super
.
getTableTypes
();
}
public
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
24
);
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
2
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
3
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColSize
(
193
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// COLUMN_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
4
);
col4
.
setColName
(
"COLUMN_NAME"
);
col4
.
setColSize
(
65
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
// DATA_TYPE
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
5
);
col5
.
setColName
(
"DATA_TYPE"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col5
);
// TYPE_NAME
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
6
);
col6
.
setColName
(
"TYPE_NAME"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
// COLUMN_SIZE
ColumnMetaData
col7
=
new
ColumnMetaData
();
col7
.
setColIndex
(
7
);
col7
.
setColName
(
"COLUMN_SIZE"
);
col7
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col7
);
// BUFFER_LENGTH ,not used
columnMetaDataList
.
add
(
null
);
// DECIMAL_DIGITS
ColumnMetaData
col9
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
col9
.
setColName
(
"DECIMAL_DIGITS"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col9
);
// add NUM_PREC_RADIX
ColumnMetaData
col10
=
new
ColumnMetaData
();
col10
.
setColIndex
(
10
);
col10
.
setColName
(
"NUM_PREC_RADIX"
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col10
);
// NULLABLE
ColumnMetaData
col11
=
new
ColumnMetaData
();
col11
.
setColIndex
(
11
);
col11
.
setColName
(
"NULLABLE"
);
col11
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col11
);
// REMARKS
ColumnMetaData
col12
=
new
ColumnMetaData
();
col12
.
setColIndex
(
12
);
col12
.
setColName
(
"REMARKS"
);
col12
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col12
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set up rowDataList
ResultSet
rs
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
"."
+
tableNamePattern
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
int
index
=
0
;
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
24
);
// set TABLE_CAT
rowData
.
setString
(
0
,
dbname
);
// set TABLE_NAME
rowData
.
setString
(
2
,
tableNamePattern
);
// set COLUMN_NAME
rowData
.
setString
(
3
,
rs
.
getString
(
"Field"
));
// set DATA_TYPE
String
typeName
=
rs
.
getString
(
"Type"
);
rowData
.
setInt
(
4
,
getDataType
(
typeName
));
// set TYPE_NAME
rowData
.
setString
(
5
,
typeName
);
// set COLUMN_SIZE
int
length
=
rs
.
getInt
(
"Length"
);
rowData
.
setInt
(
6
,
getColumnSize
(
typeName
,
length
));
// set DECIMAL_DIGITS
rowData
.
setInt
(
8
,
getDecimalDigits
(
typeName
));
// set NUM_PREC_RADIX
rowData
.
setInt
(
9
,
10
);
// set NULLABLE
rowData
.
setInt
(
10
,
getNullable
(
index
,
typeName
));
// set REMARKS
rowData
.
setString
(
11
,
rs
.
getString
(
"Note"
));
rowDataList
.
add
(
rowData
);
index
++;
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
null
;
return
super
.
getColumns
(
catalog
,
schemaPattern
,
tableNamePattern
,
columnNamePattern
,
conn
);
}
public
ResultSet
getPrimaryKeys
(
String
catalog
,
String
schema
,
String
table
)
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
return
super
.
getPrimaryKeys
(
catalog
,
schema
,
table
,
conn
);
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
0
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
1
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
2
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// COLUMN_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
3
);
col4
.
setColName
(
"COLUMN_NAME"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
// KEY_SEQ
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
4
);
col5
.
setColName
(
"KEY_SEQ"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col5
);
// PK_NAME
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
5
);
col6
.
setColName
(
"PK_NAME"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set rowData
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
rs
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
"."
+
table
);
rs
.
next
();
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
6
);
rowData
.
setString
(
0
,
null
);
rowData
.
setString
(
1
,
null
);
rowData
.
setString
(
2
,
table
);
String
pkName
=
rs
.
getString
(
1
);
rowData
.
setString
(
3
,
pkName
);
rowData
.
setInt
(
4
,
1
);
rowData
.
setString
(
5
,
pkName
);
rowDataList
.
add
(
rowData
);
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
}
public
ResultSet
getSuperTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
)
throws
SQLException
{
public
ResultSet
getSuperTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
)
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
0
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
1
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
2
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// SUPERTABLE_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
3
);
col4
.
setColName
(
"SUPERTABLE_NAME"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
ResultSet
rs
=
stmt
.
executeQuery
(
"show tables like '"
+
tableNamePattern
+
"'"
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
4
);
rowData
.
setString
(
2
,
rs
.
getString
(
1
));
rowData
.
setString
(
3
,
rs
.
getString
(
4
));
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
return
super
.
getSuperTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
conn
);
}
}
\ No newline at end of file
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java
浏览文件 @
0e987bb9
...
...
@@ -38,409 +38,35 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
if
(
connection
==
null
||
connection
.
isClosed
())
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
try
(
Statement
stmt
=
connection
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
2
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
3
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
4
);
col4
.
setColName
(
"TABLE_TYPE"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
5
);
col5
.
setColName
(
"REMARKS"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col5
);
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
6
);
col6
.
setColName
(
"TYPE_CAT"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
ColumnMetaData
col7
=
new
ColumnMetaData
();
col7
.
setColIndex
(
7
);
col7
.
setColName
(
"TYPE_SCHEM"
);
col7
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col7
);
ColumnMetaData
col8
=
new
ColumnMetaData
();
col8
.
setColIndex
(
8
);
col8
.
setColName
(
"TYPE_NAME"
);
col8
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col8
);
ColumnMetaData
col9
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
col9
.
setColName
(
"SELF_REFERENCING_COL_NAME"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col9
);
ColumnMetaData
col10
=
new
ColumnMetaData
();
col10
.
setColIndex
(
10
);
col10
.
setColName
(
"REF_GENERATION"
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col10
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
tables
=
stmt
.
executeQuery
(
"show tables"
);
while
(
tables
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
10
);
rowData
.
setString
(
0
,
dbname
);
rowData
.
setString
(
2
,
tables
.
getString
(
"table_name"
));
rowData
.
setString
(
3
,
"TABLE"
);
rowData
.
setString
(
4
,
""
);
rowDataList
.
add
(
rowData
);
}
ResultSet
stables
=
stmt
.
executeQuery
(
"show stables"
);
while
(
stables
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
10
);
rowData
.
setString
(
0
,
dbname
);
rowData
.
setString
(
2
,
stables
.
getString
(
"name"
));
rowData
.
setString
(
3
,
"TABLE"
);
rowData
.
setString
(
4
,
"STABLE"
);
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
return
super
.
getTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
types
,
connection
);
}
@Override
public
ResultSet
getCatalogs
()
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
connection
.
createStatement
())
{
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
24
);
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
rs
=
stmt
.
executeQuery
(
"show databases"
);
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
1
);
rowData
.
setString
(
0
,
rs
.
getString
(
"name"
));
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
return
super
.
getCatalogs
(
connection
);
}
@Override
public
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
connection
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
24
);
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
2
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
3
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColSize
(
193
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// COLUMN_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
4
);
col4
.
setColName
(
"COLUMN_NAME"
);
col4
.
setColSize
(
65
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
// DATA_TYPE
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
5
);
col5
.
setColName
(
"DATA_TYPE"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col5
);
// TYPE_NAME
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
6
);
col6
.
setColName
(
"TYPE_NAME"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
// COLUMN_SIZE
ColumnMetaData
col7
=
new
ColumnMetaData
();
col7
.
setColIndex
(
7
);
col7
.
setColName
(
"COLUMN_SIZE"
);
col7
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col7
);
// BUFFER_LENGTH ,not used
columnMetaDataList
.
add
(
null
);
// DECIMAL_DIGITS
ColumnMetaData
col9
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
col9
.
setColName
(
"DECIMAL_DIGITS"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col9
);
// add NUM_PREC_RADIX
ColumnMetaData
col10
=
new
ColumnMetaData
();
col10
.
setColIndex
(
10
);
col10
.
setColName
(
"NUM_PREC_RADIX"
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col10
);
// NULLABLE
ColumnMetaData
col11
=
new
ColumnMetaData
();
col11
.
setColIndex
(
11
);
col11
.
setColName
(
"NULLABLE"
);
col11
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col11
);
// REMARKS
ColumnMetaData
col12
=
new
ColumnMetaData
();
col12
.
setColIndex
(
12
);
col12
.
setColName
(
"REMARKS"
);
col12
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col12
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set up rowDataList
ResultSet
rs
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
"."
+
tableNamePattern
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
int
index
=
0
;
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
24
);
// set TABLE_CAT
rowData
.
setString
(
0
,
dbname
);
// set TABLE_NAME
rowData
.
setString
(
2
,
tableNamePattern
);
// set COLUMN_NAME
rowData
.
setString
(
3
,
rs
.
getString
(
"Field"
));
// set DATA_TYPE
String
typeName
=
rs
.
getString
(
"Type"
);
rowData
.
setInt
(
4
,
getDataType
(
typeName
));
// set TYPE_NAME
rowData
.
setString
(
5
,
typeName
);
// set COLUMN_SIZE
int
length
=
rs
.
getInt
(
"Length"
);
rowData
.
setInt
(
6
,
getColumnSize
(
typeName
,
length
));
// set DECIMAL_DIGITS
rowData
.
setInt
(
8
,
getDecimalDigits
(
typeName
));
// set NUM_PREC_RADIX
rowData
.
setInt
(
9
,
10
);
// set NULLABLE
rowData
.
setInt
(
10
,
getNullable
(
index
,
typeName
));
// set REMARKS
rowData
.
setString
(
11
,
rs
.
getString
(
"Note"
));
rowDataList
.
add
(
rowData
);
index
++;
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
null
;
return
super
.
getColumns
(
catalog
,
schemaPattern
,
tableNamePattern
,
columnNamePattern
,
connection
);
}
@Override
public
ResultSet
getPrimaryKeys
(
String
catalog
,
String
schema
,
String
table
)
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
connection
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
0
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
1
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
2
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// COLUMN_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
3
);
col4
.
setColName
(
"COLUMN_NAME"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
// KEY_SEQ
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
4
);
col5
.
setColName
(
"KEY_SEQ"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col5
);
// PK_NAME
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
5
);
col6
.
setColName
(
"PK_NAME"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set rowData
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
rs
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
"."
+
table
);
rs
.
next
();
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
6
);
rowData
.
setString
(
0
,
null
);
rowData
.
setString
(
1
,
null
);
rowData
.
setString
(
2
,
table
);
String
pkName
=
rs
.
getString
(
1
);
rowData
.
setString
(
3
,
pkName
);
rowData
.
setInt
(
4
,
1
);
rowData
.
setString
(
5
,
pkName
);
rowDataList
.
add
(
rowData
);
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
return
super
.
getPrimaryKeys
(
catalog
,
schema
,
table
,
connection
);
}
@Override
public
ResultSet
getSuperTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
)
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
try
(
Statement
stmt
=
connection
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
0
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
1
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
2
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// SUPERTABLE_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
3
);
col4
.
setColName
(
"SUPERTABLE_NAME"
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
ResultSet
rs
=
stmt
.
executeQuery
(
"show tables like '"
+
tableNamePattern
+
"'"
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
while
(
rs
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
4
);
rowData
.
setString
(
2
,
rs
.
getString
(
1
));
rowData
.
setString
(
3
,
rs
.
getString
(
4
));
rowDataList
.
add
(
rowData
);
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
return
super
.
getSuperTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
connection
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录