Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
55699eb2
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,发现更多精彩内容 >>
提交
55699eb2
编写于
12月 15, 2019
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#5172 Exasol: default schema
上级
0397ce1b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
168 addition
and
127 deletion
+168
-127
plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/model/ExasolDataSource.java
.../org/jkiss/dbeaver/ext/exasol/model/ExasolDataSource.java
+21
-127
plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/model/ExasolExecutionContext.java
...kiss/dbeaver/ext/exasol/model/ExasolExecutionContext.java
+147
-0
未找到文件。
plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/model/ExasolDataSource.java
浏览文件 @
55699eb2
...
...
@@ -46,7 +46,7 @@ import org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle;
import
org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBC
Utils
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBC
RemoteInstance
;
import
org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCObjectSimpleCache
;
import
org.jkiss.dbeaver.model.impl.sql.QueryTransformerLimit
;
import
org.jkiss.dbeaver.model.meta.Association
;
...
...
@@ -54,27 +54,20 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.DBSDataType
;
import
org.jkiss.dbeaver.model.struct.DBSObject
;
import
org.jkiss.dbeaver.model.struct.DBSObjectSelector
;
import
org.jkiss.dbeaver.model.struct.DBSStructureAssistant
;
import
org.jkiss.dbeaver.model.struct.cache.DBSObjectCache
;
import
org.jkiss.utils.CommonUtils
;
import
java.math.BigDecimal
;
import
java.sql.SQLException
;
import
java.util.*
;
import
java.util.Map.Entry
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
ExasolDataSource
extends
JDBCDataSource
implements
DBSObjectSelector
,
DBCQueryPlanner
,
IAdaptable
{
public
class
ExasolDataSource
extends
JDBCDataSource
implements
DBCQueryPlanner
,
IAdaptable
{
private
static
final
Log
LOG
=
Log
.
getLog
(
ExasolDataSource
.
class
);
private
static
final
String
GET_CURRENT_SCHEMA
=
"SELECT CURRENT_SCHEMA"
;
private
static
final
String
SET_CURRENT_SCHEMA
=
"OPEN SCHEMA \"%s\""
;
private
static
final
String
GET_CURRENT_SESSION
=
"SELECT CURRENT_SESSION"
;
private
DBSObjectCache
<
ExasolDataSource
,
ExasolSchema
>
schemaCache
;
private
DBSObjectCache
<
ExasolDataSource
,
ExasolVirtualSchema
>
virtualSchemaCache
;
...
...
@@ -97,9 +90,6 @@ public class ExasolDataSource extends JDBCDataSource
private
Properties
addMetaProps
=
new
Properties
();
private
int
driverMajorVersion
=
5
;
private
String
activeSchemaName
;
// -----------------------
// Constructors
...
...
@@ -121,15 +111,10 @@ public class ExasolDataSource extends JDBCDataSource
{
super
.
initialize
(
monitor
);
try
(
JDBCSession
session
=
DBUtils
.
openMetaSession
(
monitor
,
this
,
"Load data source meta info"
))
{
// First try to get active schema from special register 'CURRENT
// SCHEMA'
this
.
activeSchemaName
=
determineActiveSchema
(
session
);
this
.
exasolCurrentUserPrivileges
=
new
ExasolCurrentUserPrivileges
(
monitor
,
session
,
this
);
try
(
JDBCSession
session
=
DBUtils
.
openMetaSession
(
monitor
,
this
,
"Load data source meta info"
))
{
this
.
exasolCurrentUserPrivileges
=
new
ExasolCurrentUserPrivileges
(
monitor
,
session
,
this
);
this
.
driverMajorVersion
=
session
.
getMetaData
().
getDriverMajorVersion
();
}
catch
(
SQLException
e
)
{
...
...
@@ -357,41 +342,25 @@ public class ExasolDataSource extends JDBCDataSource
positions
.
add
(
pos
);
}
if
(!
positions
.
isEmpty
())
{
return
positions
.
toArray
(
new
ErrorPosition
[
positions
.
size
()
]);
return
positions
.
toArray
(
new
ErrorPosition
[
0
]);
}
}
return
null
;
}
@Override
protected
JDBCExecutionContext
createExecutionContext
(
JDBCRemoteInstance
instance
,
String
type
)
{
return
new
ExasolExecutionContext
(
instance
,
type
);
}
protected
void
initializeContextState
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
JDBCExecutionContext
context
,
boolean
setActiveObject
)
@NotNull
JDBCExecutionContext
context
,
boolean
setActiveObject
)
throws
DBException
{
if
(
setActiveObject
)
{
setCurrentSchema
(
monitor
,
context
,
getDefaultObject
());
}
}
private
String
determineActiveSchema
(
JDBCSession
session
)
throws
SQLException
{
// First try to get active schema from special register 'CURRENT SCHEMA'
String
defSchema
=
JDBCUtils
.
queryString
(
session
,
GET_CURRENT_SCHEMA
);
if
(
defSchema
==
null
)
{
return
null
;
}
return
defSchema
.
trim
();
}
public
BigDecimal
getCurrentSessionId
(
JDBCSession
session
)
throws
DBException
{
try
{
return
(
BigDecimal
)
JDBCUtils
.
queryObject
(
session
,
GET_CURRENT_SESSION
);
}
catch
(
SQLException
e
)
{
throw
new
DBCException
(
e
,
this
);
((
ExasolExecutionContext
)
context
).
setCurrentSchema
(
monitor
,
getDefaultSchema
());
}
else
{
((
ExasolExecutionContext
)
context
).
refreshDefaults
(
monitor
);
}
}
...
...
@@ -490,24 +459,15 @@ public class ExasolDataSource extends JDBCDataSource
// --------------------------
@Override
public
boolean
supportsDefaultChange
()
{
return
true
;
}
@Override
public
Class
<?
extends
ExasolSchema
>
getChildType
(
@NotNull
DBRProgressMonitor
monitor
)
throws
DBException
public
Class
<?
extends
ExasolSchema
>
getChildType
(
@NotNull
DBRProgressMonitor
monitor
)
throws
DBException
{
return
ExasolSchema
.
class
;
}
@Override
public
Collection
<
ExasolSchema
>
getChildren
(
@NotNull
DBRProgressMonitor
monitor
)
throws
DBException
public
Collection
<
ExasolSchema
>
getChildren
(
@NotNull
DBRProgressMonitor
monitor
)
throws
DBException
{
Collection
<
ExasolSchema
>
totalList
=
getSchemas
(
monitor
);
return
totalList
;
return
getSchemas
(
monitor
);
}
@Override
...
...
@@ -519,74 +479,8 @@ public class ExasolDataSource extends JDBCDataSource
return
getSchema
(
monitor
,
childName
);
}
@Override
public
ExasolSchema
getDefaultObject
()
{
return
activeSchemaName
==
null
?
null
:
schemaCache
.
getCachedObject
(
activeSchemaName
);
}
@Override
public
void
setDefaultObject
(
@NotNull
DBRProgressMonitor
monitor
,
@NotNull
DBSObject
object
)
throws
DBException
{
final
ExasolSchema
oldSelectedEntity
=
getDefaultObject
();
if
(!(
object
instanceof
ExasolSchema
))
{
throw
new
IllegalArgumentException
(
"Invalid object type: "
+
object
);
}
for
(
JDBCExecutionContext
context
:
getDefaultInstance
().
getAllContexts
())
{
setCurrentSchema
(
monitor
,
context
,
(
ExasolSchema
)
object
);
}
activeSchemaName
=
object
.
getName
();
// Send notifications
if
(
oldSelectedEntity
!=
null
)
{
DBUtils
.
fireObjectSelect
(
oldSelectedEntity
,
false
);
}
if
(
this
.
activeSchemaName
!=
null
)
{
DBUtils
.
fireObjectSelect
(
object
,
true
);
}
}
@Override
public
boolean
refreshDefaultObject
(
@NotNull
DBCSession
session
)
throws
DBException
{
try
{
final
String
newSchemaName
=
determineActiveSchema
(
(
JDBCSession
)
session
);
if
(!
CommonUtils
.
equalObjects
(
newSchemaName
,
activeSchemaName
))
{
final
ExasolSchema
newSchema
=
schemaCache
.
getCachedObject
(
newSchemaName
);
if
(
newSchema
!=
null
)
{
setDefaultObject
(
session
.
getProgressMonitor
(),
newSchema
);
return
true
;
}
}
return
false
;
}
catch
(
Exception
e
)
{
throw
new
DBException
(
e
,
this
);
}
}
private
void
setCurrentSchema
(
DBRProgressMonitor
monitor
,
JDBCExecutionContext
executionContext
,
ExasolSchema
object
)
throws
DBCException
{
if
(
object
==
null
)
{
LOG
.
debug
(
"Null current schema"
);
return
;
}
try
(
JDBCSession
session
=
executionContext
.
openSession
(
monitor
,
DBCExecutionPurpose
.
UTIL
,
"Set active schema"
))
{
JDBCUtils
.
executeSQL
(
session
,
String
.
format
(
SET_CURRENT_SCHEMA
,
object
.
getName
()));
}
catch
(
SQLException
e
)
{
throw
new
DBCException
(
e
,
this
);
}
public
ExasolSchema
getDefaultSchema
()
{
return
(
ExasolSchema
)
DBUtils
.
getDefaultContext
(
this
,
true
).
getContextDefaults
().
getDefaultSchema
();
}
// --------------
...
...
plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/model/ExasolExecutionContext.java
0 → 100644
浏览文件 @
55699eb2
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* 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.ext.exasol.model
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.exec.DBCException
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionPurpose
;
import
org.jkiss.dbeaver.model.exec.jdbc.JDBCSession
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCRemoteInstance
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.rdb.DBSCatalog
;
import
java.sql.SQLException
;
/**
* ExasolExecutionContext
*/
public
class
ExasolExecutionContext
extends
JDBCExecutionContext
implements
DBCExecutionContextDefaults
<
DBSCatalog
,
ExasolSchema
>
{
private
static
final
Log
log
=
Log
.
getLog
(
ExasolExecutionContext
.
class
);
private
static
final
String
GET_CURRENT_SCHEMA
=
"SELECT CURRENT_SCHEMA"
;
private
static
final
String
SET_CURRENT_SCHEMA
=
"OPEN SCHEMA \"%s\""
;
private
String
activeSchemaName
;
ExasolExecutionContext
(
@NotNull
JDBCRemoteInstance
instance
,
String
purpose
)
{
super
(
instance
,
purpose
);
}
@NotNull
@Override
public
ExasolDataSource
getDataSource
()
{
return
(
ExasolDataSource
)
super
.
getDataSource
();
}
@Nullable
@Override
public
DBCExecutionContextDefaults
getContextDefaults
()
{
return
this
;
}
public
String
getActiveSchemaName
()
{
return
activeSchemaName
;
}
@Override
public
DBSCatalog
getDefaultCatalog
()
{
return
null
;
}
@Override
public
ExasolSchema
getDefaultSchema
()
{
return
activeSchemaName
==
null
?
null
:
getDataSource
().
getSchemaCache
().
getCachedObject
(
activeSchemaName
);
}
@Override
public
boolean
supportsCatalogChange
()
{
return
false
;
}
@Override
public
boolean
supportsSchemaChange
()
{
return
true
;
}
@Override
public
void
setDefaultCatalog
(
DBRProgressMonitor
monitor
,
DBSCatalog
catalog
,
ExasolSchema
schema
)
throws
DBCException
{
throw
new
DBCException
(
"Not supported"
);
}
@Override
public
void
setDefaultSchema
(
DBRProgressMonitor
monitor
,
ExasolSchema
schema
)
throws
DBCException
{
final
ExasolSchema
oldSelectedEntity
=
getDefaultSchema
();
if
(
schema
==
null
||
oldSelectedEntity
==
schema
)
{
return
;
}
setCurrentSchema
(
monitor
,
schema
);
activeSchemaName
=
schema
.
getName
();
// Send notifications
if
(
oldSelectedEntity
!=
null
)
{
DBUtils
.
fireObjectSelect
(
oldSelectedEntity
,
false
);
}
DBUtils
.
fireObjectSelect
(
schema
,
true
);
}
@Override
public
boolean
refreshDefaults
(
DBRProgressMonitor
monitor
)
throws
DBException
{
// Check default active schema
try
(
JDBCSession
session
=
openSession
(
monitor
,
DBCExecutionPurpose
.
META
,
"Query active schema"
))
{
// Get active schema
this
.
activeSchemaName
=
determineActiveSchema
(
session
);
}
catch
(
Exception
e
)
{
throw
new
DBCException
(
e
,
getDataSource
());
}
return
false
;
}
void
setCurrentSchema
(
DBRProgressMonitor
monitor
,
ExasolSchema
object
)
throws
DBCException
{
if
(
object
==
null
)
{
log
.
debug
(
"Null current schema"
);
return
;
}
try
(
JDBCSession
session
=
openSession
(
monitor
,
DBCExecutionPurpose
.
UTIL
,
"Set active schema"
))
{
JDBCUtils
.
executeSQL
(
session
,
String
.
format
(
SET_CURRENT_SCHEMA
,
object
.
getName
()));
this
.
activeSchemaName
=
object
.
getName
();
}
catch
(
SQLException
e
)
{
throw
new
DBCException
(
e
,
getDataSource
());
}
}
private
String
determineActiveSchema
(
JDBCSession
session
)
throws
SQLException
{
// First try to get active schema from special register 'CURRENT SCHEMA'
String
defSchema
=
JDBCUtils
.
queryString
(
session
,
GET_CURRENT_SCHEMA
);
if
(
defSchema
==
null
)
{
return
null
;
}
return
defSchema
.
trim
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录