Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
dbf5d7fa
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dbf5d7fa
编写于
7月 01, 2021
作者:
S
Serge Rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#11533 Variables registry
上级
d37b3795
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
197 addition
and
5 deletion
+197
-5
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/SQLScriptContext.java
...sql/src/org/jkiss/dbeaver/model/sql/SQLScriptContext.java
+25
-0
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLQueryParameterRegistry.java
...dbeaver/model/sql/registry/SQLQueryParameterRegistry.java
+2
-2
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLVariablesRegistry.java
...kiss/dbeaver/model/sql/registry/SQLVariablesRegistry.java
+167
-0
plugins/org.jkiss.dbeaver.registry/src/org/jkiss/dbeaver/registry/DataSourceSerializerModern.java
...rg/jkiss/dbeaver/registry/DataSourceSerializerModern.java
+3
-3
未找到文件。
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/SQLScriptContext.java
浏览文件 @
dbf5d7fa
...
...
@@ -21,11 +21,14 @@ import org.jkiss.code.NotNull;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.model.DBPContextProvider
;
import
org.jkiss.dbeaver.model.DBPDataSourceContainer
;
import
org.jkiss.dbeaver.model.connection.DBPDriver
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionContext
;
import
org.jkiss.dbeaver.model.exec.DBCScriptContext
;
import
org.jkiss.dbeaver.model.exec.DBCScriptContextListener
;
import
org.jkiss.dbeaver.model.sql.registry.SQLCommandHandlerDescriptor
;
import
org.jkiss.dbeaver.model.sql.registry.SQLCommandsRegistry
;
import
org.jkiss.dbeaver.model.sql.registry.SQLVariablesRegistry
;
import
org.jkiss.utils.ArrayUtils
;
import
org.jkiss.utils.CommonUtils
;
...
...
@@ -274,6 +277,28 @@ public class SQLScriptContext implements DBCScriptContext {
return
params
;
}
////////////////////////////////////////////////////
// Persistence
public
void
loadVariables
(
DBPDriver
driver
,
DBPDataSourceContainer
dataSource
)
{
variables
.
clear
();
List
<
VariableInfo
>
varList
;
if
(
dataSource
!=
null
)
{
varList
=
SQLVariablesRegistry
.
getInstance
().
getDataSourceVariables
(
dataSource
);
}
else
if
(
dataSource
!=
null
)
{
varList
=
SQLVariablesRegistry
.
getInstance
().
getDriverVariables
(
driver
);
}
else
{
varList
=
new
ArrayList
<>();
}
}
public
void
saveVariables
(
DBPDriver
driver
,
DBPDataSourceContainer
dataSource
)
{
SQLVariablesRegistry
.
getInstance
().
updateVariables
(
driver
,
dataSource
,
new
ArrayList
<>(
variables
.
values
()));
}
////////////////////////////////////////////////////
// Listeners
@Override
public
synchronized
void
addListener
(
DBCScriptContextListener
listener
)
{
...
...
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLQueryParameterRegistry.java
浏览文件 @
dbf5d7fa
...
...
@@ -58,7 +58,7 @@ public class SQLQueryParameterRegistry
{
if
(
registry
==
null
)
{
registry
=
new
SQLQueryParameterRegistry
();
registry
.
loadP
rofile
s
();
registry
.
loadP
arameter
s
();
}
return
registry
;
}
...
...
@@ -77,7 +77,7 @@ public class SQLQueryParameterRegistry
parameterMap
.
put
(
name
.
toUpperCase
(
Locale
.
ENGLISH
),
new
ParameterInfo
(
name
,
value
));
}
private
void
loadP
rofile
s
()
private
void
loadP
arameter
s
()
{
File
storeFile
=
DBWorkbench
.
getPlatform
().
getConfigurationFile
(
CONFIG_FILE_NAME
);
if
(!
storeFile
.
exists
())
{
...
...
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLVariablesRegistry.java
0 → 100644
浏览文件 @
dbf5d7fa
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jkiss.dbeaver.model.sql.registry
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.DBPDataSourceContainer
;
import
org.jkiss.dbeaver.model.connection.DBPDriver
;
import
org.jkiss.dbeaver.model.data.json.JSONUtils
;
import
org.jkiss.dbeaver.model.exec.DBCScriptContext
;
import
org.jkiss.dbeaver.model.sql.internal.SQLModelActivator
;
import
org.jkiss.utils.CommonUtils
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
public
class
SQLVariablesRegistry
{
private
static
final
Log
log
=
Log
.
getLog
(
SQLVariablesRegistry
.
class
);
public
static
final
String
CONFIG_FILE_PREFIX
=
"sql-variables-"
;
//$NON-NLS-1$
public
static
final
String
CONFIG_FILE_SUFFIX
=
".json"
;
//$NON-NLS-1$
public
static
final
String
CONFIG_FILE_TYPE_DRIVER
=
"driver"
;
//$NON-NLS-1$
public
static
final
String
CONFIG_FILE_TYPE_CONNECTION
=
"con"
;
//$NON-NLS-1$
private
static
final
Gson
CONFIG_GSON
=
new
GsonBuilder
()
.
setLenient
()
.
serializeNulls
()
.
setPrettyPrinting
()
.
create
();
private
static
SQLVariablesRegistry
registry
;
private
final
Map
<
DBPDriver
,
List
<
DBCScriptContext
.
VariableInfo
>>
driverVariables
=
new
HashMap
<>();
private
final
Map
<
DBPDataSourceContainer
,
List
<
DBCScriptContext
.
VariableInfo
>>
connectionVariables
=
new
HashMap
<>();
private
SQLVariablesRegistry
()
{
}
public
static
synchronized
SQLVariablesRegistry
getInstance
()
{
if
(
registry
==
null
)
{
registry
=
new
SQLVariablesRegistry
();
registry
.
loadVariables
();
}
return
registry
;
}
private
void
loadVariables
()
{
File
configLocation
=
getConfigLocation
();
File
[]
configFiles
=
configLocation
.
listFiles
((
dir
,
name
)
->
name
.
startsWith
(
CONFIG_FILE_PREFIX
));
if
(
configFiles
==
null
)
{
return
;
}
for
(
File
configFile
:
configFiles
)
{
String
configName
=
configFile
.
getName
();
if
(!
configName
.
endsWith
(
CONFIG_FILE_SUFFIX
))
{
log
.
debug
(
"Skip variables config: bad file extension ("
+
configFile
.
getAbsolutePath
()
+
")"
);
continue
;
}
configName
=
configName
.
substring
(
CONFIG_FILE_PREFIX
.
length
(),
configName
.
length
()
-
CONFIG_FILE_SUFFIX
.
length
());
String
driverId
=
null
,
conId
=
null
;
if
(
configName
.
startsWith
(
CONFIG_FILE_TYPE_DRIVER
))
{
driverId
=
configName
.
substring
(
CONFIG_FILE_TYPE_DRIVER
.
length
()
+
1
);
}
else
if
(
configName
.
startsWith
(
CONFIG_FILE_TYPE_CONNECTION
))
{
conId
=
configName
.
substring
(
CONFIG_FILE_TYPE_DRIVER
.
length
()
+
1
);
}
else
{
log
.
debug
(
"Skip variables config: unrecognized variables target ("
+
configFile
.
getAbsolutePath
()
+
")"
);
continue
;
}
List
<
DBCScriptContext
.
VariableInfo
>
variables
=
loadVariablesFromFile
(
configFile
);
if
(
driverId
!=
null
)
{
DBPDriver
driver
=
null
;
driverVariables
.
put
(
driver
,
variables
);
}
else
{
DBPDataSourceContainer
dataSource
=
null
;
connectionVariables
.
put
(
dataSource
,
variables
);
}
}
}
private
List
<
DBCScriptContext
.
VariableInfo
>
loadVariablesFromFile
(
File
file
)
{
try
(
InputStream
is
=
new
FileInputStream
(
file
))
{
try
(
Reader
r
=
new
InputStreamReader
(
is
,
StandardCharsets
.
UTF_8
))
{
Map
<
String
,
Object
>
map
=
JSONUtils
.
parseMap
(
CONFIG_GSON
,
r
);
List
<
DBCScriptContext
.
VariableInfo
>
variables
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
map
.
entrySet
())
{
DBCScriptContext
.
VariableInfo
variableInfo
;
if
(
entry
.
getValue
()
instanceof
Map
)
{
Map
<
String
,
Object
>
valueMap
=
(
Map
<
String
,
Object
>)
entry
.
getValue
();
Object
value
=
valueMap
.
get
(
"value"
);
String
type
=
JSONUtils
.
getString
(
valueMap
,
"type"
);
if
(
value
==
null
||
type
==
null
)
{
log
.
debug
(
"Invalid variable declaration ("
+
entry
.
getKey
()
+
")"
);
continue
;
}
variableInfo
=
new
DBCScriptContext
.
VariableInfo
(
entry
.
getKey
(),
value
,
CommonUtils
.
valueOf
(
DBCScriptContext
.
VariableType
.
class
,
type
,
DBCScriptContext
.
VariableType
.
VARIABLE
));
}
else
{
variableInfo
=
new
DBCScriptContext
.
VariableInfo
(
entry
.
getKey
(),
entry
.
getValue
(),
DBCScriptContext
.
VariableType
.
VARIABLE
);
}
variables
.
add
(
variableInfo
);
}
return
variables
;
}
}
catch
(
IOException
e
)
{
log
.
error
(
e
);
return
Collections
.
emptyList
();
}
}
private
File
getConfigLocation
()
{
return
SQLModelActivator
.
getInstance
().
getStateLocation
().
toFile
();
}
@NotNull
public
List
<
DBCScriptContext
.
VariableInfo
>
getDriverVariables
(
DBPDriver
driver
)
{
List
<
DBCScriptContext
.
VariableInfo
>
variables
=
driverVariables
.
get
(
driver
);
return
variables
==
null
?
Collections
.
emptyList
()
:
new
ArrayList
<>(
variables
);
}
@NotNull
public
List
<
DBCScriptContext
.
VariableInfo
>
getDataSourceVariables
(
DBPDataSourceContainer
dataSource
)
{
List
<
DBCScriptContext
.
VariableInfo
>
variables
=
connectionVariables
.
get
(
dataSource
);
if
(
variables
==
null
)
{
return
getDriverVariables
(
dataSource
.
getDriver
());
}
List
<
DBCScriptContext
.
VariableInfo
>
result
=
new
ArrayList
<>(
variables
);
result
.
addAll
(
getDriverVariables
(
dataSource
.
getDriver
()));
return
result
;
}
public
void
updateVariables
(
@Nullable
DBPDriver
driver
,
@Nullable
DBPDataSourceContainer
dataSource
,
@NotNull
List
<
DBCScriptContext
.
VariableInfo
>
variables
)
{
}
}
plugins/org.jkiss.dbeaver.registry/src/org/jkiss/dbeaver/registry/DataSourceSerializerModern.java
浏览文件 @
dbf5d7fa
...
...
@@ -74,12 +74,12 @@ class DataSourceSerializerModern implements DataSourceSerializer
private
static
final
Log
log
=
Log
.
getLog
(
DataSourceSerializerModern
.
class
);
private
static
final
String
NODE_CONNECTION
=
"#connection"
;
private
static
Gson
CONFIG_GSON
=
new
GsonBuilder
()
private
static
final
Gson
CONFIG_GSON
=
new
GsonBuilder
()
.
setLenient
()
.
serializeNulls
()
.
setPrettyPrinting
()
.
create
();
private
static
Gson
SECURE_GSON
=
new
GsonBuilder
()
private
static
final
Gson
SECURE_GSON
=
new
GsonBuilder
()
.
setLenient
()
.
serializeNulls
()
.
create
();
...
...
@@ -92,7 +92,7 @@ class DataSourceSerializerModern implements DataSourceSerializer
// 0 level: datasource ID
// 1 level: object type (connection or handler id)
// 2 level: map of secured properties
private
Map
<
String
,
Map
<
String
,
Map
<
String
,
String
>>>
secureProperties
=
new
LinkedHashMap
<>();
private
final
Map
<
String
,
Map
<
String
,
Map
<
String
,
String
>>>
secureProperties
=
new
LinkedHashMap
<>();
DataSourceSerializerModern
(
DataSourceRegistry
registry
)
{
this
.
registry
=
registry
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录